Skip to content

Commit

Permalink
Ensure type names ignore serde rename when exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
siefkenj committed Jan 11, 2024
1 parent 66cddfe commit 3e81856
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions tsify-macros/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ impl<'a> Container<'a> {
&self.serde_container.ident
}

pub fn ident_str(&self) -> String {
self.ident().to_string()
}

#[inline]
pub fn serde_attrs(&self) -> &attr::Container {
&self.serde_container.attrs
Expand Down
4 changes: 3 additions & 1 deletion tsify-macros/src/decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ops::Deref;

use crate::typescript::{TsType, TsTypeElement, TsTypeLit};

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct TsTypeAliasDecl {
pub id: String,
pub export: bool,
Expand All @@ -27,6 +27,7 @@ impl Display for TsTypeAliasDecl {
}
}

#[derive(Debug)]
pub struct TsInterfaceDecl {
pub id: String,
pub type_params: Vec<String>,
Expand Down Expand Up @@ -69,6 +70,7 @@ impl Display for TsInterfaceDecl {
}
}

#[derive(Debug)]
pub struct TsEnumDecl {
pub id: String,
pub type_params: Vec<String>,
Expand Down
6 changes: 3 additions & 3 deletions tsify-macros/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'a> Parser<'a> {

fn create_type_alias_decl(&self, type_ann: TsType) -> Decl {
Decl::TsTypeAlias(TsTypeAliasDecl {
id: self.container.name(),
id: self.container.ident_str(),
export: true,
type_params: self.create_relevant_type_params(type_ann.type_ref_names()),
type_ann,
Expand All @@ -91,7 +91,7 @@ impl<'a> Parser<'a> {
let type_params = self.create_relevant_type_params(type_ref_names);

Decl::TsInterface(TsInterfaceDecl {
id: self.container.name(),
id: self.container.ident_str(),
type_params,
extends,
body: members,
Expand Down Expand Up @@ -264,7 +264,7 @@ impl<'a> Parser<'a> {
let relevant_type_params = self.create_relevant_type_params(type_ref_names);

Decl::TsEnum(TsEnumDecl {
id: self.container.name(),
id: self.container.ident_str(),
type_params: relevant_type_params,
members,
namespace: self.container.attrs.namespace,
Expand Down

0 comments on commit 3e81856

Please sign in to comment.