diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fb8951795a..51c89648233 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/crates/cli-support/src/wasm2es6js.rs b/crates/cli-support/src/wasm2es6js.rs index 198f0ab0578..c4a393f9fef 100644 --- a/crates/cli-support/src/wasm2es6js.rs +++ b/crates/cli-support/src/wasm2es6js.rs @@ -63,7 +63,13 @@ fn args_are_optional(name: &str) -> bool { pub fn interface(module: &Module) -> Result { 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) } diff --git a/crates/cli/tests/reference/wasm-export-colon.d.ts b/crates/cli/tests/reference/wasm-export-colon.d.ts new file mode 100644 index 00000000000..e089bd7cf23 --- /dev/null +++ b/crates/cli/tests/reference/wasm-export-colon.d.ts @@ -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): void; +/** + * Handler for `console.debug` invocations. See above. + */ +export function __wbgtest_console_debug(args: Array): void; +/** + * Handler for `console.info` invocations. See above. + */ +export function __wbgtest_console_info(args: Array): void; +/** + * Handler for `console.warn` invocations. See above. + */ +export function __wbgtest_console_warn(args: Array): void; +/** + * Handler for `console.error` invocations. See above. + */ +export function __wbgtest_console_error(args: Array): 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; +} + +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; + 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 }} module_or_path - Passing `InitInput` directly is deprecated. +* +* @returns {Promise} +*/ +export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise } | InitInput | Promise): Promise; diff --git a/crates/cli/tests/reference/wasm-export-colon.js b/crates/cli/tests/reference/wasm-export-colon.js new file mode 100644 index 00000000000..02f39b27bdd --- /dev/null +++ b/crates/cli/tests/reference/wasm-export-colon.js @@ -0,0 +1,744 @@ +let wasm; + +function isLikeNone(x) { + return x === undefined || x === null; +} + +function addToExternrefTable0(obj) { + const idx = wasm.__externref_table_alloc(); + wasm.__wbindgen_externrefs.set(idx, obj); + return idx; +} + +let WASM_VECTOR_LEN = 0; + +let cachedUint8ArrayMemory0 = null; + +function getUint8ArrayMemory0() { + if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { + cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8ArrayMemory0; +} + +const cachedTextEncoder = new TextEncoder(); + +if (!('encodeInto' in cachedTextEncoder)) { + cachedTextEncoder.encodeInto = function (arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length + }; + } +} + +function passStringToWasm0(arg, malloc, realloc) { + + if (realloc === undefined) { + const buf = cachedTextEncoder.encode(arg); + const ptr = malloc(buf.length, 1) >>> 0; + getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf); + WASM_VECTOR_LEN = buf.length; + return ptr; + } + + let len = arg.length; + let ptr = malloc(len, 1) >>> 0; + + const mem = getUint8ArrayMemory0(); + + let offset = 0; + + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7F) break; + mem[ptr + offset] = code; + } + + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; + const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); + const ret = cachedTextEncoder.encodeInto(arg, view); + + offset += ret.written; + ptr = realloc(ptr, len, offset, 1) >>> 0; + } + + WASM_VECTOR_LEN = offset; + return ptr; +} + +let cachedDataViewMemory0 = null; + +function getDataViewMemory0() { + if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) { + cachedDataViewMemory0 = new DataView(wasm.memory.buffer); + } + return cachedDataViewMemory0; +} + +function handleError(f, args) { + try { + return f.apply(this, args); + } catch (e) { + const idx = addToExternrefTable0(e); + wasm.__wbindgen_exn_store(idx); + } +} + +let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); + +cachedTextDecoder.decode(); + +const MAX_SAFARI_DECODE_BYTES = 2146435072; +let numBytesDecoded = 0; +function decodeText(ptr, len) { + numBytesDecoded += len; + if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) { + cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); + cachedTextDecoder.decode(); + numBytesDecoded = len; + } + return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); +} + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return decodeText(ptr, len); +} + +function debugString(val) { + // primitive types + const type = typeof val; + if (type == 'number' || type == 'boolean' || val == null) { + return `${val}`; + } + if (type == 'string') { + return `"${val}"`; + } + if (type == 'symbol') { + const description = val.description; + if (description == null) { + return 'Symbol'; + } else { + return `Symbol(${description})`; + } + } + if (type == 'function') { + const name = val.name; + if (typeof name == 'string' && name.length > 0) { + return `Function(${name})`; + } else { + return 'Function'; + } + } + // objects + if (Array.isArray(val)) { + const length = val.length; + let debug = '['; + if (length > 0) { + debug += debugString(val[0]); + } + for(let i = 1; i < length; i++) { + debug += ', ' + debugString(val[i]); + } + debug += ']'; + return debug; + } + // Test for built-in + const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); + let className; + if (builtInMatches && builtInMatches.length > 1) { + className = builtInMatches[1]; + } else { + // Failed to match the standard '[object ClassName]' + return toString.call(val); + } + if (className == 'Object') { + // we're a user defined class or Object + // JSON.stringify avoids problems with cycles, and is generally much + // easier than looping through ownProperties of `val`. + try { + return 'Object(' + JSON.stringify(val) + ')'; + } catch (_) { + return 'Object'; + } + } + // errors + if (val instanceof Error) { + return `${val.name}: ${val.message}\n${val.stack}`; + } + // TODO we could test for more things here, like `Set`s and `Map`s. + return className; +} + +const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(state => state.dtor(state.a, state.b)); + +function makeMutClosure(arg0, arg1, dtor, f) { + const state = { a: arg0, b: arg1, cnt: 1, dtor }; + const real = (...args) => { + + // First up with a closure we increment the internal reference + // count. This ensures that the Rust closure environment won't + // be deallocated while we're invoking it. + state.cnt++; + const a = state.a; + state.a = 0; + try { + return f(a, state.b, ...args); + } finally { + state.a = a; + real._wbg_cb_unref(); + } + }; + real._wbg_cb_unref = () => { + if (--state.cnt === 0) { + state.dtor(state.a, state.b); + state.a = 0; + CLOSURE_DTORS.unregister(state); + } + }; + CLOSURE_DTORS.register(real, state, state); + return real; +} + +function passArrayJsValueToWasm0(array, malloc) { + const ptr = malloc(array.length * 4, 4) >>> 0; + for (let i = 0; i < array.length; i++) { + const add = addToExternrefTable0(array[i]); + getDataViewMemory0().setUint32(ptr + 4 * i, add, true); + } + WASM_VECTOR_LEN = array.length; + return ptr; +} +/** + * 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`. + * @param {Array} args + */ +export function __wbgtest_console_log(args) { + wasm.__wbgtest_console_log(args); +} + +/** + * Handler for `console.debug` invocations. See above. + * @param {Array} args + */ +export function __wbgtest_console_debug(args) { + wasm.__wbgtest_console_debug(args); +} + +/** + * Handler for `console.info` invocations. See above. + * @param {Array} args + */ +export function __wbgtest_console_info(args) { + wasm.__wbgtest_console_info(args); +} + +/** + * Handler for `console.warn` invocations. See above. + * @param {Array} args + */ +export function __wbgtest_console_warn(args) { + wasm.__wbgtest_console_warn(args); +} + +/** + * Handler for `console.error` invocations. See above. + * @param {Array} args + */ +export function __wbgtest_console_error(args) { + wasm.__wbgtest_console_error(args); +} + +function getArrayU8FromWasm0(ptr, len) { + ptr = ptr >>> 0; + return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len); +} +/** + * @returns {Uint8Array | undefined} + */ +export function __wbgtest_cov_dump() { + const ret = wasm.__wbgtest_cov_dump(); + let v1; + if (ret[0] !== 0) { + v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); + wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); + } + return v1; +} + +function wasm_bindgen__convert__closures_____invoke__h0000000000000003(arg0, arg1, arg2) { + wasm.wasm_bindgen__convert__closures_____invoke__h0000000000000003(arg0, arg1, arg2); +} + +function wasm_bindgen__convert__closures_____invoke__h0000000000000004(arg0, arg1) { + wasm.wasm_bindgen__convert__closures_____invoke__h0000000000000004(arg0, arg1); +} + +function wasm_bindgen__convert__closures_____invoke__h0000000000000005(arg0, arg1) { + const ret = wasm.wasm_bindgen__convert__closures_____invoke__h0000000000000005(arg0, arg1); + return ret !== 0; +} + +function wasm_bindgen__convert__closures_____invoke__h0000000000000006(arg0, arg1, arg2, arg3, arg4) { + wasm.wasm_bindgen__convert__closures_____invoke__h0000000000000006(arg0, arg1, arg2, arg3, arg4); +} + +function wasm_bindgen__convert__closures_____invoke__h0000000000000007(arg0, arg1, arg2, arg3) { + wasm.wasm_bindgen__convert__closures_____invoke__h0000000000000007(arg0, arg1, arg2, arg3); +} + +const WasmBindgenTestContextFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_wasmbindgentestcontext_free(ptr >>> 0, 1)); +/** + * 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 { + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + WasmBindgenTestContextFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_wasmbindgentestcontext_free(ptr, 0); + } + /** + * 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() { + const ret = wasm.wasmbindgentestcontext_new(); + this.__wbg_ptr = ret >>> 0; + WasmBindgenTestContextFinalization.register(this, this.__wbg_ptr, this); + return this; + } + /** + * Handle `--include-ignored` flag. + * @param {boolean} include_ignored + */ + include_ignored(include_ignored) { + wasm.wasmbindgentestcontext_include_ignored(this.__wbg_ptr, include_ignored); + } + /** + * Handle filter argument. + * @param {number} filtered + */ + filtered_count(filtered) { + wasm.wasmbindgentestcontext_filtered_count(this.__wbg_ptr, filtered); + } + /** + * 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. + * @param {any[]} tests + * @returns {Promise} + */ + run(tests) { + const ptr0 = passArrayJsValueToWasm0(tests, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + const ret = wasm.wasmbindgentestcontext_run(this.__wbg_ptr, ptr0, len0); + return ret; + } +} +if (Symbol.dispose) WasmBindgenTestContext.prototype[Symbol.dispose] = WasmBindgenTestContext.prototype.free; + +const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']); + +async function __wbg_load(module, imports) { + if (typeof Response === 'function' && module instanceof Response) { + if (typeof WebAssembly.instantiateStreaming === 'function') { + try { + return await WebAssembly.instantiateStreaming(module, imports); + + } catch (e) { + const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type); + + if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') { + console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); + + } else { + throw e; + } + } + } + + const bytes = await module.arrayBuffer(); + return await WebAssembly.instantiate(bytes, imports); + + } else { + const instance = await WebAssembly.instantiate(module, imports); + + if (instance instanceof WebAssembly.Instance) { + return { instance, module }; + + } else { + return instance; + } + } +} + +function __wbg_get_imports() { + const imports = {}; + imports.wbg = {}; + imports.wbg.__wbg_Deno_634cb6f21eaad2dc = function(arg0) { + const ret = arg0.Deno; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_String_6bc1b67487011745 = function(arg0, arg1) { + const ret = String(arg1); + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg___wbg_test_invoke_084dacba5c704742 = function() { return handleError(function (arg0, arg1) { + try { + var state0 = {a: arg0, b: arg1}; + var cb0 = () => { + const a = state0.a; + state0.a = 0; + try { + return wasm_bindgen__convert__closures_____invoke__h0000000000000004(a, state0.b, ); + } finally { + state0.a = a; + } + }; + __wbg_test_invoke(cb0); + } finally { + state0.a = state0.b = 0; + } + }, arguments) }; + imports.wbg.__wbg___wbg_test_output_writeln_235c0c26f70c108e = function(arg0) { + __wbg_test_output_writeln(arg0); + }; + imports.wbg.__wbg___wbgtest_og_console_log_b0d67fac2af7fe41 = function(arg0, arg1) { + __wbgtest_og_console_log(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbg___wbindgen_debug_string_df47ffb5e35e6763 = function(arg0, arg1) { + const ret = debugString(arg1); + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg___wbindgen_is_function_ee8a6c5833c90377 = function(arg0) { + const ret = typeof(arg0) === 'function'; + return ret; + }; + imports.wbg.__wbg___wbindgen_is_undefined_2d472862bd29a478 = function(arg0) { + const ret = arg0 === undefined; + return ret; + }; + imports.wbg.__wbg___wbindgen_string_get_e4f06c90489ad01b = function(arg0, arg1) { + const obj = arg1; + const ret = typeof(obj) === 'string' ? obj : undefined; + var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg___wbindgen_throw_b855445ff6a94295 = function(arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbg__wbg_cb_unref_2454a539ea5790d9 = function(arg0) { + arg0._wbg_cb_unref(); + }; + imports.wbg.__wbg_call_525440f72fbfc0ea = function() { return handleError(function (arg0, arg1, arg2) { + const ret = arg0.call(arg1, arg2); + return ret; + }, arguments) }; + imports.wbg.__wbg_call_e762c39fa8ea36bf = function() { return handleError(function (arg0, arg1) { + const ret = arg0.call(arg1); + return ret; + }, arguments) }; + imports.wbg.__wbg_constructor_81f88a4860a1af7c = function(arg0) { + const ret = arg0.constructor; + return ret; + }; + imports.wbg.__wbg_createTask_9ac11a42c24ef284 = function() { return handleError(function (arg0, arg1) { + const ret = console.createTask(getStringFromWasm0(arg0, arg1)); + return ret; + }, arguments) }; + imports.wbg.__wbg_error_429b0f1cbf418127 = function(arg0, arg1) { + console.error(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbg_forEach_0243403712900242 = function(arg0, arg1, arg2) { + try { + var state0 = {a: arg1, b: arg2}; + var cb0 = (arg0, arg1, arg2) => { + const a = state0.a; + state0.a = 0; + try { + return wasm_bindgen__convert__closures_____invoke__h0000000000000006(a, state0.b, arg0, arg1, arg2); + } finally { + state0.a = a; + } + }; + arg0.forEach(cb0); + } finally { + state0.a = state0.b = 0; + } + }; + imports.wbg.__wbg_getElementById_eca4e95044d7b113 = function(arg0, arg1, arg2) { + const ret = arg0.getElementById(getStringFromWasm0(arg1, arg2)); + return ret; + }; + imports.wbg.__wbg_message_1ee258909d7264fd = function(arg0) { + const ret = arg0.message; + return ret; + }; + imports.wbg.__wbg_name_2a1ed5dceff4fd81 = function(arg0, arg1) { + const ret = arg1.name; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg_name_4810447ab1aad468 = function(arg0) { + const ret = arg0.name; + return ret; + }; + imports.wbg.__wbg_new_3c3d849046688a66 = function(arg0, arg1) { + try { + var state0 = {a: arg0, b: arg1}; + var cb0 = (arg0, arg1) => { + const a = state0.a; + state0.a = 0; + try { + return wasm_bindgen__convert__closures_____invoke__h0000000000000007(a, state0.b, arg0, arg1); + } finally { + state0.a = a; + } + }; + const ret = new Promise(cb0); + return ret; + } finally { + state0.a = state0.b = 0; + } + }; + imports.wbg.__wbg_new_627b4c8d3171e493 = function() { + const ret = new Error(); + return ret; + }; + imports.wbg.__wbg_new_no_args_ee98eee5275000a4 = function(arg0, arg1) { + const ret = new Function(getStringFromWasm0(arg0, arg1)); + return ret; + }; + imports.wbg.__wbg_now_57c19e993214f016 = function(arg0) { + const ret = arg0.now(); + return ret; + }; + imports.wbg.__wbg_performance_f352f7021f1ba8f3 = function(arg0) { + const ret = arg0.performance; + return ret; + }; + imports.wbg.__wbg_queueMicrotask_34d692c25c47d05b = function(arg0) { + const ret = arg0.queueMicrotask; + return ret; + }; + imports.wbg.__wbg_queueMicrotask_9d76cacb20c84d58 = function(arg0) { + queueMicrotask(arg0); + }; + imports.wbg.__wbg_resolve_caf97c30b83f7053 = function(arg0) { + const ret = Promise.resolve(arg0); + return ret; + }; + imports.wbg.__wbg_run_e5e1ecccf06974b2 = function(arg0, arg1, arg2) { + try { + var state0 = {a: arg1, b: arg2}; + var cb0 = () => { + const a = state0.a; + state0.a = 0; + try { + return wasm_bindgen__convert__closures_____invoke__h0000000000000005(a, state0.b, ); + } finally { + state0.a = a; + } + }; + const ret = arg0.run(cb0); + return ret; + } finally { + state0.a = state0.b = 0; + } + }; + imports.wbg.__wbg_self_3784cb9cab2938fe = function(arg0) { + const ret = arg0.self; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_set_text_content_75282044601f711a = function(arg0, arg1, arg2) { + arg0.textContent = getStringFromWasm0(arg1, arg2); + }; + imports.wbg.__wbg_stack_03cb47c2d3062fcc = function(arg0) { + const ret = arg0.stack; + return ret; + }; + imports.wbg.__wbg_stack_447914f6b88d9a93 = function(arg0, arg1) { + const ret = arg1.stack; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg_stack_b4cd7023b38fdcf1 = function(arg0) { + const ret = arg0.stack; + return ret; + }; + imports.wbg.__wbg_stack_fe563871653fe12c = function(arg0, arg1) { + const ret = arg1.stack; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg_static_accessor_DOCUMENT_bc686c3dea6d9453 = function() { + const ret = document; + return ret; + }; + imports.wbg.__wbg_static_accessor_GLOBAL_89e1d9ac6a1b250e = function() { + const ret = typeof global === 'undefined' ? null : global; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_static_accessor_GLOBAL_THIS_8b530f326a9e48ac = function() { + const ret = typeof globalThis === 'undefined' ? null : globalThis; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_static_accessor_SELF_6fdf4b64710cc91b = function() { + const ret = typeof self === 'undefined' ? null : self; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_static_accessor_WINDOW_b45bfc5a37f6cfa2 = function() { + const ret = typeof window === 'undefined' ? null : window; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_text_content_b0fce51a6f64d76b = function(arg0, arg1) { + const ret = arg1.textContent; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg_then_4f46f6544e6b4a28 = function(arg0, arg1) { + const ret = arg0.then(arg1); + return ret; + }; + imports.wbg.__wbindgen_cast_0000000000000000 = function(arg0, arg1) { + // Cast intrinsic for `Ref(String) -> Externref`. + const ret = getStringFromWasm0(arg0, arg1); + return ret; + }; + imports.wbg.__wbindgen_cast_0000000000000001 = function(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 9, function: Function { arguments: [Externref], shim_idx: 10, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h0000000000000008, wasm_bindgen__convert__closures_____invoke__h0000000000000003); + return ret; + }; + imports.wbg.__wbindgen_cast_0000000000000002 = function(arg0) { + // Cast intrinsic for `F64 -> Externref`. + const ret = arg0; + return ret; + }; + imports.wbg.__wbindgen_init_externref_table = function() { + const table = wasm.__wbindgen_externrefs; + const offset = table.grow(4); + table.set(0, undefined); + table.set(offset + 0, undefined); + table.set(offset + 1, null); + table.set(offset + 2, true); + table.set(offset + 3, false); + ; + }; + + return imports; +} + +function __wbg_finalize_init(instance, module) { + wasm = instance.exports; + __wbg_init.__wbindgen_wasm_module = module; + cachedDataViewMemory0 = null; + cachedUint8ArrayMemory0 = null; + + + wasm.__wbindgen_start(); + return wasm; +} + +function initSync(module) { + if (wasm !== undefined) return wasm; + + + if (typeof module !== 'undefined') { + if (Object.getPrototypeOf(module) === Object.prototype) { + ({module} = module) + } else { + console.warn('using deprecated parameters for `initSync()`; pass a single object instead') + } + } + + const imports = __wbg_get_imports(); + + if (!(module instanceof WebAssembly.Module)) { + module = new WebAssembly.Module(module); + } + + const instance = new WebAssembly.Instance(module, imports); + + return __wbg_finalize_init(instance, module); +} + +async function __wbg_init(module_or_path) { + if (wasm !== undefined) return wasm; + + + if (typeof module_or_path !== 'undefined') { + if (Object.getPrototypeOf(module_or_path) === Object.prototype) { + ({module_or_path} = module_or_path) + } else { + console.warn('using deprecated parameters for the initialization function; pass a single object instead') + } + } + + if (typeof module_or_path === 'undefined') { + module_or_path = new URL('reference_test_bg.wasm', import.meta.url); + } + const imports = __wbg_get_imports(); + + if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) { + module_or_path = fetch(module_or_path); + } + + const { instance, module } = await __wbg_load(await module_or_path, imports); + + return __wbg_finalize_init(instance, module); +} + +export { initSync }; +export default __wbg_init; diff --git a/crates/cli/tests/reference/wasm-export-colon.rs b/crates/cli/tests/reference/wasm-export-colon.rs new file mode 100644 index 00000000000..87df3191c06 --- /dev/null +++ b/crates/cli/tests/reference/wasm-export-colon.rs @@ -0,0 +1,13 @@ +// FLAGS: --target=web +// DEPENDENCY: wasm-bindgen-test = { path = '{root}/crates/test' } + +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; + +// This test ensures that identifiers containing colons (like `__wbgt__reference_test::colon_test`) +// are properly quoted in the generated .d.ts file, since colons are not valid in TypeScript identifiers. + +#[wasm_bindgen_test] +fn colon_test() { + assert!(true) +} diff --git a/crates/cli/tests/reference/wasm-export-colon.wat b/crates/cli/tests/reference/wasm-export-colon.wat new file mode 100644 index 00000000000..b9a5dd986b6 --- /dev/null +++ b/crates/cli/tests/reference/wasm-export-colon.wat @@ -0,0 +1,126 @@ +(module $wasm_export_colon_reftest.wasm + (type (;0;) (func)) + (type (;1;) (func (result i32))) + (type (;2;) (func (result i32 i32))) + (type (;3;) (func (result externref))) + (type (;4;) (func (param i32))) + (type (;5;) (func (param i32 i32))) + (type (;6;) (func (param i32 i32) (result i32))) + (type (;7;) (func (param i32 i32) (result externref))) + (type (;8;) (func (param i32 i32 i32))) + (type (;9;) (func (param i32 i32 i32) (result externref))) + (type (;10;) (func (param i32 i32 i32 i32) (result i32))) + (type (;11;) (func (param i32 i32 externref))) + (type (;12;) (func (param i32 i32 externref i32 externref))) + (type (;13;) (func (param i32 i32 externref externref))) + (type (;14;) (func (param i32 externref))) + (type (;15;) (func (param f64) (result externref))) + (type (;16;) (func (param externref))) + (type (;17;) (func (param externref) (result i32))) + (type (;18;) (func (param externref) (result f64))) + (type (;19;) (func (param externref) (result externref))) + (type (;20;) (func (param externref i32 i32))) + (type (;21;) (func (param externref i32 i32) (result i32))) + (type (;22;) (func (param externref i32 i32) (result externref))) + (type (;23;) (func (param externref externref) (result externref))) + (type (;24;) (func (param externref externref externref) (result externref))) + (import "wbg" "__wbg_Deno_634cb6f21eaad2dc" (func (;0;) (type 17))) + (import "wbg" "__wbg_String_6bc1b67487011745" (func (;1;) (type 14))) + (import "wbg" "__wbg___wbg_test_invoke_084dacba5c704742" (func (;2;) (type 5))) + (import "wbg" "__wbg___wbg_test_output_writeln_235c0c26f70c108e" (func (;3;) (type 16))) + (import "wbg" "__wbg___wbgtest_og_console_log_b0d67fac2af7fe41" (func (;4;) (type 5))) + (import "wbg" "__wbg___wbindgen_debug_string_df47ffb5e35e6763" (func (;5;) (type 14))) + (import "wbg" "__wbg___wbindgen_is_function_ee8a6c5833c90377" (func (;6;) (type 17))) + (import "wbg" "__wbg___wbindgen_is_undefined_2d472862bd29a478" (func (;7;) (type 17))) + (import "wbg" "__wbg___wbindgen_string_get_e4f06c90489ad01b" (func (;8;) (type 14))) + (import "wbg" "__wbg___wbindgen_throw_b855445ff6a94295" (func (;9;) (type 5))) + (import "wbg" "__wbg__wbg_cb_unref_2454a539ea5790d9" (func (;10;) (type 16))) + (import "wbg" "__wbg_call_525440f72fbfc0ea" (func (;11;) (type 24))) + (import "wbg" "__wbg_call_e762c39fa8ea36bf" (func (;12;) (type 23))) + (import "wbg" "__wbg_constructor_81f88a4860a1af7c" (func (;13;) (type 19))) + (import "wbg" "__wbg_createTask_9ac11a42c24ef284" (func (;14;) (type 7))) + (import "wbg" "__wbg_error_429b0f1cbf418127" (func (;15;) (type 5))) + (import "wbg" "__wbg_forEach_0243403712900242" (func (;16;) (type 20))) + (import "wbg" "__wbg_getElementById_eca4e95044d7b113" (func (;17;) (type 22))) + (import "wbg" "__wbg_message_1ee258909d7264fd" (func (;18;) (type 19))) + (import "wbg" "__wbg_name_2a1ed5dceff4fd81" (func (;19;) (type 14))) + (import "wbg" "__wbg_name_4810447ab1aad468" (func (;20;) (type 19))) + (import "wbg" "__wbg_new_3c3d849046688a66" (func (;21;) (type 7))) + (import "wbg" "__wbg_new_627b4c8d3171e493" (func (;22;) (type 3))) + (import "wbg" "__wbg_new_no_args_ee98eee5275000a4" (func (;23;) (type 7))) + (import "wbg" "__wbg_now_57c19e993214f016" (func (;24;) (type 18))) + (import "wbg" "__wbg_performance_f352f7021f1ba8f3" (func (;25;) (type 19))) + (import "wbg" "__wbg_queueMicrotask_34d692c25c47d05b" (func (;26;) (type 19))) + (import "wbg" "__wbg_queueMicrotask_9d76cacb20c84d58" (func (;27;) (type 16))) + (import "wbg" "__wbg_resolve_caf97c30b83f7053" (func (;28;) (type 19))) + (import "wbg" "__wbg_run_e5e1ecccf06974b2" (func (;29;) (type 21))) + (import "wbg" "__wbg_self_3784cb9cab2938fe" (func (;30;) (type 17))) + (import "wbg" "__wbg_set_text_content_75282044601f711a" (func (;31;) (type 20))) + (import "wbg" "__wbg_stack_03cb47c2d3062fcc" (func (;32;) (type 19))) + (import "wbg" "__wbg_stack_447914f6b88d9a93" (func (;33;) (type 14))) + (import "wbg" "__wbg_stack_b4cd7023b38fdcf1" (func (;34;) (type 19))) + (import "wbg" "__wbg_stack_fe563871653fe12c" (func (;35;) (type 14))) + (import "wbg" "__wbg_static_accessor_DOCUMENT_bc686c3dea6d9453" (func (;36;) (type 3))) + (import "wbg" "__wbg_static_accessor_GLOBAL_89e1d9ac6a1b250e" (func (;37;) (type 1))) + (import "wbg" "__wbg_static_accessor_GLOBAL_THIS_8b530f326a9e48ac" (func (;38;) (type 1))) + (import "wbg" "__wbg_static_accessor_SELF_6fdf4b64710cc91b" (func (;39;) (type 1))) + (import "wbg" "__wbg_static_accessor_WINDOW_b45bfc5a37f6cfa2" (func (;40;) (type 1))) + (import "wbg" "__wbg_text_content_b0fce51a6f64d76b" (func (;41;) (type 14))) + (import "wbg" "__wbg_then_4f46f6544e6b4a28" (func (;42;) (type 23))) + (import "wbg" "__wbindgen_cast_0000000000000000" (func (;43;) (type 7))) + (import "wbg" "__wbindgen_cast_0000000000000001" (func (;44;) (type 7))) + (import "wbg" "__wbindgen_cast_0000000000000002" (func (;45;) (type 15))) + (import "wbg" "__wbindgen_init_externref_table" (func (;46;) (type 0))) + (func $__wbgt__wasm_export_colon_reftest::colon_test (;47;) (type 4) (param i32)) + (func $__wbg_wasmbindgentestcontext_free (;48;) (type 5) (param i32 i32)) + (func $wasmbindgentestcontext_new (;49;) (type 1) (result i32)) + (func $wasmbindgentestcontext_include_ignored (;50;) (type 5) (param i32 i32)) + (func $wasmbindgentestcontext_filtered_count (;51;) (type 5) (param i32 i32)) + (func $"wasmbindgentestcontext_run externref shim" (;52;) (type 9) (param i32 i32 i32) (result externref)) + (func $"__wbgtest_console_log externref shim" (;53;) (type 16) (param externref)) + (func $"__wbgtest_console_debug externref shim" (;54;) (type 16) (param externref)) + (func $"__wbgtest_console_info externref shim" (;55;) (type 16) (param externref)) + (func $"__wbgtest_console_warn externref shim" (;56;) (type 16) (param externref)) + (func $"__wbgtest_console_error externref shim" (;57;) (type 16) (param externref)) + (func $"__wbgtest_cov_dump multivalue shim" (;58;) (type 2) (result i32 i32)) + (func $"wasm_bindgen::convert::closures::_::invoke::h0000000000000003 externref shim" (;59;) (type 11) (param i32 i32 externref)) + (func $wasm_bindgen::closure::destroy::h0000000000000008 (;60;) (type 5) (param i32 i32)) + (func $wasm_bindgen::convert::closures::_::invoke::h0000000000000004 (;61;) (type 5) (param i32 i32)) + (func $wasm_bindgen::convert::closures::_::invoke::h0000000000000005 (;62;) (type 6) (param i32 i32) (result i32)) + (func $"wasm_bindgen::convert::closures::_::invoke::h0000000000000006 externref shim" (;63;) (type 12) (param i32 i32 externref i32 externref)) + (func $"wasm_bindgen::convert::closures::_::invoke::h0000000000000007 externref shim" (;64;) (type 13) (param i32 i32 externref externref)) + (func $__externref_table_alloc (;65;) (type 1) (result i32)) + (func $__wbindgen_malloc (;66;) (type 6) (param i32 i32) (result i32)) + (func $__wbindgen_realloc (;67;) (type 10) (param i32 i32 i32 i32) (result i32)) + (func $__wbindgen_exn_store (;68;) (type 4) (param i32)) + (func $__wbindgen_free (;69;) (type 8) (param i32 i32 i32)) + (table $__wbindgen_externrefs (;0;) 128 externref) + (memory (;0;) 17) + (export "memory" (memory 0)) + (export "__wbgt__wasm_export_colon_reftest::colon_test" (func $__wbgt__wasm_export_colon_reftest::colon_test)) + (export "__wbg_wasmbindgentestcontext_free" (func $__wbg_wasmbindgentestcontext_free)) + (export "wasmbindgentestcontext_new" (func $wasmbindgentestcontext_new)) + (export "wasmbindgentestcontext_include_ignored" (func $wasmbindgentestcontext_include_ignored)) + (export "wasmbindgentestcontext_filtered_count" (func $wasmbindgentestcontext_filtered_count)) + (export "wasmbindgentestcontext_run" (func $"wasmbindgentestcontext_run externref shim")) + (export "__wbgtest_console_log" (func $"__wbgtest_console_log externref shim")) + (export "__wbgtest_console_debug" (func $"__wbgtest_console_debug externref shim")) + (export "__wbgtest_console_info" (func $"__wbgtest_console_info externref shim")) + (export "__wbgtest_console_warn" (func $"__wbgtest_console_warn externref shim")) + (export "__wbgtest_console_error" (func $"__wbgtest_console_error externref shim")) + (export "__wbgtest_cov_dump" (func $"__wbgtest_cov_dump multivalue shim")) + (export "wasm_bindgen__convert__closures_____invoke__h0000000000000003" (func $"wasm_bindgen::convert::closures::_::invoke::h0000000000000003 externref shim")) + (export "wasm_bindgen__closure__destroy__h0000000000000008" (func $wasm_bindgen::closure::destroy::h0000000000000008)) + (export "wasm_bindgen__convert__closures_____invoke__h0000000000000004" (func $wasm_bindgen::convert::closures::_::invoke::h0000000000000004)) + (export "wasm_bindgen__convert__closures_____invoke__h0000000000000005" (func $wasm_bindgen::convert::closures::_::invoke::h0000000000000005)) + (export "wasm_bindgen__convert__closures_____invoke__h0000000000000006" (func $"wasm_bindgen::convert::closures::_::invoke::h0000000000000006 externref shim")) + (export "wasm_bindgen__convert__closures_____invoke__h0000000000000007" (func $"wasm_bindgen::convert::closures::_::invoke::h0000000000000007 externref shim")) + (export "__externref_table_alloc" (func $__externref_table_alloc)) + (export "__wbindgen_externrefs" (table $__wbindgen_externrefs)) + (export "__wbindgen_malloc" (func $__wbindgen_malloc)) + (export "__wbindgen_realloc" (func $__wbindgen_realloc)) + (export "__wbindgen_exn_store" (func $__wbindgen_exn_store)) + (export "__wbindgen_free" (func $__wbindgen_free)) + (export "__wbindgen_start" (func 46)) + (@custom "target_features" (after code) "\08+\0bbulk-memory+\0fbulk-memory-opt+\16call-indirect-overlong+\0amultivalue+\0fmutable-globals+\13nontrapping-fptoint+\0freference-types+\08sign-ext") +)