From 366cc8f7850479666eb049245f42d927de4812fa Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Wed, 30 Oct 2024 19:08:21 +0000 Subject: [PATCH] Refactor: More efficient scope creation --- crates/oxc_transformer/src/es2022/class_properties.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/oxc_transformer/src/es2022/class_properties.rs b/crates/oxc_transformer/src/es2022/class_properties.rs index ae808a54bd0b7e..5548cadec1d2d0 100644 --- a/crates/oxc_transformer/src/es2022/class_properties.rs +++ b/crates/oxc_transformer/src/es2022/class_properties.rs @@ -64,7 +64,7 @@ use serde::Deserialize; use oxc_ast::{ast::*, AstBuilder, NONE}; use oxc_span::SPAN; -use oxc_syntax::{scope::ScopeFlags, symbol::SymbolFlags}; +use oxc_syntax::{node::NodeId, scope::ScopeFlags, symbol::SymbolFlags}; use oxc_traverse::{Ancestor, Traverse, TraverseCtx}; use crate::{common::helper_loader::Helper, TransformCtx}; @@ -213,8 +213,12 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { ctx: &mut TraverseCtx<'a>, ) { // Create scope for constructor - let scope_id = - ctx.create_child_scope_of_current(ScopeFlags::Function | ScopeFlags::Constructor); + let parent_scope_id = ctx.current_scope_id(); + let scope_id = ctx.scopes_mut().add_scope( + Some(parent_scope_id), + NodeId::DUMMY, + ScopeFlags::Function | ScopeFlags::Constructor | ScopeFlags::StrictMode, + ); // Create statements to go in function body. let mut stmts = ctx.ast.vec_with_capacity(inits.len() + has_super_class as usize);