Skip to content

wasm_bindgen_test syntax error at :: in .d.ts ("Expected type") #4449

Open
@lynn

Description

@lynn

When I define a test like

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen_test]
async fn screen_example() {
    // ...
}

in my wasm-bindgen module screening_wasm/src/lib.rs, the resulting screening_wasm/pkg/screening_wasm.d.ts contains

// ...

export interface InitOutput {
  readonly memory: WebAssembly.Memory;
  readonly __wbg_screenconfig_free: (a: number, b: number) => void;
  readonly __wbg_enumerationsettings_free: (a: number, b: number) => void;
  readonly __wbg_fixeddomains_free: (a: number, b: number) => void;
  readonly start: () => void;
  readonly screen: (a: any, b: any) => any;
  readonly __wbgt__screening_wasm::screen_example: (a: number) => void;

//                               ^ Expected a type but instead found ':'.
// ...

I'm not sure how this is supposed to work, but I guess the cause of this behavior is that wasm-bindgen-test-macro generates

#[export_name = ::core::concat!("__wbgt_", #ignore_name, "_", ::core::module_path!(), "::", ::core::stringify!(#ident))]

and then wasm2es6js.rs uses that name when making the .d.ts file, but it contains :: which is not valid in a TypeScript identifier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions