@@ -197,8 +197,9 @@ impl<'a> Context<'a> {
197
197
) -> Result < ( String , String ) , Error > {
198
198
let mut ts = self . typescript . clone ( ) ;
199
199
let mut js = String :: new ( ) ;
200
- if self . config . mode . no_modules ( ) {
201
- js. push_str ( "(function() {\n " ) ;
200
+
201
+ if let OutputMode :: NoModules { global } = & self . config . mode {
202
+ js. push_str ( & format ! ( "let {};\n (function() {{\n " , global) ) ;
202
203
}
203
204
204
205
// Depending on the output mode, generate necessary glue to actually
@@ -215,7 +216,7 @@ impl<'a> Context<'a> {
215
216
js. push_str ( "let wasm;\n " ) ;
216
217
init = self . gen_init ( needs_manual_start, None ) ?;
217
218
footer. push_str ( & format ! (
218
- "self. {} = Object.assign(init, __exports);\n " ,
219
+ "{} = Object.assign(init, __exports);\n " ,
219
220
global
220
221
) ) ;
221
222
}
@@ -441,10 +442,10 @@ impl<'a> Context<'a> {
441
442
"\
442
443
if (typeof module === 'undefined') {
443
444
let src;
444
- if (self. document === undefined) {
445
- src = self. location.href;
445
+ if (document === undefined) {
446
+ src = location.href;
446
447
} else {
447
- src = self. document.currentScript.src;
448
+ src = document.currentScript.src;
448
449
}
449
450
module = src.replace(/\\ .js$/, '_bg.wasm');
450
451
}"
0 commit comments