If consequent is a block statement, treat as trailing comment
parent
88489a9afe
commit
fa089f5bb6
|
@ -211,7 +211,11 @@ function handleIfStatementComments(
|
|||
precedingNode === enclosingNode.consequent &&
|
||||
followingNode === enclosingNode.alternate
|
||||
) {
|
||||
addDanglingComment(enclosingNode, comment);
|
||||
if (precedingNode.type === "BlockStatement") {
|
||||
addTrailingComment(precedingNode, comment);
|
||||
} else {
|
||||
addDanglingComment(enclosingNode, comment);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1456,13 +1456,18 @@ function printPathNoParens(path, options, print, args) {
|
|||
|
||||
if (n.alternate) {
|
||||
const commentOnOwnLine =
|
||||
hasDanglingComments(n) &&
|
||||
n.comments.some(
|
||||
comment =>
|
||||
!comment.leading &&
|
||||
!comment.trailing &&
|
||||
!privateUtil.isBlockComment(comment)
|
||||
);
|
||||
(hasTrailingComment(n.consequent) &&
|
||||
n.consequent.comments.some(
|
||||
comment =>
|
||||
comment.trailing && !privateUtil.isBlockComment(comment)
|
||||
)) ||
|
||||
(hasDanglingComments(n) &&
|
||||
n.comments.some(
|
||||
comment =>
|
||||
!comment.leading &&
|
||||
!comment.trailing &&
|
||||
!privateUtil.isBlockComment(comment)
|
||||
));
|
||||
const elseOnSameLine =
|
||||
n.consequent.type === "BlockStatement" && !commentOnOwnLine;
|
||||
parts.push(elseOnSameLine ? " " : hardline);
|
||||
|
|
|
@ -2571,8 +2571,7 @@ type Breakfast = Apple | Orange | Broccoli | Carrot;
|
|||
function bar(x: Breakfast) {
|
||||
if (x.kind === "Fruit") {
|
||||
(x.taste: "Good");
|
||||
}
|
||||
// error, Apple.taste = Bad
|
||||
} // error, Apple.taste = Bad
|
||||
else (x.raw: "No"); // error, Carrot.raw = Maybe
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue