Skip to content

Commit c424ef3

Browse files
author
Cameron McHenry
committed
refactor(ast): add AstKind for ComputedMemberExpression
1 parent 371473c commit c424ef3

File tree

25 files changed

+503
-408
lines changed

25 files changed

+503
-408
lines changed

crates/oxc_ast/src/ast_impl/js.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,22 @@ impl<'a> ComputedMemberExpression<'a> {
668668
_ => None,
669669
}
670670
}
671+
672+
/// Returns the static property name of this member expression, if it has one, along with the source code [`Span`],
673+
/// or `None` otherwise.
674+
/// If you don't need the [`Span`], use [`ComputedMemberExpression::static_property_name`] instead.
675+
pub fn static_property_info(&self) -> Option<(Span, &'a str)> {
676+
match &self.expression {
677+
Expression::StringLiteral(lit) => Some((lit.span, lit.value.as_str())),
678+
Expression::TemplateLiteral(lit)
679+
if lit.expressions.is_empty() && lit.quasis.len() == 1 =>
680+
{
681+
Some((lit.span, lit.quasis[0].value.raw.as_str()))
682+
}
683+
Expression::RegExpLiteral(lit) => lit.raw.map(|raw| (lit.span, raw.as_str())),
684+
_ => None,
685+
}
686+
}
671687
}
672688

673689
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)