Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix arguments * Update packages/babel-plugin-transform-private-methods/test/fixtures/accessors/arguments/exec.js Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com> * review * fix types --------- Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
- Loading branch information
1 parent
d7cd8e9
commit f370fb4
Showing
4 changed files
with
107 additions
and
4 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
33 changes: 33 additions & 0 deletions
33
packages/babel-plugin-transform-private-methods/test/fixtures/accessors/arguments/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,33 @@ | ||
class Cl { | ||
#privateField = "top secret string"; | ||
|
||
constructor() { | ||
this.publicField = "not secret string"; | ||
} | ||
|
||
get #privateFieldValue() { | ||
expect(arguments.length).toBe(0); | ||
return this.#privateField; | ||
} | ||
|
||
set #privateFieldValue(newValue) { | ||
expect(arguments.length).toBe(1); | ||
this.#privateField = newValue; | ||
} | ||
|
||
publicGetPrivateField() { | ||
return this.#privateFieldValue; | ||
} | ||
|
||
publicSetPrivateField(newValue) { | ||
this.#privateFieldValue = newValue; | ||
} | ||
} | ||
|
||
const cl = new Cl(); | ||
|
||
expect(cl.publicGetPrivateField()).toEqual("top secret string"); | ||
|
||
cl.publicSetPrivateField("new secret string"); | ||
expect(cl.publicGetPrivateField()).toEqual("new secret string"); | ||
|
25 changes: 25 additions & 0 deletions
25
packages/babel-plugin-transform-private-methods/test/fixtures/accessors/arguments/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,25 @@ | ||
class Cl { | ||
#privateField = "top secret string"; | ||
|
||
constructor() { | ||
this.publicField = "not secret string"; | ||
} | ||
|
||
get #privateFieldValue() { | ||
expect(arguments.length).toBe(0); | ||
return this.#privateField; | ||
} | ||
|
||
set #privateFieldValue(newValue) { | ||
expect(arguments.length).toBe(1); | ||
this.#privateField = newValue; | ||
} | ||
|
||
publicGetPrivateField() { | ||
return this.#privateFieldValue; | ||
} | ||
|
||
publicSetPrivateField(newValue) { | ||
this.#privateFieldValue = newValue; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/babel-plugin-transform-private-methods/test/fixtures/accessors/arguments/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,25 @@ | ||
var _privateField = /*#__PURE__*/new WeakMap(); | ||
var _Cl_brand = /*#__PURE__*/new WeakSet(); | ||
class Cl { | ||
constructor() { | ||
babelHelpers.classPrivateMethodInitSpec(this, _Cl_brand); | ||
babelHelpers.classPrivateFieldInitSpec(this, _privateField, "top secret string"); | ||
this.publicField = "not secret string"; | ||
} | ||
publicGetPrivateField() { | ||
return babelHelpers.classPrivateGetter(_Cl_brand, this, _get_privateFieldValue); | ||
} | ||
publicSetPrivateField(newValue) { | ||
babelHelpers.classPrivateSetter(_Cl_brand, _set_privateFieldValue, this, newValue); | ||
} | ||
} | ||
function _get_privateFieldValue(_this) { | ||
var _arguments = [].slice.call(arguments, 1); | ||
expect(_arguments.length).toBe(0); | ||
return babelHelpers.classPrivateFieldGet2(_privateField, _this); | ||
} | ||
function _set_privateFieldValue(_this2, newValue) { | ||
var _arguments2 = [].slice.call(arguments, 1); | ||
expect(_arguments2.length).toBe(1); | ||
babelHelpers.classPrivateFieldSet2(_privateField, _this2, newValue); | ||
} |