-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Refactor protoInit call injection
#16234
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
Refactor protoInit call injection
#16234
Conversation
`_initStatic` and `_initProto` are now declared before other element locals
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/56188/ |
| if (initializer.node) { | ||
| expressions.push(initializer.node); | ||
| } else { | ||
| expressions.push(t.unaryExpression("void", t.numericLiteral(0))); |
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.
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 0There 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.
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.
|
(please don't merge right now, as the release action is running and I don't know if merging would cause problems) |
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.