Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support bigints in update expressions for private fields (#14311)
- Loading branch information
1 parent
dd6a53d
commit 7ff3084
Showing
12 changed files
with
216 additions
and
41 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
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
50 changes: 50 additions & 0 deletions
50
...ages/babel-plugin-proposal-private-methods/test/fixtures/accessors/updates-bigint/exec.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,50 @@ | ||
class Cl { | ||
#privateField = "top secret string"; | ||
|
||
constructor() { | ||
this.publicField = "not secret string"; | ||
} | ||
|
||
get #privateFieldValue() { | ||
return this.#privateField; | ||
} | ||
|
||
set #privateFieldValue(newValue) { | ||
this.#privateField = newValue; | ||
} | ||
|
||
publicGetPrivateField() { | ||
return this.#privateFieldValue; | ||
} | ||
|
||
publicSetPrivateField(newValue) { | ||
this.#privateFieldValue = newValue; | ||
} | ||
|
||
get publicFieldValue() { | ||
return this.publicField; | ||
} | ||
|
||
set publicFieldValue(newValue) { | ||
this.publicField = newValue; | ||
} | ||
|
||
testUpdates() { | ||
this.#privateField = 0n; | ||
this.publicField = 0n; | ||
this.#privateFieldValue = this.#privateFieldValue++; | ||
this.publicFieldValue = this.publicFieldValue++; | ||
expect(this.#privateField).toEqual(this.publicField); | ||
|
||
++this.#privateFieldValue; | ||
++this.publicFieldValue; | ||
expect(this.#privateField).toEqual(this.publicField); | ||
|
||
this.#privateFieldValue += 1n; | ||
this.publicFieldValue += 1n; | ||
expect(this.#privateField).toEqual(this.publicField); | ||
} | ||
} | ||
|
||
const cl = new Cl(); | ||
cl.testUpdates(); |
47 changes: 47 additions & 0 deletions
47
...ges/babel-plugin-proposal-private-methods/test/fixtures/accessors/updates-bigint/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,47 @@ | ||
class Cl { | ||
#privateField = "top secret string"; | ||
|
||
constructor() { | ||
this.publicField = "not secret string"; | ||
} | ||
|
||
get #privateFieldValue() { | ||
return this.#privateField; | ||
} | ||
|
||
set #privateFieldValue(newValue) { | ||
this.#privateField = newValue; | ||
} | ||
|
||
publicGetPrivateField() { | ||
return this.#privateFieldValue; | ||
} | ||
|
||
publicSetPrivateField(newValue) { | ||
this.#privateFieldValue = newValue; | ||
} | ||
|
||
get publicFieldValue() { | ||
return this.publicField; | ||
} | ||
|
||
set publicFieldValue(newValue) { | ||
this.publicField = newValue; | ||
} | ||
|
||
testUpdates() { | ||
this.#privateField = 0n; | ||
this.publicField = 0n; | ||
this.#privateFieldValue = this.#privateFieldValue++; | ||
this.publicFieldValue = this.publicFieldValue++; | ||
|
||
++this.#privateFieldValue; | ||
++this.publicFieldValue; | ||
|
||
this.#privateFieldValue += 1n; | ||
this.publicFieldValue += 1n; | ||
|
||
this.#privateFieldValue = -(this.#privateFieldValue ** this.#privateFieldValue); | ||
this.publicFieldValue = -(this.publicFieldValue ** this.publicFieldValue); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...babel-plugin-proposal-private-methods/test/fixtures/accessors/updates-bigint/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,8 @@ | ||
{ | ||
"minNodeVersion": "10.0.0", | ||
"plugins": [ | ||
"proposal-private-methods", | ||
"proposal-class-properties", | ||
"transform-block-scoping" | ||
] | ||
} |
57 changes: 57 additions & 0 deletions
57
...es/babel-plugin-proposal-private-methods/test/fixtures/accessors/updates-bigint/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,57 @@ | ||
var _privateField = /*#__PURE__*/new WeakMap(); | ||
|
||
var _privateFieldValue = /*#__PURE__*/new WeakMap(); | ||
|
||
class Cl { | ||
constructor() { | ||
babelHelpers.classPrivateFieldInitSpec(this, _privateFieldValue, { | ||
get: _get_privateFieldValue, | ||
set: _set_privateFieldValue | ||
}); | ||
babelHelpers.classPrivateFieldInitSpec(this, _privateField, { | ||
writable: true, | ||
value: "top secret string" | ||
}); | ||
this.publicField = "not secret string"; | ||
} | ||
|
||
publicGetPrivateField() { | ||
return babelHelpers.classPrivateFieldGet(this, _privateFieldValue); | ||
} | ||
|
||
publicSetPrivateField(newValue) { | ||
babelHelpers.classPrivateFieldSet(this, _privateFieldValue, newValue); | ||
} | ||
|
||
get publicFieldValue() { | ||
return this.publicField; | ||
} | ||
|
||
set publicFieldValue(newValue) { | ||
this.publicField = newValue; | ||
} | ||
|
||
testUpdates() { | ||
var _this$privateFieldVal, _this$privateFieldVal2, _this$privateFieldVal3, _this$privateFieldVal4, _this$privateFieldVal5; | ||
|
||
babelHelpers.classPrivateFieldSet(this, _privateField, 0n); | ||
this.publicField = 0n; | ||
babelHelpers.classPrivateFieldSet(this, _privateFieldValue, (babelHelpers.classPrivateFieldSet(this, _privateFieldValue, (_this$privateFieldVal3 = babelHelpers.classPrivateFieldGet(this, _privateFieldValue), _this$privateFieldVal4 = _this$privateFieldVal3++, _this$privateFieldVal3)), _this$privateFieldVal4)); | ||
this.publicFieldValue = this.publicFieldValue++; | ||
babelHelpers.classPrivateFieldSet(this, _privateFieldValue, (_this$privateFieldVal5 = babelHelpers.classPrivateFieldGet(this, _privateFieldValue), ++_this$privateFieldVal5)); | ||
++this.publicFieldValue; | ||
babelHelpers.classPrivateFieldSet(this, _privateFieldValue, babelHelpers.classPrivateFieldGet(this, _privateFieldValue) + 1n); | ||
this.publicFieldValue += 1n; | ||
babelHelpers.classPrivateFieldSet(this, _privateFieldValue, -(babelHelpers.classPrivateFieldGet(this, _privateFieldValue) ** babelHelpers.classPrivateFieldGet(this, _privateFieldValue))); | ||
this.publicFieldValue = -(this.publicFieldValue ** this.publicFieldValue); | ||
} | ||
|
||
} | ||
|
||
function _get_privateFieldValue() { | ||
return babelHelpers.classPrivateFieldGet(this, _privateField); | ||
} | ||
|
||
function _set_privateFieldValue(newValue) { | ||
babelHelpers.classPrivateFieldSet(this, _privateField, newValue); | ||
} |
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
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
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
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
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
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