Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 7 additions & 6 deletions crates/oxc_transformer/src/es2022/class_properties/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ impl<'a> ClassProperties<'a, '_> {
let class_scope_id = class.scope_id().get().unwrap();
let has_super_class = class.super_class().is_some();

// Check if class has any properties or statick blocks, and locate constructor (if class has one)
// Check if class has any properties, private methods, or static blocks.
// Locate constructor (if class has one).
let mut instance_prop_count = 0;
let mut has_instance_private_method = false;
let mut has_static_prop = false;
let mut has_static_block = false;
let mut has_instance_private_method = false;
let mut has_static_private_method_or_static_block = false;
// TODO: Store `FxIndexMap`s in a pool and re-use them
let mut private_props = FxIndexMap::default();
let mut constructor = None;
Expand Down Expand Up @@ -104,7 +105,7 @@ impl<'a> ClassProperties<'a, '_> {
ClassElement::StaticBlock(_) => {
// Static block only necessitates transforming class if it's being transformed
if self.transform_static_blocks {
has_static_block = true;
has_static_private_method_or_static_block = true;
continue;
}
}
Expand All @@ -115,7 +116,7 @@ impl<'a> ClassProperties<'a, '_> {
}
} else if let PropertyKey::PrivateIdentifier(ident) = &method.key {
if method.r#static {
has_static_prop = true;
has_static_private_method_or_static_block = true;
} else {
has_instance_private_method = true;
}
Expand Down Expand Up @@ -169,7 +170,7 @@ impl<'a> ClassProperties<'a, '_> {
// Exit if nothing to transform
if instance_prop_count == 0
&& !has_static_prop
&& !has_static_block
&& !has_static_private_method_or_static_block
&& !has_instance_private_method
{
self.classes_stack.push(ClassDetails {
Expand Down
3 changes: 2 additions & 1 deletion tasks/transform_conformance/snapshots/oxc.snap.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
commit: 54a8389f

Passed: 123/141
Passed: 124/142

# All Passed:
* babel-plugin-transform-class-static-block
* babel-plugin-transform-private-methods
* babel-plugin-transform-logical-assignment-operators
* babel-plugin-transform-nullish-coalescing-operator
* babel-plugin-transform-optional-catch-binding
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"plugins": [
"transform-class-properties",
"transform-private-methods"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class C {
#method() {}
}

class C2 {
static #method() {}
}

const C3 = class {
#method() {}
};

const C4 = class {
static #method() {}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var _Class_brand;

var _C_brand = new WeakSet();
class C {
constructor() {
babelHelpers.classPrivateMethodInitSpec(this, _C_brand);
}
}
function _method() {}

class C2 {}
function _method2() {}

const C3 = (_Class_brand = new WeakSet(), class {
constructor() {
babelHelpers.classPrivateMethodInitSpec(this, _Class_brand);
}
});
function _method3() {}

const C4 = class {};
function _method4() {}
Loading