Skip to content

Commit

Permalink
chore: clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Oct 7, 2023
1 parent 77c24da commit 2e0324a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
7 changes: 7 additions & 0 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ impl<'a> PropertyKey<'a> {
matches!(self, Self::PrivateIdentifier(_))
}

pub fn private_name(&self) -> Option<Atom> {
match self {
Self::PrivateIdentifier(ident) => Some(ident.name.clone()),
_ => None,
}
}

pub fn is_specific_id(&self, name: &str) -> bool {
match self {
PropertyKey::Identifier(ident) => ident.name == name,
Expand Down
13 changes: 3 additions & 10 deletions crates/oxc_transformer/src/es2022/class_static_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ impl<'a> ClassStaticBlock<'a> {
.body
.iter()
.filter_map(ClassElement::property_key)
.filter_map(|p| match p {
PropertyKey::PrivateIdentifier(p) => Some(p.name.clone()),
_ => None,
})
.filter_map(PropertyKey::private_name)
.collect();

let mut i = 0;
Expand All @@ -49,12 +46,8 @@ impl<'a> ClassStaticBlock<'a> {
.then(|| {
// We special-case the single expression case to avoid the iife, since it's common.
let stmt = self.ast.move_statement(&mut block.body.deref_mut()[0]);
match stmt {
Statement::ExpressionStatement(mut expr_stmt) => {
self.ast.move_expression(&mut expr_stmt.expression)
}
_ => unreachable!(),
}
let Statement::ExpressionStatement(mut expr_stmt) = stmt else { unreachable!() };
self.ast.move_expression(&mut expr_stmt.expression)
})
.unwrap_or_else(|| {
let statements = self.ast.move_statement_vec(&mut block.body);
Expand Down

0 comments on commit 2e0324a

Please sign in to comment.