Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support object index minify #2214

Closed
LeuisKen opened this issue Apr 28, 2022 · 1 comment
Closed

support object index minify #2214

LeuisKen opened this issue Apr 28, 2022 · 1 comment

Comments

@LeuisKen
Copy link

input case:

var arguments=[];(function(){console.log(arguments["1"])})("bar",42);

esbuild output:

var arguments=[];(function(){console.log(arguments["1"])})("bar",42);

terser output:

var arguments=[];!function(){console.log(arguments[1])}("bar",42);

By diff this cases, we could find terser could minify the index, and use ! instead of () to save more bytes. I find the index minify source code is here: https://github.com/terser/terser/blob/master/lib/compress/index.js#L4128

I hope esbuild could support this like terser to make the minification better.

@evanw evanw closed this as completed in 99744d6 May 26, 2022
@evanw
Copy link
Owner

evanw commented May 26, 2022

I added minification of integers inside computed property strings. Doing other non-integer numbers seems risky because esbuild is implemented in Go and Go's number-to-string algorithm could hypothetically be slightly different than JavaScript's in subtle ways, which could potentially cause a miscompilation. I declined to do the () to ! transformation because it's typically a very, very small win and doing it correctly adds code complexity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants