Reland "Fix: check if param is assignable when parsing arrow return type annotation" (#12183)
* Reland "Fix: check if param is assignable when parsing arrow return type annotation"
This reverts commit 91a7a64b4b.
* Mark `RestElement` as assignable
This commit is contained in:
@@ -0,0 +1 @@
|
||||
0 ? v => (v) : v => 0;
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": [
|
||||
"typescript"
|
||||
],
|
||||
"throws": "Unexpected token, expected \":\" (1:21)"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
0 ? v => (sum += v) : v => 0;
|
||||
0 ? v => (sum(v)) : v => 0;
|
||||
0 ? v => (v.w) : v => 0;
|
||||
0 ? v => ([ v.w ]) : v => {};
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["typescript"]
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":112,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":29}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":112,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":29}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":29}},
|
||||
"expression": {
|
||||
"type": "ConditionalExpression",
|
||||
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}},
|
||||
"test": {
|
||||
"type": "NumericLiteral",
|
||||
"start":0,"end":1,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":1}},
|
||||
"extra": {
|
||||
"rawValue": 0,
|
||||
"raw": "0"
|
||||
},
|
||||
"value": 0
|
||||
},
|
||||
"consequent": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":4,"end":19,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":19}},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"v"},
|
||||
"name": "v"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "AssignmentExpression",
|
||||
"start":10,"end":18,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":18}},
|
||||
"operator": "+=",
|
||||
"left": {
|
||||
"type": "Identifier",
|
||||
"start":10,"end":13,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":13},"identifierName":"sum"},
|
||||
"name": "sum"
|
||||
},
|
||||
"right": {
|
||||
"type": "Identifier",
|
||||
"start":17,"end":18,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":18},"identifierName":"v"},
|
||||
"name": "v"
|
||||
},
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 9
|
||||
}
|
||||
}
|
||||
},
|
||||
"alternate": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":22,"end":28,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":28}},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23},"identifierName":"v"},
|
||||
"name": "v"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "NumericLiteral",
|
||||
"start":27,"end":28,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":28}},
|
||||
"extra": {
|
||||
"rawValue": 0,
|
||||
"raw": "0"
|
||||
},
|
||||
"value": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":30,"end":57,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":27}},
|
||||
"expression": {
|
||||
"type": "ConditionalExpression",
|
||||
"start":30,"end":56,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":26}},
|
||||
"test": {
|
||||
"type": "NumericLiteral",
|
||||
"start":30,"end":31,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":1}},
|
||||
"extra": {
|
||||
"rawValue": 0,
|
||||
"raw": "0"
|
||||
},
|
||||
"value": 0
|
||||
},
|
||||
"consequent": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":34,"end":47,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":17}},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":34,"end":35,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":5},"identifierName":"v"},
|
||||
"name": "v"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "CallExpression",
|
||||
"start":40,"end":46,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":16}},
|
||||
"callee": {
|
||||
"type": "Identifier",
|
||||
"start":40,"end":43,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":13},"identifierName":"sum"},
|
||||
"name": "sum"
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":44,"end":45,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":15},"identifierName":"v"},
|
||||
"name": "v"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 39
|
||||
}
|
||||
}
|
||||
},
|
||||
"alternate": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":50,"end":56,"loc":{"start":{"line":2,"column":20},"end":{"line":2,"column":26}},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":50,"end":51,"loc":{"start":{"line":2,"column":20},"end":{"line":2,"column":21},"identifierName":"v"},
|
||||
"name": "v"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "NumericLiteral",
|
||||
"start":55,"end":56,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":26}},
|
||||
"extra": {
|
||||
"rawValue": 0,
|
||||
"raw": "0"
|
||||
},
|
||||
"value": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":58,"end":82,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":24}},
|
||||
"expression": {
|
||||
"type": "ConditionalExpression",
|
||||
"start":58,"end":81,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":23}},
|
||||
"test": {
|
||||
"type": "NumericLiteral",
|
||||
"start":58,"end":59,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":1}},
|
||||
"extra": {
|
||||
"rawValue": 0,
|
||||
"raw": "0"
|
||||
},
|
||||
"value": 0
|
||||
},
|
||||
"consequent": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":62,"end":72,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":14}},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":62,"end":63,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":5},"identifierName":"v"},
|
||||
"name": "v"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "MemberExpression",
|
||||
"start":68,"end":71,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":13}},
|
||||
"object": {
|
||||
"type": "Identifier",
|
||||
"start":68,"end":69,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":11},"identifierName":"v"},
|
||||
"name": "v"
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":70,"end":71,"loc":{"start":{"line":3,"column":12},"end":{"line":3,"column":13},"identifierName":"w"},
|
||||
"name": "w"
|
||||
},
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 67
|
||||
}
|
||||
}
|
||||
},
|
||||
"alternate": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":75,"end":81,"loc":{"start":{"line":3,"column":17},"end":{"line":3,"column":23}},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":75,"end":76,"loc":{"start":{"line":3,"column":17},"end":{"line":3,"column":18},"identifierName":"v"},
|
||||
"name": "v"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "NumericLiteral",
|
||||
"start":80,"end":81,"loc":{"start":{"line":3,"column":22},"end":{"line":3,"column":23}},
|
||||
"extra": {
|
||||
"rawValue": 0,
|
||||
"raw": "0"
|
||||
},
|
||||
"value": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":83,"end":112,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":29}},
|
||||
"expression": {
|
||||
"type": "ConditionalExpression",
|
||||
"start":83,"end":111,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":28}},
|
||||
"test": {
|
||||
"type": "NumericLiteral",
|
||||
"start":83,"end":84,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":1}},
|
||||
"extra": {
|
||||
"rawValue": 0,
|
||||
"raw": "0"
|
||||
},
|
||||
"value": 0
|
||||
},
|
||||
"consequent": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":87,"end":101,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":18}},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":87,"end":88,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":5},"identifierName":"v"},
|
||||
"name": "v"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "ArrayExpression",
|
||||
"start":93,"end":100,"loc":{"start":{"line":4,"column":10},"end":{"line":4,"column":17}},
|
||||
"elements": [
|
||||
{
|
||||
"type": "MemberExpression",
|
||||
"start":95,"end":98,"loc":{"start":{"line":4,"column":12},"end":{"line":4,"column":15}},
|
||||
"object": {
|
||||
"type": "Identifier",
|
||||
"start":95,"end":96,"loc":{"start":{"line":4,"column":12},"end":{"line":4,"column":13},"identifierName":"v"},
|
||||
"name": "v"
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":97,"end":98,"loc":{"start":{"line":4,"column":14},"end":{"line":4,"column":15},"identifierName":"w"},
|
||||
"name": "w"
|
||||
}
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 92
|
||||
}
|
||||
}
|
||||
},
|
||||
"alternate": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":104,"end":111,"loc":{"start":{"line":4,"column":21},"end":{"line":4,"column":28}},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":104,"end":105,"loc":{"start":{"line":4,"column":21},"end":{"line":4,"column":22},"identifierName":"v"},
|
||||
"name": "v"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":109,"end":111,"loc":{"start":{"line":4,"column":26},"end":{"line":4,"column":28}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/typescript/regression/rest-in-arrow/input.ts
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/regression/rest-in-arrow/input.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
const f = (...args): void => {};
|
||||
61
packages/babel-parser/test/fixtures/typescript/regression/rest-in-arrow/output.json
vendored
Normal file
61
packages/babel-parser/test/fixtures/typescript/regression/rest-in-arrow/output.json
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "VariableDeclaration",
|
||||
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}},
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"start":6,"end":31,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":31}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"f"},
|
||||
"name": "f"
|
||||
},
|
||||
"init": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":10,"end":31,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":31}},
|
||||
"returnType": {
|
||||
"type": "TSTypeAnnotation",
|
||||
"start":19,"end":25,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":25}},
|
||||
"typeAnnotation": {
|
||||
"type": "TSVoidKeyword",
|
||||
"start":21,"end":25,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":25}}
|
||||
}
|
||||
},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "RestElement",
|
||||
"start":11,"end":18,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":18}},
|
||||
"argument": {
|
||||
"type": "Identifier",
|
||||
"start":14,"end":18,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":18},"identifierName":"args"},
|
||||
"name": "args"
|
||||
}
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":29,"end":31,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":31}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"kind": "const"
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user