Be sure to generate classes for empty structs

Closes #131
This commit is contained in:
Alex Crichton 2018-04-16 08:05:18 -07:00
parent f61e12af91
commit 5efde3abe9
4 changed files with 37 additions and 2 deletions

View File

@ -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(),

View File

@ -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) {

View File

@ -8,6 +8,7 @@ pub struct Program {
pub exports: Vec<Export>,
pub enums: Vec<Enum>,
pub imports: Vec<Import>,
pub structs: Vec<String>,
pub version: String,
pub schema_version: String,
}

View File

@ -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();
}