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