Fix bug with parsing TS generic async arrow function (#9055)

This commit is contained in:
Brian Ng 2018-11-21 15:34:09 -06:00 committed by GitHub
parent e7f0c065cf
commit 4f16a12c03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 140 additions and 0 deletions

View File

@ -1299,11 +1299,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return undefined; return undefined;
} }
const oldInAsync = this.state.inAsync;
const oldInGenerator = this.state.inGenerator;
this.state.inAsync = true;
this.state.inGenerator = false;
res.id = null; res.id = null;
res.generator = false; res.generator = false;
res.expression = true; // May be set again by parseFunctionBody. res.expression = true; // May be set again by parseFunctionBody.
res.async = true; res.async = true;
this.parseFunctionBody(res, true); this.parseFunctionBody(res, true);
this.state.inAsync = oldInAsync;
this.state.inGenerator = oldInGenerator;
return this.finishNode(res, "ArrowFunctionExpression"); return this.finishNode(res, "ArrowFunctionExpression");
} }

View File

@ -0,0 +1 @@
async <T>() => await null;

View File

@ -0,0 +1,133 @@
{
"type": "File",
"start": 0,
"end": 26,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 26
}
},
"program": {
"type": "Program",
"start": 0,
"end": 26,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 26
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 26,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 26
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
},
"typeParameters": {
"type": "TSTypeParameterDeclaration",
"start": 6,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 9
}
},
"params": [
{
"type": "TSTypeParameter",
"start": 7,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
}
},
"name": "T"
}
]
},
"params": [],
"id": null,
"generator": false,
"expression": true,
"async": true,
"body": {
"type": "AwaitExpression",
"start": 15,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 25
}
},
"argument": {
"type": "NullLiteral",
"start": 21,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 25
}
}
}
}
}
}
],
"directives": []
}
}