From ac1a40fb43767e0c4bf5dc26570fb2dd4ddd545d Mon Sep 17 00:00:00 2001 From: Ali Rezvani <3788964+rzvxa@users.noreply.github.com> Date: Tue, 23 Apr 2024 05:17:23 +0330 Subject: [PATCH] feat(ast): add `callee_name` method to the `CallExpression`. (#3076) Adds a simple way to get the name of a given `CallExpression`. --- crates/oxc_ast/src/ast/js.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index bc9ce0972..4c9b80da2 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -787,6 +787,14 @@ pub struct CallExpression<'a> { } impl<'a> CallExpression<'a> { + pub fn callee_name(&self) -> Option<&str> { + match &self.callee { + Expression::Identifier(ident) => Some(ident.name.as_str()), + Expression::MemberExpression(member) => member.static_property_name(), + _ => None, + } + } + pub fn is_require_call(&self) -> bool { if self.arguments.len() != 1 { return false;