esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Destructuring bug in Safari when renamed parameter property is identical to the function name

Open kripod opened this issue 1 year ago • 4 comments

Trying swc in debug mode with env.targets set to browserslist("defaults") and env.bugfixes enabled, I noticed the transform ‘bugfix/transform-safari-id-destructuring-collision-in-function-expression’ being applied.

Looking up the corresponding docs of Babel, I figured the following snippet throws a SyntaxError up until Safari 16.2 as per this bug report:

let b = function a({ test: a }) { console.log(a); };

Running esbuild on the code, it appears the project doesn’t apply a fix like Babel or swc does.

Please consider implementing a workaround as applied by Babel:

let b = function a({ test: _a }) { console.log(_a); };

Thank you in advance!

kripod avatar May 27 '24 03:05 kripod

esbuild has nothing to do with swc ...

jerome-benoit avatar Jul 03 '24 20:07 jerome-benoit

esbuild has nothing to do with swc ...

My main point is that contrary to swc and Babel, esbuild doesn’t have a transform available which fixes a Safari bug. While I appreciate the versatility of esbuild, I wanted to highlight how other transpilers have this readily available in comparison.

kripod avatar Jul 03 '24 21:07 kripod

Dunno how the maintainer deal with JS runtime bug in shipped version and workaround. But it looks like a lot of work to maintain a list of transform quirks given the JS runtime and the target.

If I were maintaining such a piece of code, I would not implement each known transform quirks for the sake of transpilation consistency, but instead abstract out the quirk code pattern detection (internal AST/CST/... representation), the minimal condition triggering it from the bundling options and the associated warning message to display a workaround it in a data structure. And that's still quite some work ...

jerome-benoit avatar Jul 03 '24 22:07 jerome-benoit

I haven't closed this because this could theoretically be something that esbuild deals with. The --target= setting supports Safari versions and uses it for platform-specific syntax compatibility stuff, so esbuild does have enough information to do this.

However, this is very low priority for me because it seems like just a theoretical concern. If you minify your code (which everyone should when shipping production code to a browser), then the function name is completely removed because it's unused, so I'd expect this bug to never occur in production code.

Is there a real case of someone's production code triggering this bug somehow? Do you have a link to such a bug report? Or is this just a theoretical concern?

evanw avatar Jul 04 '24 13:07 evanw