From 8a2372aa95a8234a8c14b926b1b81fad51dea45f Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Fri, 8 Dec 2023 14:19:54 +0100 Subject: [PATCH] problems parsing guard with two not --- src/parser/cssNodes.ts | 2 +- src/parser/lessParser.ts | 11 ++++++----- src/test/less/parser.test.ts | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/parser/cssNodes.ts b/src/parser/cssNodes.ts index 7bc09a3f..f7e6a9da 100644 --- a/src/parser/cssNodes.ts +++ b/src/parser/cssNodes.ts @@ -1795,7 +1795,6 @@ export class ListEntry extends Node { export class LessGuard extends Node { - public isNegated?: boolean; private conditions?: Nodelist; public getConditions(): Nodelist { @@ -1808,6 +1807,7 @@ export class LessGuard extends Node { export class GuardCondition extends Node { + public isNegated?: boolean; public variable?: Node; public isEquals?: boolean; public isGreater?: boolean; diff --git a/src/parser/lessParser.ts b/src/parser/lessParser.ts index 8d34c4c2..a95ca2bc 100644 --- a/src/parser/lessParser.ts +++ b/src/parser/lessParser.ts @@ -730,7 +730,6 @@ export class LESSParser extends cssParser.Parser { } const node = this.create(nodes.LessGuard); this.consumeToken(); // when - node.isNegated = this.acceptIdent('not'); if (!node.getConditions().addChild(this._parseGuardCondition())) { return this.finish(node, ParseError.ConditionExpected); @@ -745,12 +744,14 @@ export class LESSParser extends cssParser.Parser { } public _parseGuardCondition(): nodes.Node | null { - - if (!this.peek(TokenType.ParenthesisL)) { + const node = this.create(nodes.GuardCondition); + node.isNegated = this.acceptIdent('not'); + if (!this.accept(TokenType.ParenthesisL)) { + if (node.isNegated) { + return this.finish(node, ParseError.LeftParenthesisExpected); + } return null; } - const node = this.create(nodes.GuardCondition); - this.consumeToken(); // ParenthesisL if (!node.addChild(this._parseExpr())) { // empty (?) diff --git a/src/test/less/parser.test.ts b/src/test/less/parser.test.ts index dd8f1ba5..516a632c 100644 --- a/src/test/less/parser.test.ts +++ b/src/test/less/parser.test.ts @@ -313,6 +313,7 @@ suite('LESS - Parser', () => { test('CSS Guards', function () { const parser = new LESSParser(); + assertNode('.selector when not ( @testCondition = 2) and not ( @testCondition = 3 ) { }', parser, parser._parseStylesheet.bind(parser)); assertNode('button when (@my-option = true) { color: white; }', parser, parser._parseStylesheet.bind(parser)); assertNode('.something .other when (@my-option = true) { color: white; }', parser, parser._parseStylesheet.bind(parser)); assertNode('& when (@my-option = true) { button { color: white; } }', parser, parser._parseStylesheet.bind(parser));