refactor(ast): use correct lifetimes for name-related methods (#4712)

This commit is contained in:
DonIsaac 2024-08-07 03:53:39 +00:00
parent e12bd1e21a
commit 475266dde3
3 changed files with 12 additions and 12 deletions

View file

@ -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())
@ -462,13 +462,13 @@ 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
}
@ -476,7 +476,7 @@ impl<'a> MemberExpression<'a> {
_ => None,
},
MemberExpression::StaticMemberExpression(expr) => {
Some((expr.property.span, &expr.property.name))
Some((expr.property.span, expr.property.name.as_str()))
}
MemberExpression::PrivateFieldExpression(_) => None,
}

View file

@ -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,
}

View file

@ -243,7 +243,7 @@ impl<'a> IsolatedDeclarations<'a> {
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(oxc_ast::ast::TSAccessibility::is_private) {
if param.accessibility.is_some_and(TSAccessibility::is_private) {
None
} else {
// transformed params will definitely have type annotation
@ -271,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(oxc_ast::ast::TSAccessibility::is_private)
|| method.accessibility.is_some_and(TSAccessibility::is_private)
|| (method.computed && !self.is_literal_key(&method.key))
{
continue;
@ -360,7 +360,7 @@ impl<'a> IsolatedDeclarations<'a> {
if self.report_property_key(&method.key, method.computed) {
continue;
}
if method.accessibility.is_some_and(oxc_ast::ast::TSAccessibility::is_private) {
if method.accessibility.is_some_and(TSAccessibility::is_private) {
elements.push(self.transform_private_modifier_method(method));
continue;
}