Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions crates/oxc_isolated_declarations/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down