From 540ccfac9d85cf81a34627784aeda89f23e20ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Flemstr=C3=B6m?= Date: Tue, 3 Apr 2018 11:10:15 +0200 Subject: [PATCH] Only generate JS class constructor export if import is needed --- crates/cli-support/src/js.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/crates/cli-support/src/js.rs b/crates/cli-support/src/js.rs index a22288f26..dd3286895 100644 --- a/crates/cli-support/src/js.rs +++ b/crates/cli-support/src/js.rs @@ -267,10 +267,14 @@ impl<'a> Context<'a> { ")); ts_dst.push_str("constructor(ptr: number, sym: Symbol);\n"); - self.globals.push_str(&format!(" - export function {new_name}(ptr) {{ - return addHeapObject(new {class}(ptr, token)); - }}", new_name=shared::new_function(&class), class=class)); + 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 = 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"); - self.globals.push_str(&format!(" - export function {new_name}(ptr) {{ - return addHeapObject(new {class}(ptr)); - }}", new_name=shared::new_function(&class), class=class)); + 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 = new_name, class = class)); + } } dst.push_str(&format!("