Fix custom property losing its semicolon before a comment#2117
Merged
ai merged 1 commit intoJul 22, 2026
postcss:mainpostcss/postcss:mainfrom
sarathfrancis90:fix/custom-property-semicolon-before-commentsarathfrancis90/postcss:fix/custom-property-semicolon-before-commentCopy head branch name to clipboard
Merged
Fix custom property losing its semicolon before a comment#2117ai merged 1 commit intopostcss:mainpostcss/postcss:mainfrom sarathfrancis90:fix/custom-property-semicolon-before-commentsarathfrancis90/postcss:fix/custom-property-semicolon-before-commentCopy head branch name to clipboard
ai merged 1 commit into
postcss:mainpostcss/postcss:mainfrom
sarathfrancis90:fix/custom-property-semicolon-before-commentsarathfrancis90/postcss:fix/custom-property-semicolon-before-commentCopy head branch name to clipboard
Conversation
A custom property declaration that is the last non-comment child but is followed by comment siblings was stringified without its terminating semicolon. Unlike a normal declaration, a custom property keeps everything up to the next `;` or `}` as its value, so on re-parse the trailing comments were folded into the value and the comment nodes disappeared. Building such a tree with append()/insertAfter()/after() therefore silently dropped the comments. Emit the semicolon when a custom property still has following siblings so the output round-trips, mirroring the existing handling for childless at-rules.
Member
|
Released in 8.5.22. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Mutating a rule so that a custom property declaration is immediately followed by a comment node, then stringifying, produces CSS that loses the comment on re-parse:
The stringifier skips trailing comment siblings when deciding whether the last real child needs a terminating
;. That is fine for normal declarations, because the parser tokenizes a following/*as a separate comment. But a custom property keeps everything up to the next;or}as its value, so without the semicolon the comment is folded into the value and the comment node disappears. The same class of bug was fixed for childless at-rules in #2115; this is the declaration counterpart.The fix emits the semicolon when a custom property still has following siblings, right next to the existing at-rule check in
pushBody. Naturally parsed CSS is unaffected: a custom property can only be followed by a separate comment sibling if the source already had a;there (otherwise the comment is part of the value), and that case already setsraws.semicolon.Tested with two new cases in
test/stringifier.test.jscoveringappend()andafter(), both asserting the output and that it re-parses back todecl,comment. Fullpnpm test(unit, lint, types, integration, size) is green.