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
Compile static blocks without the intermediate priv field step #13297
Conversation
// we are sure that static blocks have already been transformed regarless of the | ||
// plugins order in the user config. | ||
path.traverse({ | ||
Class(path: NodePath<Class>) { |
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.
This is just indented
8294b8c
to
a6cda9a
Compare
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/46001/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 6a7ab1b:
|
Traversing the whole program to transform static block can be slow. And what if in the future we decide to compile some feature to Static Block? Can we apply the class transform on Another thought may be introducing |
@JLHwung That would cause problems, because the |
I solved this in another way, that also makes the generated code smaller when compiling both static blocks and class fields. Technically it's a new feature for the internal
|
Foo.foo = (_temp2 = _class2 = class {}, (() => { | ||
_class2.bar = 42; | ||
})(), _temp2).bar; |
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.
I think this is a bug (the super class is evaluated twice), but the bug was present also before this PR.
static-blocks
plugin
Consider this config:
Until Babel 7.14.0, this was fine: the
proposal-class-static-block
was enabled before the other class features plugins, so that it could compile static blocks to private fields.However, starting from Babel 7.14.0
@babel/preset-env
automatically enabled the class fields and private methods plugins: the new effective order isThis breaks, because the
proposal-class-properties
plugin runs beforeproposal-class-static-block
(and the only way to workaround it is to change the presets order in the user config).We can avoid this problem by transforming static blocks in
Program:enter
: it's safe, because the transform is quite self-contained so it doesn't cause problem if there are some proposals between the program node and the class node.Regardless of the behavior change introduced in 7.14.0, this is something that makes it easier to configure Babel since it's one less thing our users have to worry about.
I hope to properly solve this problem with something like #13260.