mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(transformer/class-properties): do not pass ScopeId into insert_instance_inits (#8001)
No need to pass this var through various functions, as they already have access to `self` to get it itself.
This commit is contained in:
parent
c0dd3f8e32
commit
059a5dd56a
2 changed files with 6 additions and 10 deletions
|
|
@ -486,7 +486,6 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
class,
|
class,
|
||||||
instance_inits,
|
instance_inits,
|
||||||
&instance_inits_insert_location,
|
&instance_inits_insert_location,
|
||||||
self.instance_inits_scope_id,
|
|
||||||
constructor_index,
|
constructor_index,
|
||||||
ctx,
|
ctx,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -208,14 +208,11 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert instance property initializers.
|
/// Insert instance property initializers.
|
||||||
///
|
|
||||||
/// `scope_id` has different meaning depending on type of `insertion_location`.
|
|
||||||
pub(super) fn insert_instance_inits(
|
pub(super) fn insert_instance_inits(
|
||||||
&mut self,
|
&mut self,
|
||||||
class: &mut Class<'a>,
|
class: &mut Class<'a>,
|
||||||
inits: Vec<Expression<'a>>,
|
inits: Vec<Expression<'a>>,
|
||||||
insertion_location: &InstanceInitsInsertLocation<'a>,
|
insertion_location: &InstanceInitsInsertLocation<'a>,
|
||||||
scope_id: ScopeId,
|
|
||||||
constructor_index: usize,
|
constructor_index: usize,
|
||||||
ctx: &mut TraverseCtx<'a>,
|
ctx: &mut TraverseCtx<'a>,
|
||||||
) {
|
) {
|
||||||
|
|
@ -223,7 +220,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
|
|
||||||
match insertion_location {
|
match insertion_location {
|
||||||
InstanceInitsInsertLocation::NewConstructor => {
|
InstanceInitsInsertLocation::NewConstructor => {
|
||||||
Self::insert_constructor(class, scope_id, inits, ctx);
|
self.insert_constructor(class, inits, ctx);
|
||||||
}
|
}
|
||||||
InstanceInitsInsertLocation::ExistingConstructor(stmt_index) => {
|
InstanceInitsInsertLocation::ExistingConstructor(stmt_index) => {
|
||||||
self.insert_inits_into_constructor_as_statements(
|
self.insert_inits_into_constructor_as_statements(
|
||||||
|
|
@ -239,21 +236,20 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
class,
|
class,
|
||||||
inits,
|
inits,
|
||||||
super_binding,
|
super_binding,
|
||||||
scope_id,
|
|
||||||
constructor_index,
|
constructor_index,
|
||||||
ctx,
|
ctx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
InstanceInitsInsertLocation::SuperFnOutsideClass(super_binding) => {
|
InstanceInitsInsertLocation::SuperFnOutsideClass(super_binding) => {
|
||||||
self.create_super_function_outside_constructor(inits, super_binding, scope_id, ctx);
|
self.create_super_function_outside_constructor(inits, super_binding, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a constructor to class containing property initializers.
|
/// Add a constructor to class containing property initializers.
|
||||||
fn insert_constructor(
|
fn insert_constructor(
|
||||||
|
&self,
|
||||||
class: &mut Class<'a>,
|
class: &mut Class<'a>,
|
||||||
constructor_scope_id: ScopeId,
|
|
||||||
inits: Vec<Expression<'a>>,
|
inits: Vec<Expression<'a>>,
|
||||||
ctx: &mut TraverseCtx<'a>,
|
ctx: &mut TraverseCtx<'a>,
|
||||||
) {
|
) {
|
||||||
|
|
@ -263,6 +259,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
|
|
||||||
// Add `super(..._args);` statement and `..._args` param if class has a super class.
|
// Add `super(..._args);` statement and `..._args` param if class has a super class.
|
||||||
// `constructor(..._args) { super(..._args); /* prop initialization */ }`
|
// `constructor(..._args) { super(..._args); /* prop initialization */ }`
|
||||||
|
let constructor_scope_id = self.instance_inits_scope_id;
|
||||||
let mut params_rest = None;
|
let mut params_rest = None;
|
||||||
if has_super_class {
|
if has_super_class {
|
||||||
let args_binding =
|
let args_binding =
|
||||||
|
|
@ -339,7 +336,6 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
class: &mut Class<'a>,
|
class: &mut Class<'a>,
|
||||||
inits: Vec<Expression<'a>>,
|
inits: Vec<Expression<'a>>,
|
||||||
super_binding: &BoundIdentifier<'a>,
|
super_binding: &BoundIdentifier<'a>,
|
||||||
super_func_scope_id: ScopeId,
|
|
||||||
constructor_index: usize,
|
constructor_index: usize,
|
||||||
ctx: &mut TraverseCtx<'a>,
|
ctx: &mut TraverseCtx<'a>,
|
||||||
) {
|
) {
|
||||||
|
|
@ -354,6 +350,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
// rather than an additional `return this` statement.
|
// rather than an additional `return this` statement.
|
||||||
// Actually this wouldn't work at present, as `_classPrivateFieldInitSpec(this, _prop, value)`
|
// Actually this wouldn't work at present, as `_classPrivateFieldInitSpec(this, _prop, value)`
|
||||||
// does not return `this`. We could alter it so it does when we have our own helper package.
|
// does not return `this`. We could alter it so it does when we have our own helper package.
|
||||||
|
let super_func_scope_id = self.instance_inits_scope_id;
|
||||||
let args_binding =
|
let args_binding =
|
||||||
ctx.generate_uid("args", super_func_scope_id, SymbolFlags::FunctionScopedVariable);
|
ctx.generate_uid("args", super_func_scope_id, SymbolFlags::FunctionScopedVariable);
|
||||||
let super_call = create_super_call(&args_binding, ctx);
|
let super_call = create_super_call(&args_binding, ctx);
|
||||||
|
|
@ -412,7 +409,6 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
inits: Vec<Expression<'a>>,
|
inits: Vec<Expression<'a>>,
|
||||||
super_binding: &BoundIdentifier<'a>,
|
super_binding: &BoundIdentifier<'a>,
|
||||||
super_func_scope_id: ScopeId,
|
|
||||||
ctx: &mut TraverseCtx<'a>,
|
ctx: &mut TraverseCtx<'a>,
|
||||||
) {
|
) {
|
||||||
// Add `"use strict"` directive if outer scope is not strict mode
|
// Add `"use strict"` directive if outer scope is not strict mode
|
||||||
|
|
@ -427,6 +423,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
||||||
// `<inits>; return this;`
|
// `<inits>; return this;`
|
||||||
let body_stmts = ctx.ast.vec_from_iter(exprs_into_stmts(inits, ctx).chain([return_stmt]));
|
let body_stmts = ctx.ast.vec_from_iter(exprs_into_stmts(inits, ctx).chain([return_stmt]));
|
||||||
// `function() { <inits>; return this; }`
|
// `function() { <inits>; return this; }`
|
||||||
|
let super_func_scope_id = self.instance_inits_scope_id;
|
||||||
let super_func = Expression::FunctionExpression(ctx.ast.alloc_function_with_scope_id(
|
let super_func = Expression::FunctionExpression(ctx.ast.alloc_function_with_scope_id(
|
||||||
SPAN,
|
SPAN,
|
||||||
FunctionType::FunctionExpression,
|
FunctionType::FunctionExpression,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue