Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/parser/cssParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,10 +1283,10 @@ export class Parser {
if (this.accept(TokenType.ParenthesisL)) {
// scope-start selector can start with a combinator as it defaults to :scope
// Treat as nested
if (!node.setScopeStart(this._parseSelector(true))) {
if (!node.setScopeStart(this._parseScopeSelectorList())) {
return this.finish(node, ParseError.SelectorExpected, [], [TokenType.ParenthesisR])
}

if (!this.accept(TokenType.ParenthesisR)) {
return this.finish(node, ParseError.RightParenthesisExpected, [], [TokenType.CurlyL]);
}
Expand All @@ -1299,10 +1299,10 @@ export class Parser {
}
// 'to' selector can start with a combinator as it defaults to :scope
// Treat as nested
if (!node.setScopeEnd(this._parseSelector(true))) {
if (!node.setScopeEnd(this._parseScopeSelectorList())) {
return this.finish(node, ParseError.SelectorExpected, [], [TokenType.ParenthesisR])
}

if (!this.accept(TokenType.ParenthesisR)) {
return this.finish(node, ParseError.RightParenthesisExpected, [], [TokenType.CurlyL]);
}
Expand All @@ -1311,6 +1311,17 @@ export class Parser {
return this.finish(node)
}

private _parseScopeSelectorList(): nodes.Node | null {
const selectors = this.createNode(nodes.NodeType.SelectorList);
if (!selectors.addChild(this._parseSelector(true))) {
return null;
}
while (this.accept(TokenType.Comma) && selectors.addChild(this._parseSelector(true))) {
// loop
}
return this.finish(selectors);
}

public _parseMedium(): nodes.Node | null {
const node = this.create(nodes.Node);
if (node.addChild(this._parseIdent())) {
Expand Down
5 changes: 5 additions & 0 deletions src/test/css/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ suite('CSS - Parser', () => {
assertNode('@scope (.foo) {}', parser, parser._parseStylesheet.bind(parser))
assertNode('@scope to (.bar) {}', parser, parser._parseStylesheet.bind(parser))
assertNode('@scope (.foo) to (.bar) {}', parser, parser._parseStylesheet.bind(parser))
assertNode('@scope (.foo, .bar) {}', parser, parser._parseStylesheet.bind(parser))
assertNode('@scope (.foo, .bar) to (.baz, .qux) {}', parser, parser._parseStylesheet.bind(parser))
assertNode('@-ms-viewport { width: 320px; height: 768px; }', parser, parser._parseStylesheet.bind(parser));
assertNode('#boo, far {} \n.far boo {}', parser, parser._parseStylesheet.bind(parser));
assertNode('@-moz-keyframes darkWordHighlight { from { background-color: inherit; } to { background-color: rgba(83, 83, 83, 0.7); } }', parser, parser._parseStylesheet.bind(parser));
Expand Down Expand Up @@ -279,6 +281,9 @@ suite('CSS - Parser', () => {
assertNode('@scope to (.bar) { }', parser, parser._parseScope.bind(parser))
assertNode('@scope (.foo) to (.bar) { }', parser, parser._parseScope.bind(parser))
assertNode('@scope (#foo) to (:has(> link)) {}', parser, parser._parseScope.bind(parser))
assertNode('@scope (.foo, .bar) { }', parser, parser._parseScope.bind(parser))
assertNode('@scope to (.foo, .bar) { }', parser, parser._parseScope.bind(parser))
assertNode('@scope (.foo, .bar) to (.baz, .qux) { }', parser, parser._parseScope.bind(parser))

assertError('@scope ( { }', parser, parser._parseScope.bind(parser), ParseError.SelectorExpected)
assertError('@scope () { }', parser, parser._parseScope.bind(parser), ParseError.SelectorExpected)
Expand Down