Refactor protoInit call injection#16234
Merged
nicolo-ribaudo merged 5 commits intobabel:mainfrom Jan 25, 2024
Merged
Conversation
`_initStatic` and `_initProto` are now declared before other element locals
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/56188/ |
nicolo-ribaudo
approved these changes
Jan 25, 2024
| if (initializer.node) { | ||
| expressions.push(initializer.node); | ||
| } else { | ||
| expressions.push(t.unaryExpression("void", t.numericLiteral(0))); |
Member
There was a problem hiding this comment.
It's ok to do it in a follow-up if you want to keep the fixtures diff minimal, but we can make this shorter by doing
x = expr1, void expr2instead of
x = expr1, expr2, void 0
Contributor
Author
There was a problem hiding this comment.
Good idea, I can make the change like you said. This branch is currently unreachable because the protoInit call is currently injected in the first decorated field, which will include at least a init_field call in its initializer. It is probably an oversight and I will open a new PR for that.
liuxingbaoyu
approved these changes
Jan 25, 2024
Member
|
(please don't merge right now, as the release action is running and I don't know if merging would cause problems) |
liuxingbaoyu
pushed a commit
to liuxingbaoyu/babel
that referenced
this pull request
Mar 5, 2024
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 is a refactoring PR that paves the road to implement pzuraq/ecma262#12.
Previously we are searching the first field to inject
initProto. In this PR we create afieldInitializerAssignmentsqueue, which will be prepended to the next available non-static field initializers, falling back to the class constructor. Though in this PR thefieldInitializerAssignmentscontains only theinitProtocall, it is designed to work with other assignments as well, such as the extra initializers introduced in pzuraq/ecma262#12.For example, according to the updated spec, the input
should be transformed to
as the extra initializers added by
context.addInitializers()are now run after the field is created in the receiver class.The test fixtures are updated because
protoInitand thestaticInitid are now declared before other generated identifiers. There are no behaviour changes introduced in this PR.