Skip to content

Commit

Permalink
test(transformer/class-properties): add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Dec 9, 2024
1 parent 065f7dc commit a61e9be
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tasks/transform_conformance/snapshots/oxc.snap.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
commit: 54a8389f

Passed: 95/106
Passed: 96/108

# All Passed:
* babel-plugin-transform-class-properties
* babel-plugin-transform-class-static-block
* babel-plugin-transform-nullish-coalescing-operator
* babel-plugin-transform-optional-catch-binding
Expand All @@ -16,6 +15,11 @@ Passed: 95/106
* regexp


# babel-plugin-transform-class-properties (3/4)
* private-loose-logical-assignment/input.js
x Output mismatch


# babel-plugin-transform-async-to-generator (14/15)
* super/nested/input.js
x Output mismatch
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Foo {
#nullish = 0;
#and = 0;
#or = 0;

self() {
return this;
}

test() {
this.#nullish ??= 42;
this.#and &&= 0;
this.#or ||= 0;

this.self().#nullish ??= 42;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var _nullish = /*#__PURE__*/new WeakMap();
var _and = /*#__PURE__*/new WeakMap();
var _or = /*#__PURE__*/new WeakMap();
class Foo {
constructor() {
babelHelpers.classPrivateFieldInitSpec(this, _nullish, 0);
babelHelpers.classPrivateFieldInitSpec(this, _and, 0);
babelHelpers.classPrivateFieldInitSpec(this, _or, 0);
}
self() {
return this;
}
test() {
var _this$self;
babelHelpers.classPrivateFieldGet2(_nullish, this) ?? babelHelpers.classPrivateFieldSet2(_nullish, this, 42);
babelHelpers.classPrivateFieldGet2(_and, this) && babelHelpers.classPrivateFieldSet2(_and, this, 0);
babelHelpers.classPrivateFieldGet2(_or, this) || babelHelpers.classPrivateFieldSet2(_or, this, 0);
babelHelpers.classPrivateFieldGet2(_nullish, _this$self = this.self()) ?? babelHelpers.classPrivateFieldSet2(_nullish, _this$self, 42);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Foo {
#nullish = 0;
#and = 0;
#or = 0;

self() {
return this;
}

test() {
this.#nullish ??= 42;
this.#and &&= 0;
this.#or ||= 0;

this.self().#nullish ??= 42;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-class-properties",
{
"loose": true
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var _nullish = babelHelpers.classPrivateFieldLooseKey("nullish");
var _and = babelHelpers.classPrivateFieldLooseKey("and");
var _or = babelHelpers.classPrivateFieldLooseKey("or");
class Foo {
constructor() {
Object.defineProperty(this, _nullish, {
writable: true,
value: 0
});
Object.defineProperty(this, _and, {
writable: true,
value: 0
});
Object.defineProperty(this, _or, {
writable: true,
value: 0
});
}
self() {
return this;
}
test() {
babelHelpers.classPrivateFieldLooseBase(this, _nullish)[_nullish] ??= 42;
babelHelpers.classPrivateFieldLooseBase(this, _and)[_and] &&= 0;
babelHelpers.classPrivateFieldLooseBase(this, _or)[_or] ||= 0;
babelHelpers.classPrivateFieldLooseBase(this.self(), _nullish)[_nullish] ??= 42;
}
}

0 comments on commit a61e9be

Please sign in to comment.