less / less.js

Less. The dynamic stylesheet language.
http://lesscss.org
Apache License 2.0
17.02k stars 3.41k forks source link

`if` function evaluates both values despite the condition #3528

Closed thybzi closed 4 years ago

thybzi commented 4 years ago

Inline conditional function of if(condition, then-value, else-value) has some unexpected behavior.

It tries to evaluate "else-value" even if condition is true and else-value in unneeded. In the same way, "then-value" is evaluated even if condition is false.

That may cause 'Operation on an invalid type' error if condition and value processing depends on value type.

.mymixin(@val) {
    myprop: if(isnumber(@val), @val * 42, @val);
}

a {
    .mymixin(11);    // works perfectly with the result of 462
}

b {
    .mymixin(null);  // causes 'Operation on an invalid type' error
}
matthew-dean commented 4 years ago

Duplicate of https://github.com/less/less.js/issues/3371