[scss] Support bracketed lists - #507
Open
Rusty Raven (kakiuwang-ui) wants to merge 2 commits into
Open
Conversation
Sass bracketed lists (`[a, b]`) are a superset of the CSS named-line syntax: the brackets may hold any space or comma separated list of values, not just a sequence of identifiers. The parser only accepted the CSS form, so valid Sass was reported as a syntax error. Fixes microsoft#231 Fixes microsoft#399
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.
Fixes #231
Fixes #399
Problem
Sass bracketed lists are reported as syntax errors:
The only production that accepts
[in a value position is_parseNamedLine, which implements the CSS named-line syntax and therefore only accepts a bare sequence of identifiers. That happens to cover[a b c], so space-separated lists of idents already worked — but anything else (commas, numbers, strings, variables, interpolation, function calls, nesting) fell through and produced a cascade of errors.Fix
Override
_parseNamedLineinSCSSParserso the brackets hold a full expression. A Sass bracketed list is a superset of the CSS named-line syntax, so the one production covers both; CSS and LESS are untouched.Now parsing cleanly
Still reported as errors:
And the CSS named-line syntax keeps working in both CSS and SCSS:
Testing
npm run test— 712 passing, 0 failing (710 before, plus the new cases).New tests in
src/test/scss/parser.test.ts: aBracketed listblock covering the forms above plus theRightSquareBracketExpectederror case, aBracketed list in a stylesheetblock covering the end-to-end usages from both issues, and two cases added toVariableDeclaration.