Skip to content

Commit

Permalink
Add back unraw's.
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Jul 31, 2024
1 parent ed72657 commit b5deb39
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 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::{datatype, FunctionResultVariant};
use specta_typescript as ts;
use specta_typescript::js_doc;
Expand Down Expand Up @@ -56,7 +57,7 @@ impl ExportLanguage for Language {
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 @@ -77,9 +77,17 @@ pub fn render_all_parts<T: ExportLanguage<Config = specta_typescript::ExportConf
})
}

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
3 changes: 2 additions & 1 deletion src/ts.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::js_ts::unraw;
use crate::{js_ts, *};
use heck::ToLowerCamelCase;
use indoc::formatdoc;
Expand Down Expand Up @@ -43,7 +44,7 @@ impl ExportLanguage for Language {
&FunctionResultVariant::Value(typ.clone()),
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 b5deb39

Please sign in to comment.