privatenumber / esbuild-loader

💠 Speed up your Webpack with esbuild ⚡️
MIT License
3.58k stars 106 forks source link

Cloudflare breaks the minimized code #371

Closed OverLord561 closed 5 months ago

OverLord561 commented 5 months ago

Problem with minification

Hi! I have a code like this and the problem is with (0.0) minimization (0.0).toLocaleString('en-US', { style: 'currency', currency: 'USD' }).replace('0.00', ''); it will be minified to 0 .toLocaleString('en-US', { style: 'currency', currency: 'USD' }).replace('0.00', '');

There is the whitespace after 0 before .toLocaleString

Later Cf-Bgj: minify feature of Cloudflare will remove whitespace before toLocaleString 0.toLocaleString('en-US', { style: 'currency', currency: 'USD' }).replace('0.00', '');

which cause Uncaught SyntaxError: Invalid or unexpected token

Expected behavior

Default behaviour like in Terser when number is wrapped into brackets (0).toLocaleString('en-US', { style: 'currency', currency: 'USD' }).replace('0.00', '');

Minimal reproduction URL

https://stackblitz.com/edit/vitejs-vite-tha46h?file=currency.js

Version

Chrome Version 124.0.6367.119 (Official Build) (64-bit)

Node.js version

20.11

Package manager

pnpm

Operating system

Linux

Contributions

privatenumber commented 5 months ago

Please search first: https://github.com/privatenumber/esbuild-loader/issues/349

OverLord561 commented 5 months ago

Thank you very much!

Going to post the issue here https://github.com/evanw/esbuild.

privatenumber commented 5 months ago

But isn't Cloudflare the one with the bug in their JS engine?