-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Do not define access.get
for public setter decorators
#16265
Merged
nicolo-ribaudo
merged 2 commits into
babel:feat-7.24.0/decorators
from
nicolo-ribaudo:no-get-setter-context
Feb 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,7 +200,14 @@ export default /* @no-mangle */ function applyDecs2311( | |
var symbolMetadata = Symbol.metadata || Symbol.for("Symbol.metadata"); | ||
var defineProperty = Object.defineProperty; | ||
var metadata: any; | ||
var existingNonFields: Record<string, number> = {}; | ||
// Use both as and satisfies to ensure that we only use non-zero values | ||
var existingNonFields = { __proto__: null } as Record< | ||
string, | ||
1 | 3 | 4 | ||
> satisfies Record< | ||
string, | ||
PROP_KIND.ACCESSOR | PROP_KIND.GETTER | PROP_KIND.SETTER | ||
>; | ||
var hasClassDecs = classDecs.length; | ||
// This is a temporary variable for smaller helper size | ||
var _: any; | ||
|
@@ -269,21 +276,6 @@ export default /* @no-mangle */ function applyDecs2311( | |
var isSetter = kind === PROP_KIND.SETTER; | ||
var isMethod = kind === PROP_KIND.METHOD; | ||
|
||
function markExistingNonField(hasSetter?: 1) { | ||
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. This function is now only called once, so I inlined it where it's used. |
||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
if (!i && !isField && !isPrivate) { | ||
if (existingNonFields[mapKey + hasSetter]) { | ||
throw new Error( | ||
"Decorating two elements with the same name (" + | ||
name + | ||
") is not supported yet", | ||
); | ||
} | ||
|
||
existingNonFields[mapKey + hasSetter] = 1; | ||
} | ||
} | ||
|
||
function _bindPropCall(name: keyof PropertyDescriptor, before?: Function) { | ||
return function (_this: any, value?: any) { | ||
if (before) { | ||
|
@@ -377,8 +369,30 @@ export default /* @no-mangle */ function applyDecs2311( | |
}, | ||
}; | ||
|
||
if (!i && !isField && !isPrivate) { | ||
var flag = existingNonFields[mapKey]; | ||
if (flag) { | ||
if ((flag ^ kind) === 7) { | ||
// flag is 1, 3, or 4; kind is 0, 1, 2, 3, or 4 | ||
// flag ^ kind is 7 if and only if one of them is 3 and the other one is 4. | ||
existingNonFields[mapKey] = PROP_KIND.ACCESSOR; | ||
} else { | ||
throw new Error( | ||
"Decorating two elements with the same name (" + | ||
name + | ||
") is not supported yet", | ||
); | ||
} | ||
} else { | ||
// We use PROP_KIND.ACCESSOR to mark a name as "fully used": | ||
// either a get/set pair, or a non-getter/setter. | ||
existingNonFields[mapKey] = | ||
kind > PROP_KIND.METHOD | ||
? (kind as PROP_KIND.GETTER | PROP_KIND.SETTER) | ||
: PROP_KIND.ACCESSOR; | ||
} | ||
} | ||
if (!isSetter) { | ||
markExistingNonField(); | ||
_.get = isPrivate | ||
? isMethod | ||
? function (_this: any) { | ||
|
@@ -390,8 +404,7 @@ export default /* @no-mangle */ function applyDecs2311( | |
return target[name]; | ||
}; | ||
} | ||
if (!isGetter) { | ||
markExistingNonField(1); | ||
if (kind < PROP_KIND.METHOD || isSetter) { | ||
_.set = isPrivate | ||
? _bindPropCall("set", assertInstanceIfPrivate) | ||
: function (target: any, v: any) { | ||
|
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: Commenting on Line 273
mapKey = name + "/" + isStatic;
:It doesn't work when the computed key is a symbol. In the following example, Babel throws "Cannot convert a Symbol value to a string":
we can fix that in a new PR.