Skip to content

[3.8] [BUG] TLA top-level await breaks with parenthesis #36817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
trusktr opened this issue Feb 15, 2020 · 2 comments · Fixed by #39084
Closed

[3.8] [BUG] TLA top-level await breaks with parenthesis #36817

trusktr opened this issue Feb 15, 2020 · 2 comments · Fixed by #39084
Assignees
Labels
Bug A bug in TypeScript

Comments

@trusktr
Copy link
Contributor

trusktr commented Feb 15, 2020

TypeScript Version: 3.8.1-rc

Search Terms:

Code

// works:
const DBService = await import('./DBService')
await DBService.start()

// doesn't work
await (await import('./DBService')).start()
await (1 + 1)

// works:
async function foo() {
    await (await import('./DBService')).start()
}

export {}

Expected behavior:

no error on the await word

Actual behavior:

TS thinks it is an identifier.

Playground Link:

Playground link

Related Issues:

#35276

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Feb 21, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.9.0 milestone Feb 21, 2020
@rbuckton
Copy link
Member

rbuckton commented Apr 8, 2020

This is a consequence of how we parse source files and determine whether they are a Module or a Script based on the presence or absence of import or export declarations. According to the TLA proposal, await is now treated like a keyword at the top level of a Module, but not a Script. The fact that await p (without parens) works at the top level currently is actually due to the fact we would parse it as an AwaitExpression for error reporting purposes (and still do for await in a normal function).

To address this, we will likely need to "reparse" a function call whose expression is an await and replace it with an AwaitExpression in any top-level position.

@rbuckton
Copy link
Member

rbuckton commented Apr 8, 2020

We are discussing the details necessary to make this work, but it may depend on changes to our AST Node Factory API proposed in #35282

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants