Skip to content

Commit e20f006

Browse files
authored
support nested @container (#390)
Close support nested @container #389
1 parent 958ae37 commit e20f006

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

src/parser/cssParser.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export class Parser {
325325
|| this._parseViewPort()
326326
|| this._parseNamespace()
327327
|| this._parseDocument()
328-
|| this._parseContainer()
328+
|| this._parseContainer(isNested)
329329
|| this._parseUnknownAtRule();
330330
}
331331

@@ -365,6 +365,7 @@ export class Parser {
365365
return this._parseMedia(true)
366366
|| this._parseSupports(true)
367367
|| this._parseLayer(true)
368+
|| this._parseContainer(true)
368369
|| this._parseUnknownAtRule();
369370
}
370371

@@ -1296,8 +1297,15 @@ export class Parser {
12961297
this.resync([], [TokenType.CurlyL]); // ignore all the rules
12971298
return this._parseBody(node, this._parseStylesheetStatement.bind(this));
12981299
}
1300+
public _parseContainerDeclaration(isNested = false): nodes.Node | null {
1301+
if (isNested) {
1302+
// if nested, the body can contain rulesets, but also declarations
1303+
return this._tryParseRuleset(true) || this._tryToParseDeclaration() || this._parseStylesheetStatement(true);
1304+
}
1305+
return this._parseStylesheetStatement(false);
1306+
}
12991307

1300-
public _parseContainer(): nodes.Node | null {
1308+
public _parseContainer(isNested: boolean = false): nodes.Node | null {
13011309
if (!this.peekKeyword('@container')) {
13021310
return null;
13031311
}
@@ -1307,7 +1315,7 @@ export class Parser {
13071315
node.addChild(this._parseIdent()); // optional container name
13081316
node.addChild(this._parseContainerQuery());
13091317

1310-
return this._parseBody(node, this._parseStylesheetStatement.bind(this));
1318+
return this._parseBody(node, this._parseContainerDeclaration.bind(this, isNested));
13111319
}
13121320

13131321
public _parseContainerQuery(): nodes.Node | null {

src/parser/lessParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export class LESSParser extends cssParser.Parser {
320320
|| this._parseSupports(true) // @supports
321321
|| this._parseLayer() // @layer
322322
|| this._parsePropertyAtRule() // @property
323-
|| this._parseContainer() // @container
323+
|| this._parseContainer(true) // @container
324324
|| this._parseDetachedRuleSetMixin() // less detached ruleset mixin
325325
|| this._parseVariableDeclaration() // Variable declarations
326326
|| this._parseRuleSetDeclarationAtStatement();

src/parser/scssParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export class SCSSParser extends cssParser.Parser {
256256
|| this._parseSupports(true) // @supports
257257
|| this._parseLayer() // @layer
258258
|| this._parsePropertyAtRule() // @property
259-
|| this._parseContainer() // @container
259+
|| this._parseContainer(true) // nested @container
260260
|| this._parseRuleSetDeclarationAtStatement();
261261
}
262262
return this._parseVariableDeclaration() // variable declaration

src/test/less/parser.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,6 @@ suite('LESS - Parser', () => {
352352
test('@container', function () {
353353
const parser = new LESSParser();
354354
assertNode(`.item-icon { @container (max-height: 100px) { .item-icon { display: none; } } }`, parser, parser._parseStylesheet.bind(parser));
355+
assertNode(`:root { @container (max-height: 100px) { display: none;} }`,parser,parser._parseStylesheet.bind(parser));
355356
});
356357
});

src/test/scss/parser.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ suite('SCSS - Parser', () => {
292292
const parser = new SCSSParser();
293293
assertNode(`@container (min-width: #{$minWidth}) { .scss-interpolation { line-height: 10cqh; } }`, parser, parser._parseStylesheet.bind(parser));
294294
assertNode(`.item-icon { @container (max-height: 100px) { .item-icon { display: none; } } }`, parser, parser._parseStylesheet.bind(parser));
295+
assertNode(`:root { @container (max-height: 100px) { display: none;} }`,parser,parser._parseStylesheet.bind(parser));
295296
});
296297

297298
test('@use', function () {

0 commit comments

Comments
 (0)