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

Do not inline IIFEs inside computed keys in classes that contain private fields #1514

Closed
nicolo-ribaudo opened this issue Mar 28, 2024 · 5 comments

Comments

@nicolo-ribaudo
Copy link

nicolo-ribaudo commented Mar 28, 2024

Bug report or Feature request?

Bug report? Not sure

Version (complete output of terser -V or specific git commit)

Whatever is at try.terser.org on 2024-03-28

Complete CLI command or minify() options used

{
  module: true,
  compress: {},
  mangle: {},
  output: {},
  parse: {},
  rename: {},
}

terser input

export class A {
  #x = 1;
  [(() => class {})()];
} 

terser output or error

export class A{#s=1;[class{}]}

Expected result

In all existing Firefox versions that support private fields, the original code works but the minified version throws due to a bug (https://bugzilla.mozilla.org/show_bug.cgi?id=1887677).

We received a bug report in Babel about the wrong output, so we are implementing a plugin to wrap computed keys in a IIFE if they contain a class. It would be great if terser didn't then strip the IIFE, making the code fixed by Babel break again :)

@nicolo-ribaudo
Copy link
Author

I also tried with

export class A {
  #x = 1;
  [/*@__NOINLINE__*/ (() => class {})()];
}

but the arrow function is still inlined.

@Conduitry
Copy link
Contributor

It sounds like that bug has just been fixed in the latest Firefox nightly, so I don't know how much value there is in trying to work around it now in Terser.

You may be able to prevent Terser from inlining this with the inline or reduce_funcs options, but I haven't tried this.

@nicolo-ribaudo
Copy link
Author

This is for Babel-generated code, so we cannot rely on specific Terser options (because we cannot force all users to use them).

Given that terser has even an option for Safari 10, I was assuming that the goal is not only to generate code that works in the latest version of browsers but also in older ones (I don't think an option makes sense in this case, since it's a very specific edge case and Terser could unconditionally leave that code as-is).

I'm willing to open a PR if it would be accepted.

@fabiosantoscode
Copy link
Collaborator

This isn't the first browser bug that pops up on computed keys, and often we don't need to optimize anything within, so I'm deoptimizing them.

@nicolo-ribaudo
Copy link
Author

Thank you!

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

3 participants