From 3e187151a608522eda6497be8b61e6b0adfdb564 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Sun, 25 Feb 2024 00:56:30 +0800 Subject: [PATCH] fix(napi-derive): HashMap/IndexMap and slice generated types (#1977) --- crates/backend/src/codegen/fn.rs | 6 ++-- crates/backend/src/lib.rs | 18 ++++++++++ crates/backend/src/typegen.rs | 16 ++++++++- .../__snapshots__/typegen.spec.ts.md | 34 +++++++++--------- .../__snapshots__/typegen.spec.ts.snap | Bin 4577 -> 4598 bytes .../__snapshots__/values.spec.ts.snap | Bin 368 -> 368 bytes examples/napi/index.d.ts | 34 +++++++++--------- 7 files changed, 69 insertions(+), 39 deletions(-) diff --git a/crates/backend/src/codegen/fn.rs b/crates/backend/src/codegen/fn.rs index a2f3d42b..66973867 100644 --- a/crates/backend/src/codegen/fn.rs +++ b/crates/backend/src/codegen/fn.rs @@ -5,6 +5,7 @@ use syn::spanned::Spanned; use crate::{ codegen::{get_intermediate_ident, js_mod_to_token_stream}, BindgenResult, CallbackArg, Diagnostic, FnKind, FnSelf, NapiFn, NapiFnArgKind, TryToTokens, + TYPEDARRAY_SLICE_TYPES, }; impl TryToTokens for NapiFn { @@ -428,10 +429,7 @@ impl NapiFn { if let syn::Type::Slice(slice) = &**elem { if let syn::Type::Path(ele) = &*slice.elem { if let Some(syn::PathSegment { ident, .. }) = ele.path.segments.first() { - static TYPEDARRAY_SLICE_TYPES: &[&str] = &[ - "u8", "i8", "u16", "i16", "u32", "i32", "f32", "f64", "u64", "i64", - ]; - if TYPEDARRAY_SLICE_TYPES.contains(&&*ident.to_string()) { + if TYPEDARRAY_SLICE_TYPES.contains_key(&&*ident.to_string()) { let q = quote! { let #arg_name = { #type_check diff --git a/crates/backend/src/lib.rs b/crates/backend/src/lib.rs index 16881cb6..aff83ba7 100644 --- a/crates/backend/src/lib.rs +++ b/crates/backend/src/lib.rs @@ -1,6 +1,9 @@ #[macro_use] extern crate quote; +use std::collections::HashMap; + +use once_cell::sync::Lazy; use proc_macro2::TokenStream; #[macro_use] @@ -105,3 +108,18 @@ pub(crate) static PRIMITIVE_TYPES: &[(&str, (&str, bool, bool))] = &[ ("JsSymbol", ("symbol", false, false)), ("JsFunction", ("(...args: any[]) => any", true, false)), ]; + +pub(crate) static TYPEDARRAY_SLICE_TYPES: Lazy> = Lazy::new(|| { + HashMap::from([ + ("u8", "Uint8Array"), + ("i8", "Int8Array"), + ("u16", "Uint16Array"), + ("i16", "Int16Array"), + ("u32", "Uint32Array"), + ("i32", "Int32Array"), + ("f32", "Float32Array"), + ("f64", "Float64Array"), + ("u64", "BigUint64Array"), + ("i64", "BigInt64Array"), + ]) +}); diff --git a/crates/backend/src/typegen.rs b/crates/backend/src/typegen.rs index a05ba110..4e853151 100644 --- a/crates/backend/src/typegen.rs +++ b/crates/backend/src/typegen.rs @@ -6,7 +6,7 @@ pub(crate) mod r#struct; use std::{cell::RefCell, collections::HashMap, env}; use once_cell::sync::Lazy; -use syn::Type; +use syn::{PathSegment, Type, TypePath, TypeSlice}; pub static NAPI_RS_CLI_VERSION: Lazy = Lazy::new(|| { let version = env::var("CARGO_CFG_NAPI_RS_CLI_VERSION").unwrap_or_else(|_| "0.0.0".to_string()); @@ -147,11 +147,14 @@ static KNOWN_TYPES: Lazy> = La ("Value", ("any", false, false)), ("Map", ("Record", false, false)), ("HashMap", ("Record<{}, {}>", false, false)), + ("BTreeMap", ("Record<{}, {}>", false, false)), + ("IndexMap", ("Record<{}, {}>", false, false)), ("ArrayBuffer", ("ArrayBuffer", false, false)), ("JsArrayBuffer", ("ArrayBuffer", false, false)), ("Int8Array", ("Int8Array", false, false)), ("Uint8Array", ("Uint8Array", false, false)), ("Uint8ClampedArray", ("Uint8ClampedArray", false, false)), + ("Uint8ClampedSlice", ("Uint8ClampedArray", false, false)), ("Int16Array", ("Int16Array", false, false)), ("Uint16Array", ("Uint16Array", false, false)), ("Int32Array", ("Int32Array", false, false)), @@ -166,6 +169,7 @@ static KNOWN_TYPES: Lazy> = La ("Date", ("Date", false, false)), ("JsDate", ("Date", false, false)), ("JsBuffer", ("Buffer", false, false)), + ("BufferSlice", ("Buffer", false, false)), ("Buffer", ("Buffer", false, false)), ("Vec", ("Array<{}>", false, false)), ("Result", ("Error | {}", false, true)), @@ -445,6 +449,16 @@ pub fn ty_to_ts_type( ty_to_ts_type(&p.elem, is_return_ty, is_struct_field, false); (element_type, is_optional) } + Type::Slice(TypeSlice { elem, .. }) => { + if let Type::Path(TypePath { path, .. }) = &**elem { + if let Some(PathSegment { ident, .. }) = path.segments.last() { + if let Some(js_type) = crate::TYPEDARRAY_SLICE_TYPES.get(&ident.to_string().as_str()) { + return (js_type.to_string(), false); + } + } + } + ("any[]".to_owned(), false) + } _ => ("any".to_owned(), false), } } diff --git a/examples/napi/__tests__/__snapshots__/typegen.spec.ts.md b/examples/napi/__tests__/__snapshots__/typegen.spec.ts.md index 93e4c626..d82ccfe6 100644 --- a/examples/napi/__tests__/__snapshots__/typegen.spec.ts.md +++ b/examples/napi/__tests__/__snapshots__/typegen.spec.ts.md @@ -85,7 +85,7 @@ Generated by [AVA](https://avajs.dev). constructor(name: string)␊ getCount(): number␊ getNameAsync(): Promise␊ - acceptSliceMethod(slice: any): number␊ + acceptSliceMethod(slice: Uint8Array): number␊ }␊ ␊ /** Smoking test for type generation */␊ @@ -247,7 +247,7 @@ Generated by [AVA](https://avajs.dev). foo: number␊ }␊ ␊ - export function acceptSlice(fixture: any): bigint␊ + export function acceptSlice(fixture: Uint8Array): bigint␊ ␊ export function acceptThreadsafeFunction(func: (err: Error | null, arg: number) => any): void␊ ␊ @@ -423,15 +423,15 @@ Generated by [AVA](https://avajs.dev). ␊ export function enumToI32(e: CustomNumEnum): number␊ ␊ - export function f32ArrayToArray(input: any): Array␊ + export function f32ArrayToArray(input: Float32Array): Array␊ ␊ - export function f64ArrayToArray(input: any): Array␊ + export function f64ArrayToArray(input: Float64Array): Array␊ ␊ export function fibonacci(n: number): number␊ ␊ export function fnReceivedAliased(s: AliasedStruct, e: ALIAS): void␊ ␊ - export function getBtreeMapping(): BTreeMap␊ + export function getBtreeMapping(): Record␊ ␊ export function getBuffer(): Buffer␊ ␊ @@ -443,7 +443,7 @@ Generated by [AVA](https://avajs.dev). ␊ export function getGlobal(): typeof global␊ ␊ - export function getIndexMapping(): IndexMap␊ + export function getIndexMapping(): Record␊ ␊ export function getMapping(): Record␊ ␊ @@ -468,15 +468,15 @@ Generated by [AVA](https://avajs.dev). ␊ export function getWords(): Array␊ ␊ - export function i16ArrayToArray(input: any): Array␊ + export function i16ArrayToArray(input: Int16Array): Array␊ ␊ - export function i32ArrayToArray(input: any): Array␊ + export function i32ArrayToArray(input: Int32Array): Array␊ ␊ - export function i64ArrayToArray(input: any): Array␊ + export function i64ArrayToArray(input: BigInt64Array): Array␊ ␊ - export function i8ArrayToArray(input: any): Array␊ + export function i8ArrayToArray(input: Int8Array): Array␊ ␊ - export function indexmapPassthrough(fixture: IndexMap): IndexMap␊ + export function indexmapPassthrough(fixture: Record): Record␊ ␊ /** default enum values are continuos i32s start from 0 */␊ export const enum Kind {␊ @@ -604,9 +604,9 @@ Generated by [AVA](https://avajs.dev). name: string␊ }␊ ␊ - export function sumBtreeMapping(nums: BTreeMap): number␊ + export function sumBtreeMapping(nums: Record): number␊ ␊ - export function sumIndexMapping(nums: IndexMap): number␊ + export function sumIndexMapping(nums: Record): number␊ ␊ export function sumMapping(nums: Record): number␊ ␊ @@ -649,13 +649,13 @@ Generated by [AVA](https://avajs.dev). typeOverrideOptional?: object␊ }␊ ␊ - export function u16ArrayToArray(input: any): Array␊ + export function u16ArrayToArray(input: Uint16Array): Array␊ ␊ - export function u32ArrayToArray(input: any): Array␊ + export function u32ArrayToArray(input: Uint32Array): Array␊ ␊ - export function u64ArrayToArray(input: any): Array␊ + export function u64ArrayToArray(input: BigUint64Array): Array␊ ␊ - export function u8ArrayToArray(input: any): Array␊ + export function u8ArrayToArray(input: Uint8Array): Array␊ ␊ export interface UseNullableStruct {␊ requiredNumberField: number␊ diff --git a/examples/napi/__tests__/__snapshots__/typegen.spec.ts.snap b/examples/napi/__tests__/__snapshots__/typegen.spec.ts.snap index d8e2ce56a278216354cef86cd67eef84282c30dd..a5c5f0a0580df5e3d5a4a00a7d70c6b0cae6e8d9 100644 GIT binary patch literal 4598 zcmVedk!%>wU}a+@TRwR$$Y`RBj?<=vzEgyvd2@IWb(PAz zDq~zfNSUIO4DjaG7F;cb)FjEMQsniO2FYo5I{6HV{%-t&eAyyI0!;uU4n(aM6Ooz6AHN^C%TEI`-Xi3B>w4?a{rg+wKKUsTTxppnTF9S>SZXFXnF>jM zvUh(X5`NB^1Vw0;ktu^LRYVIi0kX^|8B6*IBlH~PB~w5&oe{QJW@O35}z=yW5|(aO#zb4>?=V%uMdl{rlv5##17ugxcHpABC%M&UiX7B#wGKXNoXI^c=#` zEn9G-S910VrwbSmr6uFD?HUjzQ;G~LvH(37sYOznYL<{orsoI|pluJ_1hxp7fi~E^ zZI6zu{$_ntq(((UYBwY0Zw2^PK76%-koIzsXPQ087{|FU7QnT=k75$a2`t2CM*jMz z|NakiA187-7j(fY0*14<^L+U5VP)Dg(67YIOnf_BeLLE3Kmwr>h!P7R$(%}>Xpo9f zo|czH!OuDH1eE2{bE=8ke-j{}61s%c@4##|uw=jg`02~_qu&p{{q~E!aa~MBg3cvB zMO{2VMMBwLiCN^y4@}Pwa;3%MAkc{I0oi8~ry?#uN|wSAPuT@abD9n1?35oH1?X`h z7c?8M{F3!OeF_}!e&PPfwTHakim5n?@d~Ci&vYP%QT$Lhwun=6o-ZaKYkC|~_A7+j zkzqx#28TkvW_V@B3lZD-lp5((2BSHEHf*S}GS9%Q^?_1nc?R#8(p%Raz*tVtKN$V$1PsuJ3v(Hg&}dXA&J#iLV`bv17W$|H@A4k;& zLLG>`*0%TPBsdT`*TLM(%@ewSp<3|-AH0`h!4!OF*u)CId>49zx`p1)=sE1}|As2BKcPK@Rqq^D14lLa z9&p48%N8N|GNl@N=spKzKc7y`Dqjee*4EacxUu$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g*fgv@CmRUh9A^8RZ<(}+I8o%s3#x$y;oSntO0wSKOwJ#C_Gpn<;{CbGwk*TJJ~{cSY4h`S-cD)19O~bJVW~TdmkyX{#g} zHLHmjYSCl~IYl(a4`A`2>&GU9S0Z=9{l=TRCgk=sTf=OTW>x@C<|hf{3oNSC|JtsH znn)PSXem|wf!9UUXv6V}U@zC(UXP_&G6?}5^k4nYK`}khbsPaXzPc|sNicQScL(+k zp?+6U1O<9~J)L+?$6k>*>WaOBew#vCr_22h?eB+}8NT5`go+E}=BFCI03U+iay?W( z9(v<{_k`C&6i<90vQ?=z2Rw?RJlAsa0I^i1(uhvx-GW%g@fWSyDX8*~MlTf#TCnhA zzX?Vahisw!$6GLUOsMczJv(aRJ##sQ3#*Xk<11aU@Z;3(<;~{`V|~YNn+k7vLtiJW z`W{d5CP-bg-5)*W>h6gswiaD|5kY>X0x(UZv4g9Okps6-ooo^rTx&>*|1A=b5QNat zr`&4<>B+< z+X3_5W7o4UCP!7(z%fY&p!-sq8a&RHZ`>z7t*M|h2%~6pNwm|7SWYoiLy_iKk zR6@)Hw60du98CvVJ+@U)mt&c>U8fzii@%rZWB1M$D;HchW^Ij9l%nr&A7_bpdQ&=c z4vULljn?oy^wnA4<*oUGgn*EH*5J)iyDHl|P!n5PpH5@;HVa^?mm- zAc8H_J&S^#sE2I?h!cP}-DZw$$X#DA!LsAUzZFn!3Mw`S9idpGO$HqO(Xxlw9)45M z@uiCw@yU;!oZR?%d6Hk){fH0xGb&Y-wP~6f`O!kw|L6sct^XtsjhX+s9#vLUScUH+ zwt%$3X<;PlkM1dDhNCwp-=CcxolTvk<4nNx?%wla`7X1rOz`W023h!J_`7FMTZH#F LLLca6AWQ%Nba%)d diff --git a/examples/napi/__tests__/__snapshots__/values.spec.ts.snap b/examples/napi/__tests__/__snapshots__/values.spec.ts.snap index f693200f2138abfed89c24cef35dfd670dffa354..84b413863d284fa14c228a24b35f2156dcc80667 100644 GIT binary patch literal 368 zcmV-$0gwJcRzV$19CGwq&^o{O!r5} zYrmx}G9QZw00000000A3k2_8SF%(7bV=|LJqbSh88b;};!wzWaaAq9h;MgNSXQEUn zVht=Hlrm-p$=(@us^*1{yxUim zit3iW60~tR)S>(iz#PC6fL8$T06qa^1Y8nuMZgUK3j!VqcqZVDfDZ!3l#M984nb{+ zLo^RhuI4q_pN&5{W%O+Ku8>5!No6m6q&8vf(stYt0ku zE5!@ZiRgUVn5a2UX2EY*2MJmd^dwjxC#2#M)hL0Pz-}2lbD>=$sx7LctuABmPE1Ek z_J3Yic*@58g3RWOYX O#(x7Ue7w^o0ssJ;2cfb6 literal 368 zcmV-$0gwJcRzVv99O>~Is8y0~`aaZ`1L zD$c+G%92~K?oO#rp3{9@~e-+_>ri_b)2wVAKkguT`-^XEj>c;L-)$ zAL?2Lc?(~W7>MHsDdczbUl32kEAdWz5(x-#Nn8;(#FBUssnHW>5DAEiC5H)z!^%6vLfMwpfK{rDs)BcxP0A+u zKi-h@7`6SYXB_vBGjTfN^x~KnjoI95TUbZ$**LRXXk(DO<8H&BQ*l1we6&^b+Ur(% O?Y;pje7w^o0ssI>CaIkO diff --git a/examples/napi/index.d.ts b/examples/napi/index.d.ts index 814003eb..800e9771 100644 --- a/examples/napi/index.d.ts +++ b/examples/napi/index.d.ts @@ -75,7 +75,7 @@ export class Bird { constructor(name: string) getCount(): number getNameAsync(): Promise - acceptSliceMethod(slice: any): number + acceptSliceMethod(slice: Uint8Array): number } /** Smoking test for type generation */ @@ -237,7 +237,7 @@ export interface A { foo: number } -export function acceptSlice(fixture: any): bigint +export function acceptSlice(fixture: Uint8Array): bigint export function acceptThreadsafeFunction(func: (err: Error | null, arg: number) => any): void @@ -413,15 +413,15 @@ export const enum Empty { export function enumToI32(e: CustomNumEnum): number -export function f32ArrayToArray(input: any): Array +export function f32ArrayToArray(input: Float32Array): Array -export function f64ArrayToArray(input: any): Array +export function f64ArrayToArray(input: Float64Array): Array export function fibonacci(n: number): number export function fnReceivedAliased(s: AliasedStruct, e: ALIAS): void -export function getBtreeMapping(): BTreeMap +export function getBtreeMapping(): Record export function getBuffer(): Buffer @@ -433,7 +433,7 @@ export function getExternal(external: ExternalObject): number export function getGlobal(): typeof global -export function getIndexMapping(): IndexMap +export function getIndexMapping(): Record export function getMapping(): Record @@ -458,15 +458,15 @@ export function getUndefined(): void export function getWords(): Array -export function i16ArrayToArray(input: any): Array +export function i16ArrayToArray(input: Int16Array): Array -export function i32ArrayToArray(input: any): Array +export function i32ArrayToArray(input: Int32Array): Array -export function i64ArrayToArray(input: any): Array +export function i64ArrayToArray(input: BigInt64Array): Array -export function i8ArrayToArray(input: any): Array +export function i8ArrayToArray(input: Int8Array): Array -export function indexmapPassthrough(fixture: IndexMap): IndexMap +export function indexmapPassthrough(fixture: Record): Record /** default enum values are continuos i32s start from 0 */ export const enum Kind { @@ -594,9 +594,9 @@ export interface StrictObject { name: string } -export function sumBtreeMapping(nums: BTreeMap): number +export function sumBtreeMapping(nums: Record): number -export function sumIndexMapping(nums: IndexMap): number +export function sumIndexMapping(nums: Record): number export function sumMapping(nums: Record): number @@ -639,13 +639,13 @@ export interface TsTypeChanged { typeOverrideOptional?: object } -export function u16ArrayToArray(input: any): Array +export function u16ArrayToArray(input: Uint16Array): Array -export function u32ArrayToArray(input: any): Array +export function u32ArrayToArray(input: Uint32Array): Array -export function u64ArrayToArray(input: any): Array +export function u64ArrayToArray(input: BigUint64Array): Array -export function u8ArrayToArray(input: any): Array +export function u8ArrayToArray(input: Uint8Array): Array export interface UseNullableStruct { requiredNumberField: number