Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions crates/oxc_transformer/src/es2022/class_properties/class.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! ES2022: Class Properties
//! Transform of class itself.

use indexmap::map::Entry;
use indexmap::{IndexMap, map::Entry};
use oxc_allocator::{Address, GetAddress, TakeIn};
use oxc_ast::{NONE, ast::*};
use oxc_span::SPAN;
Expand Down Expand Up @@ -385,12 +385,11 @@ impl<'a> ClassProperties<'a, '_> {
if class_details.is_transform_required {
self.transform_class_declaration_on_exit_impl(class, ctx);
} else {
// Note: `is_transform_required` is `true` if class has any private properties/methods,
// so no need to touch `private_field_count` here
debug_assert!(class_details.bindings.temp.is_none());
}
// Pop off stack. We're done!
self.classes_stack.pop();
let class_details = self.classes_stack.pop();
self.private_field_count -= class_details.private_props.as_ref().map_or(0, IndexMap::len);
}

fn transform_class_declaration_on_exit_impl(
Expand Down Expand Up @@ -447,8 +446,6 @@ impl<'a> ClassProperties<'a, '_> {
}

if let Some(private_props) = &class_details.private_props {
self.private_field_count -= private_props.len();

if self.private_fields_as_properties {
let mut private_props = private_props
.iter()
Expand Down Expand Up @@ -539,13 +536,12 @@ impl<'a> ClassProperties<'a, '_> {
if class_details.is_transform_required {
self.transform_class_expression_on_exit_impl(expr, ctx);
} else {
// Note: `is_transform_required` is `true` if class has any private properties/methods,
// so no need to touch `private_field_count` here
debug_assert!(class_details.bindings.temp.is_none());
}

// Pop off stack. We're done!
self.classes_stack.pop();
let class_details = self.classes_stack.pop();
self.private_field_count -= class_details.private_props.as_ref().map_or(0, IndexMap::len);
}

fn transform_class_expression_on_exit_impl(
Expand Down Expand Up @@ -595,8 +591,6 @@ impl<'a> ClassProperties<'a, '_> {
// Babel has these always go first, regardless of order of class elements.
// Also insert `var _prop;` temp var declarations for private static props.
if let Some(private_props) = &class_details.private_props {
self.private_field_count -= private_props.len();

// Insert `var _prop;` declarations here rather than when binding was created to maintain
// same order of `var` declarations as Babel.
// `c = class C { #x = 1; static y = 2; }` -> `var _C, _x;`
Expand Down
Loading