Create @babel/plugin-proposal-dynamic-import#9552
Create @babel/plugin-proposal-dynamic-import#9552nicolo-ribaudo merged 5 commits intobabel:masterfrom
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10974/ |
223c1c3 to
33ba9d9
Compare
5d543c1 to
3a1c335
Compare
|
|
||
| // TODO: expose a better interface | ||
| const transformImportCall = Function.call.bind( | ||
| babelPluginDynamicImportNode(api).visitor.Import, |
There was a problem hiding this comment.
Please ignore the ugliness of this line. If this PR gets approved, I will open a PR in the babel-plugin-dynamic-import-node repo to directly export the transformImportCall function.
|
As we did for ESM, we should force to preserve the import function when using Babel loader in webpack (once it's in babel/preset-env). |
| define(["require"], function (_require) { | ||
| "use strict"; | ||
|
|
||
| var modP = new Promise(_resolve => _require(["mod"], imported => _resolve(babelHelpers.interopRequireWildcard(imported)))); |
There was a problem hiding this comment.
Is there any case where AMD will synchronously execute "mod" if the code for "mod" is already cached, or is it always async?
If so, the AMD require needs to be moved to a .then to ensure evaluation is asynchronous.
There was a problem hiding this comment.
I checked the require source, and apparentely the callback is always called after a context.nextTick:
https://github.com/requirejs/requirejs/blob/fdf4186d3e68df06a04bd71cb6ea0f24eb1600d1/require.js#L1460
It is always guaranteed to be async: requirejs/requirejs#738 (comment)
Reading RequireJS's source code made me realize that it can also generate an error.
| const MISSING_PLUGIN_WARNING = `\ | ||
| WARNING: Dynamic import() transformation must be enabled using the | ||
| @babel/plugin-proposal-dynamic-import plugin. As of Babel 8, | ||
| without that plugin it won't be transformed. |
There was a problem hiding this comment.
"Babel 8 will no longer transform import() without using that plugin."
3a1c335 to
97b0ac4
Compare
Do not duplicate code, which will unavoidably lead to bugs being fixed in one plugin and not in the other.
97b0ac4 to
ab64e93
Compare
|
Updated to use airbnb/babel-plugin-dynamic-import-node#75 |
This is an implementation of what I proposed in #9551. I had two goals:
Note: sysntemjs was already supported and enabled by default, but this PR merged it's entry point with the one for commonjs/amd.
#4986 is similar, but it only implements CommonJS support and introduces a
spec: truemode for commonjs, using different helpers.