Allow top-level await
See original GitHub issueIt seems like top-level await
expressions are not allowed:
> espree.parse('await true')
Thrown:
{ [SyntaxError: Unexpected token true
] index: 6, lineNumber: 1, column: 7 }
Should they be enabled? One reason could be that there is a proposal for top-level await
.
But actually my use case is when using ESLint inside Markdown files with eslint-plugin-markdown
. Documentations might contain one liners that miss the context (i.e. the async
function keyword) in order to be shorter.
For example let’s say I have a module dummy
that returns a promise. I might want to document it like this:
`dummy` returns a promise and take an options object as argument:
```js
const returnValue = await dummy(options)
```
Acorn has a allowAwaitOutsideFunction
option that does this.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:18 (10 by maintainers)
Top Results From Across the Web
javascript - How can I use async/await at the top level?
when a module using top-level await is evaluated, it returns a promise to the module loader (like an async function does), which waits...
Read more >Top-level await is available in Node.js modules - Stefan Judis
The await keyword allows you to untangle Promises-based code, avoid chained then calls and make source code more readable. // promise-based code ...
Read more >ECMAScript: Top-level await | Saeloun Blog
Top -level await enables modules to act as big async functions. With top-level await, ECMAScript Modules (ESM) can await resources.
Read more >await - JavaScript - MDN Web Docs
Top level await ... You can use the await keyword on its own (outside of an async function) at the top level of...
Read more >Top-level await - V8 JavaScript engine
Top -level await enables developers to use the await keyword outside of async functions. It acts like a big async function causing other ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’d be fine with adding a parser option for this which just passes through to the
acorn
option.Thank you for this issue.
As
README.md
described, we support only stage 4 syntax in general: https://github.com/eslint/espree#how-do-you-determine-which-experimental-features-to-supportBut Markdown use case sounds reasonable to me, and we don’t need any acorn plugins to implement this.
For now, I guess you can use
babel-eslint
.