diff --git a/crates/backend/src/ast.rs b/crates/backend/src/ast.rs index cc3829c0..7e5e1f1e 100644 --- a/crates/backend/src/ast.rs +++ b/crates/backend/src/ast.rs @@ -415,6 +415,7 @@ impl Program { pub fn shared(&self) -> shared::Program { shared::Program { exports: self.exports.iter().map(|a| a.shared()).collect(), + structs: self.structs.iter().map(|a| a.name.as_ref().to_string()).collect(), enums: self.enums.iter().map(|a| a.shared()).collect(), imports: self.imports.iter().map(|a| a.shared()).collect(), version: shared::version(), diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 5dc94bfa..18362654 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -1279,6 +1279,11 @@ impl<'a, 'b> SubContext<'a, 'b> { for e in self.program.enums.iter() { self.generate_enum(e); } + for s in self.program.structs.iter() { + self.cx.exported_classes + .entry(s.clone()) + .or_insert_with(Default::default); + } } pub fn generate_export(&mut self, export: &shared::Export) { diff --git a/crates/shared/src/lib.rs b/crates/shared/src/lib.rs index b46f806b..a3836391 100644 --- a/crates/shared/src/lib.rs +++ b/crates/shared/src/lib.rs @@ -8,6 +8,7 @@ pub struct Program { pub exports: Vec, pub enums: Vec, pub imports: Vec, + pub structs: Vec, pub version: String, pub schema_version: String, } diff --git a/tests/all/classes.rs b/tests/all/classes.rs index ad3b181c..b388a5df 100644 --- a/tests/all/classes.rs +++ b/tests/all/classes.rs @@ -367,8 +367,6 @@ fn pass_into_js_as_js_class() { .test(); } - - #[test] fn constructors() { project() @@ -445,3 +443,33 @@ fn constructors() { "#) .test(); } + +#[test] +fn empty_structs() { + project() + .debug(false) + .file("src/lib.rs", r#" + #![feature(proc_macro, wasm_custom_section, wasm_import_module)] + + extern crate wasm_bindgen; + + use wasm_bindgen::prelude::*; + + #[wasm_bindgen] + pub struct MissingClass {} + + #[wasm_bindgen] + pub struct Other {} + + #[wasm_bindgen] + impl Other { pub fn return_a_value() -> MissingClass { MissingClass {} } } + "#) + .file("test.ts", r#" + import { Other } from "./out"; + + export function test() { + Other.return_a_value(); + } + "#) + .test(); +}