Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
255 additions
and
27 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
60 changes: 60 additions & 0 deletions
60
...ages/babel-plugin-proposal-private-methods/test/fixtures/private-method/accessors/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,60 @@ | ||
class Foo { | ||
#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 = 0; | ||
this.publicField = 0; | ||
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 += 1; | ||
this.publicFieldValue += 1; | ||
expect(this.#privateField).toEqual(this.publicField); | ||
|
||
this.#privateFieldValue = -(this.#privateFieldValue ** this.#privateFieldValue); | ||
this.publicFieldValue = -(this.publicFieldValue ** this.publicFieldValue); | ||
expect(this.#privateField).toEqual(this.publicField); | ||
} | ||
} | ||
|
||
const foo = new Foo(); | ||
|
||
expect(foo.publicGetPrivateField()).toEqual("top secret string"); | ||
|
||
foo.publicSetPrivateField("new secret string"); | ||
expect(foo.publicGetPrivateField()).toEqual("new secret string"); | ||
|
||
foo.testUpdates(); |
47 changes: 47 additions & 0 deletions
47
...ges/babel-plugin-proposal-private-methods/test/fixtures/private-method/accessors/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 Foo { | ||
#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 = 0; | ||
this.publicField = 0; | ||
this.#privateFieldValue = this.#privateFieldValue++; | ||
this.publicFieldValue = this.publicFieldValue++; | ||
|
||
++this.#privateFieldValue; | ||
++this.publicFieldValue; | ||
|
||
this.#privateFieldValue += 1; | ||
this.publicFieldValue += 1; | ||
|
||
this.#privateFieldValue = -(this.#privateFieldValue ** this.#privateFieldValue); | ||
this.publicFieldValue = -(this.publicFieldValue ** this.publicFieldValue); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...es/babel-plugin-proposal-private-methods/test/fixtures/private-method/accessors/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,70 @@ | ||
var Foo = | ||
/*#__PURE__*/ | ||
function () { | ||
"use strict"; | ||
|
||
function Foo() { | ||
babelHelpers.classCallCheck(this, Foo); | ||
|
||
_privateField.set(this, { | ||
writable: true, | ||
value: "top secret string" | ||
}); | ||
|
||
_privateFieldValue.set(this, { | ||
get: _get_privateFieldValue, | ||
set: _set_privateFieldValue | ||
}); | ||
|
||
this.publicField = "not secret string"; | ||
} | ||
|
||
babelHelpers.createClass(Foo, [{ | ||
key: "publicGetPrivateField", | ||
value: function publicGetPrivateField() { | ||
return babelHelpers.classPrivateFieldGet(this, _privateFieldValue); | ||
} | ||
}, { | ||
key: "publicSetPrivateField", | ||
value: function publicSetPrivateField(newValue) { | ||
babelHelpers.classPrivateFieldSet(this, _privateFieldValue, newValue); | ||
} | ||
}, { | ||
key: "testUpdates", | ||
value: function testUpdates() { | ||
var _this$privateFieldVal, _this$privateFieldVal2; | ||
|
||
babelHelpers.classPrivateFieldSet(this, _privateField, 0); | ||
this.publicField = 0; | ||
babelHelpers.classPrivateFieldSet(this, _privateFieldValue, (babelHelpers.classPrivateFieldSet(this, _privateFieldValue, (_this$privateFieldVal2 = +babelHelpers.classPrivateFieldGet(this, _privateFieldValue)) + 1), _this$privateFieldVal2)); | ||
this.publicFieldValue = this.publicFieldValue++; | ||
babelHelpers.classPrivateFieldSet(this, _privateFieldValue, +babelHelpers.classPrivateFieldGet(this, _privateFieldValue) + 1); | ||
++this.publicFieldValue; | ||
babelHelpers.classPrivateFieldSet(this, _privateFieldValue, babelHelpers.classPrivateFieldGet(this, _privateFieldValue) + 1); | ||
this.publicFieldValue += 1; | ||
babelHelpers.classPrivateFieldSet(this, _privateFieldValue, -(babelHelpers.classPrivateFieldGet(this, _privateFieldValue) ** babelHelpers.classPrivateFieldGet(this, _privateFieldValue))); | ||
this.publicFieldValue = -(this.publicFieldValue ** this.publicFieldValue); | ||
} | ||
}, { | ||
key: "publicFieldValue", | ||
get: function () { | ||
return this.publicField; | ||
}, | ||
set: function (newValue) { | ||
this.publicField = newValue; | ||
} | ||
}]); | ||
return Foo; | ||
}(); | ||
|
||
var _privateField = new WeakMap(); | ||
|
||
var _privateFieldValue = new WeakMap(); | ||
|
||
var _get_privateFieldValue = function () { | ||
return babelHelpers.classPrivateFieldGet(this, _privateField); | ||
}; | ||
|
||
var _set_privateFieldValue = function (newValue) { | ||
babelHelpers.classPrivateFieldSet(this, _privateField, newValue); | ||
}; |