You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
phase: "[string?] Phase keyword: 'source', 'defer', or null.",
5090
5122
imported_name: "[AST_SymbolImport] The name of the variable holding the module's default export.",
5091
5123
imported_names: "[AST_NameMapping*] The names of non-default imported variables",
5092
5124
module_name: "[AST_String] String literal describing where this module came from",
@@ -5127,6 +5159,40 @@ var AST_ImportMeta = DEFNODE("ImportMeta", null, function AST_ImportMeta(props)
5127
5159
$documentation: "A reference to import.meta",
5128
5160
});
5129
5161
5162
+
varAST_DynamicImport=DEFNODE(
5163
+
"DynamicImport",
5164
+
"phase args",
5165
+
functionAST_DynamicImport(props){
5166
+
if(props){
5167
+
this.phase=props.phase;
5168
+
this.args=props.args;
5169
+
this.start=props.start;
5170
+
this.end=props.end;
5171
+
}
5172
+
5173
+
this.flags=0;
5174
+
},
5175
+
{
5176
+
$documentation: "A phased dynamic import expression: `import.source(specifier [, options])` or `import.defer(specifier [, options])`. Plain `import(x)` continues to be parsed as an AST_Call with a synthetic `import` SymbolRef callee.",
5177
+
$propdoc: {
5178
+
phase: "[string] Phase keyword ('source' or 'defer').",
5179
+
args: "[AST_Node*] specifier followed by optional options argument"
0 commit comments