Skip to content

refactor(core, codegen): do not emit token reference statements in codegen .d.ts files#399

Merged
mizdra merged 1 commit into
mainfrom
fix/codegen-omit-token-references
May 11, 2026
Merged

refactor(core, codegen): do not emit token reference statements in codegen .d.ts files#399
mizdra merged 1 commit into
mainfrom
fix/codegen-omit-token-references

Conversation

@mizdra
Copy link
Copy Markdown
Owner

@mizdra mizdra commented May 11, 2026

Summary

Stop emitting token reference statements (styles['a_1']; / __self['a_1'];) 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 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 existing forTsPlugin option on generateDts is 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 on options.forTsPlugin. Pass options through to generateDefaultExportDts.
  • packages/core/src/dts-generator.test.ts: Add a describe block verifying that no reference statements are emitted when forTsPlugin is false, and a separate describe block verifying that they are emitted when forTsPlugin is true.
  • examples/1-basic/generated/src/a.module.css.d.ts: Regenerated; styles['a_4']; is removed (1 line).
  • .changeset/codegen-omit-token-references.md: patch for 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.ts passes
  • vp test (full suite) passes
  • vp check / vp run build pass
  • (optional) Verify in VSCode via ts-plugin that Go to Definition / Find All References / Rename on @keyframes still work

🤖 Generated with Claude Code

…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>
@mizdra mizdra added the Type: Refactoring A code change that neither fixes a bug nor adds a feature label May 11, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 11, 2026

🦋 Changeset detected

Latest commit: 6b92574

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@css-modules-kit/codegen Patch
@css-modules-kit/core Patch
@css-modules-kit/eslint-plugin Patch
@css-modules-kit/stylelint-plugin Patch
@css-modules-kit/ts-plugin Patch
css-modules-kit-vscode Patch

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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.forTsPlugin for both default-export and named-export .d.ts generation paths.
  • Add/adjust unit tests to verify reference statements are omitted when forTsPlugin: false and preserved when forTsPlugin: true.
  • Regenerate an example .d.ts output 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.

Comment thread packages/core/src/dts-generator.ts
Comment thread packages/core/src/dts-generator.ts
@mizdra mizdra marked this pull request as ready for review May 11, 2026 14:31
@mizdra mizdra merged commit f758c23 into main May 11, 2026
38 of 39 checks passed
@mizdra mizdra deleted the fix/codegen-omit-token-references branch May 11, 2026 15:51
@github-actions github-actions Bot mentioned this pull request May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Refactoring A code change that neither fixes a bug nor adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants