use super::visit_helpers::*;
use super::*;
use crate::js_text::JsText;
use crate::{SemanticFact, TypeAliasSurfaceTargetFact};
use super::type_flow::TypeFlow;
#[derive(Debug, Clone)]
pub(in crate::visitor) struct ThisResultLocal {
frame: usize,
inherited_source: Option<String>,
rebound_frame: Option<usize>,
forked_frames: Vec<usize>,
}
pub(super) struct MethodVisitState {
span: Option<Span>,
independent_this_depth: usize,
this_result_locals: FxHashMap<String, Vec<ThisResultLocal>>,
}
impl ModuleInfoExtractor {
fn collect_type_alias_surface_targets(
ty: &TSType<'_>,
type_parameters: &FxHashSet<&str>,
targets: &mut Vec<String>,
) {
match ty {
TSType::TSTypeReference(reference) => {
if let Some(factory) = Self::store_factory_from_return_type(ty) {
targets.push(factory);
return;
}
let Some((name, _)) = type_name_root(&reference.type_name) else {
return;
};
if matches!(
name.as_str(),
"Pick" | "Omit" | "Partial" | "Required" | "Readonly" | "NonNullable"
) {
if let Some(first) = reference
.type_arguments
.as_deref()
.and_then(|arguments| arguments.params.first())
{
Self::collect_type_alias_surface_targets(first, type_parameters, targets);
}
} else if !type_parameters.contains(name.as_str()) {
targets.push(name);
}
}
TSType::TSUnionType(union) => {
for branch in &union.types {
Self::collect_type_alias_surface_targets(branch, type_parameters, targets);
}
}
TSType::TSIntersectionType(intersection) => {
for branch in &intersection.types {
Self::collect_type_alias_surface_targets(branch, type_parameters, targets);
}
}
TSType::TSParenthesizedType(parenthesized) => {
Self::collect_type_alias_surface_targets(
&parenthesized.type_annotation,
type_parameters,
targets,
);
}
_ => {}
}
}
fn collect_literal_type_strings(ty: &TSType<'_>, values: &mut Vec<String>) {
match ty {
TSType::TSLiteralType(literal) => {
if let TSLiteral::StringLiteral(value) = &literal.literal {
values.push(value.value.text().into_owned());
}
}
TSType::TSUnionType(union) => {
for branch in &union.types {
Self::collect_literal_type_strings(branch, values);
}
}
TSType::TSParenthesizedType(parenthesized) => {
Self::collect_literal_type_strings(&parenthesized.type_annotation, values);
}
_ => {}
}
}
fn collect_pick_member_accesses(
ty: &TSType<'_>,
type_parameters: &FxHashSet<&str>,
accesses: &mut Vec<MemberAccess>,
) {
match ty {
TSType::TSTypeReference(reference) => {
let Some((name, _)) = type_name_root(&reference.type_name) else {
return;
};
if name != "Pick" {
if matches!(
name.as_str(),
"Partial" | "Required" | "Readonly" | "NonNullable"
) && let Some(first) = reference
.type_arguments
.as_deref()
.and_then(|arguments| arguments.params.first())
{
Self::collect_pick_member_accesses(first, type_parameters, accesses);
}
return;
}
let Some(arguments) = reference.type_arguments.as_deref() else {
return;
};
let (Some(target), Some(keys)) =
(arguments.params.first(), arguments.params.get(1))
else {
return;
};
let mut targets = Vec::new();
Self::collect_type_alias_surface_targets(target, type_parameters, &mut targets);
let mut members = Vec::new();
Self::collect_literal_type_strings(keys, &mut members);
accesses.extend(targets.into_iter().flat_map(|object| {
members.iter().cloned().map(move |member| MemberAccess {
object: object.clone(),
member,
})
}));
}
TSType::TSUnionType(union) => {
for branch in &union.types {
Self::collect_pick_member_accesses(branch, type_parameters, accesses);
}
}
TSType::TSIntersectionType(intersection) => {
for branch in &intersection.types {
Self::collect_pick_member_accesses(branch, type_parameters, accesses);
}
}
TSType::TSParenthesizedType(parenthesized) => {
Self::collect_pick_member_accesses(
&parenthesized.type_annotation,
type_parameters,
accesses,
);
}
_ => {}
}
}
pub(super) fn record_type_alias_surface_targets(&mut self, alias: &TSTypeAliasDeclaration<'_>) {
let type_parameters: FxHashSet<&str> = alias
.type_parameters
.as_deref()
.into_iter()
.flat_map(|parameters| ¶meters.params)
.map(|parameter| parameter.name.name.as_str())
.collect();
let mut targets = Vec::new();
Self::collect_type_alias_surface_targets(
&alias.type_annotation,
&type_parameters,
&mut targets,
);
targets.sort_unstable();
targets.dedup();
self.semantic_facts
.extend(targets.into_iter().map(|target_name| {
SemanticFact::TypeAliasSurfaceTarget(TypeAliasSurfaceTargetFact {
alias_name: alias.id.name.to_string(),
target_name,
})
}));
let mut picked_members = Vec::new();
Self::collect_pick_member_accesses(
&alias.type_annotation,
&type_parameters,
&mut picked_members,
);
self.member_accesses.extend(picked_members);
}
pub(super) fn record_local_type_declaration(&mut self, name: &str, span: Span) {
self.local_type_declarations.push(LocalTypeDeclaration {
name: name.to_string(),
span,
});
}
pub(crate) fn deduplicate_local_type_declarations(
declarations: &mut Vec<LocalTypeDeclaration>,
) {
let keep = {
let mut seen = FxHashSet::default();
seen.reserve(declarations.len());
declarations
.iter()
.map(|declaration| seen.insert(declaration.name.as_str()))
.collect::<Vec<_>>()
};
let mut keep = keep.into_iter();
declarations.retain(|_| keep.next().unwrap_or(false));
}
pub(super) fn record_local_signature_refs(
&mut self,
owner_name: &str,
refs: Vec<(String, Span)>,
) {
self.push_local_signature_refs(owner_name, refs, false);
}
fn record_local_satisfies_refs(&mut self, owner_name: &str, refs: Vec<(String, Span)>) {
self.push_local_signature_refs(owner_name, refs, true);
}
fn push_local_signature_refs(
&mut self,
owner_name: &str,
refs: Vec<(String, Span)>,
from_satisfies: bool,
) {
self.local_signature_type_references
.extend(refs.into_iter().map(|(type_name, span)| {
super::super::LocalSignatureTypeReference {
owner_name: owner_name.to_string(),
type_name,
span,
from_satisfies,
}
}));
}
pub(super) fn record_public_signature_refs(
&mut self,
export_name: &str,
refs: Vec<(String, Span)>,
) {
self.public_signature_type_references
.extend(
refs.into_iter()
.map(|(type_name, span)| PublicSignatureTypeReference {
export_name: export_name.to_string(),
type_name,
span,
from_satisfies: false,
}),
);
}
fn collect_type_refs_from_annotation(annotation: &TSTypeAnnotation<'_>) -> Vec<(String, Span)> {
let mut collector = SignatureTypeCollector::default();
collector.visit_ts_type_annotation(annotation);
collector.refs
}
pub(super) fn record_module_variable_signature_refs(
&mut self,
declarator: &VariableDeclarator<'_>,
) {
let satisfies_refs = Self::collect_variable_satisfies_refs(declarator);
if let (BindingPattern::BindingIdentifier(id), None, Some(init)) = (
&declarator.id,
declarator.type_annotation.as_deref(),
&declarator.init,
) {
let parts = match Self::strip_satisfies_clauses(init).without_parentheses() {
Expression::ArrowFunctionExpression(arrow) => Some(TypeFlow::of_arrow_parts(arrow)),
Expression::FunctionExpression(function) => {
Some(TypeFlow::of_function_parts(function))
}
_ => None,
};
if let Some((whole, returned)) = parts {
self.record_type_flow(&id.name, whole);
self.record_type_flow(
&format!("{}{}", id.name, super::type_flow::CALL_RESULT_SUFFIX),
returned,
);
} else {
self.record_type_flow(&id.name, TypeFlow::of_initializer(init));
}
self.record_local_satisfies_refs(&id.name, satisfies_refs);
return;
}
let refs = Self::collect_annotated_variable_signature_refs(declarator);
for id in declarator.id.get_binding_identifiers() {
self.record_local_signature_refs(&id.name, refs.clone());
self.record_local_satisfies_refs(&id.name, satisfies_refs.clone());
}
}
fn collect_annotated_variable_signature_refs(
declarator: &VariableDeclarator<'_>,
) -> Vec<(String, Span)> {
let mut refs = Vec::new();
if let Some(annotation) = declarator.type_annotation.as_deref() {
refs.extend(Self::collect_type_refs_from_annotation(annotation));
}
if let Some(init) = &declarator.init {
let init = Self::strip_satisfies_clauses(init);
let mut inner = init.without_parentheses();
while let Expression::TSNonNullExpression(non_null) = inner {
inner = non_null.expression.without_parentheses();
}
if matches!(
inner,
Expression::ArrowFunctionExpression(_)
| Expression::FunctionExpression(_)
| Expression::CallExpression(_)
| Expression::NewExpression(_)
| Expression::TSAsExpression(_)
| Expression::TSTypeAssertion(_)
) {
refs.extend(TypeFlow::of_module_expression(inner).refs);
}
}
refs
}
fn strip_satisfies_clauses<'b>(init: &'b Expression<'b>) -> &'b Expression<'b> {
match init.without_parentheses() {
Expression::TSSatisfiesExpression(satisfies) => {
Self::strip_satisfies_clauses(&satisfies.expression).without_parentheses()
}
_ => init,
}
}
fn collect_variable_satisfies_refs(declarator: &VariableDeclarator<'_>) -> Vec<(String, Span)> {
let mut collector = SignatureTypeCollector::default();
let mut current = declarator.init.as_ref();
while let Some(expression) = current {
current = match expression.without_parentheses() {
Expression::TSSatisfiesExpression(satisfies) => {
collector.visit_ts_type(&satisfies.type_annotation);
Some(&satisfies.expression)
}
Expression::TSAsExpression(assertion) => Some(&assertion.expression),
Expression::TSTypeAssertion(assertion) => Some(&assertion.expression),
Expression::TSNonNullExpression(non_null) => Some(&non_null.expression),
_ => None,
};
}
collector.refs
}
fn collect_class_heritage_signature_refs(
class: &Class<'_>,
collector: &mut SignatureTypeCollector,
) {
if let Some(type_parameters) = class.type_parameters.as_deref() {
collector.visit_ts_type_parameter_declaration(type_parameters);
}
if let Some(heritage) = class.heritage.as_ref() {
if let Some((name, span)) = expression_root_name(&heritage.expression) {
collector.refs.push((name, span));
}
if let Some(type_arguments) = heritage.type_arguments.as_deref() {
collector.visit_ts_type_parameter_instantiation(type_arguments);
}
}
for implemented in &class.implements {
if let Some((name, span)) = type_name_root(&implemented.expression) {
collector.refs.push((name, span));
}
if let Some(type_arguments) = implemented.type_arguments.as_deref() {
collector.visit_ts_type_parameter_instantiation(type_arguments);
}
}
}
pub(super) fn collect_class_type_flow(class: &Class<'_>) -> TypeFlow {
let mut collector = SignatureTypeCollector::default();
let mut flow = TypeFlow::default();
Self::collect_class_heritage_signature_refs(class, &mut collector);
for element in &class.body.body {
match element {
ClassElement::MethodDefinition(method) => {
if matches!(method.accessibility, Some(TSAccessibility::Private))
|| is_private_member_key(&method.key)
{
continue;
}
let method_flow = TypeFlow::of_function(&method.value);
collector.refs.extend(method_flow.refs);
flow.held.extend(method_flow.held);
}
ClassElement::PropertyDefinition(prop) => {
if matches!(prop.accessibility, Some(TSAccessibility::Private))
|| is_private_member_key(&prop.key)
{
continue;
}
if let Some(annotation) = prop.type_annotation.as_deref() {
collector.visit_ts_type_annotation(annotation);
} else if let Some(value) = &prop.value {
let value_flow = TypeFlow::of_module_expression(value);
collector.refs.extend(value_flow.refs);
flow.held.extend(value_flow.held);
}
}
ClassElement::AccessorProperty(prop) => {
if matches!(prop.accessibility, Some(TSAccessibility::Private))
|| is_private_member_key(&prop.key)
{
continue;
}
if let Some(annotation) = prop.type_annotation.as_deref() {
collector.visit_ts_type_annotation(annotation);
}
}
ClassElement::TSIndexSignature(index) => {
collector.visit_ts_index_signature(index);
}
ClassElement::StaticBlock(_) => {}
}
}
super::type_flow::remove_type_parameter_refs(
&mut collector.refs,
class.type_parameters.as_deref(),
);
flow.refs = collector.refs;
flow
}
pub(super) fn collect_interface_signature_refs(
iface: &TSInterfaceDeclaration<'_>,
) -> Vec<(String, Span)> {
let mut collector = SignatureTypeCollector::default();
if let Some(type_parameters) = iface.type_parameters.as_deref() {
collector.visit_ts_type_parameter_declaration(type_parameters);
}
for heritage in &iface.extends {
if let Some((name, span)) = type_name_root(&heritage.type_name) {
collector.refs.push((name, span));
}
if let Some(type_arguments) = heritage.type_arguments.as_deref() {
collector.visit_ts_type_parameter_instantiation(type_arguments);
}
}
collector.visit_ts_interface_body(&iface.body);
super::type_flow::remove_type_parameter_refs(
&mut collector.refs,
iface.type_parameters.as_deref(),
);
collector.refs
}
pub(super) fn collect_type_alias_signature_refs(
alias: &TSTypeAliasDeclaration<'_>,
) -> Vec<(String, Span)> {
let mut collector = SignatureTypeCollector::default();
if let Some(type_parameters) = alias.type_parameters.as_deref() {
collector.visit_ts_type_parameter_declaration(type_parameters);
}
collector.visit_ts_type(&alias.type_annotation);
super::type_flow::remove_type_parameter_refs(
&mut collector.refs,
alias.type_parameters.as_deref(),
);
collector.refs
}
pub(super) fn preseed_class_bindings(&mut self, class: &Class<'_>) {
for element in &class.body.body {
if let ClassElement::PropertyDefinition(prop) = element {
if prop.r#static {
continue;
}
let name = prop.key.static_name().map_or_else(
|| match &prop.key {
PropertyKey::PrivateIdentifier(id) => Some(format!("#{}", id.name)),
_ => None,
},
|name| Some(name.text().into_owned()),
);
if let Some(name) = name
&& let Some(annotation) = prop.type_annotation.as_deref()
&& let Some(element_type) =
array_element_type_from_type(&annotation.type_annotation)
{
self.iterable_element_types
.insert(self.this_member_key(&name), element_type);
}
continue;
}
let ClassElement::MethodDefinition(method) = element else {
continue;
};
self.record_this_return_binding(method);
if method.kind != MethodDefinitionKind::Constructor {
continue;
}
for param in &method.value.params.items {
if param.accessibility.is_none() && !param.readonly {
continue;
}
let BindingPattern::BindingIdentifier(id) = ¶m.pattern else {
continue;
};
let Some(annotation) = param.type_annotation.as_deref() else {
continue;
};
if let Some(element_type) =
array_element_type_from_type(&annotation.type_annotation)
{
self.iterable_element_types
.insert(self.this_member_key(id.name.as_str()), element_type);
}
}
}
}
pub(super) fn enter_method_definition(
&mut self,
method: &MethodDefinition<'_>,
) -> MethodVisitState {
MethodVisitState {
span: self.class_method_function_span.replace(method.value.span),
independent_this_depth: std::mem::replace(&mut self.independent_this_depth, 0),
this_result_locals: std::mem::take(&mut self.this_result_locals),
}
}
pub(super) fn exit_method_definition(&mut self, previous: MethodVisitState) {
self.class_method_function_span = previous.span;
self.independent_this_depth = previous.independent_this_depth;
self.this_result_locals = previous.this_result_locals;
}
fn record_this_return_binding(&mut self, method: &MethodDefinition<'_>) {
let call_suffix = match method.kind {
MethodDefinitionKind::Method => "()",
MethodDefinitionKind::Get => "",
_ => return,
};
if method.r#static || self.class_scope_stack.is_empty() {
return;
}
let Some(type_annotation) = method.value.return_type.as_deref() else {
return;
};
let name = match &method.key {
PropertyKey::PrivateIdentifier(id) => format!("#{}", id.name),
key => match key.static_name() {
Some(name) => name.text().into_owned(),
None => return,
},
};
let names_method_type_param = extract_type_annotation_name(type_annotation)
.zip(method.value.type_parameters.as_deref())
.is_some_and(|(type_name, params)| {
params
.params
.iter()
.any(|param| param.name.name.as_str() == type_name)
});
if names_method_type_param {
return;
}
let key = self.this_member_key(&format!("{name}{call_suffix}"));
self.record_typed_binding(&key, type_annotation);
}
pub(super) fn record_this_method_result_alias(
&mut self,
declarator: &VariableDeclarator<'_>,
init: &Expression<'_>,
) {
let BindingPattern::BindingIdentifier(id) = &declarator.id else {
return;
};
let frame = self.current_binding_frame();
if let Some(locals) = self.this_result_locals.get_mut(id.name.as_str()) {
locals.retain(|local| local.frame < frame);
}
self.mark_factory_local_rebound(id.name.as_str(), init);
if self.class_scope_stack.is_empty() || self.independent_this_depth > 0 {
return;
}
let Some(name) = this_method_call_name(init) else {
return;
};
let key = self.this_member_key(&format!("{name}()"));
let inherited_source = match self.binding_target_names.get(&key) {
Some(BindingTarget::Class(type_name)) => {
let type_name = type_name.clone();
self.insert_class_binding_target(id.name.to_string(), type_name);
None
}
None => Some(format!("this.{name}()")),
Some(_) => return,
};
self.this_result_locals
.entry(id.name.to_string())
.or_default()
.push(ThisResultLocal {
frame,
inherited_source,
rebound_frame: None,
forked_frames: Vec::new(),
});
}
fn current_binding_frame(&self) -> usize {
self.scoped_direct_object_binding_roots
.len()
.saturating_sub(1)
}
pub(super) fn this_result_local_is_shadowed(&self, root: &str) -> bool {
let Some(shadow) = self.this_result_local_shadow_frame(root) else {
return false;
};
self.innermost_this_result_local(root)
.is_some_and(|local| local.rebound_frame != Some(shadow))
}
fn innermost_this_result_local(&self, root: &str) -> Option<&ThisResultLocal> {
self.this_result_locals
.get(root)
.and_then(|locals| locals.last())
}
fn this_result_local_shadow_frame(&self, root: &str) -> Option<usize> {
let local = self.innermost_this_result_local(root)?;
self.scoped_direct_object_binding_roots
.iter()
.enumerate()
.rev()
.find(|(index, roots)| roots.contains(root) && !local.forked_frames.contains(index))
.map(|(index, _)| index)
.filter(|&index| index > local.frame)
}
pub(super) fn admit_direct_object_binding_fork(
&mut self,
root: &str,
frame: usize,
owner: Option<usize>,
) -> bool {
if owner.is_some_and(|index| index >= frame) {
return false;
}
if let Some(local) = self
.this_result_locals
.get_mut(root)
.and_then(|locals| locals.last_mut())
&& frame > local.frame
&& !local.forked_frames.contains(&frame)
{
local.forked_frames.push(frame);
}
true
}
fn mark_factory_local_rebound(&mut self, name: &str, init: &Expression<'_>) {
if !self.this_result_locals.contains_key(name) {
return;
}
let call = match init {
Expression::AwaitExpression(await_expr) => &await_expr.argument,
_ => init,
};
if Self::bare_call_callee_name(self.class_carrying_init(call)).is_some() {
self.mark_this_result_local_rebound(name);
}
}
pub(super) fn mark_this_result_local_rebound(&mut self, root: &str) {
let Some(shadow) = self.this_result_local_shadow_frame(root) else {
return;
};
if let Some(local) = self
.this_result_locals
.get_mut(root)
.and_then(|locals| locals.last_mut())
{
local.rebound_frame = Some(shadow);
}
}
pub(super) fn close_this_result_local_frames(&mut self, depth: usize) {
if self.this_result_locals.is_empty() {
return;
}
self.this_result_locals.retain(|_, locals| {
locals.retain(|local| local.frame < depth);
for local in locals.iter_mut() {
if local.rebound_frame.is_some_and(|frame| frame >= depth) {
local.rebound_frame = None;
}
local.forked_frames.retain(|&frame| frame < depth);
}
!locals.is_empty()
});
}
pub(super) fn record_inherited_this_result_access(&mut self, object_name: &str, member: &str) {
let (root, rest) = object_name
.split_once('.')
.map_or((object_name, None), |(root, rest)| (root, Some(rest)));
if self.this_result_local_shadow_frame(root).is_some() {
return;
}
let Some(source) = self
.innermost_this_result_local(root)
.and_then(|local| local.inherited_source.as_deref())
else {
return;
};
let source = match rest {
Some(rest) => format!("{source}.{rest}"),
None => source.to_string(),
};
let object = self.qualify_this_scope(&source);
self.push_receiver_member_access(object, member.to_string());
}
pub(super) fn record_typed_binding(
&mut self,
binding_name: &str,
type_annotation: &TSTypeAnnotation<'_>,
) {
if let Some(factory) = self.store_factory_for_type(&type_annotation.type_annotation) {
self.insert_class_binding_target(binding_name.to_string(), factory);
self.store_instance_locals.insert(binding_name.to_string());
} else if let Some(type_name) = extract_type_annotation_name(type_annotation)
&& let Some(resolved) = self.resolve_class_type_param(&type_name)
{
let origin = self.resolve_class_type_param_origin(
&type_name,
super::super::helpers::extract_type_reference_origin(
&type_annotation.type_annotation,
),
);
self.record_binding_class_proof(binding_name, &resolved, origin);
self.insert_class_binding_target(binding_name.to_string(), resolved);
}
self.record_typed_nested_bindings(binding_name, type_annotation);
}
pub(super) fn record_typed_nested_bindings(
&mut self,
binding_name: &str,
type_annotation: &TSTypeAnnotation<'_>,
) {
for (property_path, type_name, origin) in
super::super::helpers::extract_nested_type_bindings(type_annotation)
{
if let Some(factory) = self.store_factory_for_type_name(&type_name) {
self.insert_class_binding_target(
format!("{binding_name}.{property_path}"),
factory,
);
continue;
}
let Some(resolved) = self.resolve_class_type_param(&type_name) else {
continue;
};
self.record_binding_class_proof(
&format!("{binding_name}.{property_path}"),
&resolved,
self.resolve_class_type_param_origin(&type_name, origin),
);
self.insert_class_binding_target(format!("{binding_name}.{property_path}"), resolved);
}
}
pub(super) fn record_typed_destructure_binding(
&mut self,
pattern: &ObjectPattern<'_>,
type_annotation: &TSTypeAnnotation<'_>,
) {
let bindings = extract_object_pattern_bindings(pattern);
if bindings.is_empty() {
return;
}
if let TSType::TSTypeLiteral(type_lit) = &type_annotation.type_annotation {
let properties = collect_object_type_property_types(&type_lit.members);
for (local, key) in bindings {
let Some(class_name) = properties.get(&key) else {
continue;
};
if let Some(factory) = self.store_factory_for_type_name(&class_name.name) {
self.insert_class_binding_target(local.clone(), factory);
self.store_instance_locals.insert(local);
continue;
}
let origin = super::super::helpers::extract_nested_type_bindings(type_annotation)
.into_iter()
.find(|(path, _, _)| path == &key)
.and_then(|(_, _, origin)| origin);
self.record_binding_class_proof(&local, &class_name.name, origin);
self.insert_class_binding_target_if_absent(local, class_name.name.clone());
}
} else if let Some(type_name) = extract_type_annotation_name(type_annotation) {
for (local, key) in bindings {
if let Some(target) = self
.interface_property_types
.get(&type_name)
.and_then(|properties| properties.get(&key))
.cloned()
{
let owner_reference = super::super::helpers::extract_type_reference_origin(
&type_annotation.type_annotation,
);
if let (Some(reference), Some(owner)) = (owner_reference, target.owner_span) {
self.record_binding_class_proof(
&local,
&target.name,
target.reference_span,
);
self.add_direct_binding_requirement(&local, reference, owner);
}
}
self.pending_typed_destructures
.push((local, key, type_name.clone()));
}
}
}
}
fn this_method_call_name(init: &Expression<'_>) -> Option<String> {
let mut expr = init;
let call = loop {
match expr {
Expression::ParenthesizedExpression(wrapper) => expr = &wrapper.expression,
Expression::TSNonNullExpression(wrapper) => expr = &wrapper.expression,
Expression::CallExpression(call) => break call,
Expression::ChainExpression(chain) => match &chain.expression {
ChainElement::CallExpression(call) => break call,
_ => return None,
},
_ => return None,
}
};
match &call.callee {
Expression::StaticMemberExpression(member)
if matches!(member.object, Expression::ThisExpression(_)) =>
{
Some(member.property.name.to_string())
}
Expression::PrivateFieldExpression(member)
if matches!(member.object, Expression::ThisExpression(_)) =>
{
Some(format!("#{}", member.field.name))
}
_ => None,
}
}