From c12a7df9175a149347ed73dbff9e5c95f27f12c5 Mon Sep 17 00:00:00 2001 From: meri Date: Wed, 17 Feb 2016 16:20:17 +0100 Subject: [PATCH] This fixes #2798 - left part of inequality could not be enclosed in parenthesis. --- lib/less/parser/parser.js | 36 +++++++++++++++++++-- test/css/no-strict-math/mixins-guards.css | 12 +++++++ test/less/no-strict-math/mixins-guards.less | 25 ++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 test/css/no-strict-math/mixins-guards.css create mode 100644 test/less/no-strict-math/mixins-guards.less diff --git a/lib/less/parser/parser.js b/lib/less/parser/parser.js index b527b860f..e7cee5155 100644 --- a/lib/less/parser/parser.js +++ b/lib/less/parser/parser.js @@ -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 () { diff --git a/test/css/no-strict-math/mixins-guards.css b/test/css/no-strict-math/mixins-guards.css new file mode 100644 index 000000000..81a2d7f9e --- /dev/null +++ b/test/css/no-strict-math/mixins-guards.css @@ -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; +} diff --git a/test/less/no-strict-math/mixins-guards.less b/test/less/no-strict-math/mixins-guards.less new file mode 100644 index 000000000..aa2a00588 --- /dev/null +++ b/test/less/no-strict-math/mixins-guards.less @@ -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; +}