Skip to content

Commit b0569bc

Browse files
authored
feat(semantic): add current_scope_flags function in SemanticBuilder (#1906)
1 parent a6d9356 commit b0569bc

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

crates/oxc_semantic/src/binder.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a> Binder for VariableDeclarator<'a> {
4141
// Logic for scope hoisting `var`
4242

4343
let mut var_scope_ids = vec![];
44-
if !builder.scope.get_flags(current_scope_id).is_var() {
44+
if !builder.current_scope_flags().is_var() {
4545
for scope_id in builder.scope.ancestors(current_scope_id).skip(1) {
4646
if builder.scope.get_flags(scope_id).is_var() {
4747
var_scope_ids.push(scope_id);
@@ -106,8 +106,7 @@ impl<'a> Binder for Function<'a> {
106106
fn bind(&self, builder: &mut SemanticBuilder) {
107107
let current_scope_id = builder.current_scope_id;
108108
if let Some(ident) = &self.id {
109-
let flags = builder.scope.get_flags(current_scope_id);
110-
if !flags.is_strict_mode()
109+
if !builder.current_scope_flags().is_strict_mode()
111110
&& matches!(
112111
builder.nodes.parent_kind(builder.current_node_id),
113112
Some(AstKind::IfStatement(_))
@@ -158,7 +157,7 @@ impl<'a> Binder for Function<'a> {
158157
}
159158

160159
// bind scope flags: Constructor | GetAccessor | SetAccessor
161-
debug_assert!(builder.scope.get_flags(current_scope_id).contains(ScopeFlags::Function));
160+
debug_assert!(builder.current_scope_flags().contains(ScopeFlags::Function));
162161
if let Some(kind) = builder.nodes.parent_kind(builder.current_node_id) {
163162
match kind {
164163
AstKind::MethodDefinition(def) => {

crates/oxc_semantic/src/builder.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,12 @@ impl<'a> SemanticBuilder<'a> {
219219
}
220220
}
221221

222+
pub fn current_scope_flags(&self) -> ScopeFlags {
223+
self.scope.get_flags(self.current_scope_id)
224+
}
225+
222226
pub fn strict_mode(&self) -> bool {
223-
self.scope.get_flags(self.current_scope_id).is_strict_mode()
227+
self.current_scope_flags().is_strict_mode()
224228
|| self.current_node_flags.contains(NodeFlags::Class)
225229
}
226230

0 commit comments

Comments
 (0)