@@ -406,6 +406,11 @@ function addMissingLibraryStubs(unusedLibSymbols) {
406406}
407407
408408function exportSymbol ( name ) {
409+ if ( WASM_ESM_INTEGRATION ) {
410+ // In ESM integration mode symbols are exported by being included in
411+ // an export { foo, bar } list so we build up the simple list of names
412+ return name ;
413+ }
409414 if ( MODULARIZE === 'instance' ) {
410415 return `__exp_${ name } = ${ name } ;` ;
411416 }
@@ -416,10 +421,13 @@ function exportSymbol(name) {
416421function exportRuntimeSymbols ( ) {
417422 // optionally export something.
418423 function maybeExport ( name ) {
419- // If requested to be exported, export it. HEAP objects are exported
420- // separately in updateMemoryViews
421- if ( EXPORTED_RUNTIME_METHODS . has ( name ) && ! name . startsWith ( 'HEAP' ) ) {
422- return exportSymbol ( name ) ;
424+ // If requested to be exported, export it.
425+ if ( EXPORTED_RUNTIME_METHODS . has ( name ) ) {
426+ // Unless we are in WASM_ESM_INTEGRATION mode then HEAP objects are
427+ // exported separately in updateMemoryViews
428+ if ( WASM_ESM_INTEGRATION || ! name . startsWith ( 'HEAP' ) ) {
429+ return exportSymbol ( name ) ;
430+ }
423431 }
424432 }
425433
@@ -518,6 +526,10 @@ function exportRuntimeSymbols() {
518526 const exports = runtimeElements . map ( maybeExport ) ;
519527 const results = exports . filter ( ( name ) => name ) ;
520528
529+ if ( WASM_ESM_INTEGRATION ) {
530+ return '// Runtime exports\nexport { ' + results . join ( ', ' ) + ' };\n' ;
531+ }
532+
521533 if ( ASSERTIONS && ! EXPORT_ALL ) {
522534 // in ASSERTIONS mode we show a useful error if it is used without being
523535 // exported. See `unexportedRuntimeSymbol` in runtime_debug.js.
@@ -563,7 +575,7 @@ function exportLibrarySymbols() {
563575function exportJSSymbols ( ) {
564576 // In WASM_ESM_INTEGRATION mode JS library symbols are marked with `export`
565577 // at the point of declaration.
566- if ( WASM_ESM_INTEGRATION ) return '' ;
578+ if ( WASM_ESM_INTEGRATION ) return exportRuntimeSymbols ( ) ;
567579 return exportRuntimeSymbols ( ) + ' ' + exportLibrarySymbols ( ) ;
568580}
569581
0 commit comments