Skip to content

Commit

Permalink
Refactor to reduce duplication and return early from iterating scope …
Browse files Browse the repository at this point in the history
…ancestors
  • Loading branch information
maurice committed Feb 5, 2024
1 parent 3435b20 commit 4b7e8d4
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,23 @@ impl<'a> SemanticBuilder<'a> {
}

pub fn set_function_node_flag(&mut self, flag: NodeFlags) {
if let Some(node_id) = self.get_function_node_id() {
*self.nodes.get_node_mut(node_id).flags_mut() |= flag;
}
}

fn get_function_node_id(&self) -> Option<AstNodeId> {
if self.current_scope_flags().is_function() {
*self.nodes.get_node_mut(self.scope.get_node_id(self.current_scope_id)).flags_mut() |=
flag;
} else {
for scope_id in self.scope.ancestors(self.current_scope_id) {
if self.scope.get_flags(scope_id).is_function() {
*self.nodes.get_node_mut(self.scope.get_node_id(scope_id)).flags_mut() |= flag;
}
return Some(self.scope.get_node_id(self.current_scope_id));
}

for scope_id in self.scope.ancestors(self.current_scope_id) {
if self.scope.get_flags(scope_id).is_function() {
return Some(self.scope.get_node_id(scope_id));
}
}

None
}

/// Declares a `Symbol` for the node, adds it to symbol table, and binds it to the scope.
Expand Down

0 comments on commit 4b7e8d4

Please sign in to comment.