Skip to content

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

Closed

Description

@ExpHP

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

Activity

  1. added
    scope: coreCore packages of Tauri
    status: backlogIssue is ready and we can work on it
    and removed
    status: needs triageThis issue needs to triage, applied to new issues
    on Jul 12, 2022
  2. added a commit that references this issue on Jul 12, 2022
    d4c9e73
  3. added a commit that references this issue on Dec 9, 2024
    ac72800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions