diff --git a/Cargo.toml b/Cargo.toml index 1e29293..a6731d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,45 +1,53 @@ [package] -name = "tsify" -version = "0.4.5" +name = "tsify-next" +version = "0.5.0" edition = "2021" -authors = ["Madono Haru "] +authors = [ + "Madono Haru ", + "Jason Siefken " +] license = "MIT OR Apache-2.0" -description = "Tsify is a library for generating TypeScript definitions from rust code." -repository = "https://github.com/madonoharu/tsify" -homepage = "https://github.com/madonoharu/tsify" +description = "Tsify-next is a library for generating TypeScript definitions from rust code." +repository = "https://github.com/siefkenj/tsify" +homepage = "https://github.com/siefkenj/tsify" keywords = ["wasm", "wasm-bindgen", "typescript"] categories = ["wasm"] [dependencies] -tsify-macros = { path = "tsify-macros", version = "0.4.3" } +tsify-next-macros = { path = "tsify-next-macros", version = "^0.5" } wasm-bindgen = { version = "0.2.86", optional = true } serde = { version = "1.0", optional = true } serde_json = { version = "1.0", optional = true } -serde-wasm-bindgen = { version = "0.5.0", optional = true } -gloo-utils = { version = "0.1.6", optional = true } +serde-wasm-bindgen = { version = "0.6", optional = true } +gloo-utils = { version = "0.2", optional = true } [dev-dependencies] -indoc = "2.0.1" -js-sys = "0.3.63" +indoc = "2.0.5" +js-sys = "0.3" macrotest = "1.0" -pretty_assertions = "1.3.0" +pretty_assertions = "1.4.0" serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.5.0" +serde-wasm-bindgen = "0.6" serde_json = "1.0" -wasm-bindgen = "0.2.86" -wasm-bindgen-test = "0.3.36" +wasm-bindgen = "0.2" +wasm-bindgen-test = "0.3" [features] default = ["json"] -wasm-bindgen = ["tsify-macros/wasm-bindgen", "dep:wasm-bindgen"] -js = ["wasm-bindgen", "tsify-macros/js", "dep:serde", "dep:serde-wasm-bindgen"] +wasm-bindgen = ["tsify-next-macros/wasm-bindgen", "dep:wasm-bindgen"] +js = [ + "wasm-bindgen", + "tsify-next-macros/js", + "dep:serde", + "dep:serde-wasm-bindgen" +] json = [ "wasm-bindgen", - "tsify-macros/json", + "tsify-next-macros/json", "dep:serde", "dep:gloo-utils", "dep:serde_json", ] [workspace] -members = ["tsify-macros"] +members = ["tsify-next-macros"] diff --git a/README.md b/README.md index 24144e9..b67f71e 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ wasm-bindgen = { version = "0.2" } ```rust use serde::{Deserialize, Serialize}; -use tsify::Tsify; +use tsify_next::Tsify; use wasm_bindgen::prelude::*; #[derive(Tsify, Serialize, Deserialize)] @@ -100,7 +100,7 @@ Serde attributes ## Type Override ```rust -use tsify::Tsify; +use tsify_next::Tsify; #[derive(Tsify)] pub struct Foo { @@ -209,7 +209,7 @@ export type Color = ## Type Aliases ```rust -use tsify::{declare, Tsify}; +use tsify_next::{declare, Tsify}; #[derive(Tsify)] struct Foo(T); diff --git a/src/lib.rs b/src/lib.rs index de9b26d..08da67a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ pub use gloo_utils::format::JsValueSerdeExt; #[cfg(feature = "js")] pub use serde_wasm_bindgen; -pub use tsify_macros::*; +pub use tsify_next_macros::*; #[cfg(feature = "wasm-bindgen")] use wasm_bindgen::{JsCast, JsValue}; diff --git a/tests/affixes.rs b/tests/affixes.rs index 2e94182..82cf3c3 100644 --- a/tests/affixes.rs +++ b/tests/affixes.rs @@ -2,7 +2,7 @@ use indoc::indoc; use pretty_assertions::assert_eq; -use tsify::Tsify; +use tsify_next::Tsify; #[test] fn test_prefix() { diff --git a/tests/enum.rs b/tests/enum.rs index 26653fe..83f3159 100644 --- a/tests/enum.rs +++ b/tests/enum.rs @@ -2,7 +2,7 @@ use indoc::indoc; use pretty_assertions::assert_eq; -use tsify::Tsify; +use tsify_next::Tsify; struct Foo { a: i32, diff --git a/tests/expand/borrow.expanded.rs b/tests/expand/borrow.expanded.rs index 2d7bfe3..4204c04 100644 --- a/tests/expand/borrow.expanded.rs +++ b/tests/expand/borrow.expanded.rs @@ -1,5 +1,5 @@ use std::borrow::Cow; -use tsify::Tsify; +use tsify_next::Tsify; #[tsify(into_wasm_abi, from_wasm_abi)] struct Borrow<'a> { raw: &'a str, @@ -8,7 +8,7 @@ struct Borrow<'a> { #[automatically_derived] const _: () = { extern crate serde as _serde; - use tsify::Tsify; + use tsify_next::Tsify; use wasm_bindgen::{ convert::{ FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi, @@ -16,22 +16,169 @@ const _: () = { }, describe::WasmDescribe, prelude::*, }; - #[wasm_bindgen] - extern "C" { - #[wasm_bindgen(typescript_type = "Borrow")] - pub type JsType; + #[automatically_derived] + /// + #[repr(transparent)] + pub struct JsType { + obj: wasm_bindgen::JsValue, + } + #[automatically_derived] + const _: () = { + use wasm_bindgen::convert::TryFromJsValue; + use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi}; + use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; + use wasm_bindgen::convert::{RefFromWasmAbi, LongRefFromWasmAbi}; + use wasm_bindgen::describe::WasmDescribe; + use wasm_bindgen::{JsValue, JsCast, JsObject}; + use wasm_bindgen::__rt::core; + impl WasmDescribe for JsType { + fn describe() { + use wasm_bindgen::describe::*; + inform(NAMED_EXTERNREF); + inform(6u32); + inform(66u32); + inform(111u32); + inform(114u32); + inform(114u32); + inform(111u32); + inform(119u32); + } + } + impl IntoWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + self.obj.into_abi() + } + } + impl OptionIntoWasmAbi for JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + impl<'a> OptionIntoWasmAbi for &'a JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + impl FromWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + JsType { + obj: JsValue::from_abi(js).into(), + } + } + } + impl OptionFromWasmAbi for JsType { + #[inline] + fn is_none(abi: &Self::Abi) -> bool { + *abi == 0 + } + } + impl<'a> IntoWasmAbi for &'a JsType { + type Abi = <&'a JsValue as IntoWasmAbi>::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self.obj).into_abi() + } + } + impl RefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = core::mem::ManuallyDrop; + #[inline] + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::ref_from_abi(js); + core::mem::ManuallyDrop::new(JsType { + obj: core::mem::ManuallyDrop::into_inner(tmp).into(), + }) + } + } + impl LongRefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = JsType; + #[inline] + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::long_ref_from_abi(js); + JsType { obj: tmp.into() } + } + } + impl From for JsType { + #[inline] + fn from(obj: JsValue) -> JsType { + JsType { obj: obj.into() } + } + } + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsValue { + self.obj.as_ref() + } + } + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsType { + self + } + } + impl From for JsValue { + #[inline] + fn from(obj: JsType) -> JsValue { + obj.obj.into() + } + } + impl JsCast for JsType { + fn instanceof(val: &JsValue) -> bool { + #[cfg( + not( + all( + target_arch = "wasm32", + not(any(target_os = "emscripten", target_os = "wasi")) + ) + ) + )] + unsafe fn __wbg_instanceof_JsType_1641ac20ec916ae7(_: u32) -> u32 { + { + ::std::rt::begin_panic( + "cannot check instanceof on non-wasm targets", + ); + }; + } + unsafe { + let idx = val.into_abi(); + __wbg_instanceof_JsType_1641ac20ec916ae7(idx) != 0 + } + } + #[inline] + fn unchecked_from_js(val: JsValue) -> Self { + JsType { obj: val.into() } + } + #[inline] + fn unchecked_from_js_ref(val: &JsValue) -> &Self { + unsafe { &*(val as *const JsValue as *const JsType) } + } + } + impl JsObject for JsType {} + }; + #[automatically_derived] + impl core::ops::Deref for JsType { + type Target = wasm_bindgen::JsValue; + #[inline] + fn deref(&self) -> &wasm_bindgen::JsValue { + &self.obj + } } impl<'a> Tsify for Borrow<'a> { type JsType = JsType; const DECL: &'static str = "export interface Borrow {\n raw: string;\n cow: string;\n}"; - const SERIALIZATION_CONFIG: tsify::SerializationConfig = tsify::SerializationConfig { + const SERIALIZATION_CONFIG: tsify_next::SerializationConfig = tsify_next::SerializationConfig { missing_as_null: false, hashmap_as_object: false, large_number_types_as_bigints: false, }; } - #[wasm_bindgen(typescript_custom_section)] - const TS_APPEND_CONTENT: &'static str = "export interface Borrow {\n raw: string;\n cow: string;\n}"; impl<'a> WasmDescribe for Borrow<'a> { #[inline] fn describe() { diff --git a/tests/expand/borrow.rs b/tests/expand/borrow.rs index b53248d..fc3c701 100644 --- a/tests/expand/borrow.rs +++ b/tests/expand/borrow.rs @@ -1,5 +1,5 @@ use std::borrow::Cow; -use tsify::Tsify; +use tsify_next::Tsify; #[derive(Tsify)] #[tsify(into_wasm_abi, from_wasm_abi)] diff --git a/tests/expand/generic_enum.expanded.rs b/tests/expand/generic_enum.expanded.rs index 492deeb..10a82ba 100644 --- a/tests/expand/generic_enum.expanded.rs +++ b/tests/expand/generic_enum.expanded.rs @@ -1,4 +1,4 @@ -use tsify::Tsify; +use tsify_next::Tsify; #[tsify(into_wasm_abi, from_wasm_abi)] pub enum GenericEnum { Unit, @@ -9,7 +9,7 @@ pub enum GenericEnum { #[automatically_derived] const _: () = { extern crate serde as _serde; - use tsify::Tsify; + use tsify_next::Tsify; use wasm_bindgen::{ convert::{ FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi, @@ -17,22 +17,174 @@ const _: () = { }, describe::WasmDescribe, prelude::*, }; - #[wasm_bindgen] - extern "C" { - #[wasm_bindgen(typescript_type = "GenericEnum")] - pub type JsType; + #[automatically_derived] + /// + #[repr(transparent)] + pub struct JsType { + obj: wasm_bindgen::JsValue, + } + #[automatically_derived] + const _: () = { + use wasm_bindgen::convert::TryFromJsValue; + use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi}; + use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; + use wasm_bindgen::convert::{RefFromWasmAbi, LongRefFromWasmAbi}; + use wasm_bindgen::describe::WasmDescribe; + use wasm_bindgen::{JsValue, JsCast, JsObject}; + use wasm_bindgen::__rt::core; + impl WasmDescribe for JsType { + fn describe() { + use wasm_bindgen::describe::*; + inform(NAMED_EXTERNREF); + inform(11u32); + inform(71u32); + inform(101u32); + inform(110u32); + inform(101u32); + inform(114u32); + inform(105u32); + inform(99u32); + inform(69u32); + inform(110u32); + inform(117u32); + inform(109u32); + } + } + impl IntoWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + self.obj.into_abi() + } + } + impl OptionIntoWasmAbi for JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + impl<'a> OptionIntoWasmAbi for &'a JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + impl FromWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + JsType { + obj: JsValue::from_abi(js).into(), + } + } + } + impl OptionFromWasmAbi for JsType { + #[inline] + fn is_none(abi: &Self::Abi) -> bool { + *abi == 0 + } + } + impl<'a> IntoWasmAbi for &'a JsType { + type Abi = <&'a JsValue as IntoWasmAbi>::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self.obj).into_abi() + } + } + impl RefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = core::mem::ManuallyDrop; + #[inline] + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::ref_from_abi(js); + core::mem::ManuallyDrop::new(JsType { + obj: core::mem::ManuallyDrop::into_inner(tmp).into(), + }) + } + } + impl LongRefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = JsType; + #[inline] + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::long_ref_from_abi(js); + JsType { obj: tmp.into() } + } + } + impl From for JsType { + #[inline] + fn from(obj: JsValue) -> JsType { + JsType { obj: obj.into() } + } + } + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsValue { + self.obj.as_ref() + } + } + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsType { + self + } + } + impl From for JsValue { + #[inline] + fn from(obj: JsType) -> JsValue { + obj.obj.into() + } + } + impl JsCast for JsType { + fn instanceof(val: &JsValue) -> bool { + #[cfg( + not( + all( + target_arch = "wasm32", + not(any(target_os = "emscripten", target_os = "wasi")) + ) + ) + )] + unsafe fn __wbg_instanceof_JsType_1641ac20ec916ae7(_: u32) -> u32 { + { + ::std::rt::begin_panic( + "cannot check instanceof on non-wasm targets", + ); + }; + } + unsafe { + let idx = val.into_abi(); + __wbg_instanceof_JsType_1641ac20ec916ae7(idx) != 0 + } + } + #[inline] + fn unchecked_from_js(val: JsValue) -> Self { + JsType { obj: val.into() } + } + #[inline] + fn unchecked_from_js_ref(val: &JsValue) -> &Self { + unsafe { &*(val as *const JsValue as *const JsType) } + } + } + impl JsObject for JsType {} + }; + #[automatically_derived] + impl core::ops::Deref for JsType { + type Target = wasm_bindgen::JsValue; + #[inline] + fn deref(&self) -> &wasm_bindgen::JsValue { + &self.obj + } } impl Tsify for GenericEnum { type JsType = JsType; const DECL: &'static str = "export type GenericEnum = \"Unit\" | { NewType: T } | { Seq: [T, U] } | { Map: { x: T; y: U } };"; - const SERIALIZATION_CONFIG: tsify::SerializationConfig = tsify::SerializationConfig { + const SERIALIZATION_CONFIG: tsify_next::SerializationConfig = tsify_next::SerializationConfig { missing_as_null: false, hashmap_as_object: false, large_number_types_as_bigints: false, }; } - #[wasm_bindgen(typescript_custom_section)] - const TS_APPEND_CONTENT: &'static str = "export type GenericEnum = \"Unit\" | { NewType: T } | { Seq: [T, U] } | { Map: { x: T; y: U } };"; impl WasmDescribe for GenericEnum { #[inline] fn describe() { diff --git a/tests/expand/generic_enum.rs b/tests/expand/generic_enum.rs index fd884e9..2da1cb0 100644 --- a/tests/expand/generic_enum.rs +++ b/tests/expand/generic_enum.rs @@ -1,4 +1,4 @@ -use tsify::Tsify; +use tsify_next::Tsify; #[derive(Tsify)] #[tsify(into_wasm_abi, from_wasm_abi)] diff --git a/tests/expand/generic_struct.expanded.rs b/tests/expand/generic_struct.expanded.rs index c82624a..f0afc35 100644 --- a/tests/expand/generic_struct.expanded.rs +++ b/tests/expand/generic_struct.expanded.rs @@ -1,4 +1,4 @@ -use tsify::Tsify; +use tsify_next::Tsify; #[tsify(into_wasm_abi, from_wasm_abi)] pub struct GenericStruct { x: T, @@ -6,7 +6,7 @@ pub struct GenericStruct { #[automatically_derived] const _: () = { extern crate serde as _serde; - use tsify::Tsify; + use tsify_next::Tsify; use wasm_bindgen::{ convert::{ FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi, @@ -14,22 +14,176 @@ const _: () = { }, describe::WasmDescribe, prelude::*, }; - #[wasm_bindgen] - extern "C" { - #[wasm_bindgen(typescript_type = "GenericStruct")] - pub type JsType; + #[automatically_derived] + /// + #[repr(transparent)] + pub struct JsType { + obj: wasm_bindgen::JsValue, + } + #[automatically_derived] + const _: () = { + use wasm_bindgen::convert::TryFromJsValue; + use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi}; + use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; + use wasm_bindgen::convert::{RefFromWasmAbi, LongRefFromWasmAbi}; + use wasm_bindgen::describe::WasmDescribe; + use wasm_bindgen::{JsValue, JsCast, JsObject}; + use wasm_bindgen::__rt::core; + impl WasmDescribe for JsType { + fn describe() { + use wasm_bindgen::describe::*; + inform(NAMED_EXTERNREF); + inform(13u32); + inform(71u32); + inform(101u32); + inform(110u32); + inform(101u32); + inform(114u32); + inform(105u32); + inform(99u32); + inform(83u32); + inform(116u32); + inform(114u32); + inform(117u32); + inform(99u32); + inform(116u32); + } + } + impl IntoWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + self.obj.into_abi() + } + } + impl OptionIntoWasmAbi for JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + impl<'a> OptionIntoWasmAbi for &'a JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + impl FromWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + JsType { + obj: JsValue::from_abi(js).into(), + } + } + } + impl OptionFromWasmAbi for JsType { + #[inline] + fn is_none(abi: &Self::Abi) -> bool { + *abi == 0 + } + } + impl<'a> IntoWasmAbi for &'a JsType { + type Abi = <&'a JsValue as IntoWasmAbi>::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self.obj).into_abi() + } + } + impl RefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = core::mem::ManuallyDrop; + #[inline] + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::ref_from_abi(js); + core::mem::ManuallyDrop::new(JsType { + obj: core::mem::ManuallyDrop::into_inner(tmp).into(), + }) + } + } + impl LongRefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = JsType; + #[inline] + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::long_ref_from_abi(js); + JsType { obj: tmp.into() } + } + } + impl From for JsType { + #[inline] + fn from(obj: JsValue) -> JsType { + JsType { obj: obj.into() } + } + } + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsValue { + self.obj.as_ref() + } + } + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsType { + self + } + } + impl From for JsValue { + #[inline] + fn from(obj: JsType) -> JsValue { + obj.obj.into() + } + } + impl JsCast for JsType { + fn instanceof(val: &JsValue) -> bool { + #[cfg( + not( + all( + target_arch = "wasm32", + not(any(target_os = "emscripten", target_os = "wasi")) + ) + ) + )] + unsafe fn __wbg_instanceof_JsType_1641ac20ec916ae7(_: u32) -> u32 { + { + ::std::rt::begin_panic( + "cannot check instanceof on non-wasm targets", + ); + }; + } + unsafe { + let idx = val.into_abi(); + __wbg_instanceof_JsType_1641ac20ec916ae7(idx) != 0 + } + } + #[inline] + fn unchecked_from_js(val: JsValue) -> Self { + JsType { obj: val.into() } + } + #[inline] + fn unchecked_from_js_ref(val: &JsValue) -> &Self { + unsafe { &*(val as *const JsValue as *const JsType) } + } + } + impl JsObject for JsType {} + }; + #[automatically_derived] + impl core::ops::Deref for JsType { + type Target = wasm_bindgen::JsValue; + #[inline] + fn deref(&self) -> &wasm_bindgen::JsValue { + &self.obj + } } impl Tsify for GenericStruct { type JsType = JsType; const DECL: &'static str = "export interface GenericStruct {\n x: T;\n}"; - const SERIALIZATION_CONFIG: tsify::SerializationConfig = tsify::SerializationConfig { + const SERIALIZATION_CONFIG: tsify_next::SerializationConfig = tsify_next::SerializationConfig { missing_as_null: false, hashmap_as_object: false, large_number_types_as_bigints: false, }; } - #[wasm_bindgen(typescript_custom_section)] - const TS_APPEND_CONTENT: &'static str = "export interface GenericStruct {\n x: T;\n}"; impl WasmDescribe for GenericStruct { #[inline] fn describe() { @@ -101,7 +255,7 @@ pub struct GenericNewtype(T); #[automatically_derived] const _: () = { extern crate serde as _serde; - use tsify::Tsify; + use tsify_next::Tsify; use wasm_bindgen::{ convert::{ FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi, @@ -109,22 +263,177 @@ const _: () = { }, describe::WasmDescribe, prelude::*, }; - #[wasm_bindgen] - extern "C" { - #[wasm_bindgen(typescript_type = "GenericNewtype")] - pub type JsType; + #[automatically_derived] + /// + #[repr(transparent)] + pub struct JsType { + obj: wasm_bindgen::JsValue, + } + #[automatically_derived] + const _: () = { + use wasm_bindgen::convert::TryFromJsValue; + use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi}; + use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; + use wasm_bindgen::convert::{RefFromWasmAbi, LongRefFromWasmAbi}; + use wasm_bindgen::describe::WasmDescribe; + use wasm_bindgen::{JsValue, JsCast, JsObject}; + use wasm_bindgen::__rt::core; + impl WasmDescribe for JsType { + fn describe() { + use wasm_bindgen::describe::*; + inform(NAMED_EXTERNREF); + inform(14u32); + inform(71u32); + inform(101u32); + inform(110u32); + inform(101u32); + inform(114u32); + inform(105u32); + inform(99u32); + inform(78u32); + inform(101u32); + inform(119u32); + inform(116u32); + inform(121u32); + inform(112u32); + inform(101u32); + } + } + impl IntoWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + self.obj.into_abi() + } + } + impl OptionIntoWasmAbi for JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + impl<'a> OptionIntoWasmAbi for &'a JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + impl FromWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + JsType { + obj: JsValue::from_abi(js).into(), + } + } + } + impl OptionFromWasmAbi for JsType { + #[inline] + fn is_none(abi: &Self::Abi) -> bool { + *abi == 0 + } + } + impl<'a> IntoWasmAbi for &'a JsType { + type Abi = <&'a JsValue as IntoWasmAbi>::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self.obj).into_abi() + } + } + impl RefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = core::mem::ManuallyDrop; + #[inline] + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::ref_from_abi(js); + core::mem::ManuallyDrop::new(JsType { + obj: core::mem::ManuallyDrop::into_inner(tmp).into(), + }) + } + } + impl LongRefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = JsType; + #[inline] + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::long_ref_from_abi(js); + JsType { obj: tmp.into() } + } + } + impl From for JsType { + #[inline] + fn from(obj: JsValue) -> JsType { + JsType { obj: obj.into() } + } + } + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsValue { + self.obj.as_ref() + } + } + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsType { + self + } + } + impl From for JsValue { + #[inline] + fn from(obj: JsType) -> JsValue { + obj.obj.into() + } + } + impl JsCast for JsType { + fn instanceof(val: &JsValue) -> bool { + #[cfg( + not( + all( + target_arch = "wasm32", + not(any(target_os = "emscripten", target_os = "wasi")) + ) + ) + )] + unsafe fn __wbg_instanceof_JsType_1641ac20ec916ae7(_: u32) -> u32 { + { + ::std::rt::begin_panic( + "cannot check instanceof on non-wasm targets", + ); + }; + } + unsafe { + let idx = val.into_abi(); + __wbg_instanceof_JsType_1641ac20ec916ae7(idx) != 0 + } + } + #[inline] + fn unchecked_from_js(val: JsValue) -> Self { + JsType { obj: val.into() } + } + #[inline] + fn unchecked_from_js_ref(val: &JsValue) -> &Self { + unsafe { &*(val as *const JsValue as *const JsType) } + } + } + impl JsObject for JsType {} + }; + #[automatically_derived] + impl core::ops::Deref for JsType { + type Target = wasm_bindgen::JsValue; + #[inline] + fn deref(&self) -> &wasm_bindgen::JsValue { + &self.obj + } } impl Tsify for GenericNewtype { type JsType = JsType; const DECL: &'static str = "export type GenericNewtype = T;"; - const SERIALIZATION_CONFIG: tsify::SerializationConfig = tsify::SerializationConfig { + const SERIALIZATION_CONFIG: tsify_next::SerializationConfig = tsify_next::SerializationConfig { missing_as_null: false, hashmap_as_object: false, large_number_types_as_bigints: false, }; } - #[wasm_bindgen(typescript_custom_section)] - const TS_APPEND_CONTENT: &'static str = "export type GenericNewtype = T;"; impl WasmDescribe for GenericNewtype { #[inline] fn describe() { diff --git a/tests/expand/generic_struct.rs b/tests/expand/generic_struct.rs index 335375b..04c1d1e 100644 --- a/tests/expand/generic_struct.rs +++ b/tests/expand/generic_struct.rs @@ -1,4 +1,4 @@ -use tsify::Tsify; +use tsify_next::Tsify; #[derive(Tsify)] #[tsify(into_wasm_abi, from_wasm_abi)] diff --git a/tests/expand/type_alias.expanded.rs b/tests/expand/type_alias.expanded.rs index b14cf87..f6c0529 100644 --- a/tests/expand/type_alias.expanded.rs +++ b/tests/expand/type_alias.expanded.rs @@ -2,6 +2,4 @@ type TypeAlias = Foo; #[automatically_derived] const _: () = { use wasm_bindgen::prelude::*; - #[wasm_bindgen(typescript_custom_section)] - const TS_APPEND_CONTENT: &'static str = "export type TypeAlias = Foo;"; }; diff --git a/tests/expand/type_alias.rs b/tests/expand/type_alias.rs index 3292edf..cb761b8 100644 --- a/tests/expand/type_alias.rs +++ b/tests/expand/type_alias.rs @@ -1,2 +1,2 @@ -#[tsify::declare] +#[tsify_next::declare] type TypeAlias = Foo; diff --git a/tests/expandtest.rs b/tests/expandtest.rs index 3c14bca..e1d3052 100644 --- a/tests/expandtest.rs +++ b/tests/expandtest.rs @@ -1,4 +1,4 @@ #[test] fn expandtest() { - macrotest::expand_args("tests/expand/*.rs", ["--features", "tsify/json"]); + macrotest::expand_args("tests/expand/*.rs", ["--features", "tsify-next/json"]); } diff --git a/tests/flatten.rs b/tests/flatten.rs index 86300d3..1919c35 100644 --- a/tests/flatten.rs +++ b/tests/flatten.rs @@ -2,7 +2,7 @@ use indoc::indoc; use pretty_assertions::assert_eq; -use tsify::Tsify; +use tsify_next::Tsify; #[test] fn test_flatten() { diff --git a/tests/generics.rs b/tests/generics.rs index bbb1414..50ed779 100644 --- a/tests/generics.rs +++ b/tests/generics.rs @@ -2,7 +2,7 @@ use indoc::indoc; use pretty_assertions::assert_eq; -use tsify::Tsify; +use tsify_next::Tsify; #[test] fn test_generic_struct() { diff --git a/tests/optional.rs b/tests/optional.rs index 2d91f69..2fe77a1 100644 --- a/tests/optional.rs +++ b/tests/optional.rs @@ -2,7 +2,7 @@ use indoc::indoc; use pretty_assertions::assert_eq; -use tsify::Tsify; +use tsify_next::Tsify; #[test] fn test_optional() { diff --git a/tests/options.rs b/tests/options.rs index 284ef09..20aacd9 100644 --- a/tests/options.rs +++ b/tests/options.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use indoc::indoc; use pretty_assertions::assert_eq; -use tsify::Tsify; +use tsify_next::Tsify; #[test] fn test_transparent() { diff --git a/tests/reference_rename.rs b/tests/reference_rename.rs index 0f641f0..d8dc930 100644 --- a/tests/reference_rename.rs +++ b/tests/reference_rename.rs @@ -2,7 +2,7 @@ use indoc::indoc; use pretty_assertions::assert_eq; -use tsify::Tsify; +use tsify_next::Tsify; #[test] fn test_reference_rename() { diff --git a/tests/rename.rs b/tests/rename.rs index 0027824..fd19025 100644 --- a/tests/rename.rs +++ b/tests/rename.rs @@ -2,7 +2,7 @@ use indoc::indoc; use pretty_assertions::assert_eq; -use tsify::Tsify; +use tsify_next::Tsify; #[test] fn test_rename() { diff --git a/tests/skip.rs b/tests/skip.rs index 2d65f50..618a90a 100644 --- a/tests/skip.rs +++ b/tests/skip.rs @@ -2,7 +2,7 @@ use indoc::indoc; use pretty_assertions::assert_eq; -use tsify::Tsify; +use tsify_next::Tsify; #[test] fn test_skip() { diff --git a/tests/struct.rs b/tests/struct.rs index abf7a49..63a7b69 100644 --- a/tests/struct.rs +++ b/tests/struct.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use indoc::indoc; use pretty_assertions::assert_eq; -use tsify::Tsify; +use tsify_next::Tsify; #[test] fn test_unit() { diff --git a/tests/transparent.rs b/tests/transparent.rs index 4667a43..75a1bc8 100644 --- a/tests/transparent.rs +++ b/tests/transparent.rs @@ -2,7 +2,7 @@ use indoc::indoc; use pretty_assertions::assert_eq; -use tsify::Tsify; +use tsify_next::Tsify; #[test] fn test_transparent() { diff --git a/tests/type_override.rs b/tests/type_override.rs index 4cbee82..7abdcf3 100644 --- a/tests/type_override.rs +++ b/tests/type_override.rs @@ -2,7 +2,7 @@ use indoc::indoc; use pretty_assertions::assert_eq; -use tsify::Tsify; +use tsify_next::Tsify; struct Unsupported; diff --git a/tests/wasm.rs b/tests/wasm.rs index 30e500a..0edb8c3 100644 --- a/tests/wasm.rs +++ b/tests/wasm.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use tsify::Tsify; +use tsify_next::Tsify; use wasm_bindgen_test::wasm_bindgen_test; #[wasm_bindgen_test] diff --git a/tsify-macros/Cargo.toml b/tsify-next-macros/Cargo.toml similarity index 59% rename from tsify-macros/Cargo.toml rename to tsify-next-macros/Cargo.toml index e738085..22a653b 100644 --- a/tsify-macros/Cargo.toml +++ b/tsify-next-macros/Cargo.toml @@ -1,12 +1,15 @@ [package] -name = "tsify-macros" -version = "0.4.5" +name = "tsify-next-macros" +version = "0.5.0" edition = "2021" -authors = ["Madono Haru "] +authors = [ + "Madono Haru ", + "Jason Siefken " +] license = "MIT OR Apache-2.0" -description = "Macros for tsify" -repository = "https://github.com/madonoharu/tsify" -homepage = "https://github.com/madonoharu/tsify" +description = "Macros for tsify-next" +repository = "https://github.com/siefkenj/tsify" +homepage = "https://github.com/siefkenj/tsify" keywords = ["wasm", "wasm-bindgen", "typescript"] categories = ["wasm"] diff --git a/tsify-macros/src/attrs.rs b/tsify-next-macros/src/attrs.rs similarity index 100% rename from tsify-macros/src/attrs.rs rename to tsify-next-macros/src/attrs.rs diff --git a/tsify-macros/src/comments.rs b/tsify-next-macros/src/comments.rs similarity index 100% rename from tsify-macros/src/comments.rs rename to tsify-next-macros/src/comments.rs diff --git a/tsify-macros/src/container.rs b/tsify-next-macros/src/container.rs similarity index 100% rename from tsify-macros/src/container.rs rename to tsify-next-macros/src/container.rs diff --git a/tsify-macros/src/ctxt.rs b/tsify-next-macros/src/ctxt.rs similarity index 100% rename from tsify-macros/src/ctxt.rs rename to tsify-next-macros/src/ctxt.rs diff --git a/tsify-macros/src/decl.rs b/tsify-next-macros/src/decl.rs similarity index 100% rename from tsify-macros/src/decl.rs rename to tsify-next-macros/src/decl.rs diff --git a/tsify-macros/src/derive.rs b/tsify-next-macros/src/derive.rs similarity index 92% rename from tsify-macros/src/derive.rs rename to tsify-next-macros/src/derive.rs index cced43e..85bf49d 100644 --- a/tsify-macros/src/derive.rs +++ b/tsify-next-macros/src/derive.rs @@ -21,10 +21,10 @@ pub fn expand(input: DeriveInput) -> syn::Result { quote! { #[automatically_derived] const _: () = { - use tsify::Tsify; + use tsify_next::Tsify; impl #impl_generics Tsify for #ident #ty_generics #where_clause { const DECL: &'static str = #decl_str; - const CONFIG: tsify::SerializationConfig; + const CONFIG: tsify_next::SerializationConfig; } }; } diff --git a/tsify-macros/src/lib.rs b/tsify-next-macros/src/lib.rs similarity index 100% rename from tsify-macros/src/lib.rs rename to tsify-next-macros/src/lib.rs diff --git a/tsify-macros/src/parser.rs b/tsify-next-macros/src/parser.rs similarity index 100% rename from tsify-macros/src/parser.rs rename to tsify-next-macros/src/parser.rs diff --git a/tsify-macros/src/type_alias.rs b/tsify-next-macros/src/type_alias.rs similarity index 100% rename from tsify-macros/src/type_alias.rs rename to tsify-next-macros/src/type_alias.rs diff --git a/tsify-macros/src/typescript.rs b/tsify-next-macros/src/typescript.rs similarity index 100% rename from tsify-macros/src/typescript.rs rename to tsify-next-macros/src/typescript.rs diff --git a/tsify-macros/src/wasm_bindgen.rs b/tsify-next-macros/src/wasm_bindgen.rs similarity index 97% rename from tsify-macros/src/wasm_bindgen.rs rename to tsify-next-macros/src/wasm_bindgen.rs index 39946eb..b268079 100644 --- a/tsify-macros/src/wasm_bindgen.rs +++ b/tsify-next-macros/src/wasm_bindgen.rs @@ -50,7 +50,7 @@ pub fn expand(cont: &Container, decl: Decl) -> TokenStream { #[automatically_derived] const _: () = { #use_serde - use tsify::Tsify; + use tsify_next::Tsify; use wasm_bindgen::{ convert::{FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi, RefFromWasmAbi}, describe::WasmDescribe, @@ -67,7 +67,7 @@ pub fn expand(cont: &Container, decl: Decl) -> TokenStream { impl #impl_generics Tsify for #ident #ty_generics #where_clause { type JsType = JsType; const DECL: &'static str = #decl_str; - const SERIALIZATION_CONFIG: tsify::SerializationConfig = tsify::SerializationConfig { + const SERIALIZATION_CONFIG: tsify_next::SerializationConfig = tsify_next::SerializationConfig { missing_as_null: #missing_as_null, hashmap_as_object: #hashmap_as_object, large_number_types_as_bigints: #large_number_types_as_bigints,