less / less.js

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

Dimension is not a number. #3633

Closed rockey2020 closed 3 years ago

rockey2020 commented 3 years ago

image

rockey2020 commented 3 years ago

It doesn't work

iChenLei commented 3 years ago

Not less bug, just a Math logic error. You write a invalid math compute @witdh: (@designWidth / @i) (the @i variable can be zero!).

- .loop (@className, @i) when (@i >= 0) {
+ .loop (@className, @i) when (@i > 0) {
  .@{className}-@{i} {
    @witdh: (@designWidth / @i);
    width: @witdh * @i;
  }
  .loop(@className, @i - 1);
}

non-zero / zero => we get a Infinity, and then we compute @witdh * @i , get a NaN. So you will encount this error log:

var Dimension = function (value, unit) {
    this.value = parseFloat(value);
    if (isNaN(this.value)) {
        throw new Error('Dimension is not a number.');
    }