File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -31598,7 +31598,20 @@ namespace ts {
31598
31598
31599
31599
if (forInOrOfStatement.kind === SyntaxKind.ForOfStatement && forInOrOfStatement.awaitModifier) {
31600
31600
if ((forInOrOfStatement.flags & NodeFlags.AwaitContext) === NodeFlags.None) {
31601
- return grammarErrorOnNode(forInOrOfStatement.awaitModifier, Diagnostics.A_for_await_of_statement_is_only_allowed_within_an_async_function_or_async_generator);
31601
+ // use of 'for-await-of' in non-async function
31602
+ const sourceFile = getSourceFileOfNode(forInOrOfStatement);
31603
+ if (!hasParseDiagnostics(sourceFile)) {
31604
+ const diagnostic = createDiagnosticForNode(forInOrOfStatement.awaitModifier, Diagnostics.A_for_await_of_statement_is_only_allowed_within_an_async_function_or_async_generator);
31605
+ const func = getContainingFunction(forInOrOfStatement);
31606
+ if (func) {
31607
+ Debug.assert((getFunctionFlags(func) & FunctionFlags.Async) === 0, "Enclosing function should never be an async function.");
31608
+ const relatedInfo = createDiagnosticForNode(func, Diagnostics.Did_you_mean_to_mark_this_function_as_async);
31609
+ addRelatedInfo(diagnostic, relatedInfo);
31610
+ }
31611
+ diagnostics.add(diagnostic);
31612
+ return true;
31613
+ }
31614
+ return false;
31602
31615
}
31603
31616
}
31604
31617
You can’t perform that action at this time.
0 commit comments