Fix not keyword silently ignored when used without parentheses in conditions#4421
Conversation
Previously, `boolean(not false)` silently ignored the `not` keyword while `boolean(not (false))` worked correctly. The `negatedCondition` parser function consumed the `not` keyword but only tried `parenthesisCondition`, which requires `(`. With no parens, it returned undefined with `not` already consumed, causing silent skip. Fix: fall back to `atomicCondition` when `parenthesisCondition` fails, allowing both `not false` and `not (false)` to work consistently. Co-authored-by: matthew-dean <414752+matthew-dean@users.noreply.github.com>
not keyword silently ignored when used without parentheses in conditions
|
@copilot Do we not / should we not require parentheses after not() though? It's supposed to align with the media syntax, so shouldn't something like |
Complex conditions like `not 2 < 1` still require parentheses, keeping alignment with CSS media query syntax. Only simple bare values (keywords, variables, quoted strings) are allowed after `not` without parens: `not false`, `not @var`. Remove the `boolean(not 2 < 1)` test case that relied on the broader atomicCondition fallback. Co-authored-by: matthew-dean <414752+matthew-dean@users.noreply.github.com>
Good point. I've updated the fix (571365f → latest) to restrict bare
The fallback in |
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment Tip CodeRabbit can use your project's `biome` configuration to improve the quality of JS/TS/CSS/JSON code reviews.Add a configuration file to your project to customize how CodeRabbit runs |
not falseandnot (false)produced inconsistent results — the parenthesized form correctly negated, while the bare form silently dropped thenotentirely.Root cause:
negatedConditionin the parser consumed thenottoken then only attemptedparenthesisCondition. On failure (no(), it returnedundefinedwithnotalready consumed, causing the caller to parse the bare value without negation.Fix:
parser.js— InnegatedCondition, whenparenthesisConditionfails, fall back to parsing a simple bare value (keyword, variable, quoted string) without parens. Complex conditions (comparisons, function calls) still require parentheses, aligning with CSS media query syntax:Also works consistently in
if()and mixin guards:Comparisons without parentheses are intentionally not supported — use
not (2 < 1)instead ofnot 2 < 1.Tests:
functions.less/css— addedboolean(not false),boolean(not true),if(not false, ...),if(not true, ...)mixins-guards.less/css— addedwhen not @aguard without parenthesesOriginal prompt
notkeyword and parenthesis #4401🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.