Skip to content

Commit 7f55067

Browse files
authored
Merge pull request #1617 from alexcrichton/fix-gc
Be sure to GC our imports as well as the module
2 parents a1fc270 + 2e03961 commit 7f55067

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,18 @@ impl<'a> Context<'a> {
204204
// After all we've done, especially
205205
// `unexport_unused_internal_exports()`, we probably have a bunch of
206206
// garbage in the module that's no longer necessary, so delete
207-
// everything that we don't actually need.
207+
// everything that we don't actually need. Afterwards make sure we don't
208+
// try to emit bindings for now-nonexistent imports by pruning our
209+
// `wasm_import_definitions` set.
208210
walrus::passes::gc::run(self.module);
211+
let remaining_imports = self
212+
.module
213+
.imports
214+
.iter()
215+
.map(|i| i.id())
216+
.collect::<HashSet<_>>();
217+
self.wasm_import_definitions
218+
.retain(|id, _| remaining_imports.contains(id));
209219

210220
// Cause any future calls to `should_write_global` to panic, making sure
211221
// we don't ask for items which we can no longer emit.

crates/cli/tests/wasm-bindgen/main.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,18 @@ fn works_on_empty_project() {
136136
}
137137

138138
mod npm;
139+
140+
#[test]
141+
fn one_export_works() {
142+
let (mut cmd, _out_dir) = Project::new("one_export_works")
143+
.file(
144+
"src/lib.rs",
145+
r#"
146+
use wasm_bindgen::prelude::*;
147+
#[wasm_bindgen]
148+
pub fn foo() {}
149+
"#,
150+
)
151+
.wasm_bindgen("");
152+
cmd.assert().success();
153+
}

0 commit comments

Comments
 (0)