less.js icon indicating copy to clipboard operation
less.js copied to clipboard

Cannot consume `@rest...` when not specified

Open Bilge opened this issue 7 months ago • 2 comments

To reproduce:

.foo(@a, @rest...) {
  .bar(@a, @rest);
}

.bar(@a, @b: false) {}

.foo(@a, true); // works
.foo(@a); // Cannot read properties of undefined (reading 'value')

Current behavior:

Consuming an optional variadic that is not set causes an error.

Expected behavior:

Since (@a, @rest...) supports 1..N arguments, it should be expected that in the 1 case, @rest is unset, and if so, passing @rest should be valid and a no-op instead of an error.

Environment information:

  • less version: 4.4.0
  • nodejs version: v22.12.0
  • operating system: 6.6.87.2-microsoft-standard-WSL2

Bilge avatar Jul 27 '25 10:07 Bilge

You'd have to define @a at least, but this Less

.foo(@a, @rest...) {
  .bar(@a, @rest...);
}

.bar(@a, @b: false) { div { color: @b; } }

@a: 1;

.foo(@a); 

gives me:

div {
  color: false;
}

in version 4.4.0.

puckowski avatar Jul 27 '25 12:07 puckowski

Ah, well you changed the calling convention from @rest to @rest..., which is presumably how you're supposed to do it, but this is not documented anywhere.

Bilge avatar Jul 27 '25 12:07 Bilge