@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
@@ -0,0 +1,209 @@
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.StructDefinition = void 0;
6
+ exports.default = default_1;
7
+ exports.printNativeStructDefinition = printNativeStructDefinition;
8
+ exports.printStructDefinition = printStructDefinition;
9
+ exports.printAbilityDeclarations = printAbilityDeclarations;
10
+ exports.printPostfixAbilityDeclarations = printPostfixAbilityDeclarations;
11
+ exports.printDatatypeFields = printDatatypeFields;
12
+ exports.printNamedFields = printNamedFields;
13
+ exports.printPositionalFields = printPositionalFields;
14
+ exports.printFieldAnnotation = printFieldAnnotation;
15
+ exports.printApplyType = printApplyType;
16
+ const prettier_1 = require("prettier");
17
+ const utilities_1 = require("../utilities");
18
+ const { group, join } = prettier_1.doc.builders;
19
+ function default_1(path) {
20
+ switch (path.node.type) {
21
+ case StructDefinition.StructDefinition:
22
+ return printStructDefinition;
23
+ case StructDefinition.NativeStructDefinition:
24
+ return printNativeStructDefinition;
25
+ case StructDefinition.AbilityDeclarations:
26
+ return printAbilityDeclarations;
27
+ case StructDefinition.PostfixAbilityDeclarations:
28
+ return printPostfixAbilityDeclarations;
29
+ case StructDefinition.DatatypeFields:
30
+ return printDatatypeFields;
31
+ case StructDefinition.NamedFields:
32
+ return printNamedFields;
33
+ case StructDefinition.PositionalFields:
34
+ return printPositionalFields;
35
+ case StructDefinition.FieldAnnotation:
36
+ return printFieldAnnotation;
37
+ case StructDefinition.ApplyType:
38
+ return printApplyType;
39
+ case StructDefinition.StructIdentifier:
40
+ return utilities_1.printIdentifier;
41
+ }
42
+ return null;
43
+ }
44
+ var StructDefinition;
45
+ (function (StructDefinition) {
46
+ /**
47
+ * Module-level definition
48
+ * ```
49
+ * public struct identifier ...
50
+ * ```
51
+ */
52
+ StructDefinition["StructDefinition"] = "struct_definition";
53
+ /**
54
+ * Module-level definition (features `native` keyword and has no fields)
55
+ * ```
56
+ * native struct identifier ... ;
57
+ * ```
58
+ */
59
+ StructDefinition["NativeStructDefinition"] = "native_struct_definition";
60
+ StructDefinition["AbilityDeclarations"] = "ability_decls";
61
+ /**
62
+ * Postfix ability declarations must be printed after the fields
63
+ * and be followed by a semicolon.
64
+ * ```
65
+ * struct ident {} has store;
66
+ * struct Point(u8) has store, drop;
67
+ * ```
68
+ */
69
+ StructDefinition["PostfixAbilityDeclarations"] = "postfix_ability_decls";
70
+ StructDefinition["DatatypeFields"] = "datatype_fields";
71
+ StructDefinition["NamedFields"] = "named_fields";
72
+ StructDefinition["PositionalFields"] = "positional_fields";
73
+ StructDefinition["FieldAnnotation"] = "field_annotation";
74
+ StructDefinition["ApplyType"] = "apply_type";
75
+ StructDefinition["StructIdentifier"] = "struct_identifier";
76
+ })(StructDefinition || (exports.StructDefinition = StructDefinition = {}));
77
+ /**
78
+ * Print `struct_definition` node.
79
+ */
80
+ function printNativeStructDefinition(path, options, print) {
81
+ const isPublic = path.node.child(0).type === 'public' ? ['public', ' '] : [];
82
+ return group([
83
+ ...isPublic, // insert `public` keyword if present
84
+ 'native',
85
+ ' ',
86
+ 'struct',
87
+ ' ',
88
+ path.map(print, 'nonFormattingChildren'),
89
+ ';',
90
+ ]);
91
+ }
92
+ /**
93
+ * Print `struct_definition` node.
94
+ * Insert a newline before the comment if the previous node is not a line comment.
95
+ */
96
+ function printStructDefinition(path, options, print) {
97
+ const isPublic = path.node.child(0).type === 'public' ? ['public', ' '] : [];
98
+ return group([
99
+ ...isPublic, // insert `public` keyword if present
100
+ 'struct',
101
+ ' ',
102
+ path.map(print, 'nonFormattingChildren'),
103
+ ]);
104
+ }
105
+ /**
106
+ * Print `ability_decls` node.
107
+ */
108
+ function printAbilityDeclarations(path, options, print) {
109
+ const abilities = formatAndSortAbilities(path, options, print);
110
+ return [
111
+ ' has ',
112
+ join(', ', abilities.map((ability) => ability.text)),
113
+ path.next?.namedChildren[0]?.type === StructDefinition.PositionalFields ? ' ' : '',
114
+ ];
115
+ }
116
+ /**
117
+ * Print `postfix_ability_decls` node.
118
+ */
119
+ function printPostfixAbilityDeclarations(path, options, print) {
120
+ const abilities = formatAndSortAbilities(path, options, print);
121
+ return group([
122
+ ' has ',
123
+ join(', ', abilities.map((ability) => ability.text)),
124
+ ';',
125
+ ]);
126
+ }
127
+ /**
128
+ * Print `datatype_fields` node.
129
+ * Prints the underlying fields of a datatype.
130
+ */
131
+ function printDatatypeFields(path, options, print) {
132
+ return path.map(print, 'nonFormattingChildren');
133
+ }
134
+ /**
135
+ * Print `named_fields` node.
136
+ * Prints the underlying fields of a struct.
137
+ */
138
+ function printNamedFields(path, options, print) {
139
+ const children = path.map(print, 'nonFormattingChildren');
140
+ if (children.length === 0) {
141
+ return [' ', (0, utilities_1.emptyBlockOrList)(path, '{', '}', prettier_1.doc.builders.line)];
142
+ }
143
+ return [
144
+ ' ',
145
+ group((0, utilities_1.list)({ path, print, options, open: '{', close: '}', addWhitespace: true }), {
146
+ shouldBreak: (0, utilities_1.shouldBreakFirstChild)(path),
147
+ }),
148
+ ];
149
+ }
150
+ /**
151
+ * Print `positional_fields` node.
152
+ * Prints the underlying fields of a struct.
153
+ */
154
+ function printPositionalFields(path, options, print) {
155
+ const children = path.map(print, 'nonFormattingChildren');
156
+ if (children.length === 0) {
157
+ return (0, utilities_1.emptyBlockOrList)(path, '(', ')', prettier_1.doc.builders.line);
158
+ }
159
+ return group((0, utilities_1.list)({ path, print, options, open: '(', close: ')' }), {
160
+ shouldBreak: false,
161
+ });
162
+ }
163
+ /**
164
+ * Print `field_annotation` node.
165
+ */
166
+ function printFieldAnnotation(path, options, print) {
167
+ return group([
168
+ path.call(print, 'nonFormattingChildren', 0), // field_identifier
169
+ ':',
170
+ ' ',
171
+ path.call(print, 'nonFormattingChildren', 1), // type
172
+ ]);
173
+ }
174
+ /**
175
+ * Print `apply_type` node.
176
+ */
177
+ function printApplyType(path, options, print) {
178
+ return path.map(print, 'nonFormattingChildren');
179
+ }
180
+ /**
181
+ * Utility function which formats and sorts abilities in the following order::
182
+ *
183
+ * - key
184
+ * - copy
185
+ * - drop
186
+ * - store
187
+ *
188
+ * Key always goes first, the rest are sorted alphabetically.
189
+ */
190
+ function formatAndSortAbilities(path, options, print) {
191
+ const abilities = path.map((path) => ({
192
+ name: path.node.text,
193
+ text: [
194
+ (0, utilities_1.printLeadingComment)(path, options),
195
+ path.node.text,
196
+ (0, utilities_1.printTrailingComment)(path, true),
197
+ ],
198
+ }), 'nonFormattingChildren');
199
+ // alphabetical but `key` always goes first
200
+ const priority = {
201
+ key: 0,
202
+ copy: 1,
203
+ drop: 2,
204
+ store: 3,
205
+ };
206
+ abilities.sort((a, b) => priority[a.name] - priority[b.name]);
207
+ return abilities;
208
+ }
209
+ //# sourceMappingURL=struct_definition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"struct_definition.js","sourceRoot":"","sources":["../../src/cst/struct_definition.ts"],"names":[],"mappings":";AAAA,sCAAsC;AACtC,sCAAsC;;;AAetC,4BAyBC;AAsCD,kEAeC;AAMD,sDAYC;AAOD,4DAcC;AAKD,0EAcC;AAMD,kDAMC;AAMD,4CAaC;AAMD,sDAcC;AAKD,oDAWC;AAKD,wCAEC;AA7ND,uCAA4D;AAC5D,4CAOsB;AACtB,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,cAAG,CAAC,QAAQ,CAAC;AAErC,mBAAyB,IAAmB;IACxC,QAAQ,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,gBAAgB,CAAC,gBAAgB;YAClC,OAAO,qBAAqB,CAAC;QACjC,KAAK,gBAAgB,CAAC,sBAAsB;YACxC,OAAO,2BAA2B,CAAC;QACvC,KAAK,gBAAgB,CAAC,mBAAmB;YACrC,OAAO,wBAAwB,CAAC;QACpC,KAAK,gBAAgB,CAAC,0BAA0B;YAC5C,OAAO,+BAA+B,CAAC;QAC3C,KAAK,gBAAgB,CAAC,cAAc;YAChC,OAAO,mBAAmB,CAAC;QAC/B,KAAK,gBAAgB,CAAC,WAAW;YAC7B,OAAO,gBAAgB,CAAC;QAC5B,KAAK,gBAAgB,CAAC,gBAAgB;YAClC,OAAO,qBAAqB,CAAC;QACjC,KAAK,gBAAgB,CAAC,eAAe;YACjC,OAAO,oBAAoB,CAAC;QAChC,KAAK,gBAAgB,CAAC,SAAS;YAC3B,OAAO,cAAc,CAAC;QAC1B,KAAK,gBAAgB,CAAC,gBAAgB;YAClC,OAAO,2BAAe,CAAC;IAC/B,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,IAAY,gBA+BX;AA/BD,WAAY,gBAAgB;IACxB;;;;;OAKG;IACH,0DAAsC,CAAA;IACt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,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,sBAAsB,CAC3B,IAAmB,EACnB,OAAoB,EACpB,KAAc;IAEd,MAAM,SAAS,GAAc,IAAI,CAAC,GAAG,CACjC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACP,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAuB;QACvC,IAAI,EAAE;YACF,IAAA,+BAAmB,EAAC,IAAI,EAAE,OAAO,CAAC;YAClC,IAAI,CAAC,IAAI,CAAC,IAAI;YACd,IAAA,gCAAoB,EAAC,IAAI,EAAE,IAAI,CAAC;SAC5B;KACX,CAAC,EACF,uBAAuB,CAC1B,CAAC;IAEF,2CAA2C;IAC3C,MAAM,QAAQ,GAAG;QACb,GAAG,EAAE,CAAC;QACN,IAAI,EAAE,CAAC;QACP,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,CAAC;KACX,CAAC;IAEF,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAE9D,OAAO,SAAS,CAAC;AACrB,CAAC"}
@@ -0,0 +1,212 @@
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.UseDeclaration = void 0;
6
+ exports.default = default_1;
7
+ exports.printUseDeclaration = printUseDeclaration;
8
+ exports.printUseFun = printUseFun;
9
+ exports.printFriendDeclaration = printFriendDeclaration;
10
+ exports.printFriendAccess = printFriendAccess;
11
+ exports.printUseModule = printUseModule;
12
+ exports.printUseMember = printUseMember;
13
+ exports.printUseModuleMember = printUseModuleMember;
14
+ exports.printUseModuleMembers = printUseModuleMembers;
15
+ exports.printModuleIdentity = printModuleIdentity;
16
+ exports.isUseImport = isUseImport;
17
+ const prettier_1 = require("prettier");
18
+ const { group, indent, line, softline, ifBreak, join } = prettier_1.doc.builders;
19
+ function default_1(path) {
20
+ switch (path.node.type) {
21
+ case UseDeclaration.UseDeclaration:
22
+ return printUseDeclaration;
23
+ case UseDeclaration.UseModule:
24
+ return printUseModule;
25
+ case UseDeclaration.UseMember:
26
+ return printUseMember;
27
+ case UseDeclaration.UseModuleMember:
28
+ return printUseModuleMember;
29
+ case UseDeclaration.UseModuleMembers:
30
+ return printUseModuleMembers;
31
+ case UseDeclaration.UseFun:
32
+ return printUseFun;
33
+ case UseDeclaration.ModuleIdentity:
34
+ return printModuleIdentity;
35
+ case UseDeclaration.FriendDeclaration:
36
+ return printFriendDeclaration;
37
+ case UseDeclaration.FriendAccess:
38
+ return printFriendAccess;
39
+ default:
40
+ return null;
41
+ }
42
+ }
43
+ /**
44
+ * Use Declaration
45
+ *
46
+ * Contains one of the following:
47
+ *
48
+ * `use_declaration` (
49
+ * - use `use_module` <as `alias`>;
50
+ * - use `use_module_member` <as `use_member`>;
51
+ * - use `use_module_members`;
52
+ * - use `use_fun`;
53
+ * )
54
+ *
55
+ * `use_member` (
56
+ * - `identifier` <as `alias`>;
57
+ * )
58
+ */
59
+ var UseDeclaration;
60
+ (function (UseDeclaration) {
61
+ /**
62
+ * Module-level definition
63
+ * ```
64
+ * `<public> use ...;
65
+ * ```
66
+ */
67
+ UseDeclaration["UseDeclaration"] = "use_declaration";
68
+ UseDeclaration["FriendDeclaration"] = "friend_declaration";
69
+ UseDeclaration["FriendAccess"] = "friend_access";
70
+ UseDeclaration["UseFun"] = "use_fun";
71
+ // all of the nodes below are implemented in `import-grouping.ts`
72
+ // hence should never be printed directly.
73
+ UseDeclaration["UseModule"] = "use_module";
74
+ UseDeclaration["UseMember"] = "use_member";
75
+ UseDeclaration["UseModuleMember"] = "use_module_member";
76
+ UseDeclaration["UseModuleMembers"] = "use_module_members";
77
+ UseDeclaration["ModuleIdentity"] = "module_identity";
78
+ })(UseDeclaration || (exports.UseDeclaration = UseDeclaration = {}));
79
+ /**
80
+ * Print @see `UseDeclaration.UseDeclaration` node.
81
+ */
82
+ function printUseDeclaration(path, options, print) {
83
+ const firstChild = path.node.child(0);
84
+ const isPublic = firstChild && firstChild.type === 'public' ? ['public', ' '] : [];
85
+ return [
86
+ ...isPublic, // insert `public` keyword if present
87
+ 'use ',
88
+ path.call(print, 'nonFormattingChildren', 0),
89
+ ';',
90
+ ];
91
+ }
92
+ /**
93
+ * Print `use_fun` node `module_access` as `module_access`.`function_identifier`
94
+ */
95
+ function printUseFun(path, options, print) {
96
+ return group([
97
+ 'fun ',
98
+ path.call(print, 'nonFormattingChildren', 0), // module_access
99
+ ' as',
100
+ indent(line),
101
+ path.call(print, 'nonFormattingChildren', 1), // module_access
102
+ '.',
103
+ path.call(print, 'nonFormattingChildren', 2), // function_identifier
104
+ ]);
105
+ }
106
+ /**
107
+ * Print `friend_declaration` node.
108
+ */
109
+ function printFriendDeclaration(path, options, print) {
110
+ return group([
111
+ 'friend',
112
+ indent(line),
113
+ path.call(print, 'nonFormattingChildren', 0), // module_access
114
+ ';',
115
+ ]);
116
+ }
117
+ /**
118
+ * Print `friend_access` node.
119
+ */
120
+ function printFriendAccess(path, options, print) {
121
+ return path.map(print, 'nonFormattingChildren');
122
+ }
123
+ /**
124
+ * Print `use_module` node. `module_name`
125
+ * Currently only used for `use` with annotations.
126
+ */
127
+ function printUseModule(path, options, print) {
128
+ return path.map((e) => {
129
+ if (e.node.type == 'as')
130
+ return ' as ';
131
+ return print(e);
132
+ }, 'children');
133
+ }
134
+ /**
135
+ * Print `use_member` node. `member_name`
136
+ * Currently only used for `use` with annotations.
137
+ */
138
+ function printUseMember(path, options, print) {
139
+ const isGroup = path.node.children.findIndex((e) => e.type == '{');
140
+ // not found `::{...}`
141
+ if (isGroup == -1) {
142
+ return group(path.map((e) => {
143
+ if (e.node.type == 'as')
144
+ return ' as ';
145
+ if (e.node.type == ',')
146
+ return [',', line];
147
+ return print(e);
148
+ }, 'children'));
149
+ }
150
+ const children = path.map(print, 'nonFormattingChildren');
151
+ return group([
152
+ children[0],
153
+ '::{',
154
+ indent(softline),
155
+ indent(join([',', line], children.slice(1))),
156
+ ifBreak(','), // trailing comma
157
+ softline,
158
+ '}',
159
+ ]);
160
+ }
161
+ /**
162
+ * Print `use_module_member` node. `module_name::member_name`
163
+ * Single statement of direct import;
164
+ * `use address::module_name::member_name;`
165
+ *
166
+ * Wraps the member into a group `{}` if it's too long (if line breaks).
167
+ * Currently only used for `use` with annotations.
168
+ */
169
+ function printUseModuleMember(path, options, print) {
170
+ return group([
171
+ path.call(print, 'nonFormattingChildren', 0), // module_access
172
+ '::',
173
+ ifBreak(['{', indent(line)]), // wrap with `{` if the member is too long
174
+ indent(path.call(print, 'nonFormattingChildren', 1)), // module_access
175
+ ifBreak([line, '}']), // trailing comma
176
+ ]);
177
+ }
178
+ /**
179
+ * Print `use_module_members` node. `module_identity::{member_name, member_name}`
180
+ * Currently only used for `use` with annotations.
181
+ */
182
+ function printUseModuleMembers(path, options, print) {
183
+ const children = path.map(print, 'nonFormattingChildren');
184
+ return group([
185
+ children[0],
186
+ '::{',
187
+ indent(softline),
188
+ indent(join([',', line], children.slice(1))),
189
+ ifBreak(','), // trailing comma
190
+ softline,
191
+ '}',
192
+ ]);
193
+ }
194
+ /**
195
+ * Print the `module_identity` node. `module_identifier::module_name`.
196
+ * Is present in the `use_module_member` and `use_module_members` nodes.
197
+ * Currently only used for `use` with annotations.
198
+ */
199
+ function printModuleIdentity(path, options, print) {
200
+ return join('::', path.map(print, 'nonFormattingChildren'));
201
+ }
202
+ /**
203
+ * Checks whether the given path is a `use` import.
204
+ */
205
+ function isUseImport(node) {
206
+ const firstChild = node.nonFormattingChildren[0];
207
+ return (node.type === UseDeclaration.UseDeclaration &&
208
+ (firstChild.type === UseDeclaration.UseModule ||
209
+ firstChild.type === UseDeclaration.UseModuleMember ||
210
+ firstChild.type === UseDeclaration.UseModuleMembers));
211
+ }
212
+ //# sourceMappingURL=use_declaration.js.map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