Skip to content

Commit

Permalink
problems parsing guard with two not (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli authored Jan 22, 2024
1 parent 4d5d95c commit 4af2900
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/parser/cssNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,6 @@ export class ListEntry extends Node {

export class LessGuard extends Node {

public isNegated?: boolean;
private conditions?: Nodelist;

public getConditions(): Nodelist {
Expand All @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions src/parser/lessParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,6 @@ export class LESSParser extends cssParser.Parser {
}
const node = <nodes.LessGuard>this.create(nodes.LessGuard);
this.consumeToken(); // when
node.isNegated = this.acceptIdent('not');

if (!node.getConditions().addChild(this._parseGuardCondition())) {
return <nodes.LessGuard>this.finish(node, ParseError.ConditionExpected);
Expand All @@ -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 (?)
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 @@ -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));
Expand Down

0 comments on commit 4af2900

Please sign in to comment.