Skip to content

Commit

Permalink
Parse arrows with params annotations in conditional expressions (#10669)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 6, 2019
1 parent bdb4318 commit 9082e68
Show file tree
Hide file tree
Showing 5 changed files with 476 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/babel-parser/src/plugins/flow.js
Expand Up @@ -2061,6 +2061,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return node.operator === "=";

case "ParenthesizedExpression":
case "TypeCastExpression":
return this.isAssignable(node.expression);

case "MemberExpression":
Expand Down
@@ -0,0 +1,2 @@
test
? (x: T): U => y
@@ -0,0 +1,220 @@
{
"type": "File",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 18
}
},
"program": {
"type": "Program",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 18
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 18
}
},
"expression": {
"type": "ConditionalExpression",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 18
}
},
"test": {
"type": "Identifier",
"start": 0,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "test"
},
"name": "test"
},
"consequent": {
"type": "TypeCastExpression",
"start": 10,
"end": 14,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 9
}
},
"expression": {
"type": "Identifier",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 6
},
"identifierName": "x"
},
"name": "x"
},
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 11,
"end": 14,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 9
}
},
"typeAnnotation": {
"type": "GenericTypeAnnotation",
"start": 13,
"end": 14,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 9
}
},
"typeParameters": null,
"id": {
"type": "Identifier",
"start": 13,
"end": 14,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 9
},
"identifierName": "T"
},
"name": "T"
}
}
},
"extra": {
"parenthesized": true,
"parenStart": 9
}
},
"alternate": {
"type": "ArrowFunctionExpression",
"start": 17,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 18
}
},
"id": null,
"generator": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 17,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 13
},
"identifierName": "U"
},
"name": "U"
}
],
"body": {
"type": "Identifier",
"start": 22,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 2,
"column": 18
},
"identifierName": "y"
},
"name": "y"
}
}
}
}
],
"directives": []
}
}
@@ -0,0 +1,3 @@
test
? (x: T): U => y
: z

0 comments on commit 9082e68

Please sign in to comment.