Skip to content

Commit

Permalink
Docs: Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 21, 2024
1 parent 82bea70 commit aeb5926
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/oxc_transformer/src/es2022/class_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit aeb5926

Please sign in to comment.