From c86a57a91e803c9a3c4386c97458a73cb32902a6 Mon Sep 17 00:00:00 2001 From: Danny Martini Date: Sat, 13 May 2017 00:33:03 +0200 Subject: [PATCH] fix TSFunctionType (#1600) --- package.json | 1 - src/printer.js | 57 ++++++++++++++++++++++++-------------------------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 9fe30b02..cf2ec6af 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,6 @@ "tests/typescript/conformance/types/variableDeclarator/jsfmt.spec.js", "tests/typescript/conformance/types/typeParameter/jsfmt.spec.js", "tests/typescript/custom/computedProperties/jsfmt.spec.js", - "tests/typescript/conformance/types/functions/jsfmt.spec.js", "tests/typescript/custom/new/jsfmt.spec.js", "tests/typescript/custom/call/jsfmt.spec.js", "tests/typescript/custom/typeParameters/jsfmt.spec.js", diff --git a/src/printer.js b/src/printer.js index a66fb83a..b1d78002 100644 --- a/src/printer.js +++ b/src/printer.js @@ -2732,11 +2732,8 @@ function printArgumentsList(path, options, print) { function printFunctionTypeParameters(path, options, print) { const fun = path.getValue(); - // With TypeScript `typeParameters` is an array of `TSTypeParameter` and - // with flow they are one `TypeParameterDeclaration` node. - if (fun.type === "TSFunctionType") { - return printTypeParameters(path, options, print, "typeParameters") - } else if (fun.typeParameters) { + + if (fun.typeParameters) { return path.call(print, "typeParameters"); } else { return ""; @@ -3096,35 +3093,35 @@ function printTypeScriptModifiers(path, options, print) { } function printTypeParameters(path, options, print, paramsKey) { - const n = path.getValue(); + const n = path.getValue(); - if (!n[paramsKey]) { - return ""; - } + if (!n[paramsKey]) { + return ""; + } - const shouldInline = - n[paramsKey].length === 1 && - (n[paramsKey][0].type === "ObjectTypeAnnotation" || - n[paramsKey][0].type === "NullableTypeAnnotation"); + const shouldInline = + n[paramsKey].length === 1 && + (n[paramsKey][0].type === "ObjectTypeAnnotation" || + n[paramsKey][0].type === "NullableTypeAnnotation"); - if (shouldInline) { - return concat(["<", join(", ", path.map(print, paramsKey)), ">"]); - } + if (shouldInline) { + return concat(["<", join(", ", path.map(print, paramsKey)), ">"]); + } - return group( - concat([ - "<", - indent( - concat([ - softline, - join(concat([",", line]), path.map(print, paramsKey)) - ]) - ), - ifBreak(shouldPrintComma(options, "all") ? "," : ""), - softline, - ">" - ]) - ); + return group( + concat([ + "<", + indent( + concat([ + softline, + join(concat([",", line]), path.map(print, paramsKey)) + ]) + ), + ifBreak(shouldPrintComma(options, "all") ? "," : ""), + softline, + ">" + ]) + ); } function printClass(path, options, print) {