Skip to content

Commit febb4fd

Browse files
committed
fixup
1 parent eddcf3b commit febb4fd

6 files changed

Lines changed: 35 additions & 13 deletions

test/js_optimizer/applyDCEGraphRemovals-esm-output.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ import { memory, main as _main, used_export as _used_export, memory as wasmMemor
99
export { fd_write_impl as fd_write, fd_close_impl as fd_close };
1010

1111
export { _main };
12+
13+
var HEAP32;
14+
15+
export { HEAP32 };

test/js_optimizer/applyDCEGraphRemovals-esm.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ export {
2727

2828
export { _main };
2929

30+
// MODULARIZE=instance runtime exports (bare form) must be left untouched.
31+
var HEAP32;
32+
export { HEAP32 };
33+
3034
// EXTRA_INFO: { "unusedImports": ["unused_import"], "unusedExports": ["unused_export", "__indirect_function_table"] }

test/js_optimizer/applyImportAndExportNameChanges-esm-output.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ import { memory, b as _main, c as _malloc, memory as wasmMemory } from "./a.out.
77
export { fd_write_impl as d, fd_close_impl as e };
88

99
export { _main };
10+
11+
var HEAP32;
12+
13+
export { HEAP32 };

test/js_optimizer/applyImportAndExportNameChanges-esm.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ export {
2323
// Re-export of a wasm export: the local name (_main) is never in the mapping.
2424
export { _main };
2525

26+
// MODULARIZE=instance runtime export (bare form): never in the mapping.
27+
var HEAP32;
28+
export { HEAP32 };
29+
2630
// EXTRA_INFO: { "mapping": { "main": "b", "malloc": "c", "fd_write": "d", "fd_close": "e" } }

test/js_optimizer/emitDCEGraph-esm.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export {
3838
// root the underlying `main` export, not be treated as a wasm import.
3939
export { _main };
4040

41+
// MODULARIZE=instance runtime exports. These are plain JS bindings, not wasm
42+
// import edges, and must be left untouched (bare `export {..}` form).
43+
var HEAP32;
44+
var baz = () => {};
45+
export { HEAP32, baz };
46+
4147
// Top-level uses: root the memory export (via the alias) and one wasm export.
4248
wasmMemory.buffer;
4349
_used_export();

tools/acorn-optimizer.mjs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -719,22 +719,22 @@ function emitDCEGraph(ast) {
719719
// top-level uses (that would root every export and defeat DCE).
720720
emptyOut(node);
721721
} else if (isExportSpecifierList(node)) {
722-
// WASM_ESM_INTEGRATION emits two sourceless `export {..}` forms:
722+
// Sourceless `export {..}` statements come in three forms:
723723
// (a) JS functions sent to wasm: export { _fd_write as fd_write };
724724
// (b) re-exports of wasm exports: export { _main };
725-
// (a) are the wasm imports; (b) are ordinary top-level uses that should
726-
// root the underlying export (handled in the second pass), so only (a)
727-
// is recorded and removed here.
728-
let isImportEdge = false;
729-
node.specifiers.forEach((spec) => {
730-
if (wasmExportLocals.has(spec.local.name)) {
731-
return; // (b) re-export of a wasm export
732-
}
725+
// (c) runtime/library exports: export { HEAP32, baz };
726+
// Only (a) are wasm import edges (recorded and removed here). (b) and
727+
// (c) are ordinary top-level uses left in place to root in the second
728+
// pass. (a) is the only form written with an alias (`x as y`), which
729+
// acorn represents with distinct local/exported nodes; bare specifiers
730+
// reuse a single node for both sides.
731+
const importEdges = node.specifiers.filter(
732+
(spec) =>
733+
spec.local !== spec.exported && !wasmExportLocals.has(spec.local.name),
734+
);
735+
if (importEdges.length) {
733736
// (a) `export { jsName as nativeName }` - jsName implements the import.
734-
imports.push([spec.local.name, spec.exported.name]);
735-
isImportEdge = true;
736-
});
737-
if (isImportEdge) {
737+
importEdges.forEach((spec) => imports.push([spec.local.name, spec.exported.name]));
738738
foundWasmImportsAssign = true;
739739
emptyOut(node); // does not root; second pass ignores it
740740
}

0 commit comments

Comments
 (0)