-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Feature Request: Top level await #4028
Comments
(I think this is also needed for a true WASM-ESM integration, where the loading and compiling is inherently asynchronous). https://github.com/tc39/proposal-top-level-await Without scope hoisting, this seems easy enough (just await the require call). |
For top level await while using scope hoisting, i think it'd only be possible for modules supported targets(https://github.com/babel/preset-modules) which also support top level await. Just like you said wrapping async modules would just defy scope hoisting's benefits. For this, parcel should bundle together static imports and split the others that are dynamically imported. That's pretty much it, no ? Not sure about that. |
Node now officially supports top level await nodejs/node@54746bb 🎉 |
Maybe wrapping isn't even necessary? // x.js
let v = await fetch(...);
export default "X:" + v;
// index.js
import x from "./x.js";
console.log(x); -> (async function(){
var $x$var$v = await fetch(...);
var $x$export$default = "X:" + v;
console.log($x$export$default);
})() Though I'm not sure how this should behave (or what browsers do/will do): <script type="module" src="script-with-tla.js">
<script type="module" src="script-with-tla-2.js"> |
I'm not sure what you what you mean by wrapping isn't necessary & then wrapping the scope hoisted code in a function.
Also, i tried searching for the specs that defines how scripts are executed but i couldn't really find anything so i ended up just using MDN's explanation of it.
|
Looking for this amazing feature... |
Hello, the wonderful package. Any news about this how to get the top-level await to works? |
Two big problems with that:
|
Isn't that more of a next level feature? If they aren't now there's no downside of not doing it. It would just be a possibility to further improve once TLA is possible.
Well I've never used shared bundles or require (I use import). But that's probably bad then and we users will have to continue wrapping our code into an async function ourselves :( Thx for the info tho! |
Gonna have to use good ol IIFEs then... |
Related: Detailsthe source code for c.mjs exports names: default, hi // a.mjs
import './d.mjs';
import * as c from './c.mjs';
export function getNS() {
return Object.getOwnPropertyNames(c);
}
// b.mjs
import {getNS} from './a.mjs';
console.log(getNS());
// Safari gets this right with TLA
// but V8 and SpiderMonkey incorrectly
// evaluate parents if using TLA and throwing errors
// FIXME: once V8 and SpiderMonkey allow TLA to block
// graphs correctly move to `await new Promise` to
// not fire off error alarms in devtools
throw getNS();
// await new Promise(()=>{})
// c.mjs
console.error('EVALUATING C, OH NO');
debugger;
export default 0;
export var hi;
// d.mjs
import './b.mjs'; |
No update here? |
Awesome to see this isn't supported and the error isn't saying "hey we don't supports this feature we should have had 2 years ago" |
any updates guys? |
I'm using Now I need to make an
That's because of this, right? Does parcel make the service worker not a module, even though that's specified in the manifest? Update: Actually, yes, If I just look at the bundled |
🙋 feature request
Parcel 2 could support Top Level Await.
Most bundlers/runtimes are starting to support it so it could be nice to have it in Parcel
Webpack's
experiments.topLevelAwait
experimental featureNode stable support
Node's(13.3+)--harmony-top-level-await
/--harmony_top_level_await
experimental featureDeno's native support, denoland/deno#3212
Chromium's native support, https://bugs.chromium.org/p/v8/issues/detail?id=9344. Will ship in Chrome 89
The text was updated successfully, but these errors were encountered: