Skip to content

Quote names containing colons in generated .d.ts #4488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/cli-support/src/wasm2es6js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ fn args_are_optional(name: &str) -> bool {
pub fn interface(module: &Module) -> Result<String, Error> {
let mut exports = String::new();
module_export_types(module, |name, ty| {
writeln!(exports, " readonly {}: {};", name, ty).unwrap();
if name.contains(':') {
writeln!(exports, " readonly {name:?}: {ty};").unwrap();
} else {
writeln!(exports, " readonly {name}: {ty};").unwrap();
}
});
Ok(exports)
}
Expand Down
84 changes: 83 additions & 1 deletion crates/cli/tests/reference/wasm-export-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,99 @@
/* eslint-disable */
export function example(a: number, b: bigint, c: any, d: string): string;
export function example_128(a: bigint): bigint | undefined;
/**
* Handler for `console.log` invocations.
*
* If a test is currently running it takes the `args` array and stringifies
* it and appends it to the current output of the test. Otherwise it passes
* the arguments to the original `console.log` function, psased as
* `original`.
*/
export function __wbgtest_console_log(args: Array<any>): void;
/**
* Handler for `console.debug` invocations. See above.
*/
export function __wbgtest_console_debug(args: Array<any>): void;
/**
* Handler for `console.info` invocations. See above.
*/
export function __wbgtest_console_info(args: Array<any>): void;
/**
* Handler for `console.warn` invocations. See above.
*/
export function __wbgtest_console_warn(args: Array<any>): void;
/**
* Handler for `console.error` invocations. See above.
*/
export function __wbgtest_console_error(args: Array<any>): void;
export function __wbgtest_cov_dump(): Uint8Array | undefined;
/**
* Runtime test harness support instantiated in JS.
*
* The node.js entry script instantiates a `Context` here which is used to
* drive test execution.
*/
export class WasmBindgenTestContext {
free(): void;
/**
* Creates a new context ready to run tests.
*
* A `Context` is the main structure through which test execution is
* coordinated, and this will collect output and results for all executed
* tests.
*/
constructor();
/**
* Handle `--include-ignored` flag.
*/
include_ignored(include_ignored: boolean): void;
/**
* Handle filter argument.
*/
filtered_count(filtered: number): void;
/**
* Executes a list of tests, returning a promise representing their
* eventual completion.
*
* This is the main entry point for executing tests. All the tests passed
* in are the JS `Function` object that was plucked off the
* `WebAssembly.Instance` exports list.
*
* The promise returned resolves to either `true` if all tests passed or
* `false` if at least one test failed.
*/
run(tests: any[]): Promise<any>;
}

export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;

export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly example: (a: number, b: bigint, c: any, d: number, e: number) => [number, number];
readonly example_128: (a: bigint, b: bigint) => [number, bigint, bigint];
readonly __wbindgen_export_0: WebAssembly.Table;
readonly "__wbgt__reference_test::example_test": (a: number) => void;
readonly __wbgtest_cov_dump: () => [number, number];
Comment on lines -12 to +76
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is visible here :) __wbgt__reference_test::example_test is quoted now. 🎉

readonly __wbg_wasmbindgentestcontext_free: (a: number, b: number) => void;
readonly wasmbindgentestcontext_new: () => number;
readonly wasmbindgentestcontext_include_ignored: (a: number, b: number) => void;
readonly wasmbindgentestcontext_filtered_count: (a: number, b: number) => void;
readonly wasmbindgentestcontext_run: (a: number, b: number, c: number) => any;
readonly __wbgtest_console_log: (a: any) => void;
readonly __wbgtest_console_debug: (a: any) => void;
readonly __wbgtest_console_info: (a: any) => void;
readonly __wbgtest_console_warn: (a: any) => void;
readonly __wbgtest_console_error: (a: any) => void;
readonly __externref_table_alloc: () => number;
readonly __wbindgen_export_1: WebAssembly.Table;
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_exn_store: (a: number) => void;
readonly __wbindgen_export_5: WebAssembly.Table;
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
readonly closure51_externref_shim: (a: number, b: number, c: any) => void;
readonly wasm_bindgen__convert__closures__invoke0_mut__h99d1e3009d33d179: (a: number, b: number) => void;
readonly closure81_externref_shim: (a: number, b: number, c: any, d: number, e: any) => void;
readonly closure65_externref_shim: (a: number, b: number, c: any, d: any) => void;
readonly __wbindgen_start: () => void;
}

Expand Down
Loading