You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(core, ts-plugin): support composes property with from specifier (#409)
Class names referenced via `composes: foo from './other.module.css';`
are now parsed as external token references, enabling Go to Definition,
Find All References, and Rename across files. The check phase reports
unresolvable specifiers and tokens not exported by the referenced file.
`TokenReference` is now a discriminated union of local and external
references so that each phase can handle them separately.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
feat(core, ts-plugin): support `composes: <name> from '<specifier>'`
7
+
8
+
Class names referenced via `composes: foo from './other.module.css';` are now linked to the `.foo {...}` declaration in the referenced file. Go to Definition jumps from the reference to the declaration, Find All References lists reference sites across files, and Rename updates the declaration and every reference together.
9
+
10
+
Two diagnostics are also emitted in the check phase:
11
+
12
+
-`Cannot import module '<specifier>'` when the specifier cannot be resolved.
13
+
-`Module '<specifier>' has no exported token '<name>'.` when the referenced file does not export the token.
Copy file name to clipboardExpand all lines: AGENTS.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,7 +87,9 @@ function myFunction() {
87
87
## Glossary
88
88
89
89
-**Token**: A generic term for things exported by CSS Modules, such as class names, `@value` definitions, and `@keyframes` names.
90
-
-**Token reference**: A usage of a token elsewhere in the CSS. Currently produced for `animation-name: <name>`. The referenced token may be defined in the same file (e.g. `@keyframes`) or imported via `@import` / `@value ... from`.
90
+
-**Token reference**: A usage of a token elsewhere in the CSS. Currently produced for `animation-name: <name>` and `composes: <name>`. There are two kinds:
91
+
-**Local token reference**: References a token available in the current file. The token may be defined in the same file (e.g. `@keyframes`) or imported via `@import` / `@value ... from`.
92
+
-**External token reference**: References tokens exported by another file, like `composes: <name> ... from '<specifier>'`. One reference corresponds to one `from` clause and holds an entry per referenced token.
91
93
-**Diagnostic**: An object representing errors or warnings
92
94
-**Parse phase**: The phase that parses CSS Modules files and extracts token information
93
95
-**Check phase**: The phase that validates CSS Modules files
### Local Token References (`animation-name`, `composes`) Support
309
309
310
-
In CSS, an animation name defined with `@keyframes foo {...}` can be referenced by `animation-name: foo;`. CSS ModulesKit links such references to their definitions via Volar.js mappings, making Go to Definition / Find All References / Rename work consistently.
310
+
In CSS, an animation name defined with `@keyframes foo {...}` can be referenced by `animation-name: foo;`. In CSS Modules, `composes: foo;` can also reference another class name in the same file. CSS Modules Kit links such references to tokens available in the current file (local token references) to their definitions via Volar.js mappings, making Go to Definition / Find All References / Rename work consistently.
311
311
312
312
The mechanism is to embed "reference expressions" at the end of the generated `.d.ts`. For default export, it is emitted as a bracket access expression statement like `styles['<name>'];`. For named export, after emitting a self-import (`declare const __self: typeof import('./<self-basename>');`) once, it is emitted as a bracket access like `__self['<name>'];`. A mapping is attached to the inside-of-quotes part of each reference expression, pointing to the reference position in the CSS.
313
313
@@ -343,3 +343,35 @@ export { _token_1 as 'a_2' };
### External Token References (`composes: ... from '<specifier>'`) Support
348
+
349
+
In CSS Modules, tokens of another file can be referenced with a `from` clause, like `composes: b_1 b_2 from './b.module.css';`. CSS Modules Kit links such references to tokens exported by another file (external token references) to their definitions via reference expressions and mappings, just like local token references.
350
+
351
+
For example, suppose we have the following CSS module:
352
+
353
+
`src/a.module.css`:
354
+
355
+
```css
356
+
.a_1 { composes: b_1 b_2 from './b.module.css'; }
357
+
```
358
+
359
+
For default export, the following type definition is generated:
360
+
361
+
```ts
362
+
declareconst styles = {
363
+
'a_1': ''asstring,
364
+
} asconst;
365
+
(awaitimport('./b.module.css')).default['b_1'];
366
+
(awaitimport('./b.module.css')).default['b_2'];
367
+
exportdefaultstyles;
368
+
```
369
+
370
+
For named export, the following type definition is generated:
0 commit comments