Repository navigation
Terminate a custom property after a free semicolon before a comment - #2158
Conversation
isCustomProperty() from postcss#2126 counts a declaration as a custom property unless raws.before ends with a non-space character. The parser also puts free semicolons and tokens like `:` in front of the name into before, so the check fails both ways: after `;;` a custom property is no longer terminated and an appended comment is lost on re-parse (8.5.26 kept it), and `a{: --x:red/*c*/}` gains a semicolon.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe stringifier now recognizes custom properties after whitespace or semicolons. A test verifies serialization and reparsing when a comment follows the property. ChangesCustom Property Stringification
Priority: ⬇️ Low Estimated code review effort: 1 (Trivial) | ~5 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change addresses the reported custom-property round-trip case without an established remaining production risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
| }) | ||
|
|
||
| test('keeps property after a stray token before a comment unchanged', () => { | ||
| for (let css of ['a{: --x:red/*c*/}', 'a{] --x:red/*c*/}']) { |
There was a problem hiding this comment.
I need some real proofs that in browser or any other good reference it will be red value and not --x:red/*c*/
There was a problem hiding this comment.
You are right to ask. A browser does not read that input as a declaration at all. CSS Syntax 3 only consumes a declaration when it starts with an ident; otherwise it is dropped as a bad declaration. In Chrome 152 (Edge 153 gives the same), the rules .t1{: --x:red/*c*/} and .t2{] --x:red/*c*/} end up with no declarations (cssText is .t1 { }), while .t3{--x:red/*c*/} gives --x: red.
So there is no reference for how that input should print. I removed this test and narrowed the change: only a semicolon at the end of before is now treated like a space, so input like this prints as it does on main.
What is left is the double-semicolon case, which is valid CSS: Chrome reads .t4{color:red;;--x:blue} as color: red; --x: blue, and 8.5.26 kept a comment appended after that --x. I updated the title and description to match.
Browsers drop a declaration that does not start with a name, so there
is no reference for how input like `a{: --x:red/*c*/}` should print.
Leave that as it is on main and keep only the fix for the regression
from postcss#2126: a free semicolon at the end of before no longer stops a
custom property from being terminated before a following comment.
|
Thanks |
…8.5.29 does PostCSS 8.5.29 (postcss/postcss#2158) counts a stray `;` in a custom property's leading raws as whitespace, so `.a{;--x:y;/**/}` keeps the `;` after the custom property once the rule after the comment is removed. Match it and drop the D_AFTER_SEMI flag that tracked the old behavior.
…8.5.29 does PostCSS 8.5.29 (postcss/postcss#2158) counts a stray `;` in a custom property's leading raws as whitespace, so `.a{;--x:y;/**/}` keeps the `;` after the custom property once the rule after the comment is removed. Match it and drop the D_AFTER_SEMI flag that tracked the old behavior.
…8.5.29 does PostCSS 8.5.29 (postcss/postcss#2158) counts a stray `;` in a custom property's leading raws as whitespace, so `.a{;--x:y;/**/}` keeps the `;` after the custom property once the rule after the comment is removed. Match it and drop the D_AFTER_SEMI flag that tracked the old behavior.
#2126 made the stringifier decide whether a declaration is a custom property from
raws.before: it counts as one unlessbeforeends with a non-space character, which excludes the*/_hack prefix. But the parser also puts free semicolons intobefore(Parser#freeSemicolon), so a custom property after a double semicolon is no longer terminated before a following comment, and the comment is lost when the output is parsed again. This worked in 8.5.26:a{color:red;;--x:blue}is valid CSS: CSS Syntax 3 discards a lone;inside a block (consume a block's contents), and Chrome 152 reads the rule ascolor: red; --x: blue. So--xis a real custom property here, which is also what the parser decides from its first token.A
--property now counts as a custom property whenbeforeends with a space or a semicolon. The hack-prefix test from #2126 still passes, and the new test fails without the change. The unit tests (702) and ESLint pass, and line coverage stays at 100%.Summary by CodeRabbit
Bug Fixes
Tests