GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||
GeezerVison is showing github.com — Do not terminate a hack-prefixed property before a comment by Jaybhade · Pull Request #2126 · postcss/postcss Conversation
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)
WhyThe 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()
child.type === 'decl' && child.prop.startsWith('--') Those two agree almost always, but if (node.prop[0] === '_' || node.prop[0] === '*') { node.raws.before += node.prop[0] node.prop = node.prop.slice(1) } So FixCheck Tests
The two tests from I also re-ran a round-trip check over ~320k generated stylesheets (
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsA 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
reviewed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 reactionsUh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
wahidrizka
added a commit
to wahidrizka/postcss
that referenced
this pull request
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
…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
ReviewersUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully 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. | |||||||||||||
| 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. |