fix(macros): collision when command is named cmd (#1802)

This commit is contained in:
Lucas Fernandes Nogueira 2021-05-12 11:17:33 -03:00 committed by GitHub
parent 1ab8dd93e6
commit d36b726926
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
"tauri-macros": patch
---
Fixes a name collision when the command function is named `cmd`.

View File

@ -52,11 +52,11 @@ impl From<Handler> for proc_macro::TokenStream {
}: Handler,
) -> Self {
quote::quote!(move |invoke| {
let cmd = invoke.message.command();
match cmd {
let __tauri_cmd__ = invoke.message.command();
match __tauri_cmd__ {
#(stringify!(#commands) => #wrappers!(#paths, invoke),)*
_ => {
invoke.resolver.reject(format!("command {} not found", cmd))
invoke.resolver.reject(format!("command {} not found", __tauri_cmd__))
},
}
})

View File

@ -4,6 +4,9 @@
use tauri::{command, State};
#[command]
pub fn cmd(_argument: String) {}
#[command]
pub fn simple_command(argument: String) {
println!("{}", argument);

View File

@ -9,6 +9,7 @@
// we move some basic commands to a separate module just to show it works
mod commands;
use commands::cmd;
use serde::Deserialize;
use tauri::{command, Params, State, Window};
@ -167,6 +168,7 @@ fn main() {
force_async_with_result,
commands::simple_command,
commands::stateful_command,
cmd,
async_simple_command,
future_simple_command,
async_stateful_command,