prettier-java-next-line 2.11.0 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/index.cjs +88 -43
- package/dist/index.d.cts +20 -0
- package/dist/index.d.mts +20 -0
- package/dist/index.mjs +88 -43
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,6 +35,24 @@ Set `braceStyle` only when a project needs the inherited same-line style:
|
|
|
35
35
|
}
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
With next-line braces, array initializers put every element on its own line by default. Set `arrayInitializerLayout` to `fit` to keep an array initializer on one line when it fits, and break it into the next-line layout only when it doesn't. When it fits, `bracketSpacing` decides whether to print `{ 1, 2 }` or `{1, 2}`.
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"plugins": ["prettier-java-next-line"],
|
|
43
|
+
"arrayInitializerLayout": "fit"
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Set `closingBracket` to `same-line` to keep the closing `)` or `>` of a wrapped list on its last line instead of on its own line. This matches Checkstyle's `SeparatorWrap` check on `RPAREN` with the `eol` option:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"plugins": ["prettier-java-next-line"],
|
|
52
|
+
"closingBracket": "same-line"
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
38
56
|
Set `importOrder` to group imports the way Spotless's `importOrder` step does. Groups separated by `,` get blank lines between them, prefixes joined by `|` share a group, `#` marks a static prefix, and an empty prefix catches everything else. Each import belongs to its longest matching prefix. Module imports (`import module`) always come first in their own group. When `importOrder` is empty, static imports follow them, then all others.
|
|
39
57
|
|
|
40
58
|
```json
|
package/dist/index.cjs
CHANGED
|
@@ -62,6 +62,32 @@ var options_default = {
|
|
|
62
62
|
}],
|
|
63
63
|
description: "Placement of opening braces."
|
|
64
64
|
},
|
|
65
|
+
arrayInitializerLayout: {
|
|
66
|
+
type: "choice",
|
|
67
|
+
category: "Java",
|
|
68
|
+
default: "always-break",
|
|
69
|
+
choices: [{
|
|
70
|
+
value: "always-break",
|
|
71
|
+
description: "Put each array element on its own line"
|
|
72
|
+
}, {
|
|
73
|
+
value: "fit",
|
|
74
|
+
description: "Keep array initializers on one line when they fit"
|
|
75
|
+
}],
|
|
76
|
+
description: "Layout of array initializers when braceStyle is next-line."
|
|
77
|
+
},
|
|
78
|
+
closingBracket: {
|
|
79
|
+
type: "choice",
|
|
80
|
+
category: "Java",
|
|
81
|
+
default: "next-line",
|
|
82
|
+
choices: [{
|
|
83
|
+
value: "next-line",
|
|
84
|
+
description: "Put the closing parenthesis or angle bracket of a wrapped list on its own line"
|
|
85
|
+
}, {
|
|
86
|
+
value: "same-line",
|
|
87
|
+
description: "Keep the closing parenthesis or angle bracket on the last line of a wrapped list"
|
|
88
|
+
}],
|
|
89
|
+
description: "Placement of the closing parenthesis or angle bracket when a list wraps."
|
|
90
|
+
},
|
|
65
91
|
importOrder: {
|
|
66
92
|
type: "string",
|
|
67
93
|
category: "Java",
|
|
@@ -134,11 +160,14 @@ function hasLeadingComments(node) {
|
|
|
134
160
|
function hasDanglingComments(node) {
|
|
135
161
|
return node.comments?.some(({ leading, trailing }) => !leading && !trailing) ?? false;
|
|
136
162
|
}
|
|
137
|
-
function
|
|
163
|
+
function closingBracketLine(options, lineDoc = softline$4) {
|
|
164
|
+
return options?.closingBracket === "same-line" ? "" : lineDoc;
|
|
165
|
+
}
|
|
166
|
+
function indentInParentheses(contents, options) {
|
|
138
167
|
return contents && !Array.isArray(contents) || contents.length ? [
|
|
139
168
|
"(",
|
|
140
169
|
indent$7([softline$4, contents]),
|
|
141
|
-
|
|
170
|
+
closingBracketLine(options),
|
|
142
171
|
")"
|
|
143
172
|
] : "()";
|
|
144
173
|
}
|
|
@@ -157,6 +186,16 @@ function printArrayInitializer(path, print, options) {
|
|
|
157
186
|
const list = join$7([",", line$7], path.map(print, "namedChildren"));
|
|
158
187
|
if (list.length && options.trailingComma !== "none") list.push(ifBreak$2(","));
|
|
159
188
|
if (options.braceStyle === "next-line" && path.node.type === "array_initializer") {
|
|
189
|
+
if (options.arrayInitializerLayout === "fit") {
|
|
190
|
+
const bracketLine = options.bracketSpacing ? line$7 : softline$4;
|
|
191
|
+
const block = [
|
|
192
|
+
"{",
|
|
193
|
+
indent$7([bracketLine, ...list]),
|
|
194
|
+
bracketLine,
|
|
195
|
+
"}"
|
|
196
|
+
];
|
|
197
|
+
return group$7(isNestedArray(path) ? block : [softline$4, ...block]);
|
|
198
|
+
}
|
|
160
199
|
const block = [
|
|
161
200
|
"{",
|
|
162
201
|
indent$7([line$7, ...list]),
|
|
@@ -219,12 +258,18 @@ function printBlock(path, contents, options) {
|
|
|
219
258
|
}
|
|
220
259
|
function printBlockNextLine(path, contents) {
|
|
221
260
|
const parentType = path.parent?.type;
|
|
222
|
-
const
|
|
261
|
+
const isChildOfBodyDeclaration = parentType != null && [
|
|
223
262
|
"annotation_type_body",
|
|
224
263
|
"class_body",
|
|
225
264
|
"enum_body",
|
|
226
265
|
"interface_body"
|
|
227
|
-
].includes(parentType)
|
|
266
|
+
].includes(parentType);
|
|
267
|
+
const isBlockStatement = parentType != null && [
|
|
268
|
+
"block",
|
|
269
|
+
"constructor_body",
|
|
270
|
+
"switch_block_statement_group"
|
|
271
|
+
].includes(parentType);
|
|
272
|
+
const prefix = isChildOfBodyDeclaration || isBlockStatement ? [] : [hardline$7];
|
|
228
273
|
if (contents.length) return [
|
|
229
274
|
...prefix,
|
|
230
275
|
"{",
|
|
@@ -275,7 +320,7 @@ function printBodyDeclarations(path, print, padFirst = false) {
|
|
|
275
320
|
return blankLine ? [separator, declaration] : declaration;
|
|
276
321
|
}, "namedChildren");
|
|
277
322
|
}
|
|
278
|
-
function printTypeParameters(path, print) {
|
|
323
|
+
function printTypeParameters(path, print, options) {
|
|
279
324
|
const parameters = path.node.namedChildren;
|
|
280
325
|
if (parameters.length === 0 || parameters.length === 1 && isSimpleType(parameters[0]) && !parameters.some(({ comments }) => comments?.length && comments.some(({ type }) => type === "line_comment"))) return [
|
|
281
326
|
"<",
|
|
@@ -285,7 +330,7 @@ function printTypeParameters(path, print) {
|
|
|
285
330
|
const parts = [
|
|
286
331
|
"<",
|
|
287
332
|
indent$7([softline$4, join$7([",", line$7], path.map(print, "namedChildren"))]),
|
|
288
|
-
|
|
333
|
+
closingBracketLine(options),
|
|
289
334
|
">"
|
|
290
335
|
];
|
|
291
336
|
return path.node.type === "type_arguments" ? group$7(parts) : parts;
|
|
@@ -634,7 +679,7 @@ var blocks_and_statements_default = {
|
|
|
634
679
|
";"
|
|
635
680
|
];
|
|
636
681
|
},
|
|
637
|
-
for_statement(path, print) {
|
|
682
|
+
for_statement(path, print, options) {
|
|
638
683
|
const danglingComments = printDanglingComments(path);
|
|
639
684
|
const hasInit = path.node.initNodes.length > 0;
|
|
640
685
|
const hasCondition = hasChild(path, "conditionNode");
|
|
@@ -642,13 +687,13 @@ var blocks_and_statements_default = {
|
|
|
642
687
|
const expressions = [
|
|
643
688
|
!hasInit ? ";" : path.node.initNodes[0].type === "local_variable_declaration" ? path.call(print, "initNodes", 0) : [printExpressionList(path.map(print, "initNodes")), ";"],
|
|
644
689
|
hasCondition ? [path.call(print, "conditionNode"), ";"] : ";",
|
|
645
|
-
hasUpdate ? printExpressionList(path.map(print, "updateNodes")) : ""
|
|
690
|
+
hasUpdate ? [line$6, printExpressionList(path.map(print, "updateNodes"))] : ifBreak$1("", " ")
|
|
646
691
|
];
|
|
647
692
|
const hasEmptyStatement = path.node.bodyNode.type === ";";
|
|
648
693
|
return [
|
|
649
694
|
danglingComments && [danglingComments, hardline$6],
|
|
650
695
|
"for ",
|
|
651
|
-
hasInit || hasCondition || hasUpdate ? group$6(indentInParentheses(join$6(line$6, expressions))) : "(;;)",
|
|
696
|
+
hasInit || hasCondition || hasUpdate ? group$6(indentInParentheses([join$6(line$6, expressions.slice(0, 2)), expressions[2]], options)) : "(;;)",
|
|
652
697
|
hasEmptyStatement ? ";" : [" ", path.call(print, "bodyNode")]
|
|
653
698
|
];
|
|
654
699
|
},
|
|
@@ -711,7 +756,7 @@ var blocks_and_statements_default = {
|
|
|
711
756
|
},
|
|
712
757
|
catch_clause(path, print, options) {
|
|
713
758
|
const catchFormalParameterIndex = path.node.namedChildren.findIndex(({ type }) => type === "catch_formal_parameter");
|
|
714
|
-
const params = group$6(indentInParentheses(path.call(print, "namedChildren", catchFormalParameterIndex)));
|
|
759
|
+
const params = group$6(indentInParentheses(path.call(print, "namedChildren", catchFormalParameterIndex), options));
|
|
715
760
|
const body = path.call(print, "bodyNode");
|
|
716
761
|
if (options?.braceStyle === "next-line") return [
|
|
717
762
|
hardline$6,
|
|
@@ -764,7 +809,7 @@ var blocks_and_statements_default = {
|
|
|
764
809
|
...clauses
|
|
765
810
|
]);
|
|
766
811
|
},
|
|
767
|
-
resource_specification(path, print) {
|
|
812
|
+
resource_specification(path, print, options) {
|
|
768
813
|
const resources = [];
|
|
769
814
|
let hasTrailingSemicolon = false;
|
|
770
815
|
path.each((child) => {
|
|
@@ -775,7 +820,7 @@ var blocks_and_statements_default = {
|
|
|
775
820
|
}, "children");
|
|
776
821
|
const parts = join$6([";", line$6], resources);
|
|
777
822
|
if (hasTrailingSemicolon) parts.push(ifBreak$1(";"));
|
|
778
|
-
return group$6(indentInParentheses(parts));
|
|
823
|
+
return group$6(indentInParentheses(parts, options));
|
|
779
824
|
},
|
|
780
825
|
resource(path, print) {
|
|
781
826
|
if (hasChild(path, "typeNode") && hasChild(path, "nameNode") && hasChild(path, "valueNode")) {
|
|
@@ -805,28 +850,28 @@ var blocks_and_statements_default = {
|
|
|
805
850
|
function printExpressionList(expressions) {
|
|
806
851
|
return group$6(expressions.map((expression, index) => index === 0 ? expression : [",", indent$6([line$6, expression])]));
|
|
807
852
|
}
|
|
808
|
-
function printReturnOrThrowArgument(path, print) {
|
|
853
|
+
function printReturnOrThrowArgument(path, print, options) {
|
|
809
854
|
const { node } = path;
|
|
810
855
|
const argumentDoc = print(path);
|
|
811
856
|
if (returnArgumentHasLeadingComment(node)) return [
|
|
812
857
|
"(",
|
|
813
858
|
indent$6([hardline$6, argumentDoc]),
|
|
814
|
-
hardline$6,
|
|
859
|
+
closingBracketLine(options, hardline$6),
|
|
815
860
|
")"
|
|
816
861
|
];
|
|
817
862
|
if (node.type === "binary_expression") return group$6([
|
|
818
863
|
ifBreak$1("("),
|
|
819
864
|
indent$6([softline$3, argumentDoc]),
|
|
820
|
-
|
|
865
|
+
closingBracketLine(options),
|
|
821
866
|
ifBreak$1(")")
|
|
822
867
|
]);
|
|
823
868
|
return argumentDoc;
|
|
824
869
|
}
|
|
825
|
-
function printReturnOrThrowStatement(path, print) {
|
|
870
|
+
function printReturnOrThrowStatement(path, print, options) {
|
|
826
871
|
const { node } = path;
|
|
827
872
|
return [
|
|
828
873
|
node.type === "throw_statement" ? "throw" : "return",
|
|
829
|
-
node.namedChildren.length ? [" ", path.call(() => printReturnOrThrowArgument(path, print), "namedChildren", 0)] : "",
|
|
874
|
+
node.namedChildren.length ? [" ", path.call(() => printReturnOrThrowArgument(path, print, options), "namedChildren", 0)] : "",
|
|
830
875
|
";"
|
|
831
876
|
];
|
|
832
877
|
}
|
|
@@ -844,7 +889,7 @@ var classes_default = {
|
|
|
844
889
|
const hasMultipleClauses = definedClauses.length > 1;
|
|
845
890
|
if (hasChild(path, "type_parametersNode")) {
|
|
846
891
|
const typeParameters = path.call(print, "type_parametersNode");
|
|
847
|
-
parts.push(hasMultipleClauses ? group$5(indent$5(typeParameters)) : typeParameters);
|
|
892
|
+
parts.push(hasMultipleClauses ? group$5(indent$5(typeParameters)) : options?.braceStyle === "next-line" ? group$5(typeParameters) : typeParameters);
|
|
848
893
|
}
|
|
849
894
|
if (definedClauses.length) {
|
|
850
895
|
const clauses = definedClauses.flatMap((clause) => {
|
|
@@ -910,14 +955,14 @@ var classes_default = {
|
|
|
910
955
|
receiver_parameter(path, print) {
|
|
911
956
|
return path.map((child) => child.isLast ? print(child) : [print(child), child.node.type === "identifier" ? "." : " "], "namedChildren");
|
|
912
957
|
},
|
|
913
|
-
formal_parameters(path, print) {
|
|
958
|
+
formal_parameters(path, print, options) {
|
|
914
959
|
const parameters = path.parent?.type === "record_declaration" ? printBodyDeclarations(path, print) : path.map(print, "namedChildren");
|
|
915
960
|
if (parameters.length === 0) return [
|
|
916
961
|
"(",
|
|
917
962
|
printDanglingCommentsInList(path),
|
|
918
963
|
")"
|
|
919
964
|
];
|
|
920
|
-
return indentInParentheses(join$5([",", line$5], parameters));
|
|
965
|
+
return indentInParentheses(join$5([",", line$5], parameters), options);
|
|
921
966
|
},
|
|
922
967
|
formal_parameter(path, print) {
|
|
923
968
|
const parameter = printModifiers(path, print, path.grandparent?.type === "record_declaration" ? "avoidBreak" : "noBreak");
|
|
@@ -986,12 +1031,12 @@ var classes_default = {
|
|
|
986
1031
|
if (modifiers.length || typeAnnotations.length) parts.push(join$5(" ", [...modifiers, ...typeAnnotations]));
|
|
987
1032
|
return join$5(annotationMode === "avoidBreak" ? line$5 : annotationMode === "noBreak" ? " " : hardline$5, parts);
|
|
988
1033
|
},
|
|
989
|
-
enum_declaration(path, print) {
|
|
1034
|
+
enum_declaration(path, print, options) {
|
|
990
1035
|
const modifiers = printModifiers(path, print, "declarationOnly");
|
|
991
1036
|
const parts = ["enum ", path.call(print, "nameNode")];
|
|
992
1037
|
if (hasChild(path, "interfacesNode")) {
|
|
993
1038
|
const hasBody = path.node.bodyNode.namedChildren.length > 0;
|
|
994
|
-
parts.push(indent$5([hardline$5, path.call(print, "interfacesNode")]), hasBody ? line$5 : " ");
|
|
1039
|
+
parts.push(indent$5([hardline$5, path.call(print, "interfacesNode")]), options?.braceStyle === "next-line" ? "" : hasBody ? line$5 : " ");
|
|
995
1040
|
} else parts.push(" ");
|
|
996
1041
|
return [
|
|
997
1042
|
...modifiers,
|
|
@@ -1100,7 +1145,7 @@ var expressions_default = {
|
|
|
1100
1145
|
const shouldPutBodyOnSameLine = !functionBody.comments?.some((comment) => comment.leading && hasNewline$1(options.originalText, comment.end.index)) && mayBreakAfterShortPrefix(functionBody);
|
|
1101
1146
|
const chainGroupId = Symbol("arrow-chain");
|
|
1102
1147
|
const signaturesDoc = printArrowFunctionSignatures(path, { signatureDocs });
|
|
1103
|
-
bodyDoc = printArrowFunctionBody(path, args, {
|
|
1148
|
+
bodyDoc = printArrowFunctionBody(path, args, options, {
|
|
1104
1149
|
bodyDoc,
|
|
1105
1150
|
bodyComments,
|
|
1106
1151
|
shouldPutBodyOnSameLine
|
|
@@ -1118,7 +1163,7 @@ var expressions_default = {
|
|
|
1118
1163
|
}, "namedChildren");
|
|
1119
1164
|
if (!identifiers.length) return "()";
|
|
1120
1165
|
const parameters = join$4([",", line$4], identifiers);
|
|
1121
|
-
if (identifiers.length > 1 || willBreak(identifiers)) return group$4(indentInParentheses(parameters));
|
|
1166
|
+
if (identifiers.length > 1 || willBreak(identifiers)) return group$4(indentInParentheses(parameters, options));
|
|
1122
1167
|
return options.arrowParens === "avoid" ? parameters : [
|
|
1123
1168
|
"(",
|
|
1124
1169
|
...parameters,
|
|
@@ -1159,9 +1204,9 @@ var expressions_default = {
|
|
|
1159
1204
|
const result = maybeGroup([
|
|
1160
1205
|
printTernaryTest(path, print),
|
|
1161
1206
|
forceNoIndent ? parts : indent$4(parts),
|
|
1162
|
-
breakClosingParen && !shouldExtraIndent ?
|
|
1207
|
+
breakClosingParen && !shouldExtraIndent ? closingBracketLine(options) : ""
|
|
1163
1208
|
]);
|
|
1164
|
-
return isParentTest || shouldExtraIndent ? group$4([indent$4([softline$1, result]),
|
|
1209
|
+
return isParentTest || shouldExtraIndent ? group$4([indent$4([softline$1, result]), closingBracketLine(options)]) : result;
|
|
1165
1210
|
},
|
|
1166
1211
|
assignment_expression(path, print) {
|
|
1167
1212
|
const { node } = path;
|
|
@@ -1174,7 +1219,7 @@ var expressions_default = {
|
|
|
1174
1219
|
const isInsideParentheses = (grandparent?.type === "if_statement" || grandparent?.type === "while_statement" || grandparent?.type === "switch_expression" || grandparent?.type === "do_statement") && grandparent.conditionNode === parent || grandparent?.type === "synchronized_statement" && grandparent.bodyNode !== parent;
|
|
1175
1220
|
const parts = printBinaryExpressions(path, print, options, isInsideParentheses);
|
|
1176
1221
|
if (isInsideParentheses) return parts;
|
|
1177
|
-
if (parent?.type === "unary_expression" && !node.comments || (parent?.type === "explicit_constructor_invocation" || parent?.type === "field_access" || parent?.type === "method_invocation") && parent.objectNode === node || parent?.type === "method_reference" || parent?.type === "object_creation_expression") return group$4([indent$4([softline$1, ...parts]),
|
|
1222
|
+
if (parent?.type === "unary_expression" && !node.comments || (parent?.type === "explicit_constructor_invocation" || parent?.type === "field_access" || parent?.type === "method_invocation") && parent.objectNode === node || parent?.type === "method_reference" || parent?.type === "object_creation_expression") return group$4([indent$4([softline$1, ...parts]), closingBracketLine(options)]);
|
|
1178
1223
|
if (isReturnOrThrowStatement(parent) || parent?.type === "assignment_expression" || parent?.type === "variable_declarator" || parent?.type === "guard" || parent?.type === "lambda_expression" && parent.bodyNode === node || parent?.type === "for_statement" && parent.conditionNode === node || parent?.type === "ternary_expression" && !isReturnOrThrowStatement(grandparent) && grandparent?.type !== "parenthesized_expression" && grandparent?.type !== "argument_list" || parent?.type === "unary_expression" && parent.operandNode === node) return group$4(parts);
|
|
1179
1224
|
if (parts.length === 0) return "";
|
|
1180
1225
|
const firstGroupIndex = parts.findIndex((part) => typeof part !== "string" && !Array.isArray(part) && part.type === "group");
|
|
@@ -1189,10 +1234,10 @@ var expressions_default = {
|
|
|
1189
1234
|
return [(options.experimentalOperatorPosition === "start" ? child.node.type === "instanceof" : child.previous.type === "instanceof") ? line$4 : " ", doc];
|
|
1190
1235
|
}, "children")));
|
|
1191
1236
|
},
|
|
1192
|
-
unary_expression(path, print) {
|
|
1237
|
+
unary_expression(path, print, options) {
|
|
1193
1238
|
const parts = [path.call(print, "operatorNode")];
|
|
1194
1239
|
const operandDoc = path.call(print, "operandNode");
|
|
1195
|
-
if (path.node.operandNode.comments) parts.push(group$4(indentInParentheses(operandDoc)));
|
|
1240
|
+
if (path.node.operandNode.comments) parts.push(group$4(indentInParentheses(operandDoc, options)));
|
|
1196
1241
|
else parts.push(operandDoc);
|
|
1197
1242
|
return parts;
|
|
1198
1243
|
},
|
|
@@ -1202,7 +1247,7 @@ var expressions_default = {
|
|
|
1202
1247
|
const typeArgumentsIndex = path.node.namedChildren.findIndex(({ type }) => type === "type_arguments");
|
|
1203
1248
|
return [path.call(print, "namedChildren", typeIdentifierIndex), path.call(print, "namedChildren", typeArgumentsIndex)];
|
|
1204
1249
|
},
|
|
1205
|
-
parenthesized_expression(path, print) {
|
|
1250
|
+
parenthesized_expression(path, print, options) {
|
|
1206
1251
|
const expression = path.call(print, "namedChildren", 0);
|
|
1207
1252
|
const parentType = path.parent?.type;
|
|
1208
1253
|
const grandparentType = path.grandparent?.type;
|
|
@@ -1211,12 +1256,12 @@ var expressions_default = {
|
|
|
1211
1256
|
const hasTernary = expressionType === "ternary_expression";
|
|
1212
1257
|
const hasSuffix = parentType && (parentType === "array_access" || parentType === "explicit_constructor_invocation" || parentType === "field_access" || parentType === "method_invocation" || parentType === "method_reference" || parentType === "object_creation_expression");
|
|
1213
1258
|
const isAssignment = parentType && (parentType === "assignment_expression" || parentType === "variable_declarator") || hasSuffix && (grandparentType === "assignment_expression" || grandparentType === "variable_declarator");
|
|
1214
|
-
if (!hasLambda && hasSuffix && (!hasTernary || isAssignment)) return group$4(indentInParentheses(hasTernary ? group$4(expression) : expression));
|
|
1215
|
-
else if (parentType && (parentType === "guard" || parentType === "return_statement" || parentType === "unary_expression" && grandparentType === "return_statement" || path.node.fieldName === "condition" && (parentType === "do_statement" || parentType === "if_statement" || parentType === "switch_expression" || parentType === "while_statement") || path.node.fieldName !== "body" && parentType === "synchronized_statement")) return group$4(indentInParentheses(group$4(expression)));
|
|
1259
|
+
if (!hasLambda && hasSuffix && (!hasTernary || isAssignment)) return group$4(indentInParentheses(hasTernary ? group$4(expression) : expression, options));
|
|
1260
|
+
else if (parentType && (parentType === "guard" || parentType === "return_statement" || parentType === "unary_expression" && grandparentType === "return_statement" || path.node.fieldName === "condition" && (parentType === "do_statement" || parentType === "if_statement" || parentType === "switch_expression" || parentType === "while_statement") || path.node.fieldName !== "body" && parentType === "synchronized_statement")) return group$4(indentInParentheses(group$4(expression), options));
|
|
1216
1261
|
else if (hasTernary && hasSuffix && !isAssignment) return group$4([
|
|
1217
1262
|
"(",
|
|
1218
1263
|
expression,
|
|
1219
|
-
|
|
1264
|
+
closingBracketLine(options),
|
|
1220
1265
|
")"
|
|
1221
1266
|
]);
|
|
1222
1267
|
else return group$4([
|
|
@@ -1259,7 +1304,7 @@ var expressions_default = {
|
|
|
1259
1304
|
const args = path.node.namedChildren;
|
|
1260
1305
|
if (args.length === 0) {
|
|
1261
1306
|
const shouldBreak = path.node.comments?.some(({ type, leading, trailing }) => !leading && !trailing && type === "line_comment");
|
|
1262
|
-
return group$4(indentInParentheses(printDanglingComments(path)), { shouldBreak });
|
|
1307
|
+
return group$4(indentInParentheses(printDanglingComments(path), options), { shouldBreak });
|
|
1263
1308
|
}
|
|
1264
1309
|
const lastArgIndex = args.length - 1;
|
|
1265
1310
|
let anyArgEmptyLine = false;
|
|
@@ -1285,7 +1330,7 @@ var expressions_default = {
|
|
|
1285
1330
|
return group$4([
|
|
1286
1331
|
"(",
|
|
1287
1332
|
indent$4([line$4, ...printedArguments]),
|
|
1288
|
-
line$4,
|
|
1333
|
+
closingBracketLine(options, line$4),
|
|
1289
1334
|
")"
|
|
1290
1335
|
], { shouldBreak: true });
|
|
1291
1336
|
}
|
|
@@ -1357,7 +1402,7 @@ var expressions_default = {
|
|
|
1357
1402
|
allArgsBrokenOut()
|
|
1358
1403
|
]);
|
|
1359
1404
|
}
|
|
1360
|
-
return group$4(indentInParentheses(printedArguments), { shouldBreak: printedArguments.some(willBreak) || anyArgEmptyLine });
|
|
1405
|
+
return group$4(indentInParentheses(printedArguments, options), { shouldBreak: printedArguments.some(willBreak) || anyArgEmptyLine });
|
|
1361
1406
|
},
|
|
1362
1407
|
array_creation_expression(path, print) {
|
|
1363
1408
|
const parts = ["new "];
|
|
@@ -1398,8 +1443,8 @@ var expressions_default = {
|
|
|
1398
1443
|
record_pattern(path, print) {
|
|
1399
1444
|
return path.map(print, "children");
|
|
1400
1445
|
},
|
|
1401
|
-
record_pattern_body(path, print) {
|
|
1402
|
-
return group$4(indentInParentheses(join$4([",", line$4], path.map(print, "namedChildren"))));
|
|
1446
|
+
record_pattern_body(path, print, options) {
|
|
1447
|
+
return group$4(indentInParentheses(join$4([",", line$4], path.map(print, "namedChildren")), options));
|
|
1403
1448
|
},
|
|
1404
1449
|
record_pattern_component(path, print) {
|
|
1405
1450
|
return join$4(" ", path.map(print, "children"));
|
|
@@ -1451,8 +1496,8 @@ function printArrowFunctionSignatures(path, { signatureDocs }) {
|
|
|
1451
1496
|
if (node.fieldName === "object" && parent?.type === "method_invocation") return group$4(join$4([" ->", line$4], signatureDocs));
|
|
1452
1497
|
return group$4(indent$4(join$4([" ->", line$4], signatureDocs)));
|
|
1453
1498
|
}
|
|
1454
|
-
function printArrowFunctionBody(path, args, { bodyDoc, bodyComments, shouldPutBodyOnSameLine }) {
|
|
1455
|
-
const trailingSpace = args && typeof args === "object" && "expandLastArg" in args && args.expandLastArg && !path.node.comments ?
|
|
1499
|
+
function printArrowFunctionBody(path, args, options, { bodyDoc, bodyComments, shouldPutBodyOnSameLine }) {
|
|
1500
|
+
const trailingSpace = args && typeof args === "object" && "expandLastArg" in args && args.expandLastArg && !path.node.comments ? closingBracketLine(options) : "";
|
|
1456
1501
|
return shouldPutBodyOnSameLine ? [
|
|
1457
1502
|
" ",
|
|
1458
1503
|
bodyDoc,
|
|
@@ -1809,7 +1854,7 @@ var interfaces_default = {
|
|
|
1809
1854
|
const hasMultipleClauses = hasExtendsInterfaces && hasPermits;
|
|
1810
1855
|
if (hasChild(path, "type_parametersNode")) {
|
|
1811
1856
|
const typeParameters = path.call(print, "type_parametersNode");
|
|
1812
|
-
parts.push(hasMultipleClauses ? group$3(indent$3(typeParameters)) : typeParameters);
|
|
1857
|
+
parts.push(hasMultipleClauses ? group$3(indent$3(typeParameters)) : options?.braceStyle === "next-line" ? group$3(typeParameters) : typeParameters);
|
|
1813
1858
|
}
|
|
1814
1859
|
if (hasExtendsInterfaces || hasPermits) {
|
|
1815
1860
|
const clauses = [];
|
|
@@ -1859,13 +1904,13 @@ var interfaces_default = {
|
|
|
1859
1904
|
marker_annotation(path, print) {
|
|
1860
1905
|
return ["@", path.call(print, "nameNode")];
|
|
1861
1906
|
},
|
|
1862
|
-
annotation_argument_list(path, print) {
|
|
1907
|
+
annotation_argument_list(path, print, options) {
|
|
1863
1908
|
const args = path.map(print, "namedChildren");
|
|
1864
1909
|
return args.length === 1 && path.node.namedChildren[0].type === "element_value_array_initializer" ? [
|
|
1865
1910
|
"(",
|
|
1866
1911
|
args[0],
|
|
1867
1912
|
")"
|
|
1868
|
-
] : group$3(indentInParentheses(join$3([",", line$3], args)));
|
|
1913
|
+
] : group$3(indentInParentheses(join$3([",", line$3], args), options));
|
|
1869
1914
|
},
|
|
1870
1915
|
element_value_pair(path, print) {
|
|
1871
1916
|
return group$3([
|
package/dist/index.d.cts
CHANGED
|
@@ -1631,6 +1631,26 @@ declare const _default: {
|
|
|
1631
1631
|
}[];
|
|
1632
1632
|
description: string;
|
|
1633
1633
|
};
|
|
1634
|
+
arrayInitializerLayout: {
|
|
1635
|
+
type: "choice";
|
|
1636
|
+
category: string;
|
|
1637
|
+
default: string;
|
|
1638
|
+
choices: {
|
|
1639
|
+
value: string;
|
|
1640
|
+
description: string;
|
|
1641
|
+
}[];
|
|
1642
|
+
description: string;
|
|
1643
|
+
};
|
|
1644
|
+
closingBracket: {
|
|
1645
|
+
type: "choice";
|
|
1646
|
+
category: string;
|
|
1647
|
+
default: string;
|
|
1648
|
+
choices: {
|
|
1649
|
+
value: string;
|
|
1650
|
+
description: string;
|
|
1651
|
+
}[];
|
|
1652
|
+
description: string;
|
|
1653
|
+
};
|
|
1634
1654
|
importOrder: {
|
|
1635
1655
|
type: "string";
|
|
1636
1656
|
category: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -1631,6 +1631,26 @@ declare const _default: {
|
|
|
1631
1631
|
}[];
|
|
1632
1632
|
description: string;
|
|
1633
1633
|
};
|
|
1634
|
+
arrayInitializerLayout: {
|
|
1635
|
+
type: "choice";
|
|
1636
|
+
category: string;
|
|
1637
|
+
default: string;
|
|
1638
|
+
choices: {
|
|
1639
|
+
value: string;
|
|
1640
|
+
description: string;
|
|
1641
|
+
}[];
|
|
1642
|
+
description: string;
|
|
1643
|
+
};
|
|
1644
|
+
closingBracket: {
|
|
1645
|
+
type: "choice";
|
|
1646
|
+
category: string;
|
|
1647
|
+
default: string;
|
|
1648
|
+
choices: {
|
|
1649
|
+
value: string;
|
|
1650
|
+
description: string;
|
|
1651
|
+
}[];
|
|
1652
|
+
description: string;
|
|
1653
|
+
};
|
|
1634
1654
|
importOrder: {
|
|
1635
1655
|
type: "string";
|
|
1636
1656
|
category: string;
|
package/dist/index.mjs
CHANGED
|
@@ -62,6 +62,32 @@ var options_default = {
|
|
|
62
62
|
}],
|
|
63
63
|
description: "Placement of opening braces."
|
|
64
64
|
},
|
|
65
|
+
arrayInitializerLayout: {
|
|
66
|
+
type: "choice",
|
|
67
|
+
category: "Java",
|
|
68
|
+
default: "always-break",
|
|
69
|
+
choices: [{
|
|
70
|
+
value: "always-break",
|
|
71
|
+
description: "Put each array element on its own line"
|
|
72
|
+
}, {
|
|
73
|
+
value: "fit",
|
|
74
|
+
description: "Keep array initializers on one line when they fit"
|
|
75
|
+
}],
|
|
76
|
+
description: "Layout of array initializers when braceStyle is next-line."
|
|
77
|
+
},
|
|
78
|
+
closingBracket: {
|
|
79
|
+
type: "choice",
|
|
80
|
+
category: "Java",
|
|
81
|
+
default: "next-line",
|
|
82
|
+
choices: [{
|
|
83
|
+
value: "next-line",
|
|
84
|
+
description: "Put the closing parenthesis or angle bracket of a wrapped list on its own line"
|
|
85
|
+
}, {
|
|
86
|
+
value: "same-line",
|
|
87
|
+
description: "Keep the closing parenthesis or angle bracket on the last line of a wrapped list"
|
|
88
|
+
}],
|
|
89
|
+
description: "Placement of the closing parenthesis or angle bracket when a list wraps."
|
|
90
|
+
},
|
|
65
91
|
importOrder: {
|
|
66
92
|
type: "string",
|
|
67
93
|
category: "Java",
|
|
@@ -134,11 +160,14 @@ function hasLeadingComments(node) {
|
|
|
134
160
|
function hasDanglingComments(node) {
|
|
135
161
|
return node.comments?.some(({ leading, trailing }) => !leading && !trailing) ?? false;
|
|
136
162
|
}
|
|
137
|
-
function
|
|
163
|
+
function closingBracketLine(options, lineDoc = softline$4) {
|
|
164
|
+
return options?.closingBracket === "same-line" ? "" : lineDoc;
|
|
165
|
+
}
|
|
166
|
+
function indentInParentheses(contents, options) {
|
|
138
167
|
return contents && !Array.isArray(contents) || contents.length ? [
|
|
139
168
|
"(",
|
|
140
169
|
indent$7([softline$4, contents]),
|
|
141
|
-
|
|
170
|
+
closingBracketLine(options),
|
|
142
171
|
")"
|
|
143
172
|
] : "()";
|
|
144
173
|
}
|
|
@@ -157,6 +186,16 @@ function printArrayInitializer(path, print, options) {
|
|
|
157
186
|
const list = join$7([",", line$7], path.map(print, "namedChildren"));
|
|
158
187
|
if (list.length && options.trailingComma !== "none") list.push(ifBreak$2(","));
|
|
159
188
|
if (options.braceStyle === "next-line" && path.node.type === "array_initializer") {
|
|
189
|
+
if (options.arrayInitializerLayout === "fit") {
|
|
190
|
+
const bracketLine = options.bracketSpacing ? line$7 : softline$4;
|
|
191
|
+
const block = [
|
|
192
|
+
"{",
|
|
193
|
+
indent$7([bracketLine, ...list]),
|
|
194
|
+
bracketLine,
|
|
195
|
+
"}"
|
|
196
|
+
];
|
|
197
|
+
return group$7(isNestedArray(path) ? block : [softline$4, ...block]);
|
|
198
|
+
}
|
|
160
199
|
const block = [
|
|
161
200
|
"{",
|
|
162
201
|
indent$7([line$7, ...list]),
|
|
@@ -219,12 +258,18 @@ function printBlock(path, contents, options) {
|
|
|
219
258
|
}
|
|
220
259
|
function printBlockNextLine(path, contents) {
|
|
221
260
|
const parentType = path.parent?.type;
|
|
222
|
-
const
|
|
261
|
+
const isChildOfBodyDeclaration = parentType != null && [
|
|
223
262
|
"annotation_type_body",
|
|
224
263
|
"class_body",
|
|
225
264
|
"enum_body",
|
|
226
265
|
"interface_body"
|
|
227
|
-
].includes(parentType)
|
|
266
|
+
].includes(parentType);
|
|
267
|
+
const isBlockStatement = parentType != null && [
|
|
268
|
+
"block",
|
|
269
|
+
"constructor_body",
|
|
270
|
+
"switch_block_statement_group"
|
|
271
|
+
].includes(parentType);
|
|
272
|
+
const prefix = isChildOfBodyDeclaration || isBlockStatement ? [] : [hardline$7];
|
|
228
273
|
if (contents.length) return [
|
|
229
274
|
...prefix,
|
|
230
275
|
"{",
|
|
@@ -275,7 +320,7 @@ function printBodyDeclarations(path, print, padFirst = false) {
|
|
|
275
320
|
return blankLine ? [separator, declaration] : declaration;
|
|
276
321
|
}, "namedChildren");
|
|
277
322
|
}
|
|
278
|
-
function printTypeParameters(path, print) {
|
|
323
|
+
function printTypeParameters(path, print, options) {
|
|
279
324
|
const parameters = path.node.namedChildren;
|
|
280
325
|
if (parameters.length === 0 || parameters.length === 1 && isSimpleType(parameters[0]) && !parameters.some(({ comments }) => comments?.length && comments.some(({ type }) => type === "line_comment"))) return [
|
|
281
326
|
"<",
|
|
@@ -285,7 +330,7 @@ function printTypeParameters(path, print) {
|
|
|
285
330
|
const parts = [
|
|
286
331
|
"<",
|
|
287
332
|
indent$7([softline$4, join$7([",", line$7], path.map(print, "namedChildren"))]),
|
|
288
|
-
|
|
333
|
+
closingBracketLine(options),
|
|
289
334
|
">"
|
|
290
335
|
];
|
|
291
336
|
return path.node.type === "type_arguments" ? group$7(parts) : parts;
|
|
@@ -634,7 +679,7 @@ var blocks_and_statements_default = {
|
|
|
634
679
|
";"
|
|
635
680
|
];
|
|
636
681
|
},
|
|
637
|
-
for_statement(path, print) {
|
|
682
|
+
for_statement(path, print, options) {
|
|
638
683
|
const danglingComments = printDanglingComments(path);
|
|
639
684
|
const hasInit = path.node.initNodes.length > 0;
|
|
640
685
|
const hasCondition = hasChild(path, "conditionNode");
|
|
@@ -642,13 +687,13 @@ var blocks_and_statements_default = {
|
|
|
642
687
|
const expressions = [
|
|
643
688
|
!hasInit ? ";" : path.node.initNodes[0].type === "local_variable_declaration" ? path.call(print, "initNodes", 0) : [printExpressionList(path.map(print, "initNodes")), ";"],
|
|
644
689
|
hasCondition ? [path.call(print, "conditionNode"), ";"] : ";",
|
|
645
|
-
hasUpdate ? printExpressionList(path.map(print, "updateNodes")) : ""
|
|
690
|
+
hasUpdate ? [line$6, printExpressionList(path.map(print, "updateNodes"))] : ifBreak$1("", " ")
|
|
646
691
|
];
|
|
647
692
|
const hasEmptyStatement = path.node.bodyNode.type === ";";
|
|
648
693
|
return [
|
|
649
694
|
danglingComments && [danglingComments, hardline$6],
|
|
650
695
|
"for ",
|
|
651
|
-
hasInit || hasCondition || hasUpdate ? group$6(indentInParentheses(join$6(line$6, expressions))) : "(;;)",
|
|
696
|
+
hasInit || hasCondition || hasUpdate ? group$6(indentInParentheses([join$6(line$6, expressions.slice(0, 2)), expressions[2]], options)) : "(;;)",
|
|
652
697
|
hasEmptyStatement ? ";" : [" ", path.call(print, "bodyNode")]
|
|
653
698
|
];
|
|
654
699
|
},
|
|
@@ -711,7 +756,7 @@ var blocks_and_statements_default = {
|
|
|
711
756
|
},
|
|
712
757
|
catch_clause(path, print, options) {
|
|
713
758
|
const catchFormalParameterIndex = path.node.namedChildren.findIndex(({ type }) => type === "catch_formal_parameter");
|
|
714
|
-
const params = group$6(indentInParentheses(path.call(print, "namedChildren", catchFormalParameterIndex)));
|
|
759
|
+
const params = group$6(indentInParentheses(path.call(print, "namedChildren", catchFormalParameterIndex), options));
|
|
715
760
|
const body = path.call(print, "bodyNode");
|
|
716
761
|
if (options?.braceStyle === "next-line") return [
|
|
717
762
|
hardline$6,
|
|
@@ -764,7 +809,7 @@ var blocks_and_statements_default = {
|
|
|
764
809
|
...clauses
|
|
765
810
|
]);
|
|
766
811
|
},
|
|
767
|
-
resource_specification(path, print) {
|
|
812
|
+
resource_specification(path, print, options) {
|
|
768
813
|
const resources = [];
|
|
769
814
|
let hasTrailingSemicolon = false;
|
|
770
815
|
path.each((child) => {
|
|
@@ -775,7 +820,7 @@ var blocks_and_statements_default = {
|
|
|
775
820
|
}, "children");
|
|
776
821
|
const parts = join$6([";", line$6], resources);
|
|
777
822
|
if (hasTrailingSemicolon) parts.push(ifBreak$1(";"));
|
|
778
|
-
return group$6(indentInParentheses(parts));
|
|
823
|
+
return group$6(indentInParentheses(parts, options));
|
|
779
824
|
},
|
|
780
825
|
resource(path, print) {
|
|
781
826
|
if (hasChild(path, "typeNode") && hasChild(path, "nameNode") && hasChild(path, "valueNode")) {
|
|
@@ -805,28 +850,28 @@ var blocks_and_statements_default = {
|
|
|
805
850
|
function printExpressionList(expressions) {
|
|
806
851
|
return group$6(expressions.map((expression, index) => index === 0 ? expression : [",", indent$6([line$6, expression])]));
|
|
807
852
|
}
|
|
808
|
-
function printReturnOrThrowArgument(path, print) {
|
|
853
|
+
function printReturnOrThrowArgument(path, print, options) {
|
|
809
854
|
const { node } = path;
|
|
810
855
|
const argumentDoc = print(path);
|
|
811
856
|
if (returnArgumentHasLeadingComment(node)) return [
|
|
812
857
|
"(",
|
|
813
858
|
indent$6([hardline$6, argumentDoc]),
|
|
814
|
-
hardline$6,
|
|
859
|
+
closingBracketLine(options, hardline$6),
|
|
815
860
|
")"
|
|
816
861
|
];
|
|
817
862
|
if (node.type === "binary_expression") return group$6([
|
|
818
863
|
ifBreak$1("("),
|
|
819
864
|
indent$6([softline$3, argumentDoc]),
|
|
820
|
-
|
|
865
|
+
closingBracketLine(options),
|
|
821
866
|
ifBreak$1(")")
|
|
822
867
|
]);
|
|
823
868
|
return argumentDoc;
|
|
824
869
|
}
|
|
825
|
-
function printReturnOrThrowStatement(path, print) {
|
|
870
|
+
function printReturnOrThrowStatement(path, print, options) {
|
|
826
871
|
const { node } = path;
|
|
827
872
|
return [
|
|
828
873
|
node.type === "throw_statement" ? "throw" : "return",
|
|
829
|
-
node.namedChildren.length ? [" ", path.call(() => printReturnOrThrowArgument(path, print), "namedChildren", 0)] : "",
|
|
874
|
+
node.namedChildren.length ? [" ", path.call(() => printReturnOrThrowArgument(path, print, options), "namedChildren", 0)] : "",
|
|
830
875
|
";"
|
|
831
876
|
];
|
|
832
877
|
}
|
|
@@ -844,7 +889,7 @@ var classes_default = {
|
|
|
844
889
|
const hasMultipleClauses = definedClauses.length > 1;
|
|
845
890
|
if (hasChild(path, "type_parametersNode")) {
|
|
846
891
|
const typeParameters = path.call(print, "type_parametersNode");
|
|
847
|
-
parts.push(hasMultipleClauses ? group$5(indent$5(typeParameters)) : typeParameters);
|
|
892
|
+
parts.push(hasMultipleClauses ? group$5(indent$5(typeParameters)) : options?.braceStyle === "next-line" ? group$5(typeParameters) : typeParameters);
|
|
848
893
|
}
|
|
849
894
|
if (definedClauses.length) {
|
|
850
895
|
const clauses = definedClauses.flatMap((clause) => {
|
|
@@ -910,14 +955,14 @@ var classes_default = {
|
|
|
910
955
|
receiver_parameter(path, print) {
|
|
911
956
|
return path.map((child) => child.isLast ? print(child) : [print(child), child.node.type === "identifier" ? "." : " "], "namedChildren");
|
|
912
957
|
},
|
|
913
|
-
formal_parameters(path, print) {
|
|
958
|
+
formal_parameters(path, print, options) {
|
|
914
959
|
const parameters = path.parent?.type === "record_declaration" ? printBodyDeclarations(path, print) : path.map(print, "namedChildren");
|
|
915
960
|
if (parameters.length === 0) return [
|
|
916
961
|
"(",
|
|
917
962
|
printDanglingCommentsInList(path),
|
|
918
963
|
")"
|
|
919
964
|
];
|
|
920
|
-
return indentInParentheses(join$5([",", line$5], parameters));
|
|
965
|
+
return indentInParentheses(join$5([",", line$5], parameters), options);
|
|
921
966
|
},
|
|
922
967
|
formal_parameter(path, print) {
|
|
923
968
|
const parameter = printModifiers(path, print, path.grandparent?.type === "record_declaration" ? "avoidBreak" : "noBreak");
|
|
@@ -986,12 +1031,12 @@ var classes_default = {
|
|
|
986
1031
|
if (modifiers.length || typeAnnotations.length) parts.push(join$5(" ", [...modifiers, ...typeAnnotations]));
|
|
987
1032
|
return join$5(annotationMode === "avoidBreak" ? line$5 : annotationMode === "noBreak" ? " " : hardline$5, parts);
|
|
988
1033
|
},
|
|
989
|
-
enum_declaration(path, print) {
|
|
1034
|
+
enum_declaration(path, print, options) {
|
|
990
1035
|
const modifiers = printModifiers(path, print, "declarationOnly");
|
|
991
1036
|
const parts = ["enum ", path.call(print, "nameNode")];
|
|
992
1037
|
if (hasChild(path, "interfacesNode")) {
|
|
993
1038
|
const hasBody = path.node.bodyNode.namedChildren.length > 0;
|
|
994
|
-
parts.push(indent$5([hardline$5, path.call(print, "interfacesNode")]), hasBody ? line$5 : " ");
|
|
1039
|
+
parts.push(indent$5([hardline$5, path.call(print, "interfacesNode")]), options?.braceStyle === "next-line" ? "" : hasBody ? line$5 : " ");
|
|
995
1040
|
} else parts.push(" ");
|
|
996
1041
|
return [
|
|
997
1042
|
...modifiers,
|
|
@@ -1100,7 +1145,7 @@ var expressions_default = {
|
|
|
1100
1145
|
const shouldPutBodyOnSameLine = !functionBody.comments?.some((comment) => comment.leading && hasNewline$1(options.originalText, comment.end.index)) && mayBreakAfterShortPrefix(functionBody);
|
|
1101
1146
|
const chainGroupId = Symbol("arrow-chain");
|
|
1102
1147
|
const signaturesDoc = printArrowFunctionSignatures(path, { signatureDocs });
|
|
1103
|
-
bodyDoc = printArrowFunctionBody(path, args, {
|
|
1148
|
+
bodyDoc = printArrowFunctionBody(path, args, options, {
|
|
1104
1149
|
bodyDoc,
|
|
1105
1150
|
bodyComments,
|
|
1106
1151
|
shouldPutBodyOnSameLine
|
|
@@ -1118,7 +1163,7 @@ var expressions_default = {
|
|
|
1118
1163
|
}, "namedChildren");
|
|
1119
1164
|
if (!identifiers.length) return "()";
|
|
1120
1165
|
const parameters = join$4([",", line$4], identifiers);
|
|
1121
|
-
if (identifiers.length > 1 || willBreak(identifiers)) return group$4(indentInParentheses(parameters));
|
|
1166
|
+
if (identifiers.length > 1 || willBreak(identifiers)) return group$4(indentInParentheses(parameters, options));
|
|
1122
1167
|
return options.arrowParens === "avoid" ? parameters : [
|
|
1123
1168
|
"(",
|
|
1124
1169
|
...parameters,
|
|
@@ -1159,9 +1204,9 @@ var expressions_default = {
|
|
|
1159
1204
|
const result = maybeGroup([
|
|
1160
1205
|
printTernaryTest(path, print),
|
|
1161
1206
|
forceNoIndent ? parts : indent$4(parts),
|
|
1162
|
-
breakClosingParen && !shouldExtraIndent ?
|
|
1207
|
+
breakClosingParen && !shouldExtraIndent ? closingBracketLine(options) : ""
|
|
1163
1208
|
]);
|
|
1164
|
-
return isParentTest || shouldExtraIndent ? group$4([indent$4([softline$1, result]),
|
|
1209
|
+
return isParentTest || shouldExtraIndent ? group$4([indent$4([softline$1, result]), closingBracketLine(options)]) : result;
|
|
1165
1210
|
},
|
|
1166
1211
|
assignment_expression(path, print) {
|
|
1167
1212
|
const { node } = path;
|
|
@@ -1174,7 +1219,7 @@ var expressions_default = {
|
|
|
1174
1219
|
const isInsideParentheses = (grandparent?.type === "if_statement" || grandparent?.type === "while_statement" || grandparent?.type === "switch_expression" || grandparent?.type === "do_statement") && grandparent.conditionNode === parent || grandparent?.type === "synchronized_statement" && grandparent.bodyNode !== parent;
|
|
1175
1220
|
const parts = printBinaryExpressions(path, print, options, isInsideParentheses);
|
|
1176
1221
|
if (isInsideParentheses) return parts;
|
|
1177
|
-
if (parent?.type === "unary_expression" && !node.comments || (parent?.type === "explicit_constructor_invocation" || parent?.type === "field_access" || parent?.type === "method_invocation") && parent.objectNode === node || parent?.type === "method_reference" || parent?.type === "object_creation_expression") return group$4([indent$4([softline$1, ...parts]),
|
|
1222
|
+
if (parent?.type === "unary_expression" && !node.comments || (parent?.type === "explicit_constructor_invocation" || parent?.type === "field_access" || parent?.type === "method_invocation") && parent.objectNode === node || parent?.type === "method_reference" || parent?.type === "object_creation_expression") return group$4([indent$4([softline$1, ...parts]), closingBracketLine(options)]);
|
|
1178
1223
|
if (isReturnOrThrowStatement(parent) || parent?.type === "assignment_expression" || parent?.type === "variable_declarator" || parent?.type === "guard" || parent?.type === "lambda_expression" && parent.bodyNode === node || parent?.type === "for_statement" && parent.conditionNode === node || parent?.type === "ternary_expression" && !isReturnOrThrowStatement(grandparent) && grandparent?.type !== "parenthesized_expression" && grandparent?.type !== "argument_list" || parent?.type === "unary_expression" && parent.operandNode === node) return group$4(parts);
|
|
1179
1224
|
if (parts.length === 0) return "";
|
|
1180
1225
|
const firstGroupIndex = parts.findIndex((part) => typeof part !== "string" && !Array.isArray(part) && part.type === "group");
|
|
@@ -1189,10 +1234,10 @@ var expressions_default = {
|
|
|
1189
1234
|
return [(options.experimentalOperatorPosition === "start" ? child.node.type === "instanceof" : child.previous.type === "instanceof") ? line$4 : " ", doc];
|
|
1190
1235
|
}, "children")));
|
|
1191
1236
|
},
|
|
1192
|
-
unary_expression(path, print) {
|
|
1237
|
+
unary_expression(path, print, options) {
|
|
1193
1238
|
const parts = [path.call(print, "operatorNode")];
|
|
1194
1239
|
const operandDoc = path.call(print, "operandNode");
|
|
1195
|
-
if (path.node.operandNode.comments) parts.push(group$4(indentInParentheses(operandDoc)));
|
|
1240
|
+
if (path.node.operandNode.comments) parts.push(group$4(indentInParentheses(operandDoc, options)));
|
|
1196
1241
|
else parts.push(operandDoc);
|
|
1197
1242
|
return parts;
|
|
1198
1243
|
},
|
|
@@ -1202,7 +1247,7 @@ var expressions_default = {
|
|
|
1202
1247
|
const typeArgumentsIndex = path.node.namedChildren.findIndex(({ type }) => type === "type_arguments");
|
|
1203
1248
|
return [path.call(print, "namedChildren", typeIdentifierIndex), path.call(print, "namedChildren", typeArgumentsIndex)];
|
|
1204
1249
|
},
|
|
1205
|
-
parenthesized_expression(path, print) {
|
|
1250
|
+
parenthesized_expression(path, print, options) {
|
|
1206
1251
|
const expression = path.call(print, "namedChildren", 0);
|
|
1207
1252
|
const parentType = path.parent?.type;
|
|
1208
1253
|
const grandparentType = path.grandparent?.type;
|
|
@@ -1211,12 +1256,12 @@ var expressions_default = {
|
|
|
1211
1256
|
const hasTernary = expressionType === "ternary_expression";
|
|
1212
1257
|
const hasSuffix = parentType && (parentType === "array_access" || parentType === "explicit_constructor_invocation" || parentType === "field_access" || parentType === "method_invocation" || parentType === "method_reference" || parentType === "object_creation_expression");
|
|
1213
1258
|
const isAssignment = parentType && (parentType === "assignment_expression" || parentType === "variable_declarator") || hasSuffix && (grandparentType === "assignment_expression" || grandparentType === "variable_declarator");
|
|
1214
|
-
if (!hasLambda && hasSuffix && (!hasTernary || isAssignment)) return group$4(indentInParentheses(hasTernary ? group$4(expression) : expression));
|
|
1215
|
-
else if (parentType && (parentType === "guard" || parentType === "return_statement" || parentType === "unary_expression" && grandparentType === "return_statement" || path.node.fieldName === "condition" && (parentType === "do_statement" || parentType === "if_statement" || parentType === "switch_expression" || parentType === "while_statement") || path.node.fieldName !== "body" && parentType === "synchronized_statement")) return group$4(indentInParentheses(group$4(expression)));
|
|
1259
|
+
if (!hasLambda && hasSuffix && (!hasTernary || isAssignment)) return group$4(indentInParentheses(hasTernary ? group$4(expression) : expression, options));
|
|
1260
|
+
else if (parentType && (parentType === "guard" || parentType === "return_statement" || parentType === "unary_expression" && grandparentType === "return_statement" || path.node.fieldName === "condition" && (parentType === "do_statement" || parentType === "if_statement" || parentType === "switch_expression" || parentType === "while_statement") || path.node.fieldName !== "body" && parentType === "synchronized_statement")) return group$4(indentInParentheses(group$4(expression), options));
|
|
1216
1261
|
else if (hasTernary && hasSuffix && !isAssignment) return group$4([
|
|
1217
1262
|
"(",
|
|
1218
1263
|
expression,
|
|
1219
|
-
|
|
1264
|
+
closingBracketLine(options),
|
|
1220
1265
|
")"
|
|
1221
1266
|
]);
|
|
1222
1267
|
else return group$4([
|
|
@@ -1259,7 +1304,7 @@ var expressions_default = {
|
|
|
1259
1304
|
const args = path.node.namedChildren;
|
|
1260
1305
|
if (args.length === 0) {
|
|
1261
1306
|
const shouldBreak = path.node.comments?.some(({ type, leading, trailing }) => !leading && !trailing && type === "line_comment");
|
|
1262
|
-
return group$4(indentInParentheses(printDanglingComments(path)), { shouldBreak });
|
|
1307
|
+
return group$4(indentInParentheses(printDanglingComments(path), options), { shouldBreak });
|
|
1263
1308
|
}
|
|
1264
1309
|
const lastArgIndex = args.length - 1;
|
|
1265
1310
|
let anyArgEmptyLine = false;
|
|
@@ -1285,7 +1330,7 @@ var expressions_default = {
|
|
|
1285
1330
|
return group$4([
|
|
1286
1331
|
"(",
|
|
1287
1332
|
indent$4([line$4, ...printedArguments]),
|
|
1288
|
-
line$4,
|
|
1333
|
+
closingBracketLine(options, line$4),
|
|
1289
1334
|
")"
|
|
1290
1335
|
], { shouldBreak: true });
|
|
1291
1336
|
}
|
|
@@ -1357,7 +1402,7 @@ var expressions_default = {
|
|
|
1357
1402
|
allArgsBrokenOut()
|
|
1358
1403
|
]);
|
|
1359
1404
|
}
|
|
1360
|
-
return group$4(indentInParentheses(printedArguments), { shouldBreak: printedArguments.some(willBreak) || anyArgEmptyLine });
|
|
1405
|
+
return group$4(indentInParentheses(printedArguments, options), { shouldBreak: printedArguments.some(willBreak) || anyArgEmptyLine });
|
|
1361
1406
|
},
|
|
1362
1407
|
array_creation_expression(path, print) {
|
|
1363
1408
|
const parts = ["new "];
|
|
@@ -1398,8 +1443,8 @@ var expressions_default = {
|
|
|
1398
1443
|
record_pattern(path, print) {
|
|
1399
1444
|
return path.map(print, "children");
|
|
1400
1445
|
},
|
|
1401
|
-
record_pattern_body(path, print) {
|
|
1402
|
-
return group$4(indentInParentheses(join$4([",", line$4], path.map(print, "namedChildren"))));
|
|
1446
|
+
record_pattern_body(path, print, options) {
|
|
1447
|
+
return group$4(indentInParentheses(join$4([",", line$4], path.map(print, "namedChildren")), options));
|
|
1403
1448
|
},
|
|
1404
1449
|
record_pattern_component(path, print) {
|
|
1405
1450
|
return join$4(" ", path.map(print, "children"));
|
|
@@ -1451,8 +1496,8 @@ function printArrowFunctionSignatures(path, { signatureDocs }) {
|
|
|
1451
1496
|
if (node.fieldName === "object" && parent?.type === "method_invocation") return group$4(join$4([" ->", line$4], signatureDocs));
|
|
1452
1497
|
return group$4(indent$4(join$4([" ->", line$4], signatureDocs)));
|
|
1453
1498
|
}
|
|
1454
|
-
function printArrowFunctionBody(path, args, { bodyDoc, bodyComments, shouldPutBodyOnSameLine }) {
|
|
1455
|
-
const trailingSpace = args && typeof args === "object" && "expandLastArg" in args && args.expandLastArg && !path.node.comments ?
|
|
1499
|
+
function printArrowFunctionBody(path, args, options, { bodyDoc, bodyComments, shouldPutBodyOnSameLine }) {
|
|
1500
|
+
const trailingSpace = args && typeof args === "object" && "expandLastArg" in args && args.expandLastArg && !path.node.comments ? closingBracketLine(options) : "";
|
|
1456
1501
|
return shouldPutBodyOnSameLine ? [
|
|
1457
1502
|
" ",
|
|
1458
1503
|
bodyDoc,
|
|
@@ -1809,7 +1854,7 @@ var interfaces_default = {
|
|
|
1809
1854
|
const hasMultipleClauses = hasExtendsInterfaces && hasPermits;
|
|
1810
1855
|
if (hasChild(path, "type_parametersNode")) {
|
|
1811
1856
|
const typeParameters = path.call(print, "type_parametersNode");
|
|
1812
|
-
parts.push(hasMultipleClauses ? group$3(indent$3(typeParameters)) : typeParameters);
|
|
1857
|
+
parts.push(hasMultipleClauses ? group$3(indent$3(typeParameters)) : options?.braceStyle === "next-line" ? group$3(typeParameters) : typeParameters);
|
|
1813
1858
|
}
|
|
1814
1859
|
if (hasExtendsInterfaces || hasPermits) {
|
|
1815
1860
|
const clauses = [];
|
|
@@ -1859,13 +1904,13 @@ var interfaces_default = {
|
|
|
1859
1904
|
marker_annotation(path, print) {
|
|
1860
1905
|
return ["@", path.call(print, "nameNode")];
|
|
1861
1906
|
},
|
|
1862
|
-
annotation_argument_list(path, print) {
|
|
1907
|
+
annotation_argument_list(path, print, options) {
|
|
1863
1908
|
const args = path.map(print, "namedChildren");
|
|
1864
1909
|
return args.length === 1 && path.node.namedChildren[0].type === "element_value_array_initializer" ? [
|
|
1865
1910
|
"(",
|
|
1866
1911
|
args[0],
|
|
1867
1912
|
")"
|
|
1868
|
-
] : group$3(indentInParentheses(join$3([",", line$3], args)));
|
|
1913
|
+
] : group$3(indentInParentheses(join$3([",", line$3], args), options));
|
|
1869
1914
|
},
|
|
1870
1915
|
element_value_pair(path, print) {
|
|
1871
1916
|
return group$3([
|
package/package.json
CHANGED