Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] command arguments using raw identifiers (r#ident) have r# prefixes in javascript #4654

Closed
ExpHP opened this issue Jul 12, 2022 · 0 comments
Labels
scope: core Core packages of Tauri status: backlog Issue is ready and we can work on it type: bug

Comments

@ExpHP
Copy link

ExpHP commented Jul 12, 2022

Describe the bug

Using rust's raw identifier syntax in a command's argument list does not generate the appropriately named argument in javascript, but rather includes the r#.

Reproduction

src-tauri/main.rs

fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![greet_truck, greet_struct])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

#[tauri::command]
fn greet_truck(truck: &str) -> String {
    format!("Hello, {}!", truck)
}

#[tauri::command]
fn greet_struct(r#struct: &str) -> String {
    format!("Hello, {}!", r#struct)
}
invoke('greet_truck', { truck: 'World' })
    .then((response) => console.log(response));

invoke('greet_struct', { struct: 'World' })
    .then((response) => console.log(response));

In the javascript console:

Hello, World!
[Error] Unhandled Promise Rejection: invalid args `r#struct` for command `greet_struct`: command greet_struct missing required key r#struct
	promiseEmptyOnRejected
	promiseReactionJob

Expected behavior

In the javascript console:

Hello, World!
Hello, World!

Platform and versions

Environment
  › OS: Ubuntu 20.04 X64
  › Node.js: 16.14.2
  › npm: 8.5.0
  › pnpm: Not installed!
  › yarn: Not installed!
  › rustup: 1.24.3
  › rustc: 1.62.0
  › cargo: 1.62.0
  › Rust toolchain: stable-x86_64-unknown-linux-gnu

Packages
  › @tauri-apps/cli [NPM]: 1.0.3
  › @tauri-apps/api [NPM]: 1.0.2
  › tauri [RUST]: 1.0.3,
  › tauri-build [RUST]: 1.0.3,
  › tao [RUST]: 0.12.1,
  › wry [RUST]: 0.19.0,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../ui
  › devPath: ../ui

App directory structure
  ├─ node_modules
  ├─ ui
  ├─ .git
  ├─ dist
  └─ src-tauri

Stack trace

No response

Additional context

Pat::Ident(arg) => arg.ident.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(),

This code should probably be using IdentExt::unraw:

https://docs.rs/syn/latest/syn/ext/trait.IdentExt.html#tymethod.unraw

@ExpHP ExpHP added status: needs triage This issue needs to triage, applied to new issues type: bug labels Jul 12, 2022
@amrbashir amrbashir added scope: core Core packages of Tauri status: backlog Issue is ready and we can work on it and removed status: needs triage This issue needs to triage, applied to new issues labels Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: core Core packages of Tauri status: backlog Issue is ready and we can work on it type: bug
Projects
None yet
Development

No branches or pull requests

2 participants