Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 54 additions & 16 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
fn visit_block_statement(&mut self, it: &BlockStatement<'a>) {
let kind = AstKind::BlockStatement(self.alloc(it));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));

let parent_scope_id = self.current_scope_id;
self.enter_scope(ScopeFlags::empty(), &it.scope_id);
Expand Down Expand Up @@ -806,6 +807,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
fn visit_do_while_statement(&mut self, stmt: &DoWhileStatement<'a>) {
let kind = AstKind::DoWhileStatement(self.alloc(stmt));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));

/* cfg */
#[cfg(feature = "cfg")]
Expand Down Expand Up @@ -1065,6 +1067,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
fn visit_for_statement(&mut self, stmt: &ForStatement<'a>) {
let kind = AstKind::ForStatement(self.alloc(stmt));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));
self.enter_scope(ScopeFlags::empty(), &stmt.scope_id);
if let Some(init) = &stmt.init {
self.visit_for_statement_init(init);
Expand Down Expand Up @@ -1135,6 +1138,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
fn visit_for_in_statement(&mut self, stmt: &ForInStatement<'a>) {
let kind = AstKind::ForInStatement(self.alloc(stmt));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));
self.enter_scope(ScopeFlags::empty(), &stmt.scope_id);

self.visit_for_statement_left(&stmt.left);
Expand Down Expand Up @@ -1198,6 +1202,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
fn visit_for_of_statement(&mut self, stmt: &ForOfStatement<'a>) {
let kind = AstKind::ForOfStatement(self.alloc(stmt));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));
self.enter_scope(ScopeFlags::empty(), &stmt.scope_id);

self.visit_for_statement_left(&stmt.left);
Expand Down Expand Up @@ -1260,6 +1265,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
fn visit_if_statement(&mut self, stmt: &IfStatement<'a>) {
let kind = AstKind::IfStatement(self.alloc(stmt));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));

/* cfg - condition basic block */
#[cfg(feature = "cfg")]
Expand Down Expand Up @@ -1333,6 +1339,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
fn visit_labeled_statement(&mut self, stmt: &LabeledStatement<'a>) {
let kind = AstKind::LabeledStatement(self.alloc(stmt));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));
self.unused_labels.add(stmt.label.name.as_str(), self.current_node_id);

/* cfg */
Expand Down Expand Up @@ -1399,6 +1406,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
fn visit_switch_statement(&mut self, stmt: &SwitchStatement<'a>) {
let kind = AstKind::SwitchStatement(self.alloc(stmt));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));
self.visit_expression(&stmt.discriminant);
self.enter_scope(ScopeFlags::empty(), &stmt.scope_id);

Expand Down Expand Up @@ -1524,6 +1532,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
fn visit_try_statement(&mut self, stmt: &TryStatement<'a>) {
let kind = AstKind::TryStatement(self.alloc(stmt));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));

/* cfg */

Expand Down Expand Up @@ -1658,6 +1667,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
fn visit_while_statement(&mut self, stmt: &WhileStatement<'a>) {
let kind = AstKind::WhileStatement(self.alloc(stmt));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));

/* cfg - condition basic block */
#[cfg(feature = "cfg")]
Expand Down Expand Up @@ -1706,6 +1716,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
fn visit_with_statement(&mut self, stmt: &WithStatement<'a>) {
let kind = AstKind::WithStatement(self.alloc(stmt));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));

/* cfg - condition basic block */
#[cfg(feature = "cfg")]
Expand Down Expand Up @@ -2400,26 +2411,53 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
}
self.leave_node(kind);
}

fn visit_expression_statement(&mut self, it: &ExpressionStatement<'a>) {
let kind = AstKind::ExpressionStatement(self.alloc(it));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));
self.visit_span(&it.span);
self.visit_expression(&it.expression);
self.leave_node(kind);
}

fn visit_variable_declaration(&mut self, it: &VariableDeclaration<'a>) {
let kind = AstKind::VariableDeclaration(self.alloc(it));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));
self.visit_span(&it.span);
self.visit_variable_declarators(&it.declarations);
self.leave_node(kind);
}

fn visit_empty_statement(&mut self, it: &EmptyStatement) {
let kind = AstKind::EmptyStatement(self.alloc(it));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));
self.visit_span(&it.span);
self.leave_node(kind);
}

fn visit_debugger_statement(&mut self, it: &DebuggerStatement) {
let kind = AstKind::DebuggerStatement(self.alloc(it));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));
self.visit_span(&it.span);
self.leave_node(kind);
}

fn visit_export_default_declaration(&mut self, it: &ExportDefaultDeclaration<'a>) {
let kind = AstKind::ExportDefaultDeclaration(self.alloc(it));
self.enter_node(kind);
control_flow!(self, |cfg| cfg.enter_statement(self.current_node_id));
self.visit_span(&it.span);
self.visit_export_default_declaration_kind(&it.declaration);
self.leave_node(kind);
}
}

impl<'a> SemanticBuilder<'a> {
fn enter_kind(&mut self, kind: AstKind<'a>) {
/* cfg */
control_flow!(self, |cfg| {
match kind {
AstKind::ReturnStatement(_)
| AstKind::BreakStatement(_)
| AstKind::ContinueStatement(_)
| AstKind::ThrowStatement(_) => { /* These types have their own `InstructionKind`. */
}
it if it.is_statement() => {
cfg.enter_statement(self.current_node_id);
}
_ => { /* ignore the rest */ }
}
});
/* cfg */

match kind {
AstKind::ContinueStatement(ContinueStatement { label, .. })
| AstKind::BreakStatement(BreakStatement { label, .. }) => {
Expand Down
Loading