forked from madonoharu/tsify
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check the number of type parameters before handling the Range type (#45)
Don't assume that `Range` refers to the built-in Range type unless it has exactly one type parameter. This allows for the correct export of custom-defined Range structs.
- Loading branch information
1 parent
9cb9563
commit 39acd09
Showing
4 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
/** | ||
* @param {Range} _range | ||
*/ | ||
export function consume(_range: Range): void; | ||
/** | ||
* @returns {Range} | ||
*/ | ||
export function into_js(): Range; | ||
/** | ||
* @param {(Range)[]} _ranges | ||
*/ | ||
export function consume_vector(_ranges: (Range)[]): void; | ||
/** | ||
* @returns {(Range)[]} | ||
*/ | ||
export function vector_into_js(): (Range)[]; | ||
export interface Range { | ||
foo: number; | ||
bar: string; | ||
} | ||
|
||
export interface A { | ||
range: Range; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "test_range1" | ||
publish = false | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
wasm-bindgen = "0.2" | ||
tsify-next = { path = "../..", version = "*" } | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.3" | ||
|
||
[lib] | ||
path = "entry_point.rs" | ||
crate-type = ["cdylib"] | ||
|
||
[build-dependencies] | ||
wasm-bindgen-cli = "0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use tsify_next::Tsify; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[derive(Tsify, Serialize, Deserialize)] | ||
#[tsify(into_wasm_abi, from_wasm_abi)] | ||
pub struct Range { | ||
foo: u32, | ||
bar: String, | ||
} | ||
|
||
#[derive(Tsify, Serialize, Deserialize)] | ||
#[tsify(into_wasm_abi, from_wasm_abi)] | ||
pub struct A { | ||
range: Range, | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn consume(_range: Range) {} | ||
|
||
#[wasm_bindgen] | ||
pub fn into_js() -> Range { | ||
Range { | ||
foo: 42, | ||
bar: "BAR".to_string(), | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn consume_vector(_ranges: Vec<Range>) {} | ||
|
||
#[wasm_bindgen] | ||
pub fn vector_into_js() -> Vec<Range> { | ||
vec![ | ||
Range { | ||
foo: 42, | ||
bar: "BAR".to_string(), | ||
}, | ||
Range { | ||
foo: 42, | ||
bar: "BAR".to_string(), | ||
}, | ||
Range { | ||
foo: 42, | ||
bar: "BAR".to_string(), | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters