Allow flow declarations to break on StringLiteralTypeAnnotations (#1437)
* Allow flow declarations to break on StringLiteralTypeAnnotations * canBreak
This commit is contained in:
1 parent
7a02e9ad27
commit
b2a092bd17
4 files changed
+65
-13
No files matched your search
+34
-13
@@ -1837,18 +1837,27 @@ function genericPrintNoParens(path, options, print, args) {
|
||||
parts.push("declare ");
|
||||
}
|
||||
|
||||
const canBreak = (
|
||||
n.right.type === "StringLiteralTypeAnnotation"
|
||||
);
|
||||
|
||||
const printed = printAssignmentRight(
|
||||
n.right,
|
||||
path.call(print, "right"),
|
||||
canBreak,
|
||||
options
|
||||
);
|
||||
|
||||
parts.push(
|
||||
"type ",
|
||||
path.call(print, "id"),
|
||||
path.call(print, "typeParameters"),
|
||||
" =",
|
||||
hasLeadingOwnLineComment(options.originalText, n.right)
|
||||
? indent(concat([hardline, path.call(print, "right")]))
|
||||
: concat([" ", path.call(print, "right")]),
|
||||
printed,
|
||||
semi
|
||||
);
|
||||
|
||||
return concat(parts);
|
||||
return group(concat(parts));
|
||||
}
|
||||
case "TypeCastExpression":
|
||||
return concat([
|
||||
@@ -3345,6 +3354,18 @@ function printBinaryishExpressions(path, print, options, isNested, isInsideParen
|
||||
return parts;
|
||||
}
|
||||
|
||||
function printAssignmentRight(rightNode, printedRight, canBreak, options) {
|
||||
if (hasLeadingOwnLineComment(options.originalText, rightNode)) {
|
||||
return indent(concat([hardline, printedRight]));
|
||||
}
|
||||
|
||||
if (canBreak) {
|
||||
return indent(concat([line, printedRight]));
|
||||
}
|
||||
|
||||
return concat([" ", printedRight]);
|
||||
}
|
||||
|
||||
function printAssignment(
|
||||
leftNode,
|
||||
printedLeft,
|
||||
@@ -3357,20 +3378,20 @@ function printAssignment(
|
||||
return printedLeft;
|
||||
}
|
||||
|
||||
let printed;
|
||||
if (hasLeadingOwnLineComment(options.originalText, rightNode)) {
|
||||
printed = indent(concat([hardline, printedRight]));
|
||||
} else if (
|
||||
const canBreak = (
|
||||
(isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode)) ||
|
||||
(leftNode.type === "Identifier" || leftNode.type === "MemberExpression") &&
|
||||
(rightNode.type === "StringLiteral" ||
|
||||
(rightNode.type === "Literal" && typeof rightNode.value === "string") ||
|
||||
isMemberExpressionChain(rightNode))
|
||||
) {
|
||||
printed = indent(concat([line, printedRight]));
|
||||
} else {
|
||||
printed = concat([" ", printedRight]);
|
||||
}
|
||||
);
|
||||
|
||||
const printed = printAssignmentRight(
|
||||
rightNode,
|
||||
printedRight,
|
||||
canBreak,
|
||||
options
|
||||
);
|
||||
|
||||
return group(concat([printedLeft, " ", operator, printed]));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`long.js 1`] = `
|
||||
export type AdamPlacementValidationSingleErrorKey =
|
||||
'SOME_FANCY_TARGETS.GLOBAL_TARGET';
|
||||
|
||||
export type SomeReallyLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = true;
|
||||
|
||||
export type SomeOtherLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = null;
|
||||
|
||||
type SomeOtherLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = SomeReallyLongLongLongLongLongLongIdentifier;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
export type AdamPlacementValidationSingleErrorKey =
|
||||
"SOME_FANCY_TARGETS.GLOBAL_TARGET";
|
||||
|
||||
export type SomeReallyLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = true;
|
||||
|
||||
export type SomeOtherLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = null;
|
||||
|
||||
type SomeOtherLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = SomeReallyLongLongLongLongLongLongIdentifier;
|
||||
|
||||
`;
|
||||
@@ -0,0 +1 @@
|
||||
run_spec(__dirname, null, ["babylon"]);
|
||||
@@ -0,0 +1,8 @@
|
||||
export type AdamPlacementValidationSingleErrorKey =
|
||||
'SOME_FANCY_TARGETS.GLOBAL_TARGET';
|
||||
|
||||
export type SomeReallyLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = true;
|
||||
|
||||
export type SomeOtherLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = null;
|
||||
|
||||
type SomeOtherLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = SomeReallyLongLongLongLongLongLongIdentifier;
|
||||
Reference in new issue
Block a user