Closed loilo closed 7 years ago
Thanks — it was doing an overly naive check to see if it needed to overwrite the operator or not.
"any_string" +(++1)
isn't valid JS, which is why Acorn fails to parse it in the first place — not actually a bug on Butternut's part. Uglify's parser is being a little bit too lenient here, but I don't think it's really at fault since the code would never have run in the first place (@kzc let me know if you want me to raise an issue anyway, don't know what your stance is on things like that).
Mh, I actually didn't realize that. So this is in fact a bug in the concerning library in the first place (see here).
Well, then Butternut's behaviour is fine I guess.
Uglify's parser is being a little bit too lenient here, but I don't think it's really at fault since the code would never have run in the first place
Garbage in/garbage out is fine as long as it preserves the error in the original code.
@Loilo Recent versions of uglify trap this error:
$ bin/uglifyjs -V
uglify-js 3.0.8
$ echo '"any_string" +(++1)' | bin/uglifyjs
Parse error at 0:1,15
"any_string" +(++1)
^
ERROR: Invalid use of ++ operator
Hum. Then I should probably stop using version 2 for reference.
There are still back ports of bug fixes to from 3.x to 2.x. But that third party online tool could be using a very old version of uglify.
From trying to squash minified atmosphere.
In the following example, Butternut removes the parantheses around the incrementation without any compensation, resulting in three subsequent
+
characters.Input:
Output Butternut:
Output UglifyJS:
Another issue will occur when the incremented value is not a variable but a string/number literal.
Input:
Error Butternut:
Output UglifyJS:
Side note: The whitespace before the concatenating
+
is also kept in output. It could safely be removed for a slightly better result.