Merge pull request #847 from napi-rs/mut-arg

fix(napi-derive-backend): typegen issue when arg is mut
This commit is contained in:
LongYinan 2021-11-11 18:17:25 +08:00 committed by GitHub
commit 4ff51a3c66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 2 deletions

View file

@ -1,5 +1,6 @@
use convert_case::{Case, Casing}; use convert_case::{Case, Casing};
use quote::ToTokens; use quote::ToTokens;
use syn::Pat;
use super::{ty_to_ts_type, ToTypeDef, TypeDef}; use super::{ty_to_ts_type, ToTypeDef, TypeDef};
use crate::{CallbackArg, FnKind, NapiFn}; use crate::{CallbackArg, FnKind, NapiFn};
@ -49,6 +50,11 @@ impl NapiFn {
if path.ty.to_token_stream().to_string() == "Env" { if path.ty.to_token_stream().to_string() == "Env" {
return None; 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); let mut arg = path.pat.to_token_stream().to_string().to_case(Case::Camel);
arg.push_str(": "); arg.push_str(": ");
arg.push_str(&ty_to_ts_type(&path.ty, false)); arg.push_str(&ty_to_ts_type(&path.ty, false));

View file

@ -43,7 +43,7 @@ Generated by [AVA](https://avajs.dev).
export function readPackageJson(): PackageJson␊ export function readPackageJson(): PackageJson␊
export function getPackageJsonName(packageJson: PackageJson): string␊ export function getPackageJsonName(packageJson: PackageJson): string␊
export function contains(source: string, target: string): boolean␊ 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 concatUtf16(s: string): string␊
export function concatLatin1(s: string): string␊ export function concatLatin1(s: string): string␊
export function withoutAbortController(a: number, b: number): Promise<number> export function withoutAbortController(a: number, b: number): Promise<number>

View file

@ -33,7 +33,7 @@ interface PackageJson {
export function readPackageJson(): PackageJson export function readPackageJson(): PackageJson
export function getPackageJsonName(packageJson: PackageJson): string export function getPackageJsonName(packageJson: PackageJson): string
export function contains(source: string, target: string): boolean 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 concatUtf16(s: string): string
export function concatLatin1(s: string): string export function concatLatin1(s: string): string
export function withoutAbortController(a: number, b: number): Promise<number> export function withoutAbortController(a: number, b: number): Promise<number>