Skip to content

Commit

Permalink
Merge pull request #2779 from SomMeri/master
Browse files Browse the repository at this point in the history
Logical operator and now has higher precedence then logical operator or.
  • Loading branch information
SomMeri committed Jan 17, 2016
2 parents 4ce7914 + 8cc6ea8 commit 71e4bbc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
29 changes: 25 additions & 4 deletions lib/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1619,21 +1619,42 @@ var Parser = function Parser(context, imports, fileInfo) {
}
},
condition: function () {
var result, logical, next;
function or() {
return parserInput.$str("or");
}

result = this.conditionAnd(this);
if (!result) {
return ;
}
logical = or();
if (logical) {
next = this.condition();
if (next) {
result = new(tree.Condition)(logical, result, next);
} else {
return ;
}
}
return result;
},
conditionAnd: function () {
var result, logical, next;
function insideCondition(me) {
return me.negatedCondition() || me.parenthesisCondition();
}
function logicalOperator() {
return parserInput.$str("and") || parserInput.$str("or");
function and() {
return parserInput.$str("and");
}

result = insideCondition(this);
if (!result) {
return ;
}
logical = logicalOperator();
logical = and();
if (logical) {
next = this.condition();
next = this.conditionAnd();
if (next) {
result = new(tree.Condition)(logical, result, next);
} else {
Expand Down
18 changes: 15 additions & 3 deletions test/css/mixins-guards.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,27 @@
parenthesisNot: negated once middle;
}
#orderOfEvaluation-false-false-true {
no-parenthesis: evaluated true 1a;
no-parenthesis: evaluated true 1b;
no-parenthesis: evaluated true 1d;
no-parenthesis: evaluated true 3;
no-parenthesis: evaluated true 4;
with-parenthesis: evaluated true;
}
#orderOfEvaluation-false-false-false {
orderOfEvaluation: evaluated false;
no-parenthesis: evaluated true 2a;
no-parenthesis: evaluated true 2b;
no-parenthesis: evaluated true 2c;
}
#orderOfEvaluation-true-true-false {
no-parenthesis: evaluated true 1;
no-parenthesis: evaluated true 2;
no-parenthesis: evaluated true 1a;
no-parenthesis: evaluated true 1b;
no-parenthesis: evaluated true 1c;
no-parenthesis: evaluated true 1d;
no-parenthesis: evaluated true 1e;
no-parenthesis: evaluated true 2a;
no-parenthesis: evaluated true 2b;
no-parenthesis: evaluated true 2c;
no-parenthesis: evaluated true 4;
with-parenthesis: evaluated true;
}
22 changes: 20 additions & 2 deletions test/less/mixins-guards.less
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,28 @@
}

.orderOfEvaluation(@a1, @a2, @a3) when ((@a1) and (@a2) or (@a3)) {
no-parenthesis: evaluated true 1;
no-parenthesis: evaluated true 1a;
}
.orderOfEvaluation(@a1, @a2, @a3) when ((@a3) or (@a1) and (@a2)) {
no-parenthesis: evaluated true 1b;
}
.orderOfEvaluation(@a1, @a2, @a3) when ((@a1) and ((@a2) or (@a3))) {
no-parenthesis: evaluated true 1c;
}
.orderOfEvaluation(@a1, @a2, @a3) when (@a3), (@a1) and (@a2) {
no-parenthesis: evaluated true 1d;
}
.orderOfEvaluation(@a1, @a2, @a3) when (((@a3) or (@a1)) and (@a2)) {
no-parenthesis: evaluated true 1e;
}
.orderOfEvaluation(@a1, @a2, @a3) when ((@a1) and (@a2) or not (@a3)) {
no-parenthesis: evaluated true 2;
no-parenthesis: evaluated true 2a;
}
.orderOfEvaluation(@a1, @a2, @a3) when (not (@a3) or (@a1) and (@a2)) {
no-parenthesis: evaluated true 2b;
}
.orderOfEvaluation(@a1, @a2, @a3) when not (@a3), (@a1) and (@a2) {
no-parenthesis: evaluated true 2c;
}
.orderOfEvaluation(@a1, @a2, @a3) when (not (@a1) and (@a2) or (@a3)) {
no-parenthesis: evaluated true 3;
Expand Down

0 comments on commit 71e4bbc

Please sign in to comment.