Skip to content
Open
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
27 changes: 25 additions & 2 deletions src/parser/cssParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1472,21 +1472,35 @@ export class Parser {
const node = this.create(nodes.Container);
this.consumeToken(); // @container

node.addChild(this._parseIdent()); // optional container name
node.addChild(this._parseContainerName()); // optional container name
if (node.addChild(this._parseContainerQuery())) {
while (this.accept(TokenType.Comma)) {
if (this.peek(TokenType.CurlyL)) {
break;
}

node.addChild(this._parseIdent()); // optional container name
node.addChild(this._parseContainerName()); // optional container name
node.addChild(this._parseContainerQuery());
}
}

return this._parseBody(node, this._parseContainerDeclaration.bind(this, isNested));
}

public _parseContainerName(): nodes.Node | null {
if (this.peekIdent('style') || this.peekIdent('scroll-state')) {
const mark = this.mark();
this.consumeToken();
if (!this.hasWhitespace() && this.peek(TokenType.ParenthesisL)) {
this.restoreAtMark(mark);
return null;
}
this.restoreAtMark(mark);
}

return this._parseIdent();
}

public _parseContainerQuery(): nodes.Node | null {
// <container-query> = not <query-in-parens>
// | <query-in-parens> [ [ and <query-in-parens> ]* | [ or <query-in-parens> ]* ]
Expand All @@ -1512,6 +1526,7 @@ export class Parser {
// <query-in-parens> = ( <container-query> )
// | ( <size-feature> )
// | style( <style-query> )
// | scroll-state( <scroll-state-query> )
// | <general-enclosed>
const node = this.create(nodes.Node);
if (this.accept(TokenType.ParenthesisL)) {
Expand All @@ -1531,6 +1546,14 @@ export class Parser {
if (!this.accept(TokenType.ParenthesisR)) {
return this.finish(node, ParseError.RightParenthesisExpected, [], [TokenType.CurlyL]);
}
} else if (this.acceptIdent('scroll-state')) {
if (this.hasWhitespace() || !this.accept(TokenType.ParenthesisL)) {
return this.finish(node, ParseError.LeftParenthesisExpected, [], [TokenType.CurlyL]);
}
node.addChild(this._parseDeclaration([TokenType.ParenthesisR], true));
if (!this.accept(TokenType.ParenthesisR)) {
return this.finish(node, ParseError.RightParenthesisExpected, [], [TokenType.CurlyL]);
}
} else {
if (optional) {
return null;
Expand Down
4 changes: 4 additions & 0 deletions src/test/css/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ suite('CSS - Parser', () => {
assertNode(`@container card (inline-size > 30em), style(--responsive: true) { }`, parser, parser._parseStylesheet.bind(parser));
assertNode(`@container card (inline-size > 30em), summary style(--responsive: true) { }`, parser, parser._parseStylesheet.bind(parser));
assertNode(`@container card (inline-size > 30em) { @container style(--responsive: true) {} }`, parser, parser._parseStylesheet.bind(parser));
assertNode(`@media (pointer: fine) and (hover: hover) { @container my-container scroll-state(scrollable: y) { #my-list { padding-inline-end: calc(var(--spacing) * 2); } } }`, parser, parser._parseStylesheet.bind(parser));
assertNode(`@container scroll-state(scrollable: y) { }`, parser, parser._parseStylesheet.bind(parser));
assertNode(`@container my-container scroll-state(scrollable: y) and style(--responsive: true) { }`, parser, parser._parseStylesheet.bind(parser));
assertNode(`@container card (inline-size > 30em), my-container scroll-state(stuck: top) { }`, parser, parser._parseStylesheet.bind(parser));
});

test('@starting-style', function () {
Expand Down
1 change: 1 addition & 0 deletions src/test/less/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,6 @@ suite('LESS - Parser', () => {
const parser = new LESSParser();
assertNode(`.item-icon { @container (max-height: 100px) { .item-icon { display: none; } } }`, parser, parser._parseStylesheet.bind(parser));
assertNode(`:root { @container (max-height: 100px) { display: none;} }`, parser, parser._parseStylesheet.bind(parser));
assertNode(`@container my-container scroll-state(scrollable: y) { .item-icon { display: none; } }`, parser, parser._parseStylesheet.bind(parser));
});
});
1 change: 1 addition & 0 deletions src/test/scss/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ suite('SCSS - Parser', () => {
assertNode(`@container (min-width: #{$minWidth}) { .scss-interpolation { line-height: 10cqh; } }`, parser, parser._parseStylesheet.bind(parser));
assertNode(`.item-icon { @container (max-height: 100px) { .item-icon { display: none; } } }`, parser, parser._parseStylesheet.bind(parser));
assertNode(`:root { @container (max-height: 100px) { display: none;} }`, parser, parser._parseStylesheet.bind(parser));
assertNode(`@container my-container scroll-state(scrollable: y) { .item-icon { display: none; } }`, parser, parser._parseStylesheet.bind(parser));
});

test('@use', function () {
Expand Down