Skip to content

Commit

Permalink
Fix inconsistent naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattchine committed May 30, 2022
1 parent 19665a1 commit 654c98b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions macros/src/types/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn format_variant(
let variant_dependencies = variant_type.dependencies;
let inline_type = variant_type.inline;

let doc = match doc_string {
let doc_string = match doc_string {
Some(s) => format!("\n/**\n* {}\n*/\n", s),
None => "".to_string(),
};
Expand All @@ -108,21 +108,21 @@ fn format_variant(
Tagged::Untagged => quote!(#inline_type),
Tagged::Externally => match &variant.fields {
Fields::Unit => quote!(format!("\"{}\"", #name)),
_ => quote!(format!("{}{{ {}: {} }}", #doc, #name, #inline_type)),
_ => quote!(format!("{}{{ {}: {} }}", #doc_string, #name, #inline_type)),
},
Tagged::Adjacently { tag, content } => match &variant.fields {
Fields::Unnamed(unnamed) if unnamed.unnamed.len() == 1 => {
let ty = format_type(&unnamed.unnamed[0].ty, dependencies, generics);
quote!(format!("{}{{ {}: \"{}\", {}: {} }}", #doc, #tag, #name, #content, #ty))
quote!(format!("{}{{ {}: \"{}\", {}: {} }}", #doc_string, #tag, #name, #content, #ty))
}
Fields::Unit => quote!(format!("{}{{ {}: \"{}\" }}", #doc, #tag, #name)),
_ => quote!(format!("{}{{ {}: \"{}\", {}: {} }}", #doc, #tag, #name, #content, #inline_type)),
Fields::Unit => quote!(format!("{}{{ {}: \"{}\" }}", #doc_string, #tag, #name)),
_ => quote!(format!("{}{{ {}: \"{}\", {}: {} }}", #doc_string, #tag, #name, #content, #inline_type)),
},
Tagged::Internally { tag } => match variant_type.inline_flattened {
Some(inline_flattened) => quote! {
format!(
"{}{{ {}: \"{}\", {} }}",
#doc,
#doc_string,
#tag,
#name,
#inline_flattened
Expand All @@ -131,11 +131,11 @@ fn format_variant(
None => match &variant.fields {
Fields::Unnamed(unnamed) if unnamed.unnamed.len() == 1 => {
let ty = format_type(&unnamed.unnamed[0].ty, dependencies, generics);
quote!(format!("{}{{ {}: \"{}\" }} & {}", #doc, #tag, #name, #ty))
quote!(format!("{}{{ {}: \"{}\" }} & {}", #doc_string, #tag, #name, #ty))
}
Fields::Unit => quote!(format!("{}{{ {}: \"{}\" }}", #doc, #tag, #name)),
Fields::Unit => quote!(format!("{}{{ {}: \"{}\" }}", #doc_string, #tag, #name)),
_ => {
quote!(format!("{}{{ {}: \"{}\" }} & {}", #doc, #tag, #name, #inline_type))
quote!(format!("{}{{ {}: \"{}\" }} & {}", #doc_string, #tag, #name, #inline_type))
}
},
},
Expand Down
4 changes: 2 additions & 2 deletions macros/src/types/newtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ pub(crate) fn newtype(
None => format_type(inner_ty, &mut dependencies, generics),
};

let doc = match doc_string {
let doc_string = match doc_string {
Some(s) => format!("\n/**\n* {}\n*/\n", s),
None => "".to_string(),
};

let generic_args = format_generics(&mut dependencies, generics);
Ok(DerivedTS {
decl: quote!(format!("{}type {}{} = {};", #doc, #name, #generic_args, #inline_def)),
decl: quote!(format!("{}type {}{} = {};", #doc_string, #name, #generic_args, #inline_def)),
inline: inline_def,
inline_flattened: None,
name: name.to_owned(),
Expand Down
2 changes: 1 addition & 1 deletion ts-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ mod export;
/// Flatten this field (only works if the field is a struct)
///
/// - `#[ts(doc_string = "..")]`:
/// Adding typescript docstring to this field
/// Add typescript docstring to this field
///
/// ### enum attributes
///
Expand Down

0 comments on commit 654c98b

Please sign in to comment.