Skip to content

Commit

Permalink
chore: define import object as interface and not namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardomourar committed Feb 17, 2023
1 parent 7a4e9ca commit 68340b9
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions crates/js-component-bindgen/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl JsBindgen {
*/
export function instantiate(
compileCore: (path: string, imports: Record<string, any>) => Promise<WebAssembly.Module>,
imports: typeof ImportObject,
imports: ImportObject,
instantiateCore?: (module: WebAssembly.Module, imports: Record<string, any>) => Promise<WebAssembly.Instance>
): Promise<typeof {camel}>;
",
Expand Down Expand Up @@ -406,11 +406,10 @@ impl JsBindgen {
files,
AbiVariant::GuestImport,
);
let upper_camel = name.to_upper_camel_case();
let lower_camel = name.to_lower_camel_case();
let camel = name.to_upper_camel_case();
uwriteln!(
self.import_object,
"declare const {lower_camel}: typeof {upper_camel}Imports;"
"'{name}': typeof {camel}Imports,"
);
}

Expand Down Expand Up @@ -479,7 +478,7 @@ impl JsBindgen {
// per-imported-interface where the type of that field is defined by the
// interface itself.
if self.opts.instantiation {
uwriteln!(self.src.ts, "export namespace ImportObject {{");
uwriteln!(self.src.ts, "export interface ImportObject {{");
self.src.ts(&self.import_object);
uwriteln!(self.src.ts, "}}");
}
Expand Down Expand Up @@ -510,20 +509,6 @@ impl JsBindgen {
WorldItem::Type(_) => unimplemented!("type imports"),
}
}
// We will be following the ECMA262 normative:
// https://github.com/tc39/ecma262/pull/2154
uwriteln!(self.import_object, "export {{");
for (name, import) in world.imports.iter() {
match import {
WorldItem::Function(_) => {}
WorldItem::Interface(_) => {
let camel = name.to_lower_camel_case();
uwriteln!(self.import_object, "{camel} as '{name}',");
}
WorldItem::Type(_) => {}
}
}
uwriteln!(self.import_object, "}};");
if !funcs.is_empty() {
self.import_funcs(resolve, id, &funcs, files);
}
Expand Down

0 comments on commit 68340b9

Please sign in to comment.