Skip to content

Commit

Permalink
refactor(ast): use correct lifetimes for name-related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Aug 5, 2024
1 parent 7aae05f commit 7d07291
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
10 changes: 5 additions & 5 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl<'a> MemberExpression<'a> {
}
}

pub fn static_property_name(&self) -> Option<&str> {
pub fn static_property_name(&self) -> Option<&'a str> {
match self {
MemberExpression::ComputedMemberExpression(expr) => {
expr.static_property_name().map(|name| name.as_str())
Expand All @@ -462,21 +462,21 @@ impl<'a> MemberExpression<'a> {
}
}

pub fn static_property_info(&self) -> Option<(Span, &str)> {
pub fn static_property_info(&self) -> Option<(Span, &'a str)> {
match self {
MemberExpression::ComputedMemberExpression(expr) => match &expr.expression {
Expression::StringLiteral(lit) => Some((lit.span, &lit.value)),
Expression::StringLiteral(lit) => Some((lit.span, lit.value.as_str())),
Expression::TemplateLiteral(lit) => {
if lit.expressions.is_empty() && lit.quasis.len() == 1 {
Some((lit.span, &lit.quasis[0].value.raw))
Some((lit.span, lit.quasis[0].value.raw.as_str()))
} else {
None
}
}
_ => None,
},
MemberExpression::StaticMemberExpression(expr) => {
Some((expr.property.span, &expr.property.name))
Some((expr.property.span, expr.property.name.as_str()))
}
MemberExpression::PrivateFieldExpression(_) => None,
}
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_ast/src/ast_impl/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,20 @@ impl<'a> TSModuleReference<'a> {
impl<'a> Decorator<'a> {
/// Get the name of the decorator
/// ```ts
/// // The name of the decorator is `decorator`
/// @decorator
/// @decorator.a.b
/// @decorator(xx)
/// @decorator.a.b(xx)
/// The name of the decorator is `decorator`
/// ```
pub fn name(&self) -> Option<&str> {
pub fn name(&self) -> Option<&'a str> {
match &self.expression {
Expression::Identifier(ident) => Some(&ident.name),
Expression::Identifier(ident) => Some(ident.name.as_str()),
expr @ match_member_expression!(Expression) => {
expr.to_member_expression().static_property_name()
}
Expression::CallExpression(call) => {
call.callee.get_member_expr().map(|member| member.static_property_name())?
call.callee.get_member_expr().and_then(MemberExpression::static_property_name)
}
_ => None,
}
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(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(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(TSAccessibility::is_private) {
elements.push(self.transform_private_modifier_method(method));
continue;
}
Expand Down

0 comments on commit 7d07291

Please sign in to comment.