less / less.js

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

less parse about inconsistent operation performance #3692

Closed zhusjfaker closed 1 year ago

zhusjfaker commented 2 years ago

To reproduce:


// parse ok

@c:20px + 20px * 2px;

.d {
    font-size: @c;
}

// parse ok

@c:20px + (20px * 2px);

.d {
    font-size: @c;
}

// parse fail

@c:20px + 20px / 2px;

.d {
    font-size: @c;
}

// parse ok

@c:20px + (20px / 2px);

.d {
    font-size: @c;
}

Current behavior:

less.js the operation of variables is inconsistent in multiplication and division

Expected behavior:

consistent behavior

Environment information:

please do not forcibly close issue

lumburr commented 2 years ago

I'm trying to fix this issue, there have been many discussions about math rules in less. This is an issue of historical discussions https://github.com/less/less.js/issues/1880 I found in the documentation the new operation description in less 4 https://github.com/less/less-docs/blob/master/content/usage/less-options.md 屏幕截图 2022-03-30 204547 Another issue also verified my view https://github.com/less/less.js/issues/3586 My understanding is that, we should throw error in there 7 situations.

// parse fail
@c:20px + 20px / 2px; 

// parse fail
@c:20px - 20px / 2px; 

// parse fail
@c:20px / 20px / 2px; 

// parse fail
@c:20px * 20px / 2px; 

// parse fail
@c:20px / 20px + 2px; 

// parse fail
@c:20px /20px - 2px; 

// parse fail
@c:20px / 20px * 2px; 

I'm not sure my understanding is correct. I need your advice to modify pr. @matthew-dean @iChenLei

matthew-dean commented 1 year ago

Yes, the failures are expected in the current Less math mode. See: https://github.com/less/less-docs/blob/master/content/usage/less-options.md#math