Don't force comemnts between head and body print on same line (#18808)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-01-30 14:59:42 +08:00
1 parent d4f80427db
commit af2526357a
21 files changed
+1202 -120

No files matched your search

@@ -0,0 +1,32 @@
import { addLeadingComment } from "../../../main/comments/utilities.js";
import { locStart } from "../../loc.js";
import { stripComments } from "../../utilities/strip-comments.js";
function handleForXComments({
comment,
enclosingNode,
followingNode,
options,
}) {
if (
(enclosingNode?.type === "ForInStatement" ||
enclosingNode?.type === "ForOfStatement" ||
enclosingNode?.type === "ForStatement") &&
followingNode &&
followingNode === enclosingNode.body
) {
const closingParenthesisIndex = stripComments(options).lastIndexOf(
")",
locStart(followingNode),
);
if (locStart(comment) > closingParenthesisIndex) {
addLeadingComment(followingNode, comment);
return true;
}
}
return false;
}
export { handleForXComments };
+4 -14
View File
@@ -29,6 +29,7 @@ import {
isUnionType,
} from "../utilities/node-types.js";
import { stripComments } from "../utilities/strip-comments.js";
import { handleForXComments } from "./attach/handle-for-x-statement.js";
import { handleIfStatementComments } from "./attach/handle-if-statement-comments.js";
import { handleWhileLikeComments } from "./attach/handle-while-like-comments.js";
import {
@@ -70,7 +71,7 @@ function handleOwnLineComment(context) {
handleWhileLikeComments,
handleTryStatementComments,
handleClassComments,
handleForComments,
handleForXComments,
handleUnionTypeComments,
handleMatchOrPatternComments,
handleOnlyComments,
@@ -100,6 +101,7 @@ function handleEndOfLineComment(context) {
handleWhileLikeComments,
handleTryStatementComments,
handleClassComments,
handleForXComments,
handleLabeledStatementComments,
handleCallExpressionComments,
handlePropertyComments,
@@ -125,6 +127,7 @@ function handleRemainingComment(context) {
handleIgnoreComments,
handleIfStatementComments,
handleWhileLikeComments,
handleForXComments,
handleMethodNameComments,
handleOnlyComments,
handleTSMappedTypeComments,
@@ -683,19 +686,6 @@ function handleOnlyComments({ comment, enclosingNode, ast, isLastComment }) {
return false;
}
function handleForComments({ comment, enclosingNode, followingNode }) {
if (
(enclosingNode?.type === "ForInStatement" ||
enclosingNode?.type === "ForOfStatement") &&
followingNode &&
followingNode !== enclosingNode.body
) {
addLeadingComment(enclosingNode, comment);
return true;
}
return false;
}
function handleModuleSpecifiersComments({
comment,
precedingNode,
+37 -8
View File
@@ -1,7 +1,30 @@
import { indent, line } from "../../document/index.js";
import { CommentCheckFlags, hasComment } from "../utilities/comments.js";
import { hardline, indent, line } from "../../document/index.js";
import hasNewline from "../../utilities/has-newline.js";
import hasNewlineInRange from "../../utilities/has-newline-in-range.js";
import { locEnd, locStart } from "../loc.js";
import {
CommentCheckFlags,
getComments,
hasComment,
} from "../utilities/comments.js";
function printClause(path, print, property = "body") {
function shouldPrintLeadingHardline(node, options) {
const leadingComments = getComments(node, CommentCheckFlags.Leading);
if (leadingComments.length === 0) {
return false;
}
const [firstComment] = leadingComments;
const text = options.originalText;
const start = locStart(firstComment);
return (
hasNewlineInRange(text, start, locEnd(firstComment)) ||
hasNewline(text, start, { backwards: true })
);
}
function printClause(path, options, print, property = "body") {
return path.call(({ node }) => {
const doc = print();
@@ -9,8 +32,14 @@ function printClause(path, print, property = "body") {
return hasComment(node, CommentCheckFlags.Leading) ? [" ", doc] : doc;
}
const isBlockStatement = node.type === "BlockStatement";
if (shouldPrintLeadingHardline(node, options)) {
return isBlockStatement ? [hardline, doc] : indent([hardline, doc]);
}
if (
node.type === "BlockStatement" ||
isBlockStatement ||
(node.type === "IfStatement" &&
path.parent.type === "IfStatement" &&
path.key === "alternate")
@@ -22,10 +51,10 @@ function printClause(path, print, property = "body") {
}, property);
}
const printIfStatementConsequent = (path, print) =>
printClause(path, print, "consequent");
const printIfStatementAlternate = (path, print) =>
printClause(path, print, "alternate");
const printIfStatementConsequent = (path, options, print) =>
printClause(path, options, print, "consequent");
const printIfStatementAlternate = (path, options, print) =>
printClause(path, options, print, "alternate");
export {
printClause as printDoWhileStatementBody,
+1 -1
View File
@@ -4,7 +4,7 @@ import { printDoWhileStatementCondition } from "./miscellaneous.js";
function printDoWhileStatement(path, options, print) {
return [
group(["do", printDoWhileStatementBody(path, print)]),
group(["do", printDoWhileStatementBody(path, options, print)]),
path.node.body.type === "BlockStatement" ? " " : hardline,
"while (",
printDoWhileStatementCondition(path, options, print),
+2 -2
View File
@@ -265,7 +265,7 @@ function printEstree(path, options, print, args) {
" in ",
print("right"),
")",
printForInStatementBody(path, print),
printForInStatementBody(path, options, print),
]);
case "ForOfStatement":
@@ -277,7 +277,7 @@ function printEstree(path, options, print, args) {
" of ",
print("right"),
")",
printForOfStatementBody(path, print),
printForOfStatementBody(path, options, print),
]);
case "DoExpression":
+1 -1
View File
@@ -10,7 +10,7 @@ import { printForStatementBody } from "./clause.js";
function printForStatement(path, options, print) {
const { node } = path;
const body = printForStatementBody(path, print);
const body = printForStatementBody(path, options, print);
// We want to keep dangling comments above the loop to stay consistent.
// Any comment positioned between the for statement and the parentheses
+2 -2
View File
@@ -15,7 +15,7 @@ import { printIfStatementCondition } from "./miscellaneous.js";
function printIfStatement(path, options, print) {
const { node } = path;
const consequent = printIfStatementConsequent(path, print);
const consequent = printIfStatementConsequent(path, options, print);
const opening = group([
"if (",
printIfStatementCondition(path, options, print),
@@ -42,7 +42,7 @@ function printIfStatement(path, options, print) {
);
}
parts.push("else", group(printIfStatementAlternate(path, print)));
parts.push("else", group(printIfStatementAlternate(path, options, print)));
}
return parts;
+1 -1
View File
@@ -11,7 +11,7 @@ function printWhileStatement(path, options, print) {
" (",
printWhileStatementCondition(path, options, print),
")",
printWhileStatementBody(path, print),
printWhileStatementBody(path, options, print),
]);
}
@@ -12,7 +12,6 @@ const unstableTests = new Map(
["js/ignore/semi/head-ignored.js", (options) => options.semi === false],
"js/comments/return-statement.js",
"js/comments/tagged-template-literal.js",
"js/for/9812-unstable.js",
[
"js/multiparser-markdown/codeblock.js",
(options) => options.proseWrap === "always",
@@ -22,6 +21,7 @@ const unstableTests = new Map(
"typescript/prettier-ignore/mapped-types.ts",
"typescript/prettier-ignore/issue-14238.ts",
"js/for/continue-and-break-comment-without-blocks.js",
"js/for/comment.js",
"js/sequence-expression/parenthesized.js",
"typescript/satisfies-operators/comments-unstable.ts",
"jsx/comments/in-attributes.js",
@@ -2951,7 +2951,7 @@ semi: false
| printWidth
=====================================input======================================
if (1)
// comment
// 11
{
false
}
@@ -3013,7 +3013,8 @@ else if (15) // comment
true
=====================================output=====================================
if (1) // comment
if (1)
// 11
{
false
}
@@ -3098,7 +3099,7 @@ printWidth: 80
| printWidth
=====================================input======================================
if (1)
// comment
// 11
{
false
}
@@ -3160,7 +3161,8 @@ else if (15) // comment
true
=====================================output=====================================
if (1) // comment
if (1)
// 11
{
false;
}
@@ -0,0 +1,698 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`between-head-and-body.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
do // 11
{} while(1)
for(a in b) // 12
{}
for(a of b) // 13
{}
for(;;) // 14
{}
if(a) // 15
{}
else // 152
{}
while(a) // 16
{}
with(a) // 17
{}
do
// 21
{} while(1)
for(a in b)
// 22
{}
for(a of b)
// 23
{}
for(;;)
// 24
{}
if(a)
// 25
{}
else
// 252
{}
while(a)
// 26
{}
with(a)
// 27
{}
do /* 31 */
{} while(1)
for(a in b) /* 32 */
{}
for(a of b) /* 33 */
{}
for(;;) // 34 */
{}
if(a) /* 35 */
{}
else /* 352 */
{}
while(a) /* 36 */
{}
with(a) /* 37 */
{}
do /* 41 */
{} while(1)
for(a in b) /* 42 */
{}
for(a of b) /* 43 */
{}
for(;;) // 34 */
{}
if(a) /* 45 */
{}
else /* 452 */
{}
while(a) /* 46 */
{}
with(a) /* 47 */
{}
do /*
51 */
{} while(1)
for(a in b) /*
52 */
{}
for(a of b) /*
53 */
{}
for(;;) // 54 */
{}
if(a) /*
55 */
{}
else /*
552 */
{}
while(a) /*
56 */
{}
with(a) /*
57 */
{}
do /* */ /*
61 */
{} while(1)
for(a in b) /* */ /*
62 */
{}
for(a of b) /* */ /*
63 */
{}
for(;;) // 54 */
{}
if(a) /* */ /*
65 */
{}
else /* */ /*
652 */
{}
while(a) /* */ /*
66 */
{}
with(a) /* */ /*
67 */
{}
=====================================output=====================================
do // 11
{} while (1);
for (a in b) // 12
{
}
for (a of b) // 13
{
}
for (;;) // 14
{}
if (a) // 15
{
} else // 152
{
}
while (a) // 16
{}
with (a) // 17
{
}
do
// 21
{} while (1);
for (a in b)
// 22
{
}
for (a of b)
// 23
{
}
for (;;)
// 24
{}
if (a)
// 25
{
} else
// 252
{
}
while (a)
// 26
{}
with (a)
// 27
{
}
do /* 31 */ {} while (1);
for (a in b) /* 32 */
{
}
for (a of b) /* 33 */
{
}
for (;;) // 34 */
{}
if (a) /* 35 */
{
} else /* 352 */
{
}
while (a) /* 36 */ {}
with (a) /* 37 */
{
}
do /* 41 */ {} while (1);
for (a in b) /* 42 */
{
}
for (a of b) /* 43 */
{
}
for (;;) // 34 */
{}
if (a) /* 45 */
{
} else /* 452 */
{
}
while (a) /* 46 */ {}
with (a) /* 47 */
{
}
do
/*
51 */
{} while (1);
for (a in b)
/*
52 */
{
}
for (a of b)
/*
53 */
{
}
for (;;) // 54 */
{}
if (a)
/*
55 */
{
} else
/*
552 */
{
}
while (a)
/*
56 */
{}
with (a)
/*
57 */
{
}
do /* */ /*
61 */
{} while (1);
for (a in b) /* */ /*
62 */
{
}
for (a of b) /* */ /*
63 */
{
}
for (;;) // 54 */
{}
if (a) /* */ /*
65 */
{
} else /* */ /*
652 */
{
}
while (a) /* */ /*
66 */
{}
with (a) /* */ /*
67 */
{
}
================================================================================
`;
exports[`empty-statement.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
do // 11
; while(1)
for(a in b) // 12
;
for(a of b) // 13
;
for(;;) // 14
;
if(a) // 15
;
else // 152
;
while(a) // 16
;
with(a) // 17
;
do
// 21
; while(1)
for(a in b)
// 22
;
for(a of b)
// 23
;
for(;;)
// 24
;
if(a)
// 25
;
else
// 252
;
while(a)
// 26
;
with(a)
// 27
;
do /* 31 */
; while(1)
for(a in b) /* 32 */
;
for(a of b) /* 33 */
;
for(;;) // 34 */
;
if(a) /* 35 */
;
else /* 352 */
;
while(a) /* 36 */
;
with(a) /* 37 */
;
do /* 41 */
; while(1)
for(a in b) /* 42 */
;
for(a of b) /* 43 */
;
for(;;) // 34 */
;
if(a) /* 45 */
;
else /* 452 */
;
while(a) /* 46 */
;
with(a) /* 47 */
;
do /*
51 */
; while(1)
for(a in b) /*
52 */
;
for(a of b) /*
53 */
;
for(;;) // 34 */
;
if(a) /*
55 */
;
else /*
552 */
;
while(a) /*
56 */
;
with(a) /*
57 */
;
=====================================output=====================================
do // 11
;
while (1);
for (a in b) // 12
;
for (a of b) // 13
;
for (;;) // 14
;
if (a) // 15
;
else // 152
;
while (a) // 16
;
with (a) // 17
;
do // 21
;
while (1);
for (a in b) // 22
;
for (a of b) // 23
;
for (;;) // 24
;
if (a) // 25
;
else // 252
;
while (a) // 26
;
with (a) // 27
;
do /* 31 */ ;
while (1);
for (a in b) /* 32 */ ;
for (a of b) /* 33 */ ;
for (;;) // 34 */
;
if (a) /* 35 */ ;
else /* 352 */ ;
while (a) /* 36 */ ;
with (a) /* 37 */ ;
do /* 41 */ ;
while (1);
for (a in b) /* 42 */ ;
for (a of b) /* 43 */ ;
for (;;) // 34 */
;
if (a) /* 45 */ ;
else /* 452 */ ;
while (a) /* 46 */ ;
with (a) /* 47 */ ;
do /*
51 */
;
while (1);
for (a in b) /*
52 */
;
for (a of b) /*
53 */
;
for (;;) // 34 */
;
if (a) /*
55 */
;
else /*
552 */
;
while (a) /*
56 */
;
with (a) /*
57 */
;
================================================================================
`;
exports[`non-block.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
do // 11
foo(); while(1)
for(a in b) // 12
foo();
for(a of b) // 13
foo();
for(;;) // 14
foo();
if(a) // 15
foo();
else // 152
foo();
while(a) // 16
foo();
with(a) // 17
foo();
do
// 21
foo(); while(1)
for(a in b)
// 22
foo();
for(a of b)
// 23
foo();
for(;;)
// 24
foo();
if(a)
// 25
foo();
else
// 252
foo();
while(a)
// 26
foo();
with(a)
// 27
foo();
do /* 31 */
foo(); while(1)
for(a in b) /* 32 */
foo();
for(a of b) /* 33 */
foo();
for(;;) // 34 */
foo();
if(a) /* 35 */
foo();
else /* 352 */
foo();
while(a) /* 36 */
foo();
with(a) /* 37 */
foo();
do /* 41 */
foo(); while(1)
for(a in b) /* 42 */
foo();
for(a of b) /* 43 */
foo();
for(;;) // 34 */
foo();
if(a) /* 45 */
foo();
else /* 452 */
foo();
while(a) /* 46 */
foo();
with(a) /* 47 */
foo();
do /*
51 */
foo(); while(1)
for(a in b) /*
52 */
foo();
for(a of b) /*
53 */
foo();
for(;;) // 34 */
foo();
if(a) /*
55 */
foo();
else /*
552 */
foo();
while(a) /*
56 */
foo();
with(a) /*
57 */
foo();
=====================================output=====================================
do
// 11
foo();
while (1);
for (a in b)
// 12
foo();
for (a of b)
// 13
foo();
for (;;)
// 14
foo();
if (a)
// 15
foo();
else
// 152
foo();
while (a)
// 16
foo();
with (a)
// 17
foo();
do
// 21
foo();
while (1);
for (a in b)
// 22
foo();
for (a of b)
// 23
foo();
for (;;)
// 24
foo();
if (a)
// 25
foo();
else
// 252
foo();
while (a)
// 26
foo();
with (a)
// 27
foo();
do /* 31 */ foo();
while (1);
for (a in b) /* 32 */ foo();
for (a of b) /* 33 */ foo();
for (;;)
// 34 */
foo();
if (a) /* 35 */ foo();
else /* 352 */ foo();
while (a) /* 36 */ foo();
with (a) /* 37 */ foo();
do /* 41 */ foo();
while (1);
for (a in b) /* 42 */ foo();
for (a of b) /* 43 */ foo();
for (;;)
// 34 */
foo();
if (a) /* 45 */ foo();
else /* 452 */ foo();
while (a) /* 46 */ foo();
with (a) /* 47 */ foo();
do
/*
51 */
foo();
while (1);
for (a in b)
/*
52 */
foo();
for (a of b)
/*
53 */
foo();
for (;;)
// 34 */
foo();
if (a)
/*
55 */
foo();
else
/*
552 */
foo();
while (a)
/*
56 */
foo();
with (a)
/*
57 */
foo();
================================================================================
`;
@@ -0,0 +1,123 @@
do // 11
{} while(1)
for(a in b) // 12
{}
for(a of b) // 13
{}
for(;;) // 14
{}
if(a) // 15
{}
else // 152
{}
while(a) // 16
{}
with(a) // 17
{}
do
// 21
{} while(1)
for(a in b)
// 22
{}
for(a of b)
// 23
{}
for(;;)
// 24
{}
if(a)
// 25
{}
else
// 252
{}
while(a)
// 26
{}
with(a)
// 27
{}
do /* 31 */
{} while(1)
for(a in b) /* 32 */
{}
for(a of b) /* 33 */
{}
for(;;) // 34 */
{}
if(a) /* 35 */
{}
else /* 352 */
{}
while(a) /* 36 */
{}
with(a) /* 37 */
{}
do /* 41 */
{} while(1)
for(a in b) /* 42 */
{}
for(a of b) /* 43 */
{}
for(;;) // 34 */
{}
if(a) /* 45 */
{}
else /* 452 */
{}
while(a) /* 46 */
{}
with(a) /* 47 */
{}
do /*
51 */
{} while(1)
for(a in b) /*
52 */
{}
for(a of b) /*
53 */
{}
for(;;) // 54 */
{}
if(a) /*
55 */
{}
else /*
552 */
{}
while(a) /*
56 */
{}
with(a) /*
57 */
{}
do /* */ /*
61 */
{} while(1)
for(a in b) /* */ /*
62 */
{}
for(a of b) /* */ /*
63 */
{}
for(;;) // 54 */
{}
if(a) /* */ /*
65 */
{}
else /* */ /*
652 */
{}
while(a) /* */ /*
66 */
{}
with(a) /* */ /*
67 */
{}
@@ -0,0 +1,99 @@
do // 11
; while(1)
for(a in b) // 12
;
for(a of b) // 13
;
for(;;) // 14
;
if(a) // 15
;
else // 152
;
while(a) // 16
;
with(a) // 17
;
do
// 21
; while(1)
for(a in b)
// 22
;
for(a of b)
// 23
;
for(;;)
// 24
;
if(a)
// 25
;
else
// 252
;
while(a)
// 26
;
with(a)
// 27
;
do /* 31 */
; while(1)
for(a in b) /* 32 */
;
for(a of b) /* 33 */
;
for(;;) // 34 */
;
if(a) /* 35 */
;
else /* 352 */
;
while(a) /* 36 */
;
with(a) /* 37 */
;
do /* 41 */
; while(1)
for(a in b) /* 42 */
;
for(a of b) /* 43 */
;
for(;;) // 34 */
;
if(a) /* 45 */
;
else /* 452 */
;
while(a) /* 46 */
;
with(a) /* 47 */
;
do /*
51 */
; while(1)
for(a in b) /*
52 */
;
for(a of b) /*
53 */
;
for(;;) // 34 */
;
if(a) /*
55 */
;
else /*
552 */
;
while(a) /*
56 */
;
with(a) /*
57 */
;
@@ -0,0 +1 @@
runFormatTest(import.meta, ["babel", "flow", "typescript"]);
@@ -0,0 +1,99 @@
do // 11
foo(); while(1)
for(a in b) // 12
foo();
for(a of b) // 13
foo();
for(;;) // 14
foo();
if(a) // 15
foo();
else // 152
foo();
while(a) // 16
foo();
with(a) // 17
foo();
do
// 21
foo(); while(1)
for(a in b)
// 22
foo();
for(a of b)
// 23
foo();
for(;;)
// 24
foo();
if(a)
// 25
foo();
else
// 252
foo();
while(a)
// 26
foo();
with(a)
// 27
foo();
do /* 31 */
foo(); while(1)
for(a in b) /* 32 */
foo();
for(a of b) /* 33 */
foo();
for(;;) // 34 */
foo();
if(a) /* 35 */
foo();
else /* 352 */
foo();
while(a) /* 36 */
foo();
with(a) /* 37 */
foo();
do /* 41 */
foo(); while(1)
for(a in b) /* 42 */
foo();
for(a of b) /* 43 */
foo();
for(;;) // 34 */
foo();
if(a) /* 45 */
foo();
else /* 452 */
foo();
while(a) /* 46 */
foo();
with(a) /* 47 */
foo();
do /*
51 */
foo(); while(1)
for(a in b) /*
52 */
foo();
for(a of b) /*
53 */
foo();
for(;;) // 34 */
foo();
if(a) /*
55 */
foo();
else /*
552 */
foo();
while(a) /*
56 */
foo();
with(a) /*
57 */
foo();
+1 -1
View File
@@ -1,5 +1,5 @@
if (1)
// comment
// 11
{
false
}
@@ -1,11 +1,11 @@
for(x of y)
// comment
// 11
{bar();}
for(x of y)
// comment
// 21
{}
for(x of y)
// comment
// 31
;
@@ -114,35 +114,37 @@ for (
================================================================================
`;
exports[`9812-unstable.js format 1`] = `
exports[`9812-2.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
for(x of y)
// comment
// 11
{bar();}
for(x of y)
// comment
// 21
{}
for(x of y)
// comment
// 31
;
=====================================output=====================================
for (x of y) // comment
for (x of y)
// 11
{
bar();
}
for (x of y) // comment
for (x of y)
// 21
{
}
for (x of y) // comment
for (x of y) // 31
;
================================================================================
@@ -155,69 +157,71 @@ printWidth: 80
| printWidth
=====================================input======================================
for (x
/*a*/
in //b
y) //c
/*1a*/
in //1b
y) //1c
;
for (x in /*a*/ //b
y); //c
for (x in /*2a*/ //2b
y); //2c
for (x /*a*/ in y); //b //c
for (x /*3a*/ in y); //3b //3c
for (x
//a
//4a
in y);
for(x in
//a
//5a
y);
for (x
/*a*/
of //b
y) //c
/*6a*/
of //6b
y) //6c
;
for (x of /*a*/ //b
y); //c
for (x of /*7a*/ //7b
y); //7c
for (x /*a*/ of y); //b //c
for (x /*8a*/ of y); //8b //8c
for (x
//a
//9a
of y);
for(x of
//a
//10a
y);
=====================================output=====================================
/*a*/
for (x in y); //b //c
for (x in /*1a*/ //1b
y) //1c
;
for (x /*a*/ in y); //b //c
for (x /*2a*/ in y); //2b //2c
for (x /*a*/ in y); //b //c
for (x /*3a*/ in y); //3b //3c
//a
for (x in y);
for (x in //4a
y);
//a
for (x in y);
for (x in //5a
y);
/*a*/
for (x of y); //b //c
for (x of /*6a*/ //6b
y) //6c
;
for (x /*a*/ of y); //b //c
for (x /*7a*/ of y); //7b //7c
for (x /*a*/ of y); //b //c
for (x /*8a*/ of y); //8b //8c
//a
for (x of y);
for (x of //9a
y);
//a
for (x of y);
for (x of //10a
y);
================================================================================
`;
+16 -16
View File
@@ -1,37 +1,37 @@
for (x
/*a*/
in //b
y) //c
/*1a*/
in //1b
y) //1c
;
for (x in /*a*/ //b
y); //c
for (x in /*2a*/ //2b
y); //2c
for (x /*a*/ in y); //b //c
for (x /*3a*/ in y); //3b //3c
for (x
//a
//4a
in y);
for(x in
//a
//5a
y);
for (x
/*a*/
of //b
y) //c
/*6a*/
of //6b
y) //6c
;
for (x of /*a*/ //b
y); //c
for (x of /*7a*/ //7b
y); //7c
for (x /*a*/ of y); //b //c
for (x /*8a*/ of y); //8b //8c
for (x
//a
//9a
of y);
for(x of
//a
//10a
y);
@@ -44,76 +44,78 @@ parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
if (1) { // foo may not exist
if (1) { // 11
doThing(foo);
}
if (1){}else { // foo may not exist
if (1){}else { // 12
doThing(foo);
}
if (2)
// foo may not exist
// 21
{
doThing(foo);
}
if (2){}else
// foo may not exist
// 22
{
doThing(foo);
}
if (3)// foo may not exist
if (3)// 31
{
doThing(foo);
}
if (3){}else// foo may not exist
if (3){}else// 32
{
doThing(foo);
}
if (4)/* foo may not exist */{
if (4)/* 41 */{
doThing(foo);
}
if (4){}else/* foo may not exist */{
if (4){}else/* 42 */{
doThing(foo);
}
=====================================output=====================================
if (1) {
// foo may not exist
// 11
doThing(foo);
}
if (1) {
} else {
// foo may not exist
// 12
doThing(foo);
}
if (2) // foo may not exist
if (2)
// 21
{
doThing(foo);
}
if (2) {
} else // foo may not exist
} else
// 22
{
doThing(foo);
}
if (3) // foo may not exist
if (3) // 31
{
doThing(foo);
}
if (3) {
} else // foo may not exist
} else // 32
{
doThing(foo);
}
if (4) /* foo may not exist */ {
if (4) /* 41 */ {
doThing(foo);
}
if (4) {
} else /* foo may not exist */ {
} else /* 42 */ {
doThing(foo);
}
@@ -358,12 +360,15 @@ async function f3() {
}
async function f4() {
if (untrackedChoice === 0) /* Cancel */ {
if (untrackedChoice === 0)
/* Cancel */ {
return null;
} else if (untrackedChoice === 1) /* Add */ {
} else if (untrackedChoice === 1)
/* Add */ {
await repository.addAll(Array.from(untrackedChanges.keys()));
shouldAmend = true;
} else if (untrackedChoice === 2) /* Allow Untracked */ {
} else if (untrackedChoice === 2)
/* Allow Untracked */ {
allowUntracked = true;
}
}
@@ -1,33 +1,33 @@
if (1) { // foo may not exist
if (1) { // 11
doThing(foo);
}
if (1){}else { // foo may not exist
if (1){}else { // 12
doThing(foo);
}
if (2)
// foo may not exist
// 21
{
doThing(foo);
}
if (2){}else
// foo may not exist
// 22
{
doThing(foo);
}
if (3)// foo may not exist
if (3)// 31
{
doThing(foo);
}
if (3){}else// foo may not exist
if (3){}else// 32
{
doThing(foo);
}
if (4)/* foo may not exist */{
if (4)/* 41 */{
doThing(foo);
}
if (4){}else/* foo may not exist */{
if (4){}else/* 42 */{
doThing(foo);
}