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 — Do not terminate a hack-prefixed property before a comment by Jaybhade · Pull Request #2126 · postcss/postcss

Conversation

@Jaybhade

@Jaybhade Jaybhade commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

PostCSS aims for byte-to-byte equal output, but since 8.5.22 the stringifier invents a semicolon in a declaration list:

postcss.parse('a{*--x:red/*c*/}').toString()
// => 'a{*--x:red;/*c*/}'   (8.5.21 and earlier: unchanged)

_--x behaves the same. The output stays valid CSS and re-parses to the same AST, so nothing breaks downstream — but a tool that only means to touch what it edits now emits an unrelated ;.

Why

The parser decides whether a declaration is a custom property from the first token of the declaration:

let customProperty = start[1].startsWith('--')   // lib/parser.js, other()

#2117 re-derived that decision in the stringifier from prop:

child.type === 'decl' && child.prop.startsWith('--')

Those two agree almost always, but decl() strips the */_ hack prefix out of prop and into raws.before after the parser has made its choice:

if (node.prop[0] === '_' || node.prop[0] === '*') {
  node.raws.before += node.prop[0]
  node.prop = node.prop.slice(1)
}

So *--x:red is parsed as a normal declaration — its value stops at the first comment, and the comment is already a separate node — while the stringifier sees prop === '--x' and terminates it. The semicolon #2117 adds is there to stop a custom property's value from swallowing a following comment; here there is nothing to protect, because *--x:red will not re-parse as a custom property either. The same mismatch happens whenever anything but spaces precedes the property, since decl() collects those tokens into before too (a{'s'--x:1/*c*/}).

Fix

Check before alongside prop, so the stringifier asks the same question the parser did — will this re-parse as a custom property? — and terminates only the declarations that need it.

Tests

  • keeps hack-prefixed property before a comment unchanged — *--x / _--x round-trip byte-for-byte, and still re-parse to decl,comment.
  • terminates indented custom property followed by a comment — a whitespace-only before is still a custom property and still gets its semicolon, so the narrowing can't be over-read as before === ''.

The two tests from #2115/#2117 pass unchanged. pnpm unit is 683/683, types and size-limit pass, and lint is clean apart from the pre-existing RootExit sort warning on main.

I also re-ran a round-trip check over ~320k generated stylesheets (parse(css).toString() === css, plus AST-shape stability across a re-parse) at both root level and nested in a rule/at-rule: every failure it reported was this one cause, and after the change it reports none.

Sorry, something went wrong.

Uh oh!

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

All reactions
@Jaybhade
Do not terminate a hack-prefixed property before a comment
b4f3ff6
A declaration is read as a custom property when the *first token* of the
declaration starts with `--`, but the stringifier decided it from `prop`.
The `*`/`_` hack prefix is moved out of `prop` into `raws.before` after that
decision, so for `*--x:red` the parser builds a normal declaration -- whose
value stops at the first comment -- while the stringifier saw a custom
property and terminated it:

  postcss.parse('a{*--x:red/*c*/}').toString()
  // => 'a{*--x:red;/*c*/}', semicolon invented

The same applies to any declaration with something other than spaces in
`before`. Check `before` alongside `prop` so the two stay in sync: only a
declaration that will re-parse as a custom property can swallow a following
comment, and only that one needs the semicolon.
ai
ai reviewed Aug 5, 2026
View reviewed changes
Comment thread lib/stringifier.js Outdated
// is moved from `prop` into `before` after that decision, so `*--x` is a normal
// declaration that stops at the first comment. Re-checking `before` here keeps
// this in sync: with anything but spaces in front of the property, the output
// will not re-parse as a custom property and needs no terminating semicolon.

@ai ai Aug 5, 2026

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.

Nice hack. Just ask LLM to be very minimalistic in comment.

Nowadays be smart is mean use less words.

Sorry, something went wrong.

Uh oh!

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

Jaybhade reacted with laugh emoji Jaybhade reacted with heart emoji
All reactions
  • 😄 1 reaction
  • ❤️ 1 reaction

@Jaybhade Jaybhade Aug 6, 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.

Cut to two lines in dcec52b.

Sorry, something went wrong.

Uh oh!

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

All reactions
@jayesh-keychain
Shorten the comment
dcec52b
@ai
ai merged commit 8f37847 into postcss:main Aug 6, 2026
10 checks passed

Uh oh!

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

@ai

ai commented Aug 6, 2026

Copy link
Copy Markdown
Member

Thanks

Jaybhade reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

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

@wahidrizka wahidrizka mentioned this pull request Sep 15, 2026
Terminate a custom property after a free semicolon before a comment #2158
Merged
wahidrizka added a commit to wahidrizka/postcss that referenced this pull request Sep 18, 2026
@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.
ai pushed a commit that referenced this pull request Sep 18, 2026
@wahidrizka
Terminate a custom property after a free semicolon before a comment (#…
a295dd0
…2158)

* Match the parser when deciding if a declaration is a custom property

isCustomProperty() from #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.

* Only count free semicolons as spaces in a custom property's before

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 #2126: a free semicolon at the end of before no longer stops a
custom property from being terminated before a following comment.
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.

3 participants

@Jaybhade @ai @jayesh-keychain
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.