less / less.js

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

Division make less crash #3666

Closed lyz810 closed 2 years ago

lyz810 commented 2 years ago
@rpx: 1 / 75rem;
html {
font-size: 2 * @rpx;
}
npx less index.less

output: OperationError: Operation on an invalid type in ......

This error appears in v4,while normal in v3

Is this a bug, or feature?

The following cases will not throw error in v4

@rpx: (1 / 75rem);
html {
font-size: 2 * @rpx;
}
@rpx: 1 / 75rem;
html {
font-size: 2 * (@rpx);
}
@rpx: 1rem * (1 / 75);
html {
font-size: 2 * @rpx;
}
html {
font-size: 2 * 1 / 75rem; // not throw error, but not correct, as expected feature in https://github.com/less/less.js/releases/tag/v4.0.0
}
iChenLei commented 2 years ago

It works as expected.

In order to cause fewer conflicts with CSS, which now liberally uses the / symbol between values, there is now a math mode that only requires parentheses for division. (This is now the default in Less 4.) "Strict math" has also been tweaked to operate more intuitively, although the legacy behavior is supported.

Relative source https://sass-lang.com/documentation/breaking-changes/slash-div https://lesscss.org/usage/#less-options-math

Close it now, feel free to reopen this issue if you think it's still a issue for you.