New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the support of arguments
in private get/set
method
#16307
Merged
nicolo-ribaudo
merged 4 commits into
babel:feat-7.24.0/decorators
from
liuxingbaoyu:improve-this-size
Feb 27, 2024
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* @minVersion 7.24.0 */ | ||
|
||
export default function _curryThis(fn: Function) { | ||
return function (thisArg: any) { | ||
return fn.apply(thisArg, [].slice.call(arguments, 1)); | ||
}; | ||
} | ||
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
class Cl { | ||
#privateField = "top secret string"; | ||
|
||
constructor() { | ||
this.publicField = "not secret string"; | ||
} | ||
|
||
get #privateFieldValue() { | ||
expect(arguments[0]).toBeUndefined(); | ||
liuxingbaoyu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return this.#privateField; | ||
} | ||
|
||
set #privateFieldValue(newValue) { | ||
this.#privateField = arguments[0]; | ||
} | ||
|
||
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"); | ||
|
23 changes: 23 additions & 0 deletions
23
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,23 @@ | ||
class Cl { | ||
#privateField = "top secret string"; | ||
|
||
constructor() { | ||
this.publicField = "not secret string"; | ||
} | ||
|
||
get #privateFieldValue() { | ||
return this.#privateField; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
} | ||
|
||
set #privateFieldValue(newValue) { | ||
this.#privateField = arguments[0]; | ||
} | ||
|
||
publicGetPrivateField() { | ||
return this.#privateFieldValue; | ||
} | ||
|
||
publicSetPrivateField(newValue) { | ||
this.#privateFieldValue = newValue; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
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,21 @@ | ||
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) { | ||
return babelHelpers.classPrivateFieldGet2(_privateField, _this); | ||
} | ||
var _set_privateFieldValue = babelHelpers.curryThis(function _set_privateFieldValue(newValue) { | ||
babelHelpers.classPrivateFieldSet2(_privateField, this, arguments[0]); | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as outdated.
Sorry, something went wrong.