-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
[experiment] implement tc39 Defer Module Evaluation #16567
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
base: main
Are you sure you want to change the base?
Conversation
Yeah, we can implement this under the |
For maintainers only:
|
7420ab0
to
32408f7
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Just update snaphots (
|
Is it locally? |
This comment was marked as resolved.
This comment was marked as resolved.
@Jack-Works Sounds like a bug in jest... do you use the same steps as in our CI file? Based on CI report you just need to update snapshot, no more |
Can you update |
This comment was marked as resolved.
This comment was marked as resolved.
@Jack-Works What is node version? You can try to change, also just check you have the same versions as in the lock file |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Weird, I don't have problem with jest locally... Okay, we can try to update jest (maybe new versions resolve this problem) Also can you use |
This comment was marked as resolved.
This comment was marked as resolved.
I tried to add some test cases (6041d87) but it seems like does not work... Did I do right? |
You can use virtual machine here 😄 |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
9161b0f
to
5250fd6
Compare
I have updated the doc, added the following content: I suggest putting the magic comment after the Please do not put it after the "import" keyword (like ESBuild is not compatible, please read evanw/esbuild#1439 and evanw/esbuild#309. Esbuild may support this feature ad-hoc like other webpack magic comments. |
46a4bd2
to
5ceff95
Compare
This comment was marked as resolved.
This comment was marked as resolved.
25760b8
to
d69c016
Compare
hi @alexander-akait @nicolo-ribaudo this is ready for review |
/cc @nicolo-ribaudo Can you take a look, you have more experience with this, an extra look never hurts, thank you |
if (exportName.length > 0 && exportName[0] === "default") { | ||
if (defer && exportsType !== "namespace") { |
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.
Is this for the removed export defer *
case, or is it for import defer * as ns; export { ns }
?
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.
As far as I can recall, it is use when you import (not export) a CommonJS module (exportsType !== namespace
)
runtime, | ||
runtimeTemplate, | ||
runtimeRequirements | ||
) { | ||
const importedModule = /** @type {Module} */ (moduleGraph.getModule(dep)); | ||
const importVar = dep.getImportVar(moduleGraph); | ||
|
||
if ( | ||
(mode.type === "reexport-namespace-object" || |
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.
Same question for this
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 for import defer * as ns from '...'; export { ns }
.
bd56317
to
721d60e
Compare
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 went through this one more time, and it looks good. Just a few questions/highlights that maybe should be answered by @alexander-akait:
- I see that
acorn-import-defer
is an optional peer dependency. When Webpack implemented import attributes,acorn-import-assertions
was added as a normal dependency, so that the syntax would be available to all users. Should we do something similar here? - Should we support the comment, even now that we support the syntax? Prettier already supports this syntax, and it will hopefully be included in the next minor release of TypeScript.
- Does webpack have a way to run test262 tests? There are a bunch of them for import defer at https://github.com/tc39/test262/tree/main/test/language/import/import-defer
Yes we need to move it to dependencies
I think it's a question of syntax, if we are sure that it won't change we can avoid comment syntax (hope we will not repeat Anyway it is experiment, so we can introduce comment syntax later
Good question, we have some parts of tests, but not all, I'll mark this as a task for myself |
@Jack-Works Thank you for this great work, can you make rebase, I think we will merge it for the next minor release |
bc3f543
to
a707099
Compare
Co-authored-by: Nicolo Ribaudo <hello@nicr.dev>
Can you provide feedback on this? Maybe we miss something to serialize? What error do you have? |
If the comment is put after |
Not sure why Github Actions / integration (ubuntu-latest, 10.x, b) (pull_request) and Github Actions / integration (windows-latest, 10.x, b) (pull_request) fails with |
Does this PR introduce a breaking change?
no?
What needs to be documented once your changes are merged?
Defer import
This implements the semantics of the TC39 proposal Deferring Module Evaluation.
New options:
experiments.deferImport: true
To use the native syntax, install
acorn-import-defer
as a peer dependency.Result:
Other things to notice
Alternative syntax
can be written as
I suggest putting the magic comment after the
from
keyword, which is compatible with TypeScript, Babel, SWC, and Flow if the necessary option to preserve comments is enabled.Please do not put it after the "import" keyword (like
import /* webpackDefer: true */ * as ns from './mod.mjs'
), the filesystem cache is broken, and I don't know why.ESBuild is not compatible, please read evanw/esbuild#1439 and evanw/esbuild#309. Esbuild may support this feature ad-hoc like other webpack magic comments.