closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

Support top-level await

Open AshleyScirra opened this issue 3 years ago • 2 comments

As of Safari 15, all major browsers will support top-level await. However it looks like Closure Compiler doesn't support this. (It also appears to be missing a specific flag to indicate module input or output, perhaps that is related.)

Tested with v20210601, in.js: await null;

Command line: java -jar ./compiler.jar --js in.js --js_output_file out.js

Observed result:

in.js:1:0: ERROR - [JSC_PARSE_ERROR] Parse error. 'await' used in a non-async function context
  1| await null;
     ^

1 error(s), 0 warning(s)

Expected result: allow usage of top-level await.

AshleyScirra avatar Jun 17 '21 14:06 AshleyScirra

AFAICT, changing the way modules load would require some pretty invasive changes to our broader internal JS stack, and not just the Closure compiler.

rishipal avatar Jun 18 '21 02:06 rishipal

Top level await requires either the output to be a module OR the output to have an async IIFE. We should be able to support this when the chunk type is ES_MODULE, but we need a new flag otherwise.

ChadKillingsworth avatar Jun 18 '21 11:06 ChadKillingsworth