-
-
Notifications
You must be signed in to change notification settings - Fork 777
Closed
Labels
C-enhancementCategory - New feature or requestCategory - New feature or request
Description
We have discussed this at #4147 (comment). But we do need this at the moment.
In semantic builder, We need enter_scope before enter_node in visit_function and visit_class.
oxc/crates/oxc_semantic/src/builder.rs
Lines 1423 to 1450 in 2eb37d5
| fn visit_function(&mut self, func: &Function<'a>, flags: Option<ScopeFlags>) { | |
| let kind = AstKind::Function(self.alloc(func)); | |
| self.enter_scope( | |
| { | |
| let mut flags = flags.unwrap_or(ScopeFlags::empty()) | ScopeFlags::Function; | |
| if func.is_strict() { | |
| flags |= ScopeFlags::StrictMode; | |
| } | |
| flags | |
| }, | |
| &func.scope_id, | |
| ); | |
| /* cfg */ | |
| let (before_function_graph_ix, error_harness, function_graph_ix) = | |
| control_flow!(|self, cfg| { | |
| let before_function_graph_ix = cfg.current_node_ix; | |
| cfg.push_finalization_stack(); | |
| let error_harness = cfg.attach_error_harness(ErrorEdgeKind::Implicit); | |
| let function_graph_ix = cfg.new_basic_block_function(); | |
| cfg.ctx(None).new_function(); | |
| (before_function_graph_ix, error_harness, function_graph_ix) | |
| }); | |
| /* cfg */ | |
| // We add a new basic block to the cfg before entering the node | |
| // so that the correct cfg_ix is associated with the ast node. | |
| self.enter_node(kind); |
We want to treat FunctionExpression and FunctionDeclaration differently and the class is the same too.
FunctionExpression: create a binding for function id to the current scope
FunctionDeclaration: create a binding for function id to the parent scope
To add the binding to the parent scope, we must need enter_scope before enter_node.
I tried another way to get around it (Same as TypeScript). But I find it a bit confusing. See: #4195 (review)
Metadata
Metadata
Assignees
Labels
C-enhancementCategory - New feature or requestCategory - New feature or request