Skip to content

Commit

Permalink
Revert "refactor(semantic): get function by scope_id in set_function_…
Browse files Browse the repository at this point in the history
…node_flag (#2208)"

This reverts commit c62495d.
  • Loading branch information
Boshen committed Feb 5, 2024
1 parent cdef41d commit 1db7809
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub struct SemanticBuilder<'a> {
pub current_node_flags: NodeFlags,
pub current_symbol_flags: SymbolFlags,
pub current_scope_id: ScopeId,
/// Stores current `AstKind::Function` and `AstKind::ArrowExpression` during AST visit
pub function_stack: Vec<AstNodeId>,
// To make a namespace/module value like
// we need the to know the modules we are inside
// and when we reach a value declaration we set it
Expand Down Expand Up @@ -103,6 +105,7 @@ impl<'a> SemanticBuilder<'a> {
current_symbol_flags: SymbolFlags::empty(),
in_type_definition: false,
current_scope_id,
function_stack: vec![],
namespace_stack: vec![],
nodes: AstNodes::default(),
scope,
Expand Down Expand Up @@ -226,9 +229,8 @@ impl<'a> SemanticBuilder<'a> {
}

pub fn set_function_node_flag(&mut self, flag: NodeFlags) {
if self.current_scope_flags().is_function() {
*self.nodes.get_node_mut(self.scope.get_node_id(self.current_scope_id)).flags_mut() |=
flag;
if let Some(current_function) = self.function_stack.last() {
*self.nodes.get_node_mut(*current_function).flags_mut() |= flag;
}
}

Expand Down Expand Up @@ -1659,12 +1661,14 @@ impl<'a> SemanticBuilder<'a> {
}
AstKind::StaticBlock(_) => self.label_builder.enter_function_or_static_block(),
AstKind::Function(func) => {
self.function_stack.push(self.current_node_id);
func.bind(self);
self.label_builder.enter_function_or_static_block();
self.add_current_node_id_to_current_scope();
self.make_all_namespaces_valuelike();
}
AstKind::ArrowExpression(_) => {
self.function_stack.push(self.current_node_id);
self.add_current_node_id_to_current_scope();
self.make_all_namespaces_valuelike();
}
Expand Down Expand Up @@ -1761,9 +1765,16 @@ impl<'a> SemanticBuilder<'a> {
self.current_symbol_flags -= SymbolFlags::Export;
}
AstKind::LabeledStatement(_) => self.label_builder.leave(),
AstKind::StaticBlock(_) | AstKind::Function(_) => {
AstKind::StaticBlock(_) => {
self.label_builder.leave_function_or_static_block();
}
AstKind::Function(_) => {
self.label_builder.leave_function_or_static_block();
self.function_stack.pop();
}
AstKind::ArrowExpression(_) => {
self.function_stack.pop();
}
AstKind::TSModuleBlock(_) => {
self.namespace_stack.pop();
}
Expand Down

0 comments on commit 1db7809

Please sign in to comment.