From cd7c7a342f1c74f9a31a3499aac98dd8303d6d10 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Wed, 8 Dec 2021 17:32:16 +0800 Subject: [PATCH] fix(napi-derive-backend): missing crate prefix --- crates/backend/src/codegen/struct.rs | 12 ++++++++---- examples/napi/__test__/typegen.spec.ts.md | 5 +++++ examples/napi/__test__/typegen.spec.ts.snap | Bin 1932 -> 1954 bytes examples/napi/index.d.ts | 5 +++++ examples/napi/src/class.rs | 6 ++++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/backend/src/codegen/struct.rs b/crates/backend/src/codegen/struct.rs index 1af55d32..887833c9 100644 --- a/crates/backend/src/codegen/struct.rs +++ b/crates/backend/src/codegen/struct.rs @@ -120,9 +120,9 @@ impl NapiStruct { let ty = &field.ty; match &field.name { syn::Member::Named(ident) => fields - .push(quote! { #ident: <#ty as FromNapiValue>::from_napi_value(env, cb.get_arg(#i))? }), + .push(quote! { #ident: <#ty as napi::bindgen_prelude::FromNapiValue>::from_napi_value(env, cb.get_arg(#i))? }), syn::Member::Unnamed(_) => { - fields.push(quote! { <#ty as FromNapiValue>::from_napi_value(env, cb.get_arg(#i))? }); + fields.push(quote! { <#ty as napi::bindgen_prelude::FromNapiValue>::from_napi_value(env, cb.get_arg(#i))? }); } } } @@ -171,11 +171,15 @@ impl NapiStruct { match &field.name { syn::Member::Named(ident) => { field_destructions.push(quote! { #ident }); - field_conversions.push(quote! { <#ty as ToNapiValue>::to_napi_value(env, #ident)? }); + field_conversions.push( + quote! { <#ty as napi::bindgen_prelude::ToNapiValue>::to_napi_value(env, #ident)? }, + ); } syn::Member::Unnamed(i) => { field_destructions.push(quote! { arg #i }); - field_conversions.push(quote! { <#ty as ToNapiValue>::to_napi_value(env, arg #i)? }); + field_conversions.push( + quote! { <#ty as napi::bindgen_prelude::ToNapiValue>::to_napi_value(env, arg #i)? }, + ); } } } diff --git a/examples/napi/__test__/typegen.spec.ts.md b/examples/napi/__test__/typegen.spec.ts.md index 4b3b4e40..3fe058e5 100644 --- a/examples/napi/__test__/typegen.spec.ts.md +++ b/examples/napi/__test__/typegen.spec.ts.md @@ -147,6 +147,11 @@ Generated by [AVA](https://avajs.dev). static withData(data: string): Context␊ method(): string␊ }␊ + export class AnimalWithDefaultConstructor {␊ + name: string␊ + kind: number␊ + constructor(name: string, kind: number)␊ + }␊ export class ClassWithFactory {␊ name: string␊ static withName(name: string): ClassWithFactory␊ diff --git a/examples/napi/__test__/typegen.spec.ts.snap b/examples/napi/__test__/typegen.spec.ts.snap index b73f0fe81fb13d3e92602bcefe849a7fbb51cd12..d60e614ed6df907f2aeff4b94a284940b2577236 100644 GIT binary patch literal 1954 zcmV;T2VM9{qg%>FMs*z zv(Nwe^S57rzSh7$t2Y{r>x~cW`r7-A58wOb#_f5+wBXX*in*qtU}XOG+#EX_s??B3 zP_4<$Qo@l8~hZML&~~;YyML zGtX5T>!8^toiwGRJKCgN4%V%T2h3=qRl;(1?J4m^bhE^h;Aq!NggQ$sA)MMovMJQgF=nRTW4*^2N2&* z90#;bHuzvinidI*WwTh6_#&{_Fn1VSjcjLa^#V%p@8)S7L{x~7M#pV}7g-#8f!tju zCyK`)0ROXblXS?*UGk2cK+I6aU9#LFebAVtOvBf~P0iAn-Fl;yym?5@tKwRCzN~pG zO;t+11+d1f&n1gn1P+$&6*l=tu$Gw+B{OHWF>a1nx@Y-!)2PhKI)UQw(}Z&tC#A7708`v#Q=kI zDZrXA*dr%YWDr%FGJN@l%S=IHSXqXrYba_2q?1K2#Fpz3m$5Y#JmNxVcnpvu-1#OoaK2QW_oz0boHL7#5ovjTdZ{w7ClfIV0ZPXNZVLvnA)%nS z4*-IzNp?E6In(YY3$vDPX4)uB9b5Q?ChtmC*Z>dPq8pb-DZ~90{Mc4m3hPx|@9{HO zuHkZv5023OFYu$wt(-3{Gs9Q1v{)4=P}@^GE6V|EPa9K@M01p?Q~OSWI>fsSP?U*4 z^KY1k)|v8Am!+nKxaSj~N0~HUqMVUd%*XElK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