Skip to content

Commit

Permalink
fix: invalid names in import object (#30)
Browse files Browse the repository at this point in the history
* fix: invalid names in import object

This prepares the ground for when TypeScript will have
support for "Arbitrary module namespace
identifier names":
microsoft/TypeScript#40594

* chore: define import object as interface and not namespace

---------

Co-authored-by: Eduardo Rodrigues <eduardomourar@users.noreply.github.com>
Co-authored-by: Guy Bedford <gbedford@fastly.com>
  • Loading branch information
3 people authored Feb 17, 2023
1 parent bc767da commit 4f96f97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 77 deletions.
76 changes: 5 additions & 71 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 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 @@ -407,10 +407,7 @@ impl JsBindgen {
AbiVariant::GuestImport,
);
let camel = name.to_upper_camel_case();
uwriteln!(
self.import_object,
"export const {name}: typeof {camel}Imports;"
);
uwriteln!(self.import_object, "'{name}': typeof {camel}Imports,");
}

fn import_funcs(
Expand Down Expand Up @@ -478,7 +475,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

0 comments on commit 4f96f97

Please sign in to comment.