-
Notifications
You must be signed in to change notification settings - Fork 45
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
Peeling out import() #149
Comments
I'm just coming in from nodejs/node-eps#39 - are we talking about defining a EDIT: Taking another look at the spec, I guess |
@stuartpb keyword as a function, not a global. [wrt import.context] I have been investigating something like |
What am I missing? How are a script and a module distinguished from each other? Can I see an example? +1 otherwise. |
@concavelenz they're different parsing goals. it's detailed in the spec. |
@ljharb Yes, they are different parse goal which means you need to say which you intend. As the standard is now, any valid strict mode script is a valid module. So I'm asking is how do you state which you mean? |
At the moment, you communicate that out-of-band. |
@ljharb Exactly. So what is the proposal here? |
The OP is the proposal. What is unclear about it? Your confusion about how you distinguish scripts and modules seems unrelated to the OP. |
https://whatwg.github.io/loader/#loader-import ~= the thing being pulled out |
@domenic in principle, I'm supportive of this, but I will like to dig in more on the idea of enabling Additionally, how will this play with the other effort that we (@benjamn and I) will be presenting (hopefully) for the |
The behavior of importing differs pretty drastically between require and what browsers are aiming for:
I don't really have any clue on the spec for |
I'm not confused about how to distinguish between scripts or modules. I simply misread: "import() works in both scripts and modules" as "import() works for both scripts and modules" and didn't see that was described in the steps. |
@caridy great! You can indeed work around these issues somewhat in browsers, using something like https://gist.github.com/domenic/fd84ee5f4e2dc0278ab1#file-import-module-current-js. However, it uses a URL instead of a module specifier, and will be relative to the document's URL instead of the script's URL. (In addition to it being super-ugly, modifying the DOM and creating a global temporary variable.) I think giving people a first-class solution would make a lot more sense, especially since there really is no cost to doing so. You mentioned concerns about changing HostResolveImportedModule, but as I outlined in the OP, I don't think the changes are really that invasive, and would not affect the module loading path at all. All existing parts of the pipeline would not call it with a first argument that's a script, and any environment which wants to not support scripts with this feature would just need to add some kind of "If currentScriptOrModule is a Script Record, throw a TypeError" line to their HostResolveImportedModule. I'm happy to dive in to any mor edetailed concerns you might have. I don't understand |
I've put together a proposal at https://github.com/domenic/proposal-import-function where the readme explains some of the things we discussed, @caridy. The spec is relatively complete, too: https://domenic.github.io/proposal-import-function/. Looking forward to working with you all on this! |
Now that the proposal has its own issue tracker, should this issue be closed? |
Hi all,
We're getting lots of interest from multiple corners in providing a way to add async loading to the module support specced for browsers. I was wondering if it'd be OK if I started work on a TC39-side import() spec? It would absorb some of the responsibilities of this repo, so I wanted to check here first.
The basic ideas I have so far:
import("./specifier.js")
returns a promise for a module namespace objectI think this would be a pretty small spec. It would, of course, have room for expansion in the future to support all the loader hooks, e.g. Loader could define a HostFetchModule for host environments that implement the Loader spec that goes through all the hooks, similar to what it does with HostResolveImportedModule today. But in the meantime it would give browsers and Node something they could implement.
Let me know what you think! If you're OK with me taking on this effort, I'd plan to have some spec text ready in time for the next TC39.
/cc @bmeck
The text was updated successfully, but these errors were encountered: