Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #25 #26

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests-e2e/test3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "test3"
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"
10 changes: 10 additions & 0 deletions tests-e2e/test3/entry_point.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use serde::Serialize;
use tsify_next::Tsify;
use wasm_bindgen::prelude::*;

#[derive(Serialize, Tsify)]
#[tsify(into_wasm_abi)]
pub struct Identified<Id, Value> {
pub id: Id,
pub value: Value,
}
5 changes: 4 additions & 1 deletion tests/expand/borrow.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ const _: () = {
<JsType as OptionIntoWasmAbi>::none()
}
}
impl<'a> From<Borrow<'a>> for JsValue {
impl<'a> From<Borrow<'a>> for JsValue
where
Borrow<'a>: _serde::Serialize,
{
#[inline]
fn from(value: Borrow<'a>) -> Self {
value.into_js().unwrap_throw().into()
Expand Down
5 changes: 4 additions & 1 deletion tests/expand/generic_enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ const _: () = {
<JsType as OptionIntoWasmAbi>::none()
}
}
impl<T, U> From<GenericEnum<T, U>> for JsValue {
impl<T, U> From<GenericEnum<T, U>> for JsValue
where
GenericEnum<T, U>: _serde::Serialize,
{
#[inline]
fn from(value: GenericEnum<T, U>) -> Self {
value.into_js().unwrap_throw().into()
Expand Down
10 changes: 8 additions & 2 deletions tests/expand/generic_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ const _: () = {
<JsType as OptionIntoWasmAbi>::none()
}
}
impl<T> From<GenericStruct<T>> for JsValue {
impl<T> From<GenericStruct<T>> for JsValue
where
GenericStruct<T>: _serde::Serialize,
{
#[inline]
fn from(value: GenericStruct<T>) -> Self {
value.into_js().unwrap_throw().into()
Expand Down Expand Up @@ -465,7 +468,10 @@ const _: () = {
<JsType as OptionIntoWasmAbi>::none()
}
}
impl<T> From<GenericNewtype<T>> for JsValue {
impl<T> From<GenericNewtype<T>> for JsValue
where
GenericNewtype<T>: _serde::Serialize,
{
#[inline]
fn from(value: GenericNewtype<T>) -> Self {
value.into_js().unwrap_throw().into()
Expand Down
9 changes: 7 additions & 2 deletions tsify-next-macros/src/wasm_bindgen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use proc_macro2::TokenStream;
use quote::quote;
use syn::parse_quote;
use syn::{parse_quote, WhereClause};

use crate::{container::Container, decl::Decl};

Expand Down Expand Up @@ -94,6 +94,11 @@ fn expand_into_wasm_abi(cont: &Container) -> TokenStream {

let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

let serde_where_clause = WhereClause {
where_token: parse_quote!(where),
predicates: parse_quote!(#ident #ty_generics: #serde_path::Serialize),
};

quote! {
impl #impl_generics IntoWasmAbi for #ident #ty_generics #where_clause {
type Abi = <JsType as IntoWasmAbi>::Abi;
Expand All @@ -111,7 +116,7 @@ fn expand_into_wasm_abi(cont: &Container) -> TokenStream {
}
}

impl #impl_generics From<#ident #ty_generics> for JsValue {
impl #impl_generics From<#ident #ty_generics> for JsValue #serde_where_clause {
#[inline]
fn from(value: #ident #ty_generics) -> Self {
value.into_js().unwrap_throw().into()
Expand Down
Loading