@haneullabs/prettier-plugin-move 0.3.3

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.
Files changed (149) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/CONTRIBUTING.md +31 -0
  3. package/README.md +96 -0
  4. package/bin/prettier-move.js +29 -0
  5. package/out/cst/annotation.js +64 -0
  6. package/out/cst/annotation.js.map +1 -0
  7. package/out/cst/common.js +376 -0
  8. package/out/cst/common.js.map +1 -0
  9. package/out/cst/constant.js +92 -0
  10. package/out/cst/constant.js.map +1 -0
  11. package/out/cst/enum_definition.js +69 -0
  12. package/out/cst/enum_definition.js.map +1 -0
  13. package/out/cst/expression/abort_expression.js +32 -0
  14. package/out/cst/expression/abort_expression.js.map +1 -0
  15. package/out/cst/expression/annotation_expression.js +35 -0
  16. package/out/cst/expression/annotation_expression.js.map +1 -0
  17. package/out/cst/expression/assign_expression.js +51 -0
  18. package/out/cst/expression/assign_expression.js.map +1 -0
  19. package/out/cst/expression/binary_expression.js +70 -0
  20. package/out/cst/expression/binary_expression.js.map +1 -0
  21. package/out/cst/expression/block.js +58 -0
  22. package/out/cst/expression/block.js.map +1 -0
  23. package/out/cst/expression/block_item.js +25 -0
  24. package/out/cst/expression/block_item.js.map +1 -0
  25. package/out/cst/expression/borrow_expression.js +26 -0
  26. package/out/cst/expression/borrow_expression.js.map +1 -0
  27. package/out/cst/expression/break_expression.js +27 -0
  28. package/out/cst/expression/break_expression.js.map +1 -0
  29. package/out/cst/expression/call_expression.js +25 -0
  30. package/out/cst/expression/call_expression.js.map +1 -0
  31. package/out/cst/expression/cast_expression.js +31 -0
  32. package/out/cst/expression/cast_expression.js.map +1 -0
  33. package/out/cst/expression/continue_expression.js +26 -0
  34. package/out/cst/expression/continue_expression.js.map +1 -0
  35. package/out/cst/expression/dereference_expression.js +27 -0
  36. package/out/cst/expression/dereference_expression.js.map +1 -0
  37. package/out/cst/expression/dot_expression.js +66 -0
  38. package/out/cst/expression/dot_expression.js.map +1 -0
  39. package/out/cst/expression/expression_list.js +26 -0
  40. package/out/cst/expression/expression_list.js.map +1 -0
  41. package/out/cst/expression/identified_expression.js +28 -0
  42. package/out/cst/expression/identified_expression.js.map +1 -0
  43. package/out/cst/expression/if_expression.js +133 -0
  44. package/out/cst/expression/if_expression.js.map +1 -0
  45. package/out/cst/expression/index.js +74 -0
  46. package/out/cst/expression/index.js.map +1 -0
  47. package/out/cst/expression/index_expression.js +28 -0
  48. package/out/cst/expression/index_expression.js.map +1 -0
  49. package/out/cst/expression/lambda_expression.js +72 -0
  50. package/out/cst/expression/lambda_expression.js.map +1 -0
  51. package/out/cst/expression/let_statement.js +59 -0
  52. package/out/cst/expression/let_statement.js.map +1 -0
  53. package/out/cst/expression/loop_expression.js +27 -0
  54. package/out/cst/expression/loop_expression.js.map +1 -0
  55. package/out/cst/expression/macro_call_expression.js +66 -0
  56. package/out/cst/expression/macro_call_expression.js.map +1 -0
  57. package/out/cst/expression/match_expression.js +86 -0
  58. package/out/cst/expression/match_expression.js.map +1 -0
  59. package/out/cst/expression/move_or_copy_expression.js +27 -0
  60. package/out/cst/expression/move_or_copy_expression.js.map +1 -0
  61. package/out/cst/expression/name_expression.js +26 -0
  62. package/out/cst/expression/name_expression.js.map +1 -0
  63. package/out/cst/expression/pack_expression.js +27 -0
  64. package/out/cst/expression/pack_expression.js.map +1 -0
  65. package/out/cst/expression/return_expression.js +44 -0
  66. package/out/cst/expression/return_expression.js.map +1 -0
  67. package/out/cst/expression/unary_expression.js +26 -0
  68. package/out/cst/expression/unary_expression.js.map +1 -0
  69. package/out/cst/expression/unit_expression.js +17 -0
  70. package/out/cst/expression/unit_expression.js.map +1 -0
  71. package/out/cst/expression/vector_expression.js +80 -0
  72. package/out/cst/expression/vector_expression.js.map +1 -0
  73. package/out/cst/expression/while_expression.js +42 -0
  74. package/out/cst/expression/while_expression.js.map +1 -0
  75. package/out/cst/formatting.js +100 -0
  76. package/out/cst/formatting.js.map +1 -0
  77. package/out/cst/function_definition.js +248 -0
  78. package/out/cst/function_definition.js.map +1 -0
  79. package/out/cst/literal.js +68 -0
  80. package/out/cst/literal.js.map +1 -0
  81. package/out/cst/module.js +158 -0
  82. package/out/cst/module.js.map +1 -0
  83. package/out/cst/source_file.js +38 -0
  84. package/out/cst/source_file.js.map +1 -0
  85. package/out/cst/struct_definition.js +209 -0
  86. package/out/cst/struct_definition.js.map +1 -0
  87. package/out/cst/use_declaration.js +212 -0
  88. package/out/cst/use_declaration.js.map +1 -0
  89. package/out/imports-grouping.js +259 -0
  90. package/out/imports-grouping.js.map +1 -0
  91. package/out/index.js +97 -0
  92. package/out/index.js.map +1 -0
  93. package/out/printer.js +69 -0
  94. package/out/printer.js.map +1 -0
  95. package/out/tree.js +371 -0
  96. package/out/tree.js.map +1 -0
  97. package/out/utilities.js +251 -0
  98. package/out/utilities.js.map +1 -0
  99. package/package.json +34 -0
  100. package/prettier.config.js +12 -0
  101. package/src/cst/annotation.ts +71 -0
  102. package/src/cst/common.ts +430 -0
  103. package/src/cst/constant.ts +110 -0
  104. package/src/cst/enum_definition.ts +73 -0
  105. package/src/cst/expression/abort_expression.ts +35 -0
  106. package/src/cst/expression/annotation_expression.ts +38 -0
  107. package/src/cst/expression/assign_expression.ts +66 -0
  108. package/src/cst/expression/binary_expression.ts +75 -0
  109. package/src/cst/expression/block.ts +72 -0
  110. package/src/cst/expression/block_item.ts +29 -0
  111. package/src/cst/expression/borrow_expression.ts +28 -0
  112. package/src/cst/expression/break_expression.ts +33 -0
  113. package/src/cst/expression/call_expression.ts +28 -0
  114. package/src/cst/expression/cast_expression.ts +35 -0
  115. package/src/cst/expression/continue_expression.ts +29 -0
  116. package/src/cst/expression/dereference_expression.ts +33 -0
  117. package/src/cst/expression/dot_expression.ts +89 -0
  118. package/src/cst/expression/expression_list.ts +28 -0
  119. package/src/cst/expression/identified_expression.ts +30 -0
  120. package/src/cst/expression/if_expression.ts +177 -0
  121. package/src/cst/expression/index.ts +85 -0
  122. package/src/cst/expression/index_expression.ts +37 -0
  123. package/src/cst/expression/lambda_expression.ts +84 -0
  124. package/src/cst/expression/let_statement.ts +73 -0
  125. package/src/cst/expression/loop_expression.ts +29 -0
  126. package/src/cst/expression/macro_call_expression.ts +79 -0
  127. package/src/cst/expression/match_expression.ts +102 -0
  128. package/src/cst/expression/move_or_copy_expression.ts +29 -0
  129. package/src/cst/expression/name_expression.ts +28 -0
  130. package/src/cst/expression/pack_expression.ts +29 -0
  131. package/src/cst/expression/return_expression.ts +50 -0
  132. package/src/cst/expression/unary_expression.ts +28 -0
  133. package/src/cst/expression/unit_expression.ts +18 -0
  134. package/src/cst/expression/vector_expression.ts +97 -0
  135. package/src/cst/expression/while_expression.ts +45 -0
  136. package/src/cst/formatting.ts +100 -0
  137. package/src/cst/function_definition.ts +300 -0
  138. package/src/cst/literal.ts +69 -0
  139. package/src/cst/module.ts +191 -0
  140. package/src/cst/source_file.ts +38 -0
  141. package/src/cst/struct_definition.ts +267 -0
  142. package/src/cst/use_declaration.ts +238 -0
  143. package/src/imports-grouping.ts +300 -0
  144. package/src/index.ts +119 -0
  145. package/src/printer.ts +93 -0
  146. package/src/tree.ts +438 -0
  147. package/src/utilities.ts +387 -0
  148. package/tree-sitter-move.wasm +0 -0
  149. package/tsconfig.json +26 -0
