File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -204,8 +204,18 @@ impl<'a> Context<'a> {
204
204
// After all we've done, especially
205
205
// `unexport_unused_internal_exports()`, we probably have a bunch of
206
206
// 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.
208
210
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) ) ;
209
219
210
220
// Cause any future calls to `should_write_global` to panic, making sure
211
221
// we don't ask for items which we can no longer emit.
Original file line number Diff line number Diff line change @@ -136,3 +136,18 @@ fn works_on_empty_project() {
136
136
}
137
137
138
138
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
+ }
You can’t perform that action at this time.
0 commit comments