prettier-plugin-java 2.5.0 → 2.6.0

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.
@@ -1,42 +1,16 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
- if (ar || !(i in from)) {
16
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
- ar[i] = from[i];
18
- }
19
- }
20
- return to.concat(ar || Array.prototype.slice.call(from));
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.printArrayList = exports.isUniqueMethodInvocation = exports.sortImports = exports.isStatementEmptyStatement = exports.binary = exports.putIntoBraces = exports.getInterfaceBodyDeclarationsSeparator = exports.getClassBodyDeclarationsSeparator = exports.getBlankLinesSeparator = exports.isExplicitLambdaParameter = exports.displaySemicolon = exports.findDeepElementInPartsArray = exports.sortModifiers = exports.sortClassTypeChildren = exports.matchCategory = exports.sortNodes = exports.sortTokens = exports.sortAnnotationIdentifier = exports.rejectAndConcat = exports.rejectAndJoin = exports.rejectSeparators = exports.reject = exports.rejectAndJoinSeps = exports.buildFqn = void 0;
27
- var findIndex_1 = __importDefault(require("lodash/findIndex"));
28
- var findLastIndex_1 = __importDefault(require("lodash/findLastIndex"));
29
- var forEach_1 = __importDefault(require("lodash/forEach"));
30
- var forEachRight_1 = __importDefault(require("lodash/forEachRight"));
31
- var includes_1 = __importDefault(require("lodash/includes"));
32
- var doc_1 = require("prettier/doc");
33
- var utils_1 = require("../types/utils");
34
- var utils_2 = require("../utils");
35
- var comments_utils_1 = require("./comments/comments-utils");
36
- var format_comments_1 = require("./comments/format-comments");
37
- var prettier_builder_1 = require("./prettier-builder");
38
- var indent = doc_1.builders.indent, hardline = doc_1.builders.hardline, line = doc_1.builders.line;
39
- var orderedModifiers = [
1
+ import findIndex from "lodash/findIndex.js";
2
+ import findLastIndex from "lodash/findLastIndex.js";
3
+ import forEach from "lodash/forEach.js";
4
+ import forEachRight from "lodash/forEachRight.js";
5
+ import includes from "lodash/includes.js";
6
+ import { builders } from "prettier/doc";
7
+ import { isCstNode } from "../types/utils.js";
8
+ import { isEmptyDoc } from "../utils/index.js";
9
+ import { hasComments, hasLeadingComments, hasTrailingComments } from "./comments/comments-utils.js";
10
+ import { getTokenLeadingComments, printTokenWithComments } from "./comments/format-comments.js";
11
+ import { concat, group, ifBreak, indentIfBreak, join } from "./prettier-builder.js";
12
+ const { indent, hardline, line } = builders;
13
+ const orderedModifiers = [
40
14
  "Public",
41
15
  "Protected",
42
16
  "Private",
@@ -52,28 +26,26 @@ var orderedModifiers = [
52
26
  "NonSealed",
53
27
  "Strictfp"
54
28
  ];
55
- function buildFqn(tokens, dots) {
29
+ export function buildFqn(tokens, dots) {
56
30
  return rejectAndJoinSeps(dots ? dots : [], tokens);
57
31
  }
58
- exports.buildFqn = buildFqn;
59
- function rejectAndJoinSeps(sepTokens, elems, sep) {
32
+ export function rejectAndJoinSeps(sepTokens, elems, sep) {
60
33
  if (!Array.isArray(sepTokens)) {
61
34
  return rejectAndJoin(sepTokens, elems);
62
35
  }
63
- var actualElements = reject(elems);
64
- var res = [];
65
- for (var i = 0; i < sepTokens.length; i++) {
36
+ const actualElements = reject(elems);
37
+ const res = [];
38
+ for (let i = 0; i < sepTokens.length; i++) {
66
39
  res.push(actualElements[i], sepTokens[i]);
67
40
  if (sep) {
68
41
  res.push(sep);
69
42
  }
70
43
  }
71
- res.push.apply(res, actualElements.slice(sepTokens.length));
72
- return (0, prettier_builder_1.concat)(res);
44
+ res.push(...actualElements.slice(sepTokens.length));
45
+ return concat(res);
73
46
  }
74
- exports.rejectAndJoinSeps = rejectAndJoinSeps;
75
- function reject(elems) {
76
- return elems.filter(function (item) {
47
+ export function reject(elems) {
48
+ return elems.filter(item => {
77
49
  if (typeof item === "string") {
78
50
  return item !== "";
79
51
  }
@@ -82,95 +54,87 @@ function reject(elems) {
82
54
  return item != false && item !== undefined;
83
55
  });
84
56
  }
85
- exports.reject = reject;
86
- function rejectSeparators(separators, elems) {
87
- var realElements = reject(elems);
88
- var realSeparators = [];
89
- for (var i = 0; i < realElements.length - 1; i++) {
57
+ export function rejectSeparators(separators, elems) {
58
+ const realElements = reject(elems);
59
+ const realSeparators = [];
60
+ for (let i = 0; i < realElements.length - 1; i++) {
90
61
  if (realElements[i] !== "") {
91
62
  realSeparators.push(separators[i]);
92
63
  }
93
64
  }
94
65
  return realSeparators;
95
66
  }
96
- exports.rejectSeparators = rejectSeparators;
97
- function rejectAndJoin(sep, elems) {
98
- var actualElements = reject(elems);
99
- return (0, prettier_builder_1.join)(sep, actualElements);
67
+ export function rejectAndJoin(sep, elems) {
68
+ const actualElements = reject(elems);
69
+ return join(sep, actualElements);
100
70
  }
101
- exports.rejectAndJoin = rejectAndJoin;
102
- function rejectAndConcat(elems) {
103
- var actualElements = reject(elems);
104
- return (0, prettier_builder_1.concat)(actualElements);
71
+ export function rejectAndConcat(elems) {
72
+ const actualElements = reject(elems);
73
+ return concat(actualElements);
105
74
  }
106
- exports.rejectAndConcat = rejectAndConcat;
107
- function sortAnnotationIdentifier(annotations, identifiers) {
108
- var tokens = __spreadArray([], identifiers, true);
75
+ export function sortAnnotationIdentifier(annotations, identifiers) {
76
+ let tokens = [...identifiers];
109
77
  if (annotations && annotations.length > 0) {
110
- tokens = __spreadArray(__spreadArray([], tokens, true), annotations, true);
78
+ tokens = [...tokens, ...annotations];
111
79
  }
112
- return tokens.sort(function (a, b) {
113
- var startOffset1 = (0, utils_1.isCstNode)(a)
80
+ return tokens.sort((a, b) => {
81
+ const startOffset1 = isCstNode(a)
114
82
  ? a.children.At[0].startOffset
115
83
  : a.startOffset;
116
- var startOffset2 = (0, utils_1.isCstNode)(b)
84
+ const startOffset2 = isCstNode(b)
117
85
  ? b.children.At[0].startOffset
118
86
  : b.startOffset;
119
87
  return startOffset1 - startOffset2;
120
88
  });
121
89
  }
122
- exports.sortAnnotationIdentifier = sortAnnotationIdentifier;
123
- function sortTokens(values) {
124
- var tokens = [];
125
- (0, forEach_1.default)(values, function (argument) {
90
+ export function sortTokens(values) {
91
+ let tokens = [];
92
+ forEach(values, argument => {
126
93
  if (argument) {
127
94
  tokens = tokens.concat(argument);
128
95
  }
129
96
  });
130
- return tokens.sort(function (a, b) {
97
+ return tokens.sort((a, b) => {
131
98
  return a.startOffset - b.startOffset;
132
99
  });
133
100
  }
134
- exports.sortTokens = sortTokens;
135
- function sortNodes(values) {
136
- var nodes = [];
137
- (0, forEach_1.default)(values, function (argument) {
101
+ export function sortNodes(values) {
102
+ let nodes = [];
103
+ forEach(values, argument => {
138
104
  if (argument) {
139
105
  nodes = nodes.concat(argument);
140
106
  }
141
107
  });
142
- return nodes.sort(function (a, b) {
143
- var aOffset = a.location.startOffset;
144
- var bOffset = b.location.startOffset;
108
+ return nodes.sort((a, b) => {
109
+ const aOffset = a.location.startOffset;
110
+ const bOffset = b.location.startOffset;
145
111
  return aOffset - bOffset;
146
112
  });
147
113
  }
148
- exports.sortNodes = sortNodes;
149
- function matchCategory(token, categoryName) {
150
- var labels = (token.tokenType.CATEGORIES || []).map(function (category) {
114
+ export function matchCategory(token, categoryName) {
115
+ const labels = (token.tokenType.CATEGORIES || []).map(category => {
151
116
  return category.LABEL;
152
117
  });
153
118
  return labels.indexOf(categoryName) !== -1;
154
119
  }
155
- exports.matchCategory = matchCategory;
156
- function sortClassTypeChildren(annotations, typeArguments, identifiers, dots) {
157
- var tokens = __spreadArray([], identifiers, true);
120
+ export function sortClassTypeChildren(annotations, typeArguments, identifiers, dots) {
121
+ let tokens = [...identifiers];
158
122
  if (annotations && annotations.length > 0) {
159
- tokens = __spreadArray(__spreadArray([], tokens, true), annotations, true);
123
+ tokens = [...tokens, ...annotations];
160
124
  }
161
125
  if (typeArguments && typeArguments.length > 0) {
162
- tokens = __spreadArray(__spreadArray([], tokens, true), typeArguments, true);
126
+ tokens = [...tokens, ...typeArguments];
163
127
  }
164
128
  if (dots && dots.length > 0) {
165
- tokens = __spreadArray(__spreadArray([], tokens, true), dots, true);
129
+ tokens = [...tokens, ...dots];
166
130
  }
167
- return tokens.sort(function (a, b) {
168
- var startOffsetA = (0, utils_1.isCstNode)(a)
131
+ return tokens.sort((a, b) => {
132
+ const startOffsetA = isCstNode(a)
169
133
  ? a.children.At
170
134
  ? a.children.At[0].startOffset
171
135
  : a.children.Less[0].startOffset
172
136
  : a.startOffset;
173
- var startOffsetB = (0, utils_1.isCstNode)(b)
137
+ const startOffsetB = isCstNode(b)
174
138
  ? b.children.At
175
139
  ? b.children.At[0].startOffset
176
140
  : b.children.Less[0].startOffset
@@ -178,20 +142,19 @@ function sortClassTypeChildren(annotations, typeArguments, identifiers, dots) {
178
142
  return startOffsetA - startOffsetB;
179
143
  });
180
144
  }
181
- exports.sortClassTypeChildren = sortClassTypeChildren;
182
- function sortModifiers(modifiers) {
183
- var firstAnnotations = [];
184
- var otherModifiers = [];
185
- var lastAnnotations = [];
186
- var hasOtherModifier = false;
145
+ export function sortModifiers(modifiers) {
146
+ let firstAnnotations = [];
147
+ const otherModifiers = [];
148
+ let lastAnnotations = [];
149
+ let hasOtherModifier = false;
187
150
  /**
188
151
  * iterate in reverse order because we special-case
189
152
  * type annotations which come after all other
190
153
  * modifiers
191
154
  */
192
- (0, forEachRight_1.default)(modifiers, function (modifier) {
193
- var isAnnotation = modifier.children.annotation !== undefined;
194
- var isTypeAnnotation = isAnnotation &&
155
+ forEachRight(modifiers, modifier => {
156
+ const isAnnotation = modifier.children.annotation !== undefined;
157
+ const isTypeAnnotation = isAnnotation &&
195
158
  (modifier.name === "methodModifier" ||
196
159
  modifier.name === "interfaceMethodModifier" ||
197
160
  modifier.name === "fieldModifier");
@@ -216,27 +179,26 @@ function sortModifiers(modifiers) {
216
179
  firstAnnotations = firstAnnotations.concat(lastAnnotations);
217
180
  lastAnnotations = [];
218
181
  }
219
- otherModifiers.sort(function (a, b) {
220
- var modifierIndexA = orderedModifiers.indexOf(Object.keys(a.children)[0]);
221
- var modifierIndexB = orderedModifiers.indexOf(Object.keys(b.children)[0]);
182
+ otherModifiers.sort((a, b) => {
183
+ const modifierIndexA = orderedModifiers.indexOf(Object.keys(a.children)[0]);
184
+ const modifierIndexB = orderedModifiers.indexOf(Object.keys(b.children)[0]);
222
185
  return modifierIndexA - modifierIndexB;
223
186
  });
224
187
  return [firstAnnotations, otherModifiers.concat(lastAnnotations)];
225
188
  }
226
- exports.sortModifiers = sortModifiers;
227
- function findDeepElementInPartsArray(item, elt) {
189
+ export function findDeepElementInPartsArray(item, elt) {
228
190
  if (Array.isArray(item)) {
229
- if ((0, includes_1.default)(item, elt)) {
191
+ if (includes(item, elt)) {
230
192
  return true;
231
193
  }
232
- for (var i = 0; i < item.length; i++) {
194
+ for (let i = 0; i < item.length; i++) {
233
195
  if (findDeepElementInPartsArray(item[i], elt)) {
234
196
  return true;
235
197
  }
236
198
  }
237
199
  }
238
200
  else {
239
- for (var key in item) {
201
+ for (const key in item) {
240
202
  if (typeof item[key] === "object" &&
241
203
  findDeepElementInPartsArray(item[key], elt)) {
242
204
  return true;
@@ -245,39 +207,35 @@ function findDeepElementInPartsArray(item, elt) {
245
207
  }
246
208
  return false;
247
209
  }
248
- exports.findDeepElementInPartsArray = findDeepElementInPartsArray;
249
- function displaySemicolon(token, params) {
210
+ export function displaySemicolon(token, params) {
250
211
  if (params !== undefined && params.allowEmptyStatement) {
251
- return (0, format_comments_1.printTokenWithComments)(token);
212
+ return printTokenWithComments(token);
252
213
  }
253
- if (!(0, comments_utils_1.hasComments)(token)) {
214
+ if (!hasComments(token)) {
254
215
  return "";
255
216
  }
256
217
  token.image = "";
257
- return (0, format_comments_1.printTokenWithComments)(token);
218
+ return printTokenWithComments(token);
258
219
  }
259
- exports.displaySemicolon = displaySemicolon;
260
- function isExplicitLambdaParameter(ctx) {
220
+ export function isExplicitLambdaParameter(ctx) {
261
221
  return (ctx &&
262
222
  ctx.lambdaParameterList &&
263
223
  ctx.lambdaParameterList[0] &&
264
224
  ctx.lambdaParameterList[0].children &&
265
225
  ctx.lambdaParameterList[0].children.explicitLambdaParameterList);
266
226
  }
267
- exports.isExplicitLambdaParameter = isExplicitLambdaParameter;
268
- function getBlankLinesSeparator(ctx, separator) {
269
- if (separator === void 0) { separator = hardline; }
227
+ export function getBlankLinesSeparator(ctx, separator = hardline) {
270
228
  if (ctx === undefined) {
271
229
  return [];
272
230
  }
273
- var separators = [];
274
- for (var i = 0; i < ctx.length - 1; i++) {
275
- var node = ctx[i];
276
- var previousRuleEndLineWithComment = (0, comments_utils_1.hasTrailingComments)(node)
231
+ const separators = [];
232
+ for (let i = 0; i < ctx.length - 1; i++) {
233
+ const node = ctx[i];
234
+ const previousRuleEndLineWithComment = hasTrailingComments(node)
277
235
  ? node.trailingComments[node.trailingComments.length - 1].endLine
278
236
  : node.location.endLine;
279
- var nextNode = ctx[i + 1];
280
- var nextRuleStartLineWithComment = (0, comments_utils_1.hasLeadingComments)(nextNode)
237
+ const nextNode = ctx[i + 1];
238
+ const nextRuleStartLineWithComment = hasLeadingComments(nextNode)
281
239
  ? nextNode.leadingComments[0].startLine
282
240
  : nextNode.location.startLine;
283
241
  if (nextRuleStartLineWithComment - previousRuleEndLineWithComment > 1) {
@@ -289,8 +247,7 @@ function getBlankLinesSeparator(ctx, separator) {
289
247
  }
290
248
  return separators;
291
249
  }
292
- exports.getBlankLinesSeparator = getBlankLinesSeparator;
293
- var isTwoHardLine = function (userBlankLinesSeparator) {
250
+ const isTwoHardLine = (userBlankLinesSeparator) => {
294
251
  if (!Array.isArray(userBlankLinesSeparator)) {
295
252
  return false;
296
253
  }
@@ -299,28 +256,28 @@ var isTwoHardLine = function (userBlankLinesSeparator) {
299
256
  userBlankLinesSeparator[1] === hardline);
300
257
  };
301
258
  function getDeclarationsSeparator(declarations, needLineDeclaration, isSemicolon) {
302
- var declarationsWithoutEmptyStatements = declarations.filter(function (declaration) { return !isSemicolon(declaration); });
303
- var userBlankLinesSeparators = getBlankLinesSeparator(declarationsWithoutEmptyStatements);
304
- var additionalBlankLines = declarationsWithoutEmptyStatements.map(needLineDeclaration);
305
- var separators = [];
306
- var indexNextNotEmptyDeclaration = 0;
307
- for (var i = 0; i < declarations.length - 1; i++) {
259
+ const declarationsWithoutEmptyStatements = declarations.filter(declaration => !isSemicolon(declaration));
260
+ const userBlankLinesSeparators = getBlankLinesSeparator(declarationsWithoutEmptyStatements);
261
+ const additionalBlankLines = declarationsWithoutEmptyStatements.map(needLineDeclaration);
262
+ const separators = [];
263
+ let indexNextNotEmptyDeclaration = 0;
264
+ for (let i = 0; i < declarations.length - 1; i++) {
308
265
  // if the empty statement has comments
309
266
  // we want to print them on their own line
310
267
  if (isSemicolon(declarations[i])) {
311
- if ((0, comments_utils_1.hasComments)(declarations[i])) {
268
+ if (hasComments(declarations[i])) {
312
269
  separators.push(hardline);
313
270
  }
314
271
  }
315
272
  else if (indexNextNotEmptyDeclaration <
316
273
  declarationsWithoutEmptyStatements.length - 1) {
317
- var isNextSeparatorTwoHardLine = isTwoHardLine(userBlankLinesSeparators[indexNextNotEmptyDeclaration]);
318
- var additionalSep = !isNextSeparatorTwoHardLine &&
274
+ const isNextSeparatorTwoHardLine = isTwoHardLine(userBlankLinesSeparators[indexNextNotEmptyDeclaration]);
275
+ const additionalSep = !isNextSeparatorTwoHardLine &&
319
276
  (additionalBlankLines[indexNextNotEmptyDeclaration + 1] ||
320
277
  additionalBlankLines[indexNextNotEmptyDeclaration])
321
278
  ? hardline
322
279
  : "";
323
- separators.push((0, prettier_builder_1.concat)([
280
+ separators.push(concat([
324
281
  userBlankLinesSeparators[indexNextNotEmptyDeclaration],
325
282
  additionalSep
326
283
  ]));
@@ -333,9 +290,9 @@ function needLineClassBodyDeclaration(declaration) {
333
290
  if (declaration.children.classMemberDeclaration === undefined) {
334
291
  return true;
335
292
  }
336
- var classMemberDeclaration = declaration.children.classMemberDeclaration[0];
293
+ const classMemberDeclaration = declaration.children.classMemberDeclaration[0];
337
294
  if (classMemberDeclaration.children.fieldDeclaration !== undefined) {
338
- var fieldDeclaration = classMemberDeclaration.children.fieldDeclaration[0];
295
+ const fieldDeclaration = classMemberDeclaration.children.fieldDeclaration[0];
339
296
  if (fieldDeclaration.children.fieldModifier !== undefined &&
340
297
  hasAnnotation(fieldDeclaration.children.fieldModifier) &&
341
298
  hasNonTrailingAnnotation(fieldDeclaration.children.fieldModifier)) {
@@ -350,7 +307,7 @@ function needLineClassBodyDeclaration(declaration) {
350
307
  }
351
308
  function needLineInterfaceMemberDeclaration(declaration) {
352
309
  if (declaration.children.constantDeclaration !== undefined) {
353
- var constantDeclaration = declaration.children.constantDeclaration[0];
310
+ const constantDeclaration = declaration.children.constantDeclaration[0];
354
311
  if (constantDeclaration.children.constantModifier !== undefined &&
355
312
  hasAnnotation(constantDeclaration.children.constantModifier) &&
356
313
  hasNonTrailingAnnotation(constantDeclaration.children.constantModifier)) {
@@ -359,7 +316,7 @@ function needLineInterfaceMemberDeclaration(declaration) {
359
316
  return false;
360
317
  }
361
318
  else if (declaration.children.interfaceMethodDeclaration !== undefined) {
362
- var interfaceMethodDeclaration = declaration.children.interfaceMethodDeclaration[0];
319
+ const interfaceMethodDeclaration = declaration.children.interfaceMethodDeclaration[0];
363
320
  if (interfaceMethodDeclaration.children.interfaceMethodModifier !==
364
321
  undefined &&
365
322
  hasNonTrailingAnnotation(interfaceMethodDeclaration.children.interfaceMethodModifier)) {
@@ -382,7 +339,7 @@ function isInterfaceMemberASemicolon(interfaceMemberDeclaration) {
382
339
  return interfaceMemberDeclaration.children.Semicolon !== undefined;
383
340
  }
384
341
  function hasAnnotation(modifiers) {
385
- return modifiers.some(function (modifier) { return modifier.children.annotation !== undefined; });
342
+ return modifiers.some(modifier => modifier.children.annotation !== undefined);
386
343
  }
387
344
  /**
388
345
  * Return true if there is a modifier that does not come after all other modifiers
@@ -392,83 +349,80 @@ function hasAnnotation(modifiers) {
392
349
  * @returns {boolean}
393
350
  */
394
351
  function hasNonTrailingAnnotation(modifiers) {
395
- var firstAnnotationIndex = (0, findIndex_1.default)(modifiers, function (modifier) { return modifier.children.annotation !== undefined; });
396
- var lastNonAnnotationIndex = (0, findLastIndex_1.default)(modifiers, function (modifier) { return modifier.children.annotation === undefined; });
352
+ const firstAnnotationIndex = findIndex(modifiers, modifier => modifier.children.annotation !== undefined);
353
+ const lastNonAnnotationIndex = findLastIndex(modifiers, modifier => modifier.children.annotation === undefined);
397
354
  return (firstAnnotationIndex < lastNonAnnotationIndex ||
398
355
  lastNonAnnotationIndex === -1);
399
356
  }
400
- function getClassBodyDeclarationsSeparator(classBodyDeclarationContext) {
357
+ export function getClassBodyDeclarationsSeparator(classBodyDeclarationContext) {
401
358
  return getDeclarationsSeparator(classBodyDeclarationContext, needLineClassBodyDeclaration, isClassBodyDeclarationASemicolon);
402
359
  }
403
- exports.getClassBodyDeclarationsSeparator = getClassBodyDeclarationsSeparator;
404
- function getInterfaceBodyDeclarationsSeparator(interfaceMemberDeclarationContext) {
360
+ export function getInterfaceBodyDeclarationsSeparator(interfaceMemberDeclarationContext) {
405
361
  return getDeclarationsSeparator(interfaceMemberDeclarationContext, needLineInterfaceMemberDeclaration, isInterfaceMemberASemicolon);
406
362
  }
407
- exports.getInterfaceBodyDeclarationsSeparator = getInterfaceBodyDeclarationsSeparator;
408
363
  function getAndRemoveLeadingComment(doc) {
409
- var isTokenWithLeadingComment = typeof doc !== "string" && "leadingComments" in doc;
364
+ const isTokenWithLeadingComment = typeof doc !== "string" && "leadingComments" in doc;
410
365
  if (!isTokenWithLeadingComment) {
411
366
  return [];
412
367
  }
413
- var leadingComments = (0, format_comments_1.getTokenLeadingComments)(doc);
368
+ const leadingComments = getTokenLeadingComments(doc);
414
369
  delete doc.leadingComments;
415
370
  return leadingComments;
416
371
  }
417
- function putIntoBraces(argument, separator, LBrace, RBrace) {
418
- var rightBraceLeadingComments = getAndRemoveLeadingComment(RBrace);
419
- var lastBreakLine =
372
+ export function putIntoBraces(argument, separator, LBrace, RBrace) {
373
+ const rightBraceLeadingComments = getAndRemoveLeadingComment(RBrace);
374
+ const lastBreakLine =
420
375
  // check if last element of the array is a line
421
376
  rightBraceLeadingComments.length !== 0 &&
422
377
  rightBraceLeadingComments[rightBraceLeadingComments.length - 1] === hardline
423
378
  ? rightBraceLeadingComments.pop()
424
379
  : separator;
425
- var contentInsideBraces;
426
- if ((0, utils_2.isEmptyDoc)(argument)) {
380
+ let contentInsideBraces;
381
+ if (isEmptyDoc(argument)) {
427
382
  if (rightBraceLeadingComments.length === 0) {
428
- return (0, prettier_builder_1.concat)([LBrace, RBrace]);
383
+ return concat([LBrace, RBrace]);
429
384
  }
430
- contentInsideBraces = __spreadArray([separator], rightBraceLeadingComments, true);
385
+ contentInsideBraces = [separator, ...rightBraceLeadingComments];
431
386
  }
432
387
  else if (rightBraceLeadingComments.length !== 0) {
433
- contentInsideBraces = __spreadArray([
388
+ contentInsideBraces = [
434
389
  separator,
435
390
  argument,
436
- separator
437
- ], rightBraceLeadingComments, true);
391
+ separator,
392
+ ...rightBraceLeadingComments
393
+ ];
438
394
  }
439
395
  else {
440
396
  contentInsideBraces = [separator, argument];
441
397
  }
442
- return (0, prettier_builder_1.group)(rejectAndConcat([
398
+ return group(rejectAndConcat([
443
399
  LBrace,
444
- indent((0, prettier_builder_1.concat)(contentInsideBraces)),
400
+ indent(concat(contentInsideBraces)),
445
401
  lastBreakLine,
446
402
  RBrace
447
403
  ]));
448
404
  }
449
- exports.putIntoBraces = putIntoBraces;
450
- function binary(nodes, tokens, isRoot) {
451
- if (isRoot === void 0) { isRoot = false; }
452
- var levelOperator;
453
- var levelPrecedence;
454
- var level = [];
405
+ export function binary(nodes, tokens, isRoot = false) {
406
+ let levelOperator;
407
+ let levelPrecedence;
408
+ let level = [];
455
409
  while (tokens.length) {
456
- var nextOperator = getOperator(tokens);
457
- var nextPrecedence = getOperatorPrecedence(nextOperator);
410
+ const nextOperator = getOperator(tokens);
411
+ const nextPrecedence = getOperatorPrecedence(nextOperator);
458
412
  if (levelPrecedence === undefined || nextPrecedence === levelPrecedence) {
459
- var tokenLength = ["<<", ">>", ">>>"].includes(nextOperator)
413
+ const tokenLength = ["<<", ">>", ">>>"].includes(nextOperator)
460
414
  ? nextOperator.length
461
415
  : 1;
462
- var operator = (0, prettier_builder_1.concat)(tokens.splice(0, tokenLength));
416
+ const operator = concat(tokens.splice(0, tokenLength));
463
417
  if (levelOperator !== undefined &&
464
418
  needsParentheses(levelOperator, nextOperator)) {
465
419
  level.push(nodes.shift());
466
420
  level = [
467
- (0, prettier_builder_1.concat)(["(", (0, prettier_builder_1.group)(indent((0, prettier_builder_1.join)(line, level))), ") ", operator])
421
+ concat(["(", group(indent(join(line, level))), ") ", operator])
468
422
  ];
469
423
  }
470
424
  else {
471
- level.push((0, prettier_builder_1.join)(" ", [nodes.shift(), operator]));
425
+ level.push(join(" ", [nodes.shift(), operator]));
472
426
  }
473
427
  levelOperator = nextOperator;
474
428
  levelPrecedence = nextPrecedence;
@@ -476,43 +430,48 @@ function binary(nodes, tokens, isRoot) {
476
430
  else if (nextPrecedence < levelPrecedence) {
477
431
  level.push(nodes.shift());
478
432
  if (isRoot) {
479
- var content_1 = (0, prettier_builder_1.group)(indent((0, prettier_builder_1.join)(line, level)));
433
+ const content = group(indent(join(line, level)));
480
434
  nodes.unshift(levelOperator !== undefined &&
481
435
  needsParentheses(levelOperator, nextOperator)
482
- ? (0, prettier_builder_1.concat)(["(", content_1, ")"])
483
- : content_1);
436
+ ? concat(["(", content, ")"])
437
+ : content);
484
438
  level = [];
485
439
  levelOperator = undefined;
486
440
  levelPrecedence = undefined;
487
441
  }
488
442
  else {
489
- return (0, prettier_builder_1.group)((0, prettier_builder_1.join)(line, level));
443
+ return group(join(line, level));
490
444
  }
491
445
  }
492
446
  else {
493
- var content_2 = indent(binary(nodes, tokens));
447
+ const content = indent(binary(nodes, tokens));
494
448
  nodes.unshift(levelOperator !== undefined &&
495
449
  needsParentheses(nextOperator, levelOperator)
496
- ? (0, prettier_builder_1.concat)(["(", content_2, ")"])
497
- : content_2);
450
+ ? concat(["(", content, ")"])
451
+ : content);
498
452
  }
499
453
  }
500
454
  level.push(nodes.shift());
501
- var content = (0, prettier_builder_1.group)((0, prettier_builder_1.join)(line, level));
502
- return levelOperator === "=" ? indent(content) : content;
455
+ const lineGroupId = Symbol("line");
456
+ return group(levelOperator === "="
457
+ ? [
458
+ level[0],
459
+ indent(group(line, { id: lineGroupId })),
460
+ indentIfBreak(level[1], { groupId: lineGroupId })
461
+ ]
462
+ : join(line, level));
503
463
  }
504
- exports.binary = binary;
505
464
  function getOperator(tokens) {
506
465
  if (!tokens.length) {
507
466
  return "";
508
467
  }
509
- var _a = tokens[0], image = _a.image, startOffset = _a.startOffset;
468
+ const [{ image, startOffset }] = tokens;
510
469
  if (!["<", ">"].includes(image)) {
511
470
  return image;
512
471
  }
513
- var repeatedTokenCount = 1;
514
- for (var i = 1; i < Math.min(3, tokens.length); i++) {
515
- var token = tokens[i];
472
+ let repeatedTokenCount = 1;
473
+ for (let i = 1; i < Math.min(3, tokens.length); i++) {
474
+ const token = tokens[i];
516
475
  if (token.image !== image || token.startOffset !== startOffset + i) {
517
476
  break;
518
477
  }
@@ -531,7 +490,7 @@ function getOperator(tokens) {
531
490
  return ">>>";
532
491
  }
533
492
  }
534
- var PRECEDENCES_BY_OPERATOR = new Map([
493
+ const PRECEDENCES_BY_OPERATOR = new Map([
535
494
  ["||"],
536
495
  ["&&"],
537
496
  ["|"],
@@ -542,7 +501,7 @@ var PRECEDENCES_BY_OPERATOR = new Map([
542
501
  ["<<", ">>", ">>>"],
543
502
  ["+", "-"],
544
503
  ["*", "/", "%"]
545
- ].flatMap(function (operators, index) { return operators.map(function (operator) { return [operator, index]; }); }));
504
+ ].flatMap((operators, index) => operators.map(operator => [operator, index])));
546
505
  function getOperatorPrecedence(operator) {
547
506
  var _a;
548
507
  return (_a = PRECEDENCES_BY_OPERATOR.get(operator)) !== null && _a !== void 0 ? _a : -1;
@@ -552,22 +511,21 @@ function needsParentheses(operator, parentOperator) {
552
511
  (["|", "^", "&", "<<", ">>", ">>>"].includes(parentOperator) &&
553
512
  getOperatorPrecedence(operator) >
554
513
  getOperatorPrecedence(parentOperator)) ||
555
- [operator, parentOperator].every(function (o) { return ["==", "!="].includes(o); }) ||
556
- [operator, parentOperator].every(function (o) { return ["<<", ">>", ">>>"].includes(o); }) ||
514
+ [operator, parentOperator].every(o => ["==", "!="].includes(o)) ||
515
+ [operator, parentOperator].every(o => ["<<", ">>", ">>>"].includes(o)) ||
557
516
  (operator === "*" && parentOperator === "/") ||
558
517
  (operator === "/" && parentOperator === "*") ||
559
518
  (operator === "%" && ["+", "-", "*", "/"].includes(parentOperator)) ||
560
519
  (["*", "/"].includes(operator) && parentOperator === "%"));
561
520
  }
562
- function isStatementEmptyStatement(statement) {
521
+ export function isStatementEmptyStatement(statement) {
563
522
  return (statement === ";" || (Array.isArray(statement) && statement[0] === ";"));
564
523
  }
565
- exports.isStatementEmptyStatement = isStatementEmptyStatement;
566
- function sortImports(imports) {
567
- var staticImports = [];
568
- var nonStaticImports = [];
524
+ export function sortImports(imports) {
525
+ const staticImports = [];
526
+ const nonStaticImports = [];
569
527
  if (imports !== undefined) {
570
- for (var i = 0; i < imports.length; i++) {
528
+ for (let i = 0; i < imports.length; i++) {
571
529
  if (imports[i].children.Static !== undefined) {
572
530
  staticImports.push(imports[i]);
573
531
  }
@@ -576,23 +534,20 @@ function sortImports(imports) {
576
534
  }
577
535
  }
578
536
  // TODO: Could be optimized as we could expect that the array is already almost sorted
579
- var comparator = function (first, second) {
580
- return compareFqn(first.children.packageOrTypeName[0], second.children.packageOrTypeName[0]);
581
- };
537
+ const comparator = (first, second) => compareFqn(first.children.packageOrTypeName[0], second.children.packageOrTypeName[0]);
582
538
  staticImports.sort(comparator);
583
539
  nonStaticImports.sort(comparator);
584
540
  }
585
541
  return {
586
- staticImports: staticImports,
587
- nonStaticImports: nonStaticImports
542
+ staticImports,
543
+ nonStaticImports
588
544
  };
589
545
  }
590
- exports.sortImports = sortImports;
591
546
  function compareFqn(packageOrTypeNameFirst, packageOrTypeNameSecond) {
592
- var identifiersFirst = packageOrTypeNameFirst.children.Identifier;
593
- var identifiersSecond = packageOrTypeNameSecond.children.Identifier;
594
- var minParts = Math.min(identifiersFirst.length, identifiersSecond.length);
595
- for (var i = 0; i < minParts; i++) {
547
+ const identifiersFirst = packageOrTypeNameFirst.children.Identifier;
548
+ const identifiersSecond = packageOrTypeNameSecond.children.Identifier;
549
+ const minParts = Math.min(identifiersFirst.length, identifiersSecond.length);
550
+ for (let i = 0; i < minParts; i++) {
596
551
  if (identifiersFirst[i].image < identifiersSecond[i].image) {
597
552
  return -1;
598
553
  }
@@ -608,12 +563,12 @@ function compareFqn(packageOrTypeNameFirst, packageOrTypeNameSecond) {
608
563
  }
609
564
  return 0;
610
565
  }
611
- function isUniqueMethodInvocation(primarySuffixes) {
566
+ export function isUniqueMethodInvocation(primarySuffixes) {
612
567
  if (primarySuffixes === undefined) {
613
568
  return 0;
614
569
  }
615
- var count = 0;
616
- primarySuffixes.forEach(function (primarySuffix) {
570
+ let count = 0;
571
+ primarySuffixes.forEach(primarySuffix => {
617
572
  if (primarySuffix.children.methodInvocationSuffix !== undefined) {
618
573
  count++;
619
574
  if (count > 1) {
@@ -623,18 +578,15 @@ function isUniqueMethodInvocation(primarySuffixes) {
623
578
  });
624
579
  return count;
625
580
  }
626
- exports.isUniqueMethodInvocation = isUniqueMethodInvocation;
627
- function printArrayList(_a) {
628
- var list = _a.list, extraComma = _a.extraComma, LCurly = _a.LCurly, RCurly = _a.RCurly, trailingComma = _a.trailingComma;
629
- var optionalComma;
581
+ export function printArrayList({ list, extraComma, LCurly, RCurly, trailingComma }) {
582
+ let optionalComma;
630
583
  if (trailingComma !== "none" && list !== "") {
631
584
  optionalComma = extraComma
632
- ? (0, prettier_builder_1.ifBreak)(extraComma[0], __assign(__assign({}, extraComma[0]), { image: "" }))
633
- : (0, prettier_builder_1.ifBreak)(",", "");
585
+ ? ifBreak(extraComma[0], Object.assign(Object.assign({}, extraComma[0]), { image: "" }))
586
+ : ifBreak(",", "");
634
587
  }
635
588
  else {
636
- optionalComma = extraComma ? __assign(__assign({}, extraComma[0]), { image: "" }) : "";
589
+ optionalComma = extraComma ? Object.assign(Object.assign({}, extraComma[0]), { image: "" }) : "";
637
590
  }
638
591
  return putIntoBraces(rejectAndConcat([list, optionalComma]), line, LCurly, RCurly);
639
592
  }
640
- exports.printArrayList = printArrayList;