Skip to content

fix(parser/less)!: read a mixin path without parens or lookups in a value as text, as less.js does - #231

Merged
leaysgur merged 3 commits into
oxc-project:mainfrom
Taragryen:fix/less-bare-mixin-path-in-value
Dec 2, 2026
Merged

leaysgur merged 3 commits into
oxc-project:mainfrom
Taragryen:fix/less-bare-mixin-path-in-value

Conversation

@Taragryen

@Taragryen Taragryen commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #230

less.js mixin.call(inValue) gives up on a mixin path that has neither parens nor lookups ("This isn't a valid in-value mixin call"), so @v: .a .b; is no call: value() fails and the declaration falls back to permissiveValue, which keeps .a .b as text for @{v} to substitute. This parser read it as a LessMixinCall with two callee children, the gap between them in no node, and oxfmt printed @v: .a.b;: .dark @{v} then compiles to .dark .a.b instead of .dark .a .b.

⚠️ Breaking: adds LessVariableDeclaration::value_is_raw.

  • In value position a mixin path without parens or lookups is an error (parse_less_maybe_mixin_call_or_with_lookups). .ns.m(), .ns .m() and .ns.m[@r] are calls as before, and so is a statement-position .a .b;.
  • A variable then takes the existing raw fallback (the @this: () => { ... }; read), now flagged value_is_raw as PostcssSimpleVarDeclaration flags its own: a formatter cannot otherwise tell the raw token run from a typed space list, and has to print it as written.
  • Representation: @v: .a .b; and @v: .a; were a typed LessMixinCall, now the raw run. @v: .a:hover .b; was an AtRule named v (the typed value stopped at :), now a variable declaration with the raw run.
  • Acceptance is tightened, which "Acceptance" in AGENTS.md says a change does not do: a normal property value has no raw fallback, so a { b: .c; } and .m(.a); are now errors. lessc 4.4.2 rejects both ("Unrecognised input", "expected ')' got '.'"). I read this as a bug fix toward the owner rather than a new line; if these should stay accepted, I can narrow the change to variable declarations.
  • Pins: tests/less_ast_shapes.rs (the raw shapes, and the call shapes that stay), tests/error/less/mixin/bare-call-in-value.less.
  • Conformance snapshots are unchanged (all suites).
  • Not covered: a { b: e(.c); } still parses, lessc rejects it.

oxfmt follow-up, which has to land together with the bump to this release: print a value_is_raw value verbatim. With the bump alone, @v: .a:hover .b; moves from the at-rule path (printed as written) to the raw fallback, and oxfmt prints .a: hover .b, as it already does for @v: #ns .m:hover; on main; no existing oxc_formatter_css fixture catches it. Checked locally against this branch: of 23 selector-shaped variable values, main changes what 9 compile to (.a .b → .a.b, #ns .m:hover → #ns .m: hover, #ns/* c */.b → #ns /* c */ .b), the follow-up changes none, and the existing oxc_formatter_css fixtures pass unchanged.

AI usage: written with Claude Code, model Claude Fable 5.2 (claude-fable-5-2); the reasoning effort level is not available to the model.

🤖 Generated with Claude Code

…alue 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 oxc-project#230

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
leaysgur and others added 2 commits December 2, 2026 13:45
… 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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
@codspeed

codspeed Bot commented Dec 2, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

Warning

oxc-project has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

✅ 4 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing Taragryen:fix/less-bare-mixin-path-in-value (c6f60ba) with main (ad15acd)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩

@leaysgur

leaysgur commented Dec 2, 2026

Copy link
Copy Markdown
Member

Thank you~. I added small refactor commits. 👌🏻

@leaysgur
leaysgur merged commit 476edcc into oxc-project:main Dec 2, 2026
7 checks passed
@oxc-guard oxc-guard Bot mentioned this pull request Dec 2, 2026
Dunqing pushed a commit to limadog9/oxc that referenced this pull request Dec 2, 2026
…c-project#30663)

A Less variable value with no typed reading is less.js `permissiveValue`
text, and `@{v}` substitutes those bytes as written. oxfmt re-spaced it,
which changes what the substitution compiles to.

oxc-css-parser 0.0.25 (oxc-project/oxc-css-parser#231) reads such a
value as a raw token run flagged
`LessVariableDeclaration::value_is_raw`, instead of a parenless mixin
call (which less.js never takes in a value). This PR bumps the parser
and prints a `value_is_raw` value verbatim, like a raw `$var` value. The
bump has to land with the printer change: on its own, `@p: .a:hover .b;`
moves from the at-rule path (printed as written) to the raw fallback and
becomes `.a: hover .b`.

### Example

Input:

```less
@v: .a .b;
@p: .a:hover .b;
@q: #ns .m:hover;
.x @{v} {
  c: d;
}
```

Before output:

```less
@v: .a.b;
@p: .a:hover .b;
@q: #ns .m: hover;
.x @{v} {
  c: d;
}
```

After output:

```less
@v: .a .b;
@p: .a:hover .b;
@q: #ns .m:hover;
.x @{v} {
  c: d;
}
```

Both were captured with `cargo run -p oxc_formatter_css --example
css_formatter`.

- `@v`: `.x @{v}` compiled to `.x .a.b` (a compound selector) instead of
`.x .a .b`.
- `@q`: `#ns .m: hover` is no longer a `:hover` selector.
- Prettier prints `@p: .a: hover .b;` and `@q: #ns .m: hover;`, so this
is recorded as a divergence.

### Changes

- `print/less.rs`: `write_less_variable_declaration` prints a
`value_is_raw` value with `write_verbatim_value`, as
`postcss_simple_vars.rs` does.
- `DIVERGENCES.md`: `postcss-simple-var-raw-verbatim` is merged into
`#substituted-raw-verbatim`, which covers both `$var` and Less variable
values (same reason, mechanism and output). Its references and the
conformance report are renamed.
- `AGENTS.md` "Printing raw vs typed": a Less variable value is listed
with postcss-simple-vars.
- Pin: `tests/fixtures/format/less/variable-raw-verbatim.less`.

---

AI usage: written with Claude Code, model Claude Opus 5.5
(`claude-opus-5-5`); the reasoning effort level is not available to the
model.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Less: a mixin path without parens in a variable value is read as a call, oxfmt changes its meaning

2 participants