less / less/less.js

Guarded namespace unavailable when calling mixin with ruleset

Open
#3,407 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I keep running into issues today it seems.

Example:

#media {
  #desktop (@ruleset) {
    @media (min-width: 700px) {
      @ruleset();
    }
  }

  #mobile (@ruleset) {
    @media (max-width: 699px) {
      @ruleset();
    }
  }
}


@switch: demo;

.example {
  #lookup when (@switch = demo) {
    @not-found: 1;
  }

  @found: 2;
  
  #lookup2 {
    @also-found: 3;
  }

  
  #media#desktop({
    // Comment the next line and it will all compile
    error: #lookup[@not-found];
    success1: @found;
    success2: #lookup2[@also-found];
  });
}

Expected output:

@media (min-width: 700px) {
  .example {
    error: 1;
    success1: 2;
    success2: 3;
  }
}

Actual output: variable @not-found not found .

I managed to narrow it down to usage of the guard. Remove it and it works. Put the namespace within the ruleset and it works.

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 Less example and confirm that the guarded namespace call fails while the unguarded variant succeeds. Trace the compiler path for guarded namespace lookup and add a regression test covering the expected CSS output; done when @not-found resolves to 1 without breaking the other properties.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.