Rich-Harris / butternut

The fast, future-friendly minifier

Home Page:https://butternut.now.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: Numbers with attached methods

loilo opened this issue · comments

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()

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();