fix(macros): strip r# from command arguments, closes #4654 (#4657)

This commit is contained in:
Lucas Fernandes Nogueira
2022-07-12 14:07:51 -03:00
committed by GitHub
parent c635a0dad4
commit ac72800fb6
2 changed files with 7 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"tauri-macros": patch
---
Remove raw identifier (`r#`) prefix from command arguments.

View File

@@ -6,6 +6,7 @@ use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
use syn::{
ext::IdentExt,
parse::{Parse, ParseBuffer},
parse_macro_input,
spanned::Spanned,
@@ -164,7 +165,7 @@ fn parse_arg(command: &Ident, arg: &FnArg, message: &Ident) -> syn::Result<Token
// we only support patterns that allow us to extract some sort of keyed identifier
let mut key = match &mut arg {
Pat::Ident(arg) => arg.ident.to_string(),
Pat::Ident(arg) => arg.ident.unraw().to_string(),
Pat::Wild(_) => "".into(), // we always convert to camelCase, so "_" will end up empty anyways
Pat::Struct(s) => super::path_to_command(&mut s.path).ident.to_string(),
Pat::TupleStruct(s) => super::path_to_command(&mut s.path).ident.to_string(),