Skip to content

Commit

Permalink
feat(ast): allow conversion from TSAccessibility into &'static str
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Aug 5, 2024
1 parent 40df0db commit 7aae05f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions crates/oxc_ast/src/ast_impl/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,29 @@ impl<'a> TSType<'a> {
}

impl TSAccessibility {
pub fn is_private(&self) -> bool {
matches!(self, TSAccessibility::Private)
#[inline]
pub fn is_private(self) -> bool {
matches!(self, Self::Private)
}

pub fn as_str(self) -> &'static str {
match self {
Self::Public => "public",
Self::Private => "private",
Self::Protected => "protected",
}
}
}

impl From<TSAccessibility> for &'static str {
fn from(accessibility: TSAccessibility) -> Self {
accessibility.as_str()
}
}

impl fmt::Display for TSAccessibility {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}

Expand Down

0 comments on commit 7aae05f

Please sign in to comment.