Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
* Fixed a bug in `--experimental-reset-state-function` support for heap reset.
[#4665](https://github.com/wasm-bindgen/wasm-bindgen/pull/4665)

* Quote names containing colons in generated .d.ts.
[#4488](https://github.com/rustwasm/wasm-bindgen/pull/4488)

* Fixed compilation failures on Rust v1.82 and v1.83.
[#4675](https://github.com/wasm-bindgen/wasm-bindgen/pull/4675)

Expand Down
8 changes: 7 additions & 1 deletion crates/cli-support/src/wasm2es6js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ 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(':') {
// This can happen when `name` is namespaced, like `__wbgt__reference_test::foo`.
// We should quote the name, as : is not valid in TypeScript identifiers.
writeln!(exports, " readonly {name:?}: {ty};").unwrap();
} else {
writeln!(exports, " readonly {name}: {ty};").unwrap();
}
});
Ok(exports)
}
Expand Down
118 changes: 118 additions & 0 deletions crates/cli/tests/reference/wasm-export-colon.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* tslint:disable */
/* eslint-disable */
/**
* 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;
[Symbol.dispose](): 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 "__wbgt__wasm_export_colon_reftest::colon_test": (a: number) => void;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this sufficient test of the feature? Previously, this .d.ts file would have caused a syntax error because there would be no quotes on this line.

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks great to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent! Could you take another look, @daxpedda?

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 __wbgtest_cov_dump: () => [number, number];
readonly wasm_bindgen__convert__closures_____invoke__h0000000000000003: (a: number, b: number, c: any) => void;
readonly wasm_bindgen__closure__destroy__h0000000000000008: (a: number, b: number) => void;
readonly wasm_bindgen__convert__closures_____invoke__h0000000000000004: (a: number, b: number) => void;
readonly wasm_bindgen__convert__closures_____invoke__h0000000000000005: (a: number, b: number) => number;
readonly wasm_bindgen__convert__closures_____invoke__h0000000000000006: (a: number, b: number, c: any, d: number, e: any) => void;
readonly wasm_bindgen__convert__closures_____invoke__h0000000000000007: (a: number, b: number, c: any, d: any) => void;
readonly __externref_table_alloc: () => number;
readonly __wbindgen_externrefs: 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_free: (a: number, b: number, c: number) => void;
readonly __wbindgen_start: () => void;
}

export type SyncInitInput = BufferSource | WebAssembly.Module;
/**
* Instantiates the given `module`, which can either be bytes or
* a precompiled `WebAssembly.Module`.
*
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
*
* @returns {InitOutput}
*/
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;

/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
*
* @returns {Promise<InitOutput>}
*/
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
Loading