Skip to content
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
12 changes: 11 additions & 1 deletion packages/less/lib/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions packages/test-data/tests-unit/functions/functions.css
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ html {
a: true;
b: false;
c: false;
d: true;
e: false;
}
#if {
a: 1;
Expand All @@ -236,6 +238,8 @@ html {
i: 6;
j: 8;
k: 1;
m: 1;
n: 2;
l: black;
/* results in void */
color: green;
Expand Down
6 changes: 6 additions & 0 deletions packages/test-data/tests-unit/functions/functions.less
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions packages/test-data/tests-unit/mixins-guards/mixins-guards.css
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
11 changes: 11 additions & 0 deletions packages/test-data/tests-unit/mixins-guards/mixins-guards.less
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Loading