Skip to content

Commit

Permalink
unraw function args
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Jun 24, 2024
1 parent 9823cb6 commit 92c640d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/js.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::*;
use heck::ToLowerCamelCase;
use indoc::formatdoc;
use js_ts::unraw;
use specta::{function::FunctionDataType, js_doc, ts};
use tauri::Runtime;

Expand Down Expand Up @@ -49,7 +50,7 @@ impl ExportLanguage for Language {

builder.extend(function.args.iter().flat_map(|(name, typ)| {
ts::datatype(&cfg.inner, typ, type_map).map(|typ| {
let name = name.to_lower_camel_case();
let name = unraw(name).to_lower_camel_case();

format!("@param {{ {typ} }} {name}")
})
Expand Down
10 changes: 9 additions & 1 deletion src/js_ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,17 @@ pub fn render_all_parts<T: ExportLanguage<Config = specta::ts::ExportConfig>>(
})
}

pub fn unraw(s: &str) -> &str {
if s.starts_with("r#") {
s.split_at(2).1
} else {
s.as_ref()
}
}

pub fn arg_names(args: &[(Cow<'static, str>, DataType)]) -> Vec<String> {
args.iter()
.map(|(name, _)| name.to_lower_camel_case())
.map(|(name, _)| unraw(name).to_lower_camel_case())
.collect::<Vec<_>>()
}

Expand Down
7 changes: 5 additions & 2 deletions src/ts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{js_ts, *};
use crate::{
js_ts::{self, unraw},
*,
};
use heck::ToLowerCamelCase;
use indoc::formatdoc;
use specta::{
Expand Down Expand Up @@ -43,7 +46,7 @@ impl ExportLanguage for Language {
.iter()
.map(|(name, typ)| {
ts::datatype(&cfg.inner, typ, type_map)
.map(|ty| format!("{}: {}", name.to_lower_camel_case(), ty))
.map(|ty| format!("{}: {}", unraw(name).to_lower_camel_case(), ty))
})
.collect::<Result<Vec<_>, _>>()?;

Expand Down

0 comments on commit 92c640d

Please sign in to comment.