Skip to content

Normalize case-insensitive CSS when we parse it - #20738

Open
RobinMalfait wants to merge 14 commits into
mainfrom
robin/open-pr-normalize-css-casing
Open

RobinMalfait wants to merge 14 commits into
mainfrom
robin/open-pr-normalize-css-casing

Conversation

@RobinMalfait

Copy link
Copy Markdown
Contributor

This PR lowercases the case-insensitive parts of CSS when we parse them, so the rest of the code can compare them as-is. It replaces one-off toLowerCase() calls and /i flags, and fixes the places that had no such check.

CSS is ASCII case-insensitive in many places: at-rule names, !important, function names, pseudo-class and pseudo-element names, units, CSS-wide keywords and URL schemes. We mostly compared them in lowercase only. On main:

@THEME { --color-brand: red; }         → printed as written, and `bg-brand` generates nothing
border-[2PX]                           → border-color: 2PX
@theme { --color-*: INITIAL; }         → Invalid theme value `INITIAL` for namespace `--color-*`
not-[@MEDIA_print]:flex                → generates nothing
.a { :IS(&) .b { … } }                 → .a :IS(&) .b
@import "HTTPS://example.com/a.css";   → passed to `loadStylesheet` like a local file
url(HTTPS://example.com/a.png)         → url(./foo/bar/HTTPS:/example.com/a.png) in an imported file

Each commit handles one layer, and its message has the details. So this PR is easiest to review commit by commit.

Changes

  • At-rule names and !important: parseAtRule lowercases the name, which also covers the at-rules of plugins and of rule('@…'). The AST of @tailwindcss/postcss skips our parser, so it lowercases the names itself. !IMPORTANT and ! important are the !important flag now.
  • Function names: the value parser lowercases them, e.g. CALC(…) becomes calc(…). The 11 functions that CSS spells in camelCase get that spelling, e.g. ROTATEX(…) becomes rotateX(…). Dashed functions, like --spacing(…), are case-sensitive, so they stay as written. Raw arbitrary values get the same treatment before we validate them, so bg-[URL(/a/*.png)] is a url(…).
  • Pseudo-class and pseudo-element names: the selector parser lowercases them, and the An+B of :nth-*(…). E.g. :NTH-CHILD(2N+1 OF .Foo) becomes :nth-child(2n+1 of .Foo). Classes, IDs, attributes and the contents of functions like :lang(EN) stay as written.
  • Units: the candidate parser lowercases units and exponents in arbitrary values, so border-[2PX] sets border-width: 2px. Strings, url(…)s, hashes and identifiers stay as written, and so does the value of a custom property.
  • CSS-wide keywords: INITIAL becomes initial where values come in: the CSS parser, the AST of @tailwindcss/postcss, the theme of a JS config, and arbitrary values. This includes custom properties, because a CSS-wide keyword is always the whole value.
  • Variants: the at-rule name at the start of a variant selector is lowercase, so not-[@MEDIA_print]:flex and @custom-variant print (@MEDIA print); compound with not-*. Variant signatures print the parsed selector, so [&:FOCUS]:flex canonicalizes to focus:flex.
  • URL schemes: normalizeUrlScheme lowercases only the scheme, because the rest of a URL can be case-sensitive. We use it in @import, in the url(…) rewriter of @tailwindcss/node, and in arbitrary values. A single letter is a Windows drive, like C:, so it stays as written.

These one-off checks are gone, because the parsers handle the case now:

  • toLowerCase() for url(…) and supports(…) in @import.
  • toLowerCase() for math functions in hasMathFn and addWhitespaceAroundMathOperators.
  • toLowerCase() for color and length functions in shadow values.
  • toLowerCase() in isPseudoElement and isStandardPseudoElement.
  • toLowerCase() for CSS-wide keywords in canonicalization.
  • The /i flags of IS_COLOR_FN and IS_LENGTH_FN. With /i, --ALPHA(…) and --SPACING(…) counted as --alpha(…) and --spacing(…), but dashed functions are case-sensitive.

Output that changes on purpose

  • User CSS prints at-rule names, CSS-wide keywords, !important and pseudo-classes in nested selectors in lowercase, e.g. @MEDIA print becomes @media print. The CSS does the same thing.
  • [&_:BEFORE]:flex canonicalizes to **:[&:before]:flex instead of **:[&:BEFORE]:flex.
  • bg-[URL(_'image.png')] is invalid now, like bg-[url(_'image.png')].
  • text-[1q] is a length now, like text-[1Q].

Out of scope

  • Property names. We can't lowercase them when we parse, because @plugin options (like className), CSS Modules :export keys and @font-feature-values names are case-sensitive.
  • Function names and URL schemes in plain CSS declarations, because the CSS parser doesn't parse values. E.g. THEME(…) doesn't resolve in CSS, but w-[THEME(spacing.1)] does.
  • Media query params, e.g. [@MEDIA_PRINT]:flex becomes [@media_PRINT]:flex. negateConditions compares not in lowercase, but Negate combined conditions as a whole in not-* variants #20664 rewrites it, so this PR leaves it alone.
  • Arbitrary variants that don't match a named variant keep their case, e.g. [&:HOVER]:flex.
  • Color keywords like currentColor, units in variant values and modifiers (data-[size=10PX] is a case-sensitive attribute value), the fallback of --theme(--x, INITIAL), and the CSS-in-JS values of plugins.
  • URL(…) in the url(…) rewriter of @tailwindcss/node: cssUrlRE only matches a lowercase url(, like Vite.

#20731 fixes the @import case with case-insensitive checks. This PR takes its tests, with its author as a co-author.

Test plan

  • Each commit adds tests next to the existing ones, e.g. in css-parser.test.ts, value-parser.test.ts, selector-parser.test.ts, utilities.test.ts, variants.test.ts, index.test.ts, canonicalize-candidates.test.ts, at-import.test.ts, urls.test.ts and the tests of @tailwindcss/postcss.
  • The new tests fail without the change of their commit.
  • pnpm vitest run and pnpm run build pass.
  • Benchmarks of bundled builds in Node, as the median of shuffled rounds, against main and a copy of main (A/A):
    • Parsing a 198 KiB stylesheet (the theme, Preflight and the CSS of about 2,400 candidates): 1.63 ms → 1.66 ms (+1.8%, A/A 0.0%).
    • A cold compile with the default theme, and a build of the 2,411 arbitrary candidates of this repo's tests: 19.63 ms → 19.73 ms (+0.5%, A/A -0.3%).
    • A cold canonicalizeCandidates call with 17 candidates with variants: 781 ms → 793 ms (+1.5%, A/A -0.7%).

RobinMalfait and others added 9 commits November 20, 2026 19:06
At-rule names are ASCII case-insensitive, so `@MEDIA` is `@media` and
`@THEME` is `@theme`. `parseAtRule` now lowercases the name, so the rest
of the code can compare it as-is: `@theme`, `@utility`, `@apply`,
`@layer a, b;`, `@keyframes` inside of `@theme`, and so on. Only the
ASCII letters change, so source positions stay valid. The params stay
as written.

`parseAtRule` also builds the at-rules of plugins and of `rule('@…')`.
The AST of `@tailwindcss/postcss` skips our parser, so it lowercases the
names itself, and its quick bail check compares lowercased names too.
Before, it skipped a file with only `@IMPORT "tailwindcss"` in it.

The `!important` flag is ASCII case-insensitive too, and whitespace can
be between the `!` and the keyword, e.g. `color: red ! IMPORTANT`.
Before, `!IMPORTANT` stayed in the value, so `foo!` printed it next to
an extra `!important`. We only look for the flag when the value ends in
a `t` or `T`, which keeps the parser as fast as before.
Function names are ASCII case-insensitive, so `CALC(…)` is `calc(…)` and
`URL(…)` is `url(…)`. The value parser now lowercases the name of each
function node, so the rest of the code can compare it as-is. The 11
functions that CSS spells in camelCase get that spelling, e.g.
`ROTATEX(…)` becomes `rotateX(…)`, but `rotatex(…)` stays as written.
Dashed functions, like `--my-fn(…)` and `--spacing(…)`, are
case-sensitive, so they stay as written.

Raw arbitrary values get the same treatment before we validate them,
because we validate and decode a `url(…)` differently than other
functions: we keep each `_` in it, and allow a `/*`. So `URL(…)` has to
be a `url(…)` before `isValidArbitrary` runs. An `_` is a space in a raw
arbitrary value, so in `Spin_CALC(…)` only `CALC` changes. And a name
can't start with a digit, so in `100PX-theme(…)` the name is `theme`.

This makes these one-off checks unnecessary:

- `toLowerCase()` for `url(…)` and `supports(…)` in `@import`.
- `toLowerCase()` for color and length functions in shadow values.
- `toLowerCase()` for math functions in `hasMathFn` and
  `addWhitespaceAroundMathOperators`.
- The `/i` flags of `IS_COLOR_FN` and `IS_LENGTH_FN`. With `/i`,
  `--ALPHA(…)` and `--SPACING(…)` counted as Tailwind's `--alpha(…)` and
  `--spacing(…)`, but dashed functions are case-sensitive.

`normalizeEscapes` reads the raw candidate before we parse it, so it
compares function names in lowercase, like the decoder does now.
Without that, `content-[URL(\61_b)]` became `content-[URL(ab)]`.

Changed expectations:

- `bg-[URL(/a/*.png)]`, `bg-[Url(/a/*.png)]` and `bg-[URL(a\/*b)]` are
  valid now, and print a lowercase `url(…)`. Before, we rejected them,
  because PostCSS only reads a lowercase `url(` as a URL, see
  #20690.
- `bg-[URL(_'image.png')]` is invalid now, like
  `bg-[url(_'image.png')]`. Before, `URL(…)` was a regular function, so
  the `_` became a space.
- `Asin(…)`, `Calc(…)` and `CALC(…)` print in lowercase.

Other output that changes: `text-[RGB(0_0_0)]` prints `rgb(0 0 0)`,
`w-[THEME(spacing.1)]` resolves the theme value, `[&:NOT(.a)]:flex`
prints `:not(.a)`, and a shadow theme value with `RGB(…)` prints
`rgb(…)`.

The value parser tracks uppercase letters while it fills its buffer,
and raw arbitrary values bail early when they have none. On the 684
lowercase arbitrary values in this repo, both stay within noise of
`main`.
Pseudo-class and pseudo-element names are ASCII case-insensitive, and so
are the `An+B` part of `:nth-*(…)` and its `of` keyword. The selector
parser now lowercases them, so the rest of the code can compare them
as-is. E.g. `:HOVER` is `:hover`, `::BEFORE` is `::before`, and
`:NTH-CHILD(2N+1 OF .Foo)` is `:nth-child(2n+1 of .Foo)`.

These stay as written, because they are or can be case-sensitive:

- Dashed names, e.g. `:--my-state`.
- Classes, IDs, type selectors and attribute selectors.
- The contents of functions that we don't parse as a selector list, e.g.
  `:lang(EN)`, `::part(Foo)` and `:state(Foo)`.
- An `:nth-child(…)` with an `of` that has no space after it. We only
  parse an `of` clause with a space after it, so we can't tell where its
  selector list starts.

This fixes nesting with an uppercase pseudo-class function. We didn't
parse `:IS(&)` as a selector list, so we didn't see its `&`, and
`.a { :IS(&) .b {} }` printed `.a :IS(&) .b`. It now prints
`:is(.a) .b`.

It also helps canonicalization:

- `[&:NOT(:FIRST-CHILD)]:flex` becomes `not-first:flex`.
- `[&:NTH-CHILD(ODD)]:flex` becomes `odd:flex`.
- `[&:NOT(:NTH-CHILD(ODD))]:flex` becomes `even:flex`.
- `[&:NTH-CHILD(-N+3)]:flex` becomes `nth-[-n+3]:flex`.
- `[&_>_:BEFORE]:flex` becomes `*:[&:before]:flex`.

Simple pseudo-class variants, like `[&:HOVER]:flex`, don't become
`hover:flex` yet. That comes with normalizing arbitrary variants.

This makes these one-off checks unnecessary:

- `toLowerCase()` in `isPseudoElement`, for `:BEFORE` and the like.
- `toLowerCase()` in `isStandardPseudoElement`, for the same reason.

Changed expectation: `[&_:BEFORE]:flex` becomes `**:[&:before]:flex`
instead of `**:[&:BEFORE]:flex`. The test comes from
#20550, and checks that
we keep the `&` for a legacy pseudo-element in any case. We still do,
but now print its name in lowercase, like any other pseudo name.

On the 134,524 selectors that a build with the default theme and 26
variants prints, `SelectorParser.parse` stays within noise of `main`.
Units and exponents are ASCII case-insensitive, so `10PX` is `10px`, and
`1E3` is `1e3`. But we infer the type of an arbitrary value with
lowercase units. So `border-[2PX]` set `border-color: 2PX`, `text-[1EM]`
set `color: 1EM`, and `bg-[10PX_20PX]` set `background-color`.

The candidate parser now lowercases the exponent and unit of each number
in the value of an arbitrary property, and in the arbitrary value of a
utility. So `border-[2PX]` sets `border-width: 2px`, `text-[1EM]` sets
`font-size: 1em`, and `bg-[10PX_20PX]` sets `background-position`.

These stay as written:

- Strings, `url(…)`s, hashes and identifiers, e.g. `'10PX'`,
  `url(/10PX.png)`, `#1E3A8A` and `theme(spacing.10PX)`.
- Dashed units, like `10--Foo`.
- The value of a custom property, e.g. `[--my-var:10PX]`, because we
  don't know where it ends up. The utility signature leaves custom
  properties alone for the same reason when it lowercases hex colors.
- Variant values and modifiers, because `data-[size=10PX]` is a
  case-sensitive attribute value.

`LENGTH_UNITS` had `Q` in uppercase, so `text-[1Q]` was a length, but
`text-[1q]` was a color. Now that we lowercase units, it has `q`.

We keep the `/i` in `dimensions.ts`, the `unit.toLowerCase()` in
constant folding and the `toLowerCase()` for lengths in shadow values.
They also read theme values and variant values, e.g. `max-[48REM]`, and
we print those as written.

Canonicalization gains: `rotate-[45DEG]` becomes `rotate-45`,
`border-[2PX]` becomes `border-2`, `[width:10PX]` becomes `w-2.5`,
`space-x-[0PX]` becomes `space-x-0`, and `delay-[1S]` becomes
`delay-1000`.

A regex like `/\d[a-z\d-]*[A-Z]/` takes quadratic time on a long run of
digits: 1.1s on 50,000 of them. So we look for an uppercase letter in a
number with a loop, after a `/[A-Z]/` that most values fail. On the
2,411 arbitrary candidates in this repo, `parseCandidate` is about 1%
slower, within the noise of A/A runs (up to 1.4%).
CSS-wide keywords are ASCII case-insensitive, so `INITIAL` is `initial`.
They are always the whole value of a declaration, also of a custom
property. Before, we only understood them in lowercase:

- `--color-red-500: INITIAL` in `@theme` kept the color, and printed
  `INITIAL` in `:root`.
- `--color-*: INITIAL` threw "Invalid theme value `INITIAL` for
  namespace `--color-*`".
- `text-[INHERIT]` printed `color: INHERIT`, and canonicalization kept
  it, while `text-[inherit]` becomes `text-inherit`.

`normalizeCssWideKeyword` lowercases a value that is a CSS-wide keyword,
and keeps any other value as written. We call it where values come in:

- The CSS parser, for each declaration.
- The AST of `@tailwindcss/postcss` and the theme of a JS config, because
  they skip the CSS parser.
- Arbitrary values and arbitrary properties of candidates, after the
  typehint, e.g. `bg-[color:INHERIT]`.

So each theme value is lowercase now, and canonicalization compares a
theme value with the keywords as-is, instead of with `toLowerCase()`. It
shares the list of keywords with the parser.

The output changes on purpose: user CSS like `color: INHERIT` now prints
`color: inherit`. This includes custom properties, and the options of
`@plugin`, because they are declarations too. It doesn't change what the
CSS does, because a CSS-wide keyword applies in any case.

Most values don't start with an `i`, `r` or `u`, so we bail after one
character. On a 198 KiB input (the theme, preflight and the CSS of about
2,400 candidates), the bundled parser is about 1% slower in Node, from
1.67 ms to 1.69 ms, with an A/A difference of up to 0.5%.
At-rule names are ASCII case-insensitive, but `compoundsForSelectors`
compares the start of a selector with `@media`, `@supports` and
`@container`. So a variant with an uppercase at-rule never compounded,
and `not-*` printed nothing for:

- `not-[@MEDIA_print]:flex` and `not-[@CONTAINER_(width>=24rem)]:flex`
- `not-print:flex` with `@custom-variant print (@media print);`
- `not-print:flex` with `addVariant('print', '@media print')`

The `@custom-variant` shorthand also checks for `@scope`, so
`@SCOPE (.from)` compiled differently from `@scope (.from)`.

`normalizeAtRuleName` lowercases the name of the at-rule at the start of
a variant selector, and keeps the rest as written. We call it where these
selectors come in, instead of comparing them case-insensitively in
`compoundsForSelectors`: arbitrary variants in the candidate parser, the
`@custom-variant` shorthand, and `addVariant`. Variants with a body and
CSS-in-JS variants go through the CSS parser or `rule()`, which lowercase
the name already.

Canonicalization prints the lowercase name now, e.g.
`[@SUPPORTS_(display:grid)]:flex` becomes `[@supports_(display:grid)]:flex`.
It also finds the named variant, e.g. `[@MEDIA_not_print]:flex` and
`not-[@MEDIA_print]:flex` become `not-print:flex`.
The variant signature only re-printed a selector after a structural
change, like a list, a combinator or an `:is(…)`. Otherwise it kept the
selector as written. So `&:FOCUS` never matched the `&:focus` of the
`focus` variant, and `[&:FOCUS]:flex` didn't canonicalize to
`focus:flex`.

We now always print the selector from the parsed AST. The selector
parser lowercases pseudo-class and pseudo-element names, so
`[&:FOCUS]:flex` becomes `focus:flex`, and `[&:FIRST-CHILD]:flex`
becomes `first:flex`.

The signatures of 448 default, compound and arbitrary variants are the
same as on `main`. A cold `canonicalizeCandidates` call takes the same
time: 826.6 ms before, 831.4 ms after, and 832.7 ms for an A/A copy.

An arbitrary variant that doesn't match a named variant keeps its
selector as written, e.g. `[&:HOVER]:flex`.
URL schemes are ASCII case-insensitive, so `HTTPS://` is `https://`.
The rest of a URL can be case-sensitive, so only the scheme changes.
The new `normalizeUrlScheme` helper lowercases a scheme as RFC 3986
defines it. A single letter stays as written, because it's a Windows
drive like the `C` in `C:/styles/app.css`.

We use it in three places:

- `@import`: we now skip `HTTPS://` and `DATA:` imports, like their
  lowercase forms. Before, we passed them to `loadStylesheet` like a
  local file. The `@import` stays as written in the output.
- The `url()` rewriter of `@tailwindcss/node`: it now skips
  `url(HTTPS://example.com/image.jpg)`. Before, it rebased it to
  `url(./foo/bar/HTTPS:/example.com/image.jpg)`. We only use the
  normalized URL to decide whether to skip it, so we rebase a relative
  URL as written.
- Arbitrary values and arbitrary properties: `bg-[url(HTTPS://…)]` is
  now `bg-[url(https://…)]`, also when we canonicalize it. A custom
  property keeps its value as written, like it does for units.

`dataUrlRE` keeps its `/i`, because it also allows leading whitespace,
like ` DATA:`, which the helper leaves alone. `cssUrlRE` still only
matches a lowercase `url(`, like Vite does.

The `@import` tests come from
#20731.

Co-authored-by: Ragib MRB <ragib.mrb@gmail.com>
List the fixes of this PR that users see, the canonicalization gains, and
the output that now prints in lowercase.
@RobinMalfait
RobinMalfait requested a review from a team as a code owner November 20, 2026 18:15
@RobinMalfait RobinMalfait self-assigned this Nov 20, 2026
@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous finding is fixed and no new actionable issues were found.

Reviews (3) · Last reviewed commit: "Count a `\r` and a `\f` as whitespace ar..." · Reviewed by Greptile

Comment thread packages/tailwindcss/src/css-parser.ts Resolved
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The changes add case normalization for selected CSS syntax, including at-rule names, function names, units, URL schemes, CSS-wide keywords, and pseudo-class names. Parser and candidate-processing paths apply these normalizations while preserving casing in strings, URL paths, custom properties, and dashed names in the covered cases. PostCSS, import handling, and URL rewriting also use normalized syntax for processing decisions.

Merge Risk: Low · up to 25ea7

This PR makes CSS parsing case-insensitive for at-rules, function names, units, keywords and URL schemes. A few rare inputs can still be mishandled, such as unusual whitespace or escapes in selectors and identifiers, uppercase config keywords, and uppercase directives in PostCSS path handling. These are narrow edge cases, but they are worth addressing before or shortly after merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Normalize case-insensitive CSS when we parse it" matches the main change: the PR lowercases ASCII case-insensitive CSS syntax (at-rule names, !important, function names, pseudo-class names,…
Description check Passed The description explains the goal (lowercasing case-insensitive CSS at parse time), lists the affected layers and examples, the removed one-off toLowerCase() and /i checks, intentional output changes,…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Normalize case-insensitive CSS when we parse it" matches the main change: the PR lowercases ASCII case-insensitive CSS syntax (at-rule names, !important, function names, pseudo-class names, units, CSS-wide keywords, URL schemes) during parsing so later code can compare values directly.

Full details: Description check

Explanation

The description explains the goal (lowercasing case-insensitive CSS at parse time), lists the affected layers and examples, the removed one-off toLowerCase() and /i checks, intentional output changes, out-of-scope items, test plan, and benchmarks. It is clearly related to the changeset.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Major · Match uppercase directives before their paths reach the compiler. · index.ts:67

packages/@tailwindcss-postcss/src/postcss-fix-relative-paths/index.ts:67
Major · Data Integrity & Integration · Quick win

Match uppercase directives before their paths reach the compiler.

If postcss-import inlines /app/styles/theme.css with @CONFIG "./config.js", this case-sensitive matcher skips its path. The changed AST conversion then recognizes @config. The compiler resolves ./config.js from /app, not /app/styles, so compilation fails or loads the wrong configuration. The module loader uses the compiler context base, not node.src. (raw.githubusercontent.com)

Make this matcher ASCII case-insensitive for source, plugin, and config. Add an integration case with an uppercase directive in a stylesheet inlined before Tailwind.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fbc3f04d-7601-46cf-b3e2-2e631cbb5da5
Commits

Reviewing files that changed from the base of the PR and between 511c82a and 7119454.

Files selected for processing: 43

  • .changelog/case-insensitive-css.md
  • packages/@tailwindcss-node/src/urls.test.ts
  • packages/@tailwindcss-node/src/urls.ts
  • packages/@tailwindcss-postcss/src/ast.test.ts
  • packages/@tailwindcss-postcss/src/ast.ts
  • packages/@tailwindcss-postcss/src/index.test.ts
  • packages/@tailwindcss-postcss/src/index.ts
  • packages/tailwindcss/src/ast.test.ts
  • packages/tailwindcss/src/ast.ts
  • packages/tailwindcss/src/at-import.test.ts
  • packages/tailwindcss/src/at-import.ts
  • packages/tailwindcss/src/candidate.test.ts
  • packages/tailwindcss/src/candidate.ts
  • packages/tailwindcss/src/canonicalize-candidates.test.ts
  • packages/tailwindcss/src/canonicalize-candidates.ts
  • packages/tailwindcss/src/compat/apply-config-to-theme.test.ts
  • packages/tailwindcss/src/compat/apply-config-to-theme.ts
  • packages/tailwindcss/src/compat/plugin-api.ts
  • packages/tailwindcss/src/css-parser.test.ts
  • packages/tailwindcss/src/css-parser.ts
  • packages/tailwindcss/src/index.test.ts
  • packages/tailwindcss/src/index.ts
  • packages/tailwindcss/src/selector-parser.test.ts
  • packages/tailwindcss/src/selector-parser.ts
  • packages/tailwindcss/src/utilities.test.ts
  • packages/tailwindcss/src/utils/css-wide-keywords.test.ts
  • packages/tailwindcss/src/utils/css-wide-keywords.ts
  • packages/tailwindcss/src/utils/decode-arbitrary-value.test.ts
  • packages/tailwindcss/src/utils/decode-arbitrary-value.ts
  • packages/tailwindcss/src/utils/infer-data-type.ts
  • packages/tailwindcss/src/utils/is-color.ts
  • packages/tailwindcss/src/utils/math-operators.ts
  • packages/tailwindcss/src/utils/normalize-at-rule-name.test.ts
  • packages/tailwindcss/src/utils/normalize-at-rule-name.ts
  • packages/tailwindcss/src/utils/normalize-function-name.ts
  • packages/tailwindcss/src/utils/normalize-url-scheme.test.ts
  • packages/tailwindcss/src/utils/normalize-url-scheme.ts
  • packages/tailwindcss/src/utils/replace-shadow-colors.test.ts
  • packages/tailwindcss/src/utils/replace-shadow-colors.ts
  • packages/tailwindcss/src/utils/to-ascii-lower-case.ts
  • packages/tailwindcss/src/value-parser.test.ts
  • packages/tailwindcss/src/value-parser.ts
  • packages/tailwindcss/src/variants.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


// CSS-wide keywords are never inlined
if (CSS_WIDE_KEYWORDS.includes(variableValue.toLowerCase())) return
if (CSS_WIDE_KEYWORDS.has(variableValue)) return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Keep the keyword check case-insensitive for unnormalized theme writers.

Config font tuples can still supply uppercase defaults. For example, fontFamily.sans: ['Inter', { fontFeatureSettings: 'UNSET' }] reaches theme.add('--default-font-feature-settings', ...) without normalization in apply-config-to-theme.ts. The theme resolver returns the stored value. (raw.githubusercontent.com)

This check misses UNSET, so the following code replaces the variable with a CSS-wide keyword. That violates the no-inlining requirement and can make distinct inherited variables produce the same canonicalization signature.

Normalize these remaining writers, or retain case-insensitive membership here.

// ```
case OPEN_PAREN: {
let node = fun(buffer, [])
let node = fun(bufferHasUpperCase ? normalizeFunctionNameInValue(buffer) : buffer, [])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Keep hexadecimal escape terminators inside the identifier before normalization.

In CSS text --\46 OO(), the space terminates the hexadecimal escape. It does not separate identifiers, so the function name is --FOO. (w3.org)

The escape branch consumes only \4. The space then flushes --\46, and this line normalizes the remaining OO buffer to oo. Serialization now produces --\46 oo(), which references --Foo.

Consume complete CSS escapes, including their optional whitespace terminator, before locating or normalizing a function name. Apply the same escape handling to normalizeFunctionNames.

The CSS parser and the AST of `@tailwindcss/postcss` lowercase CSS-wide
keywords in every declaration. But the options of a `@plugin` are not
CSS: we pass them to the plugin as written. So `className: INHERIT` gave
the plugin `"inherit"`.

Both now skip the declarations of a `@plugin`. At-rule names are
lowercased when we parse them, so this covers `@PLUGIN` too.

This fixes a finding of the Greptile review.
A JS config can set the `--default-font-*` and `--default-mono-font-*`
variables with `fontFamily.sans` and `fontFamily.mono`, e.g.:

  sans: ['Inter', { fontFeatureSettings: 'UNSET' }]

We lowercased CSS-wide keywords in the other theme values of a config,
but not in these. So canonicalization, which compares them in lowercase,
inlined `UNSET`.

Like before for a lowercase `initial`, `INITIAL` now removes the
variable, as it does in `@theme`.

This fixes a finding of the CodeRabbit review.
We looked for the `of` keyword of `:nth-child(An+B of S)` with
`indexOf('of ')`. When a tab or a newline follows the keyword, that
matched the `of` in a class instead, e.g. in `.Proof`:

  :nth-child(2N of\t.Proof .Bar)

So we lowercased the part before it as `An+B`, which gave `.proof`.

The `An+B` part can't contain an `of`, so now we only look at the first
`of`. It is the keyword when it has whitespace on both sides. When it
doesn't, e.g. in `2n of.Foo`, we keep the contents as written, like
before.

The test of `:nth-child(2N of\t.Foo)` changes on purpose: we split at a
tab now, so its `2N` becomes `2n`, like with a space.

This fixes a finding of the CodeRabbit review.
An escape can spell a `-`. So `\--MY-FN(…)` and `-\-MY-FN(…)` are the
dashed function `--MY-FN`, and dashed names are case-sensitive. But
`isDashed` only looked for two literal `-`, so we lowercased them to
`\--my-fn(…)`.

We don't decode escapes, so now an escape in the place of either `-`
counts as one. This keeps the name as written, like on `main`. It covers
function names in the value parser and in raw arbitrary values, and
pseudo names in the selector parser.

This fixes a finding of the CodeRabbit review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 620c6cfe-ced5-4f67-b44e-8652180f3c46
Commits

Reviewing files that changed from the base of the PR and between 7119454 and 2215cf1.

Files selected for processing: 11

  • packages/@tailwindcss-postcss/src/ast.test.ts
  • packages/@tailwindcss-postcss/src/ast.ts
  • packages/tailwindcss/src/compat/apply-config-to-theme.test.ts
  • packages/tailwindcss/src/compat/apply-config-to-theme.ts
  • packages/tailwindcss/src/css-parser.ts
  • packages/tailwindcss/src/index.test.ts
  • packages/tailwindcss/src/selector-parser.test.ts
  • packages/tailwindcss/src/selector-parser.ts
  • packages/tailwindcss/src/utils/decode-arbitrary-value.test.ts
  • packages/tailwindcss/src/utils/normalize-function-name.ts
  • packages/tailwindcss/src/value-parser.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

The `of` keyword of `:nth-child(An+B of S)` needs whitespace on both
sides. We only counted a space, a tab and a `\n`. But CSS treats a `\r`
and a `\f` as newlines too, and the CSS parser keeps a lone one in a
selector. So `:nth-child(2n\rof &)` kept the `&` in an opaque value,
and nesting couldn't replace it. On `main`, it worked, because we only
looked for an `of` with a space after it.

This fixes a finding of the Greptile review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d8144841-8363-4fda-b8e1-ea73f33c0d7c
Commits

Reviewing files that changed from the base of the PR and between 2215cf1 and 25ea786.

Files selected for processing: 2

  • packages/tailwindcss/src/selector-parser.test.ts
  • packages/tailwindcss/src/selector-parser.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment on lines +262 to +263
char === CARRIAGE_RETURN ||
char === FORM_FEED

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Parse CR and FF as whitespace throughout the selector list.

For :nth-child(2n\rof\f*\f+&), this check admits the of clause, but the recursive selector parser treats the second form feed as a selector. Nesting substitution then removes * as if it were in a compound, leaving a selector list that starts with +. The browser rejects the resulting rule. Handle CR and FF as whitespace in the selector parser as well. Add a nesting-substitution regression test. (raw.githubusercontent.com)

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.

1 participant