From db0705bc516ac40bbdd0e1efe72647cf69708bf9 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Tue, 23 Aug 2016 23:22:01 +0200 Subject: [PATCH] Fix issues with flow-types and async function (#95) the typeAnnotation was not correctly resolved in async functions --- src/parser/expression.js | 2 +- src/plugins/flow.js | 2 +- .../flow/regression/issue-92/actual.js | 1 + .../flow/regression/issue-92/expected.json | 204 ++++++++++++++++++ 4 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/flow/regression/issue-92/actual.js create mode 100644 test/fixtures/flow/regression/issue-92/expected.json diff --git a/src/parser/expression.js b/src/parser/expression.js index c911a97768..a520b7fe2d 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -946,7 +946,7 @@ pp.parseExprListItem = function (allowEmpty, refShorthandDefaultPos) { } else if (this.match(tt.ellipsis)) { elt = this.parseSpread(refShorthandDefaultPos); } else { - elt = this.parseMaybeAssign(false, refShorthandDefaultPos); + elt = this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem); } return elt; }; diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 5aaa38a6d3..7b4cf3616c 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -916,7 +916,7 @@ export default function (instance) { }); // parse an item inside a expression list eg. `(NODE, NODE)` where NODE represents - // the position where this function is cal;ed + // the position where this function is called instance.extend("parseExprListItem", function (inner) { return function (allowEmpty, refShorthandDefaultPos) { let container = this.startNode(); diff --git a/test/fixtures/flow/regression/issue-92/actual.js b/test/fixtures/flow/regression/issue-92/actual.js new file mode 100644 index 0000000000..8297c26102 --- /dev/null +++ b/test/fixtures/flow/regression/issue-92/actual.js @@ -0,0 +1 @@ +const a = async (foo: string = "") => {} diff --git a/test/fixtures/flow/regression/issue-92/expected.json b/test/fixtures/flow/regression/issue-92/expected.json new file mode 100644 index 0000000000..5a037f32c3 --- /dev/null +++ b/test/fixtures/flow/regression/issue-92/expected.json @@ -0,0 +1,204 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 10, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": true, + "params": [ + { + "type": "AssignmentPattern", + "start": 17, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "left": { + "type": "Identifier", + "start": 17, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "foo" + }, + "name": "foo", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 20, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 22, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 28 + } + } + } + } + }, + "right": { + "type": "StringLiteral", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "extra": { + "rawValue": "", + "raw": "\"\"" + }, + "value": "" + } + } + ], + "body": { + "type": "BlockStatement", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "body": [], + "directives": [] + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file