Skip to content

Commit

Permalink
Rename to tsify-next (#17)
Browse files Browse the repository at this point in the history
* Rename crate
* Bump version to 0.5
  • Loading branch information
siefkenj authored Apr 10, 2024
1 parent 9e257f9 commit 9d91b05
Show file tree
Hide file tree
Showing 37 changed files with 705 additions and 88 deletions.
46 changes: 27 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
[package]
name = "tsify"
version = "0.4.5"
name = "tsify-next"
version = "0.5.0"
edition = "2021"
authors = ["Madono Haru <[email protected]>"]
authors = [
"Madono Haru <[email protected]>",
"Jason Siefken <[email protected]>"
]
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"]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -100,7 +100,7 @@ Serde attributes
## Type Override

```rust
use tsify::Tsify;
use tsify_next::Tsify;

#[derive(Tsify)]
pub struct Foo {
Expand Down Expand Up @@ -209,7 +209,7 @@ export type Color =
## Type Aliases

```rust
use tsify::{declare, Tsify};
use tsify_next::{declare, Tsify};

#[derive(Tsify)]
struct Foo<T>(T);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion tests/affixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use indoc::indoc;
use pretty_assertions::assert_eq;
use tsify::Tsify;
use tsify_next::Tsify;

#[test]
fn test_prefix() {
Expand Down
2 changes: 1 addition & 1 deletion tests/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use indoc::indoc;
use pretty_assertions::assert_eq;
use tsify::Tsify;
use tsify_next::Tsify;

struct Foo {
a: i32,
Expand Down
165 changes: 156 additions & 9 deletions tests/expand/borrow.expanded.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -8,30 +8,177 @@ 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,
RefFromWasmAbi,
},
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 = <JsValue as IntoWasmAbi>::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 = <JsValue as FromWasmAbi>::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 = <JsValue as RefFromWasmAbi>::Abi;
type Anchor = core::mem::ManuallyDrop<JsType>;
#[inline]
unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor {
let tmp = <JsValue as RefFromWasmAbi>::ref_from_abi(js);
core::mem::ManuallyDrop::new(JsType {
obj: core::mem::ManuallyDrop::into_inner(tmp).into(),
})
}
}
impl LongRefFromWasmAbi for JsType {
type Abi = <JsValue as LongRefFromWasmAbi>::Abi;
type Anchor = JsType;
#[inline]
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor {
let tmp = <JsValue as LongRefFromWasmAbi>::long_ref_from_abi(js);
JsType { obj: tmp.into() }
}
}
impl From<JsValue> for JsType {
#[inline]
fn from(obj: JsValue) -> JsType {
JsType { obj: obj.into() }
}
}
impl AsRef<JsValue> for JsType {
#[inline]
fn as_ref(&self) -> &JsValue {
self.obj.as_ref()
}
}
impl AsRef<JsType> for JsType {
#[inline]
fn as_ref(&self) -> &JsType {
self
}
}
impl From<JsType> 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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/expand/borrow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::borrow::Cow;
use tsify::Tsify;
use tsify_next::Tsify;

#[derive(Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
Expand Down
Loading

0 comments on commit 9d91b05

Please sign in to comment.