Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logical operator and now has higher precedence then logical operator or. #2779

Merged
merged 1 commit into from
Jan 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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