less / less.js

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

Cannot read property 'clone' of undefined. #3586

Closed laino closed 3 years ago

laino commented 3 years ago
@c: 1 + 1 / 1;
SyntaxError: Cannot read property 'clone' of undefined in /home/lain/test.less on line 1, column 1:
matthew-dean commented 3 years ago

That can't be your only line in the file? Do you have more context?

laino commented 3 years ago

Nope. That's the only line. It takes just that.

laino commented 3 years ago

Here's a video ;)

laino commented 3 years ago

Actually the * 4 isn't even necessary.

Just this is enough:

@c: 1 + 1 / 1;
RealDolos commented 3 years ago

oopsie whoopsie. other is {operand: "/", ... } still when this code is called: https://github.com/less/less.js/blob/master/packages/less/src/less/tree/dimension.js#L73

matthew-dean commented 3 years ago

This is a bug that just got introduced?

laino commented 3 years ago

It's a bug that has existed at least since the 4.0.0 release and is still present in 4.1.0.

It's probably related to the "Parens-division now the default math setting" change.

matthew-dean commented 3 years ago

So it looks like for the above code, Less should be throwing 'Operation on an invalid type'. See: https://github.com/less/less.js/pull/3589

RealDolos commented 3 years ago

Less should be throwing 'Operation on an invalid type'

Why?

matthew-dean commented 3 years ago

@RealDolos Because in parens-division mode (the 4.0 Less default), you're trying to add 1 + a CSS expression 1 / 1. The division won't divide; it will be output as is, so you can't add 1 to it.

matthew-dean commented 3 years ago

@RealDolos Now, an argument could be made that just the 1 + 1 should add together in that case, but unfortunately that's not the way it's parsed. As it is, division is parsed as a division operation, even if it's not performed, so when it's not performed, it can't be part of other operations, and should throw an error.

RealDolos commented 3 years ago

Adding 1 + 1 would be surprising behavior I suppose. Still, "Operation on an invalid type" is a bit of a shit error message

matthew-dean commented 3 years ago

@RealDolos

Still, "Operation on an invalid type" is a bit of a shit error message

Please be kind. That's the error message thrown on other types if you attempt operations (with like a keyword for example). I only meant it should be throwing a proper error, and that's the current error message for operations.