Skip to content

Accept !important in SCSS if() branches - #544

Merged
2 commits merged into
microsoft:mainfrom
diptomistry:fix-543-scss-if-important
Nov 23, 2026
Merged

2 commits merged into
microsoft:mainfrom
diptomistry:fix-543-scss-if-important

Conversation

@diptomistry

Copy link
Copy Markdown
Contributor

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); }. _parseIfBranch only parsed an expression, so !important was left for the outer declaration and validation reported ) expected, semi-colon expected, at-rule or selector expected, and Unknown 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 !important is accepted the same way. The condition is unchanged, so !important before the colon still fails.

Validation: npm test passes, 361 tests, 0 failures (359 before these tests).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

@aeschli Martin Aeschlimann (aeschli) closed this pull request by merging all changes into microsoft:main in 2ccc4fc Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCSS: if(sass(...): !important; else: ...) reports ') expected' and Unknown property: 'else'

2 participants