question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow top-level await

See original GitHub issue

It 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
not-an-aardvarkcommented, Feb 19, 2019

I’d be fine with adding a parser option for this which just passes through to the acorn option.

2reactions
mysticateacommented, Feb 19, 2019

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-support

But 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found