Skip to content

Commit 50cc24a

Browse files
Added test for typescript_type
1 parent 0c86bfb commit 50cc24a

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
export function single(a: number | string): void;
4+
export function slice(a: (number | string)[]): void;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
let wasm;
2+
export function __wbg_set_wasm(val) {
3+
wasm = val;
4+
}
5+
6+
7+
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
8+
9+
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
10+
11+
cachedTextDecoder.decode();
12+
13+
let cachedUint8ArrayMemory0 = null;
14+
15+
function getUint8ArrayMemory0() {
16+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
17+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
18+
}
19+
return cachedUint8ArrayMemory0;
20+
}
21+
22+
function getStringFromWasm0(ptr, len) {
23+
ptr = ptr >>> 0;
24+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
25+
}
26+
/**
27+
* @param {number | string} a
28+
*/
29+
export function single(a) {
30+
wasm.single(a);
31+
}
32+
33+
let cachedDataViewMemory0 = null;
34+
35+
function getDataViewMemory0() {
36+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
37+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
38+
}
39+
return cachedDataViewMemory0;
40+
}
41+
42+
let WASM_VECTOR_LEN = 0;
43+
44+
function addToExternrefTable0(obj) {
45+
const idx = wasm.__externref_table_alloc();
46+
wasm.__wbindgen_export_0.set(idx, obj);
47+
return idx;
48+
}
49+
50+
function passArrayJsValueToWasm0(array, malloc) {
51+
const ptr = malloc(array.length * 4, 4) >>> 0;
52+
const mem = getDataViewMemory0();
53+
for (let i = 0; i < array.length; i++) {
54+
mem.setUint32(ptr + 4 * i, addToExternrefTable0(array[i]), true);
55+
}
56+
WASM_VECTOR_LEN = array.length;
57+
return ptr;
58+
}
59+
/**
60+
* @param {(number | string)[]} a
61+
*/
62+
export function slice(a) {
63+
const ptr0 = passArrayJsValueToWasm0(a, wasm.__wbindgen_malloc);
64+
const len0 = WASM_VECTOR_LEN;
65+
wasm.slice(ptr0, len0);
66+
}
67+
68+
export function __wbindgen_init_externref_table() {
69+
const table = wasm.__wbindgen_export_0;
70+
const offset = table.grow(4);
71+
table.set(0, undefined);
72+
table.set(offset + 0, undefined);
73+
table.set(offset + 1, null);
74+
table.set(offset + 2, true);
75+
table.set(offset + 3, false);
76+
;
77+
};
78+
79+
export function __wbindgen_throw(arg0, arg1) {
80+
throw new Error(getStringFromWasm0(arg0, arg1));
81+
};
82+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use wasm_bindgen::prelude::*;
2+
3+
#[wasm_bindgen]
4+
extern "C" {
5+
#[wasm_bindgen(typescript_type = "number | string")]
6+
type CustomType;
7+
}
8+
9+
#[wasm_bindgen]
10+
pub fn single(a: CustomType) {}
11+
12+
#[wasm_bindgen]
13+
pub fn slice(a: Vec<CustomType>) {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(module $reference_test.wasm
2+
(type (;0;) (func))
3+
(type (;1;) (func (result i32)))
4+
(type (;2;) (func (param i32 i32)))
5+
(type (;3;) (func (param i32 i32) (result i32)))
6+
(type (;4;) (func (param externref)))
7+
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
8+
(func $__wbindgen_malloc (;1;) (type 3) (param i32 i32) (result i32))
9+
(func $slice (;2;) (type 2) (param i32 i32))
10+
(func $__externref_table_alloc (;3;) (type 1) (result i32))
11+
(func $"single externref shim" (;4;) (type 4) (param externref))
12+
(table (;0;) 128 externref)
13+
(memory (;0;) 17)
14+
(export "memory" (memory 0))
15+
(export "single" (func $"single externref shim"))
16+
(export "slice" (func $slice))
17+
(export "__wbindgen_export_0" (table 0))
18+
(export "__externref_table_alloc" (func $__externref_table_alloc))
19+
(export "__wbindgen_malloc" (func $__wbindgen_malloc))
20+
(export "__wbindgen_start" (func 0))
21+
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
22+
)
23+

0 commit comments

Comments
 (0)