Skip to content
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
14 changes: 14 additions & 0 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,20 @@ impl<'a> ComputedMemberExpression<'a> {
_ => None,
}
}

/// Returns the static property name of this member expression, if it has one, along with the source code [`Span`],
/// or `None` otherwise.
/// If you don't need the [`Span`], use [`ComputedMemberExpression::static_property_name`] instead.
pub fn static_property_info(&self) -> Option<(Span, &'a str)> {
match &self.expression {
Expression::StringLiteral(lit) => Some((lit.span, lit.value.as_str())),
Expression::TemplateLiteral(lit) if lit.quasis.len() == 1 => {
lit.quasis[0].value.cooked.map(|cooked| (lit.span, cooked.as_str()))
}
Expression::RegExpLiteral(lit) => lit.raw.map(|raw| (lit.span, raw.as_str())),
_ => None,
}
}
}

impl<'a> StaticMemberExpression<'a> {
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast/src/ast_kind_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ impl AstKind<'_> {
format!("CallExpression({})", c.callee_name().unwrap_or(&COMPUTED)).into()
}
Self::ChainExpression(_) => "ChainExpression".into(),
Self::ComputedMemberExpression(_) => "ComputedMemberExpression".into(),
Self::ConditionalExpression(_) => "ConditionalExpression".into(),
Self::LogicalExpression(_) => "LogicalExpression".into(),
Self::MemberExpression(_) => "MemberExpression".into(),
Expand Down
Loading
Loading