Fix #336 by correctly setting arrow-param (#337)

This commit is contained in:
Daniel Tschinder 2017-02-10 15:01:39 +01:00 committed by GitHub
parent 88d38a1abb
commit bc771bd0f9
4 changed files with 255 additions and 5 deletions

View File

@ -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
@ -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;
};

View File

@ -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;

View File

@ -0,0 +1 @@
const fn = async (a?: any): Promise<void> => {};

View File

@ -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": []
}
}