Bug 217299

Summary: await expression breaks some surrounding expressions
Product: WebKit Reporter: thatcomputerguy0101
Component: Web InspectorAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: ashvayka, fpizlo, inspector-bugzilla-changes, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: Safari Technology Preview   
Hardware: Mac   
OS: macOS 10.15   

Description thatcomputerguy0101 2020-10-04 15:01:45 PDT
The `await` operator is not treated like a standard operator, since it breaks whenever used in several expression contexts.

The following two constructs are both broken by this bug, and I expect a few more to be as well:
let {property} = await asyncFunction() // results in SyntaxError: Unexpected identifier 'asyncFunction'. Expected ';' after variable declaration.
const result = await asyncFunction() // results in SyntaxError: Unexpected token ';'. const declared variable 'result' must have an initializer.

I expect this happens because the await operator tries to take some sort of assignment shortcut. The `await` operator is supposed to be just another operator (that happens to take an undefined duration), so it shouldn't matter where it is used. In Chrome, both of the above will work without errors (when run in the appropriate context).
Comment 1 thatcomputerguy0101 2020-10-04 15:03:20 PDT
Additionally, I believe Bug 203478 stems from this problem.
Comment 2 thatcomputerguy0101 2020-10-04 16:07:36 PDT
I have to correct myself. This only occurs in contexts that are expected to be syncronous. However, it does occur when evaluating a console expression, which makes more sense to be async-compatible.
Comment 3 Radar WebKit Bug Importer 2020-10-05 17:25:00 PDT
<rdar://problem/69978159>
Comment 4 Yusuke Suzuki 2021-02-01 02:23:59 PST
ECMAScript "await" needs to be used inside async function. I think the example code is used in normal code, and the error should occur since this is not async function.
Comment 5 thatcomputerguy0101 2021-02-01 06:41:56 PST
Beyond the poor error message, the only problem here is that the Javascript debug console is partially async compatible, with expressions like the standard `var result = await asyncFunction()` working just fine and more complicated expressions like the ones listed in my original post do not. This does not affect their compatibility in a regular async environment, only in the debug console. Additionally, the following is another syntax form affected by this bug:

var result = await (asyncFunction()) // results in ReferenceError: Can't find variable: await
Comment 6 Yusuke Suzuki 2021-02-01 10:31:10 PST
var result = await (asyncFunction()) // results in ReferenceError: Can't find variable: await

This is correct since, inside normal function, this syntax is fine. "await" is not a keyword (it is contextual keyword). So if it is used in a normal function, then, it is possible that this is variable reference.

You can write the following.

function await() { }
var result = await(30);
Comment 7 Yusuke Suzuki 2021-02-01 10:33:03 PST
I think this is related to Web Inspector's console's priority on whether we should parse the given code as async code or not. Sending it to Web Inspector category.