refactor(core, codegen): do not emit token reference statements in codegen .d.ts files#399
Merged
Merged
Conversation
…degen .d.ts files Statements like `styles['a_1'];` and `__self['a_1'];` (emitted for `animation-name` references to `@keyframes`) used to appear in the `.d.ts` files written by codegen. These statements exist solely to wire up editor language features in ts-plugin (Go to Definition, Find All References, Rename) and are not needed at compile time. The visible types exported by the .d.ts files are unchanged. Gate them on the existing `forTsPlugin` option so they are emitted only by the TS plugin and no longer clutter the type definition files written by codegen. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 6b92574 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
This PR cleans up .d.ts files emitted by codegen by removing “token reference statements” (e.g. styles['a_1']; / __self['a_1'];) that are only needed to power editor navigation features in the ts-plugin, not for TypeScript compilation.
Changes:
- Gate emission of token reference statements behind
options.forTsPluginfor both default-export and named-export.d.tsgeneration paths. - Add/adjust unit tests to verify reference statements are omitted when
forTsPlugin: falseand preserved whenforTsPlugin: true. - Regenerate an example
.d.tsoutput and add a changeset for a patch release note entry.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/core/src/dts-generator.ts | Gates token reference statement emission on forTsPlugin (default + named export paths). |
| packages/core/src/dts-generator.test.ts | Adds coverage for omitted vs emitted reference statements based on forTsPlugin. |
| examples/1-basic/generated/src/a.module.css.d.ts | Updates generated example output to remove the reference statement. |
| .changeset/codegen-omit-token-references.md | Adds patch changeset documenting the cleanup in release notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Stop emitting token reference statements (
styles['a_1'];/__self['a_1'];) in the.d.tsfiles written by codegen. These statements exist solely to wire up editor language features in ts-plugin (Go to Definition, Find All References, Rename) and are not needed by the TypeScript compiler, so to a user reading the generated type definition they look like meaningless noise. The visible types exported by these files are unchanged, so there is no observable behavior change for end users — this is a cleanup of the codegen output. The existingforTsPluginoption ongenerateDtsis now used to gate both the default-export and named-export forms; ts-plugin keeps emitting the statements as before.Changes
packages/core/src/dts-generator.ts: Gate the token reference output blocks in both the default-export and named-export forms onoptions.forTsPlugin. Passoptionsthrough togenerateDefaultExportDts.packages/core/src/dts-generator.test.ts: Add adescribeblock verifying that no reference statements are emitted whenforTsPluginisfalse, and a separatedescribeblock verifying that they are emitted whenforTsPluginistrue.examples/1-basic/generated/src/a.module.css.d.ts: Regenerated;styles['a_4'];is removed (1 line)..changeset/codegen-omit-token-references.md:patchfor both core and codegen so the cleanup shows up in the release notes.Test plan
vp test --project unit packages/core/src/dts-generator.test.tspassesvp test(full suite) passesvp check/vp run buildpass@keyframesstill work🤖 Generated with Claude Code