From aeb5926d95b717002af74c5d9c3594889246b58a Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Thu, 21 Nov 2024 23:13:45 +0000 Subject: [PATCH] Docs: Comments --- crates/oxc_transformer/src/es2022/class_properties.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/oxc_transformer/src/es2022/class_properties.rs b/crates/oxc_transformer/src/es2022/class_properties.rs index 90cefdc532402a..8bdc543eb66ada 100644 --- a/crates/oxc_transformer/src/es2022/class_properties.rs +++ b/crates/oxc_transformer/src/es2022/class_properties.rs @@ -2299,16 +2299,18 @@ impl<'a, 'c> ConstructorBodyInitsInserter<'a, 'c> { // What we get is completely legal output and correct `Semantic`, just longer than it could be. // But this should never happen in practice, so no point writing special logic to handle it. for stmt in stmts_iter.by_ref() { + // If statement is standalone `super()`, insert inits after `super()`. + // We can avoid a nested `_super` function for this common case. if let Statement::ExpressionStatement(expr_stmt) = &*stmt { if let Expression::CallExpression(call_expr) = &expr_stmt.expression { if let Expression::Super(_) = &call_expr.callee { - // `super()` as top level statement stmts.splice(insert_index..insert_index, exprs_into_stmts(inits, self.ctx)); return; } } } + // Traverse statement looking for `super()` deeper in the statement self.visit_statement(stmt); if self.super_binding.is_some() { break; @@ -2317,7 +2319,8 @@ impl<'a, 'c> ConstructorBodyInitsInserter<'a, 'c> { insert_index += 1; } - // `super()` found not in top level position. Convert all other `super()`s to `_super()`. + // `super()` found in nested position. There may be more `super()`s in constructor. + // Convert them all to `_super()`. for stmt in stmts_iter { self.visit_statement(stmt); }