Skip to content

fix(export): reject css-vars token names that are not CSS identifiers - #203

Open
giri-kondisetty wants to merge 1 commit into
google-labs-code:mainfrom
giri-kondisetty:fix/css-vars-token-name-check
Open

giri-kondisetty wants to merge 1 commit into
google-labs-code:mainfrom
giri-kondisetty:fix/css-vars-token-name-check

Conversation

@giri-kondisetty

Copy link
Copy Markdown

Fixes #202.

The css-vars export wrote token names into the stylesheet with only dots replaced. A name such as x: 0; } a { color: red } :root { --y closed the :root block and added a rule of its own. The Tailwind v4 export already rejects such names.

Changes:

  • CssVarsEmitterHandler checks colors, spacing and rounded names before emitting and returns INVALID_TOKEN_NAME for a name that is not a CSS identifier.
  • The css-vars branch of the export command prints the error code and message in the same shape as the other formats.

The check is a little wider than the Tailwind one. It also accepts _ and non-ASCII characters, because both are valid in a CSS custom property name and I did not want to reject names that export correctly today.

Not changed: the --prefix value is still written as given. It comes from the person running the command, not from the file.

Checked:

  • New tests: the name above is rejected for colors, spacing and rounded; names with -, _, a leading digit, a group dot and a non-ASCII letter still export; the CLI exits 1 with no stylesheet on stdout.
  • bun test in packages/cli: 409 pass, 1 skip, 0 fail. bun run lint is clean.

The css-vars export wrote token names into the stylesheet with only dots
replaced, so a name such as 'x: 0; } a { color: red } :root { --y' closed
the :root block and added a rule of its own. The Tailwind v4 export already
rejects such names with INVALID_TOKEN_NAME.

Check colors, spacing and rounded names before emitting, and report the
error code the same way the other formats do.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

export --format css-vars writes token names unescaped, so a name with ; } adds its own CSS rules

1 participant