Merge pull request #2819 from SomMeri/issue-2798-guards-regression

Guard expressions regression in 2.6.0 (#2798)
This commit is contained in:
Max Mikhailov
2016-02-18 07:54:29 +03:00
3 changed files with 71 additions and 2 deletions

View File

@@ -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 () {

View File

@@ -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;
}

View File

@@ -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;
}