From cc9a2195aca533f0bb701e6fb888dca3517470a3 Mon Sep 17 00:00:00 2001 From: Benjamin Bradshaw Date: Wed, 20 Dec 2023 09:54:33 -0600 Subject: [PATCH] Fix JS shim default path detection for the no-modules target (#3748) --- CHANGELOG.md | 5 +++++ crates/cli-support/src/js/mod.rs | 2 +- crates/cli/tests/wasm-bindgen/main.rs | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7f4343d59c..8929a240823 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ ## [Unreleased](https://github.com/rustwasm/wasm-bindgen/compare/0.2.89...main) +### Fixed + +* Fix JS shim default path detection for the no-modules target. + [#3748](https://github.com/rustwasm/wasm-bindgen/pull/3748) + ### Added * Add bindings for `RTCRtpSender.getCapabilities(DOMString)` method, `RTCRtpCapabilities`, `RTCRtpCodecCapability` and `RTCRtpHeaderExtensionCapability`. diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 57ff8f14f13..7a4ffbfd352 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -717,7 +717,7 @@ impl<'a> Context<'a> { stem = self.config.stem()? ), OutputMode::NoModules { .. } => "\ - if (typeof input === 'undefined' && script_src !== 'undefined') { + if (typeof input === 'undefined' && typeof script_src !== 'undefined') { input = script_src.replace(/\\.js$/, '_bg.wasm'); }" .to_string(), diff --git a/crates/cli/tests/wasm-bindgen/main.rs b/crates/cli/tests/wasm-bindgen/main.rs index f2502d8c313..b15a053d375 100644 --- a/crates/cli/tests/wasm-bindgen/main.rs +++ b/crates/cli/tests/wasm-bindgen/main.rs @@ -364,7 +364,7 @@ fn default_module_path_target_no_modules() { async function __wbg_init(input) { if (wasm !== undefined) return wasm; - if (typeof input === 'undefined' && script_src !== 'undefined') { + if (typeof input === 'undefined' && typeof script_src !== 'undefined') { input = script_src.replace(/\\.js$/, '_bg.wasm'); }", ));