Repository navigation
Commit cd5831f
authored
Keep a declaration without a
## Summary
This PR keeps a regular declaration that has no `;` at the end of the CSS input, e.g. `color: red` or `--a: 1;\ncolor: red`. Before, the parser only handled a leftover at-rule after the main loop, so it silently dropped the declaration. PostCSS keeps it (`postcss.parse('color: red')` gives a `decl`), and a top-level declaration that ends with `;` is already kept.
The fix parses the leftover `buffer` as a declaration too, and adds it to the current parent, or to the root. A leftover that is not a declaration (e.g. `foo`) is still ignored, as before, so input that parses today does not start to throw. An unclosed block (e.g. `.foo { color: red`) still throws `Missing closing }`.
A leftover with unbalanced parentheses (e.g. `color: rgb(1, 2`) is not kept, because it is incomplete.
A test also covers a custom property with an unclosed bracket at the end of the input, e.g. `--foo: [bar`. #20653 makes the rest of the input part of the custom property. Without it, the leftover `-foo: [bar` would become a declaration with this PR.
A user can only reach the bare declaration case through an `@import` inside a rule, e.g. `:root { @import './partial.css'; }`, where the partial ends with a bare declaration. That is not valid CSS, but `substituteAtImports` inlines it, because it walks the whole AST. Thus the value of this fix is small, and the change stays small.
Related: #20653 (merged) fixed the same problem for custom properties. This PR is rebased on top of it.
## Test plan
- New tests in `packages/tailwindcss/src/css-parser.test.ts` (Unix and Windows line endings) for `color: red`, `color: red\n`, `color: red !important`, `a: 1; b: 2` and `--a: 1;\ncolor: red`. They fail without the fix.
- New tests for `color: rgb(1, 2` (gives `[]`) and for `--foo: [bar` and `color: red; --foo: (bar` (keep the custom property, together with #20653).
- `pnpm exec vitest run` in `packages/tailwindcss`: all tests pass.
- `pnpm changelog check` passes.; at the end of the CSS input (#20655)1 parent 4364cad commit cd5831f
3 files changed
Lines changed: 74 additions & 0 deletions
File tree
- .changelog
- packages/tailwindcss/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
183 | 219 | | |
184 | 220 | | |
185 | 221 | | |
| |||
482 | 518 | | |
483 | 519 | | |
484 | 520 | | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
485 | 531 | | |
486 | 532 | | |
487 | 533 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
597 | 597 | | |
598 | 598 | | |
599 | 599 | | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
600 | 625 | | |
601 | 626 | | |
602 | 627 | | |
| |||
0 commit comments