prettier-java-next-line 2.11.1 → 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/dist/index.cjs +961 -869
- package/dist/index.d.cts +2 -11
- package/dist/index.d.mts +3 -13
- package/dist/index.mjs +961 -869
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
let web_tree_sitter = require("web-tree-sitter");
|
|
2
2
|
let prettier = require("prettier");
|
|
3
3
|
let prettier_doc = require("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",
|
|
@@ -95,8 +95,7 @@ var options_default = {
|
|
|
95
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."
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
|
-
|
|
99
|
-
//#region src/node-types.ts
|
|
98
|
+
// src/node-types.ts
|
|
100
99
|
const multiFieldsByType = {
|
|
101
100
|
array_creation_expression: { dimensions: true },
|
|
102
101
|
cast_expression: { type: true },
|
|
@@ -113,9 +112,9 @@ const multiFieldsByType = {
|
|
|
113
112
|
requires_module_directive: { modifiers: true },
|
|
114
113
|
spread_parameter: { annotations: true }
|
|
115
114
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
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 } = prettier.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 } = prettier_doc.builders;
|
|
119
118
|
const { mapDoc } = prettier_doc.utils;
|
|
120
119
|
function hasType(path, type) {
|
|
121
120
|
return path.node.type === type;
|
|
@@ -149,6 +148,10 @@ function printDanglingComments(path, danglingCommentsPrintOptions = {}) {
|
|
|
149
148
|
const doc = join$7(hardline$7, parts);
|
|
150
149
|
return shouldIndent ? indent$7([hardline$7, doc]) : doc;
|
|
151
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
|
+
}
|
|
152
155
|
function printComment(comment) {
|
|
153
156
|
comment.printed = true;
|
|
154
157
|
const lines = comment.value.split("\n").map((line) => line.trim());
|
|
@@ -160,56 +163,119 @@ function hasLeadingComments(node) {
|
|
|
160
163
|
function hasDanglingComments(node) {
|
|
161
164
|
return node.comments?.some(({ leading, trailing }) => !leading && !trailing) ?? false;
|
|
162
165
|
}
|
|
163
|
-
function closingBracketLine(options, lineDoc = softline$
|
|
166
|
+
function closingBracketLine(options, lineDoc = softline$3) {
|
|
164
167
|
return options?.closingBracket === "same-line" ? "" : lineDoc;
|
|
165
168
|
}
|
|
166
169
|
function indentInParentheses(contents, options) {
|
|
167
170
|
return contents && !Array.isArray(contents) || contents.length ? [
|
|
168
171
|
"(",
|
|
169
|
-
indent$7([softline$
|
|
172
|
+
indent$7([softline$3, contents]),
|
|
170
173
|
closingBracketLine(options),
|
|
171
174
|
")"
|
|
172
175
|
] : "()";
|
|
173
176
|
}
|
|
174
177
|
function printArrayInitializer(path, print, options) {
|
|
175
|
-
|
|
176
|
-
|
|
178
|
+
const { node } = path;
|
|
179
|
+
const elements = node.namedChildren;
|
|
180
|
+
const isNested = isNestedArray(path);
|
|
181
|
+
if (elements.length === 0) {
|
|
182
|
+
const danglingComments = printDanglingCommentsInList(path);
|
|
177
183
|
if (!danglingComments) return "{}";
|
|
178
|
-
const block = [
|
|
184
|
+
const block = group$7([
|
|
179
185
|
"{",
|
|
180
186
|
danglingComments,
|
|
181
|
-
|
|
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,
|
|
182
209
|
"}"
|
|
183
210
|
];
|
|
184
|
-
return
|
|
211
|
+
return group$7(isNested ? block : [softline$3, ...block], {
|
|
212
|
+
shouldBreak,
|
|
213
|
+
id: groupId
|
|
214
|
+
});
|
|
185
215
|
}
|
|
186
|
-
|
|
187
|
-
if (list.length && options.trailingComma !== "none") list.push(ifBreak$2(","));
|
|
188
|
-
if (options.braceStyle === "next-line" && path.node.type === "array_initializer") {
|
|
189
|
-
if (options.arrayInitializerLayout === "fit") {
|
|
190
|
-
const bracketLine = options.bracketSpacing ? line$7 : softline$4;
|
|
191
|
-
const block = [
|
|
192
|
-
"{",
|
|
193
|
-
indent$7([bracketLine, ...list]),
|
|
194
|
-
bracketLine,
|
|
195
|
-
"}"
|
|
196
|
-
];
|
|
197
|
-
return group$7(isNestedArray(path) ? block : [softline$4, ...block]);
|
|
198
|
-
}
|
|
216
|
+
if (nextLineLayout === "always-break") {
|
|
199
217
|
const block = [
|
|
200
218
|
"{",
|
|
201
|
-
indent$7([line$7,
|
|
219
|
+
indent$7([line$7, contents]),
|
|
202
220
|
line$7,
|
|
203
221
|
"}"
|
|
204
222
|
];
|
|
205
|
-
return
|
|
223
|
+
return isNested ? [breakParent$2, ...block] : [hardline$7, ...block];
|
|
206
224
|
}
|
|
207
225
|
return group$7([
|
|
208
226
|
"{",
|
|
209
|
-
indent$7([line$7,
|
|
227
|
+
indent$7([line$7, contents]),
|
|
210
228
|
line$7,
|
|
211
229
|
"}"
|
|
212
|
-
]
|
|
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);
|
|
213
279
|
}
|
|
214
280
|
function isNestedArray(path) {
|
|
215
281
|
return path.parent?.type === "array_initializer" || path.parent?.type === "element_value_array_initializer";
|
|
@@ -306,7 +372,7 @@ function printBlockStatements(path, print) {
|
|
|
306
372
|
function printBodyDeclarations(path, print, padFirst = false) {
|
|
307
373
|
const isInterfaceBody = path.node.type === "interface_body";
|
|
308
374
|
const isFormalParameters = path.node.type === "formal_parameters";
|
|
309
|
-
const separator = isFormalParameters ? softline$
|
|
375
|
+
const separator = isFormalParameters ? softline$3 : hardline$7;
|
|
310
376
|
let previousRequiresPadding = padFirst;
|
|
311
377
|
return path.map((child) => {
|
|
312
378
|
const { node, previous } = child;
|
|
@@ -329,7 +395,7 @@ function printTypeParameters(path, print, options) {
|
|
|
329
395
|
];
|
|
330
396
|
const parts = [
|
|
331
397
|
"<",
|
|
332
|
-
indent$7([softline$
|
|
398
|
+
indent$7([softline$3, join$7([",", line$7], path.map(print, "namedChildren"))]),
|
|
333
399
|
closingBracketLine(options),
|
|
334
400
|
">"
|
|
335
401
|
];
|
|
@@ -346,7 +412,7 @@ function printVariableDeclaration(path, print) {
|
|
|
346
412
|
}
|
|
347
413
|
function printAssignment(leftDoc, operator, rightDoc, rightNode) {
|
|
348
414
|
if (!rightDoc || !rightNode) return leftDoc;
|
|
349
|
-
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([
|
|
350
416
|
leftDoc,
|
|
351
417
|
operator,
|
|
352
418
|
group$7(indent$7([line$7, rightDoc]))
|
|
@@ -367,12 +433,14 @@ function inferParser(options, language) {
|
|
|
367
433
|
return getLanguageByLanguageName(options.plugins?.filter((plugin) => typeof plugin !== "string" && !(plugin instanceof URL)).reverse().flatMap((plugin) => plugin.languages ?? []) ?? [], language)?.parsers[0];
|
|
368
434
|
}
|
|
369
435
|
function printTextBlock(contents) {
|
|
370
|
-
return [
|
|
371
|
-
"\"\"\"",
|
|
436
|
+
return ["\"\"\"", indent$7([
|
|
372
437
|
hardline$7,
|
|
373
438
|
contents,
|
|
374
439
|
"\"\"\""
|
|
375
|
-
];
|
|
440
|
+
])];
|
|
441
|
+
}
|
|
442
|
+
function isTextBlock(node) {
|
|
443
|
+
return node.type === "string_literal" && node.children[0].value === "\"\"\"";
|
|
376
444
|
}
|
|
377
445
|
function embedTextBlock(path, options) {
|
|
378
446
|
if (path.node.namedChildren.some(({ type }) => type === "string_interpolation") || path.node.children[0].value === "\"") return null;
|
|
@@ -567,169 +635,570 @@ function unescapeTextBlockContents(text) {
|
|
|
567
635
|
}
|
|
568
636
|
});
|
|
569
637
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
const {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
]);
|
|
620
|
-
},
|
|
621
|
-
switch_block(path, print, options) {
|
|
622
|
-
return printBlock(path, path.map(print, "namedChildren"), options);
|
|
623
|
-
},
|
|
624
|
-
switch_block_statement_group(path, print) {
|
|
625
|
-
const parts = [];
|
|
626
|
-
path.each((child) => {
|
|
627
|
-
if (child.node.type === "switch_label") parts.push(print(child), ":");
|
|
628
|
-
}, "namedChildren");
|
|
629
|
-
const firstStatementIndex = path.node.namedChildren.findIndex(({ type }) => type !== "switch_label");
|
|
630
|
-
if (firstStatementIndex === path.node.namedChildren.length - 1 && path.node.namedChildren[firstStatementIndex].type === "block") parts.push(" ", path.call(print, "namedChildren", firstStatementIndex));
|
|
631
|
-
else if (firstStatementIndex !== -1) parts.push(indent$6([hardline$6, ...join$6(hardline$6, printBlockStatements(path, print))]));
|
|
632
|
-
return parts;
|
|
633
|
-
},
|
|
634
|
-
switch_label(path, print) {
|
|
635
|
-
if (!path.node.children.some(({ type }) => type === "case")) return "default";
|
|
636
|
-
const values = [];
|
|
637
|
-
path.each((child) => {
|
|
638
|
-
if (child.node.type !== "guard") values.push(print(child));
|
|
639
|
-
}, "namedChildren");
|
|
640
|
-
const hasMultipleValues = values.length > 1;
|
|
641
|
-
const label = hasMultipleValues ? ["case", indent$6([line$6, ...join$6([",", line$6], values)])] : ["case ", values[0]];
|
|
642
|
-
const guardIndex = path.node.namedChildren.findIndex(({ type }) => type === "guard");
|
|
643
|
-
return guardIndex !== -1 ? [group$6([...label, hasMultipleValues ? line$6 : " "]), path.call(print, "namedChildren", guardIndex)] : group$6(label);
|
|
644
|
-
},
|
|
645
|
-
switch_rule(path, print) {
|
|
646
|
-
const bodyIndex = path.node.namedChildren.findIndex(({ type }) => type === "block" || type === "expression_statement" || type === "throw_statement");
|
|
647
|
-
const body = path.call(print, "namedChildren", bodyIndex);
|
|
648
|
-
const switchLabelIndex = path.node.namedChildren.findIndex(({ type }) => type === "switch_label");
|
|
649
|
-
const parts = [path.call(print, "namedChildren", switchLabelIndex), " ->"];
|
|
650
|
-
const bodyNode = path.node.namedChildren[bodyIndex];
|
|
651
|
-
if (bodyNode.type !== "block" && hasLeadingComments(bodyNode)) parts.push(indent$6([hardline$6, body]));
|
|
652
|
-
else parts.push(" ", body);
|
|
653
|
-
return parts;
|
|
654
|
-
},
|
|
655
|
-
while_statement(path, print) {
|
|
656
|
-
const parts = ["while ", path.call(print, "conditionNode")];
|
|
657
|
-
const body = path.call(print, "bodyNode");
|
|
658
|
-
const bodyType = path.node.bodyNode.type;
|
|
659
|
-
if (bodyType === "block") {
|
|
660
|
-
parts.push(" ", body);
|
|
661
|
-
return parts;
|
|
662
|
-
} else if (bodyType === ";") {
|
|
663
|
-
parts.push(";");
|
|
664
|
-
return parts;
|
|
665
|
-
} else {
|
|
666
|
-
parts.push(line$6, body);
|
|
667
|
-
return group$6(indent$6(parts));
|
|
638
|
+
// src/comments.ts
|
|
639
|
+
const { hasNewline: hasNewline$1, isPreviousLineEmpty, skipNewline, skipSpaces } = prettier.util;
|
|
640
|
+
const { breakParent: breakParent$1, hardline: hardline$6, line: line$6, lineSuffix } = prettier_doc.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));
|
|
668
687
|
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
const forStatement = [
|
|
706
|
-
danglingComments && [danglingComments, hardline$6],
|
|
707
|
-
"for (",
|
|
708
|
-
...printModifiers(path, print),
|
|
709
|
-
path.call(print, "typeNode"),
|
|
710
|
-
" ",
|
|
711
|
-
path.call(print, "nameNode")
|
|
712
|
-
];
|
|
713
|
-
if (hasChild(path, "dimensionsNode")) forStatement.push(path.call(print, "dimensionsNode"));
|
|
714
|
-
forStatement.push(" : ", path.call(print, "valueNode"), ")");
|
|
715
|
-
const bodyType = path.node.bodyNode.type;
|
|
716
|
-
if (bodyType === ";") forStatement.push(";");
|
|
717
|
-
else {
|
|
718
|
-
const body = path.call(print, "bodyNode");
|
|
719
|
-
forStatement.push(bodyType === "block" ? [" ", body] : indent$6([line$6, body]));
|
|
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") prettier.util.addLeadingComment(followingNode, commentNode);
|
|
719
|
+
else prettier.util.addTrailingComment(followingNode, commentNode);
|
|
720
|
+
return true;
|
|
721
|
+
} else if (options.experimentalOperatorPosition === "start" && isBinaryOperator(precedingNode)) {
|
|
722
|
+
prettier.util.addLeadingComment(precedingNode, commentNode);
|
|
723
|
+
return true;
|
|
720
724
|
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
return
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
725
|
+
}
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
function handleFormalParametersComments(commentNode) {
|
|
729
|
+
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
730
|
+
if (enclosingNode?.type === "formal_parameters" && !precedingNode && !followingNode) {
|
|
731
|
+
prettier.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
|
+
prettier.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
|
+
prettier.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
|
+
prettier.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
|
+
prettier.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) prettier.util.addLeadingComment(followingNode.namedChildren[0], commentNode);
|
|
773
|
+
else prettier.util.addDanglingComment(followingNode, commentNode, void 0);
|
|
774
|
+
} else prettier.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
|
+
prettier.util.addLeadingComment(memberChainRoot, commentNode);
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
786
|
+
if (precedingNode && (enclosingNode.type === "field_access" || precedingNode.end.row < commentNode.start.row) && precedingNode === getMemberObject(enclosingNode)) {
|
|
787
|
+
prettier.util.addLeadingComment(enclosingNode, commentNode);
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
return false;
|
|
792
|
+
}
|
|
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;
|
|
801
|
+
}
|
|
802
|
+
function handleModifiersComments(commentNode) {
|
|
803
|
+
const { precedingNode } = commentNode;
|
|
804
|
+
if (precedingNode?.type === "annotation" || precedingNode?.type === "marker_annotation" || precedingNode?.type === "modifiers") {
|
|
805
|
+
prettier.util.addTrailingComment(precedingNode, commentNode);
|
|
806
|
+
return true;
|
|
807
|
+
}
|
|
808
|
+
return false;
|
|
809
|
+
}
|
|
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
|
+
prettier.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
|
+
prettier.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) prettier.util.addLeadingComment(blockStatement, commentNode);
|
|
833
|
+
else prettier.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 web_tree_sitter.Parser.init();
|
|
969
|
+
const parser = new web_tree_sitter.Parser();
|
|
970
|
+
const Java = await web_tree_sitter.Language.load(new URL("./tree-sitter-java_orchard.wasm", require("url").pathToFileURL(__filename).href));
|
|
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 } = prettier_doc.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 ? [
|
|
733
1202
|
"continue ",
|
|
734
1203
|
path.call(print, "namedChildren", identifierIndex),
|
|
735
1204
|
";"
|
|
@@ -759,7 +1228,7 @@ var blocks_and_statements_default = {
|
|
|
759
1228
|
const params = group$6(indentInParentheses(path.call(print, "namedChildren", catchFormalParameterIndex), options));
|
|
760
1229
|
const body = path.call(print, "bodyNode");
|
|
761
1230
|
if (options?.braceStyle === "next-line") return [
|
|
762
|
-
hardline$
|
|
1231
|
+
hardline$5,
|
|
763
1232
|
"catch ",
|
|
764
1233
|
params,
|
|
765
1234
|
body
|
|
@@ -779,11 +1248,11 @@ var blocks_and_statements_default = {
|
|
|
779
1248
|
return parts;
|
|
780
1249
|
},
|
|
781
1250
|
catch_type(path, print) {
|
|
782
|
-
return join$6([line$
|
|
1251
|
+
return join$6([line$5, "| "], path.map(print, "namedChildren"));
|
|
783
1252
|
},
|
|
784
1253
|
finally_clause(path, print, options) {
|
|
785
1254
|
if (options?.braceStyle === "next-line") return [
|
|
786
|
-
hardline$
|
|
1255
|
+
hardline$5,
|
|
787
1256
|
"finally",
|
|
788
1257
|
path.call(print, "namedChildren", 0)
|
|
789
1258
|
];
|
|
@@ -818,7 +1287,7 @@ var blocks_and_statements_default = {
|
|
|
818
1287
|
hasTrailingSemicolon = false;
|
|
819
1288
|
} else if (child.node.type === ";") hasTrailingSemicolon = true;
|
|
820
1289
|
}, "children");
|
|
821
|
-
const parts = join$6([";", line$
|
|
1290
|
+
const parts = join$6([";", line$5], resources);
|
|
822
1291
|
if (hasTrailingSemicolon) parts.push(ifBreak$1(";"));
|
|
823
1292
|
return group$6(indentInParentheses(parts, options));
|
|
824
1293
|
},
|
|
@@ -829,10 +1298,10 @@ var blocks_and_statements_default = {
|
|
|
829
1298
|
if (hasChild(path, "dimensionsNode")) parts.push(path.call(print, "dimensionsNode"));
|
|
830
1299
|
parts.push(" =");
|
|
831
1300
|
const value = path.call(print, "valueNode");
|
|
832
|
-
if (path.node.valueNode.type === "binary_expression" || hasLeadingComments(path.node.valueNode)) parts.push(group$6(indent$6([line$
|
|
1301
|
+
if (path.node.valueNode.type === "binary_expression" || hasLeadingComments(path.node.valueNode)) parts.push(group$6(indent$6([line$5, value])));
|
|
833
1302
|
else {
|
|
834
1303
|
const groupId = Symbol("assignment");
|
|
835
|
-
parts.push(group$6(indent$6(line$
|
|
1304
|
+
parts.push(group$6(indent$6(line$5), { id: groupId }), indentIfBreak$1(value, { groupId }));
|
|
836
1305
|
}
|
|
837
1306
|
return parts;
|
|
838
1307
|
}
|
|
@@ -848,20 +1317,20 @@ var blocks_and_statements_default = {
|
|
|
848
1317
|
}
|
|
849
1318
|
};
|
|
850
1319
|
function printExpressionList(expressions) {
|
|
851
|
-
return group$6(expressions.map((expression, index) => index === 0 ? expression : [",", indent$6([line$
|
|
1320
|
+
return group$6(expressions.map((expression, index) => index === 0 ? expression : [",", indent$6([line$5, expression])]));
|
|
852
1321
|
}
|
|
853
1322
|
function printReturnOrThrowArgument(path, print, options) {
|
|
854
1323
|
const { node } = path;
|
|
855
1324
|
const argumentDoc = print(path);
|
|
856
1325
|
if (returnArgumentHasLeadingComment(node)) return [
|
|
857
1326
|
"(",
|
|
858
|
-
indent$6([hardline$
|
|
859
|
-
closingBracketLine(options, hardline$
|
|
1327
|
+
indent$6([hardline$5, argumentDoc]),
|
|
1328
|
+
closingBracketLine(options, hardline$5),
|
|
860
1329
|
")"
|
|
861
1330
|
];
|
|
862
1331
|
if (node.type === "binary_expression") return group$6([
|
|
863
1332
|
ifBreak$1("("),
|
|
864
|
-
indent$6([softline$
|
|
1333
|
+
indent$6([softline$2, argumentDoc]),
|
|
865
1334
|
closingBracketLine(options),
|
|
866
1335
|
ifBreak$1(")")
|
|
867
1336
|
]);
|
|
@@ -875,9 +1344,8 @@ function printReturnOrThrowStatement(path, print, options) {
|
|
|
875
1344
|
";"
|
|
876
1345
|
];
|
|
877
1346
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
const { group: group$5, hardline: hardline$5, indent: indent$5, join: join$5, line: line$5, softline: softline$2 } = prettier_doc.builders;
|
|
1347
|
+
// src/printers/classes.ts
|
|
1348
|
+
const { group: group$5, hardline: hardline$4, indent: indent$5, join: join$5, line: line$4 } = prettier_doc.builders;
|
|
881
1349
|
var classes_default = {
|
|
882
1350
|
class_declaration(path, print, options) {
|
|
883
1351
|
const parts = ["class ", path.call(print, "nameNode")];
|
|
@@ -894,10 +1362,10 @@ var classes_default = {
|
|
|
894
1362
|
if (definedClauses.length) {
|
|
895
1363
|
const clauses = definedClauses.flatMap((clause) => {
|
|
896
1364
|
if (!hasChild(path, clause)) return [];
|
|
897
|
-
return [clause === "superclassNode" || clause === "interfacesNode" ? hardline$
|
|
1365
|
+
return [clause === "superclassNode" || clause === "interfacesNode" ? hardline$4 : line$4, path.call(print, clause)];
|
|
898
1366
|
});
|
|
899
1367
|
const hasBody = path.node.bodyNode.namedChildren.length > 0;
|
|
900
|
-
const afterClauses = options?.braceStyle === "next-line" ? "" : hasBody ? line$
|
|
1368
|
+
const afterClauses = options?.braceStyle === "next-line" ? "" : hasBody ? line$4 : " ";
|
|
901
1369
|
const clauseGroup = [indent$5(clauses), afterClauses];
|
|
902
1370
|
parts.push(hasMultipleClauses ? clauseGroup : group$5(clauseGroup));
|
|
903
1371
|
} else if (options?.braceStyle !== "next-line") parts.push(" ");
|
|
@@ -912,13 +1380,13 @@ var classes_default = {
|
|
|
912
1380
|
return ["extends ", path.call(print, "namedChildren", 0)];
|
|
913
1381
|
},
|
|
914
1382
|
super_interfaces(path, print) {
|
|
915
|
-
return group$5(["implements", indent$5([line$
|
|
1383
|
+
return group$5(["implements", indent$5([line$4, path.call(print, "namedChildren", 0)])]);
|
|
916
1384
|
},
|
|
917
1385
|
permits(path, print) {
|
|
918
|
-
return group$5(["permits", indent$5([line$
|
|
1386
|
+
return group$5(["permits", indent$5([line$4, path.call(print, "namedChildren", 0)])]);
|
|
919
1387
|
},
|
|
920
1388
|
type_list(path, print) {
|
|
921
|
-
return join$5([",", line$
|
|
1389
|
+
return join$5([",", line$4], path.map(print, "namedChildren"));
|
|
922
1390
|
},
|
|
923
1391
|
class_body(path, print, options) {
|
|
924
1392
|
return printBlock(path, printBodyDeclarations(path, print, path.parent?.type === "class_declaration" && options?.braceStyle !== "next-line"), options);
|
|
@@ -940,7 +1408,7 @@ var classes_default = {
|
|
|
940
1408
|
if (hasChild(path, "dimensionsNode")) declaration.push(path.call(print, "dimensionsNode"));
|
|
941
1409
|
declaration.push(" ", path.call(print, "nameNode"), group$5(path.call(print, "parametersNode")));
|
|
942
1410
|
const throwsIndex = path.node.namedChildren.findIndex(({ type }) => type === "throws");
|
|
943
|
-
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)])));
|
|
944
1412
|
return hasChild(path, "bodyNode") ? [
|
|
945
1413
|
modifiers,
|
|
946
1414
|
group$5(declaration),
|
|
@@ -962,7 +1430,7 @@ var classes_default = {
|
|
|
962
1430
|
printDanglingCommentsInList(path),
|
|
963
1431
|
")"
|
|
964
1432
|
];
|
|
965
|
-
return indentInParentheses(join$5([",", line$
|
|
1433
|
+
return indentInParentheses(join$5([",", line$4], parameters), options);
|
|
966
1434
|
},
|
|
967
1435
|
formal_parameter(path, print) {
|
|
968
1436
|
const parameter = printModifiers(path, print, path.grandparent?.type === "record_declaration" ? "avoidBreak" : "noBreak");
|
|
@@ -979,7 +1447,8 @@ var classes_default = {
|
|
|
979
1447
|
return parts;
|
|
980
1448
|
},
|
|
981
1449
|
throws(path, print) {
|
|
982
|
-
|
|
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)]))];
|
|
983
1452
|
},
|
|
984
1453
|
static_initializer(path, print) {
|
|
985
1454
|
return ["static ", path.call(print, "namedChildren", 0)];
|
|
@@ -990,7 +1459,7 @@ var classes_default = {
|
|
|
990
1459
|
if (hasChild(path, "type_parametersNode")) declaration.push(group$5(path.call(print, "type_parametersNode")), " ");
|
|
991
1460
|
declaration.push(path.call(print, "nameNode"), group$5(path.call(print, "parametersNode")));
|
|
992
1461
|
const throwsIndex = path.node.namedChildren.findIndex(({ type }) => type === "throws");
|
|
993
|
-
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)])));
|
|
994
1463
|
return [
|
|
995
1464
|
modifiers,
|
|
996
1465
|
group$5(declaration),
|
|
@@ -1029,14 +1498,14 @@ var classes_default = {
|
|
|
1029
1498
|
}
|
|
1030
1499
|
modifiers.sort((a, b) => (indexByModifier.get(a) ?? -1) - (indexByModifier.get(b) ?? -1));
|
|
1031
1500
|
if (modifiers.length || typeAnnotations.length) parts.push(join$5(" ", [...modifiers, ...typeAnnotations]));
|
|
1032
|
-
return join$5(annotationMode === "avoidBreak" ? line$
|
|
1501
|
+
return join$5(annotationMode === "avoidBreak" ? line$4 : annotationMode === "noBreak" ? " " : hardline$4, parts);
|
|
1033
1502
|
},
|
|
1034
1503
|
enum_declaration(path, print, options) {
|
|
1035
1504
|
const modifiers = printModifiers(path, print, "declarationOnly");
|
|
1036
1505
|
const parts = ["enum ", path.call(print, "nameNode")];
|
|
1037
1506
|
if (hasChild(path, "interfacesNode")) {
|
|
1038
1507
|
const hasBody = path.node.bodyNode.namedChildren.length > 0;
|
|
1039
|
-
parts.push(indent$5([hardline$
|
|
1508
|
+
parts.push(indent$5([hardline$4, path.call(print, "interfacesNode")]), options?.braceStyle === "next-line" ? "" : hasBody ? line$4 : " ");
|
|
1040
1509
|
} else parts.push(" ");
|
|
1041
1510
|
return [
|
|
1042
1511
|
...modifiers,
|
|
@@ -1052,16 +1521,16 @@ var classes_default = {
|
|
|
1052
1521
|
const hasDeclarations = path.node.namedChildren[enumBodyDeclarationsIndex].namedChildren.length > 0;
|
|
1053
1522
|
const enumBodyDeclarations = parts.pop();
|
|
1054
1523
|
if (hasDeclarations) {
|
|
1055
|
-
if (!parts.length) declarations.push(hardline$
|
|
1524
|
+
if (!parts.length) declarations.push(hardline$4);
|
|
1056
1525
|
declarations.push(enumBodyDeclarations);
|
|
1057
1526
|
}
|
|
1058
1527
|
}
|
|
1059
1528
|
const contents = [];
|
|
1060
1529
|
if (parts.length) {
|
|
1061
|
-
contents.push(join$5([",", hardline$
|
|
1530
|
+
contents.push(join$5([",", hardline$4], parts));
|
|
1062
1531
|
if (!declarations.length && options.trailingComma !== "none") contents.push(",");
|
|
1063
1532
|
}
|
|
1064
|
-
if (declarations.length) contents.push(";", hardline$
|
|
1533
|
+
if (declarations.length) contents.push(";", hardline$4, ...declarations);
|
|
1065
1534
|
return printBlock(path, contents.length ? [contents] : [], options);
|
|
1066
1535
|
},
|
|
1067
1536
|
enum_constant(path, print) {
|
|
@@ -1072,7 +1541,7 @@ var classes_default = {
|
|
|
1072
1541
|
return initializer;
|
|
1073
1542
|
},
|
|
1074
1543
|
enum_body_declarations(path, print) {
|
|
1075
|
-
return join$5(hardline$
|
|
1544
|
+
return join$5(hardline$4, printBodyDeclarations(path, print));
|
|
1076
1545
|
},
|
|
1077
1546
|
record_declaration(path, print) {
|
|
1078
1547
|
const modifiers = printModifiers(path, print, "declarationOnly");
|
|
@@ -1081,8 +1550,8 @@ var classes_default = {
|
|
|
1081
1550
|
parts.push(group$5(path.call(print, "parametersNode")));
|
|
1082
1551
|
if (hasChild(path, "interfacesNode")) {
|
|
1083
1552
|
const hasBody = path.node.bodyNode.namedChildren.length > 0;
|
|
1084
|
-
const interfaces = [hardline$
|
|
1085
|
-
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 : " "]));
|
|
1086
1555
|
} else parts.push(" ");
|
|
1087
1556
|
return [
|
|
1088
1557
|
...modifiers,
|
|
@@ -1112,14 +1581,9 @@ const indexByModifier = [
|
|
|
1112
1581
|
"non-sealed",
|
|
1113
1582
|
"strictfp"
|
|
1114
1583
|
].reduce((map, name, index) => map.set(name, index), /* @__PURE__ */ new Map());
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
}
|
|
1119
|
-
//#endregion
|
|
1120
|
-
//#region src/printers/expressions.ts
|
|
1121
|
-
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 } = prettier_doc.builders;
|
|
1122
|
-
const { getNextNonSpaceNonCommentCharacterIndex, hasNewline: hasNewline$1, isNextLineEmpty } = prettier.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 } = prettier_doc.builders;
|
|
1586
|
+
const { getNextNonSpaceNonCommentCharacterIndex, hasNewline, isNextLineEmpty } = prettier.util;
|
|
1123
1587
|
const { removeLines, willBreak } = prettier_doc.utils;
|
|
1124
1588
|
var expressions_default = {
|
|
1125
1589
|
lambda_expression(path, print, options, args) {
|
|
@@ -1142,7 +1606,7 @@ var expressions_default = {
|
|
|
1142
1606
|
functionBody = node.bodyNode;
|
|
1143
1607
|
} else path.call(rec, "bodyNode");
|
|
1144
1608
|
})();
|
|
1145
|
-
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);
|
|
1146
1610
|
const chainGroupId = Symbol("arrow-chain");
|
|
1147
1611
|
const signaturesDoc = printArrowFunctionSignatures(path, { signatureDocs });
|
|
1148
1612
|
bodyDoc = printArrowFunctionBody(path, args, options, {
|
|
@@ -1162,7 +1626,7 @@ var expressions_default = {
|
|
|
1162
1626
|
if (child.node.type === "identifier") identifiers.push(print(child));
|
|
1163
1627
|
}, "namedChildren");
|
|
1164
1628
|
if (!identifiers.length) return "()";
|
|
1165
|
-
const parameters = join$4([",", line$
|
|
1629
|
+
const parameters = join$4([",", line$3], identifiers);
|
|
1166
1630
|
if (identifiers.length > 1 || willBreak(identifiers)) return group$4(indentInParentheses(parameters, options));
|
|
1167
1631
|
return options.arrowParens === "avoid" ? parameters : [
|
|
1168
1632
|
"(",
|
|
@@ -1186,24 +1650,36 @@ var expressions_default = {
|
|
|
1186
1650
|
i++;
|
|
1187
1651
|
} while (currentParent && currentParent.type === node.type && currentParent.conditionNode !== previousParent);
|
|
1188
1652
|
const firstNonConditionalParent = currentParent || parent;
|
|
1189
|
-
const
|
|
1190
|
-
const
|
|
1191
|
-
|
|
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,
|
|
1192
1668
|
"? ",
|
|
1193
|
-
|
|
1669
|
+
openParen,
|
|
1194
1670
|
printBranch("consequenceNode"),
|
|
1195
|
-
|
|
1196
|
-
line$
|
|
1671
|
+
closeParen,
|
|
1672
|
+
line$3,
|
|
1197
1673
|
": ",
|
|
1198
1674
|
printBranch("alternativeNode")
|
|
1199
1675
|
];
|
|
1200
|
-
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));
|
|
1201
1677
|
const maybeGroup = (doc) => parent === firstNonConditionalParent ? group$4(doc) : doc;
|
|
1202
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";
|
|
1203
1679
|
const shouldExtraIndent = shouldExtraIndentForTernaryExpression(path);
|
|
1204
1680
|
const result = maybeGroup([
|
|
1205
1681
|
printTernaryTest(path, print),
|
|
1206
|
-
forceNoIndent ? parts : indent$4(parts),
|
|
1682
|
+
forceNoIndent && !operatorAtEnd ? parts : indent$4(parts),
|
|
1207
1683
|
breakClosingParen && !shouldExtraIndent ? closingBracketLine(options) : ""
|
|
1208
1684
|
]);
|
|
1209
1685
|
return isParentTest || shouldExtraIndent ? group$4([indent$4([softline$1, result]), closingBracketLine(options)]) : result;
|
|
@@ -1231,7 +1707,7 @@ var expressions_default = {
|
|
|
1231
1707
|
return group$4(indent$4(path.map((child) => {
|
|
1232
1708
|
const doc = print(child, { annotationMode: "noBreak" });
|
|
1233
1709
|
if (!child.previous) return doc;
|
|
1234
|
-
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];
|
|
1235
1711
|
}, "children")));
|
|
1236
1712
|
},
|
|
1237
1713
|
unary_expression(path, print, options) {
|
|
@@ -1279,7 +1755,7 @@ var expressions_default = {
|
|
|
1279
1755
|
")"
|
|
1280
1756
|
] : [
|
|
1281
1757
|
"(",
|
|
1282
|
-
indent$4([softline$1, join$4([" &", line$
|
|
1758
|
+
indent$4([softline$1, join$4([" &", line$3], path.map(print, "typeNodes"))]),
|
|
1283
1759
|
softline$1,
|
|
1284
1760
|
")"
|
|
1285
1761
|
]),
|
|
@@ -1304,7 +1780,11 @@ var expressions_default = {
|
|
|
1304
1780
|
const args = path.node.namedChildren;
|
|
1305
1781
|
if (args.length === 0) {
|
|
1306
1782
|
const shouldBreak = path.node.comments?.some(({ type, leading, trailing }) => !leading && !trailing && type === "line_comment");
|
|
1307
|
-
return group$4(
|
|
1783
|
+
return group$4([
|
|
1784
|
+
"(",
|
|
1785
|
+
printDanglingCommentsInList(path),
|
|
1786
|
+
")"
|
|
1787
|
+
], { shouldBreak });
|
|
1308
1788
|
}
|
|
1309
1789
|
const lastArgIndex = args.length - 1;
|
|
1310
1790
|
let anyArgEmptyLine = false;
|
|
@@ -1316,21 +1796,21 @@ var expressions_default = {
|
|
|
1316
1796
|
argDoc = [
|
|
1317
1797
|
argDoc,
|
|
1318
1798
|
",",
|
|
1319
|
-
hardline$
|
|
1320
|
-
hardline$
|
|
1799
|
+
hardline$3,
|
|
1800
|
+
hardline$3
|
|
1321
1801
|
];
|
|
1322
1802
|
} else argDoc = [
|
|
1323
1803
|
argDoc,
|
|
1324
1804
|
",",
|
|
1325
|
-
line$
|
|
1805
|
+
line$3
|
|
1326
1806
|
];
|
|
1327
1807
|
printedArguments.push(argDoc);
|
|
1328
1808
|
}, "namedChildren");
|
|
1329
1809
|
function allArgsBrokenOut() {
|
|
1330
1810
|
return group$4([
|
|
1331
1811
|
"(",
|
|
1332
|
-
indent$4([line$
|
|
1333
|
-
closingBracketLine(options, line$
|
|
1812
|
+
indent$4([line$3, ...printedArguments]),
|
|
1813
|
+
closingBracketLine(options, line$3),
|
|
1334
1814
|
")"
|
|
1335
1815
|
], { shouldBreak: true });
|
|
1336
1816
|
}
|
|
@@ -1345,7 +1825,7 @@ var expressions_default = {
|
|
|
1345
1825
|
if (caught instanceof ArgExpansionBailout) return allArgsBrokenOut();
|
|
1346
1826
|
throw caught;
|
|
1347
1827
|
}
|
|
1348
|
-
if (willBreak(firstArg)) return [breakParent
|
|
1828
|
+
if (willBreak(firstArg)) return [breakParent, conditionalGroup([[
|
|
1349
1829
|
"(",
|
|
1350
1830
|
group$4(firstArg, { shouldBreak: true }),
|
|
1351
1831
|
", ",
|
|
@@ -1370,7 +1850,7 @@ var expressions_default = {
|
|
|
1370
1850
|
allArgsBrokenOut()
|
|
1371
1851
|
]);
|
|
1372
1852
|
}
|
|
1373
|
-
if (shouldExpandLastArg(args)) {
|
|
1853
|
+
if (shouldExpandLastArg(args, options)) {
|
|
1374
1854
|
const headArgs = printedArguments.slice(0, -1);
|
|
1375
1855
|
if (headArgs.some(willBreak)) return allArgsBrokenOut();
|
|
1376
1856
|
let lastArg;
|
|
@@ -1380,7 +1860,7 @@ var expressions_default = {
|
|
|
1380
1860
|
if (caught instanceof ArgExpansionBailout) return allArgsBrokenOut();
|
|
1381
1861
|
throw caught;
|
|
1382
1862
|
}
|
|
1383
|
-
if (willBreak(lastArg)) return [breakParent
|
|
1863
|
+
if (willBreak(lastArg)) return [breakParent, conditionalGroup([[
|
|
1384
1864
|
"(",
|
|
1385
1865
|
...headArgs,
|
|
1386
1866
|
group$4(lastArg, { shouldBreak: true }),
|
|
@@ -1444,7 +1924,7 @@ var expressions_default = {
|
|
|
1444
1924
|
return path.map(print, "children");
|
|
1445
1925
|
},
|
|
1446
1926
|
record_pattern_body(path, print, options) {
|
|
1447
|
-
return group$4(indentInParentheses(join$4([",", line$
|
|
1927
|
+
return group$4(indentInParentheses(join$4([",", line$3], path.map(print, "namedChildren")), options));
|
|
1448
1928
|
},
|
|
1449
1929
|
record_pattern_component(path, print) {
|
|
1450
1930
|
return join$4(" ", path.map(print, "children"));
|
|
@@ -1491,10 +1971,10 @@ function printArrowFunctionSignatures(path, { signatureDocs }) {
|
|
|
1491
1971
|
if (node.fieldName !== "object" && parent?.type === "method_invocation" || parent?.type === "binary_expression") return group$4([
|
|
1492
1972
|
signatureDocs[0],
|
|
1493
1973
|
" ->",
|
|
1494
|
-
indent$4([line$
|
|
1974
|
+
indent$4([line$3, join$4([" ->", line$3], signatureDocs.slice(1))])
|
|
1495
1975
|
]);
|
|
1496
|
-
if (node.fieldName === "object" && parent?.type === "method_invocation") return group$4(join$4([" ->", line$
|
|
1497
|
-
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)));
|
|
1498
1978
|
}
|
|
1499
1979
|
function printArrowFunctionBody(path, args, options, { bodyDoc, bodyComments, shouldPutBodyOnSameLine }) {
|
|
1500
1980
|
const trailingSpace = args && typeof args === "object" && "expandLastArg" in args && args.expandLastArg && !path.node.comments ? closingBracketLine(options) : "";
|
|
@@ -1503,7 +1983,7 @@ function printArrowFunctionBody(path, args, options, { bodyDoc, bodyComments, sh
|
|
|
1503
1983
|
bodyDoc,
|
|
1504
1984
|
bodyComments
|
|
1505
1985
|
] : [indent$4([
|
|
1506
|
-
line$
|
|
1986
|
+
line$3,
|
|
1507
1987
|
bodyDoc,
|
|
1508
1988
|
bodyComments
|
|
1509
1989
|
]), trailingSpace];
|
|
@@ -1535,7 +2015,7 @@ function printMemberChain(path, print, options) {
|
|
|
1535
2015
|
printedNodes.unshift({
|
|
1536
2016
|
node,
|
|
1537
2017
|
hasTrailingEmptyLine,
|
|
1538
|
-
printed: [printComments(path, printMethodInvocation(path, print)), hasTrailingEmptyLine ? hardline$
|
|
2018
|
+
printed: [printComments(path, printMethodInvocation(path, print)), hasTrailingEmptyLine ? hardline$3 : ""]
|
|
1539
2019
|
});
|
|
1540
2020
|
path.call(rec, "objectNode");
|
|
1541
2021
|
} else if (hasType(path, "array_access")) {
|
|
@@ -1559,28 +2039,32 @@ function printMemberChain(path, print, options) {
|
|
|
1559
2039
|
if (hasType(path, "method_invocation")) {
|
|
1560
2040
|
printedNodes.unshift({
|
|
1561
2041
|
node,
|
|
1562
|
-
printed:
|
|
2042
|
+
printed: printMethodInvocation(path, print)
|
|
1563
2043
|
});
|
|
1564
2044
|
if (hasChild(path, "objectNode")) path.call(rec, "objectNode");
|
|
1565
2045
|
} else if (hasType(path, "array_access")) {
|
|
1566
2046
|
printedNodes.unshift({
|
|
1567
2047
|
node,
|
|
1568
|
-
printed:
|
|
2048
|
+
printed: printArrayAccess(path, print)
|
|
1569
2049
|
});
|
|
1570
2050
|
if (hasChild(path, "arrayNode")) path.call(rec, "arrayNode");
|
|
1571
2051
|
} else if (hasType(path, "field_access")) {
|
|
1572
2052
|
printedNodes.unshift({
|
|
1573
2053
|
node,
|
|
1574
|
-
printed:
|
|
2054
|
+
printed: printFieldAccess(path, print)
|
|
1575
2055
|
});
|
|
1576
2056
|
if (hasChild(path, "objectNode")) path.call(rec, "objectNode");
|
|
1577
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);
|
|
1578
2059
|
const danglingComments = printDanglingComments(path);
|
|
1579
|
-
if (danglingComments)
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
2060
|
+
if (danglingComments) {
|
|
2061
|
+
const lastNode = printedNodes.at(-1);
|
|
2062
|
+
lastNode.printed = [
|
|
2063
|
+
danglingComments,
|
|
2064
|
+
hardline$3,
|
|
2065
|
+
lastNode.printed
|
|
2066
|
+
];
|
|
2067
|
+
}
|
|
1584
2068
|
const groups = [];
|
|
1585
2069
|
let currentGroup = [printedNodes[0]];
|
|
1586
2070
|
let i = 1;
|
|
@@ -1631,20 +2115,20 @@ function printMemberChain(path, print, options) {
|
|
|
1631
2115
|
}
|
|
1632
2116
|
function printIndentedGroup(groups) {
|
|
1633
2117
|
if (groups.length === 0) return "";
|
|
1634
|
-
return indent$4([hardline$
|
|
2118
|
+
return indent$4([hardline$3, join$4(hardline$3, groups.map(printGroup))]);
|
|
1635
2119
|
}
|
|
1636
2120
|
const printedGroups = groups.map(printGroup);
|
|
1637
2121
|
const oneLine = printedGroups;
|
|
1638
2122
|
const cutoff = shouldMerge ? 3 : 2;
|
|
1639
2123
|
const flatGroups = groups.flat();
|
|
1640
|
-
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));
|
|
1641
2125
|
if (groups.length <= cutoff && !nodeHasComment && !groups.some((g) => g.at(-1).hasTrailingEmptyLine)) return group$4(oneLine);
|
|
1642
2126
|
const lastNodeBeforeIndent = groups[shouldMerge ? 1 : 0].at(-1).node;
|
|
1643
2127
|
const shouldHaveEmptyLineBeforeIndent = lastNodeBeforeIndent.type !== "method_invocation" && shouldInsertEmptyLineAfter(lastNodeBeforeIndent);
|
|
1644
2128
|
const expanded = [
|
|
1645
2129
|
printGroup(groups[0]),
|
|
1646
2130
|
shouldMerge ? groups.slice(1, 2).map(printGroup) : "",
|
|
1647
|
-
shouldHaveEmptyLineBeforeIndent ? hardline$
|
|
2131
|
+
shouldHaveEmptyLineBeforeIndent ? hardline$3 : "",
|
|
1648
2132
|
printIndentedGroup(groups.slice(shouldMerge ? 2 : 1))
|
|
1649
2133
|
];
|
|
1650
2134
|
const methodInvocations = printedNodes.map(({ node }) => node).filter((node) => node.type === "method_invocation");
|
|
@@ -1655,7 +2139,7 @@ function printMemberChain(path, print, options) {
|
|
|
1655
2139
|
}
|
|
1656
2140
|
let result;
|
|
1657
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);
|
|
1658
|
-
else result = [willBreak(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent
|
|
2142
|
+
else result = [willBreak(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent : "", conditionalGroup([oneLine, expanded])];
|
|
1659
2143
|
return result;
|
|
1660
2144
|
}
|
|
1661
2145
|
function printMethodInvocation(path, print) {
|
|
@@ -1705,14 +2189,14 @@ function printBinaryExpressions(path, print, options, isInsideParentheses) {
|
|
|
1705
2189
|
const operatorDoc = path.call(print, "operatorNode");
|
|
1706
2190
|
const rightContent = path.call(print, "rightNode");
|
|
1707
2191
|
let right = options.experimentalOperatorPosition === "start" ? [
|
|
1708
|
-
line$
|
|
2192
|
+
line$3,
|
|
1709
2193
|
operatorDoc,
|
|
1710
2194
|
" ",
|
|
1711
2195
|
rightContent
|
|
1712
2196
|
] : [
|
|
1713
2197
|
" ",
|
|
1714
2198
|
operatorDoc,
|
|
1715
|
-
line$
|
|
2199
|
+
line$3,
|
|
1716
2200
|
rightContent
|
|
1717
2201
|
];
|
|
1718
2202
|
const { parent } = path;
|
|
@@ -1722,6 +2206,18 @@ function printBinaryExpressions(path, print, options, isInsideParentheses) {
|
|
|
1722
2206
|
return parts;
|
|
1723
2207
|
}
|
|
1724
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
|
+
]);
|
|
1725
2221
|
function isSimpleCallArgument(node, depth = 2) {
|
|
1726
2222
|
if (depth <= 0) return false;
|
|
1727
2223
|
const isChildSimple = (child) => isSimpleCallArgument(child, depth - 1);
|
|
@@ -1736,7 +2232,10 @@ function isSimpleCallArgument(node, depth = 2) {
|
|
|
1736
2232
|
if (node.type === "array_access") return isSimpleCallArgument(node.arrayNode, depth) && isSimpleCallArgument(node.indexNode, depth);
|
|
1737
2233
|
if (node.type === "field_access") return isSimpleCallArgument(node.objectNode, depth) && isSimpleCallArgument(node.fieldNode, depth);
|
|
1738
2234
|
if (node.type === "unary_expression") return isSimpleCallArgument(node.operandNode, depth);
|
|
1739
|
-
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
|
+
}
|
|
1740
2239
|
return false;
|
|
1741
2240
|
}
|
|
1742
2241
|
function isLiteral(node) {
|
|
@@ -1753,13 +2252,11 @@ function isLiteral(node) {
|
|
|
1753
2252
|
"character_literal"
|
|
1754
2253
|
].includes(node.type) || isStringLiteral(node);
|
|
1755
2254
|
}
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
].includes(node.type);
|
|
1762
|
-
}
|
|
2255
|
+
const isSingleWordType = createTypeCheckFunction([
|
|
2256
|
+
"identifier",
|
|
2257
|
+
"this",
|
|
2258
|
+
"super"
|
|
2259
|
+
]);
|
|
1763
2260
|
function couldExpandArg(arg, lambdaChainRecursion = false) {
|
|
1764
2261
|
if (arg.type === "array_creation_expression" && arg.valueNode && (arg.valueNode.namedChildren.length > 0 || arg.valueNode.comments)) return true;
|
|
1765
2262
|
if (arg.type === "lambda_expression") {
|
|
@@ -1773,10 +2270,10 @@ function couldExpandArg(arg, lambdaChainRecursion = false) {
|
|
|
1773
2270
|
}
|
|
1774
2271
|
return false;
|
|
1775
2272
|
}
|
|
1776
|
-
function shouldExpandLastArg(args) {
|
|
2273
|
+
function shouldExpandLastArg(args, options) {
|
|
1777
2274
|
const lastArg = args.at(-1);
|
|
1778
2275
|
const penultimateArg = args.at(-2);
|
|
1779
|
-
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));
|
|
1780
2277
|
}
|
|
1781
2278
|
function shouldExpandFirstArg(args) {
|
|
1782
2279
|
if (args.length !== 2) return false;
|
|
@@ -1842,9 +2339,8 @@ var ArgExpansionBailout = class extends Error {
|
|
|
1842
2339
|
this.name = "ArgExpansionBailout";
|
|
1843
2340
|
}
|
|
1844
2341
|
};
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
const { group: group$3, hardline: hardline$3, indent: indent$3, join: join$3, line: line$3 } = prettier_doc.builders;
|
|
2342
|
+
// src/printers/interfaces.ts
|
|
2343
|
+
const { group: group$3, hardline: hardline$2, indent: indent$3, join: join$3, line: line$2 } = prettier_doc.builders;
|
|
1848
2344
|
var interfaces_default = {
|
|
1849
2345
|
interface_declaration(path, print, options) {
|
|
1850
2346
|
const parts = ["interface ", path.call(print, "nameNode")];
|
|
@@ -1858,10 +2354,10 @@ var interfaces_default = {
|
|
|
1858
2354
|
}
|
|
1859
2355
|
if (hasExtendsInterfaces || hasPermits) {
|
|
1860
2356
|
const clauses = [];
|
|
1861
|
-
if (hasExtendsInterfaces) clauses.push(hardline$
|
|
1862
|
-
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"));
|
|
1863
2359
|
const hasBody = path.node.bodyNode.namedChildren.length > 0;
|
|
1864
|
-
const clauseGroup = [indent$3(clauses), options?.braceStyle === "next-line" ? "" : hasBody ? line$
|
|
2360
|
+
const clauseGroup = [indent$3(clauses), options?.braceStyle === "next-line" ? "" : hasBody ? line$2 : " "];
|
|
1865
2361
|
parts.push(hasMultipleClauses ? clauseGroup : group$3(clauseGroup));
|
|
1866
2362
|
} else parts.push(" ");
|
|
1867
2363
|
return [
|
|
@@ -1872,7 +2368,7 @@ var interfaces_default = {
|
|
|
1872
2368
|
},
|
|
1873
2369
|
extends_interfaces(path, print) {
|
|
1874
2370
|
const typeListIndex = path.node.namedChildren.findIndex(({ type }) => type === "type_list");
|
|
1875
|
-
return group$3(["extends", indent$3([line$
|
|
2371
|
+
return group$3(["extends", indent$3([line$2, path.call(print, "namedChildren", typeListIndex)])]);
|
|
1876
2372
|
},
|
|
1877
2373
|
interface_body(path, print, options) {
|
|
1878
2374
|
return printBlock(path, printBodyDeclarations(path, print), options);
|
|
@@ -1910,7 +2406,7 @@ var interfaces_default = {
|
|
|
1910
2406
|
"(",
|
|
1911
2407
|
args[0],
|
|
1912
2408
|
")"
|
|
1913
|
-
] : group$3(indentInParentheses(join$3([",", line$
|
|
2409
|
+
] : group$3(indentInParentheses(join$3([",", line$2], args), options));
|
|
1914
2410
|
},
|
|
1915
2411
|
element_value_pair(path, print) {
|
|
1916
2412
|
return group$3([
|
|
@@ -1921,13 +2417,12 @@ var interfaces_default = {
|
|
|
1921
2417
|
},
|
|
1922
2418
|
element_value_array_initializer: printArrayInitializer
|
|
1923
2419
|
};
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
const { group: group$2, hardline: hardline$2, indent: indent$2, join: join$2, softline } = prettier_doc.builders;
|
|
2420
|
+
// src/printers/lexical-structure.ts
|
|
2421
|
+
const { group: group$2, hardline: hardline$1, indent: indent$2, join: join$2, softline } = prettier_doc.builders;
|
|
1927
2422
|
var lexical_structure_default = {
|
|
1928
2423
|
string_literal(path, print) {
|
|
1929
2424
|
if (path.node.namedChildren.some(({ type }) => type === "string_interpolation") || path.node.children[0].value === "\"") return path.map(print, "children");
|
|
1930
|
-
return printTextBlock(join$2(hardline$
|
|
2425
|
+
return printTextBlock(join$2(hardline$1, textBlockContents(path.node).split("\n")));
|
|
1931
2426
|
},
|
|
1932
2427
|
string_fragment: printValue,
|
|
1933
2428
|
multiline_string_fragment: printValue,
|
|
@@ -1961,8 +2456,7 @@ var lexical_structure_default = {
|
|
|
1961
2456
|
underscore_pattern: printValue,
|
|
1962
2457
|
asterisk: printValue
|
|
1963
2458
|
};
|
|
1964
|
-
|
|
1965
|
-
//#region src/printers/names.ts
|
|
2459
|
+
// src/printers/names.ts
|
|
1966
2460
|
var names_default = {
|
|
1967
2461
|
identifier: printValue,
|
|
1968
2462
|
type_identifier: printValue,
|
|
@@ -1977,12 +2471,11 @@ var names_default = {
|
|
|
1977
2471
|
return path.map((child) => child.node.type === "annotation" || child.node.type === "marker_annotation" ? [print(child), " "] : print(child), "children");
|
|
1978
2472
|
}
|
|
1979
2473
|
};
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
const { group: group$1, hardline: hardline$1, indent: indent$1, join: join$1, line: line$2 } = prettier_doc.builders;
|
|
2474
|
+
// src/printers/packages-and-modules.ts
|
|
2475
|
+
const { group: group$1, hardline, indent: indent$1, join: join$1, line: line$1 } = prettier_doc.builders;
|
|
1983
2476
|
var packages_and_modules_default = {
|
|
1984
2477
|
program(path, print, options) {
|
|
1985
|
-
if (!path.node.namedChildren.length) return [printDanglingComments(path), hardline
|
|
2478
|
+
if (!path.node.namedChildren.length) return [printDanglingComments(path), hardline];
|
|
1986
2479
|
const parts = [];
|
|
1987
2480
|
if (path.node.namedChildren[0].type !== "import_declaration") parts.push(path.call(print, "namedChildren", 0));
|
|
1988
2481
|
const moduleImports = [];
|
|
@@ -2001,8 +2494,8 @@ var packages_and_modules_default = {
|
|
|
2001
2494
|
});
|
|
2002
2495
|
} else if (!child.isFirst) otherDeclarations.push(doc);
|
|
2003
2496
|
}, "namedChildren");
|
|
2004
|
-
parts.push(...[moduleImports.sort(compareFqn), ...groupImports(imports, options.importOrder)].filter((group) => group.length).map((group) => join$1(hardline
|
|
2005
|
-
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];
|
|
2006
2499
|
},
|
|
2007
2500
|
package_declaration(path, print) {
|
|
2008
2501
|
const annotations = [];
|
|
@@ -2017,7 +2510,7 @@ var packages_and_modules_default = {
|
|
|
2017
2510
|
case "scoped_identifier": identifier.push(print(child));
|
|
2018
2511
|
}
|
|
2019
2512
|
}, "namedChildren");
|
|
2020
|
-
return join$1(hardline
|
|
2513
|
+
return join$1(hardline, [...annotations, [
|
|
2021
2514
|
"package ",
|
|
2022
2515
|
...identifier,
|
|
2023
2516
|
";"
|
|
@@ -2043,7 +2536,7 @@ var packages_and_modules_default = {
|
|
|
2043
2536
|
return join$1(" ", parts);
|
|
2044
2537
|
},
|
|
2045
2538
|
module_body(path, print, options) {
|
|
2046
|
-
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);
|
|
2047
2540
|
},
|
|
2048
2541
|
requires_module_directive(path, print) {
|
|
2049
2542
|
const parts = ["requires"];
|
|
@@ -2067,585 +2560,185 @@ var packages_and_modules_default = {
|
|
|
2067
2560
|
return [
|
|
2068
2561
|
"provides ",
|
|
2069
2562
|
provided,
|
|
2070
|
-
group$1(indent$1([line$
|
|
2563
|
+
group$1(indent$1([line$1, group$1(indent$1([
|
|
2071
2564
|
"with",
|
|
2072
|
-
line$
|
|
2073
|
-
...join$1([",", line$
|
|
2565
|
+
line$1,
|
|
2566
|
+
...join$1([",", line$1], providers)
|
|
2074
2567
|
]))])),
|
|
2075
2568
|
";"
|
|
2076
|
-
];
|
|
2077
|
-
},
|
|
2078
|
-
requires_modifier: printValue
|
|
2079
|
-
};
|
|
2080
|
-
function extractNames(node) {
|
|
2081
|
-
return node.type === "identifier" ? [node.value] : [...extractNames(node.scopeNode), node.nameNode.value];
|
|
2082
|
-
}
|
|
2083
|
-
const STATIC_PREFIX = "static ";
|
|
2084
|
-
const CATCH_ALL_PREFIX = "";
|
|
2085
|
-
function groupImports(imports, importOrder) {
|
|
2086
|
-
if (!importOrder) return [imports.filter(({ isStatic }) => isStatic), imports.filter(({ isStatic }) => !isStatic)].filter((group) => group.length).map((group) => group.sort(compareFqn));
|
|
2087
|
-
const groups = parseImportOrder(importOrder);
|
|
2088
|
-
const prefixes = groups.flat();
|
|
2089
|
-
const importsByPrefix = /* @__PURE__ */ new Map();
|
|
2090
|
-
for (const entry of imports) {
|
|
2091
|
-
const key = importKey(entry);
|
|
2092
|
-
const prefix = prefixes.filter((candidate) => key.startsWith(candidate)).reduce((best, candidate) => candidate.length > best.length ? candidate : best);
|
|
2093
|
-
importsByPrefix.set(prefix, [...importsByPrefix.get(prefix) ?? [], {
|
|
2094
|
-
key,
|
|
2095
|
-
entry
|
|
2096
|
-
}]);
|
|
2097
|
-
}
|
|
2098
|
-
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);
|
|
2099
|
-
}
|
|
2100
|
-
/**
|
|
2101
|
-
* Parses an import order in Spotless's format: groups separated by `,` are
|
|
2102
|
-
* printed with blank lines between them, prefixes joined by `|` share a group,
|
|
2103
|
-
* `#` marks a static prefix, and an empty prefix catches everything else.
|
|
2104
|
-
* Each import belongs to its longest matching prefix.
|
|
2105
|
-
*/
|
|
2106
|
-
function parseImportOrder(importOrder) {
|
|
2107
|
-
const knownPrefixes = /* @__PURE__ */ new Set();
|
|
2108
|
-
const groups = importOrder.split(",").map((group) => group.split("|").map((prefix) => prefix.startsWith("#") ? STATIC_PREFIX + prefix.slice(1) : prefix).filter((prefix) => {
|
|
2109
|
-
if (knownPrefixes.has(prefix)) return false;
|
|
2110
|
-
knownPrefixes.add(prefix);
|
|
2111
|
-
return true;
|
|
2112
|
-
}));
|
|
2113
|
-
if (!knownPrefixes.has(STATIC_PREFIX)) {
|
|
2114
|
-
const lastStaticGroupIndex = groups.findLastIndex((group) => group.some((prefix) => prefix.startsWith(STATIC_PREFIX)));
|
|
2115
|
-
groups.splice(Math.max(lastStaticGroupIndex, 0), 0, [STATIC_PREFIX]);
|
|
2116
|
-
}
|
|
2117
|
-
if (!knownPrefixes.has(CATCH_ALL_PREFIX)) groups.push([CATCH_ALL_PREFIX]);
|
|
2118
|
-
return groups;
|
|
2119
|
-
}
|
|
2120
|
-
function importKey({ names, isStatic }) {
|
|
2121
|
-
return (isStatic ? STATIC_PREFIX : "") + names.join(".");
|
|
2122
|
-
}
|
|
2123
|
-
function compareFqn({ names: a }, { names: b }) {
|
|
2124
|
-
const minParts = Math.min(a.length, b.length);
|
|
2125
|
-
for (let i = 0; i < minParts; i++) {
|
|
2126
|
-
const imageA = a[i];
|
|
2127
|
-
const imageB = b[i];
|
|
2128
|
-
if (imageA < imageB) return -1;
|
|
2129
|
-
else if (imageA > imageB) return 1;
|
|
2130
|
-
}
|
|
2131
|
-
return a.length - b.length;
|
|
2132
|
-
}
|
|
2133
|
-
function printToModuleNamesDirective(path, print) {
|
|
2134
|
-
const directive = [
|
|
2135
|
-
path.node.type === "exports_module_directive" ? "exports" : "opens",
|
|
2136
|
-
" ",
|
|
2137
|
-
path.call(print, "packageNode")
|
|
2138
|
-
];
|
|
2139
|
-
if (path.node.modulesNodes.length) {
|
|
2140
|
-
const moduleNames = join$1([",", line$2], path.map(print, "modulesNodes"));
|
|
2141
|
-
directive.push(group$1(indent$1([line$2, group$1(indent$1([
|
|
2142
|
-
"to",
|
|
2143
|
-
line$2,
|
|
2144
|
-
...moduleNames
|
|
2145
|
-
]))])));
|
|
2146
|
-
}
|
|
2147
|
-
directive.push(";");
|
|
2148
|
-
return directive;
|
|
2149
|
-
}
|
|
2150
|
-
//#endregion
|
|
2151
|
-
//#region src/printers/types-values-and-variables.ts
|
|
2152
|
-
const { group, indent, join, line: line$1 } = prettier_doc.builders;
|
|
2153
|
-
var types_values_and_variables_default = {
|
|
2154
|
-
boolean_type: printValue,
|
|
2155
|
-
integral_type: printValue,
|
|
2156
|
-
floating_point_type: printValue,
|
|
2157
|
-
void_type: printValue,
|
|
2158
|
-
array_type(path, print) {
|
|
2159
|
-
return [path.call(print, "elementNode"), path.call(print, "dimensionsNode")];
|
|
2160
|
-
},
|
|
2161
|
-
annotated_type(path, print) {
|
|
2162
|
-
return join(" ", path.map(print, "children"));
|
|
2163
|
-
},
|
|
2164
|
-
dimensions(path, print) {
|
|
2165
|
-
return path.map((child) => {
|
|
2166
|
-
if (child.node.isNamed) return [
|
|
2167
|
-
...child.isFirst ? [" "] : [],
|
|
2168
|
-
print(child),
|
|
2169
|
-
" "
|
|
2170
|
-
];
|
|
2171
|
-
return child.node.value;
|
|
2172
|
-
}, "children");
|
|
2173
|
-
},
|
|
2174
|
-
type_parameter(path, print) {
|
|
2175
|
-
return join(" ", path.map(print, "children"));
|
|
2176
|
-
},
|
|
2177
|
-
type_bound(path, print) {
|
|
2178
|
-
const [firstType, ...restTypes] = path.map(print, "namedChildren");
|
|
2179
|
-
const bound = ["extends ", firstType];
|
|
2180
|
-
if (restTypes.length) bound.push(group(indent([
|
|
2181
|
-
line$1,
|
|
2182
|
-
"& ",
|
|
2183
|
-
...join([line$1, "& "], restTypes)
|
|
2184
|
-
])));
|
|
2185
|
-
return bound;
|
|
2186
|
-
},
|
|
2187
|
-
type_arguments: printTypeParameters,
|
|
2188
|
-
wildcard(path, print) {
|
|
2189
|
-
return join(" ", path.map(print, "children"));
|
|
2190
|
-
}
|
|
2191
|
-
};
|
|
2192
|
-
//#endregion
|
|
2193
|
-
//#region src/printers/index.ts
|
|
2194
|
-
const printersByNodeType = {
|
|
2195
|
-
ERROR(path) {
|
|
2196
|
-
throw new Error(`Failed to parse: "${printValue(path)}"`);
|
|
2197
|
-
},
|
|
2198
|
-
...arrays_default,
|
|
2199
|
-
...blocks_and_statements_default,
|
|
2200
|
-
...classes_default,
|
|
2201
|
-
...expressions_default,
|
|
2202
|
-
...interfaces_default,
|
|
2203
|
-
...lexical_structure_default,
|
|
2204
|
-
...names_default,
|
|
2205
|
-
...packages_and_modules_default,
|
|
2206
|
-
...types_values_and_variables_default
|
|
2207
|
-
};
|
|
2208
|
-
function printerForNodeType(type) {
|
|
2209
|
-
return printersByNodeType[type];
|
|
2210
|
-
}
|
|
2211
|
-
//#endregion
|
|
2212
|
-
//#region src/printer.ts
|
|
2213
|
-
var printer_default = {
|
|
2214
|
-
print(path, options, print, args) {
|
|
2215
|
-
if (!hasNamedNode(path)) return printValue(path);
|
|
2216
|
-
const doc = printerForNodeType(path.node.type)(path, print, options, args);
|
|
2217
|
-
return needsParentheses(path) ? [
|
|
2218
|
-
"(",
|
|
2219
|
-
doc,
|
|
2220
|
-
")"
|
|
2221
|
-
] : doc;
|
|
2222
|
-
},
|
|
2223
|
-
embed(path, options) {
|
|
2224
|
-
return hasType(path, "string_literal") ? embedTextBlock(path, options) : null;
|
|
2225
|
-
},
|
|
2226
|
-
hasPrettierIgnore(path) {
|
|
2227
|
-
return path.node.comments?.some(isPrettierIgnore) === true || canAttachComment(path.node, path.parent ? [path.parent] : []) && isFullyBetweenPrettierIgnore(path);
|
|
2228
|
-
},
|
|
2229
|
-
canAttachComment,
|
|
2230
|
-
isBlockComment(node) {
|
|
2231
|
-
return node.type === "block_comment";
|
|
2232
|
-
},
|
|
2233
|
-
willPrintOwnComments,
|
|
2234
|
-
printComment(commentPath) {
|
|
2235
|
-
return printComment(commentPath.node);
|
|
2236
|
-
},
|
|
2237
|
-
getCommentChildNodes(node) {
|
|
2238
|
-
return node.isNamed ? node.children : [];
|
|
2239
|
-
},
|
|
2240
|
-
handleComments: {
|
|
2241
|
-
ownLine: handleLineComment,
|
|
2242
|
-
endOfLine: handleLineComment,
|
|
2243
|
-
remaining: handleRemainingComment
|
|
2569
|
+
];
|
|
2244
2570
|
},
|
|
2245
|
-
|
|
2246
|
-
return ["namedChildren"];
|
|
2247
|
-
}
|
|
2571
|
+
requires_modifier: printValue
|
|
2248
2572
|
};
|
|
2249
|
-
function
|
|
2250
|
-
return
|
|
2251
|
-
}
|
|
2252
|
-
//#endregion
|
|
2253
|
-
//#region src/comments.ts
|
|
2254
|
-
const { hasNewline, isPreviousLineEmpty, skipNewline, skipSpaces } = prettier.util;
|
|
2255
|
-
const { breakParent, hardline, line, lineSuffix } = prettier_doc.builders;
|
|
2256
|
-
const prettierIgnoreRangesByTree = /* @__PURE__ */ new WeakMap();
|
|
2257
|
-
function determinePrettierIgnoreRanges(tree) {
|
|
2258
|
-
const { comments } = tree;
|
|
2259
|
-
if (!comments) return;
|
|
2260
|
-
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 }) => {
|
|
2261
|
-
const previous = ranges.at(-1);
|
|
2262
|
-
if (value.includes("start") || value.includes("off")) {
|
|
2263
|
-
if (previous?.end !== Infinity) ranges.push({
|
|
2264
|
-
start: start.index,
|
|
2265
|
-
end: Infinity
|
|
2266
|
-
});
|
|
2267
|
-
} else if (previous?.end === Infinity) previous.end = start.index;
|
|
2268
|
-
return ranges;
|
|
2269
|
-
}, new Array());
|
|
2270
|
-
prettierIgnoreRangesByTree.set(tree, ranges);
|
|
2271
|
-
}
|
|
2272
|
-
function isFullyBetweenPrettierIgnore(path) {
|
|
2273
|
-
const { node, root } = path;
|
|
2274
|
-
const start = parser_default.locStart(node);
|
|
2275
|
-
const end = parser_default.locEnd(node);
|
|
2276
|
-
return prettierIgnoreRangesByTree.get(root)?.some((range) => range.start < start && end < range.end) === true;
|
|
2277
|
-
}
|
|
2278
|
-
function isPrettierIgnore(comment) {
|
|
2279
|
-
return /^(\/\/\s*prettier-ignore|\/\*\s*prettier-ignore\s*\*\/)$/.test(comment.value);
|
|
2280
|
-
}
|
|
2281
|
-
function willPrintOwnComments(path) {
|
|
2282
|
-
return isMember(path.node) && !printer_default.hasPrettierIgnore(path);
|
|
2283
|
-
}
|
|
2284
|
-
function canAttachComment(node, ancestors) {
|
|
2285
|
-
if (!node.isNamed) return isBinaryOperator(node);
|
|
2286
|
-
switch (node.type) {
|
|
2287
|
-
case "enum_body_declarations":
|
|
2288
|
-
case "escape_sequence":
|
|
2289
|
-
case "modifier":
|
|
2290
|
-
case "multiline_string_fragment":
|
|
2291
|
-
case "program":
|
|
2292
|
-
case "string_fragment":
|
|
2293
|
-
case "visibility": return false;
|
|
2294
|
-
case "parenthesized_expression": {
|
|
2295
|
-
const [parent] = ancestors;
|
|
2296
|
-
return !(parent.isNamed && [
|
|
2297
|
-
"do_statement",
|
|
2298
|
-
"if_statement",
|
|
2299
|
-
"switch_expression",
|
|
2300
|
-
"synchronized_statement",
|
|
2301
|
-
"try_statement",
|
|
2302
|
-
"try_with_resources_statement",
|
|
2303
|
-
"while_statement"
|
|
2304
|
-
].includes(parent.type));
|
|
2305
|
-
}
|
|
2306
|
-
default: return true;
|
|
2307
|
-
}
|
|
2308
|
-
}
|
|
2309
|
-
function handleLineComment(commentNode, _, options) {
|
|
2310
|
-
return [
|
|
2311
|
-
handleBinaryExpressionComments,
|
|
2312
|
-
handleFormalParametersComments,
|
|
2313
|
-
handleFqnOrRefTypeComments,
|
|
2314
|
-
handleIfStatementComments,
|
|
2315
|
-
handleJumpStatementComments,
|
|
2316
|
-
handleLabeledStatementComments,
|
|
2317
|
-
handleLambdaExpressionComments,
|
|
2318
|
-
handleMemberChainComments,
|
|
2319
|
-
handleModifiersComments,
|
|
2320
|
-
handleNameComments,
|
|
2321
|
-
handleTernaryExpressionComments,
|
|
2322
|
-
handleTryStatementComments
|
|
2323
|
-
].some((fn) => fn(commentNode, options));
|
|
2324
|
-
}
|
|
2325
|
-
function handleRemainingComment(commentNode) {
|
|
2326
|
-
return [
|
|
2327
|
-
handleFqnOrRefTypeComments,
|
|
2328
|
-
handleNameComments,
|
|
2329
|
-
handleJumpStatementComments
|
|
2330
|
-
].some((fn) => fn(commentNode));
|
|
2331
|
-
}
|
|
2332
|
-
function handleBinaryExpressionComments(commentNode, options) {
|
|
2333
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
2334
|
-
if (enclosingNode?.type === "binary_expression") {
|
|
2335
|
-
if (isBinaryOperator(followingNode)) {
|
|
2336
|
-
if (options.experimentalOperatorPosition === "start") prettier.util.addLeadingComment(followingNode, commentNode);
|
|
2337
|
-
else prettier.util.addTrailingComment(followingNode, commentNode);
|
|
2338
|
-
return true;
|
|
2339
|
-
} else if (options.experimentalOperatorPosition === "start" && isBinaryOperator(precedingNode)) {
|
|
2340
|
-
prettier.util.addLeadingComment(precedingNode, commentNode);
|
|
2341
|
-
return true;
|
|
2342
|
-
}
|
|
2343
|
-
}
|
|
2344
|
-
return false;
|
|
2345
|
-
}
|
|
2346
|
-
function handleFormalParametersComments(commentNode) {
|
|
2347
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
2348
|
-
if (enclosingNode?.type === "formal_parameters" && !precedingNode && !followingNode) {
|
|
2349
|
-
prettier.util.addDanglingComment(enclosingNode, commentNode, void 0);
|
|
2350
|
-
return true;
|
|
2351
|
-
}
|
|
2352
|
-
return false;
|
|
2353
|
-
}
|
|
2354
|
-
function handleFqnOrRefTypeComments(commentNode) {
|
|
2355
|
-
const { enclosingNode, followingNode } = commentNode;
|
|
2356
|
-
if (enclosingNode?.type === "scoped_type_identifier" && followingNode) {
|
|
2357
|
-
prettier.util.addLeadingComment(followingNode, commentNode);
|
|
2358
|
-
return true;
|
|
2359
|
-
}
|
|
2360
|
-
return false;
|
|
2361
|
-
}
|
|
2362
|
-
function handleIfStatementComments(commentNode) {
|
|
2363
|
-
const { enclosingNode, precedingNode } = commentNode;
|
|
2364
|
-
if (enclosingNode?.type === "if_statement" && precedingNode?.fieldName === "consequence") {
|
|
2365
|
-
prettier.util.addDanglingComment(enclosingNode, commentNode, void 0);
|
|
2366
|
-
return true;
|
|
2367
|
-
}
|
|
2368
|
-
return false;
|
|
2369
|
-
}
|
|
2370
|
-
function handleJumpStatementComments(commentNode) {
|
|
2371
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
2372
|
-
if (enclosingNode && !precedingNode && !followingNode && (enclosingNode.type === "break_statement" || enclosingNode.type === "continue_statement" || enclosingNode.type === "return_statement")) {
|
|
2373
|
-
prettier.util.addTrailingComment(enclosingNode, commentNode);
|
|
2374
|
-
return true;
|
|
2375
|
-
}
|
|
2376
|
-
return false;
|
|
2377
|
-
}
|
|
2378
|
-
function handleLabeledStatementComments(commentNode) {
|
|
2379
|
-
const { enclosingNode, precedingNode } = commentNode;
|
|
2380
|
-
if (enclosingNode?.type === "labeled_statement" && precedingNode?.type === "identifier") {
|
|
2381
|
-
prettier.util.addLeadingComment(precedingNode, commentNode);
|
|
2382
|
-
return true;
|
|
2383
|
-
}
|
|
2384
|
-
return false;
|
|
2385
|
-
}
|
|
2386
|
-
function handleLambdaExpressionComments(commentNode) {
|
|
2387
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
2388
|
-
if (enclosingNode?.type === "lambda_expression" && precedingNode && followingNode && enclosingNode.children.find(({ type }) => type === "->").end.index < commentNode.start.index) {
|
|
2389
|
-
if (followingNode.type === "block") {
|
|
2390
|
-
if (followingNode.namedChildren.length) prettier.util.addLeadingComment(followingNode.namedChildren[0], commentNode);
|
|
2391
|
-
else prettier.util.addDanglingComment(followingNode, commentNode, void 0);
|
|
2392
|
-
} else prettier.util.addLeadingComment(followingNode, commentNode);
|
|
2393
|
-
return true;
|
|
2394
|
-
}
|
|
2395
|
-
}
|
|
2396
|
-
function handleMemberChainComments(commentNode) {
|
|
2397
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
2398
|
-
if (precedingNode && (enclosingNode?.type === "field_access" || enclosingNode?.type === "method_invocation" && precedingNode.end.row < commentNode.start.row) && precedingNode === enclosingNode.objectNode) {
|
|
2399
|
-
prettier.util.addLeadingComment(enclosingNode, commentNode);
|
|
2400
|
-
return true;
|
|
2401
|
-
} else if (isMember(followingNode) && (!precedingNode || precedingNode !== getMemberObject(followingNode) && precedingNode.end.row < commentNode.start.row) && !isPrettierIgnore(commentNode)) {
|
|
2402
|
-
prettier.util.addDanglingComment(followingNode, commentNode, void 0);
|
|
2403
|
-
return true;
|
|
2404
|
-
}
|
|
2405
|
-
return false;
|
|
2406
|
-
}
|
|
2407
|
-
function handleModifiersComments(commentNode) {
|
|
2408
|
-
const { precedingNode } = commentNode;
|
|
2409
|
-
if (precedingNode?.type === "annotation" || precedingNode?.type === "marker_annotation" || precedingNode?.type === "modifiers") {
|
|
2410
|
-
prettier.util.addTrailingComment(precedingNode, commentNode);
|
|
2411
|
-
return true;
|
|
2412
|
-
}
|
|
2413
|
-
return false;
|
|
2414
|
-
}
|
|
2415
|
-
function handleNameComments(commentNode) {
|
|
2416
|
-
const { enclosingNode, precedingNode } = commentNode;
|
|
2417
|
-
if (enclosingNode && precedingNode?.type === "identifier" && (enclosingNode.type === "scoped_identifier" || enclosingNode.type === "module_declaration" || enclosingNode.type === "package_declaration" || enclosingNode.type === "scoped_type_identifier")) {
|
|
2418
|
-
prettier.util.addTrailingComment(precedingNode, commentNode);
|
|
2419
|
-
return true;
|
|
2420
|
-
}
|
|
2421
|
-
return false;
|
|
2422
|
-
}
|
|
2423
|
-
function handleTernaryExpressionComments(commentNode) {
|
|
2424
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
2425
|
-
if (enclosingNode?.type === "ternary_expression" && precedingNode?.isNamed && followingNode?.isNamed && precedingNode.end.row < commentNode.start.row && commentNode.end.row < followingNode.start.row) {
|
|
2426
|
-
prettier.util.addLeadingComment(followingNode, commentNode);
|
|
2427
|
-
return true;
|
|
2428
|
-
}
|
|
2429
|
-
return false;
|
|
2573
|
+
function extractNames(node) {
|
|
2574
|
+
return node.type === "identifier" ? [node.value] : [...extractNames(node.scopeNode), node.nameNode.value];
|
|
2430
2575
|
}
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
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
|
+
}]);
|
|
2440
2590
|
}
|
|
2441
|
-
return
|
|
2442
|
-
}
|
|
2443
|
-
function getMemberObject(node) {
|
|
2444
|
-
return node.type === "array_access" ? node.arrayNode : node.objectNode;
|
|
2445
|
-
}
|
|
2446
|
-
const binaryOperators = /* @__PURE__ */ new Set([
|
|
2447
|
-
"<<",
|
|
2448
|
-
">>",
|
|
2449
|
-
">>>",
|
|
2450
|
-
"instanceof",
|
|
2451
|
-
"<=",
|
|
2452
|
-
">=",
|
|
2453
|
-
"==",
|
|
2454
|
-
"-",
|
|
2455
|
-
"+",
|
|
2456
|
-
"&&",
|
|
2457
|
-
"&",
|
|
2458
|
-
"^",
|
|
2459
|
-
"!=",
|
|
2460
|
-
"||",
|
|
2461
|
-
"|",
|
|
2462
|
-
"*",
|
|
2463
|
-
"/",
|
|
2464
|
-
"%"
|
|
2465
|
-
]);
|
|
2466
|
-
function isBinaryOperator(node) {
|
|
2467
|
-
return node !== void 0 && binaryOperators.has(node.type);
|
|
2468
|
-
}
|
|
2469
|
-
function printLeadingComment(path) {
|
|
2470
|
-
const comment = path.node;
|
|
2471
|
-
const parts = [printComment(comment)];
|
|
2472
|
-
const originalText = path.root.value;
|
|
2473
|
-
if (comment.type === "block_comment") {
|
|
2474
|
-
let lineBreak = " ";
|
|
2475
|
-
if (hasNewline(originalText, parser_default.locEnd(comment))) {
|
|
2476
|
-
if (hasNewline(originalText, parser_default.locStart(comment), { backwards: true })) lineBreak = hardline;
|
|
2477
|
-
else lineBreak = line;
|
|
2478
|
-
}
|
|
2479
|
-
parts.push(lineBreak);
|
|
2480
|
-
} else parts.push(hardline);
|
|
2481
|
-
const index = skipNewline(originalText, skipSpaces(originalText, parser_default.locEnd(comment)));
|
|
2482
|
-
if (index !== false && hasNewline(originalText, index)) parts.push(hardline);
|
|
2483
|
-
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);
|
|
2484
2592
|
}
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
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]);
|
|
2501
2609
|
}
|
|
2502
|
-
if (!
|
|
2503
|
-
|
|
2504
|
-
isBlock,
|
|
2505
|
-
hasLineSuffix: true
|
|
2506
|
-
};
|
|
2507
|
-
return {
|
|
2508
|
-
doc: [" ", printed],
|
|
2509
|
-
isBlock,
|
|
2510
|
-
hasLineSuffix: false
|
|
2511
|
-
};
|
|
2610
|
+
if (!knownPrefixes.has(CATCH_ALL_PREFIX)) groups.push([CATCH_ALL_PREFIX]);
|
|
2611
|
+
return groups;
|
|
2512
2612
|
}
|
|
2513
|
-
function
|
|
2514
|
-
|
|
2515
|
-
const docs = [];
|
|
2516
|
-
path.each((path) => {
|
|
2517
|
-
const { node: comment } = path;
|
|
2518
|
-
if (!comment.leading) return;
|
|
2519
|
-
docs.push(printLeadingComment(path));
|
|
2520
|
-
}, "comments");
|
|
2521
|
-
return docs;
|
|
2613
|
+
function importKey({ names, isStatic }) {
|
|
2614
|
+
return (isStatic ? STATIC_PREFIX : "") + names.join(".");
|
|
2522
2615
|
}
|
|
2523
|
-
function
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
if (
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
}, "comments");
|
|
2533
|
-
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;
|
|
2534
2625
|
}
|
|
2535
|
-
function
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
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;
|
|
2540
2642
|
}
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2643
|
+
// src/printers/types-values-and-variables.ts
|
|
2644
|
+
const { group, indent, join, line } = prettier_doc.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];
|
|
2549
2701
|
}
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
const
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
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;
|
|
2561
2712
|
},
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
return /^\/\*\*\n\s+\*\s@(format|prettier)\n\s+\*\//.test(text);
|
|
2713
|
+
embed(path, options) {
|
|
2714
|
+
return hasType(path, "string_literal") ? embedTextBlock(path, options) : null;
|
|
2565
2715
|
},
|
|
2566
|
-
|
|
2567
|
-
return node.
|
|
2716
|
+
hasPrettierIgnore(path) {
|
|
2717
|
+
return path.node.comments?.some(isPrettierIgnore) === true || canAttachComment(path.node, path.parent ? [path.parent] : []) && isFullyBetweenPrettierIgnore(path);
|
|
2568
2718
|
},
|
|
2569
|
-
|
|
2570
|
-
|
|
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"];
|
|
2571
2736
|
}
|
|
2572
2737
|
};
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
const parser = new web_tree_sitter.Parser();
|
|
2576
|
-
const Java = await web_tree_sitter.Language.load(new URL("./tree-sitter-java_orchard.wasm", require("url").pathToFileURL(__filename).href));
|
|
2577
|
-
parser.setLanguage(Java);
|
|
2578
|
-
return parser;
|
|
2579
|
-
})();
|
|
2580
|
-
const isParenthesizedParent = createTypeCheckFunction([
|
|
2581
|
-
"do_statement",
|
|
2582
|
-
"if_statement",
|
|
2583
|
-
"switch_expression",
|
|
2584
|
-
"synchronized_statement",
|
|
2585
|
-
"try_statement",
|
|
2586
|
-
"try_with_resources_statement",
|
|
2587
|
-
"while_statement"
|
|
2588
|
-
]);
|
|
2589
|
-
function processTree(node, fieldName = null, comments) {
|
|
2590
|
-
const { type, isNamed, text: value, startPosition, endPosition } = node;
|
|
2591
|
-
const javaNode = {
|
|
2592
|
-
type,
|
|
2593
|
-
isNamed,
|
|
2594
|
-
value,
|
|
2595
|
-
start: {
|
|
2596
|
-
index: node.startIndex,
|
|
2597
|
-
row: startPosition.row,
|
|
2598
|
-
column: startPosition.column
|
|
2599
|
-
},
|
|
2600
|
-
end: {
|
|
2601
|
-
index: node.endIndex,
|
|
2602
|
-
row: endPosition.row,
|
|
2603
|
-
column: endPosition.column
|
|
2604
|
-
},
|
|
2605
|
-
children: [],
|
|
2606
|
-
namedChildren: [],
|
|
2607
|
-
fieldName
|
|
2608
|
-
};
|
|
2609
|
-
if (!comments) comments = javaNode.comments = [];
|
|
2610
|
-
if (!javaNode.isNamed) return javaNode;
|
|
2611
|
-
const multiFields = multiFieldsByType[node.type];
|
|
2612
|
-
if (multiFields) Object.keys(multiFields).forEach((name) => javaNode[`${name}Nodes`] = []);
|
|
2613
|
-
node.children.forEach((child, index) => {
|
|
2614
|
-
const fieldName = node.fieldNameForChild(index);
|
|
2615
|
-
(child.type === "parenthesized_expression" && !isParenthesizedParent(javaNode) ? child.namedChildren : [child]).forEach((child) => {
|
|
2616
|
-
const { type, text: value, startPosition, endPosition } = child;
|
|
2617
|
-
if (type === "block_comment" || type === "line_comment") comments.push({
|
|
2618
|
-
type,
|
|
2619
|
-
value,
|
|
2620
|
-
start: {
|
|
2621
|
-
index: child.startIndex,
|
|
2622
|
-
row: startPosition.row,
|
|
2623
|
-
column: startPosition.column
|
|
2624
|
-
},
|
|
2625
|
-
end: {
|
|
2626
|
-
index: child.endIndex,
|
|
2627
|
-
row: endPosition.row,
|
|
2628
|
-
column: endPosition.column
|
|
2629
|
-
},
|
|
2630
|
-
leading: false,
|
|
2631
|
-
trailing: false,
|
|
2632
|
-
printed: false
|
|
2633
|
-
});
|
|
2634
|
-
else {
|
|
2635
|
-
const javaChild = processTree(child, fieldName, comments);
|
|
2636
|
-
javaNode.children.push(javaChild);
|
|
2637
|
-
if (javaChild.isNamed) javaNode.namedChildren.push(javaChild);
|
|
2638
|
-
if (fieldName) {
|
|
2639
|
-
if (multiFields?.[fieldName]) javaNode[`${fieldName}Nodes`].push(javaChild);
|
|
2640
|
-
else javaNode[`${fieldName}Node`] = javaChild;
|
|
2641
|
-
}
|
|
2642
|
-
}
|
|
2643
|
-
});
|
|
2644
|
-
});
|
|
2645
|
-
return javaNode;
|
|
2738
|
+
function hasNamedNode(path) {
|
|
2739
|
+
return path.node.isNamed;
|
|
2646
2740
|
}
|
|
2647
|
-
|
|
2648
|
-
//#region src/index.ts
|
|
2741
|
+
// src/index.ts
|
|
2649
2742
|
var src_default = {
|
|
2650
2743
|
languages: [{
|
|
2651
2744
|
name: "Java",
|
|
@@ -2664,5 +2757,4 @@ var src_default = {
|
|
|
2664
2757
|
options: options_default,
|
|
2665
2758
|
defaultOptions: { arrowParens: "avoid" }
|
|
2666
2759
|
};
|
|
2667
|
-
//#endregion
|
|
2668
2760
|
module.exports = src_default;
|