Skip to content

fix(core): honor the from clause of var() inside @container style() query values#428

Merged
mizdra merged 4 commits into
mainfrom
fix/style-query-var-from-clause
Jul 2, 2026
Merged

fix(core): honor the from clause of var() inside @container style() query values#428
mizdra merged 4 commits into
mainfrom
fix/style-query-var-from-clause

Conversation

@mizdra

@mizdra mizdra commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Fixes #423

Changes

Previously, a var() with a from clause inside a @container style() query value was collected as a local token reference, ignoring the from clause:

@container style(--a: var(--b from './other.module.css')) {
}

Now --b is treated as an external token reference to ./other.module.css, the same as in a declaration value. var(--b from global) is likewise excluded from references, also matching declaration values.

Test plan

  • vp test --project unit
  • vp check --fix

🤖 Generated with Claude Code

…uery values

The style query collector picked up the first dashed-ident word in each
group, so var(--b from './other.module.css') was collected as a local
reference. Route var() found in query values through the same parsing
path as declaration values so that external and global specifiers are
respected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mizdra mizdra added the Type: Bug Bug or Bug fixes label Jul 2, 2026
@changeset-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 91267d9

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/core Patch
@css-modules-kit/ts-plugin Patch
@css-modules-kit/codegen Patch
@css-modules-kit/eslint-plugin Patch
@css-modules-kit/stylelint-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

mizdra and others added 3 commits July 3, 2026 00:20
…t node parameter

Passing a callback is an uncommon pattern in this codebase and hurts
readability. Instead, thread the parent postcss node (Declaration | AtRule)
through the value collectors and branch on its type once in calcValueLoc.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…produces a reference

A style query tests the computed value of a property rather than declaring
it, so the queried dashed-ident must not become a token definition.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

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 fixes token-reference extraction for var() calls that appear inside @container style(...) query values in the core parser, so var(--x from "<file>") is treated as an external reference (and from global is excluded) consistently with normal declaration-value parsing.

Changes:

  • Route function parsing inside @media / @container style() conditions through the same var() first-argument parsing used for declaration values, enabling correct from "<specifier>" handling.
  • Generalize value-location calculation so token reference locations can be computed for both declarations and at-rule params.
  • Add unit tests covering style-query var(... from "<file>") and a style-query case where a name-defining property should still produce a reference.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/core/src/parser/dashed-ident-parser.ts Reuses declaration-value parsing for functions in style-query values and adds at-rule-compatible location calculation to correctly emit external references for var(... from "<file>").
packages/core/src/parser/dashed-ident-parser.test.ts Adds coverage for the fixed var(... from "<file>") behavior and clarifies reference-vs-definition behavior in style queries.
examples/1-basic/src/a.module.css Adds an example @container style() query using var() to help manual verification of language features.
.changeset/style-query-var-from-clause.md Publishes the core fix as a patch changeset.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mizdra mizdra marked this pull request as ready for review July 2, 2026 15:53
@mizdra mizdra merged commit 4a8630f into main Jul 2, 2026
17 checks passed
@mizdra mizdra deleted the fix/style-query-var-from-clause branch July 2, 2026 15:53
@github-actions github-actions Bot mentioned this pull request Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Bug or Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Honor the from clause of var() inside @container style() query values

2 participants