Skip to content

Commit

Permalink
Merge pull request #2819 from SomMeri/issue-2798-guards-regression
Browse files Browse the repository at this point in the history
Guard expressions regression in 2.6.0 (#2798)
  • Loading branch information
seven-phases-max committed Feb 18, 2016
2 parents 7b4dcc1 + c12a7df commit 1bc481b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
36 changes: 34 additions & 2 deletions lib/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1640,12 +1640,44 @@ var Parser = function Parser(context, imports, fileInfo) {
}
},
parenthesisCondition: function () {
function tryConditionFollowedByParenthesis(me) {
var body;
parserInput.save();
body = me.condition();
if (!body) {
parserInput.restore();
return ;
}
if (!parserInput.$char(')')) {
parserInput.restore();
return ;
}
parserInput.forget();
return body;
}

var body;
parserInput.save();
if (!parserInput.$str("(")) {
parserInput.restore();
return ;
}
body = this.condition() || this.atomicCondition();
expectChar(')');
body = tryConditionFollowedByParenthesis(this);
if (body) {
parserInput.forget();
return body;
}

body = this.atomicCondition();
if (!body) {
parserInput.restore();
return ;
}
if (!parserInput.$char(')')) {
parserInput.restore("expected ')' got '" + parserInput.currentChar() + "'");
return ;
}
parserInput.forget();
return body;
},
atomicCondition: function () {
Expand Down
12 changes: 12 additions & 0 deletions test/css/no-strict-math/mixins-guards.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.test-2798 {
regression: fixed;
}
.conditions-parser-1 {
only-atomic: ok;
}
.conditions-parser-2 {
only-atomic-with-nested-parenthesis: ok;
}
.conditions-parser-3 {
only-atomic-nested-parenthesis-on-right: ok;
}
25 changes: 25 additions & 0 deletions test/less/no-strict-math/mixins-guards.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// https://github.com/less/less.js/issues/2798
.test-2798 when ((8+4) < 13) {
regression: fixed;
}
.test-2798 when ((8+6) < 13) {
regression: should not be visible;
}
.conditions-parser-1 when (8+4 < 13) {
only-atomic: ok;
}
.conditions-parser-1 when (8+6 < 13) {
only-atomic: should not be visible;
}
.conditions-parser-2 when (8+(5-1) < 13) {
only-atomic-with-nested-parenthesis: ok;
}
.conditions-parser-2 when (8+(15-1) < 13) {
only-atomic-with-nested-parenthesis: should not be visible;
}
.conditions-parser-3 when (8 < (13+1)) {
only-atomic-nested-parenthesis-on-right: ok;
}
.conditions-parser-3 when (8 < (3+1)) {
only-atomic-nested-parenthesis-on-right: should not be visible;
}

0 comments on commit 1bc481b

Please sign in to comment.