Skip to content

Commit 4af2900

Browse files
authored
problems parsing guard with two not (#376)
1 parent 4d5d95c commit 4af2900

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/parser/cssNodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,6 @@ export class ListEntry extends Node {
17951795

17961796
export class LessGuard extends Node {
17971797

1798-
public isNegated?: boolean;
17991798
private conditions?: Nodelist;
18001799

18011800
public getConditions(): Nodelist {
@@ -1808,6 +1807,7 @@ export class LessGuard extends Node {
18081807

18091808
export class GuardCondition extends Node {
18101809

1810+
public isNegated?: boolean;
18111811
public variable?: Node;
18121812
public isEquals?: boolean;
18131813
public isGreater?: boolean;

src/parser/lessParser.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,6 @@ export class LESSParser extends cssParser.Parser {
730730
}
731731
const node = <nodes.LessGuard>this.create(nodes.LessGuard);
732732
this.consumeToken(); // when
733-
node.isNegated = this.acceptIdent('not');
734733

735734
if (!node.getConditions().addChild(this._parseGuardCondition())) {
736735
return <nodes.LessGuard>this.finish(node, ParseError.ConditionExpected);
@@ -745,12 +744,14 @@ export class LESSParser extends cssParser.Parser {
745744
}
746745

747746
public _parseGuardCondition(): nodes.Node | null {
748-
749-
if (!this.peek(TokenType.ParenthesisL)) {
747+
const node = this.create(nodes.GuardCondition);
748+
node.isNegated = this.acceptIdent('not');
749+
if (!this.accept(TokenType.ParenthesisL)) {
750+
if (node.isNegated) {
751+
return this.finish(node, ParseError.LeftParenthesisExpected);
752+
}
750753
return null;
751754
}
752-
const node = this.create(nodes.GuardCondition);
753-
this.consumeToken(); // ParenthesisL
754755

755756
if (!node.addChild(this._parseExpr())) {
756757
// empty (?)

src/test/less/parser.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ suite('LESS - Parser', () => {
313313

314314
test('CSS Guards', function () {
315315
const parser = new LESSParser();
316+
assertNode('.selector when not ( @testCondition = 2) and not ( @testCondition = 3 ) { }', parser, parser._parseStylesheet.bind(parser));
316317
assertNode('button when (@my-option = true) { color: white; }', parser, parser._parseStylesheet.bind(parser));
317318
assertNode('.something .other when (@my-option = true) { color: white; }', parser, parser._parseStylesheet.bind(parser));
318319
assertNode('& when (@my-option = true) { button { color: white; } }', parser, parser._parseStylesheet.bind(parser));

0 commit comments

Comments
 (0)