Merge pull request #57 from danez/fix-arrow-location

Fix arrow param locations with flow types
This commit is contained in:
Sebastian McKenzie
2016-08-16 15:06:19 +01:00
committed by GitHub
12 changed files with 47 additions and 74 deletions

View File

@@ -689,6 +689,17 @@ pp.flowParseTypeAnnotatableIdentifier = function (requireTypeAnnotation, canBeOp
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) {
// plain function return types: function name(): string {}
instance.extend("parseFunctionBody", function (inner) {
@@ -866,15 +877,10 @@ export default function (instance) {
};
});
function typeCastToParameter(node) {
node.expression.typeAnnotation = node.typeAnnotation;
return node.expression;
}
instance.extend("toAssignable", function (inner) {
return function (node) {
if (node.type === "TypeCastExpression") {
return typeCastToParameter(node);
return this.typeCastToParameter(node);
} else {
return inner.apply(this, arguments);
}
@@ -887,7 +893,7 @@ export default function (instance) {
for (let i = 0; i < exprList.length; i++) {
let expr = exprList[i];
if (expr && expr.type === "TypeCastExpression") {
exprList[i] = typeCastToParameter(expr);
exprList[i] = this.typeCastToParameter(expr);
}
}
return inner.call(this, exprList, isBinding);
@@ -986,7 +992,7 @@ export default function (instance) {
};
});
// parse type parameters for object method shorthand
// parse type parameters for object method shorthand
instance.extend("parseObjPropValue", function (inner) {
return function (prop) {
let typeParameters;