/rfc-js-async-pragma-top-level-await

A proposal for JS `async` pragma for top-level `await`.

MIT LicenseMIT

rfc-js-async-scripts

In order to use await, you need to be inside an async function.

For scripting purposes, or at the top-level scope of a file, this is cumbersome:

(async () => {
  const foo = await bar()
  
  // ...
})()

JavaScript should support making a whole file async by default, either as a pragma comment, like // @flow:

// @async

const foo = await bar()

// ...

or a directive prologue, like 'use strict';:

'async';

const foo = await bar()

// ...

or even a keyword:

async;

const foo = await bar()

// ...

May be possible to implement as a Babel transform plugin.