fix(compiler): track type query references - #6825
Conversation
Collect class and enum names used by TypeQueryNode expressions so generated component declarations preserve imports and type-library entries across aliases and re-exports. fixes: stenciljs#2482
johnjenkins
left a comment
There was a problem hiding this comment.
looks great - tysm!
Few little bits. More generally, I noticed you removed some of the (now outdated) comments describing the branching variations etc. Can you make sure to replace with updated ones, seeing as the branching logic - if anything - is slightly more opaque / subtle now. Nothing too long - just simple pointers 🙏
Use the compiler's mock filesystem for the type-query fixture and document the updated export/import branches.
|
@Boulea7 - my-bad ... need to normalise the path before it touches import { join as pathJoin, resolve } from 'path';
...
const join = (...segments: string[]) => normalizePath(pathJoin(...segments), false);Additionally, you now need to restore cwd const compiler = await createCompiler({ ...config, tsconfig: tsconfigPath });
+ const originalCwd = process.cwd();
try {
const results = await compiler.build();
...
} finally {
+ process.chdir(originalCwd);
await compiler.destroy();
} |
Head branch was pushed to by a user without write access
|
Windows was reading the docs output through an unnormalized backslash path, so the mock filesystem lookup returned |
* fix(compiler): track type query references (#6825) * fix(compiler): track type query references Collect class and enum names used by TypeQueryNode expressions so generated component declarations preserve imports and type-library entries across aliases and re-exports. fixes: #2482 * refactor(compiler): share alias resolver Use the compiler's mock filesystem for the type-query fixture and document the updated export/import branches. * test(compiler): normalize mock paths * chore: v5 update the deps --------- Co-authored-by: Langning Zhang <zln1905391059@163.com>
What is the current behavior?
Class and enum names used in identifier-based
keyof typeofprop types are not collected as type references. As a result, generatedcomponents.d.tsfiles can omit required imports. Aliases and re-exports can also produce incorrect imports or colliding docs type-library IDs.GitHub Issue Number: Fixes #2482
What is the new behavior?
The compiler now collects identifier-based
TypeQueryNodereferences when they resolve to classes or enums. It preserves local, named, default, and re-exported aliases in generated component declarations, supports multiple local names for the same default export, and derives docs type-library IDs from the resolved declaration source.Documentation
N/A. This is a compiler fix covered by regression tests.
Does this introduce a breaking change?
Testing
npm run test.jest -- src/compiler/transformers/test/parse-props.spec.ts --runInBand(48 tests)npm run test.jest -- src/compiler/transformers/test --runInBand(356 tests)npm run test.jest -- src/compiler/types/tests/generate-app-types.spec.ts --runInBand(16 tests, 16 snapshots)npm run tsc.prodnpm run lintnpm run prettier.dry-runnpm run buildOther information
Qualified namespace expressions are outside this change's scope; this addresses identifier-based enum and class queries such as the one reported in #2482.