less / less.js

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

Value is not calculated for css --variables #3800

Closed Dagur closed 1 year ago

Dagur commented 1 year ago

To reproduce:

.test {
  width: 20px + 40px;  
  --width: 20px + 40px;  
}

Current behavior:

output is

.test {
  width: 60px;
  --width: 20px + 40px;
}

Expected behavior:

I expected

.test {
  width: 60px;
  --width: 60px;
}

Environment information:

This can cause unexpected problems when combined with less @variables.

matthew-dean commented 1 year ago

This is by design and not a bug. For example, let's say you had this:

.test {
  --width: 20px + foo({ 40: 'px' });
}

What should Less do with this? The value you have for --width is 100% perfectly valid, and you could be intending to evaluate it as JavaScript, so it couldn't throw an error as an invalid expression. Instead, you have to evaluate it before-hand:

.test {
  @width: 20px + 40px;
  --width: @width;
}

Less evaluating at-rules in custom properties has its own add-in side-effects / bugs, but that's what is currently supported.

Dagur commented 1 year ago

Maybe this bug should be about lack of documentation then? I tried to look this up and found nothing.