fix(napi-derive): should not generate this types for Constructor/Getter/Setter

This commit is contained in:
LongYinan 2022-08-30 16:39:51 +08:00
parent 7e3b1ef330
commit 32a039aad0
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
2 changed files with 21 additions and 13 deletions

View file

@ -65,6 +65,7 @@ pub(crate) static PRIMITIVE_TYPES: &[(&str, &str)] = &[
("i16", "number"),
("i32", "number"),
("i64", "number"),
("f32", "number"),
("f64", "number"),
("u8", "number"),
("u16", "number"),

View file

@ -139,24 +139,31 @@ impl NapiFn {
return None;
}
if let syn::Type::Path(path) = path.ty.as_ref() {
if let Some(PathSegment {
ident,
arguments:
PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {
args: angle_bracketed_args,
..
}),
}) = path.path.segments.last()
{
if let Some(PathSegment { ident, arguments }) = path.path.segments.last() {
if ident == "Reference" || ident == "WeakReference" {
return None;
}
if ident == "This" {
if let Some(syn::GenericArgument::Type(ty)) = angle_bracketed_args.first() {
let (ts_type, _) = ty_to_ts_type(ty, false, false);
if ident == "This" || ident == "this" {
if self.kind != FnKind::Normal {
return None;
}
if let PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {
args: angle_bracketed_args,
..
}) = arguments
{
if let Some(syn::GenericArgument::Type(ty)) = angle_bracketed_args.first() {
let (ts_type, _) = ty_to_ts_type(ty, false, false);
return Some(FnArg {
arg: "this".to_owned(),
ts_type,
is_optional: false,
});
}
} else {
return Some(FnArg {
arg: "this".to_owned(),
ts_type,
ts_type: "this".to_owned(),
is_optional: false,
});
}