Repository navigation
Conversation
Stencil's `transpile()` type-checks a single file with module resolution
disabled (`noResolve: true`, a compiler host whose `fileExists` only matches
the root file). `resolveVar()` therefore only works for constants declared in
the same file. Components that read event names from a shared catalog, e.g.
import { EVENTS } from '@my-org/design-tokens';
@event({ eventName: resolveVar(EVENTS.MY_EMITTER.PING_EVENT) })
compile fine under `stencil build` but fail inside `stencilVitestPlugin` with
`resolveVar() cannot find property "PING_EVENT" on object "EVENTS.MY_EMITTER"`,
which leaves the decorators unconverted and the component unable to load.
Before handing a component to `transpile()`, the plugin now:
- detects `resolveVar()` calls whose argument is rooted at a value import
- builds a type-check-only `ts.Program` for that file with real module
resolution, seeded from the nearest `tsconfig.json` (so `paths`, `baseUrl`
and `moduleResolution` match the project)
- inlines the resolved string literal in place of the call
Same-file constants are untouched (Stencil already handles them), and
arguments that do not resolve to a string literal are passed through so the
Stencil compiler reports its usual diagnostic. The TypeScript instance is the
one bundled in `@stencil/core/compiler`, so no new dependency is added.
Adds unit coverage for the helper and a `my-emitter` fixture + plugin spec in
`test/project` that fails without this change.
Co-authored-by: Cursor <cursoragent@cursor.com>
Author
|
Companion: stenciljs/core#6924 |
1 of 2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request checklist
pnpm build) was run locally and passedpnpm test:unitandpnpm test:e2e) were run locally and passedpnpm lint) was run locally and passedPull request type
What is the current behavior?
resolveVar()lets@Event({ eventName })and@Listen()read event names from a constant. Understencil buildthat constant can live in another module.stencilVitestPlugincompiles each component withtranspile()from@stencil/core/compiler, which type-checks a single file with module resolution disabled (noResolve: true). An imported catalog therefore fails:The component never registers. Every
resolveVar()test instenciljs/coredeclares the constant in the same file, so this path was uncovered. Companion pull request: stenciljs/core#6924Issue URL:
What is the new behavior?
Before handing a
.tsxcomponent totranspile(), the plugin resolvesresolveVar()calls whose argument is rooted at a value import and inlines the string literal.ts.Programis built for that file with real module resolution, seeded from the nearesttsconfig.json, using the in-memory source Vite provides.@stencil/core/compiler, so no new dependency is added.string, the declaration's string-literal initializer is read instead, matching the compiler.Does this introduce a breaking change?
Made with Cursor