Skip to content

Commit aa5e65f

Browse files
committed
refactor(transformer/private-methods): simplify finding parent statement of class expression (#8364)
Pure refactor. Simplify code a little.
1 parent c786fd1 commit aa5e65f

File tree

1 file changed

+10
-9
lines changed
  • crates/oxc_transformer/src/es2022/class_properties

1 file changed

+10
-9
lines changed

crates/oxc_transformer/src/es2022/class_properties/class.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -641,17 +641,18 @@ impl<'a> ClassProperties<'a, '_> {
641641

642642
// Insert private methods
643643
if !self.insert_after_stmts.is_empty() {
644-
// Find address of statement of class expression
645-
let position = ctx
646-
.ancestors()
647-
.position(Ancestor::is_parent_of_statement)
648-
.expect("Expression always inside a statement.");
649-
// Position points to parent of statement, we need to find the statement itself,
650-
// so `position - 1`.
651-
let stmt_ancestor = ctx.ancestor(position - 1);
644+
// Find `Address` of statement containing class expression
645+
let mut stmt_address = Address::DUMMY;
646+
for ancestor in ctx.ancestors() {
647+
if ancestor.is_parent_of_statement() {
648+
break;
649+
}
650+
stmt_address = ancestor.address();
651+
}
652+
652653
self.ctx
653654
.statement_injector
654-
.insert_many_after(&stmt_ancestor, self.insert_after_stmts.drain(..));
655+
.insert_many_after(&stmt_address, self.insert_after_stmts.drain(..));
655656
}
656657

657658
// Insert computed key initializers

0 commit comments

Comments
 (0)