From ab3e1c3df4927dafb433e2257d3437980031c7db Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:05:00 +0000 Subject: [PATCH] refactor(transformer/class-properties): add TODO comments (#7702) Add "TODO" comments for future optimizations we could make. --- .../src/es2022/class_properties/constructor.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/oxc_transformer/src/es2022/class_properties/constructor.rs b/crates/oxc_transformer/src/es2022/class_properties/constructor.rs index cc10f9daf..1b7dfafc0 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/constructor.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/constructor.rs @@ -398,6 +398,10 @@ impl<'a, 'c> ConstructorParamsSuperReplacer<'a, 'c> { /// Create `_super` function to go outside class. /// `function() { ; return this; }` + // + // TODO(improve-on-babel): When not in loose mode, inits are `_defineProperty(this, propName, value)`. + // `_defineProperty` returns `this`, so last statement could be `return _defineProperty(this, propName, value)`, + // rather than an additional `return this` statement. fn create_super_func(inits: Vec>, ctx: &mut TraverseCtx<'a>) -> Expression<'a> { let outer_scope_id = ctx.current_scope_id(); let super_func_scope_id = ctx.scopes_mut().add_scope( @@ -518,6 +522,10 @@ impl<'a, 'c> ConstructorBodyInitsInserter<'a, 'c> { ctx.generate_uid("args", super_func_scope_id, SymbolFlags::FunctionScopedVariable); // `super(..._args); ; return this;` + // + // TODO(improve-on-babel): When not in loose mode, inits are `_defineProperty(this, propName, value)`. + // `_defineProperty` returns `this`, so last statement could be `return _defineProperty(this, propName, value)`, + // rather than an additional `return this` statement. let super_call = create_super_call_stmt(&args_binding, ctx); let return_stmt = ctx.ast.statement_return(SPAN, Some(ctx.ast.expression_this(SPAN))); let body_stmts = ctx.ast.vec_from_iter(