Commit ec4927c
committed
Support source-phase imports in the acorn/terser optimizer pipeline
When -sSOURCE_PHASE_IMPORTS=1, emcc emits
```js
import source wasmModule from './foo.wasm';
```
in its JS runtime. At -O2/-O3/-Os/-Oz the emitted JS is run through
tools/acorn-optimizer.mjs which currently fails with a SyntaxError at
parse time because acorn 8.x does not yet understand the source-phase
imports proposal (https://github.com/tc39/proposal-source-phase-imports).
Wire in the acorn-import-phases plugin so acorn can parse the syntax,
and pull in the matching terser support (downstream of emscripten-core/terser#1)
so the round-trip through from_mozilla_ast / to_mozilla_ast preserves
the `phase` keyword on the way back out. Without the terser side,
terser would silently drop the keyword and the host would return the
module's exports namespace instead of a WebAssembly.Module, changing
runtime semantics.
* package.json: add acorn-import-phases dependency.
* tools/acorn-optimizer.mjs: extend acorn with the plugin and use the
extended parser at the parse site.
* third_party/terser/terser.js: rebuilt from the emscripten-core/terser
branch with source-phase imports support (PR
emscripten-core/terser#1, the v5.18.2
downstream port of upstream terser PR
terser/terser#1682).
* test/js_optimizer/sourcePhaseImports{,-output}.js: new fixture that
feeds two `import source` declarations through the JSDCE pass and
checks the keyword survives.
* test/test_other.py: register the fixture in test_js_optimizer, and
parametrize test_esm_source_phase_imports across no-args and -O2 to
exercise the optimizer pipeline.1 parent 85ee810 commit ec4927c
8 files changed
Lines changed: 175 additions & 36 deletions
File tree
- test
- js_optimizer
- third_party/terser
- tools
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
424 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
425 | 429 | | |
426 | 430 | | |
427 | 431 | | |
428 | | - | |
| 432 | + | |
429 | 433 | | |
430 | 434 | | |
431 | 435 | | |
| |||
3012 | 3016 | | |
3013 | 3017 | | |
3014 | 3018 | | |
| 3019 | + | |
3015 | 3020 | | |
3016 | 3021 | | |
3017 | 3022 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
0 commit comments