Repository navigation
Accept !important in SCSS if() branches - #544
2 commits merged into
Conversation
Martin Aeschlimann (aeschli)
left a comment
There was a problem hiding this comment.
Keep Sass-only branch values out of the shared CSS parser
The fix addresses a real Sass parsing problem, but adding _parsePrio() / _tryParsePrio() to the base _parseIfBranch() also changes plain CSS validation.
Reproduced with the CSS language service:
a { color: if(style(--x: yes): red !important; else: blue); }The existing parser reports errors and the browser rejects this value; this PR returns no diagnostics. The equivalent branch without !important is accepted by the browser.
Please keep the additional Sass branch-value handling in SCSSParser, via an override or narrowly scoped extension hook, following the existing SCSS _parseIfTest() override. Add paired regressions: the Sass example remains accepted, while invalid plain-CSS branches containing !important remain rejected. The current new tests cover only SCSS.
Reviewed commit: 7f85510. Location: src/parser/cssParser.ts, _parseIfBranch().
2ccc4fc
Fixes #543.
The SCSS parser rejected a Sass special
if()when a branch value was!important, as in.a { color: if(sass($e): !important; else: null); }._parseIfBranchonly parsed an expression, so!importantwas left for the outer declaration and validation reported) expected,semi-colon expected,at-rule or selector expected, andUnknown property: 'else'.After the branch colon, the parser now follows the existing function-argument path: parse an expression and then
_parsePrio(), or_tryParsePrio()when the branch is only!important. An expression followed by!importantis accepted the same way. The condition is unchanged, so!importantbefore the colon still fails.Validation:
npm testpasses, 361 tests, 0 failures (359 before these tests).