Bug 203478

Summary: Poor Async/Await Syntax Error Message
Product: WebKit Reporter: Ezekiel Elin <ezekielelin>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: NEW    
Severity: Normal CC: fpizlo, ross.kirsling, simon.fraser, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: Safari 13   
Hardware: Unspecified   
OS: Unspecified   

Ezekiel Elin
Reported 2019-10-27 19:47:38 PDT
The `await` keyword can only be used in functions marked `async.` When one tries to use it in a function not marked as such, evaluation fails with the error: function b() { const x = await "Hello"; } SyntaxError: Unexpected string literal "Hello". Expected ';' after variable declaration. This should instead say something like (copied from Firefox): SyntaxError: await is only valid in async functions and async generators The correct code is: async function b() { const x = await "Hello"; }
Attachments
Ross Kirsling
Comment 1 2019-10-28 16:07:31 PDT
That would be a more helpful error message indeed. Note that the reason for the current error message is that `await` is a valid *identifier* just when we're *not* in an async function. So this is all perfectly valid code (for web compatibility reasons): const await = "Hello"; const x = await; function f(await) { console.log(await); }
Radar WebKit Bug Importer
Comment 2 2022-04-07 13:09:27 PDT
Note You need to log in before you can comment on or make changes to this bug.