diff --git a/crates/backend/src/typegen/fn.rs b/crates/backend/src/typegen/fn.rs index 4c93b3e8..48a779e5 100644 --- a/crates/backend/src/typegen/fn.rs +++ b/crates/backend/src/typegen/fn.rs @@ -1,5 +1,6 @@ use convert_case::{Case, Casing}; use quote::ToTokens; +use syn::Pat; use super::{ty_to_ts_type, ToTypeDef, TypeDef}; use crate::{CallbackArg, FnKind, NapiFn}; @@ -49,6 +50,11 @@ impl NapiFn { if path.ty.to_token_stream().to_string() == "Env" { return None; } + let mut path = path.clone(); + // remove mutability from PatIdent + if let Pat::Ident(i) = path.pat.as_mut() { + i.mutability = None; + } let mut arg = path.pat.to_token_stream().to_string().to_case(Case::Camel); arg.push_str(": "); arg.push_str(&ty_to_ts_type(&path.ty, false)); diff --git a/examples/napi/__test__/typegen.spec.ts.md b/examples/napi/__test__/typegen.spec.ts.md index 66ac07d0..a5582548 100644 --- a/examples/napi/__test__/typegen.spec.ts.md +++ b/examples/napi/__test__/typegen.spec.ts.md @@ -43,7 +43,7 @@ Generated by [AVA](https://avajs.dev). export function readPackageJson(): PackageJson␊ export function getPackageJsonName(packageJson: PackageJson): string␊ export function contains(source: string, target: string): boolean␊ - export function concatStr(mutS: string): string␊ + export function concatStr(s: string): string␊ export function concatUtf16(s: string): string␊ export function concatLatin1(s: string): string␊ export function withoutAbortController(a: number, b: number): Promise␊ diff --git a/examples/napi/__test__/typegen.spec.ts.snap b/examples/napi/__test__/typegen.spec.ts.snap index 17956eb9..3b1d6568 100644 Binary files a/examples/napi/__test__/typegen.spec.ts.snap and b/examples/napi/__test__/typegen.spec.ts.snap differ diff --git a/examples/napi/index.d.ts b/examples/napi/index.d.ts index 66f9791c..a1e3c170 100644 --- a/examples/napi/index.d.ts +++ b/examples/napi/index.d.ts @@ -33,7 +33,7 @@ interface PackageJson { export function readPackageJson(): PackageJson export function getPackageJsonName(packageJson: PackageJson): string export function contains(source: string, target: string): boolean -export function concatStr(mutS: string): string +export function concatStr(s: string): string export function concatUtf16(s: string): string export function concatLatin1(s: string): string export function withoutAbortController(a: number, b: number): Promise