@@ -13,6 +13,11 @@ import {
13
13
CommonFlags
14
14
} from "../common" ;
15
15
16
+ import {
17
+ runtimeFunctions ,
18
+ runtimeGlobals
19
+ } from "../compiler" ;
20
+
16
21
import {
17
22
ElementKind ,
18
23
Element ,
@@ -945,19 +950,31 @@ export class JSBuilder extends ExportsWalker {
945
950
assert ( this . indentLevel == 0 ) ;
946
951
947
952
if ( this . esm ) {
948
- sb . push ( "export const {\n" ) ;
953
+ sb . push ( "export const {\n" ) ;
949
954
if ( this . program . options . exportMemory ) {
950
- sb . push ( "memory,\n" ) ;
955
+ sb . push ( "memory,\n" ) ;
951
956
}
952
957
if ( this . program . options . exportTable ) {
953
- sb . push ( "table,\n " ) ;
958
+ sb . push ( " table,\n" ) ;
959
+ }
960
+ if ( this . program . options . exportRuntime ) {
961
+ for ( let i = 0 , k = runtimeFunctions . length ; i < k ; ++ i ) {
962
+ sb . push ( " " ) ;
963
+ sb . push ( runtimeFunctions [ i ] ) ;
964
+ sb . push ( ",\n" ) ;
965
+ }
966
+ for ( let i = 0 , k = runtimeGlobals . length ; i < k ; ++ i ) {
967
+ sb . push ( " " ) ;
968
+ sb . push ( runtimeGlobals [ i ] ) ;
969
+ sb . push ( ",\n" ) ;
970
+ }
954
971
}
955
972
for ( let i = 0 , k = exports . length ; i < k ; ++ i ) {
956
- if ( i > 0 ) sb . push ( ",\n " ) ;
973
+ sb . push ( " " ) ;
957
974
sb . push ( exports [ i ] ) ;
975
+ sb . push ( ",\n" ) ;
958
976
}
959
- sb . push ( `
960
- } = await (async url => instantiate(
977
+ sb . push ( `} = await (async url => instantiate(
961
978
await (async () => {
962
979
try { return await globalThis.WebAssembly.compileStreaming(globalThis.fetch(url)); }
963
980
catch { return globalThis.WebAssembly.compile(await (await import("node:fs/promises")).readFile(url)); }
0 commit comments