Add support for breaks in TupleTypeAnnotation (#1003)
parent
2b93bf4f30
commit
a2b560887c
|
@ -805,31 +805,16 @@ function genericPrintNoParens(path, options, print) {
|
|||
const needsForcedTrailingComma = canHaveTrailingComma &&
|
||||
lastElem === null;
|
||||
|
||||
var printedElements = [];
|
||||
let separatorParts = [];
|
||||
path.each(
|
||||
function(childPath) {
|
||||
printedElements.push(concat(separatorParts));
|
||||
printedElements.push(group(print(childPath)));
|
||||
|
||||
separatorParts = [",", line];
|
||||
if (
|
||||
childPath.getValue() &&
|
||||
util.isNextLineEmpty(options.originalText, childPath.getValue())
|
||||
) {
|
||||
separatorParts.push(softline);
|
||||
}
|
||||
},
|
||||
"elements"
|
||||
);
|
||||
|
||||
parts.push(
|
||||
group(
|
||||
concat([
|
||||
"[",
|
||||
indent(
|
||||
options.tabWidth,
|
||||
concat([softline, concat(printedElements)])
|
||||
concat([
|
||||
softline,
|
||||
printArrayItems(path, options, "elements", print)
|
||||
])
|
||||
),
|
||||
needsForcedTrailingComma ? "," : "",
|
||||
ifBreak(
|
||||
|
@ -1484,7 +1469,27 @@ function genericPrintNoParens(path, options, print) {
|
|||
|
||||
return "";
|
||||
case "TupleTypeAnnotation":
|
||||
return concat(["[", join(", ", path.map(print, "types")), "]"]);
|
||||
return group(
|
||||
concat([
|
||||
"[",
|
||||
indent(
|
||||
options.tabWidth,
|
||||
concat([
|
||||
softline,
|
||||
printArrayItems(path, options, "types", print)
|
||||
])
|
||||
),
|
||||
ifBreak(shouldPrintComma(options) ? "," : ""),
|
||||
comments.printDanglingComments(
|
||||
path,
|
||||
options,
|
||||
/* sameIndent */ true
|
||||
),
|
||||
softline,
|
||||
"]"
|
||||
])
|
||||
);
|
||||
|
||||
case "ExistentialTypeParam":
|
||||
case "ExistsTypeAnnotation":
|
||||
return "*";
|
||||
|
@ -3040,6 +3045,29 @@ function isFlowNodeStartingWithDeclare(node, options) {
|
|||
.match(/declare\s*$/);
|
||||
}
|
||||
|
||||
function printArrayItems(path, options, printPath, print) {
|
||||
const printedElements = [];
|
||||
let separatorParts = [];
|
||||
|
||||
path.each(
|
||||
function(childPath) {
|
||||
printedElements.push(concat(separatorParts));
|
||||
printedElements.push(group(print(childPath)));
|
||||
|
||||
separatorParts = [",", line];
|
||||
if (
|
||||
childPath.getValue() &&
|
||||
util.isNextLineEmpty(options.originalText, childPath.getValue())
|
||||
) {
|
||||
separatorParts.push(softline);
|
||||
}
|
||||
},
|
||||
printPath
|
||||
);
|
||||
|
||||
return concat(printedElements);
|
||||
}
|
||||
|
||||
function printAstToDoc(ast, options) {
|
||||
function printGenerically(path) {
|
||||
return comments.printComments(
|
||||
|
|
|
@ -82,6 +82,27 @@ module.exports = \\"arrays\\";
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`comments.js 1`] = `
|
||||
"export type FileMetaData = [
|
||||
/* id */ string,
|
||||
/* mtime */ number,
|
||||
/* visited */ 0|1,
|
||||
/* dependencies */ Array<string>,
|
||||
];
|
||||
|
||||
export type ModuleMetaData = [Path, /* type */ number];
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
export type FileMetaData = [
|
||||
/* id */ string,
|
||||
/* mtime */ number,
|
||||
/* visited */ 0 | 1,
|
||||
/* dependencies */ Array<string>
|
||||
];
|
||||
|
||||
export type ModuleMetaData = [Path, /* type */ number];
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`numeric_elem.js 1`] = `
|
||||
"var arr = [];
|
||||
var day = new Date;
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
export type FileMetaData = [
|
||||
/* id */ string,
|
||||
/* mtime */ number,
|
||||
/* visited */ 0|1,
|
||||
/* dependencies */ Array<string>,
|
||||
];
|
||||
|
||||
export type ModuleMetaData = [Path, /* type */ number];
|
Loading…
Reference in New Issue