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

Variable alias breaks unrelated detached rulesets call

Open zaquest opened this issue 3 years ago • 2 comments

I have a piece of code that comes down to the following:

@blue: #007bff;
// @primary: @blue;  // Breaks if this line is uncommented

.unlock(@colors, @rules) {
  @rules();
}

.positive(@colors) {
  fg: @colors[dark];
  bg: @colors[light];
}


@fg: { color: @colors[fg]; };


h1 {
  @colors: { light: white; dark: black; };
  @positive: .positive(@colors);
  .unlock(@positive, @fg);
}

Without the @primary definition it works as expected. However when @primary is uncommented I get the following error:

SyntaxError: property "fg" not found in ...:
23   @positive: .positive(@colors);
24   .unlock(@positive, @fg);
25 }

First two lines and the rest of the code are seemingly unrelated to each other, yet these first two lines somehow break the rest of it.

Checked with 4.1.2 (earlier versions have the same issue, at least as early as 3.12.2).

zaquest avatar Dec 22 '21 09:12 zaquest

What output are you expecting? What is the use case?

matthew-dean avatar Apr 01 '23 17:04 matthew-dean

I expect

h1 {
    color: black;
}

And I get it as long as @primary: @blue; is commented out. So the issue is that additional variable alias breaks style compilation.

My usecase for the code above is implementing color schemes. I want to define a set of base colors (@colors) call a mixin on it to translate it to a color scheme (positive - black on white, negative white on black, and some other variations), and use this color scheme to "unlock" some detached ruleset (@fg).

zaquest avatar Apr 01 '23 18:04 zaquest