less / less/less.js

Variable alias breaks unrelated detached rulesets call

Open
#3,677 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs info question
Dominant language
JavaScript
Stars
17k
Forks
3.4k
Avg merge
7h 42m
Merged PRs (30d)
26

Description

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).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied detached-ruleset example with Less 4.1.2, then trace how the @primary alias affects variable lookup and detached ruleset calls. Add a regression test covering both versions of the example and verify that defining @primary no longer causes the unrelated property "fg" error.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, javascript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.