Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be sure to GC our imports as well as the module #1617

Merged
merged 1 commit into from
Jun 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,18 @@ impl<'a> Context<'a> {
// After all we've done, especially
// `unexport_unused_internal_exports()`, we probably have a bunch of
// garbage in the module that's no longer necessary, so delete
// everything that we don't actually need.
// everything that we don't actually need. Afterwards make sure we don't
// try to emit bindings for now-nonexistent imports by pruning our
// `wasm_import_definitions` set.
walrus::passes::gc::run(self.module);
let remaining_imports = self
.module
.imports
.iter()
.map(|i| i.id())
.collect::<HashSet<_>>();
self.wasm_import_definitions
.retain(|id, _| remaining_imports.contains(id));

// Cause any future calls to `should_write_global` to panic, making sure
// we don't ask for items which we can no longer emit.
Expand Down
15 changes: 15 additions & 0 deletions crates/cli/tests/wasm-bindgen/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,18 @@ fn works_on_empty_project() {
}

mod npm;

#[test]
fn one_export_works() {
let (mut cmd, _out_dir) = Project::new("one_export_works")
.file(
"src/lib.rs",
r#"
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn foo() {}
"#,
)
.wasm_bindgen("");
cmd.assert().success();
}