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

Cannot override variable imported via :extend()

Open Bilge opened this issue 3 years ago • 2 comments

To reproduce:

@color: red;

a {
  color: @color;
}

.foo {
  a:extend(a all) {
    @color: green;
  }
}

Current behavior:

.foo a colour is red.

Expected behavior:

.foo a colour is green.

Environment information:

  • less version: 4.1.2
  • nodejs version: v14.15.3
  • operating system: windows

Bilge avatar Mar 29 '22 22:03 Bilge

I have a different opinion, it's not a bug.

@color: red;

a {
  color: @color;
}

.foo {
  a:extend(a all){
    @w: 10px;
    @color: green;
    width: @w;
    color: @color;
  }
}

It become

// first part
a,
.foo a {
  color: red;
}
// second part
.foo a {
  width: 10px;
  color: green;
}

First part is public section, the variable you declare the second time can't affect the first part.

lumburr avatar Mar 31 '22 07:03 lumburr

You are correct. Even without extension, this does not work. I misunderstood from lazy evaluation that declaring a variable after the property that consumes it will update the property if it exists in the same scope or deeper, however that appears not to be the case.

It seems to me lazy evaluation is not really lazy at all. Once a property is declared referencing some variable, that variable has to exist (even if it's physically specified later in the file) in the current scope, and if it is redeclared at any point later, this change is ignored.

Bilge avatar Mar 31 '22 08:03 Bilge