Avoid unnecessary code for unused lazy imports #15449
Merged
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.
Thanks to #15446, I noticed that out released code include this:
even if that
_module()
function is then not used anywhere.Babel generates that code when there is a
import Module from "module"
import, and it's then unused because all the usages ofModule
are stripped away at build time. With this PR, we avoid injecting any code for lazy imports that are not actually used, since it's code that would never be executed at runtime anyway.As before, we continue emitting eager imports for
import "x"
since these import statements are explicitly used for side effects.I have a feeling that #15446 is caused by trying to bundle
@babel/core
with a webpack version that throws by default when trying to include some node-specific modules. That issue is not a bug with Babel, but once we merge this PR and we release a Babel version compiled with this PR (so in at least two releases), that issue will be fixed because the dead require call will be removed.