fix(scss): don't treat !default/!global inside strings as flags#19245
Closed
xfocus3 wants to merge 3 commits into
Closed
fix(scss): don't treat !default/!global inside strings as flags#19245xfocus3 wants to merge 3 commits into
!default/!global inside strings as flags#19245xfocus3 wants to merge 3 commits into
Conversation
`!default` and `!global` were detected with a regex that matched the raw text anywhere in the value, so values containing those substrings inside a string or function argument (e.g. `$a: "!default"`) were incorrectly split as if they had a trailing declaration flag, injecting a stray space. Detect the flag structurally instead: it is only a real flag when it parses as the final top-level `value-word`. Falls back to the previous regex when the value cannot be parsed. Closes prettier#19203
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
fisker
reviewed
May 31, 2026
| @@ -22,6 +22,77 @@ import isSCSSNestedPropertyNode from "./utilities/is-scss-nested-property-node.j | |||
| const DEFAULT_SCSS_DIRECTIVE = /(\s*)(!default).*$/; | |||
Member
There was a problem hiding this comment.
Can we update this pattern to only match /(\s*)(!default)\s?$/; instead?
6 tasks
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.
Description
Closes #19203.
When
!defaultor!globalappeared inside a string or function argument in SCSS, Prettier treated it as a Sass declaration flag and split it off the value, injecting a stray space:Cause
The flag was detected with
value.match(/(\s*)(!default).*$/), which matches the raw!default/!globaltext anywhere in the value — including inside strings andurl(...)/ function arguments — and then sliced everything after it off the value.Fix
Detect the directive structurally. A genuine trailing flag parses as the final top-level
value-wordnode whose value is exactly!default/!global(optionally followed only by comments). Text inside a string parses as avalue-string, and text inside a function parses as avalue-func, so those are correctly left untouched. The comma-separated case (where the flag lives in the last comma item) is handled too. If the value can't be parsed structurally, it falls back to the original regex so existing behavior is preserved.Checklist
tests/format/scss/flag/19203.scss) covering in-string, function-argument, and mixed string-plus-genuine-flag cases.yarn jest tests/format/scss tests/format/css tests/format/lesspasses (358/358).yarn eslint src/language-css/parser-postcss.jspasses.yarn lint:prettierpasses.