Open jimmywarting opened 3 years ago
still want to be able to just simply import scripts in a easier way. top level await would be awesome to have
Hello, Could you please reopen this ? Thanks.
Top level await is supported in all modern browsers, could JSFiddle please be updated to remove the error indicator from the editor?
The linter is now updated, will not throw errors on async/await features.
That said, the following code will still throw an error:
const gift = await loader.loadAsync(src)
I don't know what this syntax is, never saw it before, ESLint in VSCode is also throwing an error and implying:
If anyone know a way to configure ESLint so it accepts this syntax, I'll happily take it.
@oskarkrawczyk That syntax is top level await, it's supported in all browsers since 2021 https://github.com/jsfiddle/jsfiddle-issues/issues/1674#issuecomment-1491281331. I'm confused what was fixed here, as this issue was requesting that syntax 😅
The particular screenshot I showed was using Three.js to load a glTF asset, but you can await any promise at top level
await Promise.resolve()
JSFiddle can execute this code, it just displays an error in the editor.
https://jsfiddle.net/mattrossman/78gbLzd5/1/
Note: the import
from lodash is just so that JSFiddle treats this script as type="module"
, though it would be nice if we had a better way to trigger this.
Editor | Console |
---|---|
In a fresh project VSCode doesn't have an issue:
ESLint accepts top level await when configured with ECMAScript 2022 or newer. (ESLint Playground).
However, I don't see an ESLint error in your screenshot—that looks like an error from VSCode's TypeScript language server given the ts(1308)
tag. TypeScript accepts top-level await with "module" set to ES2022 or later.
(TypeScript Playground)
Thank you for the details.
I see what the issue is - we have ESLint statically configured for type script
not module
, no matter the ECMA version.
It'll take more work to get make this dynamic. Reopening.
@mattrossman Out of curiosity, would an editor option like Treat JS as module
without the need of forcing it with an import
is something you'd be interested in?
Yes, an editor option to treat the script as a module would be great!
Ever thought about creating a iife async function so that you could use top level await?
would be cool!