diff --git a/packages/less/lib/less/parser/parser.js b/packages/less/lib/less/parser/parser.js index 72014aab2..6a439fb89 100644 --- a/packages/less/lib/less/parser/parser.js +++ b/packages/less/lib/less/parser/parser.js @@ -2438,8 +2438,18 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) { const result = this.parenthesisCondition(needsParens); if (result) { result.negate = !result.negate; + return result; + } + + // Allow simple bare values (keyword/variable) without parens, + // e.g., `not false` or `not @var`. + // Complex conditions (comparisons, function calls) require parentheses. + const entities = this.entities; + const index = parserInput.i; + const a = entities.keyword() || entities.variable() || entities.quoted() || entities.mixinLookup(); + if (a) { + return new(tree.Condition)('=', a, new(tree.Keyword)('true'), index + currentIndex, true); } - return result; } }, parenthesisCondition: function (needsParens) { diff --git a/packages/test-data/tests-unit/functions/functions.css b/packages/test-data/tests-unit/functions/functions.css index 4876f5874..17a990259 100644 --- a/packages/test-data/tests-unit/functions/functions.css +++ b/packages/test-data/tests-unit/functions/functions.css @@ -224,6 +224,8 @@ html { a: true; b: false; c: false; + d: true; + e: false; } #if { a: 1; @@ -236,6 +238,8 @@ html { i: 6; j: 8; k: 1; + m: 1; + n: 2; l: black; /* results in void */ color: green; diff --git a/packages/test-data/tests-unit/functions/functions.less b/packages/test-data/tests-unit/functions/functions.less index bc476b6e2..f11b756d2 100644 --- a/packages/test-data/tests-unit/functions/functions.less +++ b/packages/test-data/tests-unit/functions/functions.less @@ -256,6 +256,9 @@ html { a: boolean(not(2 < 1)); b: boolean(not(2 > 1) and (true)); c: boolean(not(boolean(true))); + // not without parentheses (should behave the same as with parentheses) + d: boolean(not false); + e: boolean(not true); } #if { @@ -271,6 +274,9 @@ html { i: if(true and isnumber(6), 6, 8); j: if(not(true) and true, 6, 8); k: if(true or true, 1); + // not without parentheses + m: if(not false, 1, 2); + n: if(not true, 1, 2); // see: https://github.com/less/less.js/issues/3371 @some: foo; diff --git a/packages/test-data/tests-unit/mixins-guards/mixins-guards.css b/packages/test-data/tests-unit/mixins-guards/mixins-guards.css index c54eca77e..fa164dd18 100644 --- a/packages/test-data/tests-unit/mixins-guards/mixins-guards.css +++ b/packages/test-data/tests-unit/mixins-guards/mixins-guards.css @@ -209,3 +209,9 @@ no-parenthesis: evaluated true 4; with-parenthesis: evaluated true; } +.test-not-noparens1 { + content: "not without parens true."; +} +.test-not-noparens2 { + content: "not without parens false."; +} diff --git a/packages/test-data/tests-unit/mixins-guards/mixins-guards.less b/packages/test-data/tests-unit/mixins-guards/mixins-guards.less index 834c57d2c..c52749acb 100644 --- a/packages/test-data/tests-unit/mixins-guards/mixins-guards.less +++ b/packages/test-data/tests-unit/mixins-guards/mixins-guards.less @@ -356,3 +356,14 @@ .orderOfEvaluation(true, true, false); } +// not without parentheses should work the same as not with parentheses +.test-not-noparens (@a) when not @a { + content: "not without parens false."; +} +.test-not-noparens (@a) when (@a) { + content: "not without parens true."; +} + +.test-not-noparens1 { .test-not-noparens(true) } +.test-not-noparens2 { .test-not-noparens(false) } +