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

Commit

Permalink
Fix #336 by correctly setting arrow-param (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
danez authored Feb 10, 2017
1 parent 88d38a1 commit bc771bd
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ pp.parseCallExpressionArguments = function (close, possibleAsyncArrow) {
innerParenStart = this.state.start;
}

elts.push(this.parseExprListItem(undefined, possibleAsyncArrow ? { start: 0 } : undefined));
elts.push(this.parseExprListItem(false, possibleAsyncArrow ? { start: 0 } : undefined, possibleAsyncArrow ? { start: 0 } : undefined));
}

// we found an async arrow function so let's not allow any inner parens
Expand Down Expand Up @@ -1021,14 +1021,14 @@ pp.parseExprList = function (close, allowEmpty, refShorthandDefaultPos) {
return elts;
};

pp.parseExprListItem = function (allowEmpty, refShorthandDefaultPos) {
pp.parseExprListItem = function (allowEmpty, refShorthandDefaultPos, refNeedsArrowPos) {
let elt;
if (allowEmpty && this.match(tt.comma)) {
elt = null;
} else if (this.match(tt.ellipsis)) {
elt = this.parseSpread(refShorthandDefaultPos);
} else {
elt = this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem);
elt = this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem, refNeedsArrowPos);
}
return elt;
};
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -1087,9 +1087,9 @@ export default function (instance) {
// parse an item inside a expression list eg. `(NODE, NODE)` where NODE represents
// the position where this function is called
instance.extend("parseExprListItem", function (inner) {
return function (allowEmpty, refShorthandDefaultPos) {
return function (...args) {
const container = this.startNode();
const node = inner.call(this, allowEmpty, refShorthandDefaultPos);
const node = inner.call(this, ...args);
if (this.match(tt.colon)) {
container._exprListItem = true;
container.expression = node;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/flow/regression/issue-336/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const fn = async (a?: any): Promise<void> => {};
249 changes: 249 additions & 0 deletions test/fixtures/flow/regression/issue-336/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
{
"type": "File",
"start": 0,
"end": 48,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 48
}
},
"program": {
"type": "Program",
"start": 0,
"end": 48,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 48
}
},
"sourceType": "module",
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 48,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 48
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 6,
"end": 47,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 47
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 8
},
"identifierName": "fn"
},
"name": "fn"
},
"init": {
"type": "ArrowFunctionExpression",
"start": 11,
"end": 47,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 47
}
},
"returnType": {
"type": "TypeAnnotation",
"start": 26,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 41
}
},
"typeAnnotation": {
"type": "GenericTypeAnnotation",
"start": 28,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 41
}
},
"typeParameters": {
"type": "TypeParameterInstantiation",
"start": 35,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 35
},
"end": {
"line": 1,
"column": 41
}
},
"params": [
{
"type": "VoidTypeAnnotation",
"start": 36,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 36
},
"end": {
"line": 1,
"column": 40
}
}
}
]
},
"id": {
"type": "Identifier",
"start": 28,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 35
},
"identifierName": "Promise"
},
"name": "Promise"
}
}
},
"id": null,
"generator": false,
"expression": false,
"async": true,
"params": [
{
"type": "Identifier",
"start": 18,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 25
},
"identifierName": "a"
},
"name": "a",
"optional": true,
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 20,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 25
}
},
"typeAnnotation": {
"type": "AnyTypeAnnotation",
"start": 22,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 25
}
}
}
}
}
],
"body": {
"type": "BlockStatement",
"start": 45,
"end": 47,
"loc": {
"start": {
"line": 1,
"column": 45
},
"end": {
"line": 1,
"column": 47
}
},
"body": [],
"directives": []
}
}
}
],
"kind": "const"
}
],
"directives": []
}
}

0 comments on commit bc771bd

Please sign in to comment.