GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@wahidrizka wahidrizka commented Sep 15, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

#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.

All reactions
@wahidrizka
Match the parser when deciding if a declaration is a custom property
5df8356
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

coderabbitai Bot commented Sep 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Review Change StackReview Change Stack

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)
  • test/stringifier.test.js

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)
  • Create a new PR

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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ai
ai reviewed Sep 15, 2026
View reviewed changes
Comment thread test/stringifier.test.js Outdated
})

test('keeps property after a stray token before a comment unchanged', () => {
for (let css of ['a{: --x:red/*c*/}', 'a{] --x:red/*c*/}']) {

@ai ai Sep 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

All reactions

@wahidrizka wahidrizka Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

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.

All reactions
@wahidrizka
Only count free semicolons as spaces in a custom property's before
f1caa72
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 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
@ai
ai merged commit a295dd0 into postcss:main Sep 18, 2026
11 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@ai

ai commented Sep 18, 2026

Copy link
Copy Markdown
Member

Thanks

All reactions

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
@metonym
fix: terminate a custom property after a stray semicolon, as postcss …
5570c00
…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
@metonym
fix: terminate a custom property after a stray semicolon, as postcss …
8c8a509
…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
@metonym
fix: terminate a custom property after a stray semicolon, as postcss …
3637858
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ai ai ai left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

2 participants

@wahidrizka @ai
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.