Skip to content

Commit

Permalink
Fix bug with parsing TS generic async arrow function (#9055)
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism committed Nov 21, 2018
1 parent e7f0c06 commit 4f16a12
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/babel-parser/src/plugins/typescript.js
Expand Up @@ -1299,11 +1299,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return undefined;
}

const oldInAsync = this.state.inAsync;
const oldInGenerator = this.state.inGenerator;
this.state.inAsync = true;
this.state.inGenerator = false;
res.id = null;
res.generator = false;
res.expression = true; // May be set again by parseFunctionBody.
res.async = true;
this.parseFunctionBody(res, true);
this.state.inAsync = oldInAsync;
this.state.inGenerator = oldInGenerator;
return this.finishNode(res, "ArrowFunctionExpression");
}

Expand Down
@@ -0,0 +1 @@
async <T>() => await null;
@@ -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": []
}
}

0 comments on commit 4f16a12

Please sign in to comment.