ampproject/rollup-plugin-closure-compiler

Closure compiler artifacts left in the minified bundle

Closed this issue · 10 comments

Repro can be found in this PR, you can check out complete output in my comment here.

Basically what I see are things like some kind of scope object gathering properties like

  • ASSUME_ES5
  • ASSUME_NO_NATIVE_MAP
  • ASSUME_NO_NATIVE_SET
  • getGlobal
  • SYMBOL_PREFIX
  • initSymbol
  • Symbol
  • ... and others.

I understand that this can be disabled with language_out: 'ECMASCRIPT_2015', but I'm wondering why this is not added in CJS case but is added for ESM? Could this be prevented altogether in the plugin itself? Without adding extra config like the mentioned language_out?

cc @TrySound

Taking a look at this. Will respond back by EOD tomorrow with changes or a clarification.

@Andarist Is it possible to get a smaller reproduction? Perhaps something with just the input that is expected to be minified with the options used?

I'll try to extract one in following days.

Here you go - https://github.com/Andarist/rollup-closure-symbol-repro

Couldn't repro it for a while because changing a function declaration to an arrow function expression causes the "polyfill bloat" to be added to both, keeping it as function declaration doesn't add the bloat to cjs output but adds it to esm.

EDIT:// some options passed to the closure plugin are irrelevant, dont have time to slim it down further now, those are exact options used by react

Taking a look. Thank you so much!

The issue for this particular example appears to be in transpilation of the export, which isn't removed (but we do add a statement to ensure the name isn't mangled so the export can be repaired after Closure Compiler is finished).

Transpilation is triggered in this example because the source is indicated to be exported as ES5.

Going to remove the export statements, and try to resolve.

Released 0.7.0 with the change. However, NPM went down right afterwards.

@Andarist – Confirmed fixed with 0.7.1.

Great job! Thanks

Cool! Thanks