Skip to content

Commit c2101ad

Browse files
committed
fix(transformer/class-properties): do not insert an empty iterator to insert_many_before (oxc-project#9157)
Insert an empty iterator which will cause panic after oxc-project#9063
1 parent 611b029 commit c2101ad

File tree

1 file changed

+16
-12
lines changed
  • crates/oxc_transformer/src/es2022/class_properties

1 file changed

+16
-12
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,9 @@ impl<'a> ClassProperties<'a, '_> {
448448

449449
if let Some(private_props) = &class_details.private_props {
450450
if self.private_fields_as_properties {
451-
// TODO: Only call `insert_many_before` if some private *props*
452-
self.ctx.statement_injector.insert_many_before(
453-
&stmt_address,
454-
private_props.iter().filter_map(|(&name, prop)| {
451+
let mut private_props = private_props
452+
.iter()
453+
.filter_map(|(&name, prop)| {
455454
// TODO: Output `var _C_brand = new WeakSet();` for private instance method
456455
if prop.is_method() || prop.is_accessor {
457456
return None;
@@ -460,15 +459,17 @@ impl<'a> ClassProperties<'a, '_> {
460459
// `var _prop = _classPrivateFieldLooseKey("prop");`
461460
let value = Self::create_private_prop_key_loose(name, self.ctx, ctx);
462461
Some(create_variable_declaration(&prop.binding, value, ctx))
463-
}),
464-
);
462+
})
463+
.peekable();
464+
if private_props.peek().is_some() {
465+
self.ctx.statement_injector.insert_many_before(&stmt_address, private_props);
466+
}
465467
} else {
466-
// TODO: Only call `insert_many_before` if some private *instance* props
467468
let mut weakmap_symbol_id = None;
468469
let mut has_method = false;
469-
self.ctx.statement_injector.insert_many_before(
470-
&stmt_address,
471-
private_props.values().filter_map(|prop| {
470+
let mut private_props = private_props
471+
.values()
472+
.filter_map(|prop| {
472473
if prop.is_static || (prop.is_method() && has_method) || prop.is_accessor {
473474
return None;
474475
}
@@ -483,8 +484,11 @@ impl<'a> ClassProperties<'a, '_> {
483484
let value = create_new_weakmap(&mut weakmap_symbol_id, ctx);
484485
Some(create_variable_declaration(&prop.binding, value, ctx))
485486
}
486-
}),
487-
);
487+
})
488+
.peekable();
489+
if private_props.peek().is_some() {
490+
self.ctx.statement_injector.insert_many_before(&stmt_address, private_props);
491+
}
488492
}
489493
}
490494

0 commit comments

Comments
 (0)