ampproject / ampproject/rollup-plugin-closure-compiler

SyntaxError: Cannot use keyword 'await' outside an async function

Open
#466 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
293
Forks
28
PR merge metrics
No merged PRs in 30d

Description

## What's the issue?
Exporting an async function with `await` keyword inside cause rollup-plugin-closure-compiler to report this error:

```
SyntaxError: Cannot use keyword 'await' outside an async function
```
## How do we reproduce the issue?
1. copy this to test folder `test/export-default/async-function.test.js`
``` js
import { generator } from '../generator';

generator('export-default', 'async-function', false, ['esm'], {stable: {}});
```
Keep everything the same as the rest of the tests, except for making `language_out` as default to avoid polyfills, which simplifies the test.

2. the test in the fixtures folder 'test/export-default/fixtures/async-function.js'
``` js
export async function asyncTest() {
await Promise.resolve('async-test');
console.log('async-test')
}

export async function asyncTestWithArgument(argument) {
await Promise.resolve('async-test-with-argument');
console.log(argument)
}
```
We'll likely need to know:
1. Your Rollup configuration.
As mentioned above, default options.
3. Error logs from your console when invoking Rollup with this plugin present.
```

Unhandled rejection in test/export-default/async-function.test.js

/workspaces/rollup-plugin-closure-compiler/node_modules/acorn/dist/acorn.js:2927

SyntaxError: Cannot use keyword 'await' outside an async function (1:21)

Parser.pp$4.raise (node_modules/acorn/dist/acorn.js:2927:15)
Parser.pp$3.checkUnreserved (node_modules/acorn/dist/acorn.js:2853:16)
Parser.pp$3.parseIdent (node_modules/acorn/dist/acorn.js:2883:12)
Parser.pp$3.parseExprAtom (node_modules/acorn/dist/acorn.js:2254:21)
Parser.pp$3.parseExprSubscripts (node_modules/acorn/dist/acorn.js:2129:21)
Parser.pp$3.parseMaybeUnary (node_modules/acorn/dist/acorn.js:2106:19)
Parser.pp$3.parseExprOps (node_modules/acorn/dist/acorn.js:2041:21)
Parser.pp$3.parseMaybeConditional (node_modules/acorn/dist/acorn.js:2024:21)
Parser.pp$3.parseMaybeAssign (node_modules/acorn/dist/acorn.js:1997:21)
Parser.pp$3.parseExpression (node_modules/acorn/dist/acorn.js:1963:21)
```

If this is a feature request you can use this section to point to a prototype/mockup that will help us understand the request.

## Additional context

Add any other context about the problem here.

Contributor guide

Open the contributing guide

Research direction

Start with the proposed test/export-default/async-function.test.js and test/export-default/fixtures/async-function.js, then inspect the existing export-default tests and generator configuration. Run the new case with language_out left at its default and compare the failure with the Acorn stack trace. Done means the async fixture is processed without the reported await syntax error and the test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, rollup
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.