File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31598,7 +31598,20 @@ namespace ts {
3159831598
3159931599 if (forInOrOfStatement.kind === SyntaxKind.ForOfStatement && forInOrOfStatement.awaitModifier) {
3160031600 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;
3160231615 }
3160331616 }
3160431617
You can’t perform that action at this time.
0 commit comments