Skip to content

fix(compiler): track type query references - #6825

Merged
johnjenkins merged 3 commits into
stenciljs:mainfrom
Boulea7:fix-2482-type-query-references
Aug 12, 2026
Merged

fix(compiler): track type query references#6825
johnjenkins merged 3 commits into
stenciljs:mainfrom
Boulea7:fix-2482-type-query-references

Conversation

@Boulea7

@Boulea7 Boulea7 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

What is the current behavior?

Class and enum names used in identifier-based keyof typeof prop types are not collected as type references. As a result, generated components.d.ts files 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 TypeQueryNode references 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?

  • Yes
  • No

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.prod
  • npm run lint
  • npm run prettier.dry-run
  • npm run build

Other 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.

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
@Boulea7
Boulea7 marked this pull request as ready for review August 12, 2026 08:43
@Boulea7
Boulea7 requested a review from a team as a code owner August 12, 2026 08:43

@johnjenkins johnjenkins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🙏

Comment thread src/compiler/transformers/test/parse-props.spec.ts
Comment thread src/compiler/transformers/transform-utils.ts Outdated
Use the compiler's mock filesystem for the type-query fixture and document the updated export/import branches.
@johnjenkins
johnjenkins enabled auto-merge August 12, 2026 10:44
@johnjenkins

johnjenkins commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

@Boulea7 - my-bad ... need to normalise the path before it touches sys e.g.

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();
     }

auto-merge was automatically disabled August 12, 2026 11:35

Head branch was pushed to by a user without write access

@Boulea7

Boulea7 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Windows was reading the docs output through an unnormalized backslash path, so the mock filesystem lookup returned undefined. The fixture now normalizes every joined path before it reaches the mock system and restores the original cwd before compiler teardown. The focused regression and full unit suite pass; lint, formatting, and build pass as well.

@johnjenkins
johnjenkins added this pull request to the merge queue Aug 12, 2026
Merged via the queue into stenciljs:main with commit 4c90b3b Aug 12, 2026
28 checks passed
johnjenkins added a commit that referenced this pull request Aug 12, 2026
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compiler issue: @Prop decorator on variable with 'keyof typeof' results in components.d.ts that lacks class import

2 participants