fix(napi-derive): unraw rust identifiers before sending it to js. (#987)

This commit is contained in:
Flux Xu 2022-01-02 22:28:35 -05:00 committed by GitHub
parent ca3790bdf1
commit 881fd52063
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,6 +15,7 @@ use napi_derive_backend::{
}; };
use proc_macro2::{Ident, TokenStream, TokenTree}; use proc_macro2::{Ident, TokenStream, TokenTree};
use quote::ToTokens; use quote::ToTokens;
use syn::ext::IdentExt;
use syn::parse::{Parse, ParseStream, Result as SynResult}; use syn::parse::{Parse, ParseStream, Result as SynResult};
use syn::{Attribute, Signature, Type, Visibility}; use syn::{Attribute, Signature, Type, Visibility};
@ -745,7 +746,7 @@ impl ConvertToAST for syn::ItemStruct {
let (js_name, name) = match &field.ident { let (js_name, name) = match &field.ident {
Some(ident) => ( Some(ident) => (
field_opts.js_name().map_or_else( field_opts.js_name().map_or_else(
|| ident.to_string().to_case(Case::Camel), || ident.unraw().to_string().to_case(Case::Camel),
|(js_name, _)| js_name.to_owned(), |(js_name, _)| js_name.to_owned(),
), ),
syn::Member::Named(ident.clone()), syn::Member::Named(ident.clone()),