Skip to content

Commit bbbb56b

Browse files
committed
Allow async as parameter in arrowfunction (#8488)
* Allow async as a parameter name in simple arrow function * Add tests
1 parent 85ab935 commit bbbb56b

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

src/compiler/parser.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3002,9 +3002,14 @@ namespace ts {
30023002
}
30033003

30043004
function isUnParenthesizedAsyncArrowFunctionWorker(): Tristate {
3005+
// AsyncArrowFunctionExpression:
3006+
// 1) async[no LineTerminator here]AsyncArrowBindingIdentifier[?Yield][no LineTerminator here]=>AsyncConciseBody[?In]
3007+
// 2) CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await][no LineTerminator here]=>AsyncConciseBody[?In]
30053008
if (token === SyntaxKind.AsyncKeyword) {
30063009
nextToken();
3007-
if (scanner.hasPrecedingLineBreak()) {
3010+
// If the "async" is followed by "=>" token then it is not a begining of an async arrow-function
3011+
// but instead a simple arrow-function which will be parsed inside "parseAssignmentExpressionOrHigher"
3012+
if (scanner.hasPrecedingLineBreak() || token === SyntaxKind.EqualsGreaterThanToken) {
30083013
return Tristate.False;
30093014
}
30103015
// Check for un-parenthesized AsyncArrowFunction
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [arrowFunctionWithParameterNameAsync.ts]
2+
3+
const x = async => async;
4+
5+
//// [arrowFunctionWithParameterNameAsync.js]
6+
var x = function (async) { return async; };
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/conformance/async/es6/asyncArrowFunction/arrowFunctionWithParameterNameAsync.ts ===
2+
3+
const x = async => async;
4+
>x : Symbol(x, Decl(arrowFunctionWithParameterNameAsync.ts, 1, 5))
5+
>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync.ts, 1, 9))
6+
>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync.ts, 1, 9))
7+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/conformance/async/es6/asyncArrowFunction/arrowFunctionWithParameterNameAsync.ts ===
2+
3+
const x = async => async;
4+
>x : (async: any) => any
5+
>async => async : (async: any) => any
6+
>async : any
7+
>async : any
8+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @target: ES5
2+
// @noEmitHelpers: true
3+
4+
const x = async => async;

0 commit comments

Comments
 (0)