File tree 2 files changed +19
-14
lines changed
2 files changed +19
-14
lines changed Original file line number Diff line number Diff line change @@ -378,6 +378,15 @@ impl<'a> Context<'a> {
378
378
// function.
379
379
OutputMode :: NoModules { global } => {
380
380
js. push_str ( "const __exports = {};\n " ) ;
381
+ js. push_str ( "let script_src;\n " ) ;
382
+ js. push_str (
383
+ "\
384
+ if (typeof document === 'undefined') {
385
+ script_src = location.href;
386
+ } else {
387
+ script_src = document.currentScript.src;
388
+ }\n " ,
389
+ ) ;
381
390
js. push_str ( "let wasm;\n " ) ;
382
391
init = self . gen_init ( needs_manual_start, None ) ?;
383
392
footer. push_str ( & format ! (
@@ -712,13 +721,7 @@ impl<'a> Context<'a> {
712
721
) ,
713
722
OutputMode :: NoModules { .. } => "\
714
723
if (typeof input === 'undefined') {
715
- let src;
716
- if (typeof document === 'undefined') {
717
- src = location.href;
718
- } else {
719
- src = document.currentScript.src;
720
- }
721
- input = src.replace(/\\ .js$/, '_bg.wasm');
724
+ input = script_src.replace(/\\ .js$/, '_bg.wasm');
722
725
}"
723
726
. to_string ( ) ,
724
727
_ => "" . to_string ( ) ,
Original file line number Diff line number Diff line change @@ -258,17 +258,19 @@ fn default_module_path_target_no_modules() {
258
258
cmd. assert ( ) . success ( ) ;
259
259
let contents =
260
260
fs:: read_to_string ( out_dir. join ( "default_module_path_target_no_modules.js" ) ) . unwrap ( ) ;
261
+ assert ! ( contents. contains(
262
+ "\
263
+ if (typeof document === 'undefined') {
264
+ script_src = location.href;
265
+ } else {
266
+ script_src = document.currentScript.src;
267
+ }" ,
268
+ ) ) ;
261
269
assert ! ( contents. contains(
262
270
"\
263
271
async function init(input) {
264
272
if (typeof input === 'undefined') {
265
- let src;
266
- if (typeof document === 'undefined') {
267
- src = location.href;
268
- } else {
269
- src = document.currentScript.src;
270
- }
271
- input = src.replace(/\\ .js$/, '_bg.wasm');
273
+ input = script_src.replace(/\\ .js$/, '_bg.wasm');
272
274
}" ,
273
275
) ) ;
274
276
}
You can’t perform that action at this time.
0 commit comments