package/out/tree.js ADDED
@@ -0,0 +1,371 @@
1
+ "use strict";
2
+ // Copyright (c) The Move Contributors
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.Tree = void 0;
6
+ const formatting_1 = require("./cst/formatting");
7
+ const use_declaration_1 = require("./cst/use_declaration");
8
+ class Tree {
9
+ /**
10
+ * Construct the `Tree` node from the `Parser.SyntaxNode`, additionally, run
11
+ * some passes to clean-up the tree and make the structure more manageable and
12
+ * easier to work with.
13
+ *
14
+ * Passes:
15
+ * - Sum-up pairs of newlines into a single empty line.
16
+ * - Filter out sequential empty lines.
17
+ * - Filter out leading and trailing empty lines.
18
+ * - Assign trailing comments to the node.
19
+ * - Assign leading comments to the node.
20
+ * - Filter out all assigned comments.
21
+ *
22
+ * @param node
23
+ * @param parent
24
+ */
25
+ constructor(node, parent = null) {
26
+ this.enableLeadingComment = true;
27
+ this.enableTrailingComment = true;
28
+ /**
29
+ * Marks if the comment has been used. This is useful to avoid using the same
30
+ * comment multiple times + filter out comments that are already used.
31
+ */
32
+ this.isUsedComment = false;
33
+ this.type = node.type;
34
+ this.text = node.text;
35
+ this.isNamed = node.isNamed();
36
+ this.leadingComment = [];
37
+ this.trailingComment = null;
38
+ this.getParent = () => parent;
39
+ // === Clean-up passes ===
40
+ // turn every node into a `Tree` node.
41
+ this.children = node.children.map((child) => new Tree(child, this));
42
+ // sum-up pairs of newlines into a single empty line.
43
+ this.children = this.children.reduce((acc, node) => {
44
+ if (node.isNewline && node.nextSibling?.isNewline)
45
+ node.type = 'empty_line';
46
+ if (node.isNewline && acc[acc.length - 1]?.isEmptyLine)
47
+ return acc;
48
+ return [...acc, node];
49
+ }, []);
50
+ // filter out sequential empty lines.
51
+ this.children = this.children.filter((node) => {
52
+ return !node.isEmptyLine || !node.previousNamedSibling?.isEmptyLine;
53
+ });
54
+ // filter out leading and trailing empty lines.
55
+ this.children = this.children.filter((node) => {
56
+ if (!node.isEmptyLine)
57
+ return true; // we only filter out empty lines
58
+ if (!node.previousNamedSibling)
59
+ return false; // remove leading empty lines
60
+ if (!node.nextNamedSibling)
61
+ return false; // remove trailing empty lines
62
+ return true;
63
+ });
64
+ // assign trailing comments to the node. modifies the tree in place.
65
+ this.children.forEach((child) => child.assignTrailingComments());
66
+ // assign leading comments to the node. modifies the tree in place.
67
+ this.children.forEach((child) => child.assignLeadingComments());
68
+ // filter out all leading comments.
69
+ this.children = this.children.filter((child) => !child.isUsedComment);
70
+ }
71
+ /**
72
+ * Disable the trailing comment for the current node.
73
+ */
74
+ disableTrailingComment() {
75
+ this.enableTrailingComment = false;
76
+ }
77
+ /**
78
+ * Special case for lists, where we want to print the leading character (eg `dot_expression`).
79
+ */
80
+ disableLeadingComment() {
81
+ this.enableLeadingComment = false;
82
+ }
83
+ /**
84
+ * Find the parent node of a specific type. Optionally, break on a specific type.
85
+ */
86
+ findParentUntil(type, breakOn) {
87
+ let parent = this.parent;
88
+ while (parent) {
89
+ if (parent.type === type)
90
+ return parent;
91
+ if (breakOn.includes(parent.type))
92
+ return null;
93
+ parent = parent.parent;
94
+ }
95
+ return null;
96
+ }
97
+ /**
98
+ * Check if the previous sibling is an annotation node. Ignore formatting nodes.
99
+ */
100
+ get hasAnnotation() {
101
+ let prev = this.previousNamedSibling;
102
+ while (prev) {
103
+ if (prev.type === 'annotation')
104
+ return true;
105
+ if (!prev.isFormatting)
106
+ return false;
107
+ prev = prev.previousNamedSibling;
108
+ }
109
+ return false;
110
+ }
111
+ /**
112
+ * A flag to skip formatting for a specific node. A manual instruction from
113
+ * the user is `prettier-ignore`. When placed above (leading comment) a node,
114
+ * it will skip formatting for that node.
115
+ */
116
+ get skipFormattingNode() {
117
+ return (!!this.leadingComment.find((comment) => comment.text.includes('prettier-ignore')) ||
118
+ false);
119
+ }
120
+ /**
121
+ * Get the number of named children.
122
+ */
123
+ get namedChildCount() {
124
+ return this.namedChildren.length;
125
+ }
126
+ get isFunctionCall() {
127
+ return this.type === 'call_expression' || this.type === 'macro_call_expression';
128
+ }
129
+ /**
130
+ * Tells whether a `Node` knows how to break itself.
131
+ * Nodes that match the following types are considered breakable:
132
+ * - `dot_expression`
133
+ * - `vector_expression`
134
+ * - `expression_list`
135
+ * - `if_expression` (?)
136
+ * - `pack_expression`
137
+ * - `match_expression`
138
+ * - `block`
139
+ */
140
+ get isBreakableExpression() {
141
+ return [
142
+ // TODO: consider revisiting `call_expression` and `macro_call_expression`
143
+ // 'call_expression',
144
+ // 'macro_call_expression',
145
+ 'dot_expression',
146
+ 'index_expression',
147
+ 'vector_expression',
148
+ 'expression_list',
149
+ 'if_expression',
150
+ 'pack_expression',
151
+ 'match_expression',
152
+ 'block',
153
+ ].includes(this.type);
154
+ }
155
+ /**
156
+ * Whether a node is a list node, like `vector_expression`, `expression_list`, or `block`.
157
+ * Lists are typical breakable nodes, where each element is separated by a newline.
158
+ */
159
+ get isList() {
160
+ return ['vector_expression', 'expression_list', 'block'].includes(this.type);
161
+ }
162
+ /**
163
+ * Whether a node is a control flow node, like `if_expression`, `while_expression`,
164
+ * `loop_expression`, `abort_expression`, or `return_expression`.
165
+ */
166
+ get isControlFlow() {
167
+ return [
168
+ 'identified_expression',
169
+ 'if_expression',
170
+ 'while_expression',
171
+ 'loop_expression',
172
+ 'abort_expression',
173
+ 'return_expression',
174
+ ].includes(this.type);
175
+ }
176
+ /**
177
+ * Important part of the `imports-grouping` functionality. This flag is used to
178
+ * determine whether a node is an `use_module`, `use_module_members` or
179
+ * `use_module_member` node to skip their printing if they're printed as grouped.
180
+ */
181
+ get isGroupedImport() {
182
+ return (0, use_declaration_1.isUseImport)(this) && !this.hasAnnotation;
183
+ }
184
+ /**
185
+ * Whether a node is a `Formatting` node, like `line_comment`, `block_comment`,
186
+ * `empty_line`, or `next_line`.
187
+ */
188
+ get isFormatting() {
189
+ return (0, formatting_1.isFormatting)(this);
190
+ }
191
+ child(index) {
192
+ return this.children[index] || null;
193
+ }
194
+ get isEmptyLine() {
195
+ return this.type === 'empty_line';
196
+ }
197
+ get isNewline() {
198
+ return this.type === 'newline';
199
+ }
200
+ get isComment() {
201
+ return this.type === 'line_comment' || this.type === 'block_comment';
202
+ }
203
+ get isTypeParam() {
204
+ return ['apply_type', 'ref_type', 'tuple_type', 'function_type', 'primitive_type'].includes(this.type);
205
+ }
206
+ get previousSibling() {
207
+ const parent = this.getParent();
208
+ if (!parent) {
209
+ return null;
210
+ }
211
+ const index = parent.children.indexOf(this);
212
+ if (index === 0) {
213
+ return null;
214
+ }
215
+ return parent.children[index - 1] || null;
216
+ }
217
+ get previousNamedSibling() {
218
+ let node = this.previousSibling;
219
+ while (node && !node.isNamed) {
220
+ node = node.previousSibling;
221
+ }
222
+ return node;
223
+ }
224
+ get startsOnNewLine() {
225
+ return this.previousSibling?.isNewline || false;
226
+ }
227
+ get nonFormattingChildren() {
228
+ return this.namedChildren.filter((child) => !child.isFormatting);
229
+ }
230
+ get namedChildren() {
231
+ return this.children.filter((child) => child.isNamed);
232
+ }
233
+ get firstNamedChild() {
234
+ return this.namedChildren[0] || null;
235
+ }
236
+ get namedAndEmptyLineChildren() {
237
+ return this.namedChildren.filter((child) => {
238
+ return (child.isNamed &&
239
+ (child.isEmptyLine ||
240
+ (child.isComment && !child.isUsedComment) ||
241
+ !child.isFormatting));
242
+ });
243
+ }
244
+ get nextSibling() {
245
+ const parent = this.getParent();
246
+ if (!parent) {
247
+ return null;
248
+ }
249
+ const index = parent.children.indexOf(this);
250
+ if (index === parent.children.length - 1) {
251
+ return null;
252
+ }
253
+ return parent.children[index + 1] || null;
254
+ }
255
+ get nextNamedSibling() {
256
+ let node = this.nextSibling;
257
+ while (node && !node.isNamed) {
258
+ node = node.nextSibling;
259
+ }
260
+ return node;
261
+ }
262
+ get parent() {
263
+ return this.getParent();
264
+ }
265
+ /**
266
+ * Print the Node as a JSON object. Remove the fields that are not necessary
267
+ * for printing. May be extended shall one need to debug deeper.
268
+ */
269
+ toJSON() {
270
+ return {
271
+ type: this.type,
272
+ isNamed: this.isNamed,
273
+ children: this.children.map((child) => child.toJSON()),
274
+ leadingComment: this.leadingComment,
275
+ trailingComment: this.trailingComment,
276
+ };
277
+ }
278
+ /**
279
+ * Checks the following node and assigns it as a trailing comment if it is a comment.
280
+ * The comment is then marked as used and will not be used again.
281
+ */
282
+ assignTrailingComments() {
283
+ if (!this.isNamed)
284
+ return this;
285
+ if (this.isFormatting)
286
+ return this;
287
+ const nextNamed = this.nextNamedSibling;
288
+ if (!nextNamed?.isComment)
289
+ return this;
290
+ if (nextNamed.isUsedComment)
291
+ return this;
292
+ const comment = nextNamed;
293
+ // if it's a block comment, we need to make sure there's nothing in
294
+ // between the current node and the comment, otherwise block comment is
295
+ // associated with the next node.
296
+ if (comment.type == 'block_comment') {
297
+ // any non-named node between the current node and the comment
298
+ // breaks the association.
299
+ if (comment.previousSibling != this && !!comment.nextNamedSibling)
300
+ return this;
301
+ const addSpace = !!comment.nextNamedSibling ? ' ' : '';
302
+ this.trailingComment = {
303
+ type: comment.type,
304
+ text: comment.text + addSpace,
305
+ newline: false,
306
+ };
307
+ this.nextNamedSibling.isUsedComment = true;
308
+ }
309
+ if (comment.type == 'line_comment') {
310
+ this.trailingComment = {
311
+ type: comment.type,
312
+ text: comment.text,
313
+ newline: false,
314
+ };
315
+ this.nextNamedSibling.isUsedComment = true;
316
+ }
317
+ return this;
318
+ }
319
+ /**
320
+ * Walks backwards through the siblings and searches for comments preceding
321
+ * the current node. If a comment is found, it is assigned to the `leadingComment`
322
+ * property of the node, and the comment is marked as used.
323
+ *
324
+ * Used comments are filtered out and not used again.
325
+ *
326
+ * Motivation for this is to avoid duplicate association of a comment both as
327
+ * a trailing comment and a leading comment.
328
+ */
329
+ assignLeadingComments() {
330
+ let comments = [];
331
+ let prev = this.previousNamedSibling;
332
+ let newline = false;
333
+ if (!this.isNamed)
334
+ return this;
335
+ if (this.isFormatting)
336
+ return this;
337
+ while (prev?.isNewline) {
338
+ newline = true;
339
+ prev = prev.previousNamedSibling;
340
+ }
341
+ if (prev?.type == 'block_comment') {
342
+ if (prev.isUsedComment)
343
+ return this;
344
+ comments.unshift({
345
+ type: prev.type,
346
+ text: prev.text,
347
+ newline,
348
+ });
349
+ prev.isUsedComment = true;
350
+ this.leadingComment = comments;
351
+ return this;
352
+ }
353
+ while (prev?.isComment || (prev?.isNewline && !prev?.isUsedComment)) {
354
+ if (prev.isUsedComment)
355
+ break;
356
+ if (prev.isComment) {
357
+ comments.unshift({
358
+ type: prev.type,
359
+ text: prev.text,
360
+ newline: true,
361
+ });
362
+ prev.isUsedComment = true;
363
+ }
364
+ prev = prev.previousNamedSibling; // move to the previous comment
365
+ }
366
+ this.leadingComment = comments;
367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C,oBAAoB,CAAC,CAAC,+BAA+B;QACrE,CAAC;QAED,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;QAE/B,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAxaD,oBAwaC"}
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+ // Copyright (c) The Move Contributors
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.printIdentifier = printIdentifier;
6
+ exports.shouldBreakFirstChild = shouldBreakFirstChild;
7
+ exports.printLeadingComment = printLeadingComment;
8
+ exports.printTrailingComment = printTrailingComment;
9
+ exports.emptyBlockOrList = emptyBlockOrList;
10
+ exports.block = block;
11
+ exports.nonBreakingBlock = nonBreakingBlock;
12
+ exports.list = list;
13
+ const prettier_1 = require("prettier");
14
+ const { indent, join, fill, softline, dedent, hardline, line, lineSuffix, group, indentIfBreak, hardlineWithoutBreakParent, breakParent, ifBreak, } = prettier_1.doc.builders;
15
+ /**
16
+ * Prints an `identifier` node.
17
+ */
18
+ function printIdentifier(path) {
19
+ return path.node.text;
20
+ }
21
+ /**
22
+ * Returns `true` if the first non-formatting child of the path starts on a new line.
23
+ * This function is useful for respecting developer formatting if they choose to break
24
+ * the list.
25
+ *
26
+ * ```move
27
+ * // input
28
+ * fun args(a: u8) {} // no break
29
+ * fun args(
30
+ * a: u8 // first child starts on a new line
31
+ * ) {}
32
+ *
33
+ * // output
34
+ * fun args(a: u8) {} // no break
35
+ * fun args(
36
+ * a: u8 // respect developer formatting
37
+ * ) {}
38
+ * ```
39
+ *
40
+ * @param path
41
+ * @returns
42
+ */
43
+ function shouldBreakFirstChild(path) {
44
+ return path.node.nonFormattingChildren[0]?.startsOnNewLine || false;
45
+ }
46
+ /**
47
+ * Prints all comments that are leading the node. This function is injected into
48
+ * the `printFn` to print comments before the node. See the `print` function in
49
+ * `printer.ts` for more information.
50
+ *
51
+ * @param path
52
+ * @returns
53
+ */
54
+ function printLeadingComment(path, options) {
55
+ const comments = path.node.leadingComment;
56
+ if (!comments || !comments.length)
57
+ return [];
58
+ if (!path.node.enableLeadingComment)
59
+ return [];
60
+ if (comments.length == 1 && comments[0].type == 'block_comment') {
61
+ return [comments[0].text, comments[0].newline ? hardlineWithoutBreakParent : ' '];
62
+ }
63
+ if (options.wrapComments == false) {
64
+ return [
65
+ join(hardlineWithoutBreakParent, comments.map((c) => c.type == 'line_comment' ? [c.text, /* used to be breakParent */ ''] : [c.text])),
66
+ hardlineWithoutBreakParent,
67
+ ];
68
+ }
69
+ // we do not concatenate the comments into a single string, and treat each
70
+ // line separately.
71
+ return comments.map((comment) => {
72
+ if (comment.type == 'line_comment') {
73
+ const isDoc = comment.text.startsWith('///');
74
+ const parts = comment.text.slice(isDoc ? 4 : 3).split(' ');
75
+ return [
76
+ isDoc ? '/// ' : '// ',
77
+ fill(join(ifBreak([softline, isDoc ? '/// ' : '// '], ' '), parts)),
78
+ hardlineWithoutBreakParent,
79
+ ];
80
+ }
81
+ return comment.text;
82
+ });
83
+ }
84
+ /**
85
+ * Prints the trailing comments of the node. Currently, we only allow a single line
86
+ * comment to be printed. This function is injected into the `printFn` to print
87
+ * comments after the node. See the `print` function in `printer.ts` for more information.
88
+ *
89
+ * @param path
90
+ * @returns
91
+ */
92
+ function printTrailingComment(path, shouldBreak = false) {
93
+ // we do not allow comments on empty lines
94
+ if (path.node.isEmptyLine)
95
+ return '';
96
+ if (!path.node.enableTrailingComment)
97
+ return '';
98
+ const comment = path.node.trailingComment;
99
+ if (!comment)
100
+ return '';
101
+ if (comment.type == 'line_comment' && shouldBreak) {
102
+ return [' ', comment.text, hardline];
103
+ }
104
+ return [' ', comment.text];
105
+ }
106
+ function emptyBlockOrList(path, open, close, line = hardline) {
107
+ const length = path.node.nonFormattingChildren.length;
108
+ const comments = path.node.namedChildren.filter((e) => e.isComment);
109
+ if (length != 0) {
110
+ throw new Error('The list is not empty');
111
+ }
112
+ if (comments.length == 0) {
113
+ return [open, close];
114
+ }
115
+ if (comments.length == 1 && comments[0].type == 'block_comment') {
116
+ return group([open, indent(line), indent(comments[0].text), line, close]);
117
+ }
118
+ return group([
119
+ open,
120
+ indent(line),
121
+ indent(join(line, comments.map((c) => c.text))),
122
+ line,
123
+ close,
124
+ ], { shouldBreak: true });
125
+ }
126
+ /**
127
+ */
128
+ function block({ path, print, options, shouldBreak, skipChildren }) {
129
+ const length = path.node.nonFormattingChildren.length;
130
+ if (length == 0) {
131
+ return emptyBlockOrList(path, '{', '}', hardline);
132
+ }
133
+ return group([
134
+ '{',
135
+ options.bracketSpacing ? ifBreak('', ' ') : '',
136
+ indent(softline),
137
+ indent(join(line, path.map(print, 'namedAndEmptyLineChildren').slice(skipChildren))),
138
+ softline,
139
+ options.bracketSpacing ? ifBreak('', ' ') : '',
140
+ '}',
141
+ ], { shouldBreak });
142
+ }
143
+ function nonBreakingBlock({ path, print, options, shouldBreak, // always breaks
144
+ skipChildren, }) {
145
+ const length = path.node.nonFormattingChildren.length;
146
+ if (length == 0) {
147
+ return emptyBlockOrList(path, '{', '}', hardlineWithoutBreakParent);
148
+ }
149
+ return group([
150
+ '{',
151
+ indent(hardlineWithoutBreakParent),
152
+ indent(join(hardlineWithoutBreakParent, path.map(print, 'namedAndEmptyLineChildren').slice(skipChildren || 0))),
153
+ hardlineWithoutBreakParent,
154
+ '}',
155
+ ]);
156
+ }
157
+ /**
158
+ * Prints a list of non-formatting children. Handles commas and trailing comments.
159
+ * TODO: keep trailing comments after the last element of the list.
160
+ */
161
+ function list({ path, print, options, open, close, indentGroup = null, addWhitespace = false, skipChildren = 0, shouldBreak = false, }) {
162
+ const length = path.node.nonFormattingChildren.length;
163
+ const indentCb = (el) => indentGroup ? indentIfBreak(el, { groupId: indentGroup }) : indent(el);
164
+ // if there's no children the list should print, we still look up for non-
165
+ // formatting nodes, namely comments, to print them.
166
+ if (length == skipChildren) {
167
+ const lastNode = path.node.nonFormattingChildren[length - 1];
168
+ const indexInNamedChildren = path.node.namedChildren.indexOf(lastNode);
169
+ const otherNamedChildren = path.node.namedChildren
170
+ .slice(indexInNamedChildren + 1)
171
+ .filter((e) => e.isComment);
172
+ if (!otherNamedChildren.length) {
173
+ return [open, close];
174
+ }
175
+ return [
176
+ open,
177
+ indentCb(softline),
178
+ indentCb(join(hardline, otherNamedChildren.map((c) => c.text))),
179
+ hardline,
180
+ dedent(close),
181
+ ];
182
+ }
183
+ const lastNode = path.node.nonFormattingChildren[length - 1];
184
+ const indexInNamedChildren = path.node.namedChildren.indexOf(lastNode);
185
+ // collect all trailing comments
186
+ // after `nonFormattingChildren` and before end
187
+ let trailingComments = [];
188
+ if (indexInNamedChildren != -1) {
189
+ path.each((path, idx) => {
190
+ if (idx + 1 > indexInNamedChildren && path.node.isComment) {
191
+ return trailingComments.push(path.node.text);
192
+ }
193
+ return;
194
+ }, 'namedChildren');
195
+ }
196
+ return [
197
+ open,
198
+ indentCb(addWhitespace ? line : softline),
199
+ shouldBreak ? breakParent : '',
200
+ indentCb(path
201
+ .map((path, i) => {
202
+ const leading = printLeadingComment(path, options);
203
+ const comment = printTrailingComment(path, false);
204
+ let shouldBreak = false;
205
+ // if the node has a trailing comment, we should break
206
+ if (path.node.trailingComment?.type == 'line_comment') {
207
+ shouldBreak = true;
208
+ }
209
+ const leadComment = path.node.leadingComment;
210
+ if (leadComment.length > 0 && leadComment[0].type == 'line_comment') {
211
+ shouldBreak = true;
212
+ }
213
+ if (leadComment.length > 0 &&
214
+ leadComment[0].type == 'block_comment' &&
215
+ leadComment[0].newline) {
216
+ shouldBreak = true;
217
+ }
218
+ path.node.disableTrailingComment();
219
+ path.node.disableLeadingComment();
220
+ const breakExpr = shouldBreak ? breakParent : '';
221
+ const shouldDedent = trailingComments.length == 0;
222
+ const endingExpr = addWhitespace ? line : softline;
223
+ const isLastChild = i == length - 1;
224
+ if (isLastChild) {
225
+ return [
226
+ leading,
227
+ breakExpr,
228
+ print(path),
229
+ ifBreak(','),
230
+ shouldBreak ? lineSuffix(comment) : comment,
231
+ shouldDedent ? dedent(endingExpr) : endingExpr,
232
+ ];
233
+ }
234
+ // if we are not at the last child, add a comma
235
+ return [
236
+ leading,
237
+ breakExpr,
238
+ print(path),
239
+ ',',
240
+ shouldBreak ? lineSuffix(comment) : comment,
241
+ line,
242
+ ];
243
+ }, 'nonFormattingChildren')
244
+ .slice(skipChildren)
245
+ .concat(trailingComments.length
246
+ ? [join(hardline, trailingComments), dedent(hardline)]
247
+ : [])),
248
+ dedent(close),
249
+ ];
250
+ }
251
+ //# sourceMappingURL=utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":";AAAA,sCAAsC;AACtC,sCAAsC;;AAyBtC,0CAEC;AAwBD,sDAEC;AAUD,kDAqCC;AAUD,oDAWC;AAED,4CAoCC;AAmBD,sBAmBC;AAED,4CAyBC;AAoCD,oBA6HC;AA9XD,uCAA4D;AAG5D,MAAM,EACF,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,UAAU,EACV,KAAK,EACL,aAAa,EACb,0BAA0B,EAC1B,WAAW,EACX,OAAO,GACV,GAAG,cAAG,CAAC,QAAQ,CAAC;AAEjB;;GAEG;AACH,SAAgB,eAAe,CAAC,IAAmB;IAC/C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAC1B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,qBAAqB,CAAC,IAAmB;IACrD,OAAO,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,eAAe,IAAI,KAAK,CAAC;AACxE,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAAC,IAAmB,EAAE,OAAoB;IACzE,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;IAC1C,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ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