Refactor: Simplify printSequence() (#12535)
This commit is contained in:
1 parent
0dcb0a1a30
commit
b40a5d03d6
1 file changed
+16
-66
@@ -91,13 +91,7 @@ function genericPrint(path, options, print) {
|
||||
"{",
|
||||
indent([
|
||||
hardline,
|
||||
join(
|
||||
hardline,
|
||||
path.call(
|
||||
(selectionsPath) => printSequence(selectionsPath, options, print),
|
||||
"selections"
|
||||
)
|
||||
),
|
||||
join(hardline, printSequence(path, options, print, "selections")),
|
||||
]),
|
||||
hardline,
|
||||
"}",
|
||||
@@ -114,10 +108,7 @@ function genericPrint(path, options, print) {
|
||||
softline,
|
||||
join(
|
||||
[ifBreak("", ", "), softline],
|
||||
path.call(
|
||||
(argsPath) => printSequence(argsPath, options, print),
|
||||
"arguments"
|
||||
)
|
||||
printSequence(path, options, print, "arguments")
|
||||
),
|
||||
]),
|
||||
softline,
|
||||
@@ -205,10 +196,7 @@ function genericPrint(path, options, print) {
|
||||
softline,
|
||||
join(
|
||||
[ifBreak("", ", "), softline],
|
||||
path.call(
|
||||
(argsPath) => printSequence(argsPath, options, print),
|
||||
"arguments"
|
||||
)
|
||||
printSequence(path, options, print, "arguments")
|
||||
),
|
||||
]),
|
||||
softline,
|
||||
@@ -249,13 +237,7 @@ function genericPrint(path, options, print) {
|
||||
" {",
|
||||
indent([
|
||||
hardline,
|
||||
join(
|
||||
hardline,
|
||||
path.call(
|
||||
(fieldsPath) => printSequence(fieldsPath, options, print),
|
||||
"fields"
|
||||
)
|
||||
),
|
||||
join(hardline, printSequence(path, options, print, "fields")),
|
||||
]),
|
||||
hardline,
|
||||
"}",
|
||||
@@ -276,10 +258,7 @@ function genericPrint(path, options, print) {
|
||||
softline,
|
||||
join(
|
||||
[ifBreak("", ", "), softline],
|
||||
path.call(
|
||||
(argsPath) => printSequence(argsPath, options, print),
|
||||
"arguments"
|
||||
)
|
||||
printSequence(path, options, print, "arguments")
|
||||
),
|
||||
]),
|
||||
softline,
|
||||
@@ -306,10 +285,7 @@ function genericPrint(path, options, print) {
|
||||
softline,
|
||||
join(
|
||||
[ifBreak("", ", "), softline],
|
||||
path.call(
|
||||
(argsPath) => printSequence(argsPath, options, print),
|
||||
"arguments"
|
||||
)
|
||||
printSequence(path, options, print, "arguments")
|
||||
),
|
||||
]),
|
||||
softline,
|
||||
@@ -337,13 +313,7 @@ function genericPrint(path, options, print) {
|
||||
" {",
|
||||
indent([
|
||||
hardline,
|
||||
join(
|
||||
hardline,
|
||||
path.call(
|
||||
(valuesPath) => printSequence(valuesPath, options, print),
|
||||
"values"
|
||||
)
|
||||
),
|
||||
join(hardline, printSequence(path, options, print, "values")),
|
||||
]),
|
||||
hardline,
|
||||
"}",
|
||||
@@ -387,13 +357,7 @@ function genericPrint(path, options, print) {
|
||||
" {",
|
||||
indent([
|
||||
hardline,
|
||||
join(
|
||||
hardline,
|
||||
path.call(
|
||||
(fieldsPath) => printSequence(fieldsPath, options, print),
|
||||
"fields"
|
||||
)
|
||||
),
|
||||
join(hardline, printSequence(path, options, print, "fields")),
|
||||
]),
|
||||
hardline,
|
||||
"}",
|
||||
@@ -413,10 +377,7 @@ function genericPrint(path, options, print) {
|
||||
hardline,
|
||||
join(
|
||||
hardline,
|
||||
path.call(
|
||||
(opsPath) => printSequence(opsPath, options, print),
|
||||
"operationTypes"
|
||||
)
|
||||
printSequence(path, options, print, "operationTypes")
|
||||
),
|
||||
]),
|
||||
hardline,
|
||||
@@ -437,10 +398,7 @@ function genericPrint(path, options, print) {
|
||||
hardline,
|
||||
join(
|
||||
hardline,
|
||||
path.call(
|
||||
(opsPath) => printSequence(opsPath, options, print),
|
||||
"operationTypes"
|
||||
)
|
||||
printSequence(path, options, print, "operationTypes")
|
||||
),
|
||||
])
|
||||
: "",
|
||||
@@ -470,13 +428,7 @@ function genericPrint(path, options, print) {
|
||||
" {",
|
||||
indent([
|
||||
hardline,
|
||||
join(
|
||||
hardline,
|
||||
path.call(
|
||||
(fieldsPath) => printSequence(fieldsPath, options, print),
|
||||
"fields"
|
||||
)
|
||||
),
|
||||
join(hardline, printSequence(path, options, print, "fields")),
|
||||
]),
|
||||
hardline,
|
||||
"}",
|
||||
@@ -566,21 +518,19 @@ function printDirectives(path, print, node) {
|
||||
return [" ", group(indent([softline, printed]))];
|
||||
}
|
||||
|
||||
function printSequence(sequencePath, options, print) {
|
||||
const count = sequencePath.getValue().length;
|
||||
|
||||
return sequencePath.map((path, i) => {
|
||||
function printSequence(path, options, print, property) {
|
||||
return path.map((path, index, sequence) => {
|
||||
const printed = print();
|
||||
|
||||
if (
|
||||
isNextLineEmpty(options.originalText, path.getValue(), locEnd) &&
|
||||
i < count - 1
|
||||
index < sequence.length - 1 &&
|
||||
isNextLineEmpty(options.originalText, path.getValue(), locEnd)
|
||||
) {
|
||||
return [printed, hardline];
|
||||
}
|
||||
|
||||
return printed;
|
||||
});
|
||||
}, property);
|
||||
}
|
||||
|
||||
function canAttachComment(node) {
|
||||
|
||||
Reference in new issue
Block a user