mirror of
https://github.com/danbulant/oxc
synced 2026-05-22 13:48:55 +00:00
refactor(transformer/class-properties): store temp_var_is_created on ClassBindings (#7981)
Move `temp_var_is_created` from main `ClassProperties` object to `ClassBindings`. It makes more sense there.
This commit is contained in:
parent
27cc6da328
commit
2e5ffd30a1
3 changed files with 13 additions and 8 deletions
|
|
@ -141,7 +141,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
let class_expr = ctx.ast.move_expression(expr);
|
let class_expr = ctx.ast.move_expression(expr);
|
||||||
if let Some(binding) = &class_details.bindings.temp {
|
if let Some(binding) = &class_details.bindings.temp {
|
||||||
// Insert `var _Class` statement, if it wasn't already in `transform_class`
|
// Insert `var _Class` statement, if it wasn't already in `transform_class`
|
||||||
if !self.temp_var_is_created {
|
if !class_details.bindings.temp_var_is_created {
|
||||||
self.ctx.var_declarations.insert_var(binding, ctx);
|
self.ctx.var_declarations.insert_var(binding, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,7 +191,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
// Binding for class name is required
|
// Binding for class name is required
|
||||||
if let Some(ident) = &class.id {
|
if let Some(ident) = &class.id {
|
||||||
// Insert `var _Class` statement, if it wasn't already in `transform_class`
|
// Insert `var _Class` statement, if it wasn't already in `transform_class`
|
||||||
if !self.temp_var_is_created {
|
if !class_details.bindings.temp_var_is_created {
|
||||||
self.ctx.var_declarations.insert_var(temp_binding, ctx);
|
self.ctx.var_declarations.insert_var(temp_binding, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -373,7 +373,6 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
let mut class_name_binding = class.id.as_ref().map(BoundIdentifier::from_binding_ident);
|
let mut class_name_binding = class.id.as_ref().map(BoundIdentifier::from_binding_ident);
|
||||||
|
|
||||||
let need_temp_var = has_static_prop && (!is_declaration || class.id.is_none());
|
let need_temp_var = has_static_prop && (!is_declaration || class.id.is_none());
|
||||||
self.temp_var_is_created = need_temp_var;
|
|
||||||
|
|
||||||
let class_temp_binding = if need_temp_var {
|
let class_temp_binding = if need_temp_var {
|
||||||
let temp_binding = ClassBindings::create_temp_binding(class_name_binding.as_ref(), ctx);
|
let temp_binding = ClassBindings::create_temp_binding(class_name_binding.as_ref(), ctx);
|
||||||
|
|
@ -393,7 +392,8 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let class_bindings = ClassBindings::new(class_name_binding, class_temp_binding);
|
let class_bindings =
|
||||||
|
ClassBindings::new(class_name_binding, class_temp_binding, need_temp_var);
|
||||||
|
|
||||||
// Add entry to `classes_stack`
|
// Add entry to `classes_stack`
|
||||||
self.classes_stack.push(ClassDetails {
|
self.classes_stack.push(ClassDetails {
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,8 @@ pub(super) struct ClassBindings<'a> {
|
||||||
/// `true` if should use temp binding for references to class in transpiled static private fields,
|
/// `true` if should use temp binding for references to class in transpiled static private fields,
|
||||||
/// `false` if can use name binding
|
/// `false` if can use name binding
|
||||||
pub static_private_fields_use_temp: bool,
|
pub static_private_fields_use_temp: bool,
|
||||||
|
/// `true` if temp var for class has been inserted
|
||||||
|
pub temp_var_is_created: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ClassBindings<'a> {
|
impl<'a> ClassBindings<'a> {
|
||||||
|
|
@ -52,8 +54,14 @@ impl<'a> ClassBindings<'a> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
name_binding: Option<BoundIdentifier<'a>>,
|
name_binding: Option<BoundIdentifier<'a>>,
|
||||||
temp_binding: Option<BoundIdentifier<'a>>,
|
temp_binding: Option<BoundIdentifier<'a>>,
|
||||||
|
temp_var_is_created: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { name: name_binding, temp: temp_binding, static_private_fields_use_temp: true }
|
Self {
|
||||||
|
name: name_binding,
|
||||||
|
temp: temp_binding,
|
||||||
|
static_private_fields_use_temp: true,
|
||||||
|
temp_var_is_created,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get `SymbolId` of name binding.
|
/// Get `SymbolId` of name binding.
|
||||||
|
|
|
||||||
|
|
@ -218,8 +218,6 @@ pub struct ClassProperties<'a, 'ctx> {
|
||||||
|
|
||||||
// State during transform of class
|
// State during transform of class
|
||||||
//
|
//
|
||||||
/// `true` if temp var for class has been inserted
|
|
||||||
temp_var_is_created: bool,
|
|
||||||
/// Scope that instance init initializers will be inserted into
|
/// Scope that instance init initializers will be inserted into
|
||||||
instance_inits_scope_id: ScopeId,
|
instance_inits_scope_id: ScopeId,
|
||||||
/// `ScopeId` of class constructor, if instance init initializers will be inserted into constructor.
|
/// `ScopeId` of class constructor, if instance init initializers will be inserted into constructor.
|
||||||
|
|
@ -256,7 +254,6 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
classes_stack: ClassesStack::default(),
|
classes_stack: ClassesStack::default(),
|
||||||
class_expression_addresses_stack: NonEmptyStack::new(Address::DUMMY),
|
class_expression_addresses_stack: NonEmptyStack::new(Address::DUMMY),
|
||||||
// Temporary values - overwritten when entering class
|
// Temporary values - overwritten when entering class
|
||||||
temp_var_is_created: false,
|
|
||||||
instance_inits_scope_id: ScopeId::new(0),
|
instance_inits_scope_id: ScopeId::new(0),
|
||||||
instance_inits_constructor_scope_id: None,
|
instance_inits_constructor_scope_id: None,
|
||||||
// `Vec`s and `FxHashMap`s which are reused for every class being transformed
|
// `Vec`s and `FxHashMap`s which are reused for every class being transformed
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue