Fix arrow param locations with flow types
This patch corrects the end locations for params in arrow functions which use type params.
This commit is contained in:
parent
f576865ce9
commit
cd987cd8e4
@ -685,6 +685,17 @@ pp.flowParseTypeAnnotatableIdentifier = function (requireTypeAnnotation, canBeOp
|
|||||||
return ident;
|
return ident;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pp.typeCastToParameter = function (node) {
|
||||||
|
node.expression.typeAnnotation = node.typeAnnotation;
|
||||||
|
|
||||||
|
return this.finishNodeAt(
|
||||||
|
node.expression,
|
||||||
|
node.expression.type,
|
||||||
|
node.typeAnnotation.end,
|
||||||
|
node.typeAnnotation.loc.end
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default function (instance) {
|
export default function (instance) {
|
||||||
// plain function return types: function name(): string {}
|
// plain function return types: function name(): string {}
|
||||||
instance.extend("parseFunctionBody", function (inner) {
|
instance.extend("parseFunctionBody", function (inner) {
|
||||||
@ -862,15 +873,10 @@ export default function (instance) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
function typeCastToParameter(node) {
|
|
||||||
node.expression.typeAnnotation = node.typeAnnotation;
|
|
||||||
return node.expression;
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.extend("toAssignable", function (inner) {
|
instance.extend("toAssignable", function (inner) {
|
||||||
return function (node) {
|
return function (node) {
|
||||||
if (node.type === "TypeCastExpression") {
|
if (node.type === "TypeCastExpression") {
|
||||||
return typeCastToParameter(node);
|
return this.typeCastToParameter(node);
|
||||||
} else {
|
} else {
|
||||||
return inner.apply(this, arguments);
|
return inner.apply(this, arguments);
|
||||||
}
|
}
|
||||||
@ -883,7 +889,7 @@ export default function (instance) {
|
|||||||
for (let i = 0; i < exprList.length; i++) {
|
for (let i = 0; i < exprList.length; i++) {
|
||||||
let expr = exprList[i];
|
let expr = exprList[i];
|
||||||
if (expr && expr.type === "TypeCastExpression") {
|
if (expr && expr.type === "TypeCastExpression") {
|
||||||
exprList[i] = typeCastToParameter(expr);
|
exprList[i] = this.typeCastToParameter(expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return inner.call(this, exprList, isBinding);
|
return inner.call(this, exprList, isBinding);
|
||||||
@ -982,7 +988,7 @@ export default function (instance) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// parse type parameters for object method shorthand
|
// parse type parameters for object method shorthand
|
||||||
instance.extend("parseObjPropValue", function (inner) {
|
instance.extend("parseObjPropValue", function (inner) {
|
||||||
return function (prop) {
|
return function (prop) {
|
||||||
let typeParameters;
|
let typeParameters;
|
||||||
|
|||||||
@ -126,7 +126,7 @@
|
|||||||
"left": {
|
"left": {
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start": 15,
|
"start": 15,
|
||||||
"end": 16,
|
"end": 24,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
@ -134,7 +134,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
"column": 16
|
"column": 24
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "y",
|
"name": "y",
|
||||||
|
|||||||
@ -109,7 +109,7 @@
|
|||||||
"left": {
|
"left": {
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start": 13,
|
"start": 13,
|
||||||
"end": 21,
|
"end": 28,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
@ -117,7 +117,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
"column": 21
|
"column": 28
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "greeting",
|
"name": "greeting",
|
||||||
|
|||||||
@ -64,7 +64,7 @@
|
|||||||
{
|
{
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start": 2,
|
"start": 2,
|
||||||
"end": 7,
|
"end": 17,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
@ -72,7 +72,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
"column": 7
|
"column": 17
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "props",
|
"name": "props",
|
||||||
|
|||||||
@ -126,7 +126,7 @@
|
|||||||
{
|
{
|
||||||
"type": "RestElement",
|
"type": "RestElement",
|
||||||
"start": 2,
|
"start": 2,
|
||||||
"end": 10,
|
"end": 20,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
@ -134,7 +134,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
"column": 10
|
"column": 20
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"argument": {
|
"argument": {
|
||||||
|
|||||||
@ -142,7 +142,7 @@
|
|||||||
{
|
{
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start": 16,
|
"start": 16,
|
||||||
"end": 24,
|
"end": 32,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
@ -150,7 +150,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
"column": 24
|
"column": 32
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "rootPath",
|
"name": "rootPath",
|
||||||
@ -188,7 +188,7 @@
|
|||||||
{
|
{
|
||||||
"type": "RestElement",
|
"type": "RestElement",
|
||||||
"start": 34,
|
"start": 34,
|
||||||
"end": 49,
|
"end": 64,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
@ -196,7 +196,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
"column": 49
|
"column": 64
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"argument": {
|
"argument": {
|
||||||
|
|||||||
@ -95,7 +95,7 @@
|
|||||||
{
|
{
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start": 17,
|
"start": 17,
|
||||||
"end": 20,
|
"end": 25,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
@ -103,7 +103,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
"column": 20
|
"column": 25
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "foo",
|
"name": "foo",
|
||||||
@ -158,7 +158,7 @@
|
|||||||
{
|
{
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start": 27,
|
"start": 27,
|
||||||
"end": 30,
|
"end": 35,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
@ -166,7 +166,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
"column": 30
|
"column": 35
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "bar",
|
"name": "bar",
|
||||||
|
|||||||
@ -63,7 +63,7 @@
|
|||||||
{
|
{
|
||||||
"type": "RestElement",
|
"type": "RestElement",
|
||||||
"start": 2,
|
"start": 2,
|
||||||
"end": 9,
|
"end": 24,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
@ -71,7 +71,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
"column": 9
|
"column": 24
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"argument": {
|
"argument": {
|
||||||
|
|||||||
@ -155,7 +155,7 @@
|
|||||||
{
|
{
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start": 13,
|
"start": 13,
|
||||||
"end": 14,
|
"end": 25,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
@ -163,7 +163,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 1,
|
"line": 1,
|
||||||
"column": 14
|
"column": 25
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "x",
|
"name": "x",
|
||||||
|
|||||||
@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "File",
|
|
||||||
"start": 0,
|
|
||||||
"end": 0,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"program": {
|
|
||||||
"type": "Program",
|
|
||||||
"start": 0,
|
|
||||||
"end": 0,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sourceType": "module",
|
|
||||||
"body": [],
|
|
||||||
"directives": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -257,7 +257,7 @@
|
|||||||
{
|
{
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start": 33,
|
"start": 33,
|
||||||
"end": 34,
|
"end": 42,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 3,
|
"line": 3,
|
||||||
@ -265,7 +265,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 3,
|
"line": 3,
|
||||||
"column": 5
|
"column": 13
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "x",
|
"name": "x",
|
||||||
@ -392,7 +392,7 @@
|
|||||||
{
|
{
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start": 56,
|
"start": 56,
|
||||||
"end": 57,
|
"end": 65,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 4,
|
"line": 4,
|
||||||
@ -400,7 +400,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 4,
|
"line": 4,
|
||||||
"column": 5
|
"column": 13
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "x",
|
"name": "x",
|
||||||
|
|||||||
@ -257,7 +257,7 @@
|
|||||||
{
|
{
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start": 33,
|
"start": 33,
|
||||||
"end": 34,
|
"end": 42,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 3,
|
"line": 3,
|
||||||
@ -265,7 +265,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 3,
|
"line": 3,
|
||||||
"column": 5
|
"column": 13
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "x",
|
"name": "x",
|
||||||
@ -392,7 +392,7 @@
|
|||||||
{
|
{
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start": 56,
|
"start": 56,
|
||||||
"end": 57,
|
"end": 65,
|
||||||
"loc": {
|
"loc": {
|
||||||
"start": {
|
"start": {
|
||||||
"line": 4,
|
"line": 4,
|
||||||
@ -400,7 +400,7 @@
|
|||||||
},
|
},
|
||||||
"end": {
|
"end": {
|
||||||
"line": 4,
|
"line": 4,
|
||||||
"column": 5
|
"column": 13
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "x",
|
"name": "x",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user