Skip to content

Commit

Permalink
Added test for typescript_type
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Dec 9, 2024
1 parent 0c86bfb commit 50cc24a
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/cli/tests/reference/typescript-type.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* tslint:disable */
/* eslint-disable */
export function single(a: number | string): void;
export function slice(a: (number | string)[]): void;
82 changes: 82 additions & 0 deletions crates/cli/tests/reference/typescript-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
let wasm;
export function __wbg_set_wasm(val) {
wasm = val;
}


const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });

cachedTextDecoder.decode();

let cachedUint8ArrayMemory0 = null;

function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8ArrayMemory0;
}

function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}
/**
* @param {number | string} a
*/
export function single(a) {
wasm.single(a);
}

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;
}

let WASM_VECTOR_LEN = 0;

function addToExternrefTable0(obj) {
const idx = wasm.__externref_table_alloc();
wasm.__wbindgen_export_0.set(idx, obj);
return idx;
}

function passArrayJsValueToWasm0(array, malloc) {
const ptr = malloc(array.length * 4, 4) >>> 0;
const mem = getDataViewMemory0();
for (let i = 0; i < array.length; i++) {
mem.setUint32(ptr + 4 * i, addToExternrefTable0(array[i]), true);
}
WASM_VECTOR_LEN = array.length;
return ptr;
}
/**
* @param {(number | string)[]} a
*/
export function slice(a) {
const ptr0 = passArrayJsValueToWasm0(a, wasm.__wbindgen_malloc);
const len0 = WASM_VECTOR_LEN;
wasm.slice(ptr0, len0);
}

export function __wbindgen_init_externref_table() {
const table = wasm.__wbindgen_export_0;
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);
;
};

export function __wbindgen_throw(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};

13 changes: 13 additions & 0 deletions crates/cli/tests/reference/typescript-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(typescript_type = "number | string")]
type CustomType;
}

#[wasm_bindgen]
pub fn single(a: CustomType) {}

#[wasm_bindgen]
pub fn slice(a: Vec<CustomType>) {}
23 changes: 23 additions & 0 deletions crates/cli/tests/reference/typescript-type.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(module $reference_test.wasm
(type (;0;) (func))
(type (;1;) (func (result i32)))
(type (;2;) (func (param i32 i32)))
(type (;3;) (func (param i32 i32) (result i32)))
(type (;4;) (func (param externref)))
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
(func $__wbindgen_malloc (;1;) (type 3) (param i32 i32) (result i32))
(func $slice (;2;) (type 2) (param i32 i32))
(func $__externref_table_alloc (;3;) (type 1) (result i32))
(func $"single externref shim" (;4;) (type 4) (param externref))
(table (;0;) 128 externref)
(memory (;0;) 17)
(export "memory" (memory 0))
(export "single" (func $"single externref shim"))
(export "slice" (func $slice))
(export "__wbindgen_export_0" (table 0))
(export "__externref_table_alloc" (func $__externref_table_alloc))
(export "__wbindgen_malloc" (func $__wbindgen_malloc))
(export "__wbindgen_start" (func 0))
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

0 comments on commit 50cc24a

Please sign in to comment.