-
-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(transformer/class-properties): add more tests
- Loading branch information
1 parent
065f7dc
commit a61e9be
Showing
6 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...babel-plugin-transform-class-properties/test/fixtures/private-logical-assignment/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...abel-plugin-transform-class-properties/test/fixtures/private-logical-assignment/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...plugin-transform-class-properties/test/fixtures/private-loose-logical-assignment/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...in-transform-class-properties/test/fixtures/private-loose-logical-assignment/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"transform-class-properties", | ||
{ | ||
"loose": true | ||
} | ||
] | ||
] | ||
} |
28 changes: 28 additions & 0 deletions
28
...lugin-transform-class-properties/test/fixtures/private-loose-logical-assignment/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |