GeezerVison is showing github.com — Terminate a custom property after a free semicolon before a comment by wahidrizka · Pull Request #2158 · postcss/postcss
Conversation
wahidrizka
commented
Sep 15, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
#2126 made the stringifier decide whether a declaration is a custom property from raws.before: it counts as one unless before ends with a non-space character, which excludes the */_ hack prefix. But the parser also puts free semicolons into before (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:
let root = postcss.parse('a{color:red;;--x:blue}')
root.first.append(new postcss.Comment({ text: 'note' }))
root.toString()
// 8.5.28: 'a{color:red;;--x:blue/* note */}' re-parses as decl, decl
// 8.5.26: 'a{color:red;;--x:blue;/* note */}' re-parses as decl, decl, comment
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 as color: red; --x: blue. So --x is a real custom property here, which is also what the parser decides from its first token.
A -- property now counts as a custom property when before ends 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
- Improved handling of custom properties when preceded by semicolons, whitespace, parser-generated prefixes, or stray tokens.
- Preserved correct formatting and parsing when comments follow custom property declarations.
-
Tests
- Added coverage for custom properties following free semicolons and preceding comments.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
coderabbitai
Bot
commented
Sep 15, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
 
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 29d92afd-1f3a-4208-9dd7-2a472ff3a065
📥 Commits
Reviewing files that changed from the base of the PR and between 5df8356 and f1caa72.
📒 Files selected for processing (2)
lib/stringifier.js
test/stringifier.test.js
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough
The stringifier now recognizes custom properties after whitespace or semicolons. A test verifies serialization and reparsing when a comment follows the property.
Changes
Custom Property Stringification
| Layer / File(s) |
Summary |
Custom property prefix handling and validation lib/stringifier.js, test/stringifier.test.js |
isCustomProperty accepts whitespace or semicolon prefixes before -- properties. The test verifies serialized output and reparsed node types. |
Priority: ⬇️ Low
Estimated code review effort: 1 (Trivial) | ~5 minutes
Change: Bug fix
Suggested reviewers: ai
Merge Risk: ⚪ Minimal · up to f1caa
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)
| Check name |
Status |
Explanation |
Resolution |
| Docstring Coverage |
⚠️ Warning |
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. |
Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name |
Status |
Explanation |
| 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. |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
✅ Passed |
The title clearly and specifically summarizes the main change: terminating a custom property before a following comment when a free semicolon precedes it. |
- Fix all pre-merge checks with AI
✨ 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.
❤️ Share
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
})
|
|
|
|
|
|
test('keeps property after a stray token before a comment unchanged', () => {
|
|
|
for (let css of ['a{: --x:red/*c*/}', 'a{] --x:red/*c*/}']) {
|
ai
Sep 15, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need some real proofs that in browser or any other good reference it will be red value and not --x:red/*c*/
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
wahidrizka
changed the title
Match the parser when deciding if a declaration is a custom property
Terminate a custom property after a free semicolon before a comment
Sep 18, 2026
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
metonym
added a commit
to metonym/caligula
that referenced
this pull request
Oct 11, 2026
…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.
metonym
added a commit
to metonym/caligula
that referenced
this pull request
Oct 12, 2026
…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.
metonym
added a commit
to metonym/caligula
that referenced
this pull request
Oct 12, 2026
…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.
Reviewers
ai
ai left review comments
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|