Rich-Harris / butternut

The fast, future-friendly minifier
https://butternut.now.sh
MIT License
1.17k stars 17 forks source link

Bug: Numbers with attached methods #126

Closed loilo closed 7 years ago

loilo commented 7 years ago

Error from squashing the minified aight source.

Long story short: Butternut rewrites non-decimals to decimals. If there were method calls on the non-decimals (without surrounding parantheses), they will be kept. This leads to invalid syntax.

Input:

0x0.toFixed()

Output Butternut:

0.toFixed()

Output UglifyJS:

0..toFixed()

EDIT: It's actually not just non-decimals. Numbers in general get their necessary surroundings removed:

Input:

(1).toFixed()

Output Butternut:

1.toFixed()

Output UglifyJS:

1..toFixed()
loilo commented 7 years ago

This still occurs with negative numbers.

Basic example

Input:

(-2).toFixed()

Output Butternut 0.4.6:

(-2)..toFixed()

Output UglifyJS 3.0.8:

(-2).toFixed();

Example with extended Number prototype

As used in Turf.js.

Input:

(-2).toRadians()

Output Butternut 0.4.6:

-2.toRadians()

Output UglifyJS 3.0.8:

(-2).toRadians();