prettier-java-next-line 2.11.0 → 2.11.2
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 +1203 -1066
- package/dist/index.d.cts +22 -11
- package/dist/index.d.mts +23 -13
- package/dist/index.mjs +1203 -1066
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Language, Parser } from "web-tree-sitter";
|
|
2
2
|
import { util } from "prettier";
|
|
3
3
|
import { builders, utils } from "prettier/doc";
|
|
4
|
-
|
|
4
|
+
// src/options.ts
|
|
5
5
|
var options_default = {
|
|
6
6
|
arrowParens: {
|
|
7
7
|
type: "choice",
|
|
@@ -47,7 +47,7 @@ var options_default = {
|
|
|
47
47
|
value: "end",
|
|
48
48
|
description: ""
|
|
49
49
|
}],
|
|
50
|
-
description: "Where to print operators when binary expressions wrap lines."
|
|
50
|
+
description: "Where to print operators when binary and ternary expressions wrap lines."
|
|
51
51
|
},
|
|
52
52
|
braceStyle: {
|
|
53
53
|
type: "choice",
|
|
@@ -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",
|
|
@@ -69,8 +95,7 @@ var options_default = {
|
|
|
69
95
|
description: "Import groups in Spotless's format, such as `java,javax,,#java|#javax,#`. Module imports always come first. Empty puts static imports next, then all others."
|
|
70
96
|
}
|
|
71
97
|
};
|
|
72
|
-
|
|
73
|
-
//#region src/node-types.ts
|
|
98
|
+
// src/node-types.ts
|
|
74
99
|
const multiFieldsByType = {
|
|
75
100
|
array_creation_expression: { dimensions: true },
|
|
76
101
|
cast_expression: { type: true },
|
|
@@ -87,9 +112,9 @@ const multiFieldsByType = {
|
|
|
87
112
|
requires_module_directive: { modifiers: true },
|
|
88
113
|
spread_parameter: { annotations: true }
|
|
89
114
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const { group: group$7, hardline: hardline$7, ifBreak: ifBreak$2, indent: indent$7, indentIfBreak: indentIfBreak$2, join: join$7, line: line$7, lineSuffixBoundary: lineSuffixBoundary$1, softline: softline$
|
|
115
|
+
// src/printers/helpers.ts
|
|
116
|
+
const { hasNewline: hasNewline$2, isNextLineEmpty: isNextLineEmpty$1, skipInlineComment, skipTrailingComment } = util;
|
|
117
|
+
const { breakParent: breakParent$2, fill, group: group$7, hardline: hardline$7, ifBreak: ifBreak$2, indent: indent$7, indentIfBreak: indentIfBreak$2, join: join$7, line: line$7, lineSuffixBoundary: lineSuffixBoundary$1, softline: softline$3 } = builders;
|
|
93
118
|
const { mapDoc } = utils;
|
|
94
119
|
function hasType(path, type) {
|
|
95
120
|
return path.node.type === type;
|
|
@@ -123,6 +148,10 @@ function printDanglingComments(path, danglingCommentsPrintOptions = {}) {
|
|
|
123
148
|
const doc = join$7(hardline$7, parts);
|
|
124
149
|
return shouldIndent ? indent$7([hardline$7, doc]) : doc;
|
|
125
150
|
}
|
|
151
|
+
function printDanglingCommentsInList(path) {
|
|
152
|
+
const { node } = path;
|
|
153
|
+
return node.comments?.some(({ leading, trailing }) => !leading && !trailing) ? [indent$7([softline$3, printDanglingComments(path)]), node.comments?.some(({ type, leading, trailing }) => !leading && !trailing && type === "line_comment") ? hardline$7 : softline$3] : "";
|
|
154
|
+
}
|
|
126
155
|
function printComment(comment) {
|
|
127
156
|
comment.printed = true;
|
|
128
157
|
const lines = comment.value.split("\n").map((line) => line.trim());
|
|
@@ -134,43 +163,119 @@ function hasLeadingComments(node) {
|
|
|
134
163
|
function hasDanglingComments(node) {
|
|
135
164
|
return node.comments?.some(({ leading, trailing }) => !leading && !trailing) ?? false;
|
|
136
165
|
}
|
|
137
|
-
function
|
|
166
|
+
function closingBracketLine(options, lineDoc = softline$3) {
|
|
167
|
+
return options?.closingBracket === "same-line" ? "" : lineDoc;
|
|
168
|
+
}
|
|
169
|
+
function indentInParentheses(contents, options) {
|
|
138
170
|
return contents && !Array.isArray(contents) || contents.length ? [
|
|
139
171
|
"(",
|
|
140
|
-
indent$7([softline$
|
|
141
|
-
|
|
172
|
+
indent$7([softline$3, contents]),
|
|
173
|
+
closingBracketLine(options),
|
|
142
174
|
")"
|
|
143
175
|
] : "()";
|
|
144
176
|
}
|
|
145
177
|
function printArrayInitializer(path, print, options) {
|
|
146
|
-
|
|
147
|
-
|
|
178
|
+
const { node } = path;
|
|
179
|
+
const elements = node.namedChildren;
|
|
180
|
+
const isNested = isNestedArray(path);
|
|
181
|
+
if (elements.length === 0) {
|
|
182
|
+
const danglingComments = printDanglingCommentsInList(path);
|
|
148
183
|
if (!danglingComments) return "{}";
|
|
149
|
-
const block = [
|
|
184
|
+
const block = group$7([
|
|
150
185
|
"{",
|
|
151
186
|
danglingComments,
|
|
152
|
-
|
|
187
|
+
"}"
|
|
188
|
+
]);
|
|
189
|
+
return options.braceStyle === "next-line" && !isNested ? [hardline$7, block] : block;
|
|
190
|
+
}
|
|
191
|
+
const groupId = Symbol("array");
|
|
192
|
+
const nextLineLayout = options.braceStyle === "next-line" && node.type === "array_initializer" ? options.arrayInitializerLayout : void 0;
|
|
193
|
+
const shouldBreak = node.comments?.some(({ type, leading, trailing }) => !leading && !trailing && type === "line_comment") || nextLineLayout !== "fit" && elements.length > 1 && elements.every((element, i, elements) => {
|
|
194
|
+
if (element.type !== "array_initializer") return false;
|
|
195
|
+
const elementType = element.type;
|
|
196
|
+
const nextElement = elements[i + 1];
|
|
197
|
+
if (nextElement && elementType !== nextElement.type) return false;
|
|
198
|
+
return element.namedChildren.length > 1;
|
|
199
|
+
});
|
|
200
|
+
const shouldUseConciseFormatting = nextLineLayout !== "always-break" && isConciselyPrintedArray(node, options);
|
|
201
|
+
const trailingComma = options.trailingComma === "none" ? "" : shouldUseConciseFormatting ? ifBreak$2(",", "", { groupId }) : ifBreak$2(",");
|
|
202
|
+
const contents = [shouldUseConciseFormatting ? printArrayElementsConcisely(path, options, print, trailingComma) : [printArrayElements(path, options, print), trailingComma], printDanglingComments(path)];
|
|
203
|
+
if (nextLineLayout === "fit") {
|
|
204
|
+
const bracketLine = options.bracketSpacing ? line$7 : softline$3;
|
|
205
|
+
const block = [
|
|
206
|
+
"{",
|
|
207
|
+
indent$7([bracketLine, contents]),
|
|
208
|
+
bracketLine,
|
|
153
209
|
"}"
|
|
154
210
|
];
|
|
155
|
-
return
|
|
211
|
+
return group$7(isNested ? block : [softline$3, ...block], {
|
|
212
|
+
shouldBreak,
|
|
213
|
+
id: groupId
|
|
214
|
+
});
|
|
156
215
|
}
|
|
157
|
-
|
|
158
|
-
if (list.length && options.trailingComma !== "none") list.push(ifBreak$2(","));
|
|
159
|
-
if (options.braceStyle === "next-line" && path.node.type === "array_initializer") {
|
|
216
|
+
if (nextLineLayout === "always-break") {
|
|
160
217
|
const block = [
|
|
161
218
|
"{",
|
|
162
|
-
indent$7([line$7,
|
|
219
|
+
indent$7([line$7, contents]),
|
|
163
220
|
line$7,
|
|
164
221
|
"}"
|
|
165
222
|
];
|
|
166
|
-
return
|
|
223
|
+
return isNested ? [breakParent$2, ...block] : [hardline$7, ...block];
|
|
167
224
|
}
|
|
168
225
|
return group$7([
|
|
169
226
|
"{",
|
|
170
|
-
indent$7([line$7,
|
|
227
|
+
indent$7([line$7, contents]),
|
|
171
228
|
line$7,
|
|
172
229
|
"}"
|
|
173
|
-
]
|
|
230
|
+
], {
|
|
231
|
+
shouldBreak,
|
|
232
|
+
id: groupId
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function isConciselyPrintedArray(node, options) {
|
|
236
|
+
return node.namedChildren.length > 0 && node.namedChildren.every((element) => element && (isNumericLiteral(element) || isSignedNumericLiteral(element) && !element.operandNode.comments) && !element.comments?.some((comment) => comment.trailing && comment.type === "line_comment" && !hasNewline$2(options.originalText, parser_default.locStart(comment), { backwards: true })));
|
|
237
|
+
}
|
|
238
|
+
const isNumericLiteral = createTypeCheckFunction([
|
|
239
|
+
"binary_integer_literal",
|
|
240
|
+
"decimal_floating_point_literal",
|
|
241
|
+
"decimal_integer_literal",
|
|
242
|
+
"hex_floating_point_literal",
|
|
243
|
+
"hex_integer_literal",
|
|
244
|
+
"octal_integer_literal"
|
|
245
|
+
]);
|
|
246
|
+
function isSignedNumericLiteral(node) {
|
|
247
|
+
return node.type === "unary_expression" && (node.operatorNode.type === "+" || node.operatorNode.type === "-") && isNumericLiteral(node.operandNode);
|
|
248
|
+
}
|
|
249
|
+
function isLineAfterElementEmpty({ node }, { originalText: text }) {
|
|
250
|
+
let currentIdx = parser_default.locEnd(node);
|
|
251
|
+
if (currentIdx === parser_default.locStart(node)) return false;
|
|
252
|
+
const { length } = text;
|
|
253
|
+
while (currentIdx < length) {
|
|
254
|
+
if (text[currentIdx] === ",") break;
|
|
255
|
+
currentIdx = skipInlineComment(text, skipTrailingComment(text, currentIdx + 1));
|
|
256
|
+
}
|
|
257
|
+
return isNextLineEmpty$1(text, currentIdx);
|
|
258
|
+
}
|
|
259
|
+
function printArrayElements(path, options, print) {
|
|
260
|
+
const parts = [];
|
|
261
|
+
path.each((element) => {
|
|
262
|
+
parts.push(group$7(print(element)));
|
|
263
|
+
if (!element.isLast) parts.push([
|
|
264
|
+
",",
|
|
265
|
+
line$7,
|
|
266
|
+
isLineAfterElementEmpty(path, options) ? softline$3 : ""
|
|
267
|
+
]);
|
|
268
|
+
}, "namedChildren");
|
|
269
|
+
return parts;
|
|
270
|
+
}
|
|
271
|
+
function printArrayElementsConcisely(path, options, print, trailingComma) {
|
|
272
|
+
const parts = [];
|
|
273
|
+
path.each((element) => {
|
|
274
|
+
const { next } = element;
|
|
275
|
+
parts.push([print(element), !next ? trailingComma : ","]);
|
|
276
|
+
if (next) parts.push(isLineAfterElementEmpty(path, options) ? [hardline$7, hardline$7] : next.comments?.some(({ type, leading }) => leading && type === "line_comment") ? hardline$7 : line$7);
|
|
277
|
+
}, "namedChildren");
|
|
278
|
+
return fill(parts);
|
|
174
279
|
}
|
|
175
280
|
function isNestedArray(path) {
|
|
176
281
|
return path.parent?.type === "array_initializer" || path.parent?.type === "element_value_array_initializer";
|
|
@@ -219,12 +324,18 @@ function printBlock(path, contents, options) {
|
|
|
219
324
|
}
|
|
220
325
|
function printBlockNextLine(path, contents) {
|
|
221
326
|
const parentType = path.parent?.type;
|
|
222
|
-
const
|
|
327
|
+
const isChildOfBodyDeclaration = parentType != null && [
|
|
223
328
|
"annotation_type_body",
|
|
224
329
|
"class_body",
|
|
225
330
|
"enum_body",
|
|
226
331
|
"interface_body"
|
|
227
|
-
].includes(parentType)
|
|
332
|
+
].includes(parentType);
|
|
333
|
+
const isBlockStatement = parentType != null && [
|
|
334
|
+
"block",
|
|
335
|
+
"constructor_body",
|
|
336
|
+
"switch_block_statement_group"
|
|
337
|
+
].includes(parentType);
|
|
338
|
+
const prefix = isChildOfBodyDeclaration || isBlockStatement ? [] : [hardline$7];
|
|
228
339
|
if (contents.length) return [
|
|
229
340
|
...prefix,
|
|
230
341
|
"{",
|
|
@@ -261,7 +372,7 @@ function printBlockStatements(path, print) {
|
|
|
261
372
|
function printBodyDeclarations(path, print, padFirst = false) {
|
|
262
373
|
const isInterfaceBody = path.node.type === "interface_body";
|
|
263
374
|
const isFormalParameters = path.node.type === "formal_parameters";
|
|
264
|
-
const separator = isFormalParameters ? softline$
|
|
375
|
+
const separator = isFormalParameters ? softline$3 : hardline$7;
|
|
265
376
|
let previousRequiresPadding = padFirst;
|
|
266
377
|
return path.map((child) => {
|
|
267
378
|
const { node, previous } = child;
|
|
@@ -275,7 +386,7 @@ function printBodyDeclarations(path, print, padFirst = false) {
|
|
|
275
386
|
return blankLine ? [separator, declaration] : declaration;
|
|
276
387
|
}, "namedChildren");
|
|
277
388
|
}
|
|
278
|
-
function printTypeParameters(path, print) {
|
|
389
|
+
function printTypeParameters(path, print, options) {
|
|
279
390
|
const parameters = path.node.namedChildren;
|
|
280
391
|
if (parameters.length === 0 || parameters.length === 1 && isSimpleType(parameters[0]) && !parameters.some(({ comments }) => comments?.length && comments.some(({ type }) => type === "line_comment"))) return [
|
|
281
392
|
"<",
|
|
@@ -284,8 +395,8 @@ function printTypeParameters(path, print) {
|
|
|
284
395
|
];
|
|
285
396
|
const parts = [
|
|
286
397
|
"<",
|
|
287
|
-
indent$7([softline$
|
|
288
|
-
|
|
398
|
+
indent$7([softline$3, join$7([",", line$7], path.map(print, "namedChildren"))]),
|
|
399
|
+
closingBracketLine(options),
|
|
289
400
|
">"
|
|
290
401
|
];
|
|
291
402
|
return path.node.type === "type_arguments" ? group$7(parts) : parts;
|
|
@@ -301,7 +412,7 @@ function printVariableDeclaration(path, print) {
|
|
|
301
412
|
}
|
|
302
413
|
function printAssignment(leftDoc, operator, rightDoc, rightNode) {
|
|
303
414
|
if (!rightDoc || !rightNode) return leftDoc;
|
|
304
|
-
if (rightNode.type === "binary_expression" || rightNode.type === "instanceof_expression" || rightNode.type === "ternary_expression" && (rightNode.conditionNode.type === "binary_expression" || rightNode.conditionNode.type === "instanceof_expression") ||
|
|
415
|
+
if (rightNode.type === "binary_expression" || rightNode.type === "instanceof_expression" || rightNode.type === "ternary_expression" && (rightNode.conditionNode.type === "binary_expression" || rightNode.conditionNode.type === "instanceof_expression") || hasLeadingComments(rightNode)) return group$7([
|
|
305
416
|
leftDoc,
|
|
306
417
|
operator,
|
|
307
418
|
group$7(indent$7([line$7, rightDoc]))
|
|
@@ -322,12 +433,14 @@ function inferParser(options, language) {
|
|
|
322
433
|
return getLanguageByLanguageName(options.plugins?.filter((plugin) => typeof plugin !== "string" && !(plugin instanceof URL)).reverse().flatMap((plugin) => plugin.languages ?? []) ?? [], language)?.parsers[0];
|
|
323
434
|
}
|
|
324
435
|
function printTextBlock(contents) {
|
|
325
|
-
return [
|
|
326
|
-
"\"\"\"",
|
|
436
|
+
return ["\"\"\"", indent$7([
|
|
327
437
|
hardline$7,
|
|
328
438
|
contents,
|
|
329
439
|
"\"\"\""
|
|
330
|
-
];
|
|
440
|
+
])];
|
|
441
|
+
}
|
|
442
|
+
function isTextBlock(node) {
|
|
443
|
+
return node.type === "string_literal" && node.children[0].value === "\"\"\"";
|
|
331
444
|
}
|
|
332
445
|
function embedTextBlock(path, options) {
|
|
333
446
|
if (path.node.namedChildren.some(({ type }) => type === "string_interpolation") || path.node.children[0].value === "\"") return null;
|
|
@@ -522,380 +635,780 @@ function unescapeTextBlockContents(text) {
|
|
|
522
635
|
}
|
|
523
636
|
});
|
|
524
637
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
const {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
638
|
+
// src/comments.ts
|
|
639
|
+
const { hasNewline: hasNewline$1, isPreviousLineEmpty, skipNewline, skipSpaces } = util;
|
|
640
|
+
const { breakParent: breakParent$1, hardline: hardline$6, line: line$6, lineSuffix } = builders;
|
|
641
|
+
const prettierIgnoreRangesByTree = /* @__PURE__ */ new WeakMap();
|
|
642
|
+
function determinePrettierIgnoreRanges(tree) {
|
|
643
|
+
const { comments } = tree;
|
|
644
|
+
if (!comments) return;
|
|
645
|
+
const ranges = comments.filter(({ value }) => /^\/(?:\/\s*(?:prettier-ignore-(?:start|end)|@formatter:(?:off|on))\s*|\*\s*(?:prettier-ignore-(?:start|end)|@formatter:(?:off|on))\s*\*\/)$/.test(value)).reduce((ranges, { value, start }) => {
|
|
646
|
+
const previous = ranges.at(-1);
|
|
647
|
+
if (value.includes("start") || value.includes("off")) {
|
|
648
|
+
if (previous?.end !== Infinity) ranges.push({
|
|
649
|
+
start: start.index,
|
|
650
|
+
end: Infinity
|
|
651
|
+
});
|
|
652
|
+
} else if (previous?.end === Infinity) previous.end = start.index;
|
|
653
|
+
return ranges;
|
|
654
|
+
}, new Array());
|
|
655
|
+
prettierIgnoreRangesByTree.set(tree, ranges);
|
|
656
|
+
}
|
|
657
|
+
function isFullyBetweenPrettierIgnore(path) {
|
|
658
|
+
const { node, root } = path;
|
|
659
|
+
const start = parser_default.locStart(node);
|
|
660
|
+
const end = parser_default.locEnd(node);
|
|
661
|
+
return prettierIgnoreRangesByTree.get(root)?.some((range) => range.start < start && end < range.end) === true;
|
|
662
|
+
}
|
|
663
|
+
function isPrettierIgnore(comment) {
|
|
664
|
+
return /^(\/\/\s*prettier-ignore|\/\*\s*prettier-ignore\s*\*\/)$/.test(comment.value);
|
|
665
|
+
}
|
|
666
|
+
function canAttachComment(node, ancestors) {
|
|
667
|
+
if (!node.isNamed) return isBinaryOperator(node);
|
|
668
|
+
switch (node.type) {
|
|
669
|
+
case "enum_body_declarations":
|
|
670
|
+
case "escape_sequence":
|
|
671
|
+
case "modifier":
|
|
672
|
+
case "multiline_string_fragment":
|
|
673
|
+
case "program":
|
|
674
|
+
case "string_fragment":
|
|
675
|
+
case "visibility": return false;
|
|
676
|
+
case "parenthesized_expression": {
|
|
677
|
+
const [parent] = ancestors;
|
|
678
|
+
return !(parent.isNamed && [
|
|
679
|
+
"do_statement",
|
|
680
|
+
"if_statement",
|
|
681
|
+
"switch_expression",
|
|
682
|
+
"synchronized_statement",
|
|
683
|
+
"try_statement",
|
|
684
|
+
"try_with_resources_statement",
|
|
685
|
+
"while_statement"
|
|
686
|
+
].includes(parent.type));
|
|
556
687
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
if (
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
if (child.node.type !== "guard") values.push(print(child));
|
|
594
|
-
}, "namedChildren");
|
|
595
|
-
const hasMultipleValues = values.length > 1;
|
|
596
|
-
const label = hasMultipleValues ? ["case", indent$6([line$6, ...join$6([",", line$6], values)])] : ["case ", values[0]];
|
|
597
|
-
const guardIndex = path.node.namedChildren.findIndex(({ type }) => type === "guard");
|
|
598
|
-
return guardIndex !== -1 ? [group$6([...label, hasMultipleValues ? line$6 : " "]), path.call(print, "namedChildren", guardIndex)] : group$6(label);
|
|
599
|
-
},
|
|
600
|
-
switch_rule(path, print) {
|
|
601
|
-
const bodyIndex = path.node.namedChildren.findIndex(({ type }) => type === "block" || type === "expression_statement" || type === "throw_statement");
|
|
602
|
-
const body = path.call(print, "namedChildren", bodyIndex);
|
|
603
|
-
const switchLabelIndex = path.node.namedChildren.findIndex(({ type }) => type === "switch_label");
|
|
604
|
-
const parts = [path.call(print, "namedChildren", switchLabelIndex), " ->"];
|
|
605
|
-
const bodyNode = path.node.namedChildren[bodyIndex];
|
|
606
|
-
if (bodyNode.type !== "block" && hasLeadingComments(bodyNode)) parts.push(indent$6([hardline$6, body]));
|
|
607
|
-
else parts.push(" ", body);
|
|
608
|
-
return parts;
|
|
609
|
-
},
|
|
610
|
-
while_statement(path, print) {
|
|
611
|
-
const parts = ["while ", path.call(print, "conditionNode")];
|
|
612
|
-
const body = path.call(print, "bodyNode");
|
|
613
|
-
const bodyType = path.node.bodyNode.type;
|
|
614
|
-
if (bodyType === "block") {
|
|
615
|
-
parts.push(" ", body);
|
|
616
|
-
return parts;
|
|
617
|
-
} else if (bodyType === ";") {
|
|
618
|
-
parts.push(";");
|
|
619
|
-
return parts;
|
|
620
|
-
} else {
|
|
621
|
-
parts.push(line$6, body);
|
|
622
|
-
return group$6(indent$6(parts));
|
|
688
|
+
default: return true;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
function handleLineComment(commentNode, _, options) {
|
|
692
|
+
return [
|
|
693
|
+
handleBinaryExpressionComments,
|
|
694
|
+
handleFormalParametersComments,
|
|
695
|
+
handleFqnOrRefTypeComments,
|
|
696
|
+
handleIfStatementComments,
|
|
697
|
+
handleJumpStatementComments,
|
|
698
|
+
handleLabeledStatementComments,
|
|
699
|
+
handleLambdaExpressionComments,
|
|
700
|
+
handleMemberChainComments,
|
|
701
|
+
handleModifiersComments,
|
|
702
|
+
handleNameComments,
|
|
703
|
+
handleTernaryExpressionComments,
|
|
704
|
+
handleTryStatementComments
|
|
705
|
+
].some((fn) => fn(commentNode, options));
|
|
706
|
+
}
|
|
707
|
+
function handleRemainingComment(commentNode) {
|
|
708
|
+
return [
|
|
709
|
+
handleFqnOrRefTypeComments,
|
|
710
|
+
handleNameComments,
|
|
711
|
+
handleJumpStatementComments
|
|
712
|
+
].some((fn) => fn(commentNode));
|
|
713
|
+
}
|
|
714
|
+
function handleBinaryExpressionComments(commentNode, options) {
|
|
715
|
+
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
716
|
+
if (enclosingNode?.type === "binary_expression") {
|
|
717
|
+
if (isBinaryOperator(followingNode)) {
|
|
718
|
+
if (options.experimentalOperatorPosition === "start") util.addLeadingComment(followingNode, commentNode);
|
|
719
|
+
else util.addTrailingComment(followingNode, commentNode);
|
|
720
|
+
return true;
|
|
721
|
+
} else if (options.experimentalOperatorPosition === "start" && isBinaryOperator(precedingNode)) {
|
|
722
|
+
util.addLeadingComment(precedingNode, commentNode);
|
|
723
|
+
return true;
|
|
623
724
|
}
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
725
|
+
}
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
function handleFormalParametersComments(commentNode) {
|
|
729
|
+
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
730
|
+
if (enclosingNode?.type === "formal_parameters" && !precedingNode && !followingNode) {
|
|
731
|
+
util.addDanglingComment(enclosingNode, commentNode, void 0);
|
|
732
|
+
return true;
|
|
733
|
+
}
|
|
734
|
+
return false;
|
|
735
|
+
}
|
|
736
|
+
function handleFqnOrRefTypeComments(commentNode) {
|
|
737
|
+
const { enclosingNode, followingNode } = commentNode;
|
|
738
|
+
if (enclosingNode?.type === "scoped_type_identifier" && followingNode) {
|
|
739
|
+
util.addLeadingComment(followingNode, commentNode);
|
|
740
|
+
return true;
|
|
741
|
+
}
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
function handleIfStatementComments(commentNode) {
|
|
745
|
+
const { enclosingNode, precedingNode } = commentNode;
|
|
746
|
+
if (enclosingNode?.type === "if_statement" && precedingNode?.fieldName === "consequence") {
|
|
747
|
+
util.addDanglingComment(enclosingNode, commentNode, void 0);
|
|
748
|
+
return true;
|
|
749
|
+
}
|
|
750
|
+
return false;
|
|
751
|
+
}
|
|
752
|
+
function handleJumpStatementComments(commentNode) {
|
|
753
|
+
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
754
|
+
if (enclosingNode && !precedingNode && !followingNode && (enclosingNode.type === "break_statement" || enclosingNode.type === "continue_statement" || enclosingNode.type === "return_statement")) {
|
|
755
|
+
util.addTrailingComment(enclosingNode, commentNode);
|
|
756
|
+
return true;
|
|
757
|
+
}
|
|
758
|
+
return false;
|
|
759
|
+
}
|
|
760
|
+
function handleLabeledStatementComments(commentNode) {
|
|
761
|
+
const { enclosingNode, precedingNode } = commentNode;
|
|
762
|
+
if (enclosingNode?.type === "labeled_statement" && precedingNode?.type === "identifier") {
|
|
763
|
+
util.addLeadingComment(precedingNode, commentNode);
|
|
764
|
+
return true;
|
|
765
|
+
}
|
|
766
|
+
return false;
|
|
767
|
+
}
|
|
768
|
+
function handleLambdaExpressionComments(commentNode) {
|
|
769
|
+
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
770
|
+
if (enclosingNode?.type === "lambda_expression" && precedingNode && followingNode && enclosingNode.children.find(({ type }) => type === "->").end.index < commentNode.start.index) {
|
|
771
|
+
if (followingNode.type === "block") {
|
|
772
|
+
if (followingNode.namedChildren.length) util.addLeadingComment(followingNode.namedChildren[0], commentNode);
|
|
773
|
+
else util.addDanglingComment(followingNode, commentNode, void 0);
|
|
774
|
+
} else util.addLeadingComment(followingNode, commentNode);
|
|
775
|
+
return true;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
function handleMemberChainComments(commentNode) {
|
|
779
|
+
const { enclosingNode, precedingNode } = commentNode;
|
|
780
|
+
if (isMember(enclosingNode)) {
|
|
781
|
+
if (commentNode.end.index <= enclosingNode.start.index) {
|
|
782
|
+
const memberChainRoot = getMemberChainRoot(enclosingNode);
|
|
783
|
+
util.addLeadingComment(memberChainRoot, commentNode);
|
|
784
|
+
return true;
|
|
675
785
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
const parts = ["break"];
|
|
680
|
-
const identifierIndex = path.node.namedChildren.findIndex(({ type }) => type === "identifier");
|
|
681
|
-
if (identifierIndex !== -1) parts.push(" ", path.call(print, "namedChildren", identifierIndex));
|
|
682
|
-
parts.push(";");
|
|
683
|
-
return parts;
|
|
684
|
-
},
|
|
685
|
-
continue_statement(path, print) {
|
|
686
|
-
const identifierIndex = path.node.namedChildren.findIndex(({ type }) => type === "identifier");
|
|
687
|
-
return identifierIndex !== -1 ? [
|
|
688
|
-
"continue ",
|
|
689
|
-
path.call(print, "namedChildren", identifierIndex),
|
|
690
|
-
";"
|
|
691
|
-
] : "continue;";
|
|
692
|
-
},
|
|
693
|
-
return_statement: printReturnOrThrowStatement,
|
|
694
|
-
throw_statement: printReturnOrThrowStatement,
|
|
695
|
-
synchronized_statement(path, print) {
|
|
696
|
-
const parenthesizedExpressionIndex = path.node.namedChildren.findIndex(({ type }) => type === "parenthesized_expression");
|
|
697
|
-
return [
|
|
698
|
-
"synchronized ",
|
|
699
|
-
path.call(print, "namedChildren", parenthesizedExpressionIndex),
|
|
700
|
-
" ",
|
|
701
|
-
path.call(print, "bodyNode")
|
|
702
|
-
];
|
|
703
|
-
},
|
|
704
|
-
try_statement(path, print, options) {
|
|
705
|
-
const parts = ["try", path.call(print, "bodyNode")];
|
|
706
|
-
path.each((child) => {
|
|
707
|
-
if (child.node.type === "catch_clause" || child.node.type === "finally_clause") parts.push(print(child));
|
|
708
|
-
}, "namedChildren");
|
|
709
|
-
if (options?.braceStyle === "next-line") return parts;
|
|
710
|
-
return join$6(" ", parts);
|
|
711
|
-
},
|
|
712
|
-
catch_clause(path, print, options) {
|
|
713
|
-
const catchFormalParameterIndex = path.node.namedChildren.findIndex(({ type }) => type === "catch_formal_parameter");
|
|
714
|
-
const params = group$6(indentInParentheses(path.call(print, "namedChildren", catchFormalParameterIndex)));
|
|
715
|
-
const body = path.call(print, "bodyNode");
|
|
716
|
-
if (options?.braceStyle === "next-line") return [
|
|
717
|
-
hardline$6,
|
|
718
|
-
"catch ",
|
|
719
|
-
params,
|
|
720
|
-
body
|
|
721
|
-
];
|
|
722
|
-
return [
|
|
723
|
-
"catch ",
|
|
724
|
-
params,
|
|
725
|
-
" ",
|
|
726
|
-
body
|
|
727
|
-
];
|
|
728
|
-
},
|
|
729
|
-
catch_formal_parameter(path, print) {
|
|
730
|
-
const parts = printModifiers(path, print, "noBreak");
|
|
731
|
-
const catchTypeIndex = path.node.namedChildren.findIndex(({ type }) => type === "catch_type");
|
|
732
|
-
parts.push(path.call(print, "namedChildren", catchTypeIndex), " ", path.call(print, "nameNode"));
|
|
733
|
-
if (hasChild(path, "dimensionsNode")) parts.push(path.call(print, "dimensionsNode"));
|
|
734
|
-
return parts;
|
|
735
|
-
},
|
|
736
|
-
catch_type(path, print) {
|
|
737
|
-
return join$6([line$6, "| "], path.map(print, "namedChildren"));
|
|
738
|
-
},
|
|
739
|
-
finally_clause(path, print, options) {
|
|
740
|
-
if (options?.braceStyle === "next-line") return [
|
|
741
|
-
hardline$6,
|
|
742
|
-
"finally",
|
|
743
|
-
path.call(print, "namedChildren", 0)
|
|
744
|
-
];
|
|
745
|
-
return ["finally ", path.call(print, "namedChildren", 0)];
|
|
746
|
-
},
|
|
747
|
-
try_with_resources_statement(path, print, options) {
|
|
748
|
-
const resources = path.call(print, "resourcesNode");
|
|
749
|
-
const body = path.call(print, "bodyNode");
|
|
750
|
-
const clauses = [];
|
|
751
|
-
path.each((child) => {
|
|
752
|
-
if (child.node.type === "catch_clause" || child.node.type === "finally_clause") clauses.push(print(child));
|
|
753
|
-
}, "namedChildren");
|
|
754
|
-
if (options?.braceStyle === "next-line") return [
|
|
755
|
-
"try ",
|
|
756
|
-
resources,
|
|
757
|
-
body,
|
|
758
|
-
...clauses
|
|
759
|
-
];
|
|
760
|
-
return join$6(" ", [
|
|
761
|
-
"try",
|
|
762
|
-
resources,
|
|
763
|
-
body,
|
|
764
|
-
...clauses
|
|
765
|
-
]);
|
|
766
|
-
},
|
|
767
|
-
resource_specification(path, print) {
|
|
768
|
-
const resources = [];
|
|
769
|
-
let hasTrailingSemicolon = false;
|
|
770
|
-
path.each((child) => {
|
|
771
|
-
if (child.node.type === "resource") {
|
|
772
|
-
resources.push(print(child));
|
|
773
|
-
hasTrailingSemicolon = false;
|
|
774
|
-
} else if (child.node.type === ";") hasTrailingSemicolon = true;
|
|
775
|
-
}, "children");
|
|
776
|
-
const parts = join$6([";", line$6], resources);
|
|
777
|
-
if (hasTrailingSemicolon) parts.push(ifBreak$1(";"));
|
|
778
|
-
return group$6(indentInParentheses(parts));
|
|
779
|
-
},
|
|
780
|
-
resource(path, print) {
|
|
781
|
-
if (hasChild(path, "typeNode") && hasChild(path, "nameNode") && hasChild(path, "valueNode")) {
|
|
782
|
-
const parts = printModifiers(path, print);
|
|
783
|
-
parts.push(path.call(print, "typeNode"), " ", path.call(print, "nameNode"));
|
|
784
|
-
if (hasChild(path, "dimensionsNode")) parts.push(path.call(print, "dimensionsNode"));
|
|
785
|
-
parts.push(" =");
|
|
786
|
-
const value = path.call(print, "valueNode");
|
|
787
|
-
if (path.node.valueNode.type === "binary_expression" || hasLeadingComments(path.node.valueNode)) parts.push(group$6(indent$6([line$6, value])));
|
|
788
|
-
else {
|
|
789
|
-
const groupId = Symbol("assignment");
|
|
790
|
-
parts.push(group$6(indent$6(line$6), { id: groupId }), indentIfBreak$1(value, { groupId }));
|
|
791
|
-
}
|
|
792
|
-
return parts;
|
|
786
|
+
if (precedingNode && (enclosingNode.type === "field_access" || precedingNode.end.row < commentNode.start.row) && precedingNode === getMemberObject(enclosingNode)) {
|
|
787
|
+
util.addLeadingComment(enclosingNode, commentNode);
|
|
788
|
+
return true;
|
|
793
789
|
}
|
|
794
|
-
const resourceIndex = path.node.namedChildren.findIndex(({ type }) => type === "identifier" || type === "field_access");
|
|
795
|
-
return path.call(print, "namedChildren", resourceIndex);
|
|
796
|
-
},
|
|
797
|
-
yield_statement(path, print) {
|
|
798
|
-
return [
|
|
799
|
-
"yield ",
|
|
800
|
-
path.call(print, "namedChildren", 0),
|
|
801
|
-
";"
|
|
802
|
-
];
|
|
803
790
|
}
|
|
804
|
-
|
|
805
|
-
function printExpressionList(expressions) {
|
|
806
|
-
return group$6(expressions.map((expression, index) => index === 0 ? expression : [",", indent$6([line$6, expression])]));
|
|
791
|
+
return false;
|
|
807
792
|
}
|
|
808
|
-
function
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
];
|
|
817
|
-
if (node.type === "binary_expression") return group$6([
|
|
818
|
-
ifBreak$1("("),
|
|
819
|
-
indent$6([softline$3, argumentDoc]),
|
|
820
|
-
softline$3,
|
|
821
|
-
ifBreak$1(")")
|
|
822
|
-
]);
|
|
823
|
-
return argumentDoc;
|
|
793
|
+
function getMemberChainRoot(node) {
|
|
794
|
+
let current = node;
|
|
795
|
+
while (isMember(current)) {
|
|
796
|
+
const next = getMemberObject(current);
|
|
797
|
+
if (!next) return current;
|
|
798
|
+
else current = next;
|
|
799
|
+
}
|
|
800
|
+
return current;
|
|
824
801
|
}
|
|
825
|
-
function
|
|
826
|
-
const {
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
802
|
+
function handleModifiersComments(commentNode) {
|
|
803
|
+
const { precedingNode } = commentNode;
|
|
804
|
+
if (precedingNode?.type === "annotation" || precedingNode?.type === "marker_annotation" || precedingNode?.type === "modifiers") {
|
|
805
|
+
util.addTrailingComment(precedingNode, commentNode);
|
|
806
|
+
return true;
|
|
807
|
+
}
|
|
808
|
+
return false;
|
|
832
809
|
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
810
|
+
function handleNameComments(commentNode) {
|
|
811
|
+
const { enclosingNode, precedingNode } = commentNode;
|
|
812
|
+
if (enclosingNode && precedingNode?.type === "identifier" && (enclosingNode.type === "scoped_identifier" || enclosingNode.type === "module_declaration" || enclosingNode.type === "package_declaration" || enclosingNode.type === "scoped_type_identifier")) {
|
|
813
|
+
util.addTrailingComment(precedingNode, commentNode);
|
|
814
|
+
return true;
|
|
815
|
+
}
|
|
816
|
+
return false;
|
|
817
|
+
}
|
|
818
|
+
function handleTernaryExpressionComments(commentNode) {
|
|
819
|
+
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
820
|
+
if (enclosingNode?.type === "ternary_expression" && precedingNode?.isNamed && followingNode?.isNamed && precedingNode.end.row < commentNode.start.row && commentNode.end.row < followingNode.start.row) {
|
|
821
|
+
util.addLeadingComment(followingNode, commentNode);
|
|
822
|
+
return true;
|
|
823
|
+
}
|
|
824
|
+
return false;
|
|
825
|
+
}
|
|
826
|
+
function handleTryStatementComments(commentNode) {
|
|
827
|
+
const { enclosingNode, followingNode } = commentNode;
|
|
828
|
+
if (enclosingNode && (enclosingNode.type === "catch_clause" || enclosingNode.type === "try_statement" || enclosingNode.type === "try_with_resources_statement") && followingNode?.isNamed) {
|
|
829
|
+
const block = followingNode.type === "catch_clause" ? followingNode.bodyNode : followingNode.type === "finally_clause" ? followingNode.namedChildren[0] : null;
|
|
830
|
+
if (!block) return false;
|
|
831
|
+
const blockStatement = block.namedChildren.at(0);
|
|
832
|
+
if (blockStatement) util.addLeadingComment(blockStatement, commentNode);
|
|
833
|
+
else util.addDanglingComment(block, commentNode, void 0);
|
|
834
|
+
return true;
|
|
835
|
+
}
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
function getMemberObject(node) {
|
|
839
|
+
return node.type === "array_access" ? node.arrayNode : node.objectNode;
|
|
840
|
+
}
|
|
841
|
+
const binaryOperators = /* @__PURE__ */ new Set([
|
|
842
|
+
"<<",
|
|
843
|
+
">>",
|
|
844
|
+
">>>",
|
|
845
|
+
"instanceof",
|
|
846
|
+
"<=",
|
|
847
|
+
">=",
|
|
848
|
+
"==",
|
|
849
|
+
"-",
|
|
850
|
+
"+",
|
|
851
|
+
"&&",
|
|
852
|
+
"&",
|
|
853
|
+
"^",
|
|
854
|
+
"!=",
|
|
855
|
+
"||",
|
|
856
|
+
"|",
|
|
857
|
+
"*",
|
|
858
|
+
"/",
|
|
859
|
+
"%"
|
|
860
|
+
]);
|
|
861
|
+
function isBinaryOperator(node) {
|
|
862
|
+
return node !== void 0 && binaryOperators.has(node.type);
|
|
863
|
+
}
|
|
864
|
+
function printLeadingComment(path) {
|
|
865
|
+
const comment = path.node;
|
|
866
|
+
const parts = [printComment(comment)];
|
|
867
|
+
const originalText = path.root.value;
|
|
868
|
+
if (comment.type === "block_comment") {
|
|
869
|
+
let lineBreak = " ";
|
|
870
|
+
if (hasNewline$1(originalText, parser_default.locEnd(comment))) {
|
|
871
|
+
if (hasNewline$1(originalText, parser_default.locStart(comment), { backwards: true })) lineBreak = hardline$6;
|
|
872
|
+
else lineBreak = line$6;
|
|
873
|
+
}
|
|
874
|
+
parts.push(lineBreak);
|
|
875
|
+
} else parts.push(hardline$6);
|
|
876
|
+
const index = skipNewline(originalText, skipSpaces(originalText, parser_default.locEnd(comment)));
|
|
877
|
+
if (index !== false && hasNewline$1(originalText, index)) parts.push(hardline$6);
|
|
878
|
+
return parts;
|
|
879
|
+
}
|
|
880
|
+
function printTrailingComment(path, previousComment) {
|
|
881
|
+
const comment = path.node;
|
|
882
|
+
const printed = printComment(comment);
|
|
883
|
+
const originalText = path.root.value;
|
|
884
|
+
const isBlock = comment.type === "block_comment";
|
|
885
|
+
if (previousComment?.hasLineSuffix && !previousComment?.isBlock || hasNewline$1(originalText, parser_default.locStart(comment), { backwards: true })) {
|
|
886
|
+
const isLineBeforeEmpty = isPreviousLineEmpty(originalText, parser_default.locStart(comment));
|
|
887
|
+
return {
|
|
888
|
+
doc: lineSuffix([
|
|
889
|
+
hardline$6,
|
|
890
|
+
isLineBeforeEmpty ? hardline$6 : "",
|
|
891
|
+
printed
|
|
892
|
+
]),
|
|
893
|
+
isBlock,
|
|
894
|
+
hasLineSuffix: true
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
if (!isBlock || previousComment?.hasLineSuffix) return {
|
|
898
|
+
doc: [lineSuffix([" ", printed]), breakParent$1],
|
|
899
|
+
isBlock,
|
|
900
|
+
hasLineSuffix: true
|
|
901
|
+
};
|
|
902
|
+
return {
|
|
903
|
+
doc: [" ", printed],
|
|
904
|
+
isBlock,
|
|
905
|
+
hasLineSuffix: false
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
function printLeadingComments(path) {
|
|
909
|
+
if (!hasChild(path, "comments")) return [];
|
|
910
|
+
const docs = [];
|
|
911
|
+
path.each((path) => {
|
|
912
|
+
const { node: comment } = path;
|
|
913
|
+
if (!comment.leading) return;
|
|
914
|
+
docs.push(printLeadingComment(path));
|
|
915
|
+
}, "comments");
|
|
916
|
+
return docs;
|
|
917
|
+
}
|
|
918
|
+
function printTrailingComments(path) {
|
|
919
|
+
if (!hasChild(path, "comments")) return [];
|
|
920
|
+
const docs = [];
|
|
921
|
+
let printedTrailingComment;
|
|
922
|
+
path.each((path) => {
|
|
923
|
+
const { node: comment } = path;
|
|
924
|
+
if (!comment.trailing) return;
|
|
925
|
+
printedTrailingComment = printTrailingComment(path, printedTrailingComment);
|
|
926
|
+
docs.push(printedTrailingComment.doc);
|
|
927
|
+
}, "comments");
|
|
928
|
+
return docs;
|
|
929
|
+
}
|
|
930
|
+
function printCommentsSeparately(path) {
|
|
931
|
+
return {
|
|
932
|
+
leading: printLeadingComments(path),
|
|
933
|
+
trailing: printTrailingComments(path)
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
function printComments(path, doc) {
|
|
937
|
+
const leading = printLeadingComments(path);
|
|
938
|
+
const trailing = printTrailingComments(path);
|
|
939
|
+
return leading.length || trailing.length ? [
|
|
940
|
+
leading,
|
|
941
|
+
doc,
|
|
942
|
+
trailing
|
|
943
|
+
] : doc;
|
|
944
|
+
}
|
|
945
|
+
// src/parser.ts
|
|
946
|
+
var parser_default = {
|
|
947
|
+
async parse(text) {
|
|
948
|
+
const tree = (await parser).parse(text);
|
|
949
|
+
const { rootNode } = tree;
|
|
950
|
+
if (rootNode.hasError) throw new Error("Failed to parse: " + rootNode);
|
|
951
|
+
const ast = processTree(rootNode);
|
|
952
|
+
determinePrettierIgnoreRanges(ast);
|
|
953
|
+
tree.delete();
|
|
954
|
+
return ast;
|
|
955
|
+
},
|
|
956
|
+
astFormat: "java",
|
|
957
|
+
hasPragma(text) {
|
|
958
|
+
return /^\/\*\*\n\s+\*\s@(format|prettier)\n\s+\*\//.test(text);
|
|
959
|
+
},
|
|
960
|
+
locStart(node) {
|
|
961
|
+
return node.start.index;
|
|
962
|
+
},
|
|
963
|
+
locEnd(node) {
|
|
964
|
+
return node.end.index;
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
const parser = (async () => {
|
|
968
|
+
await Parser.init();
|
|
969
|
+
const parser = new Parser();
|
|
970
|
+
const Java = await Language.load(new URL("./tree-sitter-java_orchard.wasm", import.meta.url));
|
|
971
|
+
parser.setLanguage(Java);
|
|
972
|
+
return parser;
|
|
973
|
+
})();
|
|
974
|
+
const isParenthesizedParent = createTypeCheckFunction([
|
|
975
|
+
"do_statement",
|
|
976
|
+
"if_statement",
|
|
977
|
+
"switch_expression",
|
|
978
|
+
"synchronized_statement",
|
|
979
|
+
"try_statement",
|
|
980
|
+
"try_with_resources_statement",
|
|
981
|
+
"while_statement"
|
|
982
|
+
]);
|
|
983
|
+
function processTree(node, fieldName = null, comments) {
|
|
984
|
+
const { type, isNamed, text: value, startPosition, endPosition } = node;
|
|
985
|
+
const javaNode = {
|
|
986
|
+
type,
|
|
987
|
+
isNamed,
|
|
988
|
+
value,
|
|
989
|
+
start: {
|
|
990
|
+
index: node.startIndex,
|
|
991
|
+
row: startPosition.row,
|
|
992
|
+
column: startPosition.column
|
|
993
|
+
},
|
|
994
|
+
end: {
|
|
995
|
+
index: node.endIndex,
|
|
996
|
+
row: endPosition.row,
|
|
997
|
+
column: endPosition.column
|
|
998
|
+
},
|
|
999
|
+
children: [],
|
|
1000
|
+
namedChildren: [],
|
|
1001
|
+
fieldName
|
|
1002
|
+
};
|
|
1003
|
+
if (!comments) comments = javaNode.comments = [];
|
|
1004
|
+
if (!javaNode.isNamed) return javaNode;
|
|
1005
|
+
const multiFields = multiFieldsByType[node.type];
|
|
1006
|
+
if (multiFields) Object.keys(multiFields).forEach((name) => javaNode[`${name}Nodes`] = []);
|
|
1007
|
+
node.children.forEach((child, index) => {
|
|
1008
|
+
const fieldName = node.fieldNameForChild(index);
|
|
1009
|
+
(child.type === "parenthesized_expression" && !isParenthesizedParent(javaNode) ? child.namedChildren : [child]).forEach((child) => {
|
|
1010
|
+
const { type, text: value, startPosition, endPosition } = child;
|
|
1011
|
+
if (type === "block_comment" || type === "line_comment") comments.push({
|
|
1012
|
+
type,
|
|
1013
|
+
value,
|
|
1014
|
+
start: {
|
|
1015
|
+
index: child.startIndex,
|
|
1016
|
+
row: startPosition.row,
|
|
1017
|
+
column: startPosition.column
|
|
1018
|
+
},
|
|
1019
|
+
end: {
|
|
1020
|
+
index: child.endIndex,
|
|
1021
|
+
row: endPosition.row,
|
|
1022
|
+
column: endPosition.column
|
|
1023
|
+
},
|
|
1024
|
+
leading: false,
|
|
1025
|
+
trailing: false,
|
|
1026
|
+
printed: false
|
|
1027
|
+
});
|
|
1028
|
+
else {
|
|
1029
|
+
const javaChild = processTree(child, fieldName, comments);
|
|
1030
|
+
javaNode.children.push(javaChild);
|
|
1031
|
+
if (javaChild.isNamed) javaNode.namedChildren.push(javaChild);
|
|
1032
|
+
if (fieldName) {
|
|
1033
|
+
if (multiFields?.[fieldName]) javaNode[`${fieldName}Nodes`].push(javaChild);
|
|
1034
|
+
else javaNode[`${fieldName}Node`] = javaChild;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
});
|
|
1039
|
+
return javaNode;
|
|
1040
|
+
}
|
|
1041
|
+
// src/printers/arrays.ts
|
|
1042
|
+
var arrays_default = { array_initializer: printArrayInitializer };
|
|
1043
|
+
// src/printers/blocks-and-statements.ts
|
|
1044
|
+
const { group: group$6, hardline: hardline$5, ifBreak: ifBreak$1, indent: indent$6, indentIfBreak: indentIfBreak$1, join: join$6, line: line$5, softline: softline$2 } = builders;
|
|
1045
|
+
var blocks_and_statements_default = {
|
|
1046
|
+
block(path, print, options) {
|
|
1047
|
+
return printBlock(path, printBlockStatements(path, print), options);
|
|
1048
|
+
},
|
|
1049
|
+
local_variable_declaration: printVariableDeclaration,
|
|
1050
|
+
labeled_statement(path, print) {
|
|
1051
|
+
return join$6(": ", path.map(print, "namedChildren"));
|
|
1052
|
+
},
|
|
1053
|
+
expression_statement(path, print) {
|
|
1054
|
+
const parentType = path.parent?.type;
|
|
1055
|
+
const expressionType = path.node.namedChildren[0].type;
|
|
1056
|
+
const expression = path.call(print, "namedChildren", 0);
|
|
1057
|
+
return expressionType === "switch_expression" && parentType !== "assignment_expression" && parentType !== "switch_rule" ? expression : [expression, ";"];
|
|
1058
|
+
},
|
|
1059
|
+
if_statement(path, print, options) {
|
|
1060
|
+
const statement = ["if ", path.call(print, "conditionNode")];
|
|
1061
|
+
if (path.node.consequenceNode.type === ";") statement.push(";");
|
|
1062
|
+
else statement.push(" ", path.call(print, "consequenceNode"));
|
|
1063
|
+
if (!hasChild(path, "alternativeNode")) return statement;
|
|
1064
|
+
const danglingComments = printDanglingComments(path);
|
|
1065
|
+
if (danglingComments) statement.push(hardline$5, danglingComments, hardline$5);
|
|
1066
|
+
else if (options?.braceStyle === "next-line") statement.push(hardline$5);
|
|
1067
|
+
else {
|
|
1068
|
+
const ifHasBlock = path.node.consequenceNode.type === "block";
|
|
1069
|
+
statement.push(ifHasBlock ? " " : hardline$5);
|
|
1070
|
+
}
|
|
1071
|
+
statement.push("else");
|
|
1072
|
+
if (path.node.alternativeNode.type === ";") statement.push(";");
|
|
1073
|
+
else statement.push(" ", path.call(print, "alternativeNode"));
|
|
1074
|
+
return statement;
|
|
1075
|
+
},
|
|
1076
|
+
assert_statement(path, print) {
|
|
1077
|
+
return [
|
|
1078
|
+
"assert ",
|
|
1079
|
+
...join$6(" : ", path.map(print, "namedChildren")),
|
|
1080
|
+
";"
|
|
1081
|
+
];
|
|
1082
|
+
},
|
|
1083
|
+
switch_expression(path, print) {
|
|
1084
|
+
return join$6(" ", [
|
|
1085
|
+
"switch",
|
|
1086
|
+
path.call(print, "conditionNode"),
|
|
1087
|
+
path.call(print, "bodyNode")
|
|
1088
|
+
]);
|
|
1089
|
+
},
|
|
1090
|
+
switch_block(path, print, options) {
|
|
1091
|
+
return printBlock(path, path.map(print, "namedChildren"), options);
|
|
1092
|
+
},
|
|
1093
|
+
switch_block_statement_group(path, print) {
|
|
1094
|
+
const parts = [];
|
|
1095
|
+
path.each((child) => {
|
|
1096
|
+
if (child.node.type === "switch_label") parts.push(print(child), ":");
|
|
1097
|
+
}, "namedChildren");
|
|
1098
|
+
const firstStatementIndex = path.node.namedChildren.findIndex(({ type }) => type !== "switch_label");
|
|
1099
|
+
if (firstStatementIndex === path.node.namedChildren.length - 1 && path.node.namedChildren[firstStatementIndex].type === "block") parts.push(" ", path.call(print, "namedChildren", firstStatementIndex));
|
|
1100
|
+
else if (firstStatementIndex !== -1) parts.push(indent$6([hardline$5, ...join$6(hardline$5, printBlockStatements(path, print))]));
|
|
1101
|
+
return parts;
|
|
1102
|
+
},
|
|
1103
|
+
switch_label(path, print) {
|
|
1104
|
+
if (!path.node.children.some(({ type }) => type === "case")) return "default";
|
|
1105
|
+
const values = [];
|
|
1106
|
+
path.each((child) => {
|
|
1107
|
+
if (child.node.type !== "guard") values.push(print(child));
|
|
1108
|
+
}, "namedChildren");
|
|
1109
|
+
const hasMultipleValues = values.length > 1;
|
|
1110
|
+
const label = hasMultipleValues ? ["case", indent$6([line$5, ...join$6([",", line$5], values)])] : ["case ", values[0]];
|
|
1111
|
+
const guardIndex = path.node.namedChildren.findIndex(({ type }) => type === "guard");
|
|
1112
|
+
return guardIndex !== -1 ? [group$6([...label, hasMultipleValues ? line$5 : " "]), path.call(print, "namedChildren", guardIndex)] : group$6(label);
|
|
1113
|
+
},
|
|
1114
|
+
switch_rule(path, print) {
|
|
1115
|
+
const bodyIndex = path.node.namedChildren.findIndex(({ type }) => type === "block" || type === "expression_statement" || type === "throw_statement");
|
|
1116
|
+
const body = path.call(print, "namedChildren", bodyIndex);
|
|
1117
|
+
const switchLabelIndex = path.node.namedChildren.findIndex(({ type }) => type === "switch_label");
|
|
1118
|
+
const parts = [path.call(print, "namedChildren", switchLabelIndex), " ->"];
|
|
1119
|
+
const bodyNode = path.node.namedChildren[bodyIndex];
|
|
1120
|
+
if (bodyNode.type !== "block" && hasLeadingComments(bodyNode)) parts.push(indent$6([hardline$5, body]));
|
|
1121
|
+
else parts.push(" ", body);
|
|
1122
|
+
return parts;
|
|
1123
|
+
},
|
|
1124
|
+
while_statement(path, print) {
|
|
1125
|
+
const parts = ["while ", path.call(print, "conditionNode")];
|
|
1126
|
+
const body = path.call(print, "bodyNode");
|
|
1127
|
+
const bodyType = path.node.bodyNode.type;
|
|
1128
|
+
if (bodyType === "block") {
|
|
1129
|
+
parts.push(" ", body);
|
|
1130
|
+
return parts;
|
|
1131
|
+
} else if (bodyType === ";") {
|
|
1132
|
+
parts.push(";");
|
|
1133
|
+
return parts;
|
|
1134
|
+
} else {
|
|
1135
|
+
parts.push(line$5, body);
|
|
1136
|
+
return group$6(indent$6(parts));
|
|
1137
|
+
}
|
|
1138
|
+
},
|
|
1139
|
+
do_statement(path, print, options) {
|
|
1140
|
+
const hasEmptyStatement = path.node.bodyNode.type === ";";
|
|
1141
|
+
const isNextLine = options?.braceStyle === "next-line";
|
|
1142
|
+
const whilePrefix = isNextLine ? [hardline$5, "while "] : " while ";
|
|
1143
|
+
return [
|
|
1144
|
+
"do",
|
|
1145
|
+
hasEmptyStatement ? ";" : isNextLine ? path.call(print, "bodyNode") : [" ", path.call(print, "bodyNode")],
|
|
1146
|
+
whilePrefix,
|
|
1147
|
+
path.call(print, "conditionNode"),
|
|
1148
|
+
";"
|
|
1149
|
+
];
|
|
1150
|
+
},
|
|
1151
|
+
for_statement(path, print, options) {
|
|
1152
|
+
const danglingComments = printDanglingComments(path);
|
|
1153
|
+
const hasInit = path.node.initNodes.length > 0;
|
|
1154
|
+
const hasCondition = hasChild(path, "conditionNode");
|
|
1155
|
+
const hasUpdate = path.node.updateNodes.length > 0;
|
|
1156
|
+
const expressions = [
|
|
1157
|
+
!hasInit ? ";" : path.node.initNodes[0].type === "local_variable_declaration" ? path.call(print, "initNodes", 0) : [printExpressionList(path.map(print, "initNodes")), ";"],
|
|
1158
|
+
hasCondition ? [path.call(print, "conditionNode"), ";"] : ";",
|
|
1159
|
+
hasUpdate ? [line$5, printExpressionList(path.map(print, "updateNodes"))] : ifBreak$1("", " ")
|
|
1160
|
+
];
|
|
1161
|
+
const hasEmptyStatement = path.node.bodyNode.type === ";";
|
|
1162
|
+
return [
|
|
1163
|
+
danglingComments && [danglingComments, hardline$5],
|
|
1164
|
+
"for ",
|
|
1165
|
+
hasInit || hasCondition || hasUpdate ? group$6(indentInParentheses([join$6(line$5, expressions.slice(0, 2)), expressions[2]], options)) : "(;;)",
|
|
1166
|
+
hasEmptyStatement ? ";" : [" ", path.call(print, "bodyNode")]
|
|
1167
|
+
];
|
|
1168
|
+
},
|
|
1169
|
+
update_expression(path, print) {
|
|
1170
|
+
return path.map(print, "children");
|
|
1171
|
+
},
|
|
1172
|
+
enhanced_for_statement(path, print) {
|
|
1173
|
+
const danglingComments = printDanglingComments(path);
|
|
1174
|
+
const forStatement = [
|
|
1175
|
+
danglingComments && [danglingComments, hardline$5],
|
|
1176
|
+
"for (",
|
|
1177
|
+
...printModifiers(path, print),
|
|
1178
|
+
path.call(print, "typeNode"),
|
|
1179
|
+
" ",
|
|
1180
|
+
path.call(print, "nameNode")
|
|
1181
|
+
];
|
|
1182
|
+
if (hasChild(path, "dimensionsNode")) forStatement.push(path.call(print, "dimensionsNode"));
|
|
1183
|
+
forStatement.push(" : ", path.call(print, "valueNode"), ")");
|
|
1184
|
+
const bodyType = path.node.bodyNode.type;
|
|
1185
|
+
if (bodyType === ";") forStatement.push(";");
|
|
1186
|
+
else {
|
|
1187
|
+
const body = path.call(print, "bodyNode");
|
|
1188
|
+
forStatement.push(bodyType === "block" ? [" ", body] : indent$6([line$5, body]));
|
|
1189
|
+
}
|
|
1190
|
+
return group$6(forStatement);
|
|
1191
|
+
},
|
|
1192
|
+
break_statement(path, print) {
|
|
1193
|
+
const parts = ["break"];
|
|
1194
|
+
const identifierIndex = path.node.namedChildren.findIndex(({ type }) => type === "identifier");
|
|
1195
|
+
if (identifierIndex !== -1) parts.push(" ", path.call(print, "namedChildren", identifierIndex));
|
|
1196
|
+
parts.push(";");
|
|
1197
|
+
return parts;
|
|
1198
|
+
},
|
|
1199
|
+
continue_statement(path, print) {
|
|
1200
|
+
const identifierIndex = path.node.namedChildren.findIndex(({ type }) => type === "identifier");
|
|
1201
|
+
return identifierIndex !== -1 ? [
|
|
1202
|
+
"continue ",
|
|
1203
|
+
path.call(print, "namedChildren", identifierIndex),
|
|
1204
|
+
";"
|
|
1205
|
+
] : "continue;";
|
|
1206
|
+
},
|
|
1207
|
+
return_statement: printReturnOrThrowStatement,
|
|
1208
|
+
throw_statement: printReturnOrThrowStatement,
|
|
1209
|
+
synchronized_statement(path, print) {
|
|
1210
|
+
const parenthesizedExpressionIndex = path.node.namedChildren.findIndex(({ type }) => type === "parenthesized_expression");
|
|
1211
|
+
return [
|
|
1212
|
+
"synchronized ",
|
|
1213
|
+
path.call(print, "namedChildren", parenthesizedExpressionIndex),
|
|
1214
|
+
" ",
|
|
1215
|
+
path.call(print, "bodyNode")
|
|
1216
|
+
];
|
|
1217
|
+
},
|
|
1218
|
+
try_statement(path, print, options) {
|
|
1219
|
+
const parts = ["try", path.call(print, "bodyNode")];
|
|
1220
|
+
path.each((child) => {
|
|
1221
|
+
if (child.node.type === "catch_clause" || child.node.type === "finally_clause") parts.push(print(child));
|
|
1222
|
+
}, "namedChildren");
|
|
1223
|
+
if (options?.braceStyle === "next-line") return parts;
|
|
1224
|
+
return join$6(" ", parts);
|
|
1225
|
+
},
|
|
1226
|
+
catch_clause(path, print, options) {
|
|
1227
|
+
const catchFormalParameterIndex = path.node.namedChildren.findIndex(({ type }) => type === "catch_formal_parameter");
|
|
1228
|
+
const params = group$6(indentInParentheses(path.call(print, "namedChildren", catchFormalParameterIndex), options));
|
|
1229
|
+
const body = path.call(print, "bodyNode");
|
|
1230
|
+
if (options?.braceStyle === "next-line") return [
|
|
1231
|
+
hardline$5,
|
|
1232
|
+
"catch ",
|
|
1233
|
+
params,
|
|
1234
|
+
body
|
|
1235
|
+
];
|
|
1236
|
+
return [
|
|
1237
|
+
"catch ",
|
|
1238
|
+
params,
|
|
1239
|
+
" ",
|
|
1240
|
+
body
|
|
1241
|
+
];
|
|
1242
|
+
},
|
|
1243
|
+
catch_formal_parameter(path, print) {
|
|
1244
|
+
const parts = printModifiers(path, print, "noBreak");
|
|
1245
|
+
const catchTypeIndex = path.node.namedChildren.findIndex(({ type }) => type === "catch_type");
|
|
1246
|
+
parts.push(path.call(print, "namedChildren", catchTypeIndex), " ", path.call(print, "nameNode"));
|
|
1247
|
+
if (hasChild(path, "dimensionsNode")) parts.push(path.call(print, "dimensionsNode"));
|
|
1248
|
+
return parts;
|
|
1249
|
+
},
|
|
1250
|
+
catch_type(path, print) {
|
|
1251
|
+
return join$6([line$5, "| "], path.map(print, "namedChildren"));
|
|
1252
|
+
},
|
|
1253
|
+
finally_clause(path, print, options) {
|
|
1254
|
+
if (options?.braceStyle === "next-line") return [
|
|
1255
|
+
hardline$5,
|
|
1256
|
+
"finally",
|
|
1257
|
+
path.call(print, "namedChildren", 0)
|
|
1258
|
+
];
|
|
1259
|
+
return ["finally ", path.call(print, "namedChildren", 0)];
|
|
1260
|
+
},
|
|
1261
|
+
try_with_resources_statement(path, print, options) {
|
|
1262
|
+
const resources = path.call(print, "resourcesNode");
|
|
1263
|
+
const body = path.call(print, "bodyNode");
|
|
1264
|
+
const clauses = [];
|
|
1265
|
+
path.each((child) => {
|
|
1266
|
+
if (child.node.type === "catch_clause" || child.node.type === "finally_clause") clauses.push(print(child));
|
|
1267
|
+
}, "namedChildren");
|
|
1268
|
+
if (options?.braceStyle === "next-line") return [
|
|
1269
|
+
"try ",
|
|
1270
|
+
resources,
|
|
1271
|
+
body,
|
|
1272
|
+
...clauses
|
|
1273
|
+
];
|
|
1274
|
+
return join$6(" ", [
|
|
1275
|
+
"try",
|
|
1276
|
+
resources,
|
|
1277
|
+
body,
|
|
1278
|
+
...clauses
|
|
1279
|
+
]);
|
|
1280
|
+
},
|
|
1281
|
+
resource_specification(path, print, options) {
|
|
1282
|
+
const resources = [];
|
|
1283
|
+
let hasTrailingSemicolon = false;
|
|
1284
|
+
path.each((child) => {
|
|
1285
|
+
if (child.node.type === "resource") {
|
|
1286
|
+
resources.push(print(child));
|
|
1287
|
+
hasTrailingSemicolon = false;
|
|
1288
|
+
} else if (child.node.type === ";") hasTrailingSemicolon = true;
|
|
1289
|
+
}, "children");
|
|
1290
|
+
const parts = join$6([";", line$5], resources);
|
|
1291
|
+
if (hasTrailingSemicolon) parts.push(ifBreak$1(";"));
|
|
1292
|
+
return group$6(indentInParentheses(parts, options));
|
|
1293
|
+
},
|
|
1294
|
+
resource(path, print) {
|
|
1295
|
+
if (hasChild(path, "typeNode") && hasChild(path, "nameNode") && hasChild(path, "valueNode")) {
|
|
1296
|
+
const parts = printModifiers(path, print);
|
|
1297
|
+
parts.push(path.call(print, "typeNode"), " ", path.call(print, "nameNode"));
|
|
1298
|
+
if (hasChild(path, "dimensionsNode")) parts.push(path.call(print, "dimensionsNode"));
|
|
1299
|
+
parts.push(" =");
|
|
1300
|
+
const value = path.call(print, "valueNode");
|
|
1301
|
+
if (path.node.valueNode.type === "binary_expression" || hasLeadingComments(path.node.valueNode)) parts.push(group$6(indent$6([line$5, value])));
|
|
1302
|
+
else {
|
|
1303
|
+
const groupId = Symbol("assignment");
|
|
1304
|
+
parts.push(group$6(indent$6(line$5), { id: groupId }), indentIfBreak$1(value, { groupId }));
|
|
1305
|
+
}
|
|
1306
|
+
return parts;
|
|
1307
|
+
}
|
|
1308
|
+
const resourceIndex = path.node.namedChildren.findIndex(({ type }) => type === "identifier" || type === "field_access");
|
|
1309
|
+
return path.call(print, "namedChildren", resourceIndex);
|
|
1310
|
+
},
|
|
1311
|
+
yield_statement(path, print) {
|
|
1312
|
+
return [
|
|
1313
|
+
"yield ",
|
|
1314
|
+
path.call(print, "namedChildren", 0),
|
|
1315
|
+
";"
|
|
1316
|
+
];
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
function printExpressionList(expressions) {
|
|
1320
|
+
return group$6(expressions.map((expression, index) => index === 0 ? expression : [",", indent$6([line$5, expression])]));
|
|
1321
|
+
}
|
|
1322
|
+
function printReturnOrThrowArgument(path, print, options) {
|
|
1323
|
+
const { node } = path;
|
|
1324
|
+
const argumentDoc = print(path);
|
|
1325
|
+
if (returnArgumentHasLeadingComment(node)) return [
|
|
1326
|
+
"(",
|
|
1327
|
+
indent$6([hardline$5, argumentDoc]),
|
|
1328
|
+
closingBracketLine(options, hardline$5),
|
|
1329
|
+
")"
|
|
1330
|
+
];
|
|
1331
|
+
if (node.type === "binary_expression") return group$6([
|
|
1332
|
+
ifBreak$1("("),
|
|
1333
|
+
indent$6([softline$2, argumentDoc]),
|
|
1334
|
+
closingBracketLine(options),
|
|
1335
|
+
ifBreak$1(")")
|
|
1336
|
+
]);
|
|
1337
|
+
return argumentDoc;
|
|
1338
|
+
}
|
|
1339
|
+
function printReturnOrThrowStatement(path, print, options) {
|
|
1340
|
+
const { node } = path;
|
|
1341
|
+
return [
|
|
1342
|
+
node.type === "throw_statement" ? "throw" : "return",
|
|
1343
|
+
node.namedChildren.length ? [" ", path.call(() => printReturnOrThrowArgument(path, print, options), "namedChildren", 0)] : "",
|
|
1344
|
+
";"
|
|
1345
|
+
];
|
|
1346
|
+
}
|
|
1347
|
+
// src/printers/classes.ts
|
|
1348
|
+
const { group: group$5, hardline: hardline$4, indent: indent$5, join: join$5, line: line$4 } = builders;
|
|
1349
|
+
var classes_default = {
|
|
1350
|
+
class_declaration(path, print, options) {
|
|
1351
|
+
const parts = ["class ", path.call(print, "nameNode")];
|
|
1352
|
+
const definedClauses = definedKeys(path.node, [
|
|
1353
|
+
"superclassNode",
|
|
1354
|
+
"interfacesNode",
|
|
1355
|
+
"permitsNode"
|
|
1356
|
+
]);
|
|
1357
|
+
const hasMultipleClauses = definedClauses.length > 1;
|
|
1358
|
+
if (hasChild(path, "type_parametersNode")) {
|
|
1359
|
+
const typeParameters = path.call(print, "type_parametersNode");
|
|
1360
|
+
parts.push(hasMultipleClauses ? group$5(indent$5(typeParameters)) : options?.braceStyle === "next-line" ? group$5(typeParameters) : typeParameters);
|
|
1361
|
+
}
|
|
1362
|
+
if (definedClauses.length) {
|
|
1363
|
+
const clauses = definedClauses.flatMap((clause) => {
|
|
1364
|
+
if (!hasChild(path, clause)) return [];
|
|
1365
|
+
return [clause === "superclassNode" || clause === "interfacesNode" ? hardline$4 : line$4, path.call(print, clause)];
|
|
1366
|
+
});
|
|
1367
|
+
const hasBody = path.node.bodyNode.namedChildren.length > 0;
|
|
1368
|
+
const afterClauses = options?.braceStyle === "next-line" ? "" : hasBody ? line$4 : " ";
|
|
1369
|
+
const clauseGroup = [indent$5(clauses), afterClauses];
|
|
1370
|
+
parts.push(hasMultipleClauses ? clauseGroup : group$5(clauseGroup));
|
|
1371
|
+
} else if (options?.braceStyle !== "next-line") parts.push(" ");
|
|
1372
|
+
return [
|
|
1373
|
+
...printModifiers(path, print, "declarationOnly"),
|
|
1374
|
+
group$5(parts),
|
|
1375
|
+
path.call(print, "bodyNode")
|
|
1376
|
+
];
|
|
1377
|
+
},
|
|
1378
|
+
type_parameters: printTypeParameters,
|
|
1379
|
+
superclass(path, print) {
|
|
1380
|
+
return ["extends ", path.call(print, "namedChildren", 0)];
|
|
1381
|
+
},
|
|
1382
|
+
super_interfaces(path, print) {
|
|
1383
|
+
return group$5(["implements", indent$5([line$4, path.call(print, "namedChildren", 0)])]);
|
|
1384
|
+
},
|
|
1385
|
+
permits(path, print) {
|
|
1386
|
+
return group$5(["permits", indent$5([line$4, path.call(print, "namedChildren", 0)])]);
|
|
1387
|
+
},
|
|
1388
|
+
type_list(path, print) {
|
|
1389
|
+
return join$5([",", line$4], path.map(print, "namedChildren"));
|
|
1390
|
+
},
|
|
1391
|
+
class_body(path, print, options) {
|
|
1392
|
+
return printBlock(path, printBodyDeclarations(path, print, path.parent?.type === "class_declaration" && options?.braceStyle !== "next-line"), options);
|
|
1393
|
+
},
|
|
1394
|
+
field_declaration: printVariableDeclaration,
|
|
1395
|
+
variable_declarator(path, print) {
|
|
1396
|
+
const leftDoc = [path.call(print, "nameNode")];
|
|
1397
|
+
if (hasChild(path, "dimensionsNode")) leftDoc.push(path.call(print, "dimensionsNode"));
|
|
1398
|
+
return printAssignment(leftDoc, " =", hasChild(path, "valueNode") ? path.call(print, "valueNode") : void 0, path.node.valueNode);
|
|
1399
|
+
},
|
|
1400
|
+
method_declaration(path, print) {
|
|
1401
|
+
const modifiers = printModifiers(path, print);
|
|
1402
|
+
const declaration = [];
|
|
1403
|
+
if (hasChild(path, "type_parametersNode")) declaration.push(group$5(path.call(print, "type_parametersNode")), " ");
|
|
1404
|
+
path.each((child) => {
|
|
1405
|
+
if (child.node.type === "annotation" || child.node.type === "marker_annotation") declaration.push(print(child), " ");
|
|
1406
|
+
}, "children");
|
|
1407
|
+
declaration.push(path.call(print, "typeNode"));
|
|
895
1408
|
if (hasChild(path, "dimensionsNode")) declaration.push(path.call(print, "dimensionsNode"));
|
|
896
1409
|
declaration.push(" ", path.call(print, "nameNode"), group$5(path.call(print, "parametersNode")));
|
|
897
1410
|
const throwsIndex = path.node.namedChildren.findIndex(({ type }) => type === "throws");
|
|
898
|
-
if (throwsIndex !== -1) declaration.push(group$5(indent$5([hardline$
|
|
1411
|
+
if (throwsIndex !== -1) declaration.push(group$5(indent$5([hardline$4, path.call(print, "namedChildren", throwsIndex)])));
|
|
899
1412
|
return hasChild(path, "bodyNode") ? [
|
|
900
1413
|
modifiers,
|
|
901
1414
|
group$5(declaration),
|
|
@@ -910,14 +1423,14 @@ var classes_default = {
|
|
|
910
1423
|
receiver_parameter(path, print) {
|
|
911
1424
|
return path.map((child) => child.isLast ? print(child) : [print(child), child.node.type === "identifier" ? "." : " "], "namedChildren");
|
|
912
1425
|
},
|
|
913
|
-
formal_parameters(path, print) {
|
|
1426
|
+
formal_parameters(path, print, options) {
|
|
914
1427
|
const parameters = path.parent?.type === "record_declaration" ? printBodyDeclarations(path, print) : path.map(print, "namedChildren");
|
|
915
1428
|
if (parameters.length === 0) return [
|
|
916
1429
|
"(",
|
|
917
1430
|
printDanglingCommentsInList(path),
|
|
918
1431
|
")"
|
|
919
1432
|
];
|
|
920
|
-
return indentInParentheses(join$5([",", line$
|
|
1433
|
+
return indentInParentheses(join$5([",", line$4], parameters), options);
|
|
921
1434
|
},
|
|
922
1435
|
formal_parameter(path, print) {
|
|
923
1436
|
const parameter = printModifiers(path, print, path.grandparent?.type === "record_declaration" ? "avoidBreak" : "noBreak");
|
|
@@ -934,7 +1447,8 @@ var classes_default = {
|
|
|
934
1447
|
return parts;
|
|
935
1448
|
},
|
|
936
1449
|
throws(path, print) {
|
|
937
|
-
|
|
1450
|
+
const exceptions = path.map(print, "namedChildren");
|
|
1451
|
+
return exceptions.length === 1 ? ["throws ", exceptions[0]] : ["throws", group$5(indent$5([line$4, ...join$5([",", line$4], exceptions)]))];
|
|
938
1452
|
},
|
|
939
1453
|
static_initializer(path, print) {
|
|
940
1454
|
return ["static ", path.call(print, "namedChildren", 0)];
|
|
@@ -945,7 +1459,7 @@ var classes_default = {
|
|
|
945
1459
|
if (hasChild(path, "type_parametersNode")) declaration.push(group$5(path.call(print, "type_parametersNode")), " ");
|
|
946
1460
|
declaration.push(path.call(print, "nameNode"), group$5(path.call(print, "parametersNode")));
|
|
947
1461
|
const throwsIndex = path.node.namedChildren.findIndex(({ type }) => type === "throws");
|
|
948
|
-
if (throwsIndex !== -1) declaration.push(group$5(indent$5([hardline$
|
|
1462
|
+
if (throwsIndex !== -1) declaration.push(group$5(indent$5([hardline$4, path.call(print, "namedChildren", throwsIndex)])));
|
|
949
1463
|
return [
|
|
950
1464
|
modifiers,
|
|
951
1465
|
group$5(declaration),
|
|
@@ -984,14 +1498,14 @@ var classes_default = {
|
|
|
984
1498
|
}
|
|
985
1499
|
modifiers.sort((a, b) => (indexByModifier.get(a) ?? -1) - (indexByModifier.get(b) ?? -1));
|
|
986
1500
|
if (modifiers.length || typeAnnotations.length) parts.push(join$5(" ", [...modifiers, ...typeAnnotations]));
|
|
987
|
-
return join$5(annotationMode === "avoidBreak" ? line$
|
|
1501
|
+
return join$5(annotationMode === "avoidBreak" ? line$4 : annotationMode === "noBreak" ? " " : hardline$4, parts);
|
|
988
1502
|
},
|
|
989
|
-
enum_declaration(path, print) {
|
|
1503
|
+
enum_declaration(path, print, options) {
|
|
990
1504
|
const modifiers = printModifiers(path, print, "declarationOnly");
|
|
991
1505
|
const parts = ["enum ", path.call(print, "nameNode")];
|
|
992
1506
|
if (hasChild(path, "interfacesNode")) {
|
|
993
1507
|
const hasBody = path.node.bodyNode.namedChildren.length > 0;
|
|
994
|
-
parts.push(indent$5([hardline$
|
|
1508
|
+
parts.push(indent$5([hardline$4, path.call(print, "interfacesNode")]), options?.braceStyle === "next-line" ? "" : hasBody ? line$4 : " ");
|
|
995
1509
|
} else parts.push(" ");
|
|
996
1510
|
return [
|
|
997
1511
|
...modifiers,
|
|
@@ -1007,16 +1521,16 @@ var classes_default = {
|
|
|
1007
1521
|
const hasDeclarations = path.node.namedChildren[enumBodyDeclarationsIndex].namedChildren.length > 0;
|
|
1008
1522
|
const enumBodyDeclarations = parts.pop();
|
|
1009
1523
|
if (hasDeclarations) {
|
|
1010
|
-
if (!parts.length) declarations.push(hardline$
|
|
1524
|
+
if (!parts.length) declarations.push(hardline$4);
|
|
1011
1525
|
declarations.push(enumBodyDeclarations);
|
|
1012
1526
|
}
|
|
1013
1527
|
}
|
|
1014
1528
|
const contents = [];
|
|
1015
1529
|
if (parts.length) {
|
|
1016
|
-
contents.push(join$5([",", hardline$
|
|
1530
|
+
contents.push(join$5([",", hardline$4], parts));
|
|
1017
1531
|
if (!declarations.length && options.trailingComma !== "none") contents.push(",");
|
|
1018
1532
|
}
|
|
1019
|
-
if (declarations.length) contents.push(";", hardline$
|
|
1533
|
+
if (declarations.length) contents.push(";", hardline$4, ...declarations);
|
|
1020
1534
|
return printBlock(path, contents.length ? [contents] : [], options);
|
|
1021
1535
|
},
|
|
1022
1536
|
enum_constant(path, print) {
|
|
@@ -1027,7 +1541,7 @@ var classes_default = {
|
|
|
1027
1541
|
return initializer;
|
|
1028
1542
|
},
|
|
1029
1543
|
enum_body_declarations(path, print) {
|
|
1030
|
-
return join$5(hardline$
|
|
1544
|
+
return join$5(hardline$4, printBodyDeclarations(path, print));
|
|
1031
1545
|
},
|
|
1032
1546
|
record_declaration(path, print) {
|
|
1033
1547
|
const modifiers = printModifiers(path, print, "declarationOnly");
|
|
@@ -1036,8 +1550,8 @@ var classes_default = {
|
|
|
1036
1550
|
parts.push(group$5(path.call(print, "parametersNode")));
|
|
1037
1551
|
if (hasChild(path, "interfacesNode")) {
|
|
1038
1552
|
const hasBody = path.node.bodyNode.namedChildren.length > 0;
|
|
1039
|
-
const interfaces = [hardline$
|
|
1040
|
-
parts.push(group$5([indent$5(interfaces), hasBody ? line$
|
|
1553
|
+
const interfaces = [hardline$4, path.call(print, "interfacesNode")];
|
|
1554
|
+
parts.push(group$5([indent$5(interfaces), hasBody ? line$4 : " "]));
|
|
1041
1555
|
} else parts.push(" ");
|
|
1042
1556
|
return [
|
|
1043
1557
|
...modifiers,
|
|
@@ -1067,14 +1581,9 @@ const indexByModifier = [
|
|
|
1067
1581
|
"non-sealed",
|
|
1068
1582
|
"strictfp"
|
|
1069
1583
|
].reduce((map, name, index) => map.set(name, index), /* @__PURE__ */ new Map());
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
}
|
|
1074
|
-
//#endregion
|
|
1075
|
-
//#region src/printers/expressions.ts
|
|
1076
|
-
const { align, breakParent: breakParent$1, conditionalGroup, dedent, group: group$4, hardline: hardline$4, ifBreak, indent: indent$4, indentIfBreak, join: join$4, line: line$4, lineSuffixBoundary, softline: softline$1 } = builders;
|
|
1077
|
-
const { getNextNonSpaceNonCommentCharacterIndex, hasNewline: hasNewline$1, isNextLineEmpty } = util;
|
|
1584
|
+
// src/printers/expressions.ts
|
|
1585
|
+
const { align, breakParent, conditionalGroup, dedent, group: group$4, hardline: hardline$3, ifBreak, indent: indent$4, indentIfBreak, join: join$4, line: line$3, lineSuffixBoundary, softline: softline$1 } = builders;
|
|
1586
|
+
const { getNextNonSpaceNonCommentCharacterIndex, hasNewline, isNextLineEmpty } = util;
|
|
1078
1587
|
const { removeLines, willBreak } = utils;
|
|
1079
1588
|
var expressions_default = {
|
|
1080
1589
|
lambda_expression(path, print, options, args) {
|
|
@@ -1097,10 +1606,10 @@ var expressions_default = {
|
|
|
1097
1606
|
functionBody = node.bodyNode;
|
|
1098
1607
|
} else path.call(rec, "bodyNode");
|
|
1099
1608
|
})();
|
|
1100
|
-
const shouldPutBodyOnSameLine = !functionBody.comments?.some((comment) => comment.leading && hasNewline
|
|
1609
|
+
const shouldPutBodyOnSameLine = !functionBody.comments?.some((comment) => comment.leading && hasNewline(options.originalText, comment.end.index)) && mayBreakAfterShortPrefix(functionBody);
|
|
1101
1610
|
const chainGroupId = Symbol("arrow-chain");
|
|
1102
1611
|
const signaturesDoc = printArrowFunctionSignatures(path, { signatureDocs });
|
|
1103
|
-
bodyDoc = printArrowFunctionBody(path, args, {
|
|
1612
|
+
bodyDoc = printArrowFunctionBody(path, args, options, {
|
|
1104
1613
|
bodyDoc,
|
|
1105
1614
|
bodyComments,
|
|
1106
1615
|
shouldPutBodyOnSameLine
|
|
@@ -1117,8 +1626,8 @@ var expressions_default = {
|
|
|
1117
1626
|
if (child.node.type === "identifier") identifiers.push(print(child));
|
|
1118
1627
|
}, "namedChildren");
|
|
1119
1628
|
if (!identifiers.length) return "()";
|
|
1120
|
-
const parameters = join$4([",", line$
|
|
1121
|
-
if (identifiers.length > 1 || willBreak(identifiers)) return group$4(indentInParentheses(parameters));
|
|
1629
|
+
const parameters = join$4([",", line$3], identifiers);
|
|
1630
|
+
if (identifiers.length > 1 || willBreak(identifiers)) return group$4(indentInParentheses(parameters, options));
|
|
1122
1631
|
return options.arrowParens === "avoid" ? parameters : [
|
|
1123
1632
|
"(",
|
|
1124
1633
|
...parameters,
|
|
@@ -1141,27 +1650,39 @@ var expressions_default = {
|
|
|
1141
1650
|
i++;
|
|
1142
1651
|
} while (currentParent && currentParent.type === node.type && currentParent.conditionNode !== previousParent);
|
|
1143
1652
|
const firstNonConditionalParent = currentParent || parent;
|
|
1144
|
-
const
|
|
1145
|
-
const
|
|
1146
|
-
|
|
1653
|
+
const operatorAtEnd = options.experimentalOperatorPosition === "end";
|
|
1654
|
+
const printBranch = (nodePropertyName) => operatorAtEnd || isTextBlock(node[nodePropertyName]) ? path.call(print, nodePropertyName) : options.useTabs ? indent$4(path.call(print, nodePropertyName)) : align(2, path.call(print, nodePropertyName));
|
|
1655
|
+
const openParen = consequentNode.type === node.type ? ifBreak("", "(") : "";
|
|
1656
|
+
const closeParen = consequentNode.type === node.type ? ifBreak("", ")") : "";
|
|
1657
|
+
const part = operatorAtEnd ? [
|
|
1658
|
+
" ?",
|
|
1659
|
+
line$3,
|
|
1660
|
+
openParen,
|
|
1661
|
+
printBranch("consequenceNode"),
|
|
1662
|
+
closeParen,
|
|
1663
|
+
" :",
|
|
1664
|
+
line$3,
|
|
1665
|
+
printBranch("alternativeNode")
|
|
1666
|
+
] : [
|
|
1667
|
+
line$3,
|
|
1147
1668
|
"? ",
|
|
1148
|
-
|
|
1669
|
+
openParen,
|
|
1149
1670
|
printBranch("consequenceNode"),
|
|
1150
|
-
|
|
1151
|
-
line$
|
|
1671
|
+
closeParen,
|
|
1672
|
+
line$3,
|
|
1152
1673
|
": ",
|
|
1153
1674
|
printBranch("alternativeNode")
|
|
1154
1675
|
];
|
|
1155
|
-
parts.push(parent.type !== node.type || parent.alternativeNode === node || isParentTest ? part : options.useTabs ? dedent(indent$4(part)) : align(Math.max(0, options.tabWidth - 2), part));
|
|
1676
|
+
parts.push(operatorAtEnd || parent.type !== node.type || parent.alternativeNode === node || isParentTest ? part : options.useTabs ? dedent(indent$4(part)) : align(Math.max(0, options.tabWidth - 2), part));
|
|
1156
1677
|
const maybeGroup = (doc) => parent === firstNonConditionalParent ? group$4(doc) : doc;
|
|
1157
1678
|
const breakClosingParen = parent.type === "explicit_constructor_invocation" || parent.type === "field_access" || parent.type === "method_invocation" || parent.type === "method_reference" || parent.type === "object_creation_expression";
|
|
1158
1679
|
const shouldExtraIndent = shouldExtraIndentForTernaryExpression(path);
|
|
1159
1680
|
const result = maybeGroup([
|
|
1160
1681
|
printTernaryTest(path, print),
|
|
1161
|
-
forceNoIndent ? parts : indent$4(parts),
|
|
1162
|
-
breakClosingParen && !shouldExtraIndent ?
|
|
1682
|
+
forceNoIndent && !operatorAtEnd ? parts : indent$4(parts),
|
|
1683
|
+
breakClosingParen && !shouldExtraIndent ? closingBracketLine(options) : ""
|
|
1163
1684
|
]);
|
|
1164
|
-
return isParentTest || shouldExtraIndent ? group$4([indent$4([softline$1, result]),
|
|
1685
|
+
return isParentTest || shouldExtraIndent ? group$4([indent$4([softline$1, result]), closingBracketLine(options)]) : result;
|
|
1165
1686
|
},
|
|
1166
1687
|
assignment_expression(path, print) {
|
|
1167
1688
|
const { node } = path;
|
|
@@ -1174,7 +1695,7 @@ var expressions_default = {
|
|
|
1174
1695
|
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
1696
|
const parts = printBinaryExpressions(path, print, options, isInsideParentheses);
|
|
1176
1697
|
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]),
|
|
1698
|
+
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
1699
|
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
1700
|
if (parts.length === 0) return "";
|
|
1180
1701
|
const firstGroupIndex = parts.findIndex((part) => typeof part !== "string" && !Array.isArray(part) && part.type === "group");
|
|
@@ -1186,13 +1707,13 @@ var expressions_default = {
|
|
|
1186
1707
|
return group$4(indent$4(path.map((child) => {
|
|
1187
1708
|
const doc = print(child, { annotationMode: "noBreak" });
|
|
1188
1709
|
if (!child.previous) return doc;
|
|
1189
|
-
return [(options.experimentalOperatorPosition === "start" ? child.node.type === "instanceof" : child.previous.type === "instanceof") ? line$
|
|
1710
|
+
return [(options.experimentalOperatorPosition === "start" ? child.node.type === "instanceof" : child.previous.type === "instanceof") ? line$3 : " ", doc];
|
|
1190
1711
|
}, "children")));
|
|
1191
1712
|
},
|
|
1192
|
-
unary_expression(path, print) {
|
|
1713
|
+
unary_expression(path, print, options) {
|
|
1193
1714
|
const parts = [path.call(print, "operatorNode")];
|
|
1194
1715
|
const operandDoc = path.call(print, "operandNode");
|
|
1195
|
-
if (path.node.operandNode.comments) parts.push(group$4(indentInParentheses(operandDoc)));
|
|
1716
|
+
if (path.node.operandNode.comments) parts.push(group$4(indentInParentheses(operandDoc, options)));
|
|
1196
1717
|
else parts.push(operandDoc);
|
|
1197
1718
|
return parts;
|
|
1198
1719
|
},
|
|
@@ -1202,7 +1723,7 @@ var expressions_default = {
|
|
|
1202
1723
|
const typeArgumentsIndex = path.node.namedChildren.findIndex(({ type }) => type === "type_arguments");
|
|
1203
1724
|
return [path.call(print, "namedChildren", typeIdentifierIndex), path.call(print, "namedChildren", typeArgumentsIndex)];
|
|
1204
1725
|
},
|
|
1205
|
-
parenthesized_expression(path, print) {
|
|
1726
|
+
parenthesized_expression(path, print, options) {
|
|
1206
1727
|
const expression = path.call(print, "namedChildren", 0);
|
|
1207
1728
|
const parentType = path.parent?.type;
|
|
1208
1729
|
const grandparentType = path.grandparent?.type;
|
|
@@ -1211,12 +1732,12 @@ var expressions_default = {
|
|
|
1211
1732
|
const hasTernary = expressionType === "ternary_expression";
|
|
1212
1733
|
const hasSuffix = parentType && (parentType === "array_access" || parentType === "explicit_constructor_invocation" || parentType === "field_access" || parentType === "method_invocation" || parentType === "method_reference" || parentType === "object_creation_expression");
|
|
1213
1734
|
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)));
|
|
1735
|
+
if (!hasLambda && hasSuffix && (!hasTernary || isAssignment)) return group$4(indentInParentheses(hasTernary ? group$4(expression) : expression, options));
|
|
1736
|
+
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
1737
|
else if (hasTernary && hasSuffix && !isAssignment) return group$4([
|
|
1217
1738
|
"(",
|
|
1218
1739
|
expression,
|
|
1219
|
-
|
|
1740
|
+
closingBracketLine(options),
|
|
1220
1741
|
")"
|
|
1221
1742
|
]);
|
|
1222
1743
|
else return group$4([
|
|
@@ -1234,7 +1755,7 @@ var expressions_default = {
|
|
|
1234
1755
|
")"
|
|
1235
1756
|
] : [
|
|
1236
1757
|
"(",
|
|
1237
|
-
indent$4([softline$1, join$4([" &", line$
|
|
1758
|
+
indent$4([softline$1, join$4([" &", line$3], path.map(print, "typeNodes"))]),
|
|
1238
1759
|
softline$1,
|
|
1239
1760
|
")"
|
|
1240
1761
|
]),
|
|
@@ -1259,7 +1780,11 @@ var expressions_default = {
|
|
|
1259
1780
|
const args = path.node.namedChildren;
|
|
1260
1781
|
if (args.length === 0) {
|
|
1261
1782
|
const shouldBreak = path.node.comments?.some(({ type, leading, trailing }) => !leading && !trailing && type === "line_comment");
|
|
1262
|
-
return group$4(
|
|
1783
|
+
return group$4([
|
|
1784
|
+
"(",
|
|
1785
|
+
printDanglingCommentsInList(path),
|
|
1786
|
+
")"
|
|
1787
|
+
], { shouldBreak });
|
|
1263
1788
|
}
|
|
1264
1789
|
const lastArgIndex = args.length - 1;
|
|
1265
1790
|
let anyArgEmptyLine = false;
|
|
@@ -1271,21 +1796,21 @@ var expressions_default = {
|
|
|
1271
1796
|
argDoc = [
|
|
1272
1797
|
argDoc,
|
|
1273
1798
|
",",
|
|
1274
|
-
hardline$
|
|
1275
|
-
hardline$
|
|
1799
|
+
hardline$3,
|
|
1800
|
+
hardline$3
|
|
1276
1801
|
];
|
|
1277
1802
|
} else argDoc = [
|
|
1278
1803
|
argDoc,
|
|
1279
1804
|
",",
|
|
1280
|
-
line$
|
|
1805
|
+
line$3
|
|
1281
1806
|
];
|
|
1282
1807
|
printedArguments.push(argDoc);
|
|
1283
1808
|
}, "namedChildren");
|
|
1284
1809
|
function allArgsBrokenOut() {
|
|
1285
1810
|
return group$4([
|
|
1286
1811
|
"(",
|
|
1287
|
-
indent$4([line$
|
|
1288
|
-
line$
|
|
1812
|
+
indent$4([line$3, ...printedArguments]),
|
|
1813
|
+
closingBracketLine(options, line$3),
|
|
1289
1814
|
")"
|
|
1290
1815
|
], { shouldBreak: true });
|
|
1291
1816
|
}
|
|
@@ -1300,7 +1825,7 @@ var expressions_default = {
|
|
|
1300
1825
|
if (caught instanceof ArgExpansionBailout) return allArgsBrokenOut();
|
|
1301
1826
|
throw caught;
|
|
1302
1827
|
}
|
|
1303
|
-
if (willBreak(firstArg)) return [breakParent
|
|
1828
|
+
if (willBreak(firstArg)) return [breakParent, conditionalGroup([[
|
|
1304
1829
|
"(",
|
|
1305
1830
|
group$4(firstArg, { shouldBreak: true }),
|
|
1306
1831
|
", ",
|
|
@@ -1325,7 +1850,7 @@ var expressions_default = {
|
|
|
1325
1850
|
allArgsBrokenOut()
|
|
1326
1851
|
]);
|
|
1327
1852
|
}
|
|
1328
|
-
if (shouldExpandLastArg(args)) {
|
|
1853
|
+
if (shouldExpandLastArg(args, options)) {
|
|
1329
1854
|
const headArgs = printedArguments.slice(0, -1);
|
|
1330
1855
|
if (headArgs.some(willBreak)) return allArgsBrokenOut();
|
|
1331
1856
|
let lastArg;
|
|
@@ -1335,7 +1860,7 @@ var expressions_default = {
|
|
|
1335
1860
|
if (caught instanceof ArgExpansionBailout) return allArgsBrokenOut();
|
|
1336
1861
|
throw caught;
|
|
1337
1862
|
}
|
|
1338
|
-
if (willBreak(lastArg)) return [breakParent
|
|
1863
|
+
if (willBreak(lastArg)) return [breakParent, conditionalGroup([[
|
|
1339
1864
|
"(",
|
|
1340
1865
|
...headArgs,
|
|
1341
1866
|
group$4(lastArg, { shouldBreak: true }),
|
|
@@ -1357,7 +1882,7 @@ var expressions_default = {
|
|
|
1357
1882
|
allArgsBrokenOut()
|
|
1358
1883
|
]);
|
|
1359
1884
|
}
|
|
1360
|
-
return group$4(indentInParentheses(printedArguments), { shouldBreak: printedArguments.some(willBreak) || anyArgEmptyLine });
|
|
1885
|
+
return group$4(indentInParentheses(printedArguments, options), { shouldBreak: printedArguments.some(willBreak) || anyArgEmptyLine });
|
|
1361
1886
|
},
|
|
1362
1887
|
array_creation_expression(path, print) {
|
|
1363
1888
|
const parts = ["new "];
|
|
@@ -1398,8 +1923,8 @@ var expressions_default = {
|
|
|
1398
1923
|
record_pattern(path, print) {
|
|
1399
1924
|
return path.map(print, "children");
|
|
1400
1925
|
},
|
|
1401
|
-
record_pattern_body(path, print) {
|
|
1402
|
-
return group$4(indentInParentheses(join$4([",", line$
|
|
1926
|
+
record_pattern_body(path, print, options) {
|
|
1927
|
+
return group$4(indentInParentheses(join$4([",", line$3], path.map(print, "namedChildren")), options));
|
|
1403
1928
|
},
|
|
1404
1929
|
record_pattern_component(path, print) {
|
|
1405
1930
|
return join$4(" ", path.map(print, "children"));
|
|
@@ -1446,19 +1971,19 @@ function printArrowFunctionSignatures(path, { signatureDocs }) {
|
|
|
1446
1971
|
if (node.fieldName !== "object" && parent?.type === "method_invocation" || parent?.type === "binary_expression") return group$4([
|
|
1447
1972
|
signatureDocs[0],
|
|
1448
1973
|
" ->",
|
|
1449
|
-
indent$4([line$
|
|
1974
|
+
indent$4([line$3, join$4([" ->", line$3], signatureDocs.slice(1))])
|
|
1450
1975
|
]);
|
|
1451
|
-
if (node.fieldName === "object" && parent?.type === "method_invocation") return group$4(join$4([" ->", line$
|
|
1452
|
-
return group$4(indent$4(join$4([" ->", line$
|
|
1976
|
+
if (node.fieldName === "object" && parent?.type === "method_invocation") return group$4(join$4([" ->", line$3], signatureDocs));
|
|
1977
|
+
return group$4(indent$4(join$4([" ->", line$3], signatureDocs)));
|
|
1453
1978
|
}
|
|
1454
|
-
function printArrowFunctionBody(path, args, { bodyDoc, bodyComments, shouldPutBodyOnSameLine }) {
|
|
1455
|
-
const trailingSpace = args && typeof args === "object" && "expandLastArg" in args && args.expandLastArg && !path.node.comments ?
|
|
1979
|
+
function printArrowFunctionBody(path, args, options, { bodyDoc, bodyComments, shouldPutBodyOnSameLine }) {
|
|
1980
|
+
const trailingSpace = args && typeof args === "object" && "expandLastArg" in args && args.expandLastArg && !path.node.comments ? closingBracketLine(options) : "";
|
|
1456
1981
|
return shouldPutBodyOnSameLine ? [
|
|
1457
1982
|
" ",
|
|
1458
1983
|
bodyDoc,
|
|
1459
1984
|
bodyComments
|
|
1460
1985
|
] : [indent$4([
|
|
1461
|
-
line$
|
|
1986
|
+
line$3,
|
|
1462
1987
|
bodyDoc,
|
|
1463
1988
|
bodyComments
|
|
1464
1989
|
]), trailingSpace];
|
|
@@ -1490,7 +2015,7 @@ function printMemberChain(path, print, options) {
|
|
|
1490
2015
|
printedNodes.unshift({
|
|
1491
2016
|
node,
|
|
1492
2017
|
hasTrailingEmptyLine,
|
|
1493
|
-
printed: [printComments(path, printMethodInvocation(path, print)), hasTrailingEmptyLine ? hardline$
|
|
2018
|
+
printed: [printComments(path, printMethodInvocation(path, print)), hasTrailingEmptyLine ? hardline$3 : ""]
|
|
1494
2019
|
});
|
|
1495
2020
|
path.call(rec, "objectNode");
|
|
1496
2021
|
} else if (hasType(path, "array_access")) {
|
|
@@ -1514,28 +2039,32 @@ function printMemberChain(path, print, options) {
|
|
|
1514
2039
|
if (hasType(path, "method_invocation")) {
|
|
1515
2040
|
printedNodes.unshift({
|
|
1516
2041
|
node,
|
|
1517
|
-
printed:
|
|
2042
|
+
printed: printMethodInvocation(path, print)
|
|
1518
2043
|
});
|
|
1519
2044
|
if (hasChild(path, "objectNode")) path.call(rec, "objectNode");
|
|
1520
2045
|
} else if (hasType(path, "array_access")) {
|
|
1521
2046
|
printedNodes.unshift({
|
|
1522
2047
|
node,
|
|
1523
|
-
printed:
|
|
2048
|
+
printed: printArrayAccess(path, print)
|
|
1524
2049
|
});
|
|
1525
2050
|
if (hasChild(path, "arrayNode")) path.call(rec, "arrayNode");
|
|
1526
2051
|
} else if (hasType(path, "field_access")) {
|
|
1527
2052
|
printedNodes.unshift({
|
|
1528
2053
|
node,
|
|
1529
|
-
printed:
|
|
2054
|
+
printed: printFieldAccess(path, print)
|
|
1530
2055
|
});
|
|
1531
2056
|
if (hasChild(path, "objectNode")) path.call(rec, "objectNode");
|
|
1532
2057
|
}
|
|
2058
|
+
node.comments?.filter(({ leading }) => leading).filter(({ start }) => start.index >= node.start.index).filter(({ end }) => end.index <= node.end.index).map((comment) => comment.leading = false);
|
|
1533
2059
|
const danglingComments = printDanglingComments(path);
|
|
1534
|
-
if (danglingComments)
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
2060
|
+
if (danglingComments) {
|
|
2061
|
+
const lastNode = printedNodes.at(-1);
|
|
2062
|
+
lastNode.printed = [
|
|
2063
|
+
danglingComments,
|
|
2064
|
+
hardline$3,
|
|
2065
|
+
lastNode.printed
|
|
2066
|
+
];
|
|
2067
|
+
}
|
|
1539
2068
|
const groups = [];
|
|
1540
2069
|
let currentGroup = [printedNodes[0]];
|
|
1541
2070
|
let i = 1;
|
|
@@ -1586,20 +2115,20 @@ function printMemberChain(path, print, options) {
|
|
|
1586
2115
|
}
|
|
1587
2116
|
function printIndentedGroup(groups) {
|
|
1588
2117
|
if (groups.length === 0) return "";
|
|
1589
|
-
return indent$4([hardline$
|
|
2118
|
+
return indent$4([hardline$3, join$4(hardline$3, groups.map(printGroup))]);
|
|
1590
2119
|
}
|
|
1591
2120
|
const printedGroups = groups.map(printGroup);
|
|
1592
2121
|
const oneLine = printedGroups;
|
|
1593
2122
|
const cutoff = shouldMerge ? 3 : 2;
|
|
1594
2123
|
const flatGroups = groups.flat();
|
|
1595
|
-
const nodeHasComment = flatGroups.some((node) => node.node.comments?.some(({ leading }) => leading)) || flatGroups.slice(0, -1).some((node) => node.node.comments?.some(({ trailing }) => trailing));
|
|
2124
|
+
const nodeHasComment = flatGroups.at(-1).node.comments?.some(({ leading, trailing }) => !leading && !trailing) || flatGroups.slice(1, -1).some((node) => node.node.comments?.some(({ leading }) => leading)) || flatGroups.slice(0, -1).some((node) => node.node.comments?.some(({ trailing }) => trailing));
|
|
1596
2125
|
if (groups.length <= cutoff && !nodeHasComment && !groups.some((g) => g.at(-1).hasTrailingEmptyLine)) return group$4(oneLine);
|
|
1597
2126
|
const lastNodeBeforeIndent = groups[shouldMerge ? 1 : 0].at(-1).node;
|
|
1598
2127
|
const shouldHaveEmptyLineBeforeIndent = lastNodeBeforeIndent.type !== "method_invocation" && shouldInsertEmptyLineAfter(lastNodeBeforeIndent);
|
|
1599
2128
|
const expanded = [
|
|
1600
2129
|
printGroup(groups[0]),
|
|
1601
2130
|
shouldMerge ? groups.slice(1, 2).map(printGroup) : "",
|
|
1602
|
-
shouldHaveEmptyLineBeforeIndent ? hardline$
|
|
2131
|
+
shouldHaveEmptyLineBeforeIndent ? hardline$3 : "",
|
|
1603
2132
|
printIndentedGroup(groups.slice(shouldMerge ? 2 : 1))
|
|
1604
2133
|
];
|
|
1605
2134
|
const methodInvocations = printedNodes.map(({ node }) => node).filter((node) => node.type === "method_invocation");
|
|
@@ -1610,7 +2139,7 @@ function printMemberChain(path, print, options) {
|
|
|
1610
2139
|
}
|
|
1611
2140
|
let result;
|
|
1612
2141
|
if (nodeHasComment || methodInvocations.length > 2 && methodInvocations.some((inv) => !inv.argumentsNode.namedChildren.every((arg) => isSimpleCallArgument(arg))) || printedGroups.slice(0, -1).some(willBreak) || lastGroupWillBreakAndOtherCallsHaveFunctionArguments()) result = group$4(expanded);
|
|
1613
|
-
else result = [willBreak(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent
|
|
2142
|
+
else result = [willBreak(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent : "", conditionalGroup([oneLine, expanded])];
|
|
1614
2143
|
return result;
|
|
1615
2144
|
}
|
|
1616
2145
|
function printMethodInvocation(path, print) {
|
|
@@ -1660,14 +2189,14 @@ function printBinaryExpressions(path, print, options, isInsideParentheses) {
|
|
|
1660
2189
|
const operatorDoc = path.call(print, "operatorNode");
|
|
1661
2190
|
const rightContent = path.call(print, "rightNode");
|
|
1662
2191
|
let right = options.experimentalOperatorPosition === "start" ? [
|
|
1663
|
-
line$
|
|
2192
|
+
line$3,
|
|
1664
2193
|
operatorDoc,
|
|
1665
2194
|
" ",
|
|
1666
2195
|
rightContent
|
|
1667
2196
|
] : [
|
|
1668
2197
|
" ",
|
|
1669
2198
|
operatorDoc,
|
|
1670
|
-
line$
|
|
2199
|
+
line$3,
|
|
1671
2200
|
rightContent
|
|
1672
2201
|
];
|
|
1673
2202
|
const { parent } = path;
|
|
@@ -1677,6 +2206,18 @@ function printBinaryExpressions(path, print, options, isInsideParentheses) {
|
|
|
1677
2206
|
return parts;
|
|
1678
2207
|
}
|
|
1679
2208
|
const logicalOperators = /* @__PURE__ */ new Set(["||", "&&"]);
|
|
2209
|
+
const isType = createTypeCheckFunction([
|
|
2210
|
+
"void_type",
|
|
2211
|
+
"integral_type",
|
|
2212
|
+
"floating_point_type",
|
|
2213
|
+
"floating_point_type",
|
|
2214
|
+
"boolean_type",
|
|
2215
|
+
"type_identifier",
|
|
2216
|
+
"scoped_type_identifier",
|
|
2217
|
+
"generic_type",
|
|
2218
|
+
"array_type",
|
|
2219
|
+
"annotated_type"
|
|
2220
|
+
]);
|
|
1680
2221
|
function isSimpleCallArgument(node, depth = 2) {
|
|
1681
2222
|
if (depth <= 0) return false;
|
|
1682
2223
|
const isChildSimple = (child) => isSimpleCallArgument(child, depth - 1);
|
|
@@ -1691,7 +2232,10 @@ function isSimpleCallArgument(node, depth = 2) {
|
|
|
1691
2232
|
if (node.type === "array_access") return isSimpleCallArgument(node.arrayNode, depth) && isSimpleCallArgument(node.indexNode, depth);
|
|
1692
2233
|
if (node.type === "field_access") return isSimpleCallArgument(node.objectNode, depth) && isSimpleCallArgument(node.fieldNode, depth);
|
|
1693
2234
|
if (node.type === "unary_expression") return isSimpleCallArgument(node.operandNode, depth);
|
|
1694
|
-
if (node.type === "method_reference" || node.type === "update_expression")
|
|
2235
|
+
if (node.type === "method_reference" || node.type === "update_expression") {
|
|
2236
|
+
const [qualifierNode] = node.namedChildren;
|
|
2237
|
+
return isType(qualifierNode) || isSimpleCallArgument(qualifierNode, depth);
|
|
2238
|
+
}
|
|
1695
2239
|
return false;
|
|
1696
2240
|
}
|
|
1697
2241
|
function isLiteral(node) {
|
|
@@ -1708,13 +2252,11 @@ function isLiteral(node) {
|
|
|
1708
2252
|
"character_literal"
|
|
1709
2253
|
].includes(node.type) || isStringLiteral(node);
|
|
1710
2254
|
}
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
].includes(node.type);
|
|
1717
|
-
}
|
|
2255
|
+
const isSingleWordType = createTypeCheckFunction([
|
|
2256
|
+
"identifier",
|
|
2257
|
+
"this",
|
|
2258
|
+
"super"
|
|
2259
|
+
]);
|
|
1718
2260
|
function couldExpandArg(arg, lambdaChainRecursion = false) {
|
|
1719
2261
|
if (arg.type === "array_creation_expression" && arg.valueNode && (arg.valueNode.namedChildren.length > 0 || arg.valueNode.comments)) return true;
|
|
1720
2262
|
if (arg.type === "lambda_expression") {
|
|
@@ -1728,10 +2270,10 @@ function couldExpandArg(arg, lambdaChainRecursion = false) {
|
|
|
1728
2270
|
}
|
|
1729
2271
|
return false;
|
|
1730
2272
|
}
|
|
1731
|
-
function shouldExpandLastArg(args) {
|
|
2273
|
+
function shouldExpandLastArg(args, options) {
|
|
1732
2274
|
const lastArg = args.at(-1);
|
|
1733
2275
|
const penultimateArg = args.at(-2);
|
|
1734
|
-
return !lastArg.comments?.some(({ leading }) => leading
|
|
2276
|
+
return !lastArg.comments?.some(({ leading, trailing }) => leading || trailing) && couldExpandArg(lastArg) && (!penultimateArg || penultimateArg.type !== lastArg.type) && (args.length !== 2 || penultimateArg.type !== "lambda_expression" || lastArg.type !== "array_creation_expression") && !(args.length > 1 && lastArg.type === "array_creation_expression" && lastArg.valueNode && isConciselyPrintedArray(lastArg.valueNode, options));
|
|
1735
2277
|
}
|
|
1736
2278
|
function shouldExpandFirstArg(args) {
|
|
1737
2279
|
if (args.length !== 2) return false;
|
|
@@ -1797,9 +2339,8 @@ var ArgExpansionBailout = class extends Error {
|
|
|
1797
2339
|
this.name = "ArgExpansionBailout";
|
|
1798
2340
|
}
|
|
1799
2341
|
};
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
const { group: group$3, hardline: hardline$3, indent: indent$3, join: join$3, line: line$3 } = builders;
|
|
2342
|
+
// src/printers/interfaces.ts
|
|
2343
|
+
const { group: group$3, hardline: hardline$2, indent: indent$3, join: join$3, line: line$2 } = builders;
|
|
1803
2344
|
var interfaces_default = {
|
|
1804
2345
|
interface_declaration(path, print, options) {
|
|
1805
2346
|
const parts = ["interface ", path.call(print, "nameNode")];
|
|
@@ -1809,14 +2350,14 @@ var interfaces_default = {
|
|
|
1809
2350
|
const hasMultipleClauses = hasExtendsInterfaces && hasPermits;
|
|
1810
2351
|
if (hasChild(path, "type_parametersNode")) {
|
|
1811
2352
|
const typeParameters = path.call(print, "type_parametersNode");
|
|
1812
|
-
parts.push(hasMultipleClauses ? group$3(indent$3(typeParameters)) : typeParameters);
|
|
2353
|
+
parts.push(hasMultipleClauses ? group$3(indent$3(typeParameters)) : options?.braceStyle === "next-line" ? group$3(typeParameters) : typeParameters);
|
|
1813
2354
|
}
|
|
1814
2355
|
if (hasExtendsInterfaces || hasPermits) {
|
|
1815
2356
|
const clauses = [];
|
|
1816
|
-
if (hasExtendsInterfaces) clauses.push(hardline$
|
|
1817
|
-
if (hasPermits) clauses.push(line$
|
|
2357
|
+
if (hasExtendsInterfaces) clauses.push(hardline$2, path.call(print, "namedChildren", extendsInterfacesIndex));
|
|
2358
|
+
if (hasPermits) clauses.push(line$2, path.call(print, "permitsNode"));
|
|
1818
2359
|
const hasBody = path.node.bodyNode.namedChildren.length > 0;
|
|
1819
|
-
const clauseGroup = [indent$3(clauses), options?.braceStyle === "next-line" ? "" : hasBody ? line$
|
|
2360
|
+
const clauseGroup = [indent$3(clauses), options?.braceStyle === "next-line" ? "" : hasBody ? line$2 : " "];
|
|
1820
2361
|
parts.push(hasMultipleClauses ? clauseGroup : group$3(clauseGroup));
|
|
1821
2362
|
} else parts.push(" ");
|
|
1822
2363
|
return [
|
|
@@ -1827,7 +2368,7 @@ var interfaces_default = {
|
|
|
1827
2368
|
},
|
|
1828
2369
|
extends_interfaces(path, print) {
|
|
1829
2370
|
const typeListIndex = path.node.namedChildren.findIndex(({ type }) => type === "type_list");
|
|
1830
|
-
return group$3(["extends", indent$3([line$
|
|
2371
|
+
return group$3(["extends", indent$3([line$2, path.call(print, "namedChildren", typeListIndex)])]);
|
|
1831
2372
|
},
|
|
1832
2373
|
interface_body(path, print, options) {
|
|
1833
2374
|
return printBlock(path, printBodyDeclarations(path, print), options);
|
|
@@ -1859,13 +2400,13 @@ var interfaces_default = {
|
|
|
1859
2400
|
marker_annotation(path, print) {
|
|
1860
2401
|
return ["@", path.call(print, "nameNode")];
|
|
1861
2402
|
},
|
|
1862
|
-
annotation_argument_list(path, print) {
|
|
2403
|
+
annotation_argument_list(path, print, options) {
|
|
1863
2404
|
const args = path.map(print, "namedChildren");
|
|
1864
2405
|
return args.length === 1 && path.node.namedChildren[0].type === "element_value_array_initializer" ? [
|
|
1865
2406
|
"(",
|
|
1866
2407
|
args[0],
|
|
1867
2408
|
")"
|
|
1868
|
-
] : group$3(indentInParentheses(join$3([",", line$
|
|
2409
|
+
] : group$3(indentInParentheses(join$3([",", line$2], args), options));
|
|
1869
2410
|
},
|
|
1870
2411
|
element_value_pair(path, print) {
|
|
1871
2412
|
return group$3([
|
|
@@ -1876,13 +2417,12 @@ var interfaces_default = {
|
|
|
1876
2417
|
},
|
|
1877
2418
|
element_value_array_initializer: printArrayInitializer
|
|
1878
2419
|
};
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
const { group: group$2, hardline: hardline$2, indent: indent$2, join: join$2, softline } = builders;
|
|
2420
|
+
// src/printers/lexical-structure.ts
|
|
2421
|
+
const { group: group$2, hardline: hardline$1, indent: indent$2, join: join$2, softline } = builders;
|
|
1882
2422
|
var lexical_structure_default = {
|
|
1883
2423
|
string_literal(path, print) {
|
|
1884
2424
|
if (path.node.namedChildren.some(({ type }) => type === "string_interpolation") || path.node.children[0].value === "\"") return path.map(print, "children");
|
|
1885
|
-
return printTextBlock(join$2(hardline$
|
|
2425
|
+
return printTextBlock(join$2(hardline$1, textBlockContents(path.node).split("\n")));
|
|
1886
2426
|
},
|
|
1887
2427
|
string_fragment: printValue,
|
|
1888
2428
|
multiline_string_fragment: printValue,
|
|
@@ -1916,8 +2456,7 @@ var lexical_structure_default = {
|
|
|
1916
2456
|
underscore_pattern: printValue,
|
|
1917
2457
|
asterisk: printValue
|
|
1918
2458
|
};
|
|
1919
|
-
|
|
1920
|
-
//#region src/printers/names.ts
|
|
2459
|
+
// src/printers/names.ts
|
|
1921
2460
|
var names_default = {
|
|
1922
2461
|
identifier: printValue,
|
|
1923
2462
|
type_identifier: printValue,
|
|
@@ -1932,12 +2471,11 @@ var names_default = {
|
|
|
1932
2471
|
return path.map((child) => child.node.type === "annotation" || child.node.type === "marker_annotation" ? [print(child), " "] : print(child), "children");
|
|
1933
2472
|
}
|
|
1934
2473
|
};
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
const { group: group$1, hardline: hardline$1, indent: indent$1, join: join$1, line: line$2 } = builders;
|
|
2474
|
+
// src/printers/packages-and-modules.ts
|
|
2475
|
+
const { group: group$1, hardline, indent: indent$1, join: join$1, line: line$1 } = builders;
|
|
1938
2476
|
var packages_and_modules_default = {
|
|
1939
2477
|
program(path, print, options) {
|
|
1940
|
-
if (!path.node.namedChildren.length) return [printDanglingComments(path), hardline
|
|
2478
|
+
if (!path.node.namedChildren.length) return [printDanglingComments(path), hardline];
|
|
1941
2479
|
const parts = [];
|
|
1942
2480
|
if (path.node.namedChildren[0].type !== "import_declaration") parts.push(path.call(print, "namedChildren", 0));
|
|
1943
2481
|
const moduleImports = [];
|
|
@@ -1956,8 +2494,8 @@ var packages_and_modules_default = {
|
|
|
1956
2494
|
});
|
|
1957
2495
|
} else if (!child.isFirst) otherDeclarations.push(doc);
|
|
1958
2496
|
}, "namedChildren");
|
|
1959
|
-
parts.push(...[moduleImports.sort(compareFqn), ...groupImports(imports, options.importOrder)].filter((group) => group.length).map((group) => join$1(hardline
|
|
1960
|
-
return [...join$1([hardline
|
|
2497
|
+
parts.push(...[moduleImports.sort(compareFqn), ...groupImports(imports, options.importOrder)].filter((group) => group.length).map((group) => join$1(hardline, group.map(({ doc }) => doc))), ...otherDeclarations);
|
|
2498
|
+
return [...join$1([hardline, hardline], parts), hardline];
|
|
1961
2499
|
},
|
|
1962
2500
|
package_declaration(path, print) {
|
|
1963
2501
|
const annotations = [];
|
|
@@ -1972,7 +2510,7 @@ var packages_and_modules_default = {
|
|
|
1972
2510
|
case "scoped_identifier": identifier.push(print(child));
|
|
1973
2511
|
}
|
|
1974
2512
|
}, "namedChildren");
|
|
1975
|
-
return join$1(hardline
|
|
2513
|
+
return join$1(hardline, [...annotations, [
|
|
1976
2514
|
"package ",
|
|
1977
2515
|
...identifier,
|
|
1978
2516
|
";"
|
|
@@ -1998,7 +2536,7 @@ var packages_and_modules_default = {
|
|
|
1998
2536
|
return join$1(" ", parts);
|
|
1999
2537
|
},
|
|
2000
2538
|
module_body(path, print, options) {
|
|
2001
|
-
return printBlock(path, path.map((child) => child.previous && child.node.start.row > child.previous.end.row + 1 ? [hardline
|
|
2539
|
+
return printBlock(path, path.map((child) => child.previous && child.node.start.row > child.previous.end.row + 1 ? [hardline, print(child)] : print(child), "namedChildren"), options);
|
|
2002
2540
|
},
|
|
2003
2541
|
requires_module_directive(path, print) {
|
|
2004
2542
|
const parts = ["requires"];
|
|
@@ -2022,585 +2560,185 @@ var packages_and_modules_default = {
|
|
|
2022
2560
|
return [
|
|
2023
2561
|
"provides ",
|
|
2024
2562
|
provided,
|
|
2025
|
-
group$1(indent$1([line$
|
|
2563
|
+
group$1(indent$1([line$1, group$1(indent$1([
|
|
2026
2564
|
"with",
|
|
2027
|
-
line$
|
|
2028
|
-
...join$1([",", line$
|
|
2565
|
+
line$1,
|
|
2566
|
+
...join$1([",", line$1], providers)
|
|
2029
2567
|
]))])),
|
|
2030
2568
|
";"
|
|
2031
|
-
];
|
|
2032
|
-
},
|
|
2033
|
-
requires_modifier: printValue
|
|
2034
|
-
};
|
|
2035
|
-
function extractNames(node) {
|
|
2036
|
-
return node.type === "identifier" ? [node.value] : [...extractNames(node.scopeNode), node.nameNode.value];
|
|
2037
|
-
}
|
|
2038
|
-
const STATIC_PREFIX = "static ";
|
|
2039
|
-
const CATCH_ALL_PREFIX = "";
|
|
2040
|
-
function groupImports(imports, importOrder) {
|
|
2041
|
-
if (!importOrder) return [imports.filter(({ isStatic }) => isStatic), imports.filter(({ isStatic }) => !isStatic)].filter((group) => group.length).map((group) => group.sort(compareFqn));
|
|
2042
|
-
const groups = parseImportOrder(importOrder);
|
|
2043
|
-
const prefixes = groups.flat();
|
|
2044
|
-
const importsByPrefix = /* @__PURE__ */ new Map();
|
|
2045
|
-
for (const entry of imports) {
|
|
2046
|
-
const key = importKey(entry);
|
|
2047
|
-
const prefix = prefixes.filter((candidate) => key.startsWith(candidate)).reduce((best, candidate) => candidate.length > best.length ? candidate : best);
|
|
2048
|
-
importsByPrefix.set(prefix, [...importsByPrefix.get(prefix) ?? [], {
|
|
2049
|
-
key,
|
|
2050
|
-
entry
|
|
2051
|
-
}]);
|
|
2052
|
-
}
|
|
2053
|
-
return groups.map((group) => group.flatMap((prefix) => (importsByPrefix.get(prefix) ?? []).sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0).map(({ entry }) => entry))).filter((group) => group.length);
|
|
2054
|
-
}
|
|
2055
|
-
/**
|
|
2056
|
-
* Parses an import order in Spotless's format: groups separated by `,` are
|
|
2057
|
-
* printed with blank lines between them, prefixes joined by `|` share a group,
|
|
2058
|
-
* `#` marks a static prefix, and an empty prefix catches everything else.
|
|
2059
|
-
* Each import belongs to its longest matching prefix.
|
|
2060
|
-
*/
|
|
2061
|
-
function parseImportOrder(importOrder) {
|
|
2062
|
-
const knownPrefixes = /* @__PURE__ */ new Set();
|
|
2063
|
-
const groups = importOrder.split(",").map((group) => group.split("|").map((prefix) => prefix.startsWith("#") ? STATIC_PREFIX + prefix.slice(1) : prefix).filter((prefix) => {
|
|
2064
|
-
if (knownPrefixes.has(prefix)) return false;
|
|
2065
|
-
knownPrefixes.add(prefix);
|
|
2066
|
-
return true;
|
|
2067
|
-
}));
|
|
2068
|
-
if (!knownPrefixes.has(STATIC_PREFIX)) {
|
|
2069
|
-
const lastStaticGroupIndex = groups.findLastIndex((group) => group.some((prefix) => prefix.startsWith(STATIC_PREFIX)));
|
|
2070
|
-
groups.splice(Math.max(lastStaticGroupIndex, 0), 0, [STATIC_PREFIX]);
|
|
2071
|
-
}
|
|
2072
|
-
if (!knownPrefixes.has(CATCH_ALL_PREFIX)) groups.push([CATCH_ALL_PREFIX]);
|
|
2073
|
-
return groups;
|
|
2074
|
-
}
|
|
2075
|
-
function importKey({ names, isStatic }) {
|
|
2076
|
-
return (isStatic ? STATIC_PREFIX : "") + names.join(".");
|
|
2077
|
-
}
|
|
2078
|
-
function compareFqn({ names: a }, { names: b }) {
|
|
2079
|
-
const minParts = Math.min(a.length, b.length);
|
|
2080
|
-
for (let i = 0; i < minParts; i++) {
|
|
2081
|
-
const imageA = a[i];
|
|
2082
|
-
const imageB = b[i];
|
|
2083
|
-
if (imageA < imageB) return -1;
|
|
2084
|
-
else if (imageA > imageB) return 1;
|
|
2085
|
-
}
|
|
2086
|
-
return a.length - b.length;
|
|
2087
|
-
}
|
|
2088
|
-
function printToModuleNamesDirective(path, print) {
|
|
2089
|
-
const directive = [
|
|
2090
|
-
path.node.type === "exports_module_directive" ? "exports" : "opens",
|
|
2091
|
-
" ",
|
|
2092
|
-
path.call(print, "packageNode")
|
|
2093
|
-
];
|
|
2094
|
-
if (path.node.modulesNodes.length) {
|
|
2095
|
-
const moduleNames = join$1([",", line$2], path.map(print, "modulesNodes"));
|
|
2096
|
-
directive.push(group$1(indent$1([line$2, group$1(indent$1([
|
|
2097
|
-
"to",
|
|
2098
|
-
line$2,
|
|
2099
|
-
...moduleNames
|
|
2100
|
-
]))])));
|
|
2101
|
-
}
|
|
2102
|
-
directive.push(";");
|
|
2103
|
-
return directive;
|
|
2104
|
-
}
|
|
2105
|
-
//#endregion
|
|
2106
|
-
//#region src/printers/types-values-and-variables.ts
|
|
2107
|
-
const { group, indent, join, line: line$1 } = builders;
|
|
2108
|
-
var types_values_and_variables_default = {
|
|
2109
|
-
boolean_type: printValue,
|
|
2110
|
-
integral_type: printValue,
|
|
2111
|
-
floating_point_type: printValue,
|
|
2112
|
-
void_type: printValue,
|
|
2113
|
-
array_type(path, print) {
|
|
2114
|
-
return [path.call(print, "elementNode"), path.call(print, "dimensionsNode")];
|
|
2115
|
-
},
|
|
2116
|
-
annotated_type(path, print) {
|
|
2117
|
-
return join(" ", path.map(print, "children"));
|
|
2118
|
-
},
|
|
2119
|
-
dimensions(path, print) {
|
|
2120
|
-
return path.map((child) => {
|
|
2121
|
-
if (child.node.isNamed) return [
|
|
2122
|
-
...child.isFirst ? [" "] : [],
|
|
2123
|
-
print(child),
|
|
2124
|
-
" "
|
|
2125
|
-
];
|
|
2126
|
-
return child.node.value;
|
|
2127
|
-
}, "children");
|
|
2128
|
-
},
|
|
2129
|
-
type_parameter(path, print) {
|
|
2130
|
-
return join(" ", path.map(print, "children"));
|
|
2131
|
-
},
|
|
2132
|
-
type_bound(path, print) {
|
|
2133
|
-
const [firstType, ...restTypes] = path.map(print, "namedChildren");
|
|
2134
|
-
const bound = ["extends ", firstType];
|
|
2135
|
-
if (restTypes.length) bound.push(group(indent([
|
|
2136
|
-
line$1,
|
|
2137
|
-
"& ",
|
|
2138
|
-
...join([line$1, "& "], restTypes)
|
|
2139
|
-
])));
|
|
2140
|
-
return bound;
|
|
2141
|
-
},
|
|
2142
|
-
type_arguments: printTypeParameters,
|
|
2143
|
-
wildcard(path, print) {
|
|
2144
|
-
return join(" ", path.map(print, "children"));
|
|
2145
|
-
}
|
|
2146
|
-
};
|
|
2147
|
-
//#endregion
|
|
2148
|
-
//#region src/printers/index.ts
|
|
2149
|
-
const printersByNodeType = {
|
|
2150
|
-
ERROR(path) {
|
|
2151
|
-
throw new Error(`Failed to parse: "${printValue(path)}"`);
|
|
2152
|
-
},
|
|
2153
|
-
...arrays_default,
|
|
2154
|
-
...blocks_and_statements_default,
|
|
2155
|
-
...classes_default,
|
|
2156
|
-
...expressions_default,
|
|
2157
|
-
...interfaces_default,
|
|
2158
|
-
...lexical_structure_default,
|
|
2159
|
-
...names_default,
|
|
2160
|
-
...packages_and_modules_default,
|
|
2161
|
-
...types_values_and_variables_default
|
|
2162
|
-
};
|
|
2163
|
-
function printerForNodeType(type) {
|
|
2164
|
-
return printersByNodeType[type];
|
|
2165
|
-
}
|
|
2166
|
-
//#endregion
|
|
2167
|
-
//#region src/printer.ts
|
|
2168
|
-
var printer_default = {
|
|
2169
|
-
print(path, options, print, args) {
|
|
2170
|
-
if (!hasNamedNode(path)) return printValue(path);
|
|
2171
|
-
const doc = printerForNodeType(path.node.type)(path, print, options, args);
|
|
2172
|
-
return needsParentheses(path) ? [
|
|
2173
|
-
"(",
|
|
2174
|
-
doc,
|
|
2175
|
-
")"
|
|
2176
|
-
] : doc;
|
|
2177
|
-
},
|
|
2178
|
-
embed(path, options) {
|
|
2179
|
-
return hasType(path, "string_literal") ? embedTextBlock(path, options) : null;
|
|
2180
|
-
},
|
|
2181
|
-
hasPrettierIgnore(path) {
|
|
2182
|
-
return path.node.comments?.some(isPrettierIgnore) === true || canAttachComment(path.node, path.parent ? [path.parent] : []) && isFullyBetweenPrettierIgnore(path);
|
|
2183
|
-
},
|
|
2184
|
-
canAttachComment,
|
|
2185
|
-
isBlockComment(node) {
|
|
2186
|
-
return node.type === "block_comment";
|
|
2187
|
-
},
|
|
2188
|
-
willPrintOwnComments,
|
|
2189
|
-
printComment(commentPath) {
|
|
2190
|
-
return printComment(commentPath.node);
|
|
2191
|
-
},
|
|
2192
|
-
getCommentChildNodes(node) {
|
|
2193
|
-
return node.isNamed ? node.children : [];
|
|
2194
|
-
},
|
|
2195
|
-
handleComments: {
|
|
2196
|
-
ownLine: handleLineComment,
|
|
2197
|
-
endOfLine: handleLineComment,
|
|
2198
|
-
remaining: handleRemainingComment
|
|
2569
|
+
];
|
|
2199
2570
|
},
|
|
2200
|
-
|
|
2201
|
-
return ["namedChildren"];
|
|
2202
|
-
}
|
|
2571
|
+
requires_modifier: printValue
|
|
2203
2572
|
};
|
|
2204
|
-
function
|
|
2205
|
-
return
|
|
2206
|
-
}
|
|
2207
|
-
//#endregion
|
|
2208
|
-
//#region src/comments.ts
|
|
2209
|
-
const { hasNewline, isPreviousLineEmpty, skipNewline, skipSpaces } = util;
|
|
2210
|
-
const { breakParent, hardline, line, lineSuffix } = builders;
|
|
2211
|
-
const prettierIgnoreRangesByTree = /* @__PURE__ */ new WeakMap();
|
|
2212
|
-
function determinePrettierIgnoreRanges(tree) {
|
|
2213
|
-
const { comments } = tree;
|
|
2214
|
-
if (!comments) return;
|
|
2215
|
-
const ranges = comments.filter(({ value }) => /^\/(?:\/\s*(?:prettier-ignore-(?:start|end)|@formatter:(?:off|on))\s*|\*\s*(?:prettier-ignore-(?:start|end)|@formatter:(?:off|on))\s*\*\/)$/.test(value)).reduce((ranges, { value, start }) => {
|
|
2216
|
-
const previous = ranges.at(-1);
|
|
2217
|
-
if (value.includes("start") || value.includes("off")) {
|
|
2218
|
-
if (previous?.end !== Infinity) ranges.push({
|
|
2219
|
-
start: start.index,
|
|
2220
|
-
end: Infinity
|
|
2221
|
-
});
|
|
2222
|
-
} else if (previous?.end === Infinity) previous.end = start.index;
|
|
2223
|
-
return ranges;
|
|
2224
|
-
}, new Array());
|
|
2225
|
-
prettierIgnoreRangesByTree.set(tree, ranges);
|
|
2226
|
-
}
|
|
2227
|
-
function isFullyBetweenPrettierIgnore(path) {
|
|
2228
|
-
const { node, root } = path;
|
|
2229
|
-
const start = parser_default.locStart(node);
|
|
2230
|
-
const end = parser_default.locEnd(node);
|
|
2231
|
-
return prettierIgnoreRangesByTree.get(root)?.some((range) => range.start < start && end < range.end) === true;
|
|
2232
|
-
}
|
|
2233
|
-
function isPrettierIgnore(comment) {
|
|
2234
|
-
return /^(\/\/\s*prettier-ignore|\/\*\s*prettier-ignore\s*\*\/)$/.test(comment.value);
|
|
2235
|
-
}
|
|
2236
|
-
function willPrintOwnComments(path) {
|
|
2237
|
-
return isMember(path.node) && !printer_default.hasPrettierIgnore(path);
|
|
2238
|
-
}
|
|
2239
|
-
function canAttachComment(node, ancestors) {
|
|
2240
|
-
if (!node.isNamed) return isBinaryOperator(node);
|
|
2241
|
-
switch (node.type) {
|
|
2242
|
-
case "enum_body_declarations":
|
|
2243
|
-
case "escape_sequence":
|
|
2244
|
-
case "modifier":
|
|
2245
|
-
case "multiline_string_fragment":
|
|
2246
|
-
case "program":
|
|
2247
|
-
case "string_fragment":
|
|
2248
|
-
case "visibility": return false;
|
|
2249
|
-
case "parenthesized_expression": {
|
|
2250
|
-
const [parent] = ancestors;
|
|
2251
|
-
return !(parent.isNamed && [
|
|
2252
|
-
"do_statement",
|
|
2253
|
-
"if_statement",
|
|
2254
|
-
"switch_expression",
|
|
2255
|
-
"synchronized_statement",
|
|
2256
|
-
"try_statement",
|
|
2257
|
-
"try_with_resources_statement",
|
|
2258
|
-
"while_statement"
|
|
2259
|
-
].includes(parent.type));
|
|
2260
|
-
}
|
|
2261
|
-
default: return true;
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
function handleLineComment(commentNode, _, options) {
|
|
2265
|
-
return [
|
|
2266
|
-
handleBinaryExpressionComments,
|
|
2267
|
-
handleFormalParametersComments,
|
|
2268
|
-
handleFqnOrRefTypeComments,
|
|
2269
|
-
handleIfStatementComments,
|
|
2270
|
-
handleJumpStatementComments,
|
|
2271
|
-
handleLabeledStatementComments,
|
|
2272
|
-
handleLambdaExpressionComments,
|
|
2273
|
-
handleMemberChainComments,
|
|
2274
|
-
handleModifiersComments,
|
|
2275
|
-
handleNameComments,
|
|
2276
|
-
handleTernaryExpressionComments,
|
|
2277
|
-
handleTryStatementComments
|
|
2278
|
-
].some((fn) => fn(commentNode, options));
|
|
2279
|
-
}
|
|
2280
|
-
function handleRemainingComment(commentNode) {
|
|
2281
|
-
return [
|
|
2282
|
-
handleFqnOrRefTypeComments,
|
|
2283
|
-
handleNameComments,
|
|
2284
|
-
handleJumpStatementComments
|
|
2285
|
-
].some((fn) => fn(commentNode));
|
|
2286
|
-
}
|
|
2287
|
-
function handleBinaryExpressionComments(commentNode, options) {
|
|
2288
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
2289
|
-
if (enclosingNode?.type === "binary_expression") {
|
|
2290
|
-
if (isBinaryOperator(followingNode)) {
|
|
2291
|
-
if (options.experimentalOperatorPosition === "start") util.addLeadingComment(followingNode, commentNode);
|
|
2292
|
-
else util.addTrailingComment(followingNode, commentNode);
|
|
2293
|
-
return true;
|
|
2294
|
-
} else if (options.experimentalOperatorPosition === "start" && isBinaryOperator(precedingNode)) {
|
|
2295
|
-
util.addLeadingComment(precedingNode, commentNode);
|
|
2296
|
-
return true;
|
|
2297
|
-
}
|
|
2298
|
-
}
|
|
2299
|
-
return false;
|
|
2300
|
-
}
|
|
2301
|
-
function handleFormalParametersComments(commentNode) {
|
|
2302
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
2303
|
-
if (enclosingNode?.type === "formal_parameters" && !precedingNode && !followingNode) {
|
|
2304
|
-
util.addDanglingComment(enclosingNode, commentNode, void 0);
|
|
2305
|
-
return true;
|
|
2306
|
-
}
|
|
2307
|
-
return false;
|
|
2308
|
-
}
|
|
2309
|
-
function handleFqnOrRefTypeComments(commentNode) {
|
|
2310
|
-
const { enclosingNode, followingNode } = commentNode;
|
|
2311
|
-
if (enclosingNode?.type === "scoped_type_identifier" && followingNode) {
|
|
2312
|
-
util.addLeadingComment(followingNode, commentNode);
|
|
2313
|
-
return true;
|
|
2314
|
-
}
|
|
2315
|
-
return false;
|
|
2316
|
-
}
|
|
2317
|
-
function handleIfStatementComments(commentNode) {
|
|
2318
|
-
const { enclosingNode, precedingNode } = commentNode;
|
|
2319
|
-
if (enclosingNode?.type === "if_statement" && precedingNode?.fieldName === "consequence") {
|
|
2320
|
-
util.addDanglingComment(enclosingNode, commentNode, void 0);
|
|
2321
|
-
return true;
|
|
2322
|
-
}
|
|
2323
|
-
return false;
|
|
2324
|
-
}
|
|
2325
|
-
function handleJumpStatementComments(commentNode) {
|
|
2326
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
2327
|
-
if (enclosingNode && !precedingNode && !followingNode && (enclosingNode.type === "break_statement" || enclosingNode.type === "continue_statement" || enclosingNode.type === "return_statement")) {
|
|
2328
|
-
util.addTrailingComment(enclosingNode, commentNode);
|
|
2329
|
-
return true;
|
|
2330
|
-
}
|
|
2331
|
-
return false;
|
|
2332
|
-
}
|
|
2333
|
-
function handleLabeledStatementComments(commentNode) {
|
|
2334
|
-
const { enclosingNode, precedingNode } = commentNode;
|
|
2335
|
-
if (enclosingNode?.type === "labeled_statement" && precedingNode?.type === "identifier") {
|
|
2336
|
-
util.addLeadingComment(precedingNode, commentNode);
|
|
2337
|
-
return true;
|
|
2338
|
-
}
|
|
2339
|
-
return false;
|
|
2340
|
-
}
|
|
2341
|
-
function handleLambdaExpressionComments(commentNode) {
|
|
2342
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
2343
|
-
if (enclosingNode?.type === "lambda_expression" && precedingNode && followingNode && enclosingNode.children.find(({ type }) => type === "->").end.index < commentNode.start.index) {
|
|
2344
|
-
if (followingNode.type === "block") {
|
|
2345
|
-
if (followingNode.namedChildren.length) util.addLeadingComment(followingNode.namedChildren[0], commentNode);
|
|
2346
|
-
else util.addDanglingComment(followingNode, commentNode, void 0);
|
|
2347
|
-
} else util.addLeadingComment(followingNode, commentNode);
|
|
2348
|
-
return true;
|
|
2349
|
-
}
|
|
2350
|
-
}
|
|
2351
|
-
function handleMemberChainComments(commentNode) {
|
|
2352
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
2353
|
-
if (precedingNode && (enclosingNode?.type === "field_access" || enclosingNode?.type === "method_invocation" && precedingNode.end.row < commentNode.start.row) && precedingNode === enclosingNode.objectNode) {
|
|
2354
|
-
util.addLeadingComment(enclosingNode, commentNode);
|
|
2355
|
-
return true;
|
|
2356
|
-
} else if (isMember(followingNode) && (!precedingNode || precedingNode !== getMemberObject(followingNode) && precedingNode.end.row < commentNode.start.row) && !isPrettierIgnore(commentNode)) {
|
|
2357
|
-
util.addDanglingComment(followingNode, commentNode, void 0);
|
|
2358
|
-
return true;
|
|
2359
|
-
}
|
|
2360
|
-
return false;
|
|
2361
|
-
}
|
|
2362
|
-
function handleModifiersComments(commentNode) {
|
|
2363
|
-
const { precedingNode } = commentNode;
|
|
2364
|
-
if (precedingNode?.type === "annotation" || precedingNode?.type === "marker_annotation" || precedingNode?.type === "modifiers") {
|
|
2365
|
-
util.addTrailingComment(precedingNode, commentNode);
|
|
2366
|
-
return true;
|
|
2367
|
-
}
|
|
2368
|
-
return false;
|
|
2369
|
-
}
|
|
2370
|
-
function handleNameComments(commentNode) {
|
|
2371
|
-
const { enclosingNode, precedingNode } = commentNode;
|
|
2372
|
-
if (enclosingNode && precedingNode?.type === "identifier" && (enclosingNode.type === "scoped_identifier" || enclosingNode.type === "module_declaration" || enclosingNode.type === "package_declaration" || enclosingNode.type === "scoped_type_identifier")) {
|
|
2373
|
-
util.addTrailingComment(precedingNode, commentNode);
|
|
2374
|
-
return true;
|
|
2375
|
-
}
|
|
2376
|
-
return false;
|
|
2377
|
-
}
|
|
2378
|
-
function handleTernaryExpressionComments(commentNode) {
|
|
2379
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
2380
|
-
if (enclosingNode?.type === "ternary_expression" && precedingNode?.isNamed && followingNode?.isNamed && precedingNode.end.row < commentNode.start.row && commentNode.end.row < followingNode.start.row) {
|
|
2381
|
-
util.addLeadingComment(followingNode, commentNode);
|
|
2382
|
-
return true;
|
|
2383
|
-
}
|
|
2384
|
-
return false;
|
|
2573
|
+
function extractNames(node) {
|
|
2574
|
+
return node.type === "identifier" ? [node.value] : [...extractNames(node.scopeNode), node.nameNode.value];
|
|
2385
2575
|
}
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2576
|
+
const STATIC_PREFIX = "static ";
|
|
2577
|
+
const CATCH_ALL_PREFIX = "";
|
|
2578
|
+
function groupImports(imports, importOrder) {
|
|
2579
|
+
if (!importOrder) return [imports.filter(({ isStatic }) => isStatic), imports.filter(({ isStatic }) => !isStatic)].filter((group) => group.length).map((group) => group.sort(compareFqn));
|
|
2580
|
+
const groups = parseImportOrder(importOrder);
|
|
2581
|
+
const prefixes = groups.flat();
|
|
2582
|
+
const importsByPrefix = /* @__PURE__ */ new Map();
|
|
2583
|
+
for (const entry of imports) {
|
|
2584
|
+
const key = importKey(entry);
|
|
2585
|
+
const prefix = prefixes.filter((candidate) => key.startsWith(candidate)).reduce((best, candidate) => candidate.length > best.length ? candidate : best);
|
|
2586
|
+
importsByPrefix.set(prefix, [...importsByPrefix.get(prefix) ?? [], {
|
|
2587
|
+
key,
|
|
2588
|
+
entry
|
|
2589
|
+
}]);
|
|
2395
2590
|
}
|
|
2396
|
-
return
|
|
2397
|
-
}
|
|
2398
|
-
function getMemberObject(node) {
|
|
2399
|
-
return node.type === "array_access" ? node.arrayNode : node.objectNode;
|
|
2400
|
-
}
|
|
2401
|
-
const binaryOperators = /* @__PURE__ */ new Set([
|
|
2402
|
-
"<<",
|
|
2403
|
-
">>",
|
|
2404
|
-
">>>",
|
|
2405
|
-
"instanceof",
|
|
2406
|
-
"<=",
|
|
2407
|
-
">=",
|
|
2408
|
-
"==",
|
|
2409
|
-
"-",
|
|
2410
|
-
"+",
|
|
2411
|
-
"&&",
|
|
2412
|
-
"&",
|
|
2413
|
-
"^",
|
|
2414
|
-
"!=",
|
|
2415
|
-
"||",
|
|
2416
|
-
"|",
|
|
2417
|
-
"*",
|
|
2418
|
-
"/",
|
|
2419
|
-
"%"
|
|
2420
|
-
]);
|
|
2421
|
-
function isBinaryOperator(node) {
|
|
2422
|
-
return node !== void 0 && binaryOperators.has(node.type);
|
|
2423
|
-
}
|
|
2424
|
-
function printLeadingComment(path) {
|
|
2425
|
-
const comment = path.node;
|
|
2426
|
-
const parts = [printComment(comment)];
|
|
2427
|
-
const originalText = path.root.value;
|
|
2428
|
-
if (comment.type === "block_comment") {
|
|
2429
|
-
let lineBreak = " ";
|
|
2430
|
-
if (hasNewline(originalText, parser_default.locEnd(comment))) {
|
|
2431
|
-
if (hasNewline(originalText, parser_default.locStart(comment), { backwards: true })) lineBreak = hardline;
|
|
2432
|
-
else lineBreak = line;
|
|
2433
|
-
}
|
|
2434
|
-
parts.push(lineBreak);
|
|
2435
|
-
} else parts.push(hardline);
|
|
2436
|
-
const index = skipNewline(originalText, skipSpaces(originalText, parser_default.locEnd(comment)));
|
|
2437
|
-
if (index !== false && hasNewline(originalText, index)) parts.push(hardline);
|
|
2438
|
-
return parts;
|
|
2591
|
+
return groups.map((group) => group.flatMap((prefix) => (importsByPrefix.get(prefix) ?? []).sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0).map(({ entry }) => entry))).filter((group) => group.length);
|
|
2439
2592
|
}
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2593
|
+
/**
|
|
2594
|
+
* Parses an import order in Spotless's format: groups separated by `,` are
|
|
2595
|
+
* printed with blank lines between them, prefixes joined by `|` share a group,
|
|
2596
|
+
* `#` marks a static prefix, and an empty prefix catches everything else.
|
|
2597
|
+
* Each import belongs to its longest matching prefix.
|
|
2598
|
+
*/
|
|
2599
|
+
function parseImportOrder(importOrder) {
|
|
2600
|
+
const knownPrefixes = /* @__PURE__ */ new Set();
|
|
2601
|
+
const groups = importOrder.split(",").map((group) => group.split("|").map((prefix) => prefix.startsWith("#") ? STATIC_PREFIX + prefix.slice(1) : prefix).filter((prefix) => {
|
|
2602
|
+
if (knownPrefixes.has(prefix)) return false;
|
|
2603
|
+
knownPrefixes.add(prefix);
|
|
2604
|
+
return true;
|
|
2605
|
+
}));
|
|
2606
|
+
if (!knownPrefixes.has(STATIC_PREFIX)) {
|
|
2607
|
+
const lastStaticGroupIndex = groups.findLastIndex((group) => group.some((prefix) => prefix.startsWith(STATIC_PREFIX)));
|
|
2608
|
+
groups.splice(Math.max(lastStaticGroupIndex, 0), 0, [STATIC_PREFIX]);
|
|
2456
2609
|
}
|
|
2457
|
-
if (!
|
|
2458
|
-
|
|
2459
|
-
isBlock,
|
|
2460
|
-
hasLineSuffix: true
|
|
2461
|
-
};
|
|
2462
|
-
return {
|
|
2463
|
-
doc: [" ", printed],
|
|
2464
|
-
isBlock,
|
|
2465
|
-
hasLineSuffix: false
|
|
2466
|
-
};
|
|
2610
|
+
if (!knownPrefixes.has(CATCH_ALL_PREFIX)) groups.push([CATCH_ALL_PREFIX]);
|
|
2611
|
+
return groups;
|
|
2467
2612
|
}
|
|
2468
|
-
function
|
|
2469
|
-
|
|
2470
|
-
const docs = [];
|
|
2471
|
-
path.each((path) => {
|
|
2472
|
-
const { node: comment } = path;
|
|
2473
|
-
if (!comment.leading) return;
|
|
2474
|
-
docs.push(printLeadingComment(path));
|
|
2475
|
-
}, "comments");
|
|
2476
|
-
return docs;
|
|
2613
|
+
function importKey({ names, isStatic }) {
|
|
2614
|
+
return (isStatic ? STATIC_PREFIX : "") + names.join(".");
|
|
2477
2615
|
}
|
|
2478
|
-
function
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
if (
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
}, "comments");
|
|
2488
|
-
return docs;
|
|
2616
|
+
function compareFqn({ names: a }, { names: b }) {
|
|
2617
|
+
const minParts = Math.min(a.length, b.length);
|
|
2618
|
+
for (let i = 0; i < minParts; i++) {
|
|
2619
|
+
const imageA = a[i];
|
|
2620
|
+
const imageB = b[i];
|
|
2621
|
+
if (imageA < imageB) return -1;
|
|
2622
|
+
else if (imageA > imageB) return 1;
|
|
2623
|
+
}
|
|
2624
|
+
return a.length - b.length;
|
|
2489
2625
|
}
|
|
2490
|
-
function
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2626
|
+
function printToModuleNamesDirective(path, print) {
|
|
2627
|
+
const directive = [
|
|
2628
|
+
path.node.type === "exports_module_directive" ? "exports" : "opens",
|
|
2629
|
+
" ",
|
|
2630
|
+
path.call(print, "packageNode")
|
|
2631
|
+
];
|
|
2632
|
+
if (path.node.modulesNodes.length) {
|
|
2633
|
+
const moduleNames = join$1([",", line$1], path.map(print, "modulesNodes"));
|
|
2634
|
+
directive.push(group$1(indent$1([line$1, group$1(indent$1([
|
|
2635
|
+
"to",
|
|
2636
|
+
line$1,
|
|
2637
|
+
...moduleNames
|
|
2638
|
+
]))])));
|
|
2639
|
+
}
|
|
2640
|
+
directive.push(";");
|
|
2641
|
+
return directive;
|
|
2495
2642
|
}
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2643
|
+
// src/printers/types-values-and-variables.ts
|
|
2644
|
+
const { group, indent, join, line } = builders;
|
|
2645
|
+
var types_values_and_variables_default = {
|
|
2646
|
+
boolean_type: printValue,
|
|
2647
|
+
integral_type: printValue,
|
|
2648
|
+
floating_point_type: printValue,
|
|
2649
|
+
void_type: printValue,
|
|
2650
|
+
array_type(path, print) {
|
|
2651
|
+
return [path.call(print, "elementNode"), path.call(print, "dimensionsNode")];
|
|
2652
|
+
},
|
|
2653
|
+
annotated_type(path, print) {
|
|
2654
|
+
return join(" ", path.map(print, "children"));
|
|
2655
|
+
},
|
|
2656
|
+
dimensions(path, print) {
|
|
2657
|
+
return path.map((child) => {
|
|
2658
|
+
if (child.node.isNamed) return [
|
|
2659
|
+
...child.isFirst ? [" "] : [],
|
|
2660
|
+
print(child),
|
|
2661
|
+
" "
|
|
2662
|
+
];
|
|
2663
|
+
return child.node.value;
|
|
2664
|
+
}, "children");
|
|
2665
|
+
},
|
|
2666
|
+
type_parameter(path, print) {
|
|
2667
|
+
return join(" ", path.map(print, "children"));
|
|
2668
|
+
},
|
|
2669
|
+
type_bound(path, print) {
|
|
2670
|
+
const [firstType, ...restTypes] = path.map(print, "namedChildren");
|
|
2671
|
+
const bound = ["extends ", firstType];
|
|
2672
|
+
if (restTypes.length) bound.push(group(indent([
|
|
2673
|
+
line,
|
|
2674
|
+
"& ",
|
|
2675
|
+
...join([line, "& "], restTypes)
|
|
2676
|
+
])));
|
|
2677
|
+
return bound;
|
|
2678
|
+
},
|
|
2679
|
+
type_arguments: printTypeParameters,
|
|
2680
|
+
wildcard(path, print) {
|
|
2681
|
+
return join(" ", path.map(print, "children"));
|
|
2682
|
+
}
|
|
2683
|
+
};
|
|
2684
|
+
// src/printers/index.ts
|
|
2685
|
+
const printersByNodeType = {
|
|
2686
|
+
ERROR(path) {
|
|
2687
|
+
throw new Error(`Failed to parse: "${printValue(path)}"`);
|
|
2688
|
+
},
|
|
2689
|
+
...arrays_default,
|
|
2690
|
+
...blocks_and_statements_default,
|
|
2691
|
+
...classes_default,
|
|
2692
|
+
...expressions_default,
|
|
2693
|
+
...interfaces_default,
|
|
2694
|
+
...lexical_structure_default,
|
|
2695
|
+
...names_default,
|
|
2696
|
+
...packages_and_modules_default,
|
|
2697
|
+
...types_values_and_variables_default
|
|
2698
|
+
};
|
|
2699
|
+
function printerForNodeType(type) {
|
|
2700
|
+
return printersByNodeType[type];
|
|
2504
2701
|
}
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
const
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
return ast;
|
|
2702
|
+
// src/printer.ts
|
|
2703
|
+
var printer_default = {
|
|
2704
|
+
print(path, options, print, args) {
|
|
2705
|
+
if (!hasNamedNode(path)) return printValue(path);
|
|
2706
|
+
const doc = printerForNodeType(path.node.type)(path, print, options, args);
|
|
2707
|
+
return needsParentheses(path) ? [
|
|
2708
|
+
"(",
|
|
2709
|
+
doc,
|
|
2710
|
+
")"
|
|
2711
|
+
] : doc;
|
|
2516
2712
|
},
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
return /^\/\*\*\n\s+\*\s@(format|prettier)\n\s+\*\//.test(text);
|
|
2713
|
+
embed(path, options) {
|
|
2714
|
+
return hasType(path, "string_literal") ? embedTextBlock(path, options) : null;
|
|
2520
2715
|
},
|
|
2521
|
-
|
|
2522
|
-
return node.
|
|
2716
|
+
hasPrettierIgnore(path) {
|
|
2717
|
+
return path.node.comments?.some(isPrettierIgnore) === true || canAttachComment(path.node, path.parent ? [path.parent] : []) && isFullyBetweenPrettierIgnore(path);
|
|
2523
2718
|
},
|
|
2524
|
-
|
|
2525
|
-
|
|
2719
|
+
canAttachComment,
|
|
2720
|
+
isBlockComment(node) {
|
|
2721
|
+
return node.type === "block_comment";
|
|
2722
|
+
},
|
|
2723
|
+
printComment(commentPath) {
|
|
2724
|
+
return printComment(commentPath.node);
|
|
2725
|
+
},
|
|
2726
|
+
getCommentChildNodes(node) {
|
|
2727
|
+
return node.isNamed ? node.children : [];
|
|
2728
|
+
},
|
|
2729
|
+
handleComments: {
|
|
2730
|
+
ownLine: handleLineComment,
|
|
2731
|
+
endOfLine: handleLineComment,
|
|
2732
|
+
remaining: handleRemainingComment
|
|
2733
|
+
},
|
|
2734
|
+
getVisitorKeys() {
|
|
2735
|
+
return ["namedChildren"];
|
|
2526
2736
|
}
|
|
2527
2737
|
};
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
const parser = new Parser();
|
|
2531
|
-
const Java = await Language.load(new URL("./tree-sitter-java_orchard.wasm", import.meta.url));
|
|
2532
|
-
parser.setLanguage(Java);
|
|
2533
|
-
return parser;
|
|
2534
|
-
})();
|
|
2535
|
-
const isParenthesizedParent = createTypeCheckFunction([
|
|
2536
|
-
"do_statement",
|
|
2537
|
-
"if_statement",
|
|
2538
|
-
"switch_expression",
|
|
2539
|
-
"synchronized_statement",
|
|
2540
|
-
"try_statement",
|
|
2541
|
-
"try_with_resources_statement",
|
|
2542
|
-
"while_statement"
|
|
2543
|
-
]);
|
|
2544
|
-
function processTree(node, fieldName = null, comments) {
|
|
2545
|
-
const { type, isNamed, text: value, startPosition, endPosition } = node;
|
|
2546
|
-
const javaNode = {
|
|
2547
|
-
type,
|
|
2548
|
-
isNamed,
|
|
2549
|
-
value,
|
|
2550
|
-
start: {
|
|
2551
|
-
index: node.startIndex,
|
|
2552
|
-
row: startPosition.row,
|
|
2553
|
-
column: startPosition.column
|
|
2554
|
-
},
|
|
2555
|
-
end: {
|
|
2556
|
-
index: node.endIndex,
|
|
2557
|
-
row: endPosition.row,
|
|
2558
|
-
column: endPosition.column
|
|
2559
|
-
},
|
|
2560
|
-
children: [],
|
|
2561
|
-
namedChildren: [],
|
|
2562
|
-
fieldName
|
|
2563
|
-
};
|
|
2564
|
-
if (!comments) comments = javaNode.comments = [];
|
|
2565
|
-
if (!javaNode.isNamed) return javaNode;
|
|
2566
|
-
const multiFields = multiFieldsByType[node.type];
|
|
2567
|
-
if (multiFields) Object.keys(multiFields).forEach((name) => javaNode[`${name}Nodes`] = []);
|
|
2568
|
-
node.children.forEach((child, index) => {
|
|
2569
|
-
const fieldName = node.fieldNameForChild(index);
|
|
2570
|
-
(child.type === "parenthesized_expression" && !isParenthesizedParent(javaNode) ? child.namedChildren : [child]).forEach((child) => {
|
|
2571
|
-
const { type, text: value, startPosition, endPosition } = child;
|
|
2572
|
-
if (type === "block_comment" || type === "line_comment") comments.push({
|
|
2573
|
-
type,
|
|
2574
|
-
value,
|
|
2575
|
-
start: {
|
|
2576
|
-
index: child.startIndex,
|
|
2577
|
-
row: startPosition.row,
|
|
2578
|
-
column: startPosition.column
|
|
2579
|
-
},
|
|
2580
|
-
end: {
|
|
2581
|
-
index: child.endIndex,
|
|
2582
|
-
row: endPosition.row,
|
|
2583
|
-
column: endPosition.column
|
|
2584
|
-
},
|
|
2585
|
-
leading: false,
|
|
2586
|
-
trailing: false,
|
|
2587
|
-
printed: false
|
|
2588
|
-
});
|
|
2589
|
-
else {
|
|
2590
|
-
const javaChild = processTree(child, fieldName, comments);
|
|
2591
|
-
javaNode.children.push(javaChild);
|
|
2592
|
-
if (javaChild.isNamed) javaNode.namedChildren.push(javaChild);
|
|
2593
|
-
if (fieldName) {
|
|
2594
|
-
if (multiFields?.[fieldName]) javaNode[`${fieldName}Nodes`].push(javaChild);
|
|
2595
|
-
else javaNode[`${fieldName}Node`] = javaChild;
|
|
2596
|
-
}
|
|
2597
|
-
}
|
|
2598
|
-
});
|
|
2599
|
-
});
|
|
2600
|
-
return javaNode;
|
|
2738
|
+
function hasNamedNode(path) {
|
|
2739
|
+
return path.node.isNamed;
|
|
2601
2740
|
}
|
|
2602
|
-
|
|
2603
|
-
//#region src/index.ts
|
|
2741
|
+
// src/index.ts
|
|
2604
2742
|
var src_default = {
|
|
2605
2743
|
languages: [{
|
|
2606
2744
|
name: "Java",
|
|
@@ -2619,5 +2757,4 @@ var src_default = {
|
|
|
2619
2757
|
options: options_default,
|
|
2620
2758
|
defaultOptions: { arrowParens: "avoid" }
|
|
2621
2759
|
};
|
|
2622
|
-
//#endregion
|
|
2623
2760
|
export { src_default as default };
|