fix(napi-derive-backend): missing crate prefix

This commit is contained in:
LongYinan 2021-12-08 17:32:16 +08:00
parent 3ae12f7c36
commit cd7c7a342f
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
5 changed files with 24 additions and 4 deletions

View file

@ -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)? },
);
}
}
}

View file

@ -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␊

View file

@ -137,6 +137,11 @@ export class Context {
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

View file

@ -114,3 +114,9 @@ impl Context {
self.data.clone()
}
}
#[napi(constructor)]
pub struct AnimalWithDefaultConstructor {
pub name: String,
pub kind: u32,
}