Skip to content

Commit 91f0dbd

Browse files
authored
Removing self from no-modules target (#1995)
1 parent 0f3c53b commit 91f0dbd

File tree

1 file changed

+7
-6
lines changed
  • crates/cli-support/src/js

1 file changed

+7
-6
lines changed

crates/cli-support/src/js/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ impl<'a> Context<'a> {
197197
) -> Result<(String, String), Error> {
198198
let mut ts = self.typescript.clone();
199199
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));
202203
}
203204

204205
// Depending on the output mode, generate necessary glue to actually
@@ -215,7 +216,7 @@ impl<'a> Context<'a> {
215216
js.push_str("let wasm;\n");
216217
init = self.gen_init(needs_manual_start, None)?;
217218
footer.push_str(&format!(
218-
"self.{} = Object.assign(init, __exports);\n",
219+
"{} = Object.assign(init, __exports);\n",
219220
global
220221
));
221222
}
@@ -441,10 +442,10 @@ impl<'a> Context<'a> {
441442
"\
442443
if (typeof module === 'undefined') {
443444
let src;
444-
if (self.document === undefined) {
445-
src = self.location.href;
445+
if (document === undefined) {
446+
src = location.href;
446447
} else {
447-
src = self.document.currentScript.src;
448+
src = document.currentScript.src;
448449
}
449450
module = src.replace(/\\.js$/, '_bg.wasm');
450451
}"

0 commit comments

Comments
 (0)