Skip to content

Commit 3ac893e

Browse files
committed
refactor(semantic): add Scoping to Semantic
part of #9607
1 parent 2e91dc4 commit 3ac893e

File tree

6 files changed

+101
-110
lines changed

6 files changed

+101
-110
lines changed

crates/oxc_semantic/src/binder.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ impl<'a> Binder<'a> for VariableDeclarator<'a> {
4545
let mut var_scope_ids = vec![];
4646

4747
// Collect all scopes where variable hoisting can occur
48-
for scope_id in builder.scope.scope_ancestors(target_scope_id) {
49-
let flags = builder.scope.scope_flags(scope_id);
48+
for scope_id in builder.scoping.scopes.scope_ancestors(target_scope_id) {
49+
let flags = builder.scoping.scopes.scope_flags(scope_id);
5050
if flags.is_var() {
5151
target_scope_id = scope_id;
5252
break;
@@ -68,9 +68,9 @@ impl<'a> Binder<'a> for VariableDeclarator<'a> {
6868

6969
// remove current scope binding and add to target scope
7070
// avoid same symbols appear in multi-scopes
71-
builder.scope.remove_binding(scope_id, &name);
72-
builder.scope.add_binding(target_scope_id, &name, symbol_id);
73-
builder.symbols.symbol_scope_ids[symbol_id] = target_scope_id;
71+
builder.scoping.scopes.remove_binding(scope_id, &name);
72+
builder.scoping.scopes.add_binding(target_scope_id, &name, symbol_id);
73+
builder.scoping.symbols.symbol_scope_ids[symbol_id] = target_scope_id;
7474
break;
7575
}
7676
}
@@ -106,7 +106,7 @@ impl<'a> Binder<'a> for VariableDeclarator<'a> {
106106
Expression::ArrowFunctionExpression(func) => func.pure,
107107
_ => false,
108108
} {
109-
builder.symbols.no_side_effects.insert(symbol_id);
109+
builder.scoping.symbols.no_side_effects.insert(symbol_id);
110110
}
111111
}
112112
}
@@ -169,7 +169,7 @@ impl<'a> Binder<'a> for Function<'a> {
169169
let scope_flags = builder.current_scope_flags();
170170
if let Some(ident) = &self.id {
171171
if is_function_part_of_if_statement(self, builder) {
172-
let symbol_id = builder.symbols.create_symbol(
172+
let symbol_id = builder.scoping.symbols.create_symbol(
173173
ident.span,
174174
ident.name.into(),
175175
SymbolFlags::Function,
@@ -215,7 +215,7 @@ impl<'a> Binder<'a> for Function<'a> {
215215
if let Some(AstKind::ObjectProperty(prop)) =
216216
builder.nodes.parent_kind(builder.current_node_id)
217217
{
218-
let flags = builder.scope.scope_flags_mut(current_scope_id);
218+
let flags = builder.scoping.scopes.scope_flags_mut(current_scope_id);
219219
match prop.kind {
220220
PropertyKind::Get => *flags |= ScopeFlags::GetAccessor,
221221
PropertyKind::Set => *flags |= ScopeFlags::SetAccessor,
@@ -226,7 +226,7 @@ impl<'a> Binder<'a> for Function<'a> {
226226
// Save `@__NO_SIDE_EFFECTS__`
227227
if self.pure {
228228
if let Some(symbold_id) = self.id.as_ref().and_then(|id| id.symbol_id.get()) {
229-
builder.symbols.no_side_effects.insert(symbold_id);
229+
builder.scoping.symbols.no_side_effects.insert(symbold_id);
230230
}
231231
}
232232
}
@@ -439,17 +439,17 @@ impl<'a> Binder<'a> for TSModuleDeclaration<'a> {
439439

440440
impl<'a> Binder<'a> for TSTypeParameter<'a> {
441441
fn bind(&self, builder: &mut SemanticBuilder) {
442-
let scope_id = if matches!(
443-
builder.nodes.parent_kind(builder.current_node_id),
444-
Some(AstKind::TSInferType(_))
445-
) {
446-
builder
447-
.scope
448-
.scope_ancestors(builder.current_scope_id)
449-
.find(|scope_id| builder.scope.scope_flags(*scope_id).is_ts_conditional())
450-
} else {
451-
None
452-
};
442+
let scope_id =
443+
if matches!(
444+
builder.nodes.parent_kind(builder.current_node_id),
445+
Some(AstKind::TSInferType(_))
446+
) {
447+
builder.scoping.scopes.scope_ancestors(builder.current_scope_id).find(|scope_id| {
448+
builder.scoping.scopes.scope_flags(*scope_id).is_ts_conditional()
449+
})
450+
} else {
451+
None
452+
};
453453

454454
let symbol_id = builder.declare_symbol_on_scope(
455455
self.name.span,

0 commit comments

Comments
 (0)