Bug 203478
| Summary: | Poor Async/Await Syntax Error Message | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Ezekiel Elin <ezekielelin> |
| Component: | JavaScriptCore | Assignee: | 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
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 | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Ross Kirsling
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
<rdar://problem/91439731>