@@ -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