use super::ScopeVisitor;
use no_mistakes_ts_facts::syntax_helpers::unwrap_ts_wrappers;
use oxc_ast::ast::Expression;
impl ScopeVisitor<'_> {
pub(in crate::embedded::walk) fn enter_function(&mut self, start: u32, executes_now: bool) {
let proof = &mut self.member_query_proof;
proof.next_function_id += 1;
let callback = self.scoped.transaction_callback_starts.contains(&start);
proof.callback_frames.push(callback);
if executes_now || callback {
let parent = proof.function_ids.last().copied().unwrap_or(0);
proof
.transaction_callbacks
.parents
.insert(proof.next_function_id, parent);
}
proof.function_ids.push(proof.next_function_id);
self.var_scopes.push(self.scopes.len().saturating_sub(1));
self.function_scopes
.push(self.scopes.len().saturating_sub(1));
}
pub(in crate::embedded::walk) fn leave_function(&mut self) {
self.member_query_proof.function_ids.pop();
self.member_query_proof.callback_frames.pop();
self.function_scopes.pop();
self.var_scopes.pop();
}
pub(in crate::embedded::walk) fn note_returned_callback_call(
&mut self,
expression: &Expression<'_>,
) {
if self.executor_options.track_transaction_helpers
&& self.transaction_options.suspended == 0
&& self.member_query_proof.callback_frames.last() == Some(&true)
{
if let Expression::CallExpression(call) = unwrap_ts_wrappers(expression) {
self.awaited_lock_helper_calls.insert(call.span.start);
}
}
}
pub(in crate::embedded::walk) fn record_opaque_callback(&mut self, start: u32) {
if self.scoped.opaque_transaction_calls.contains(&start) {
let scope = super::super::transaction::execution_scope(self);
self.member_query_proof
.transaction_callbacks
.opaque_callers
.insert(scope);
}
}
pub(in crate::embedded::walk) fn append_crosses_function(&self, name: &str) -> bool {
let Some(&fn_start) = self.function_scopes.last() else {
return false;
};
self.scopes
.iter()
.enumerate()
.rev()
.find_map(|(index, scope)| scope.contains_key(name).then_some(index))
.is_some_and(|index| index < fn_start)
}
}