Don't treat SCSS !default/!global inside strings as flags#19404
Don't treat SCSS !default/!global inside strings as flags#19404patrickwehbe wants to merge 4 commits into
!default/!global inside strings as flags#19404Conversation
The directive regexes matched `!default`/`!global` anywhere in a declaration value via `.*$`, so the text was picked up as a Sass flag even when it appeared inside a string, `url(...)`, or another function argument. The matched part was then sliced off the value, injecting a stray space (e.g. `$a: "!default"` became `$a: " !default"`). Tighten the patterns so a flag is only recognized when it sits at the end of the value, optionally followed by block comments. Text inside a string or function no longer matches, while genuine trailing flags (including a flag after a quoted value, and a flag followed by a comment) keep working. Fixes 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. |
| $k: "!default" !default; | ||
| $l: "!global" !global; | ||
| $m: map-get($map, "!default") !default; | ||
| $n: map-get($map, "!global") !global; |
There was a problem hiding this comment.
Can you add some tests for cases that have comments after !default/!global?
|
Added cases for a genuine flag followed by single, multiple, and multiline block comments, plus one combined with the flag text inside a string. Snapshot regenerated and FULL_TEST passes. |
|
SCSS also allow single line comments |
|
Added single-line comment cases too. postcss-scss keeps a trailing |
|
Description
Fixes #19203.
!defaultand!globalinside a string or function argument were treated as Sass declaration flags. The flag text was sliced off the value, which injected a stray space:Cause
The directives were detected with
/(\s*)(!default).*$/and/(\s*)(!global).*$/. The.*$matches the flag text anywhere in the value, including inside strings andurl(...)/ function arguments, after which everything from the match onward is sliced off.Fix
In #19245 fisker suggested tightening the pattern to
/(\s*)(!default)\s?$/so it only matches a trailing flag. That is the right direction, but it drops the existing support for a flag followed by a comment, e.g.green !global /* note */, which has a snapshot intests/format/scss/comments/variable-declaration.scss.So the patterns now match the flag only when it sits at the end of the value, optionally followed by block comments:
Flag text inside a string or function no longer matches, while genuine trailing flags keep working, including a flag after a quoted value (
$d: "!default" !default;) and a flag followed by a comment.Tests
Added
tests/format/scss/flag/19203.scsscovering the in-string,url(...), and function-argument cases, plus mixed cases where a string value is followed by a real trailing flag. The existingflagandcommentssnapshots are unchanged, so genuine flags and flag-with-comment behavior are preserved.Checklist
docs/directory).changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.