Skip to content

Commit

Permalink
style: clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Aug 6, 2024
1 parent c13f147 commit 6d7adb6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 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
17 changes: 9 additions & 8 deletions crates/oxc_isolated_declarations/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,13 @@ impl<'a> IsolatedDeclarations<'a> {
let mut elements = self.ast.vec();
for (index, param) in function.params.items.iter().enumerate() {
if param.accessibility.is_some() || param.readonly {
let type_annotation = if param.accessibility.is_some_and(|a| a.is_private()) {
None
} else {
// transformed params will definitely have type annotation
self.ast.copy(&params.items[index].pattern.type_annotation)
};
let type_annotation =
if param.accessibility.is_some_and(oxc_ast::ast::TSAccessibility::is_private) {
None
} else {
// transformed params will definitely have type annotation
self.ast.copy(&params.items[index].pattern.type_annotation)
};
if let Some(new_element) =
self.transform_formal_parameter_to_class_property(param, type_annotation)
{
Expand All @@ -270,7 +271,7 @@ impl<'a> IsolatedDeclarations<'a> {
for element in &decl.body.body {
if let ClassElement::MethodDefinition(method) = element {
if method.key.is_private_identifier()
|| method.accessibility.is_some_and(|a| a.is_private())
|| method.accessibility.is_some_and(oxc_ast::ast::TSAccessibility::is_private)
|| (method.computed && !self.is_literal_key(&method.key))
{
continue;
Expand Down Expand Up @@ -359,7 +360,7 @@ impl<'a> IsolatedDeclarations<'a> {
if self.report_property_key(&method.key, method.computed) {
continue;
}
if method.accessibility.is_some_and(|a| a.is_private()) {
if method.accessibility.is_some_and(oxc_ast::ast::TSAccessibility::is_private) {
elements.push(self.transform_private_modifier_method(method));
continue;
}
Expand Down

0 comments on commit 6d7adb6

Please sign in to comment.