Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Fix issues with flow-types and async function (#95)
Browse files Browse the repository at this point in the history
the typeAnnotation was not correctly resolved in async
functions
  • Loading branch information
danez authored and hzoo committed Aug 23, 2016
1 parent 2cfae60 commit db0705b
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/flow/regression/issue-92/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const a = async (foo: string = "") => {}
204 changes: 204 additions & 0 deletions test/fixtures/flow/regression/issue-92/expected.json
Original file line number Diff line number Diff line change
@@ -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": []
}
}

0 comments on commit db0705b

Please sign in to comment.