diff --git a/crates/typescript-tests/index.ts b/crates/typescript-tests/index.ts deleted file mode 100644 index f36c5192..00000000 --- a/crates/typescript-tests/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -import * as wbg from './pkg/typescript_tests'; -import * as wasm from './pkg/typescript_tests_bg'; - -const a1: (a: string) => void = wbg.greet; -const a2: (a: number, b: number) => void = wasm.greet; -const a3: WebAssembly.Memory = wasm.memory; - -const c = new wbg.A(); -wbg.A.other(); -c.foo(); -c.free(); diff --git a/crates/typescript-tests/src/custom_section.rs b/crates/typescript-tests/src/custom_section.rs new file mode 100644 index 00000000..e1f5c1fc --- /dev/null +++ b/crates/typescript-tests/src/custom_section.rs @@ -0,0 +1,11 @@ +use wasm_bindgen::prelude::*; + +#[wasm_bindgen(typescript_custom_section)] +const TS_INTERFACE_EXPORT: &'static str = r" + interface Height { height: number; } +"; + +#[wasm_bindgen] +pub struct Person { + pub height: u32, +} \ No newline at end of file diff --git a/crates/typescript-tests/src/custom_section.ts b/crates/typescript-tests/src/custom_section.ts new file mode 100644 index 00000000..6420ea6d --- /dev/null +++ b/crates/typescript-tests/src/custom_section.ts @@ -0,0 +1,3 @@ +import * as wbg from '../pkg/typescript_tests'; + +const height: wbg.Height = new wbg.Person(); \ No newline at end of file diff --git a/crates/typescript-tests/src/lib.rs b/crates/typescript-tests/src/lib.rs index ea10b7b2..5e927e5a 100644 --- a/crates/typescript-tests/src/lib.rs +++ b/crates/typescript-tests/src/lib.rs @@ -1,20 +1,4 @@ -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -pub fn greet(_: &str) {} - -#[wasm_bindgen] -struct A { -} - -#[wasm_bindgen] -impl A { - #[wasm_bindgen(constructor)] - pub fn new() -> A { - A {} - } - - pub fn other() {} - - pub fn foo(&self) {} -} +mod custom_section; +mod opt_args_and_ret; +mod simple_fn; +mod simple_struct; \ No newline at end of file diff --git a/crates/typescript-tests/src/memory.ts b/crates/typescript-tests/src/memory.ts new file mode 100644 index 00000000..b1095b00 --- /dev/null +++ b/crates/typescript-tests/src/memory.ts @@ -0,0 +1,3 @@ +import * as wasm from '../pkg/typescript_tests_bg'; + +const memory: WebAssembly.Memory = wasm.memory; diff --git a/crates/typescript-tests/src/opt_args_and_ret.rs b/crates/typescript-tests/src/opt_args_and_ret.rs new file mode 100644 index 00000000..a84f2bfe --- /dev/null +++ b/crates/typescript-tests/src/opt_args_and_ret.rs @@ -0,0 +1,6 @@ +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub fn opt_fn(_a: Option) -> Option { + None +} \ No newline at end of file diff --git a/crates/typescript-tests/src/opt_args_and_ret.ts b/crates/typescript-tests/src/opt_args_and_ret.ts new file mode 100644 index 00000000..d0bd20a4 --- /dev/null +++ b/crates/typescript-tests/src/opt_args_and_ret.ts @@ -0,0 +1,3 @@ +import * as wbg from '../pkg/typescript_tests'; + +const opt_fn: (a: number | undefined) => number | undefined = wbg.opt_fn; \ No newline at end of file diff --git a/crates/typescript-tests/src/simple_fn.rs b/crates/typescript-tests/src/simple_fn.rs new file mode 100644 index 00000000..29a7d4aa --- /dev/null +++ b/crates/typescript-tests/src/simple_fn.rs @@ -0,0 +1,4 @@ +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub fn greet(_: &str) {} \ No newline at end of file diff --git a/crates/typescript-tests/src/simple_fn.ts b/crates/typescript-tests/src/simple_fn.ts new file mode 100644 index 00000000..f8b91d08 --- /dev/null +++ b/crates/typescript-tests/src/simple_fn.ts @@ -0,0 +1,5 @@ +import * as wbg from '../pkg/typescript_tests'; +import * as wasm from '../pkg/typescript_tests_bg'; + +const wbg_greet: (a: string) => void = wbg.greet; +const wasm_greet: (a: number, b: number) => void = wasm.greet; \ No newline at end of file diff --git a/crates/typescript-tests/src/simple_struct.rs b/crates/typescript-tests/src/simple_struct.rs new file mode 100644 index 00000000..d15e5031 --- /dev/null +++ b/crates/typescript-tests/src/simple_struct.rs @@ -0,0 +1,17 @@ +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub struct A { +} + +#[wasm_bindgen] +impl A { + #[wasm_bindgen(constructor)] + pub fn new() -> A { + A {} + } + + pub fn other() {} + + pub fn foo(&self) {} +} \ No newline at end of file diff --git a/crates/typescript-tests/src/simple_struct.ts b/crates/typescript-tests/src/simple_struct.ts new file mode 100644 index 00000000..95830399 --- /dev/null +++ b/crates/typescript-tests/src/simple_struct.ts @@ -0,0 +1,6 @@ +import * as wbg from '../pkg/typescript_tests'; + +const a = new wbg.A(); +wbg.A.other(); +a.foo(); +a.free(); diff --git a/crates/typescript-tests/tsconfig.json b/crates/typescript-tests/tsconfig.json index bdd06907..90892979 100644 --- a/crates/typescript-tests/tsconfig.json +++ b/crates/typescript-tests/tsconfig.json @@ -9,6 +9,6 @@ "baseUrl": "." }, "include": [ - "index.ts" + "src/*.ts" ] }