Only generate JS class constructor export if import is needed

This commit is contained in:
David Flemström 2018-04-03 11:10:15 +02:00
parent 86625e78bc
commit 540ccfac9d

View File

@ -267,10 +267,14 @@ impl<'a> Context<'a> {
"));
ts_dst.push_str("constructor(ptr: number, sym: Symbol);\n");
let new_name = shared::new_function(&class);
if self.wasm_import_needed(&new_name) {
self.globals.push_str(&format!("
export function {new_name}(ptr) {{
return addHeapObject(new {class}(ptr, token));
}}", new_name=shared::new_function(&class), class=class));
}}
", new_name = new_name, class = class));
}
} else {
dst.push_str(&format!("
constructor(ptr) {{
@ -279,10 +283,14 @@ impl<'a> Context<'a> {
"));
ts_dst.push_str("constructor(ptr: number);\n");
let new_name = shared::new_function(&class);
if self.wasm_import_needed(&new_name) {
self.globals.push_str(&format!("
export function {new_name}(ptr) {{
return addHeapObject(new {class}(ptr));
}}", new_name=shared::new_function(&class), class=class));
}}
", new_name = new_name, class = class));
}
}
dst.push_str(&format!("