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
add support for source-phase imports (import source, import.source(...))
Implements the TC39 source-phase imports proposal (https://github.com/tc39/proposal-source-phase-imports) for both the static and dynamic forms:
// static
import source wasmModule from "./foo.wasm";
import defer * as ns from "./mod.js";
// dynamic
const m = await import.source("./foo.wasm");
const m = await import.defer("./mod.js");
The `source` phase tells the host to materialize the module's source
representation (e.g. a WebAssembly.Module for .wasm) instead of its
exports namespace; `defer` requests a lazily-evaluated namespace.
Dropping the phase keyword silently changes runtime semantics, which
is what terser was doing on the mozilla-AST round-trip used by tools
like Emscripten's acorn-optimizer.
Static side:
* Parser recognises the contextual `source` / `defer` phase keyword
after `import`, with peek-based disambiguation so existing patterns
like `import source from "x"` and `import defer, {y} from "x"`
keep parsing as default-name imports.
* AST_Import gains a `phase` field (null for plain imports).
* mozilla-ast from_moz / to_moz carry the phase across, matching the
shape produced by acorn-import-phases.
* Output prints the phase keyword between `import` and the specifier.
* equivalent-to includes phase in shallow_cmp.
Dynamic side:
* New AST_DynamicImport node used as the callee of an AST_Call
representing a phased dynamic import; carries the phase. Plain
dynamic `import(x)` continues to use the synthetic
AST_SymbolRef("import") callee for back-compat.
* Parser dispatches `import.source` / `import.defer` via a new
import_phase_call helper; they must be followed by a call, else
a parse error is raised, mirroring the proposal.
* mozilla-ast: from_moz ImportExpression builds the AST_DynamicImport
callee when M.phase is set; to_moz AST_Call emits a phased
ImportExpression { phase } when the callee is AST_DynamicImport.
* Output prints `import.source` / `import.defer` for the callee.
* size and equivalent-to updated.
Local bindings stay AST_SymbolImport / AST_SymbolRef, so scope,
mangle and drop_unused behave exactly as for ordinary imports.
This fork is on terser 4.8.0 which lacks `import.meta` parser
support, so the import_phase_call helper handles only `source` /
`defer` (the upstream terser PR includes `meta` dispatch too).
$documentation: "The callee of a dynamic `import(...)` / `import.source(...)` / `import.defer(...)` expression. Always appears as the `expression` of an AST_Call.",
885
+
$propdoc: {
886
+
phase: "[string?] Phase keyword ('source' or 'defer'), or null for a plain dynamic import."
0 commit comments