diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b4995a103f4..daebf8a930b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3002,9 +3002,14 @@ namespace ts { } function isUnParenthesizedAsyncArrowFunctionWorker(): Tristate { + // AsyncArrowFunctionExpression: + // 1) async[no LineTerminator here]AsyncArrowBindingIdentifier[?Yield][no LineTerminator here]=>AsyncConciseBody[?In] + // 2) CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await][no LineTerminator here]=>AsyncConciseBody[?In] if (token === SyntaxKind.AsyncKeyword) { nextToken(); - if (scanner.hasPrecedingLineBreak()) { + // If the "async" is followed by "=>" token then it is not a begining of an async arrow-function + // but instead a simple arrow-function which will be parsed inside "parseAssignmentExpressionOrHigher" + if (scanner.hasPrecedingLineBreak() || token === SyntaxKind.EqualsGreaterThanToken) { return Tristate.False; } // Check for un-parenthesized AsyncArrowFunction diff --git a/tests/baselines/reference/arrowFunctionWithParameterNameAsync.js b/tests/baselines/reference/arrowFunctionWithParameterNameAsync.js new file mode 100644 index 00000000000..0baea798c03 --- /dev/null +++ b/tests/baselines/reference/arrowFunctionWithParameterNameAsync.js @@ -0,0 +1,6 @@ +//// [arrowFunctionWithParameterNameAsync.ts] + +const x = async => async; + +//// [arrowFunctionWithParameterNameAsync.js] +var x = function (async) { return async; }; diff --git a/tests/baselines/reference/arrowFunctionWithParameterNameAsync.symbols b/tests/baselines/reference/arrowFunctionWithParameterNameAsync.symbols new file mode 100644 index 00000000000..26f36f48df7 --- /dev/null +++ b/tests/baselines/reference/arrowFunctionWithParameterNameAsync.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/async/es6/asyncArrowFunction/arrowFunctionWithParameterNameAsync.ts === + +const x = async => async; +>x : Symbol(x, Decl(arrowFunctionWithParameterNameAsync.ts, 1, 5)) +>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync.ts, 1, 9)) +>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync.ts, 1, 9)) + diff --git a/tests/baselines/reference/arrowFunctionWithParameterNameAsync.types b/tests/baselines/reference/arrowFunctionWithParameterNameAsync.types new file mode 100644 index 00000000000..4bdc60935ea --- /dev/null +++ b/tests/baselines/reference/arrowFunctionWithParameterNameAsync.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/async/es6/asyncArrowFunction/arrowFunctionWithParameterNameAsync.ts === + +const x = async => async; +>x : (async: any) => any +>async => async : (async: any) => any +>async : any +>async : any + diff --git a/tests/cases/conformance/async/es6/asyncArrowFunction/arrowFunctionWithParameterNameAsync.ts b/tests/cases/conformance/async/es6/asyncArrowFunction/arrowFunctionWithParameterNameAsync.ts new file mode 100644 index 00000000000..1ade02c09d2 --- /dev/null +++ b/tests/cases/conformance/async/es6/asyncArrowFunction/arrowFunctionWithParameterNameAsync.ts @@ -0,0 +1,4 @@ +// @target: ES5 +// @noEmitHelpers: true + +const x = async => async; \ No newline at end of file