Update tsep and apply breaking changes (#3455)

master
James Henry 2017-12-12 03:20:54 +00:00 committed by Lucas Duailibe
parent 76c5d91ce6
commit dc91108453
5 changed files with 32 additions and 20 deletions

View File

@ -50,7 +50,7 @@
"semver": "5.4.1",
"string-width": "2.1.1",
"typescript": "2.6.2",
"typescript-eslint-parser": "9.0.1",
"typescript-eslint-parser": "10.0.0",
"unicode-regex": "1.0.1",
"unified": "6.1.6"
},

View File

@ -179,7 +179,7 @@ function massageAST(ast, parent) {
// (TypeScript) bypass TSParenthesizedType
if (
ast.type === "TSParenthesizedType" &&
ast.typeAnnotation.type === "TypeAnnotation"
ast.typeAnnotation.type === "TSTypeAnnotation"
) {
return newObj.typeAnnotation.typeAnnotation;
}

View File

@ -373,12 +373,13 @@ FastPath.prototype.needsParens = function(options) {
case "TSParenthesizedType": {
const grandParent = this.getParentNode(1);
if (
(parent.type === "TypeParameter" ||
(parent.type === "TSTypeParameter" ||
parent.type === "TypeParameter" ||
parent.type === "VariableDeclarator" ||
parent.type === "TypeAnnotation" ||
parent.type === "TSTypeAnnotation" ||
parent.type === "GenericTypeAnnotation" ||
parent.type === "TSTypeReference") &&
(node.typeAnnotation.type === "TypeAnnotation" &&
(node.typeAnnotation.type === "TSTypeAnnotation" &&
node.typeAnnotation.typeAnnotation.type !== "TSFunctionType" &&
grandParent.type !== "TSTypeOperator")
) {

View File

@ -2033,6 +2033,7 @@ function genericPrintNoParens(path, options, print, args) {
// Type Annotations for Facebook Flow, typically stripped out or
// transformed away before printing.
case "TypeAnnotation":
case "TSTypeAnnotation":
if (n.typeAnnotation) {
return path.call(print, "typeAnnotation");
}
@ -2160,7 +2161,9 @@ function genericPrintNoParens(path, options, print, args) {
);
let needsColon =
isArrowFunctionTypeAnnotation && parent.type === "TypeAnnotation";
isArrowFunctionTypeAnnotation &&
(parent.type === "TypeAnnotation" ||
parent.type === "TSTypeAnnotation");
// Sadly we can't put it inside of FastPath::needsColon because we are
// printing ":" as part of the expression and it would put parenthesis
@ -2168,7 +2171,8 @@ function genericPrintNoParens(path, options, print, args) {
const needsParens =
needsColon &&
isArrowFunctionTypeAnnotation &&
parent.type === "TypeAnnotation" &&
(parent.type === "TypeAnnotation" ||
parent.type === "TSTypeAnnotation") &&
parentParent.type === "ArrowFunctionExpression";
if (isObjectTypePropertyAFunction(parent)) {
@ -2295,6 +2299,7 @@ function genericPrintNoParens(path, options, print, args) {
// If there's a leading comment, the parent is doing the indentation
const shouldIndent =
parent.type !== "TypeParameterInstantiation" &&
parent.type !== "TSTypeParameterInstantiation" &&
parent.type !== "GenericTypeAnnotation" &&
parent.type !== "TSTypeReference" &&
parent.type !== "FunctionTypeParam" &&
@ -2452,8 +2457,21 @@ function genericPrintNoParens(path, options, print, args) {
]);
case "TypeParameterDeclaration":
case "TypeParameterInstantiation":
case "TSTypeParameterDeclaration":
case "TSTypeParameterInstantiation":
return printTypeParameters(path, options, print, "params");
case "TSTypeParameter":
case "TypeParameter": {
const parent = path.getParentNode();
if (parent.type === "TSMappedType") {
parts.push(path.call(print, "name"));
if (n.constraint) {
parts.push(" in ", path.call(print, "constraint"));
}
return concat(parts);
}
const variance = getFlowVariance(n);
if (variance) {
@ -2683,14 +2701,6 @@ function genericPrintNoParens(path, options, print, args) {
"}"
])
);
case "TSTypeParameter":
parts.push(path.call(print, "name"));
if (n.constraint) {
parts.push(" in ", path.call(print, "constraint"));
}
return concat(parts);
case "TSMethodSignature":
parts.push(
n.accessibility ? concat([n.accessibility, " "]) : "",
@ -4955,7 +4965,7 @@ function sameLocStart(nodeA, nodeB) {
// var f: (a) => void;
function isTypeAnnotationAFunction(node) {
return (
node.type === "TypeAnnotation" &&
(node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") &&
node.typeAnnotation.type === "FunctionTypeAnnotation" &&
!node.static &&
!sameLocStart(node, node.typeAnnotation)
@ -5017,7 +5027,8 @@ function shouldHugArguments(fun) {
fun.params[0].type === "ArrayPattern" ||
(fun.params[0].type === "Identifier" &&
fun.params[0].typeAnnotation &&
fun.params[0].typeAnnotation.type === "TypeAnnotation" &&
(fun.params[0].typeAnnotation.type === "TypeAnnotation" ||
fun.params[0].typeAnnotation.type === "TSTypeAnnotation") &&
isObjectType(fun.params[0].typeAnnotation.typeAnnotation)) ||
(fun.params[0].type === "FunctionTypeParam" &&
isObjectType(fun.params[0].typeAnnotation)) ||

View File

@ -4411,9 +4411,9 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
typescript-eslint-parser@9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/typescript-eslint-parser/-/typescript-eslint-parser-9.0.1.tgz#1497a565d192ca2a321bc5bbf89dcab0a2da75e8"
typescript-eslint-parser@10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/typescript-eslint-parser/-/typescript-eslint-parser-10.0.0.tgz#82b550253659c311c2e4a4d18311b94dd08a36d7"
dependencies:
lodash.unescape "4.0.1"
semver "5.4.1"