fix TSFunctionType (#1600)

master
Danny Martini 2017-05-13 00:33:03 +02:00 committed by Christopher Chedeau
parent 2fc6024a20
commit c86a57a91e
2 changed files with 27 additions and 31 deletions

View File

@ -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",

View File

@ -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) {