diff --git a/packages/babel-parser/src/plugins/typescript.js b/packages/babel-parser/src/plugins/typescript.js index 49603c0cce..8970a6e4cf 100644 --- a/packages/babel-parser/src/plugins/typescript.js +++ b/packages/babel-parser/src/plugins/typescript.js @@ -1299,11 +1299,17 @@ export default (superClass: Class): Class => 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"); } diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null/input.js b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null/input.js new file mode 100644 index 0000000000..924ee33ccd --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null/input.js @@ -0,0 +1 @@ +async () => await null; diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null/output.json new file mode 100644 index 0000000000..b8ff07769c --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null/output.json @@ -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": [] + } +} \ No newline at end of file