Skip to content

Commit 190e390

Browse files
committed
refactor(ast): add AstKind for ComputedMemberExpression (#11766)
- part of #11490
1 parent 19cee8c commit 190e390

File tree

25 files changed

+508
-408
lines changed

25 files changed

+508
-408
lines changed

crates/oxc_ast/src/ast_impl/js.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,20 @@ impl<'a> ComputedMemberExpression<'a> {
664664
_ => None,
665665
}
666666
}
667+
668+
/// Returns the static property name of this member expression, if it has one, along with the source code [`Span`],
669+
/// or `None` otherwise.
670+
/// If you don't need the [`Span`], use [`ComputedMemberExpression::static_property_name`] instead.
671+
pub fn static_property_info(&self) -> Option<(Span, &'a str)> {
672+
match &self.expression {
673+
Expression::StringLiteral(lit) => Some((lit.span, lit.value.as_str())),
674+
Expression::TemplateLiteral(lit) if lit.quasis.len() == 1 => {
675+
lit.quasis[0].value.cooked.map(|cooked| (lit.span, cooked.as_str()))
676+
}
677+
Expression::RegExpLiteral(lit) => lit.raw.map(|raw| (lit.span, raw.as_str())),
678+
_ => None,
679+
}
680+
}
667681
}
668682

669683
impl<'a> StaticMemberExpression<'a> {

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ impl AstKind<'_> {
217217
format!("CallExpression({})", c.callee_name().unwrap_or(&COMPUTED)).into()
218218
}
219219
Self::ChainExpression(_) => "ChainExpression".into(),
220+
Self::ComputedMemberExpression(_) => "ComputedMemberExpression".into(),
220221
Self::ConditionalExpression(_) => "ConditionalExpression".into(),
221222
Self::LogicalExpression(_) => "LogicalExpression".into(),
222223
Self::MemberExpression(_) => "MemberExpression".into(),

0 commit comments

Comments
 (0)