google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.31k stars 1.15k forks source link

Support es6 exports from --entry_point #4167

Open KimlikDAO-bot opened 1 month ago

KimlikDAO-bot commented 1 month ago

Support export statements from the entry point file. This will enable many requested features such as

while giving the user precise control.

Given a file

// entry.js
import { m1, m2 } from "./mod"
...
...
export { sym1, ..., symN }
export default symDefault;

When compiled with

google-closure-compiler -O ADVANCED --js mod.js entry.js --entry_point entry.js --module_resolution NODE

should output a file containing export { sym1, ..., symN, symDefault as default}.

Currently, this behavior can be achieved by assigning each exported symbol to globalThis in a preprocessing step and then replacing each such assignment in the compiled file to an export statement in a postprocessing step.