From 77044dc5a84b17e11d3e3596330322600d5f892d Mon Sep 17 00:00:00 2001 From: Taragryen <44627712+Taragryen@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:03:11 +0800 Subject: [PATCH 1/3] fix(parser/less)!: read a mixin path without parens or lookups in a value as text, as less.js does less.js `mixin.call(inValue)` gives up on a mixin path with neither parens nor lookups, so `@v: .a .b;` is no call: the variable keeps it as text for `@{v}` to substitute. It was read as a `LessMixinCall`, with the gap between the names in no node, and oxfmt printed `@v: .a.b;`. Such a path is now an error in value position, so a variable declaration takes the existing raw fallback, flagged `value_is_raw`. A normal property value has no raw fallback: `a { b: .c; }` is now an error, as in lessc. Closes #230 Co-Authored-By: Claude Fable 5.2 --- AGENTS.md | 2 ++ crates/oxc_css_parser/src/ast.rs | 3 +++ crates/oxc_css_parser/src/parser/less.rs | 8 ++++++- .../error/less/mixin/bare-call-in-value.less | 1 + .../error/less/mixin/bare-call-in-value.snap | 8 +++++++ .../oxc_css_parser/tests/less_ast_shapes.rs | 24 +++++++++++++++++++ 6 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 crates/oxc_css_parser/tests/error/less/mixin/bare-call-in-value.less create mode 100644 crates/oxc_css_parser/tests/error/less/mixin/bare-call-in-value.snap diff --git a/AGENTS.md b/AGENTS.md index 5c69191..5ea468e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -56,6 +56,8 @@ No postcss-less leniency. - Variable and property names are `[\w-]+` (`@-`, `@1`, `$-`), not CSS idents - A string interpolates only on an exact `@{name}` / `${name}`; `"@{box"` and the outer `@{box-` of `"@{box-@{suffix}}"` are text - An unquoted `url()` body runs to `)`, whitespace and newlines included +- A mixin path without parens or lookups is no call in a value (`mixin.call(inValue)`): a normal property rejects it, + a variable keeps it as text (`@v: .a .b`), flagged `value_is_raw` - A variable declaration must reach `;` / `}`: `@page :first { ... }` is an at-rule, and the permissive `@this: () => { ... };` read is tried only when no typed value parses ### Block contents diff --git a/crates/oxc_css_parser/src/ast.rs b/crates/oxc_css_parser/src/ast.rs index 5d19114..5f0ada5 100644 --- a/crates/oxc_css_parser/src/ast.rs +++ b/crates/oxc_css_parser/src/ast.rs @@ -1303,6 +1303,9 @@ pub struct LessVariableDeclaration<'a> { pub name: LessVariable<'a>, pub colon_span: Span, pub value: ComponentValue<'a>, + /// No typed value parsed, so `value` is the raw token run less.js `permissiveValue` + /// keeps as text: `@{name}` substitutes it as written. + pub value_is_raw: bool, } #[derive(Debug)] diff --git a/crates/oxc_css_parser/src/parser/less.rs b/crates/oxc_css_parser/src/parser/less.rs index debd49a..1957081 100644 --- a/crates/oxc_css_parser/src/parser/less.rs +++ b/crates/oxc_css_parser/src/parser/less.rs @@ -328,6 +328,10 @@ impl<'a> Parser<'a> { lookups, span, }))) + } else if mixin_call.args.is_none() { + // less.js `mixin.call(inValue)`: without parens or lookups it is no call in a value. + // A variable then keeps it as text (`permissiveValue`): `@v: .a .b` is a selector for `@{v}` + Err(Error { kind: ErrorKind::ExpectComponentValue, span: mixin_call.span }) } else { Ok(ComponentValue::LessMixinCall(self.alloc(mixin_call))) } @@ -1840,6 +1844,7 @@ impl<'a> Parse<'a> for LessVariableDeclaration<'a> { let name = input.parse::()?; let (_, colon_span) = input.cursor.expect_colon()?; + let mut value_is_raw = false; let value = if matches!(input.cursor.peek()?.token, Token::LBrace(..)) { ComponentValue::LessDetachedRuleset(input.parse()?) } else { @@ -1865,6 +1870,7 @@ impl<'a> Parse<'a> for LessVariableDeclaration<'a> { let Some(end) = end else { return Err(error); }; + value_is_raw = true; ComponentValue::LessList(LessList { elements: values, comma_spans: None, @@ -1885,7 +1891,7 @@ impl<'a> Parse<'a> for LessVariableDeclaration<'a> { value }; let span = Span { start: name.span.start, end: value.span().end }; - Ok(LessVariableDeclaration { span, name, colon_span, value }) + Ok(LessVariableDeclaration { span, name, colon_span, value, value_is_raw }) } } diff --git a/crates/oxc_css_parser/tests/error/less/mixin/bare-call-in-value.less b/crates/oxc_css_parser/tests/error/less/mixin/bare-call-in-value.less new file mode 100644 index 0000000..7238485 --- /dev/null +++ b/crates/oxc_css_parser/tests/error/less/mixin/bare-call-in-value.less @@ -0,0 +1 @@ +a { b: .c; } diff --git a/crates/oxc_css_parser/tests/error/less/mixin/bare-call-in-value.snap b/crates/oxc_css_parser/tests/error/less/mixin/bare-call-in-value.snap new file mode 100644 index 0000000..75371b7 --- /dev/null +++ b/crates/oxc_css_parser/tests/error/less/mixin/bare-call-in-value.snap @@ -0,0 +1,8 @@ +--- +source: crates/oxc_css_parser/tests/error.rs +--- +error: expect token `(`, but found `{` + ┌─ bare-call-in-value.less:1:3 + │ +1 │ a { b: .c; } + │ ^ diff --git a/crates/oxc_css_parser/tests/less_ast_shapes.rs b/crates/oxc_css_parser/tests/less_ast_shapes.rs index 2b5a158..7127074 100644 --- a/crates/oxc_css_parser/tests/less_ast_shapes.rs +++ b/crates/oxc_css_parser/tests/less_ast_shapes.rs @@ -194,3 +194,27 @@ fn percentage_is_a_selector_outside_keyframes() { block.statements ); } + +// A mixin path without parens or lookups is no call in a value (less.js `mixin.call(inValue)`): +// a variable keeps it as text, so the gap in `.a .b` is still a descendant combinator for `@{v}`. +#[test] +fn bare_mixin_path_in_variable_value_is_raw() { + let code = "@v: .a .b;\n@p: .a:hover > .b;\n@c: .ns .m();\n@l: .ns.m[@r];"; + let ss = parse_less(code); + let decl = |i: usize| { + let Statement::LessVariableDeclaration(decl) = &ss.statements[i] else { + panic!("expected a variable declaration, got {:?}", ss.statements[i]); + }; + decl + }; + assert!(decl(0).value_is_raw); + assert_eq!(text(code, decl(0).value.span()), ".a .b"); + assert!(decl(1).value_is_raw); + assert_eq!(text(code, decl(1).value.span()), ".a:hover > .b"); + + // With parens or a lookup it is a call + assert!(!decl(2).value_is_raw); + assert!(matches!(decl(2).value, ComponentValue::LessMixinCall(..))); + assert!(!decl(3).value_is_raw); + assert!(matches!(decl(3).value, ComponentValue::LessNamespaceValue(..))); +} From cdc214d2d9244712642088e305a1744f5714707a Mon Sep 17 00:00:00 2001 From: leaysgur <6259812+leaysgur@users.noreply.github.com> Date: Wed, 2 Dec 2026 13:45:46 +0900 Subject: [PATCH 2/3] chore(parser/less): name the bare in-value mixin path error and allow owner-backed tightening - Report `UnexpectedLessMixinCall` instead of `ExpectComponentValue` for a mixin path without parens or lookups in a value - AGENTS.md "Acceptance": rejecting a parse the owner itself rejects is a bug fix, the one exception to "changing acceptance is additive" Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 1 + crates/oxc_css_parser/src/parser/less.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 5ea468e..5153c2e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,6 +13,7 @@ Each line has one grammar owner. postcss is never one, and neither is "Prettier prints it". Changing acceptance is additive: it only turns errors into parses, with a comment citing the owner, a test pinning the strict shape, and the conformance snapshot flip in the PR. +The one exception is a parse the owner itself rejects: turning it into an error is a bug fix, with the owner's rejection cited in the PR and a `tests/error/**` fixture pinning it. Changing how already-accepted input is represented is a bug fix or a refactor, and the PR says which. ### CSS diff --git a/crates/oxc_css_parser/src/parser/less.rs b/crates/oxc_css_parser/src/parser/less.rs index 1957081..8cc7d25 100644 --- a/crates/oxc_css_parser/src/parser/less.rs +++ b/crates/oxc_css_parser/src/parser/less.rs @@ -331,7 +331,7 @@ impl<'a> Parser<'a> { } else if mixin_call.args.is_none() { // less.js `mixin.call(inValue)`: without parens or lookups it is no call in a value. // A variable then keeps it as text (`permissiveValue`): `@v: .a .b` is a selector for `@{v}` - Err(Error { kind: ErrorKind::ExpectComponentValue, span: mixin_call.span }) + Err(Error { kind: ErrorKind::UnexpectedLessMixinCall, span: mixin_call.span }) } else { Ok(ComponentValue::LessMixinCall(self.alloc(mixin_call))) } From c6f60ba80f0520cf5c8726b79d3a85d7e9f5562b Mon Sep 17 00:00:00 2001 From: leaysgur <6259812+leaysgur@users.noreply.github.com> Date: Wed, 2 Dec 2026 13:53:03 +0900 Subject: [PATCH 3/3] refactor(parser/less): return `value_is_raw` with the variable value Bind `(value, value_is_raw)` from the `if` / `match` instead of setting a `mut` flag in the raw-fallback arm, as `Declaration` and `PostcssSimpleVarDeclaration` do. Co-Authored-By: Claude Opus 5.5 --- crates/oxc_css_parser/src/parser/less.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/crates/oxc_css_parser/src/parser/less.rs b/crates/oxc_css_parser/src/parser/less.rs index 8cc7d25..6e8cde1 100644 --- a/crates/oxc_css_parser/src/parser/less.rs +++ b/crates/oxc_css_parser/src/parser/less.rs @@ -1844,9 +1844,8 @@ impl<'a> Parse<'a> for LessVariableDeclaration<'a> { let name = input.parse::()?; let (_, colon_span) = input.cursor.expect_colon()?; - let mut value_is_raw = false; - let value = if matches!(input.cursor.peek()?.token, Token::LBrace(..)) { - ComponentValue::LessDetachedRuleset(input.parse()?) + let (value, value_is_raw) = if matches!(input.cursor.peek()?.token, Token::LBrace(..)) { + (ComponentValue::LessDetachedRuleset(input.parse()?), false) } else { let typed = input.try_parse(|p| { p.with_state(ParserState { @@ -1855,8 +1854,8 @@ impl<'a> Parse<'a> for LessVariableDeclaration<'a> { }) .parse_maybe_less_list(/* allow_comma */ true) }); - let value = match typed { - Ok(value) => value, + let (value, value_is_raw) = match typed { + Ok(value) => (value, false), // No typed value: only then does less.js `permissiveValue` take any // balanced token run (`@this: () => { ... };`), and only one ending in `;` Err(error) => { @@ -1870,12 +1869,9 @@ impl<'a> Parse<'a> for LessVariableDeclaration<'a> { let Some(end) = end else { return Err(error); }; - value_is_raw = true; - ComponentValue::LessList(LessList { - elements: values, - comma_spans: None, - span: Span { start, end }, - }) + let list = + LessList { elements: values, comma_spans: None, span: Span { start, end } }; + (ComponentValue::LessList(list), true) } }; // less.js `declaration`: a value that stops short of the statement boundary is @@ -1888,7 +1884,7 @@ impl<'a> Parse<'a> for LessVariableDeclaration<'a> { let span = input.cursor.peek()?.span; return Err(Error { kind: ErrorKind::TryParseError, span }); } - value + (value, value_is_raw) }; let span = Span { start: name.span.start, end: value.span().end }; Ok(LessVariableDeclaration { span, name, colon_span, value, value_is_raw })