add relatedInfo to error message for 'await' used in non-async function

This commit is contained in:
uhyo 2019-05-02 01:09:29 +09:00
parent e8161efc3a
commit b0143bb446
2 changed files with 19 additions and 2 deletions

View file

@ -23087,7 +23087,20 @@ namespace ts {
// Grammar checking
if (produceDiagnostics) {
if (!(node.flags & NodeFlags.AwaitContext)) {
grammarErrorOnFirstToken(node, Diagnostics.await_expression_is_only_allowed_within_an_async_function);
// use of 'await' in non-async function
const sourceFile = getSourceFileOfNode(node);
if (!hasParseDiagnostics(sourceFile)) {
const span = getSpanOfTokenAtPosition(sourceFile, node.pos);
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length, Diagnostics.await_expression_is_only_allowed_within_an_async_function);
const func = getContainingFunction(node);
if (func) {
Debug.assert((getFunctionFlags(func) & FunctionFlags.Async) === 0, "Enclosing function should never be an async function.");
const relatedInfo = createDiagnosticForNode(func, Diagnostics.Did_you_mean_to_mark_this_function_as_async);
addRelatedInfo(diagnostic, relatedInfo);
}
diagnostics.add(diagnostic);
}
}
if (isInParameterInitializerBeforeContainingFunction(node)) {

View file

@ -1035,6 +1035,10 @@
"category": "Error",
"code": 1355
},
"Did you mean to mark this function as 'async'?": {
"category": "Error",
"code": 1356
},
"Duplicate identifier '{0}'.": {
"category": "Error",
@ -2959,7 +2963,7 @@
"category": "Error",
"code": 4104
},
"The current host does not support the '{0}' option.": {
"category": "Error",
"code": 5001