From cc79c9794ebe202837ea847d598c4c1af6320b76 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Tue, 26 Apr 2022 17:49:53 +0800 Subject: [PATCH] fix(napi-derive): should transform struct case on Impl --- crates/macro/src/parser/mod.rs | 2 +- examples/napi/__test__/typegen.spec.ts.md | 2 +- examples/napi/__test__/typegen.spec.ts.snap | Bin 2926 -> 2924 bytes examples/napi/index.d.ts | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/macro/src/parser/mod.rs b/crates/macro/src/parser/mod.rs index 53947c19..a331ea41 100644 --- a/crates/macro/src/parser/mod.rs +++ b/crates/macro/src/parser/mod.rs @@ -816,7 +816,7 @@ impl ConvertToAST for syn::ItemImpl { let struct_name = extract_path_ident(struct_name)?; - let mut struct_js_name = struct_name.to_string(); + let mut struct_js_name = struct_name.to_string().to_case(Case::UpperCamel); let mut items = vec![]; let mut task_output_type = None; for item in self.items.iter_mut() { diff --git a/examples/napi/__test__/typegen.spec.ts.md b/examples/napi/__test__/typegen.spec.ts.md index 5f236e26..30492b9a 100644 --- a/examples/napi/__test__/typegen.spec.ts.md +++ b/examples/napi/__test__/typegen.spec.ts.md @@ -217,7 +217,7 @@ Generated by [AVA](https://avajs.dev). export type Blake2bHasher = Blake2BHasher␊ /** Smoking test for type generation */␊ export class Blake2BHasher {␊ - static withKey(key: Blake2bKey): Blake2BHasher␊ + update(data: Buffer): void␊ }␊ export type Blake2bKey = Blake2BKey␊ export class Blake2BKey { }␊ diff --git a/examples/napi/__test__/typegen.spec.ts.snap b/examples/napi/__test__/typegen.spec.ts.snap index b96a5c9202dd00c2daebc908aa7e1105a1363e8f..00747f191b817573755d69c5d831665c075e2707 100644 GIT binary patch literal 2924 zcmV-y3zPIgRzVv$~4HYPfKY}0?5*xB?=j_C?VavT7 ze8y!(uB44AF2h~gR(%F~|Dex(Deit@e?n(=x#UtLE%|zZ19O)%voo{vP5(3+hQhy; zKmN=VS0TIki=2ow49J*8ETM`KUnB|h6;Z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K4FCX}-r>68C-}pFjD2n#ijqyY?Wug+%v%fp0oqe{+ABQszC{#@@Xw zKh{{e<24GmhFSam<_zw00F_6JU^shR6;{P5~!(@@uh5dd0Se_bHyxKTq1 zfbJ*s5&1L{x-`trM=M0tV-0p1YwT Y!2q{jrym#2%kNhH2PlB>4uvNG01?!puK)l5 diff --git a/examples/napi/index.d.ts b/examples/napi/index.d.ts index 50da5905..909980ed 100644 --- a/examples/napi/index.d.ts +++ b/examples/napi/index.d.ts @@ -207,7 +207,7 @@ export class Bird { export type Blake2bHasher = Blake2BHasher /** Smoking test for type generation */ export class Blake2BHasher { - static withKey(key: Blake2bKey): Blake2BHasher + update(data: Buffer): void } export type Blake2bKey = Blake2BKey export class Blake2BKey { }