@openrewrite/rewrite 8.72.2 → 8.72.4

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 (197) hide show
  1. package/dist/execution.js +3 -16
  2. package/dist/execution.js.map +1 -1
  3. package/dist/index.js +34 -49
  4. package/dist/index.js.map +1 -1
  5. package/dist/java/markers.js +12 -29
  6. package/dist/java/markers.js.map +1 -1
  7. package/dist/java/print.js +2 -13
  8. package/dist/java/print.js.map +1 -1
  9. package/dist/java/rpc.js +1344 -1725
  10. package/dist/java/rpc.js.map +1 -1
  11. package/dist/java/type-visitor.js +143 -184
  12. package/dist/java/type-visitor.js.map +1 -1
  13. package/dist/java/visitor.js +1072 -1249
  14. package/dist/java/visitor.js.map +1 -1
  15. package/dist/javascript/add-import.js +495 -534
  16. package/dist/javascript/add-import.js.map +1 -1
  17. package/dist/javascript/autodetect.js +116 -159
  18. package/dist/javascript/autodetect.js.map +1 -1
  19. package/dist/javascript/cleanup/add-parse-int-radix.js +41 -57
  20. package/dist/javascript/cleanup/add-parse-int-radix.js.map +1 -1
  21. package/dist/javascript/cleanup/prefer-optional-chain.js +89 -105
  22. package/dist/javascript/cleanup/prefer-optional-chain.js.map +1 -1
  23. package/dist/javascript/cleanup/use-object-property-shorthand.js +74 -95
  24. package/dist/javascript/cleanup/use-object-property-shorthand.js.map +1 -1
  25. package/dist/javascript/comparator.js +815 -1167
  26. package/dist/javascript/comparator.js.map +1 -1
  27. package/dist/javascript/dependency-workspace.js +206 -219
  28. package/dist/javascript/dependency-workspace.js.map +1 -1
  29. package/dist/javascript/format/format.js +682 -908
  30. package/dist/javascript/format/format.js.map +1 -1
  31. package/dist/javascript/format/minimum-viable-spacing-visitor.js +152 -231
  32. package/dist/javascript/format/minimum-viable-spacing-visitor.js.map +1 -1
  33. package/dist/javascript/format/normalize-whitespace-visitor.js +12 -31
  34. package/dist/javascript/format/normalize-whitespace-visitor.js.map +1 -1
  35. package/dist/javascript/format/prettier-config-loader.js +134 -153
  36. package/dist/javascript/format/prettier-config-loader.js.map +1 -1
  37. package/dist/javascript/format/prettier-format.js +112 -129
  38. package/dist/javascript/format/prettier-format.js.map +1 -1
  39. package/dist/javascript/format/tabs-and-indents-visitor.js +112 -136
  40. package/dist/javascript/format/tabs-and-indents-visitor.js.map +1 -1
  41. package/dist/javascript/markers.js +59 -92
  42. package/dist/javascript/markers.js.map +1 -1
  43. package/dist/javascript/migrate/es6/modernize-octal-escape-sequences.js +39 -52
  44. package/dist/javascript/migrate/es6/modernize-octal-escape-sequences.js.map +1 -1
  45. package/dist/javascript/migrate/es6/modernize-octal-literals.js +25 -38
  46. package/dist/javascript/migrate/es6/modernize-octal-literals.js.map +1 -1
  47. package/dist/javascript/migrate/es6/remove-duplicate-object-keys.js +66 -82
  48. package/dist/javascript/migrate/es6/remove-duplicate-object-keys.js.map +1 -1
  49. package/dist/javascript/migrate/typescript/export-assignment-to-export-default.js +10 -23
  50. package/dist/javascript/migrate/typescript/export-assignment-to-export-default.js.map +1 -1
  51. package/dist/javascript/node-resolution-result.js +137 -166
  52. package/dist/javascript/node-resolution-result.js.map +1 -1
  53. package/dist/javascript/package-json-parser.js +312 -343
  54. package/dist/javascript/package-json-parser.js.map +1 -1
  55. package/dist/javascript/package-manager.js +145 -170
  56. package/dist/javascript/package-manager.js.map +1 -1
  57. package/dist/javascript/parser.d.ts.map +1 -1
  58. package/dist/javascript/parser.js +94 -68
  59. package/dist/javascript/parser.js.map +1 -1
  60. package/dist/javascript/print.js +1572 -1835
  61. package/dist/javascript/print.js.map +1 -1
  62. package/dist/javascript/project-parser.js +151 -172
  63. package/dist/javascript/project-parser.js.map +1 -1
  64. package/dist/javascript/recipes/add-dependency.js +140 -175
  65. package/dist/javascript/recipes/add-dependency.js.map +1 -1
  66. package/dist/javascript/recipes/async-callback-in-sync-array-method.js +20 -36
  67. package/dist/javascript/recipes/async-callback-in-sync-array-method.js.map +1 -1
  68. package/dist/javascript/recipes/auto-format.js +3 -14
  69. package/dist/javascript/recipes/auto-format.js.map +1 -1
  70. package/dist/javascript/recipes/change-import.js +447 -495
  71. package/dist/javascript/recipes/change-import.js.map +1 -1
  72. package/dist/javascript/recipes/order-imports.js +162 -175
  73. package/dist/javascript/recipes/order-imports.js.map +1 -1
  74. package/dist/javascript/recipes/upgrade-dependency-version.js +167 -197
  75. package/dist/javascript/recipes/upgrade-dependency-version.js.map +1 -1
  76. package/dist/javascript/recipes/upgrade-transitive-dependency-version.js +166 -193
  77. package/dist/javascript/recipes/upgrade-transitive-dependency-version.js.map +1 -1
  78. package/dist/javascript/remove-import.js +689 -724
  79. package/dist/javascript/remove-import.js.map +1 -1
  80. package/dist/javascript/rpc.js +1007 -1332
  81. package/dist/javascript/rpc.js.map +1 -1
  82. package/dist/javascript/search/find-dependency.js +84 -110
  83. package/dist/javascript/search/find-dependency.js.map +1 -1
  84. package/dist/javascript/search/uses-method.js +5 -19
  85. package/dist/javascript/search/uses-method.js.map +1 -1
  86. package/dist/javascript/search/uses-type.js +9 -20
  87. package/dist/javascript/search/uses-type.js.map +1 -1
  88. package/dist/javascript/templating/comparator.js +737 -822
  89. package/dist/javascript/templating/comparator.js.map +1 -1
  90. package/dist/javascript/templating/engine.js +211 -245
  91. package/dist/javascript/templating/engine.js.map +1 -1
  92. package/dist/javascript/templating/pattern.js +169 -190
  93. package/dist/javascript/templating/pattern.js.map +1 -1
  94. package/dist/javascript/templating/placeholder-replacement.js +172 -210
  95. package/dist/javascript/templating/placeholder-replacement.js.map +1 -1
  96. package/dist/javascript/templating/rewrite.js +75 -97
  97. package/dist/javascript/templating/rewrite.js.map +1 -1
  98. package/dist/javascript/templating/template.js +69 -82
  99. package/dist/javascript/templating/template.js.map +1 -1
  100. package/dist/javascript/tree-debug.js +109 -137
  101. package/dist/javascript/tree-debug.js.map +1 -1
  102. package/dist/javascript/visitor.js +1090 -1254
  103. package/dist/javascript/visitor.js.map +1 -1
  104. package/dist/json/print.js +72 -103
  105. package/dist/json/print.js.map +1 -1
  106. package/dist/json/rpc.js +120 -181
  107. package/dist/json/rpc.js.map +1 -1
  108. package/dist/json/visitor.js +69 -100
  109. package/dist/json/visitor.js.map +1 -1
  110. package/dist/marketplace.js +20 -33
  111. package/dist/marketplace.js.map +1 -1
  112. package/dist/parse-error.js +41 -62
  113. package/dist/parse-error.js.map +1 -1
  114. package/dist/parser.js +7 -18
  115. package/dist/parser.js.map +1 -1
  116. package/dist/path-utils.js +46 -59
  117. package/dist/path-utils.js.map +1 -1
  118. package/dist/preconditions.js +30 -47
  119. package/dist/preconditions.js.map +1 -1
  120. package/dist/print.js +6 -19
  121. package/dist/print.js.map +1 -1
  122. package/dist/recipe.js +42 -73
  123. package/dist/recipe.js.map +1 -1
  124. package/dist/rpc/index.js +74 -115
  125. package/dist/rpc/index.js.map +1 -1
  126. package/dist/rpc/queue.js +71 -90
  127. package/dist/rpc/queue.js.map +1 -1
  128. package/dist/rpc/recipe.js +32 -57
  129. package/dist/rpc/recipe.js.map +1 -1
  130. package/dist/rpc/request/generate.js +4 -13
  131. package/dist/rpc/request/generate.js.map +1 -1
  132. package/dist/rpc/request/get-languages.js +2 -11
  133. package/dist/rpc/request/get-languages.js.map +1 -1
  134. package/dist/rpc/request/get-marketplace.js +9 -20
  135. package/dist/rpc/request/get-marketplace.js.map +1 -1
  136. package/dist/rpc/request/get-object.js +4 -13
  137. package/dist/rpc/request/get-object.js.map +1 -1
  138. package/dist/rpc/request/install-recipes.js +25 -36
  139. package/dist/rpc/request/install-recipes.js.map +1 -1
  140. package/dist/rpc/request/metrics.js +8 -17
  141. package/dist/rpc/request/metrics.js.map +1 -1
  142. package/dist/rpc/request/parse-project.js +36 -45
  143. package/dist/rpc/request/parse-project.js.map +1 -1
  144. package/dist/rpc/request/parse.js +5 -14
  145. package/dist/rpc/request/parse.js.map +1 -1
  146. package/dist/rpc/request/prepare-recipe.js +37 -52
  147. package/dist/rpc/request/prepare-recipe.js.map +1 -1
  148. package/dist/rpc/request/print.js +5 -14
  149. package/dist/rpc/request/print.js.map +1 -1
  150. package/dist/rpc/request/visit.js +56 -71
  151. package/dist/rpc/request/visit.js.map +1 -1
  152. package/dist/rpc/rewrite-rpc.js +70 -97
  153. package/dist/rpc/rewrite-rpc.js.map +1 -1
  154. package/dist/rpc/server.js +76 -89
  155. package/dist/rpc/server.js.map +1 -1
  156. package/dist/run.js +47 -66
  157. package/dist/run.js.map +1 -1
  158. package/dist/search/is-source-file.js +8 -19
  159. package/dist/search/is-source-file.js.map +1 -1
  160. package/dist/test/rewrite-test.js +154 -188
  161. package/dist/test/rewrite-test.js.map +1 -1
  162. package/dist/text/print.js +23 -38
  163. package/dist/text/print.js.map +1 -1
  164. package/dist/text/rpc.js +29 -44
  165. package/dist/text/rpc.js.map +1 -1
  166. package/dist/text/visitor.js +16 -33
  167. package/dist/text/visitor.js.map +1 -1
  168. package/dist/util.js +13 -24
  169. package/dist/util.js.map +1 -1
  170. package/dist/version.txt +1 -1
  171. package/dist/visitor.js +84 -115
  172. package/dist/visitor.js.map +1 -1
  173. package/dist/yaml/index.d.ts +2 -0
  174. package/dist/yaml/index.d.ts.map +1 -1
  175. package/dist/yaml/index.js +2 -0
  176. package/dist/yaml/index.js.map +1 -1
  177. package/dist/yaml/markers.d.ts +21 -0
  178. package/dist/yaml/markers.d.ts.map +1 -0
  179. package/dist/yaml/markers.js +37 -0
  180. package/dist/yaml/markers.js.map +1 -0
  181. package/dist/yaml/parser.d.ts.map +1 -1
  182. package/dist/yaml/parser.js +4 -1
  183. package/dist/yaml/parser.js.map +1 -1
  184. package/dist/yaml/print.d.ts +1 -1
  185. package/dist/yaml/print.d.ts.map +1 -1
  186. package/dist/yaml/print.js +175 -208
  187. package/dist/yaml/print.js.map +1 -1
  188. package/dist/yaml/rpc.js +154 -219
  189. package/dist/yaml/rpc.js.map +1 -1
  190. package/dist/yaml/visitor.js +78 -113
  191. package/dist/yaml/visitor.js.map +1 -1
  192. package/package.json +1 -1
  193. package/src/javascript/parser.ts +56 -14
  194. package/src/yaml/index.ts +2 -0
  195. package/src/yaml/markers.ts +70 -0
  196. package/src/yaml/parser.ts +5 -1
  197. package/src/yaml/print.ts +5 -2
@@ -1,14 +1,5 @@
1
1
  "use strict";
2
2
  // noinspection DuplicatedCode
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
3
  Object.defineProperty(exports, "__esModule", { value: true });
13
4
  exports.JavaScriptPrinter = void 0;
14
5
  /*
@@ -37,1704 +28,1480 @@ class JavaScriptPrinter extends visitor_1.JavaScriptVisitor {
37
28
  super(...arguments);
38
29
  this.JAVA_SCRIPT_MARKER_WRAPPER = (out) => `/*~~${out}${out.length === 0 ? "" : "~~"}>*/`;
39
30
  }
40
- visitJsCompilationUnit(cu, p) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- yield this.beforeSyntax(cu, p);
43
- yield this.visitRightPaddedLocal(cu.statements, "", p);
44
- yield this.visitSpace(cu.eof, p);
45
- yield this.afterSyntax(cu, p);
46
- return cu;
47
- });
48
- }
49
- visitAlias(alias, p) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- yield this.beforeSyntax(alias, p);
52
- yield this.visitRightPadded(alias.propertyName, p);
53
- p.append("as");
54
- yield this.visit(alias.alias, p);
55
- yield this.afterSyntax(alias, p);
56
- return alias;
57
- });
58
- }
59
- visitAwait(awaitExpr, p) {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- yield this.beforeSyntax(awaitExpr, p);
62
- p.append("await");
63
- yield this.visit(awaitExpr.expression, p);
64
- yield this.afterSyntax(awaitExpr, p);
65
- return awaitExpr;
66
- });
67
- }
68
- visitBindingElement(binding, p) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- yield this.beforeSyntax(binding, p);
71
- if (binding.propertyName) {
72
- yield this.visitRightPadded(binding.propertyName, p);
73
- p.append(":");
74
- }
75
- yield this.visit(binding.name, p);
76
- binding.initializer && (yield this.visitLeftPaddedLocal("=", binding.initializer, p));
77
- yield this.afterSyntax(binding, p);
78
- return binding;
79
- });
80
- }
81
- visitDelete(del, p) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- yield this.beforeSyntax(del, p);
84
- p.append("delete");
85
- yield this.visit(del.expression, p);
86
- yield this.afterSyntax(del, p);
87
- return del;
88
- });
89
- }
90
- visitExpressionStatement(statement, p) {
91
- return __awaiter(this, void 0, void 0, function* () {
92
- yield this.beforeSyntax(statement, p);
93
- yield this.visit(statement.expression, p);
94
- yield this.afterSyntax(statement, p);
95
- return statement;
96
- });
97
- }
98
- visitStatementExpression(statementExpression, p) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- yield this.beforeSyntax(statementExpression, p);
101
- yield this.visit(statementExpression.statement, p);
102
- yield this.afterSyntax(statementExpression, p);
103
- return statementExpression;
104
- });
105
- }
106
- visitSpread(spread, p) {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- yield this.beforeSyntax(spread, p);
109
- p.append("...");
110
- yield this.visit(spread.expression, p);
111
- yield this.afterSyntax(spread, p);
112
- return spread;
113
- });
114
- }
115
- visitInferType(inferType, p) {
116
- return __awaiter(this, void 0, void 0, function* () {
117
- yield this.beforeSyntax(inferType, p);
118
- yield this.visitLeftPaddedLocal("infer", inferType.typeParameter, p);
119
- yield this.afterSyntax(inferType, p);
120
- return inferType;
121
- });
122
- }
123
- visitJsxTag(element, p) {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- yield this.beforeSyntax(element, p);
126
- // Print < first, then the space after < (openName.before), then the tag name
127
- p.append("<");
128
- yield this.visitSpace(element.openName.before, p);
129
- yield this.visit(element.openName.element, p);
130
- if (element.typeArguments) {
131
- yield this.visitContainerLocal("<", element.typeArguments, ",", ">", p);
132
- }
133
- yield this.visitSpace(element.afterName, p);
134
- yield this.visitRightPaddedLocal(element.attributes, "", p);
135
- if (element.selfClosing) {
136
- yield this.visitSpace(element.selfClosing, p);
137
- p.append("/>");
138
- }
139
- else {
140
- p.append(">");
141
- if (element.children) {
142
- for (let i = 0; i < element.children.length; i++) {
143
- yield this.visit(element.children[i], p);
144
- }
145
- // Print </ first, then the space after </ (closingName.before), then the tag name
146
- p.append("</");
147
- yield this.visitSpace(element.closingName.before, p);
148
- yield this.visit(element.closingName.element, p);
149
- yield this.visitSpace(element.afterClosingName, p);
150
- p.append(">");
151
- }
152
- }
153
- yield this.afterSyntax(element, p);
154
- return element;
155
- });
156
- }
157
- visitJsxAttribute(attribute, p) {
158
- return __awaiter(this, void 0, void 0, function* () {
159
- yield this.beforeSyntax(attribute, p);
160
- yield this.visit(attribute.key, p);
161
- if (attribute.value) {
162
- p.append("=");
163
- yield this.visit(attribute.value.element, p);
164
- }
165
- yield this.afterSyntax(attribute, p);
166
- return attribute;
167
- });
168
- }
169
- visitJsxSpreadAttribute(spread, p) {
170
- return __awaiter(this, void 0, void 0, function* () {
171
- yield this.beforeSyntax(spread, p);
172
- p.append("{");
173
- yield this.visitSpace(spread.dots, p);
174
- p.append("...");
175
- yield this.visitRightPaddedLocal([spread.expression], "}", p);
176
- p.append("}");
177
- yield this.afterSyntax(spread, p);
178
- return spread;
179
- });
180
- }
181
- visitJsxEmbeddedExpression(expr, p) {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- yield this.beforeSyntax(expr, p);
184
- p.append("{");
185
- if (expr.expression) {
186
- yield this.visitRightPaddedLocal([expr.expression], "}", p);
187
- }
188
- p.append("}");
189
- yield this.afterSyntax(expr, p);
190
- return expr;
191
- });
192
- }
193
- visitJsxNamespacedName(ns, p) {
194
- return __awaiter(this, void 0, void 0, function* () {
195
- yield this.beforeSyntax(ns, p);
196
- yield this.visit(ns.namespace, p);
31
+ async visitJsCompilationUnit(cu, p) {
32
+ await this.beforeSyntax(cu, p);
33
+ await this.visitRightPaddedLocal(cu.statements, "", p);
34
+ await this.visitSpace(cu.eof, p);
35
+ await this.afterSyntax(cu, p);
36
+ return cu;
37
+ }
38
+ async visitAlias(alias, p) {
39
+ await this.beforeSyntax(alias, p);
40
+ await this.visitRightPadded(alias.propertyName, p);
41
+ p.append("as");
42
+ await this.visit(alias.alias, p);
43
+ await this.afterSyntax(alias, p);
44
+ return alias;
45
+ }
46
+ async visitAwait(awaitExpr, p) {
47
+ await this.beforeSyntax(awaitExpr, p);
48
+ p.append("await");
49
+ await this.visit(awaitExpr.expression, p);
50
+ await this.afterSyntax(awaitExpr, p);
51
+ return awaitExpr;
52
+ }
53
+ async visitBindingElement(binding, p) {
54
+ await this.beforeSyntax(binding, p);
55
+ if (binding.propertyName) {
56
+ await this.visitRightPadded(binding.propertyName, p);
197
57
  p.append(":");
198
- yield this.visitLeftPadded(ns.name, p);
199
- yield this.afterSyntax(ns, p);
200
- return ns;
201
- });
202
- }
203
- visitImportDeclaration(jsImport, p) {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- for (const it of jsImport.modifiers) {
206
- yield this.visitDefined(it, p);
207
- }
208
- yield this.beforeSyntax(jsImport, p);
209
- p.append("import");
210
- jsImport.importClause && (yield this.visit(jsImport.importClause, p));
211
- yield this.visitLeftPaddedLocal(jsImport.importClause ? "from" : "", jsImport.moduleSpecifier, p);
212
- jsImport.attributes && (yield this.visit(jsImport.attributes, p));
213
- if (jsImport.initializer) {
214
- p.append("=");
215
- yield this.visitLeftPadded(jsImport.initializer, p);
216
- }
217
- yield this.afterSyntax(jsImport, p);
218
- return jsImport;
219
- });
220
- }
221
- visitImportClause(jsImportClause, p) {
222
- return __awaiter(this, void 0, void 0, function* () {
223
- yield this.beforeSyntax(jsImportClause, p);
224
- if (jsImportClause.typeOnly) {
225
- p.append("type");
226
- }
227
- if (jsImportClause.name) {
228
- yield this.visitRightPadded(jsImportClause.name, p);
229
- if (jsImportClause.namedBindings) {
230
- p.append(",");
58
+ }
59
+ await this.visit(binding.name, p);
60
+ binding.initializer && await this.visitLeftPaddedLocal("=", binding.initializer, p);
61
+ await this.afterSyntax(binding, p);
62
+ return binding;
63
+ }
64
+ async visitDelete(del, p) {
65
+ await this.beforeSyntax(del, p);
66
+ p.append("delete");
67
+ await this.visit(del.expression, p);
68
+ await this.afterSyntax(del, p);
69
+ return del;
70
+ }
71
+ async visitExpressionStatement(statement, p) {
72
+ await this.beforeSyntax(statement, p);
73
+ await this.visit(statement.expression, p);
74
+ await this.afterSyntax(statement, p);
75
+ return statement;
76
+ }
77
+ async visitStatementExpression(statementExpression, p) {
78
+ await this.beforeSyntax(statementExpression, p);
79
+ await this.visit(statementExpression.statement, p);
80
+ await this.afterSyntax(statementExpression, p);
81
+ return statementExpression;
82
+ }
83
+ async visitSpread(spread, p) {
84
+ await this.beforeSyntax(spread, p);
85
+ p.append("...");
86
+ await this.visit(spread.expression, p);
87
+ await this.afterSyntax(spread, p);
88
+ return spread;
89
+ }
90
+ async visitInferType(inferType, p) {
91
+ await this.beforeSyntax(inferType, p);
92
+ await this.visitLeftPaddedLocal("infer", inferType.typeParameter, p);
93
+ await this.afterSyntax(inferType, p);
94
+ return inferType;
95
+ }
96
+ async visitJsxTag(element, p) {
97
+ await this.beforeSyntax(element, p);
98
+ // Print < first, then the space after < (openName.before), then the tag name
99
+ p.append("<");
100
+ await this.visitSpace(element.openName.before, p);
101
+ await this.visit(element.openName.element, p);
102
+ if (element.typeArguments) {
103
+ await this.visitContainerLocal("<", element.typeArguments, ",", ">", p);
104
+ }
105
+ await this.visitSpace(element.afterName, p);
106
+ await this.visitRightPaddedLocal(element.attributes, "", p);
107
+ if (element.selfClosing) {
108
+ await this.visitSpace(element.selfClosing, p);
109
+ p.append("/>");
110
+ }
111
+ else {
112
+ p.append(">");
113
+ if (element.children) {
114
+ for (let i = 0; i < element.children.length; i++) {
115
+ await this.visit(element.children[i], p);
231
116
  }
117
+ // Print </ first, then the space after </ (closingName.before), then the tag name
118
+ p.append("</");
119
+ await this.visitSpace(element.closingName.before, p);
120
+ await this.visit(element.closingName.element, p);
121
+ await this.visitSpace(element.afterClosingName, p);
122
+ p.append(">");
232
123
  }
233
- jsImportClause.namedBindings && (yield this.visit(jsImportClause.namedBindings, p));
234
- yield this.afterSyntax(jsImportClause, p);
235
- return jsImportClause;
236
- });
237
- }
238
- visitTypeTreeExpression(typeTreeExpression, p) {
239
- return __awaiter(this, void 0, void 0, function* () {
240
- yield this.beforeSyntax(typeTreeExpression, p);
241
- yield this.visit(typeTreeExpression.expression, p);
242
- yield this.afterSyntax(typeTreeExpression, p);
243
- return typeTreeExpression;
244
- });
245
- }
246
- visitNamespaceDeclaration(namespaceDeclaration, p) {
247
- return __awaiter(this, void 0, void 0, function* () {
248
- yield this.beforeSyntax(namespaceDeclaration, p);
249
- for (const it of namespaceDeclaration.modifiers) {
250
- yield this.visitModifier(it, p);
251
- }
252
- yield this.visitSpace(namespaceDeclaration.keywordType.before, p);
253
- switch (namespaceDeclaration.keywordType.element) {
254
- case tree_1.JS.NamespaceDeclaration.KeywordType.Namespace:
255
- p.append("namespace");
256
- break;
257
- case tree_1.JS.NamespaceDeclaration.KeywordType.Module:
258
- p.append("module");
259
- break;
260
- default:
261
- break;
262
- }
263
- yield this.visitRightPadded(namespaceDeclaration.name, p);
264
- if (namespaceDeclaration.body) {
265
- yield this.visit(namespaceDeclaration.body, p);
266
- }
267
- yield this.afterSyntax(namespaceDeclaration, p);
268
- return namespaceDeclaration;
269
- });
270
- }
271
- visitSatisfiesExpression(satisfiesExpression, p) {
272
- return __awaiter(this, void 0, void 0, function* () {
273
- yield this.beforeSyntax(satisfiesExpression, p);
274
- yield this.visit(satisfiesExpression.expression, p);
275
- yield this.visitLeftPaddedLocal("satisfies", satisfiesExpression.satisfiesType, p);
276
- yield this.afterSyntax(satisfiesExpression, p);
277
- return satisfiesExpression;
278
- });
279
- }
280
- visitVoid(aVoid, p) {
281
- return __awaiter(this, void 0, void 0, function* () {
282
- yield this.beforeSyntax(aVoid, p);
283
- p.append("void");
284
- yield this.visit(aVoid.expression, p);
285
- yield this.afterSyntax(aVoid, p);
286
- return aVoid;
287
- });
288
- }
289
- visitYield(aYield, p) {
290
- return __awaiter(this, void 0, void 0, function* () {
291
- yield this.beforeSyntax(aYield, p);
292
- p.append("yield");
293
- const delegated = (0, markers_1.findMarker)(aYield, tree_1.JS.Markers.DelegatedYield);
294
- if (delegated) {
295
- yield this.visitSpace(delegated.prefix, p);
296
- p.append("*");
297
- }
298
- aYield.value && (yield this.visit(aYield.value, p));
299
- yield this.afterSyntax(aYield, p);
300
- return aYield;
301
- });
302
- }
303
- visitTry(aTry, p) {
304
- return __awaiter(this, void 0, void 0, function* () {
305
- yield this.beforeSyntax(aTry, p);
306
- p.append("try");
307
- yield this.visit(aTry.body, p);
308
- yield this.visitNodes(aTry.catches, p);
309
- aTry.finally && (yield this.visitLeftPaddedLocal("finally", aTry.finally, p));
310
- yield this.afterSyntax(aTry, p);
311
- return aTry;
312
- });
313
- }
314
- visitTryCatch(aCatch, p) {
315
- return __awaiter(this, void 0, void 0, function* () {
316
- yield this.beforeSyntax(aCatch, p);
317
- p.append("catch");
318
- if (aCatch.parameter.tree.element.variables.length > 0) {
319
- yield this.visit(aCatch.parameter, p);
320
- }
321
- yield this.visit(aCatch.body, p);
322
- yield this.afterSyntax(aCatch, p);
323
- return aCatch;
324
- });
325
- }
326
- visitArrayDimension(arrayDimension, p) {
327
- return __awaiter(this, void 0, void 0, function* () {
328
- yield this.beforeSyntax(arrayDimension, p);
329
- p.append("[");
330
- yield this.visitRightPaddedLocalSingle(arrayDimension.index, "]", p);
331
- yield this.afterSyntax(arrayDimension, p);
332
- return arrayDimension;
333
- });
334
- }
335
- visitArrayType(arrayType, p) {
336
- return __awaiter(this, void 0, void 0, function* () {
337
- yield this.beforeSyntax(arrayType, p);
338
- let type = arrayType;
339
- while (type.kind === java_1.J.Kind.ArrayType) {
340
- type = type.elementType;
341
- }
342
- yield this.visit(type, p);
343
- yield this.visitNodes(arrayType.annotations, p);
344
- if (arrayType.dimension) {
345
- yield this.visitSpace(arrayType.dimension.before, p);
346
- p.append("[");
347
- yield this.visitSpace(arrayType.dimension.element, p);
348
- p.append("]");
349
- if (arrayType.elementType.kind === java_1.J.Kind.ArrayType) {
350
- yield this.printDimensions(arrayType.elementType, p);
351
- }
124
+ }
125
+ await this.afterSyntax(element, p);
126
+ return element;
127
+ }
128
+ async visitJsxAttribute(attribute, p) {
129
+ await this.beforeSyntax(attribute, p);
130
+ await this.visit(attribute.key, p);
131
+ if (attribute.value) {
132
+ p.append("=");
133
+ await this.visit(attribute.value.element, p);
134
+ }
135
+ await this.afterSyntax(attribute, p);
136
+ return attribute;
137
+ }
138
+ async visitJsxSpreadAttribute(spread, p) {
139
+ await this.beforeSyntax(spread, p);
140
+ p.append("{");
141
+ await this.visitSpace(spread.dots, p);
142
+ p.append("...");
143
+ await this.visitRightPaddedLocal([spread.expression], "}", p);
144
+ p.append("}");
145
+ await this.afterSyntax(spread, p);
146
+ return spread;
147
+ }
148
+ async visitJsxEmbeddedExpression(expr, p) {
149
+ await this.beforeSyntax(expr, p);
150
+ p.append("{");
151
+ if (expr.expression) {
152
+ await this.visitRightPaddedLocal([expr.expression], "}", p);
153
+ }
154
+ p.append("}");
155
+ await this.afterSyntax(expr, p);
156
+ return expr;
157
+ }
158
+ async visitJsxNamespacedName(ns, p) {
159
+ await this.beforeSyntax(ns, p);
160
+ await this.visit(ns.namespace, p);
161
+ p.append(":");
162
+ await this.visitLeftPadded(ns.name, p);
163
+ await this.afterSyntax(ns, p);
164
+ return ns;
165
+ }
166
+ async visitImportDeclaration(jsImport, p) {
167
+ for (const it of jsImport.modifiers) {
168
+ await this.visitDefined(it, p);
169
+ }
170
+ await this.beforeSyntax(jsImport, p);
171
+ p.append("import");
172
+ jsImport.importClause && await this.visit(jsImport.importClause, p);
173
+ await this.visitLeftPaddedLocal(jsImport.importClause ? "from" : "", jsImport.moduleSpecifier, p);
174
+ jsImport.attributes && await this.visit(jsImport.attributes, p);
175
+ if (jsImport.initializer) {
176
+ p.append("=");
177
+ await this.visitLeftPadded(jsImport.initializer, p);
178
+ }
179
+ await this.afterSyntax(jsImport, p);
180
+ return jsImport;
181
+ }
182
+ async visitImportClause(jsImportClause, p) {
183
+ await this.beforeSyntax(jsImportClause, p);
184
+ if (jsImportClause.typeOnly) {
185
+ p.append("type");
186
+ }
187
+ if (jsImportClause.name) {
188
+ await this.visitRightPadded(jsImportClause.name, p);
189
+ if (jsImportClause.namedBindings) {
190
+ p.append(",");
352
191
  }
353
- yield this.afterSyntax(arrayType, p);
354
- return arrayType;
355
- });
356
- }
357
- printDimensions(arrayType, p) {
358
- return __awaiter(this, void 0, void 0, function* () {
359
- var _a, _b, _c, _d;
360
- yield this.beforeSyntax(arrayType, p);
361
- yield this.visitNodes(arrayType.annotations, p);
362
- yield this.visitSpace((_b = (_a = arrayType.dimension) === null || _a === void 0 ? void 0 : _a.before) !== null && _b !== void 0 ? _b : java_1.emptySpace, p);
192
+ }
193
+ jsImportClause.namedBindings && await this.visit(jsImportClause.namedBindings, p);
194
+ await this.afterSyntax(jsImportClause, p);
195
+ return jsImportClause;
196
+ }
197
+ async visitTypeTreeExpression(typeTreeExpression, p) {
198
+ await this.beforeSyntax(typeTreeExpression, p);
199
+ await this.visit(typeTreeExpression.expression, p);
200
+ await this.afterSyntax(typeTreeExpression, p);
201
+ return typeTreeExpression;
202
+ }
203
+ async visitNamespaceDeclaration(namespaceDeclaration, p) {
204
+ await this.beforeSyntax(namespaceDeclaration, p);
205
+ for (const it of namespaceDeclaration.modifiers) {
206
+ await this.visitModifier(it, p);
207
+ }
208
+ await this.visitSpace(namespaceDeclaration.keywordType.before, p);
209
+ switch (namespaceDeclaration.keywordType.element) {
210
+ case tree_1.JS.NamespaceDeclaration.KeywordType.Namespace:
211
+ p.append("namespace");
212
+ break;
213
+ case tree_1.JS.NamespaceDeclaration.KeywordType.Module:
214
+ p.append("module");
215
+ break;
216
+ default:
217
+ break;
218
+ }
219
+ await this.visitRightPadded(namespaceDeclaration.name, p);
220
+ if (namespaceDeclaration.body) {
221
+ await this.visit(namespaceDeclaration.body, p);
222
+ }
223
+ await this.afterSyntax(namespaceDeclaration, p);
224
+ return namespaceDeclaration;
225
+ }
226
+ async visitSatisfiesExpression(satisfiesExpression, p) {
227
+ await this.beforeSyntax(satisfiesExpression, p);
228
+ await this.visit(satisfiesExpression.expression, p);
229
+ await this.visitLeftPaddedLocal("satisfies", satisfiesExpression.satisfiesType, p);
230
+ await this.afterSyntax(satisfiesExpression, p);
231
+ return satisfiesExpression;
232
+ }
233
+ async visitVoid(aVoid, p) {
234
+ await this.beforeSyntax(aVoid, p);
235
+ p.append("void");
236
+ await this.visit(aVoid.expression, p);
237
+ await this.afterSyntax(aVoid, p);
238
+ return aVoid;
239
+ }
240
+ async visitYield(aYield, p) {
241
+ await this.beforeSyntax(aYield, p);
242
+ p.append("yield");
243
+ const delegated = (0, markers_1.findMarker)(aYield, tree_1.JS.Markers.DelegatedYield);
244
+ if (delegated) {
245
+ await this.visitSpace(delegated.prefix, p);
246
+ p.append("*");
247
+ }
248
+ aYield.value && await this.visit(aYield.value, p);
249
+ await this.afterSyntax(aYield, p);
250
+ return aYield;
251
+ }
252
+ async visitTry(aTry, p) {
253
+ await this.beforeSyntax(aTry, p);
254
+ p.append("try");
255
+ await this.visit(aTry.body, p);
256
+ await this.visitNodes(aTry.catches, p);
257
+ aTry.finally && await this.visitLeftPaddedLocal("finally", aTry.finally, p);
258
+ await this.afterSyntax(aTry, p);
259
+ return aTry;
260
+ }
261
+ async visitTryCatch(aCatch, p) {
262
+ await this.beforeSyntax(aCatch, p);
263
+ p.append("catch");
264
+ if (aCatch.parameter.tree.element.variables.length > 0) {
265
+ await this.visit(aCatch.parameter, p);
266
+ }
267
+ await this.visit(aCatch.body, p);
268
+ await this.afterSyntax(aCatch, p);
269
+ return aCatch;
270
+ }
271
+ async visitArrayDimension(arrayDimension, p) {
272
+ await this.beforeSyntax(arrayDimension, p);
273
+ p.append("[");
274
+ await this.visitRightPaddedLocalSingle(arrayDimension.index, "]", p);
275
+ await this.afterSyntax(arrayDimension, p);
276
+ return arrayDimension;
277
+ }
278
+ async visitArrayType(arrayType, p) {
279
+ await this.beforeSyntax(arrayType, p);
280
+ let type = arrayType;
281
+ while (type.kind === java_1.J.Kind.ArrayType) {
282
+ type = type.elementType;
283
+ }
284
+ await this.visit(type, p);
285
+ await this.visitNodes(arrayType.annotations, p);
286
+ if (arrayType.dimension) {
287
+ await this.visitSpace(arrayType.dimension.before, p);
363
288
  p.append("[");
364
- yield this.visitSpace((_d = (_c = arrayType.dimension) === null || _c === void 0 ? void 0 : _c.element) !== null && _d !== void 0 ? _d : java_1.emptySpace, p);
289
+ await this.visitSpace(arrayType.dimension.element, p);
365
290
  p.append("]");
366
291
  if (arrayType.elementType.kind === java_1.J.Kind.ArrayType) {
367
- yield this.printDimensions(arrayType.elementType, p);
368
- }
369
- yield this.afterSyntax(arrayType, p);
370
- });
371
- }
372
- visitTernary(ternary, p) {
373
- return __awaiter(this, void 0, void 0, function* () {
374
- yield this.beforeSyntax(ternary, p);
375
- yield this.visit(ternary.condition, p);
376
- yield this.visitLeftPaddedLocal("?", ternary.truePart, p);
377
- yield this.visitLeftPaddedLocal(":", ternary.falsePart, p);
378
- yield this.afterSyntax(ternary, p);
379
- return ternary;
380
- });
381
- }
382
- visitThrow(thrown, p) {
383
- return __awaiter(this, void 0, void 0, function* () {
384
- yield this.beforeSyntax(thrown, p);
385
- p.append("throw");
386
- yield this.visit(thrown.exception, p);
387
- yield this.afterSyntax(thrown, p);
388
- return thrown;
389
- });
390
- }
391
- visitIf(iff, p) {
392
- return __awaiter(this, void 0, void 0, function* () {
393
- yield this.beforeSyntax(iff, p);
394
- p.append("if");
395
- yield this.visit(iff.ifCondition, p);
396
- yield this.visitStatementLocal(iff.thenPart, p);
397
- iff.elsePart && (yield this.visit(iff.elsePart, p));
398
- yield this.afterSyntax(iff, p);
399
- return iff;
400
- });
401
- }
402
- visitElse(else_, p) {
403
- return __awaiter(this, void 0, void 0, function* () {
404
- yield this.beforeSyntax(else_, p);
405
- p.append("else");
406
- yield this.visitStatementLocal(else_.body, p);
407
- yield this.afterSyntax(else_, p);
408
- return else_;
409
- });
410
- }
411
- visitDoWhileLoop(doWhileLoop, p) {
412
- return __awaiter(this, void 0, void 0, function* () {
413
- yield this.beforeSyntax(doWhileLoop, p);
414
- p.append("do");
415
- yield this.visitStatementLocal(doWhileLoop.body, p);
416
- yield this.visitLeftPaddedLocal("while", doWhileLoop.whileCondition, p);
417
- yield this.afterSyntax(doWhileLoop, p);
418
- return doWhileLoop;
419
- });
420
- }
421
- visitWhileLoop(whileLoop, p) {
422
- return __awaiter(this, void 0, void 0, function* () {
423
- yield this.beforeSyntax(whileLoop, p);
424
- p.append("while");
425
- yield this.visit(whileLoop.condition, p);
426
- yield this.visitStatementLocal(whileLoop.body, p);
427
- yield this.afterSyntax(whileLoop, p);
428
- return whileLoop;
429
- });
430
- }
431
- visitInstanceOf(instanceOf, p) {
432
- return __awaiter(this, void 0, void 0, function* () {
433
- yield this.beforeSyntax(instanceOf, p);
434
- yield this.visitRightPaddedLocalSingle(instanceOf.expression, "instanceof", p);
435
- yield this.visit(instanceOf.class, p);
436
- instanceOf.pattern && (yield this.visit(instanceOf.pattern, p));
437
- yield this.afterSyntax(instanceOf, p);
438
- return instanceOf;
439
- });
440
- }
441
- visitLiteral(literal, p) {
442
- return __awaiter(this, void 0, void 0, function* () {
443
- var _a, _b, _c;
444
- yield this.beforeSyntax(literal, p);
445
- const unicodeEscapes = literal.unicodeEscapes;
446
- if (!unicodeEscapes) {
447
- p.append(literal.valueSource);
292
+ await this.printDimensions(arrayType.elementType, p);
448
293
  }
449
- else if (literal.valueSource) {
450
- const surrogateIter = unicodeEscapes[Symbol.iterator]();
451
- let surrogate = (_a = surrogateIter.next().value) !== null && _a !== void 0 ? _a : null;
452
- let i = 0;
453
- if (surrogate && surrogate.valueSourceIndex === 0) {
454
- p.append("\\u").append(surrogate.codePoint);
455
- surrogate = (_b = surrogateIter.next().value) !== null && _b !== void 0 ? _b : null;
456
- }
457
- const valueSource = literal.valueSource;
458
- for (let j = 0; j < valueSource.length; j++) {
459
- const c = valueSource[j];
460
- p.append(c);
461
- if (surrogate && surrogate.valueSourceIndex === ++i) {
462
- while (surrogate && surrogate.valueSourceIndex === i) {
463
- p.append("\\u").append(surrogate.codePoint);
464
- surrogate = (_c = surrogateIter.next().value) !== null && _c !== void 0 ? _c : null;
465
- }
294
+ }
295
+ await this.afterSyntax(arrayType, p);
296
+ return arrayType;
297
+ }
298
+ async printDimensions(arrayType, p) {
299
+ var _a, _b, _c, _d;
300
+ await this.beforeSyntax(arrayType, p);
301
+ await this.visitNodes(arrayType.annotations, p);
302
+ await this.visitSpace((_b = (_a = arrayType.dimension) === null || _a === void 0 ? void 0 : _a.before) !== null && _b !== void 0 ? _b : java_1.emptySpace, p);
303
+ p.append("[");
304
+ await this.visitSpace((_d = (_c = arrayType.dimension) === null || _c === void 0 ? void 0 : _c.element) !== null && _d !== void 0 ? _d : java_1.emptySpace, p);
305
+ p.append("]");
306
+ if (arrayType.elementType.kind === java_1.J.Kind.ArrayType) {
307
+ await this.printDimensions(arrayType.elementType, p);
308
+ }
309
+ await this.afterSyntax(arrayType, p);
310
+ }
311
+ async visitTernary(ternary, p) {
312
+ await this.beforeSyntax(ternary, p);
313
+ await this.visit(ternary.condition, p);
314
+ await this.visitLeftPaddedLocal("?", ternary.truePart, p);
315
+ await this.visitLeftPaddedLocal(":", ternary.falsePart, p);
316
+ await this.afterSyntax(ternary, p);
317
+ return ternary;
318
+ }
319
+ async visitThrow(thrown, p) {
320
+ await this.beforeSyntax(thrown, p);
321
+ p.append("throw");
322
+ await this.visit(thrown.exception, p);
323
+ await this.afterSyntax(thrown, p);
324
+ return thrown;
325
+ }
326
+ async visitIf(iff, p) {
327
+ await this.beforeSyntax(iff, p);
328
+ p.append("if");
329
+ await this.visit(iff.ifCondition, p);
330
+ await this.visitStatementLocal(iff.thenPart, p);
331
+ iff.elsePart && await this.visit(iff.elsePart, p);
332
+ await this.afterSyntax(iff, p);
333
+ return iff;
334
+ }
335
+ async visitElse(else_, p) {
336
+ await this.beforeSyntax(else_, p);
337
+ p.append("else");
338
+ await this.visitStatementLocal(else_.body, p);
339
+ await this.afterSyntax(else_, p);
340
+ return else_;
341
+ }
342
+ async visitDoWhileLoop(doWhileLoop, p) {
343
+ await this.beforeSyntax(doWhileLoop, p);
344
+ p.append("do");
345
+ await this.visitStatementLocal(doWhileLoop.body, p);
346
+ await this.visitLeftPaddedLocal("while", doWhileLoop.whileCondition, p);
347
+ await this.afterSyntax(doWhileLoop, p);
348
+ return doWhileLoop;
349
+ }
350
+ async visitWhileLoop(whileLoop, p) {
351
+ await this.beforeSyntax(whileLoop, p);
352
+ p.append("while");
353
+ await this.visit(whileLoop.condition, p);
354
+ await this.visitStatementLocal(whileLoop.body, p);
355
+ await this.afterSyntax(whileLoop, p);
356
+ return whileLoop;
357
+ }
358
+ async visitInstanceOf(instanceOf, p) {
359
+ await this.beforeSyntax(instanceOf, p);
360
+ await this.visitRightPaddedLocalSingle(instanceOf.expression, "instanceof", p);
361
+ await this.visit(instanceOf.class, p);
362
+ instanceOf.pattern && await this.visit(instanceOf.pattern, p);
363
+ await this.afterSyntax(instanceOf, p);
364
+ return instanceOf;
365
+ }
366
+ async visitLiteral(literal, p) {
367
+ var _a, _b, _c;
368
+ await this.beforeSyntax(literal, p);
369
+ const unicodeEscapes = literal.unicodeEscapes;
370
+ if (!unicodeEscapes) {
371
+ p.append(literal.valueSource);
372
+ }
373
+ else if (literal.valueSource) {
374
+ const surrogateIter = unicodeEscapes[Symbol.iterator]();
375
+ let surrogate = (_a = surrogateIter.next().value) !== null && _a !== void 0 ? _a : null;
376
+ let i = 0;
377
+ if (surrogate && surrogate.valueSourceIndex === 0) {
378
+ p.append("\\u").append(surrogate.codePoint);
379
+ surrogate = (_b = surrogateIter.next().value) !== null && _b !== void 0 ? _b : null;
380
+ }
381
+ const valueSource = literal.valueSource;
382
+ for (let j = 0; j < valueSource.length; j++) {
383
+ const c = valueSource[j];
384
+ p.append(c);
385
+ if (surrogate && surrogate.valueSourceIndex === ++i) {
386
+ while (surrogate && surrogate.valueSourceIndex === i) {
387
+ p.append("\\u").append(surrogate.codePoint);
388
+ surrogate = (_c = surrogateIter.next().value) !== null && _c !== void 0 ? _c : null;
466
389
  }
467
390
  }
468
391
  }
469
- yield this.afterSyntax(literal, p);
470
- return literal;
471
- });
472
- }
473
- visitScopedVariableDeclarations(variableDeclarations, p) {
474
- return __awaiter(this, void 0, void 0, function* () {
475
- yield this.beforeSyntax(variableDeclarations, p);
476
- for (const m of variableDeclarations.modifiers) {
477
- yield this.visitModifier(m, p);
478
- }
479
- yield this.visitRightPaddedLocal(variableDeclarations.variables, ",", p);
480
- yield this.afterSyntax(variableDeclarations, p);
481
- return variableDeclarations;
482
- });
483
- }
484
- visitShebang(shebang, p) {
485
- return __awaiter(this, void 0, void 0, function* () {
486
- yield this.beforeSyntax(shebang, p);
487
- p.append(shebang.text);
488
- yield this.afterSyntax(shebang, p);
489
- return shebang;
490
- });
491
- }
492
- visitVariableDeclarations(multiVariable, p) {
493
- return __awaiter(this, void 0, void 0, function* () {
494
- yield this.beforeSyntax(multiVariable, p);
495
- yield this.visitNodes(multiVariable.leadingAnnotations, p);
496
- for (const it of multiVariable.modifiers) {
497
- yield this.visitModifier(it, p);
498
- }
499
- const variables = multiVariable.variables;
500
- for (let i = 0; i < variables.length; i++) {
501
- const variable = variables[i];
502
- yield this.beforeSyntax(variable.element, p);
503
- if (multiVariable.varargs) {
504
- p.append("...");
505
- }
506
- yield this.visit(variable.element.name, p);
507
- // print non-null assertions or optional
508
- yield this.postVisit(variable.element, p);
509
- yield this.visitSpace(variable.after, p);
510
- if (multiVariable.typeExpression) {
511
- yield this.visit(multiVariable.typeExpression, p);
512
- }
513
- if (variable.element.initializer) {
514
- yield this.visitLeftPaddedLocal("=", variable.element.initializer, p);
515
- }
516
- yield this.afterSyntax(variable.element, p);
517
- if (i < variables.length - 1) {
518
- p.append(",");
519
- }
520
- else if ((0, markers_1.findMarker)(variable, java_1.J.Markers.Semicolon)) {
521
- p.append(";");
522
- }
523
- }
524
- yield this.afterSyntax(multiVariable, p);
525
- return multiVariable;
526
- });
527
- }
528
- visitVariable(variable, p) {
529
- return __awaiter(this, void 0, void 0, function* () {
530
- yield this.beforeSyntax(variable, p);
531
- yield this.visit(variable.name, p);
532
- variable.initializer && (yield this.visitLeftPaddedLocal("=", variable.initializer, p));
533
- yield this.afterSyntax(variable, p);
534
- return variable;
535
- });
536
- }
537
- visitIdentifier(ident, p) {
538
- return __awaiter(this, void 0, void 0, function* () {
539
- yield this.visitSpace(java_1.emptySpace, p);
540
- yield this.visitNodes(ident.annotations, p);
541
- yield this.beforeSyntax(ident, p);
542
- p.append(ident.simpleName);
543
- yield this.afterSyntax(ident, p);
544
- return ident;
545
- });
546
- }
547
- visitBlock(block, p) {
548
- return __awaiter(this, void 0, void 0, function* () {
549
- yield this.beforeSyntax(block, p);
550
- if (block.static.element) {
551
- p.append("static");
552
- yield this.visitRightPadded(block.static, p);
553
- }
554
- p.append("{");
555
- yield this.visitStatements(block.statements, p);
556
- yield this.visitSpace(block.end, p);
557
- p.append("}");
558
- yield this.afterSyntax(block, p);
559
- return block;
560
- });
561
- }
562
- visitTypeInfo(typeInfo, p) {
563
- return __awaiter(this, void 0, void 0, function* () {
564
- yield this.beforeSyntax(typeInfo, p);
565
- p.append(":");
566
- yield this.visit(typeInfo.typeIdentifier, p);
567
- yield this.afterSyntax(typeInfo, p);
568
- return typeInfo;
569
- });
570
- }
571
- visitReturn(return_, p) {
572
- return __awaiter(this, void 0, void 0, function* () {
573
- yield this.beforeSyntax(return_, p);
574
- p.append("return");
575
- return_.expression && (yield this.visit(return_.expression, p));
576
- yield this.afterSyntax(return_, p);
577
- return return_;
578
- });
579
- }
580
- visitModifier(mod, p) {
581
- return __awaiter(this, void 0, void 0, function* () {
582
- var _a;
583
- yield this.visitNodes(mod.annotations, p);
584
- let keyword;
585
- switch (mod.type) {
586
- case java_1.J.ModifierType.Default:
587
- keyword = "default";
588
- break;
589
- case java_1.J.ModifierType.Public:
590
- keyword = "public";
591
- break;
592
- case java_1.J.ModifierType.Protected:
593
- keyword = "protected";
594
- break;
595
- case java_1.J.ModifierType.Private:
596
- keyword = "private";
597
- break;
598
- case java_1.J.ModifierType.Abstract:
599
- keyword = "abstract";
600
- break;
601
- case java_1.J.ModifierType.Async:
602
- keyword = "async";
603
- break;
604
- case java_1.J.ModifierType.Static:
605
- keyword = "static";
606
- break;
607
- case java_1.J.ModifierType.Final:
608
- keyword = "const";
609
- break;
610
- case java_1.J.ModifierType.Native:
611
- keyword = "native";
612
- break;
613
- case java_1.J.ModifierType.NonSealed:
614
- keyword = "non-sealed";
615
- break;
616
- case java_1.J.ModifierType.Sealed:
617
- keyword = "sealed";
618
- break;
619
- case java_1.J.ModifierType.Strictfp:
620
- keyword = "strictfp";
621
- break;
622
- case java_1.J.ModifierType.Synchronized:
623
- keyword = "synchronized";
624
- break;
625
- case java_1.J.ModifierType.Transient:
626
- keyword = "transient";
627
- break;
628
- case java_1.J.ModifierType.Volatile:
629
- keyword = "volatile";
630
- break;
631
- default:
632
- keyword = (_a = mod.keyword) !== null && _a !== void 0 ? _a : "";
633
- }
634
- yield this.beforeSyntax(mod, p);
635
- p.append(keyword);
636
- yield this.afterSyntax(mod, p);
637
- return mod;
638
- });
639
- }
640
- visitFunctionCall(functionCall, p) {
641
- return __awaiter(this, void 0, void 0, function* () {
642
- yield this.beforeSyntax(functionCall, p);
643
- if (functionCall.function) {
644
- yield this.visitRightPadded(functionCall.function, p);
645
- if (functionCall.function.element.markers.markers.find(m => m.kind === tree_1.JS.Markers.Optional)) {
646
- p.append("?.");
647
- }
648
- }
649
- functionCall.typeParameters && (yield this.visitContainerLocal("<", functionCall.typeParameters, ",", ">", p));
650
- yield this.visitContainerLocal("(", functionCall.arguments, ",", ")", p);
651
- yield this.afterSyntax(functionCall, p);
652
- return functionCall;
653
- });
654
- }
655
- visitFunctionType(functionType, p) {
656
- return __awaiter(this, void 0, void 0, function* () {
657
- yield this.beforeSyntax(functionType, p);
658
- for (const m of functionType.modifiers) {
659
- yield this.visitModifier(m, p);
660
- }
661
- if (functionType.constructorType.element) {
662
- yield this.visitLeftPaddedLocal("new", functionType.constructorType, p);
663
- }
664
- const typeParameters = functionType.typeParameters;
665
- if (typeParameters) {
666
- yield this.visitNodes(typeParameters.annotations, p);
667
- yield this.visitSpace(typeParameters.prefix, p);
668
- yield this.visitMarkers(typeParameters.markers, p);
669
- p.append("<");
670
- yield this.visitRightPaddedLocal(typeParameters.typeParameters, ",", p);
671
- p.append(">");
672
- }
673
- yield this.visitContainerLocal("(", functionType.parameters, ",", ")", p);
674
- yield this.visitLeftPaddedLocal("=>", functionType.returnType, p);
675
- yield this.afterSyntax(functionType, p);
676
- return functionType;
677
- });
678
- }
679
- visitClassDeclaration(classDecl, p) {
680
- return __awaiter(this, void 0, void 0, function* () {
681
- let kind = "";
682
- switch (classDecl.classKind.type) {
683
- case java_1.J.ClassDeclaration.Kind.Type.Class:
684
- kind = "class";
685
- break;
686
- case java_1.J.ClassDeclaration.Kind.Type.Enum:
687
- kind = "enum";
688
- break;
689
- case java_1.J.ClassDeclaration.Kind.Type.Interface:
690
- kind = "interface";
691
- break;
692
- case java_1.J.ClassDeclaration.Kind.Type.Annotation:
693
- kind = "@interface";
694
- break;
695
- case java_1.J.ClassDeclaration.Kind.Type.Record:
696
- kind = "record";
697
- break;
698
- }
699
- yield this.beforeSyntax(classDecl, p);
700
- yield this.visitSpace(java_1.emptySpace, p);
701
- yield this.visitNodes(classDecl.leadingAnnotations, p);
702
- for (const m of classDecl.modifiers) {
703
- yield this.visitModifier(m, p);
704
- }
705
- yield this.visitNodes(classDecl.classKind.annotations, p);
706
- yield this.visitSpace(classDecl.classKind.prefix, p);
707
- p.append(kind);
708
- yield this.visit(classDecl.name, p);
709
- classDecl.typeParameters && (yield this.visitContainerLocal("<", classDecl.typeParameters, ",", ">", p));
710
- classDecl.primaryConstructor && (yield this.visitContainerLocal("(", classDecl.primaryConstructor, ",", ")", p));
711
- classDecl.extends && (yield this.visitLeftPaddedLocal("extends", classDecl.extends, p));
712
- classDecl.implements && (yield this.visitContainerLocal(classDecl.classKind.type === java_1.J.ClassDeclaration.Kind.Type.Interface ? "extends" : "implements", classDecl.implements, ",", null, p));
713
- yield this.visit(classDecl.body, p);
714
- yield this.afterSyntax(classDecl, p);
715
- return classDecl;
716
- });
717
- }
718
- visitMethodDeclaration(method, p) {
719
- return __awaiter(this, void 0, void 0, function* () {
720
- yield this.beforeSyntax(method, p);
721
- yield this.visitSpace(java_1.emptySpace, p);
722
- yield this.visitNodes(method.leadingAnnotations, p);
723
- for (const m of method.modifiers) {
724
- yield this.visitModifier(m, p);
725
- }
726
- let m;
727
- if ((m = (0, markers_1.findMarker)(method, tree_1.JS.Markers.FunctionDeclaration))) {
728
- yield this.visitSpace(m.prefix, p);
729
- p.append("function");
730
- }
731
- const asterisk = (0, markers_1.findMarker)(method, tree_1.JS.Markers.Generator);
732
- if (asterisk) {
733
- yield this.visitSpace(asterisk.prefix, p);
734
- p.append("*");
735
- }
736
- yield this.visit(method.name, p);
737
- const typeParameters = method.typeParameters;
738
- if (typeParameters) {
739
- yield this.visitNodes(typeParameters.annotations, p);
740
- yield this.visitSpace(typeParameters.prefix, p);
741
- yield this.visitMarkers(typeParameters.markers, p);
742
- p.append("<");
743
- yield this.visitRightPaddedLocal(typeParameters.typeParameters, ",", p);
744
- p.append(">");
745
- }
746
- yield this.visitContainerLocal("(", method.parameters, ",", ")", p);
747
- if (method.returnTypeExpression) {
748
- yield this.visit(method.returnTypeExpression, p);
749
- }
750
- method.body && (yield this.visit(method.body, p));
751
- yield this.afterSyntax(method, p);
752
- return method;
753
- });
754
- }
755
- visitComputedPropertyMethodDeclaration(method, p) {
756
- return __awaiter(this, void 0, void 0, function* () {
757
- yield this.beforeSyntax(method, p);
758
- yield this.visitSpace(java_1.emptySpace, p);
759
- yield this.visitNodes(method.leadingAnnotations, p);
760
- for (const it of method.modifiers) {
761
- yield this.visitModifier(it, p);
762
- }
763
- const generator = (0, markers_1.findMarker)(method, tree_1.JS.Markers.Generator);
764
- if (generator) {
765
- yield this.visitSpace(generator.prefix, p);
766
- p.append("*");
767
- }
768
- yield this.visit(method.name, p);
769
- const typeParameters = method.typeParameters;
770
- if (typeParameters) {
771
- yield this.visitNodes(typeParameters.annotations, p);
772
- yield this.visitSpace(typeParameters.prefix, p);
773
- yield this.visitMarkers(typeParameters.markers, p);
774
- p.append("<");
775
- yield this.visitRightPaddedLocal(typeParameters.typeParameters, ",", p);
776
- p.append(">");
777
- }
778
- yield this.visitContainerLocal("(", method.parameters, ",", ")", p);
779
- if (method.returnTypeExpression) {
780
- yield this.visit(method.returnTypeExpression, p);
392
+ }
393
+ await this.afterSyntax(literal, p);
394
+ return literal;
395
+ }
396
+ async visitScopedVariableDeclarations(variableDeclarations, p) {
397
+ await this.beforeSyntax(variableDeclarations, p);
398
+ for (const m of variableDeclarations.modifiers) {
399
+ await this.visitModifier(m, p);
400
+ }
401
+ await this.visitRightPaddedLocal(variableDeclarations.variables, ",", p);
402
+ await this.afterSyntax(variableDeclarations, p);
403
+ return variableDeclarations;
404
+ }
405
+ async visitShebang(shebang, p) {
406
+ await this.beforeSyntax(shebang, p);
407
+ p.append(shebang.text);
408
+ await this.afterSyntax(shebang, p);
409
+ return shebang;
410
+ }
411
+ async visitVariableDeclarations(multiVariable, p) {
412
+ await this.beforeSyntax(multiVariable, p);
413
+ await this.visitNodes(multiVariable.leadingAnnotations, p);
414
+ for (const it of multiVariable.modifiers) {
415
+ await this.visitModifier(it, p);
416
+ }
417
+ const variables = multiVariable.variables;
418
+ for (let i = 0; i < variables.length; i++) {
419
+ const variable = variables[i];
420
+ await this.beforeSyntax(variable.element, p);
421
+ if (multiVariable.varargs) {
422
+ p.append("...");
423
+ }
424
+ await this.visit(variable.element.name, p);
425
+ // print non-null assertions or optional
426
+ await this.postVisit(variable.element, p);
427
+ await this.visitSpace(variable.after, p);
428
+ if (multiVariable.typeExpression) {
429
+ await this.visit(multiVariable.typeExpression, p);
430
+ }
431
+ if (variable.element.initializer) {
432
+ await this.visitLeftPaddedLocal("=", variable.element.initializer, p);
433
+ }
434
+ await this.afterSyntax(variable.element, p);
435
+ if (i < variables.length - 1) {
436
+ p.append(",");
781
437
  }
782
- method.body && (yield this.visit(method.body, p));
783
- yield this.afterSyntax(method, p);
784
- return method;
785
- });
786
- }
787
- visitMethodInvocation(method, p) {
788
- return __awaiter(this, void 0, void 0, function* () {
789
- yield this.beforeSyntax(method, p);
790
- if (method.name.simpleName.length === 0) {
791
- method.select && (yield this.visitRightPadded(method.select, p));
438
+ else if ((0, markers_1.findMarker)(variable, java_1.J.Markers.Semicolon)) {
439
+ p.append(";");
792
440
  }
793
- else {
794
- if (method.select) {
795
- yield this.visitRightPadded(method.select, p);
796
- if (!method.select.element.markers.markers.find(m => m.kind === tree_1.JS.Markers.Optional)) {
797
- p.append(".");
798
- }
799
- else {
800
- p.append("?.");
801
- }
802
- }
803
- yield this.visit(method.name, p);
804
- }
805
- method.typeParameters && (yield this.visitContainerLocal("<", method.typeParameters, ",", ">", p));
806
- yield this.visitContainerLocal("(", method.arguments, ",", ")", p);
807
- yield this.afterSyntax(method, p);
808
- return method;
809
- });
810
- }
811
- visitTypeParameter(typeParameter, p) {
812
- return __awaiter(this, void 0, void 0, function* () {
813
- yield this.beforeSyntax(typeParameter, p);
814
- yield this.visitNodes(typeParameter.annotations, p);
815
- for (const m of typeParameter.modifiers) {
816
- yield this.visitModifier(m, p);
441
+ }
442
+ await this.afterSyntax(multiVariable, p);
443
+ return multiVariable;
444
+ }
445
+ async visitVariable(variable, p) {
446
+ await this.beforeSyntax(variable, p);
447
+ await this.visit(variable.name, p);
448
+ variable.initializer && await this.visitLeftPaddedLocal("=", variable.initializer, p);
449
+ await this.afterSyntax(variable, p);
450
+ return variable;
451
+ }
452
+ async visitIdentifier(ident, p) {
453
+ await this.visitSpace(java_1.emptySpace, p);
454
+ await this.visitNodes(ident.annotations, p);
455
+ await this.beforeSyntax(ident, p);
456
+ p.append(ident.simpleName);
457
+ await this.afterSyntax(ident, p);
458
+ return ident;
459
+ }
460
+ async visitBlock(block, p) {
461
+ await this.beforeSyntax(block, p);
462
+ if (block.static.element) {
463
+ p.append("static");
464
+ await this.visitRightPadded(block.static, p);
465
+ }
466
+ p.append("{");
467
+ await this.visitStatements(block.statements, p);
468
+ await this.visitSpace(block.end, p);
469
+ p.append("}");
470
+ await this.afterSyntax(block, p);
471
+ return block;
472
+ }
473
+ async visitTypeInfo(typeInfo, p) {
474
+ await this.beforeSyntax(typeInfo, p);
475
+ p.append(":");
476
+ await this.visit(typeInfo.typeIdentifier, p);
477
+ await this.afterSyntax(typeInfo, p);
478
+ return typeInfo;
479
+ }
480
+ async visitReturn(return_, p) {
481
+ await this.beforeSyntax(return_, p);
482
+ p.append("return");
483
+ return_.expression && await this.visit(return_.expression, p);
484
+ await this.afterSyntax(return_, p);
485
+ return return_;
486
+ }
487
+ async visitModifier(mod, p) {
488
+ var _a;
489
+ await this.visitNodes(mod.annotations, p);
490
+ let keyword;
491
+ switch (mod.type) {
492
+ case java_1.J.ModifierType.Default:
493
+ keyword = "default";
494
+ break;
495
+ case java_1.J.ModifierType.Public:
496
+ keyword = "public";
497
+ break;
498
+ case java_1.J.ModifierType.Protected:
499
+ keyword = "protected";
500
+ break;
501
+ case java_1.J.ModifierType.Private:
502
+ keyword = "private";
503
+ break;
504
+ case java_1.J.ModifierType.Abstract:
505
+ keyword = "abstract";
506
+ break;
507
+ case java_1.J.ModifierType.Async:
508
+ keyword = "async";
509
+ break;
510
+ case java_1.J.ModifierType.Static:
511
+ keyword = "static";
512
+ break;
513
+ case java_1.J.ModifierType.Final:
514
+ keyword = "const";
515
+ break;
516
+ case java_1.J.ModifierType.Native:
517
+ keyword = "native";
518
+ break;
519
+ case java_1.J.ModifierType.NonSealed:
520
+ keyword = "non-sealed";
521
+ break;
522
+ case java_1.J.ModifierType.Sealed:
523
+ keyword = "sealed";
524
+ break;
525
+ case java_1.J.ModifierType.Strictfp:
526
+ keyword = "strictfp";
527
+ break;
528
+ case java_1.J.ModifierType.Synchronized:
529
+ keyword = "synchronized";
530
+ break;
531
+ case java_1.J.ModifierType.Transient:
532
+ keyword = "transient";
533
+ break;
534
+ case java_1.J.ModifierType.Volatile:
535
+ keyword = "volatile";
536
+ break;
537
+ default:
538
+ keyword = (_a = mod.keyword) !== null && _a !== void 0 ? _a : "";
539
+ }
540
+ await this.beforeSyntax(mod, p);
541
+ p.append(keyword);
542
+ await this.afterSyntax(mod, p);
543
+ return mod;
544
+ }
545
+ async visitFunctionCall(functionCall, p) {
546
+ await this.beforeSyntax(functionCall, p);
547
+ if (functionCall.function) {
548
+ await this.visitRightPadded(functionCall.function, p);
549
+ if (functionCall.function.element.markers.markers.find(m => m.kind === tree_1.JS.Markers.Optional)) {
550
+ p.append("?.");
817
551
  }
818
- yield this.visit(typeParameter.name, p);
819
- const bounds = typeParameter.bounds;
820
- if (bounds) {
821
- yield this.visitSpace(bounds.before, p);
822
- const constraintType = bounds.elements[0];
823
- if (!(constraintType.element.kind === java_1.J.Kind.Empty)) {
824
- p.append("extends");
825
- yield this.visitRightPadded(constraintType, p);
552
+ }
553
+ functionCall.typeParameters && await this.visitContainerLocal("<", functionCall.typeParameters, ",", ">", p);
554
+ await this.visitContainerLocal("(", functionCall.arguments, ",", ")", p);
555
+ await this.afterSyntax(functionCall, p);
556
+ return functionCall;
557
+ }
558
+ async visitFunctionType(functionType, p) {
559
+ await this.beforeSyntax(functionType, p);
560
+ for (const m of functionType.modifiers) {
561
+ await this.visitModifier(m, p);
562
+ }
563
+ if (functionType.constructorType.element) {
564
+ await this.visitLeftPaddedLocal("new", functionType.constructorType, p);
565
+ }
566
+ const typeParameters = functionType.typeParameters;
567
+ if (typeParameters) {
568
+ await this.visitNodes(typeParameters.annotations, p);
569
+ await this.visitSpace(typeParameters.prefix, p);
570
+ await this.visitMarkers(typeParameters.markers, p);
571
+ p.append("<");
572
+ await this.visitRightPaddedLocal(typeParameters.typeParameters, ",", p);
573
+ p.append(">");
574
+ }
575
+ await this.visitContainerLocal("(", functionType.parameters, ",", ")", p);
576
+ await this.visitLeftPaddedLocal("=>", functionType.returnType, p);
577
+ await this.afterSyntax(functionType, p);
578
+ return functionType;
579
+ }
580
+ async visitClassDeclaration(classDecl, p) {
581
+ let kind = "";
582
+ switch (classDecl.classKind.type) {
583
+ case java_1.J.ClassDeclaration.Kind.Type.Class:
584
+ kind = "class";
585
+ break;
586
+ case java_1.J.ClassDeclaration.Kind.Type.Enum:
587
+ kind = "enum";
588
+ break;
589
+ case java_1.J.ClassDeclaration.Kind.Type.Interface:
590
+ kind = "interface";
591
+ break;
592
+ case java_1.J.ClassDeclaration.Kind.Type.Annotation:
593
+ kind = "@interface";
594
+ break;
595
+ case java_1.J.ClassDeclaration.Kind.Type.Record:
596
+ kind = "record";
597
+ break;
598
+ }
599
+ await this.beforeSyntax(classDecl, p);
600
+ await this.visitSpace(java_1.emptySpace, p);
601
+ await this.visitNodes(classDecl.leadingAnnotations, p);
602
+ for (const m of classDecl.modifiers) {
603
+ await this.visitModifier(m, p);
604
+ }
605
+ await this.visitNodes(classDecl.classKind.annotations, p);
606
+ await this.visitSpace(classDecl.classKind.prefix, p);
607
+ p.append(kind);
608
+ await this.visit(classDecl.name, p);
609
+ classDecl.typeParameters && await this.visitContainerLocal("<", classDecl.typeParameters, ",", ">", p);
610
+ classDecl.primaryConstructor && await this.visitContainerLocal("(", classDecl.primaryConstructor, ",", ")", p);
611
+ classDecl.extends && await this.visitLeftPaddedLocal("extends", classDecl.extends, p);
612
+ classDecl.implements && await this.visitContainerLocal(classDecl.classKind.type === java_1.J.ClassDeclaration.Kind.Type.Interface ? "extends" : "implements", classDecl.implements, ",", null, p);
613
+ await this.visit(classDecl.body, p);
614
+ await this.afterSyntax(classDecl, p);
615
+ return classDecl;
616
+ }
617
+ async visitMethodDeclaration(method, p) {
618
+ await this.beforeSyntax(method, p);
619
+ await this.visitSpace(java_1.emptySpace, p);
620
+ await this.visitNodes(method.leadingAnnotations, p);
621
+ for (const m of method.modifiers) {
622
+ await this.visitModifier(m, p);
623
+ }
624
+ let m;
625
+ if ((m = (0, markers_1.findMarker)(method, tree_1.JS.Markers.FunctionDeclaration))) {
626
+ await this.visitSpace(m.prefix, p);
627
+ p.append("function");
628
+ }
629
+ const asterisk = (0, markers_1.findMarker)(method, tree_1.JS.Markers.Generator);
630
+ if (asterisk) {
631
+ await this.visitSpace(asterisk.prefix, p);
632
+ p.append("*");
633
+ }
634
+ await this.visit(method.name, p);
635
+ const typeParameters = method.typeParameters;
636
+ if (typeParameters) {
637
+ await this.visitNodes(typeParameters.annotations, p);
638
+ await this.visitSpace(typeParameters.prefix, p);
639
+ await this.visitMarkers(typeParameters.markers, p);
640
+ p.append("<");
641
+ await this.visitRightPaddedLocal(typeParameters.typeParameters, ",", p);
642
+ p.append(">");
643
+ }
644
+ await this.visitContainerLocal("(", method.parameters, ",", ")", p);
645
+ if (method.returnTypeExpression) {
646
+ await this.visit(method.returnTypeExpression, p);
647
+ }
648
+ method.body && await this.visit(method.body, p);
649
+ await this.afterSyntax(method, p);
650
+ return method;
651
+ }
652
+ async visitComputedPropertyMethodDeclaration(method, p) {
653
+ await this.beforeSyntax(method, p);
654
+ await this.visitSpace(java_1.emptySpace, p);
655
+ await this.visitNodes(method.leadingAnnotations, p);
656
+ for (const it of method.modifiers) {
657
+ await this.visitModifier(it, p);
658
+ }
659
+ const generator = (0, markers_1.findMarker)(method, tree_1.JS.Markers.Generator);
660
+ if (generator) {
661
+ await this.visitSpace(generator.prefix, p);
662
+ p.append("*");
663
+ }
664
+ await this.visit(method.name, p);
665
+ const typeParameters = method.typeParameters;
666
+ if (typeParameters) {
667
+ await this.visitNodes(typeParameters.annotations, p);
668
+ await this.visitSpace(typeParameters.prefix, p);
669
+ await this.visitMarkers(typeParameters.markers, p);
670
+ p.append("<");
671
+ await this.visitRightPaddedLocal(typeParameters.typeParameters, ",", p);
672
+ p.append(">");
673
+ }
674
+ await this.visitContainerLocal("(", method.parameters, ",", ")", p);
675
+ if (method.returnTypeExpression) {
676
+ await this.visit(method.returnTypeExpression, p);
677
+ }
678
+ method.body && await this.visit(method.body, p);
679
+ await this.afterSyntax(method, p);
680
+ return method;
681
+ }
682
+ async visitMethodInvocation(method, p) {
683
+ await this.beforeSyntax(method, p);
684
+ if (method.name.simpleName.length === 0) {
685
+ method.select && await this.visitRightPadded(method.select, p);
686
+ }
687
+ else {
688
+ if (method.select) {
689
+ await this.visitRightPadded(method.select, p);
690
+ if (!method.select.element.markers.markers.find(m => m.kind === tree_1.JS.Markers.Optional)) {
691
+ p.append(".");
826
692
  }
827
- const defaultType = bounds.elements[1];
828
- if (!(defaultType.element.kind === java_1.J.Kind.Empty)) {
829
- p.append("=");
830
- yield this.visitRightPadded(defaultType, p);
693
+ else {
694
+ p.append("?.");
831
695
  }
832
696
  }
833
- yield this.afterSyntax(typeParameter, p);
834
- return typeParameter;
835
- });
836
- }
837
- visitArrowFunction(arrowFunction, p) {
838
- return __awaiter(this, void 0, void 0, function* () {
839
- yield this.beforeSyntax(arrowFunction, p);
840
- yield this.visitNodes(arrowFunction.leadingAnnotations, p);
841
- for (const m of arrowFunction.modifiers) {
842
- yield this.visitModifier(m, p);
843
- }
844
- const typeParameters = arrowFunction.typeParameters;
845
- if (typeParameters) {
846
- yield this.visitNodes(typeParameters.annotations, p);
847
- yield this.visitSpace(typeParameters.prefix, p);
848
- yield this.visitMarkers(typeParameters.markers, p);
849
- p.append("<");
850
- yield this.visitRightPaddedLocal(typeParameters.typeParameters, ",", p);
851
- p.append(">");
852
- }
853
- const lambda = arrowFunction.lambda;
854
- if (lambda.parameters.parenthesized) {
855
- yield this.visitSpace(lambda.parameters.prefix, p);
856
- p.append("(");
857
- yield this.visitRightPaddedLocal(lambda.parameters.parameters, ",", p);
858
- p.append(")");
859
- }
860
- else {
861
- yield this.visitRightPaddedLocal(lambda.parameters.parameters, ",", p);
862
- }
863
- if (arrowFunction.returnTypeExpression) {
864
- yield this.visit(arrowFunction.returnTypeExpression, p);
865
- }
866
- yield this.visitSpace(lambda.arrow, p);
867
- p.append("=>");
868
- yield this.visit(lambda.body, p);
869
- yield this.afterSyntax(arrowFunction, p);
870
- return arrowFunction;
871
- });
872
- }
873
- visitConditionalType(conditionalType, p) {
874
- return __awaiter(this, void 0, void 0, function* () {
875
- yield this.beforeSyntax(conditionalType, p);
876
- yield this.visit(conditionalType.checkType, p);
877
- yield this.visitLeftPaddedLocal("extends", conditionalType.condition, p);
878
- yield this.afterSyntax(conditionalType, p);
879
- return conditionalType;
880
- });
881
- }
882
- visitExpressionWithTypeArguments(type, p) {
883
- return __awaiter(this, void 0, void 0, function* () {
884
- yield this.beforeSyntax(type, p);
885
- yield this.visit(type.clazz, p);
886
- type.typeArguments && (yield this.visitContainerLocal("<", type.typeArguments, ",", ">", p));
887
- yield this.afterSyntax(type, p);
888
- return type;
889
- });
890
- }
891
- visitImportType(importType, p) {
892
- return __awaiter(this, void 0, void 0, function* () {
893
- yield this.beforeSyntax(importType, p);
894
- if (importType.hasTypeof.element) {
895
- p.append("typeof");
896
- yield this.visitRightPadded(importType.hasTypeof, p);
897
- }
898
- p.append("import");
899
- yield this.visitContainerLocal("(", importType.argumentAndAttributes, ",", ")", p);
900
- importType.qualifier && (yield this.visitLeftPaddedLocal(".", importType.qualifier, p));
901
- importType.typeArguments && (yield this.visitContainerLocal("<", importType.typeArguments, ",", ">", p));
902
- yield this.afterSyntax(importType, p);
903
- return importType;
904
- });
905
- }
906
- visitTypeDeclaration(typeDeclaration, p) {
907
- return __awaiter(this, void 0, void 0, function* () {
908
- yield this.beforeSyntax(typeDeclaration, p);
909
- for (const m of typeDeclaration.modifiers) {
910
- yield this.visitModifier(m, p);
911
- }
912
- yield this.visitLeftPaddedLocal("type", typeDeclaration.name, p);
913
- const typeParameters = typeDeclaration.typeParameters;
914
- if (typeParameters) {
915
- yield this.visitNodes(typeParameters.annotations, p);
916
- yield this.visitSpace(typeParameters.prefix, p);
917
- yield this.visitMarkers(typeParameters.markers, p);
918
- p.append("<");
919
- yield this.visitRightPaddedLocal(typeParameters.typeParameters, ",", p);
920
- p.append(">");
921
- }
922
- yield this.visitLeftPaddedLocal("=", typeDeclaration.initializer, p);
923
- yield this.afterSyntax(typeDeclaration, p);
924
- return typeDeclaration;
925
- });
926
- }
927
- visitLiteralType(literalType, p) {
928
- return __awaiter(this, void 0, void 0, function* () {
929
- yield this.beforeSyntax(literalType, p);
930
- yield this.visit(literalType.literal, p);
931
- yield this.afterSyntax(literalType, p);
932
- return literalType;
933
- });
934
- }
935
- visitNamedImports(namedImports, p) {
936
- return __awaiter(this, void 0, void 0, function* () {
937
- yield this.beforeSyntax(namedImports, p);
938
- yield this.visitContainerLocal("{", namedImports.elements, ",", "}", p);
939
- yield this.afterSyntax(namedImports, p);
940
- return namedImports;
941
- });
942
- }
943
- visitImportSpecifier(jis, p) {
944
- return __awaiter(this, void 0, void 0, function* () {
945
- yield this.beforeSyntax(jis, p);
946
- if (jis.importType.element) {
947
- yield this.visitLeftPaddedLocal("type", jis.importType, p);
948
- }
949
- yield this.visit(jis.specifier, p);
950
- yield this.afterSyntax(jis, p);
951
- return jis;
952
- });
953
- }
954
- visitExportDeclaration(ed, p) {
955
- return __awaiter(this, void 0, void 0, function* () {
956
- yield this.beforeSyntax(ed, p);
957
- p.append("export");
958
- for (const it of ed.modifiers) {
959
- yield this.visitModifier(it, p);
960
- }
961
- if (ed.typeOnly.element) {
962
- yield this.visitLeftPaddedLocal("type", ed.typeOnly, p);
963
- }
964
- ed.exportClause && (yield this.visit(ed.exportClause, p));
965
- ed.moduleSpecifier && (yield this.visitLeftPaddedLocal("from", ed.moduleSpecifier, p));
966
- ed.attributes && (yield this.visit(ed.attributes, p));
967
- yield this.afterSyntax(ed, p);
968
- return ed;
969
- });
970
- }
971
- visitExportAssignment(es, p) {
972
- return __awaiter(this, void 0, void 0, function* () {
973
- yield this.beforeSyntax(es, p);
974
- p.append("export");
975
- yield this.visitLeftPaddedLocal(es.exportEquals ? "=" : "default", es.expression, p);
976
- yield this.afterSyntax(es, p);
977
- return es;
978
- });
979
- }
980
- visitIndexedAccessType(iat, p) {
981
- return __awaiter(this, void 0, void 0, function* () {
982
- yield this.beforeSyntax(iat, p);
983
- yield this.visit(iat.objectType, p);
984
- // expect that this element is printed accordingly
985
- // <space_before>[<inner_space_before>index<inner_right_padded_suffix_space>]<right_padded_suffix_space>
986
- yield this.visit(iat.indexType, p);
987
- yield this.afterSyntax(iat, p);
988
- return iat;
989
- });
990
- }
991
- visitIndexedAccessTypeIndexType(indexType, p) {
992
- return __awaiter(this, void 0, void 0, function* () {
993
- yield this.beforeSyntax(indexType, p);
994
- p.append("[");
995
- yield this.visitRightPadded(indexType.element, p);
996
- p.append("]");
997
- yield this.afterSyntax(indexType, p);
998
- return indexType;
999
- });
1000
- }
1001
- visitWithStatement(withStatement, p) {
1002
- return __awaiter(this, void 0, void 0, function* () {
1003
- yield this.beforeSyntax(withStatement, p);
1004
- p.append("with");
1005
- yield this.visit(withStatement.expression, p);
1006
- yield this.visitRightPadded(withStatement.body, p);
1007
- yield this.afterSyntax(withStatement, p);
1008
- return withStatement;
1009
- });
1010
- }
1011
- visitExportSpecifier(es, p) {
1012
- return __awaiter(this, void 0, void 0, function* () {
1013
- yield this.beforeSyntax(es, p);
1014
- if (es.typeOnly.element) {
1015
- yield this.visitLeftPaddedLocal("type", es.typeOnly, p);
1016
- }
1017
- yield this.visit(es.specifier, p);
1018
- yield this.afterSyntax(es, p);
1019
- return es;
1020
- });
1021
- }
1022
- visitNamedExports(ne, p) {
1023
- return __awaiter(this, void 0, void 0, function* () {
1024
- yield this.beforeSyntax(ne, p);
1025
- yield this.visitContainerLocal("{", ne.elements, ",", "}", p);
1026
- yield this.afterSyntax(ne, p);
1027
- return ne;
1028
- });
1029
- }
1030
- visitImportAttributes(importAttributes, p) {
1031
- return __awaiter(this, void 0, void 0, function* () {
1032
- yield this.beforeSyntax(importAttributes, p);
1033
- p.append((importAttributes.token === tree_1.JS.ImportAttributes.Token.With ? "with" : "assert"));
1034
- yield this.visitContainerLocal("{", importAttributes.elements, ",", "}", p);
1035
- yield this.afterSyntax(importAttributes, p);
1036
- return importAttributes;
1037
- });
1038
- }
1039
- visitImportAttribute(importAttribute, p) {
1040
- return __awaiter(this, void 0, void 0, function* () {
1041
- yield this.beforeSyntax(importAttribute, p);
1042
- yield this.visit(importAttribute.name, p);
1043
- yield this.visitLeftPaddedLocal(":", importAttribute.value, p);
1044
- yield this.afterSyntax(importAttribute, p);
1045
- return importAttribute;
1046
- });
1047
- }
1048
- visitImportTypeAttributes(importAttributes, p) {
1049
- return __awaiter(this, void 0, void 0, function* () {
1050
- yield this.beforeSyntax(importAttributes, p);
1051
- p.append("{");
1052
- yield this.visitRightPadded(importAttributes.token, p);
1053
- p.append(":");
1054
- yield this.visitContainerLocal("{", importAttributes.elements, ",", "}", p);
1055
- yield this.visitSpace(importAttributes.end, p);
1056
- p.append("}");
1057
- yield this.afterSyntax(importAttributes, p);
1058
- return importAttributes;
1059
- });
1060
- }
1061
- visitArrayBindingPattern(abp, p) {
1062
- return __awaiter(this, void 0, void 0, function* () {
1063
- yield this.beforeSyntax(abp, p);
1064
- yield this.visitContainerLocal("[", abp.elements, ",", "]", p);
1065
- yield this.afterSyntax(abp, p);
1066
- return abp;
1067
- });
1068
- }
1069
- visitMappedType(mappedType, p) {
1070
- return __awaiter(this, void 0, void 0, function* () {
1071
- yield this.beforeSyntax(mappedType, p);
1072
- p.append("{");
1073
- if (mappedType.prefixToken) {
1074
- yield this.visitLeftPadded(mappedType.prefixToken, p);
1075
- }
1076
- if (mappedType.hasReadonly.element) {
1077
- yield this.visitLeftPaddedLocal("readonly", mappedType.hasReadonly, p);
1078
- }
1079
- yield this.visitMappedTypeKeysRemapping(mappedType.keysRemapping, p);
1080
- if (mappedType.suffixToken) {
1081
- yield this.visitLeftPadded(mappedType.suffixToken, p);
1082
- }
1083
- if (mappedType.hasQuestionToken.element) {
1084
- yield this.visitLeftPaddedLocal("?", mappedType.hasQuestionToken, p);
1085
- }
1086
- const colon = mappedType.valueType.elements[0].element.kind === java_1.J.Kind.Empty ? "" : ":";
1087
- yield this.visitContainerLocal(colon, mappedType.valueType, "", "", p);
1088
- p.append("}");
1089
- yield this.afterSyntax(mappedType, p);
1090
- return mappedType;
1091
- });
1092
- }
1093
- visitMappedTypeKeysRemapping(mappedTypeKeys, p) {
1094
- return __awaiter(this, void 0, void 0, function* () {
1095
- yield this.beforeSyntax(mappedTypeKeys, p);
1096
- p.append("[");
1097
- yield this.visitRightPadded(mappedTypeKeys.typeParameter, p);
1098
- if (mappedTypeKeys.nameType) {
1099
- p.append("as");
1100
- yield this.visitRightPadded(mappedTypeKeys.nameType, p);
1101
- }
1102
- p.append("]");
1103
- yield this.afterSyntax(mappedTypeKeys, p);
1104
- return mappedTypeKeys;
1105
- });
1106
- }
1107
- visitMappedTypeParameter(mappedTypeParameter, p) {
1108
- return __awaiter(this, void 0, void 0, function* () {
1109
- yield this.beforeSyntax(mappedTypeParameter, p);
1110
- yield this.visit(mappedTypeParameter.name, p);
1111
- yield this.visitLeftPaddedLocal("in", mappedTypeParameter.iterateType, p);
1112
- yield this.afterSyntax(mappedTypeParameter, p);
1113
- return mappedTypeParameter;
1114
- });
1115
- }
1116
- visitObjectBindingPattern(objectBindingPattern, p) {
1117
- return __awaiter(this, void 0, void 0, function* () {
1118
- yield this.beforeSyntax(objectBindingPattern, p);
1119
- yield this.visitNodes(objectBindingPattern.leadingAnnotations, p);
1120
- for (const m of objectBindingPattern.modifiers) {
1121
- yield this.visitModifier(m, p);
697
+ await this.visit(method.name, p);
698
+ }
699
+ method.typeParameters && await this.visitContainerLocal("<", method.typeParameters, ",", ">", p);
700
+ await this.visitContainerLocal("(", method.arguments, ",", ")", p);
701
+ await this.afterSyntax(method, p);
702
+ return method;
703
+ }
704
+ async visitTypeParameter(typeParameter, p) {
705
+ await this.beforeSyntax(typeParameter, p);
706
+ await this.visitNodes(typeParameter.annotations, p);
707
+ for (const m of typeParameter.modifiers) {
708
+ await this.visitModifier(m, p);
709
+ }
710
+ await this.visit(typeParameter.name, p);
711
+ const bounds = typeParameter.bounds;
712
+ if (bounds) {
713
+ await this.visitSpace(bounds.before, p);
714
+ const constraintType = bounds.elements[0];
715
+ if (!(constraintType.element.kind === java_1.J.Kind.Empty)) {
716
+ p.append("extends");
717
+ await this.visitRightPadded(constraintType, p);
718
+ }
719
+ const defaultType = bounds.elements[1];
720
+ if (!(defaultType.element.kind === java_1.J.Kind.Empty)) {
721
+ p.append("=");
722
+ await this.visitRightPadded(defaultType, p);
1122
723
  }
1123
- objectBindingPattern.typeExpression && (yield this.visit(objectBindingPattern.typeExpression, p));
1124
- yield this.visitContainerLocal("{", objectBindingPattern.bindings, ",", "}", p);
1125
- objectBindingPattern.initializer && (yield this.visitLeftPaddedLocal("=", objectBindingPattern.initializer, p));
1126
- yield this.afterSyntax(objectBindingPattern, p);
1127
- return objectBindingPattern;
1128
- });
1129
- }
1130
- visitTaggedTemplateExpression(taggedTemplateExpression, p) {
1131
- return __awaiter(this, void 0, void 0, function* () {
1132
- yield this.beforeSyntax(taggedTemplateExpression, p);
1133
- taggedTemplateExpression.tag && (yield this.visitRightPadded(taggedTemplateExpression.tag, p));
1134
- taggedTemplateExpression.typeArguments && (yield this.visitContainerLocal("<", taggedTemplateExpression.typeArguments, ",", ">", p));
1135
- yield this.visit(taggedTemplateExpression.templateExpression, p);
1136
- yield this.afterSyntax(taggedTemplateExpression, p);
1137
- return taggedTemplateExpression;
1138
- });
1139
- }
1140
- visitTemplateExpression(templateExpression, p) {
1141
- return __awaiter(this, void 0, void 0, function* () {
1142
- yield this.beforeSyntax(templateExpression, p);
1143
- yield this.visit(templateExpression.head, p);
1144
- yield this.visitRightPaddedLocal(templateExpression.spans, "", p);
1145
- yield this.afterSyntax(templateExpression, p);
1146
- return templateExpression;
1147
- });
1148
- }
1149
- visitTemplateExpressionSpan(value, p) {
1150
- return __awaiter(this, void 0, void 0, function* () {
1151
- yield this.beforeSyntax(value, p);
1152
- yield this.visit(value.expression, p);
1153
- yield this.visit(value.tail, p);
1154
- yield this.afterSyntax(value, p);
1155
- return value;
1156
- });
1157
- }
1158
- visitTuple(tuple, p) {
1159
- return __awaiter(this, void 0, void 0, function* () {
1160
- yield this.beforeSyntax(tuple, p);
1161
- yield this.visitContainerLocal("[", tuple.elements, ",", "]", p);
1162
- yield this.afterSyntax(tuple, p);
1163
- return tuple;
1164
- });
1165
- }
1166
- visitTypeQuery(typeQuery, p) {
1167
- return __awaiter(this, void 0, void 0, function* () {
1168
- yield this.beforeSyntax(typeQuery, p);
1169
- p.append("typeof");
1170
- yield this.visit(typeQuery.typeExpression, p);
1171
- typeQuery.typeArguments && (yield this.visitContainerLocal("<", typeQuery.typeArguments, ",", ">", p));
1172
- yield this.afterSyntax(typeQuery, p);
1173
- return typeQuery;
1174
- });
1175
- }
1176
- visitTypeOf(typeOf, p) {
1177
- return __awaiter(this, void 0, void 0, function* () {
1178
- yield this.beforeSyntax(typeOf, p);
724
+ }
725
+ await this.afterSyntax(typeParameter, p);
726
+ return typeParameter;
727
+ }
728
+ async visitArrowFunction(arrowFunction, p) {
729
+ await this.beforeSyntax(arrowFunction, p);
730
+ await this.visitNodes(arrowFunction.leadingAnnotations, p);
731
+ for (const m of arrowFunction.modifiers) {
732
+ await this.visitModifier(m, p);
733
+ }
734
+ const typeParameters = arrowFunction.typeParameters;
735
+ if (typeParameters) {
736
+ await this.visitNodes(typeParameters.annotations, p);
737
+ await this.visitSpace(typeParameters.prefix, p);
738
+ await this.visitMarkers(typeParameters.markers, p);
739
+ p.append("<");
740
+ await this.visitRightPaddedLocal(typeParameters.typeParameters, ",", p);
741
+ p.append(">");
742
+ }
743
+ const lambda = arrowFunction.lambda;
744
+ if (lambda.parameters.parenthesized) {
745
+ await this.visitSpace(lambda.parameters.prefix, p);
746
+ p.append("(");
747
+ await this.visitRightPaddedLocal(lambda.parameters.parameters, ",", p);
748
+ p.append(")");
749
+ }
750
+ else {
751
+ await this.visitRightPaddedLocal(lambda.parameters.parameters, ",", p);
752
+ }
753
+ if (arrowFunction.returnTypeExpression) {
754
+ await this.visit(arrowFunction.returnTypeExpression, p);
755
+ }
756
+ await this.visitSpace(lambda.arrow, p);
757
+ p.append("=>");
758
+ await this.visit(lambda.body, p);
759
+ await this.afterSyntax(arrowFunction, p);
760
+ return arrowFunction;
761
+ }
762
+ async visitConditionalType(conditionalType, p) {
763
+ await this.beforeSyntax(conditionalType, p);
764
+ await this.visit(conditionalType.checkType, p);
765
+ await this.visitLeftPaddedLocal("extends", conditionalType.condition, p);
766
+ await this.afterSyntax(conditionalType, p);
767
+ return conditionalType;
768
+ }
769
+ async visitExpressionWithTypeArguments(type, p) {
770
+ await this.beforeSyntax(type, p);
771
+ await this.visit(type.clazz, p);
772
+ type.typeArguments && await this.visitContainerLocal("<", type.typeArguments, ",", ">", p);
773
+ await this.afterSyntax(type, p);
774
+ return type;
775
+ }
776
+ async visitImportType(importType, p) {
777
+ await this.beforeSyntax(importType, p);
778
+ if (importType.hasTypeof.element) {
1179
779
  p.append("typeof");
1180
- yield this.visit(typeOf.expression, p);
1181
- yield this.afterSyntax(typeOf, p);
1182
- return typeOf;
1183
- });
1184
- }
1185
- visitComputedPropertyName(computedPropertyName, p) {
1186
- return __awaiter(this, void 0, void 0, function* () {
1187
- yield this.beforeSyntax(computedPropertyName, p);
1188
- p.append("[");
1189
- yield this.visitRightPaddedLocalSingle(computedPropertyName.expression, "]", p);
1190
- yield this.afterSyntax(computedPropertyName, p);
1191
- return computedPropertyName;
1192
- });
1193
- }
1194
- visitTypeOperator(typeOperator, p) {
1195
- return __awaiter(this, void 0, void 0, function* () {
1196
- yield this.beforeSyntax(typeOperator, p);
1197
- let keyword = "";
1198
- if (typeOperator.operator === tree_1.JS.TypeOperator.Type.ReadOnly) {
1199
- keyword = "readonly";
1200
- }
1201
- else if (typeOperator.operator === tree_1.JS.TypeOperator.Type.KeyOf) {
1202
- keyword = "keyof";
1203
- }
1204
- else if (typeOperator.operator === tree_1.JS.TypeOperator.Type.Unique) {
1205
- keyword = "unique";
1206
- }
1207
- p.append(keyword);
1208
- yield this.visitLeftPadded(typeOperator.expression, p);
1209
- yield this.afterSyntax(typeOperator, p);
1210
- return typeOperator;
1211
- });
1212
- }
1213
- visitTypePredicate(typePredicate, p) {
1214
- return __awaiter(this, void 0, void 0, function* () {
1215
- yield this.beforeSyntax(typePredicate, p);
1216
- if (typePredicate.asserts.element) {
1217
- yield this.visitLeftPaddedLocal("asserts", typePredicate.asserts, p);
1218
- }
1219
- yield this.visit(typePredicate.parameterName, p);
1220
- typePredicate.expression && (yield this.visitLeftPaddedLocal("is", typePredicate.expression, p));
1221
- yield this.afterSyntax(typePredicate, p);
1222
- return typePredicate;
1223
- });
1224
- }
1225
- visitIndexSignatureDeclaration(isd, p) {
1226
- return __awaiter(this, void 0, void 0, function* () {
1227
- yield this.beforeSyntax(isd, p);
1228
- for (const m of isd.modifiers) {
1229
- yield this.visitModifier(m, p);
1230
- }
1231
- yield this.visitContainerLocal("[", isd.parameters, "", "]", p);
1232
- yield this.visitLeftPaddedLocal(":", isd.typeExpression, p);
1233
- yield this.afterSyntax(isd, p);
1234
- return isd;
1235
- });
1236
- }
1237
- visitAnnotation(annotation, p) {
1238
- return __awaiter(this, void 0, void 0, function* () {
1239
- yield this.beforeSyntax(annotation, p);
1240
- p.append("@");
1241
- yield this.visit(annotation.annotationType, p);
1242
- annotation.arguments && (yield this.visitContainerLocal("(", annotation.arguments, ",", ")", p));
1243
- yield this.afterSyntax(annotation, p);
1244
- return annotation;
1245
- });
1246
- }
1247
- visitNewArray(newArray, p) {
1248
- return __awaiter(this, void 0, void 0, function* () {
1249
- yield this.beforeSyntax(newArray, p);
1250
- newArray.typeExpression && (yield this.visit(newArray.typeExpression, p));
1251
- yield this.visitNodes(newArray.dimensions, p);
1252
- newArray.initializer && (yield this.visitContainerLocal("[", newArray.initializer, ",", "]", p));
1253
- yield this.afterSyntax(newArray, p);
1254
- return newArray;
1255
- });
1256
- }
1257
- visitNewClass(newClass, p) {
1258
- return __awaiter(this, void 0, void 0, function* () {
1259
- yield this.beforeSyntax(newClass, p);
1260
- newClass.enclosing && (yield this.visitRightPaddedLocalSingle(newClass.enclosing, ".", p));
1261
- yield this.visitSpace(newClass.new, p);
1262
- if (newClass.class) {
1263
- p.append("new");
1264
- yield this.visit(newClass.class, p);
1265
- if (!newClass.arguments.markers.markers.find(m => m.kind === java_1.J.Markers.OmitParentheses)) {
1266
- yield this.visitContainerLocal("(", newClass.arguments, ",", ")", p);
1267
- }
1268
- }
1269
- newClass.body && (yield this.visit(newClass.body, p));
1270
- yield this.afterSyntax(newClass, p);
1271
- return newClass;
1272
- });
1273
- }
1274
- visitSwitch(switch_, p) {
1275
- return __awaiter(this, void 0, void 0, function* () {
1276
- yield this.beforeSyntax(switch_, p);
1277
- p.append("switch");
1278
- yield this.visit(switch_.selector, p);
1279
- yield this.visit(switch_.cases, p);
1280
- yield this.afterSyntax(switch_, p);
1281
- return switch_;
1282
- });
1283
- }
1284
- visitCase(case_, p) {
1285
- return __awaiter(this, void 0, void 0, function* () {
1286
- yield this.beforeSyntax(case_, p);
1287
- const elem = case_.caseLabels.elements[0].element;
1288
- if (elem.kind !== java_1.J.Kind.Identifier || elem.simpleName !== "default") {
1289
- p.append("case");
1290
- }
1291
- yield this.visitContainerLocal("", case_.caseLabels, ",", "", p);
1292
- yield this.visitSpace(case_.statements.before, p);
1293
- p.append(case_.type === java_1.J.Case.Type.Statement ? ":" : "->");
1294
- yield this.visitStatements(case_.statements.elements, p);
1295
- yield this.afterSyntax(case_, p);
1296
- return case_;
1297
- });
1298
- }
1299
- visitLabel(label, p) {
1300
- return __awaiter(this, void 0, void 0, function* () {
1301
- yield this.beforeSyntax(label, p);
1302
- yield this.visitRightPaddedLocalSingle(label.label, ":", p);
1303
- yield this.visit(label.statement, p);
1304
- yield this.afterSyntax(label, p);
1305
- return label;
1306
- });
1307
- }
1308
- visitContinue(continueStatement, p) {
1309
- return __awaiter(this, void 0, void 0, function* () {
1310
- yield this.beforeSyntax(continueStatement, p);
1311
- p.append("continue");
1312
- continueStatement.label && (yield this.visit(continueStatement.label, p));
1313
- yield this.afterSyntax(continueStatement, p);
1314
- return continueStatement;
1315
- });
1316
- }
1317
- visitBreak(breakStatement, p) {
1318
- return __awaiter(this, void 0, void 0, function* () {
1319
- yield this.beforeSyntax(breakStatement, p);
1320
- p.append("break");
1321
- breakStatement.label && (yield this.visit(breakStatement.label, p));
1322
- yield this.afterSyntax(breakStatement, p);
1323
- return breakStatement;
1324
- });
1325
- }
1326
- visitFieldAccess(fieldAccess, p) {
1327
- return __awaiter(this, void 0, void 0, function* () {
1328
- yield this.beforeSyntax(fieldAccess, p);
1329
- yield this.visit(fieldAccess.target, p);
1330
- yield this.visitLeftPaddedLocal(".", fieldAccess.name, p);
1331
- yield this.afterSyntax(fieldAccess, p);
1332
- return fieldAccess;
1333
- });
1334
- }
1335
- visitTypeLiteral(tl, p) {
1336
- return __awaiter(this, void 0, void 0, function* () {
1337
- yield this.beforeSyntax(tl, p);
1338
- yield this.visit(tl.members, p);
1339
- yield this.afterSyntax(tl, p);
1340
- return tl;
1341
- });
1342
- }
1343
- visitParentheses(parens, p) {
1344
- return __awaiter(this, void 0, void 0, function* () {
1345
- yield this.beforeSyntax(parens, p);
1346
- p.append('(');
1347
- yield this.visitRightPaddedLocalSingle(parens.tree, ")", p);
1348
- yield this.afterSyntax(parens, p);
1349
- return parens;
1350
- });
1351
- }
1352
- visitParameterizedType(type, p) {
1353
- return __awaiter(this, void 0, void 0, function* () {
1354
- yield this.beforeSyntax(type, p);
1355
- yield this.visit(type.class, p);
1356
- type.typeParameters && (yield this.visitContainerLocal("<", type.typeParameters, ",", ">", p));
1357
- yield this.afterSyntax(type, p);
1358
- return type;
1359
- });
1360
- }
1361
- visitAs(as_, p) {
1362
- return __awaiter(this, void 0, void 0, function* () {
1363
- yield this.beforeSyntax(as_, p);
1364
- yield this.visitRightPadded(as_.left, p);
780
+ await this.visitRightPadded(importType.hasTypeof, p);
781
+ }
782
+ p.append("import");
783
+ await this.visitContainerLocal("(", importType.argumentAndAttributes, ",", ")", p);
784
+ importType.qualifier && await this.visitLeftPaddedLocal(".", importType.qualifier, p);
785
+ importType.typeArguments && await this.visitContainerLocal("<", importType.typeArguments, ",", ">", p);
786
+ await this.afterSyntax(importType, p);
787
+ return importType;
788
+ }
789
+ async visitTypeDeclaration(typeDeclaration, p) {
790
+ await this.beforeSyntax(typeDeclaration, p);
791
+ for (const m of typeDeclaration.modifiers) {
792
+ await this.visitModifier(m, p);
793
+ }
794
+ await this.visitLeftPaddedLocal("type", typeDeclaration.name, p);
795
+ const typeParameters = typeDeclaration.typeParameters;
796
+ if (typeParameters) {
797
+ await this.visitNodes(typeParameters.annotations, p);
798
+ await this.visitSpace(typeParameters.prefix, p);
799
+ await this.visitMarkers(typeParameters.markers, p);
800
+ p.append("<");
801
+ await this.visitRightPaddedLocal(typeParameters.typeParameters, ",", p);
802
+ p.append(">");
803
+ }
804
+ await this.visitLeftPaddedLocal("=", typeDeclaration.initializer, p);
805
+ await this.afterSyntax(typeDeclaration, p);
806
+ return typeDeclaration;
807
+ }
808
+ async visitLiteralType(literalType, p) {
809
+ await this.beforeSyntax(literalType, p);
810
+ await this.visit(literalType.literal, p);
811
+ await this.afterSyntax(literalType, p);
812
+ return literalType;
813
+ }
814
+ async visitNamedImports(namedImports, p) {
815
+ await this.beforeSyntax(namedImports, p);
816
+ await this.visitContainerLocal("{", namedImports.elements, ",", "}", p);
817
+ await this.afterSyntax(namedImports, p);
818
+ return namedImports;
819
+ }
820
+ async visitImportSpecifier(jis, p) {
821
+ await this.beforeSyntax(jis, p);
822
+ if (jis.importType.element) {
823
+ await this.visitLeftPaddedLocal("type", jis.importType, p);
824
+ }
825
+ await this.visit(jis.specifier, p);
826
+ await this.afterSyntax(jis, p);
827
+ return jis;
828
+ }
829
+ async visitExportDeclaration(ed, p) {
830
+ await this.beforeSyntax(ed, p);
831
+ p.append("export");
832
+ for (const it of ed.modifiers) {
833
+ await this.visitModifier(it, p);
834
+ }
835
+ if (ed.typeOnly.element) {
836
+ await this.visitLeftPaddedLocal("type", ed.typeOnly, p);
837
+ }
838
+ ed.exportClause && await this.visit(ed.exportClause, p);
839
+ ed.moduleSpecifier && await this.visitLeftPaddedLocal("from", ed.moduleSpecifier, p);
840
+ ed.attributes && await this.visit(ed.attributes, p);
841
+ await this.afterSyntax(ed, p);
842
+ return ed;
843
+ }
844
+ async visitExportAssignment(es, p) {
845
+ await this.beforeSyntax(es, p);
846
+ p.append("export");
847
+ await this.visitLeftPaddedLocal(es.exportEquals ? "=" : "default", es.expression, p);
848
+ await this.afterSyntax(es, p);
849
+ return es;
850
+ }
851
+ async visitIndexedAccessType(iat, p) {
852
+ await this.beforeSyntax(iat, p);
853
+ await this.visit(iat.objectType, p);
854
+ // expect that this element is printed accordingly
855
+ // <space_before>[<inner_space_before>index<inner_right_padded_suffix_space>]<right_padded_suffix_space>
856
+ await this.visit(iat.indexType, p);
857
+ await this.afterSyntax(iat, p);
858
+ return iat;
859
+ }
860
+ async visitIndexedAccessTypeIndexType(indexType, p) {
861
+ await this.beforeSyntax(indexType, p);
862
+ p.append("[");
863
+ await this.visitRightPadded(indexType.element, p);
864
+ p.append("]");
865
+ await this.afterSyntax(indexType, p);
866
+ return indexType;
867
+ }
868
+ async visitWithStatement(withStatement, p) {
869
+ await this.beforeSyntax(withStatement, p);
870
+ p.append("with");
871
+ await this.visit(withStatement.expression, p);
872
+ await this.visitRightPadded(withStatement.body, p);
873
+ await this.afterSyntax(withStatement, p);
874
+ return withStatement;
875
+ }
876
+ async visitExportSpecifier(es, p) {
877
+ await this.beforeSyntax(es, p);
878
+ if (es.typeOnly.element) {
879
+ await this.visitLeftPaddedLocal("type", es.typeOnly, p);
880
+ }
881
+ await this.visit(es.specifier, p);
882
+ await this.afterSyntax(es, p);
883
+ return es;
884
+ }
885
+ async visitNamedExports(ne, p) {
886
+ await this.beforeSyntax(ne, p);
887
+ await this.visitContainerLocal("{", ne.elements, ",", "}", p);
888
+ await this.afterSyntax(ne, p);
889
+ return ne;
890
+ }
891
+ async visitImportAttributes(importAttributes, p) {
892
+ await this.beforeSyntax(importAttributes, p);
893
+ p.append((importAttributes.token === tree_1.JS.ImportAttributes.Token.With ? "with" : "assert"));
894
+ await this.visitContainerLocal("{", importAttributes.elements, ",", "}", p);
895
+ await this.afterSyntax(importAttributes, p);
896
+ return importAttributes;
897
+ }
898
+ async visitImportAttribute(importAttribute, p) {
899
+ await this.beforeSyntax(importAttribute, p);
900
+ await this.visit(importAttribute.name, p);
901
+ await this.visitLeftPaddedLocal(":", importAttribute.value, p);
902
+ await this.afterSyntax(importAttribute, p);
903
+ return importAttribute;
904
+ }
905
+ async visitImportTypeAttributes(importAttributes, p) {
906
+ await this.beforeSyntax(importAttributes, p);
907
+ p.append("{");
908
+ await this.visitRightPadded(importAttributes.token, p);
909
+ p.append(":");
910
+ await this.visitContainerLocal("{", importAttributes.elements, ",", "}", p);
911
+ await this.visitSpace(importAttributes.end, p);
912
+ p.append("}");
913
+ await this.afterSyntax(importAttributes, p);
914
+ return importAttributes;
915
+ }
916
+ async visitArrayBindingPattern(abp, p) {
917
+ await this.beforeSyntax(abp, p);
918
+ await this.visitContainerLocal("[", abp.elements, ",", "]", p);
919
+ await this.afterSyntax(abp, p);
920
+ return abp;
921
+ }
922
+ async visitMappedType(mappedType, p) {
923
+ await this.beforeSyntax(mappedType, p);
924
+ p.append("{");
925
+ if (mappedType.prefixToken) {
926
+ await this.visitLeftPadded(mappedType.prefixToken, p);
927
+ }
928
+ if (mappedType.hasReadonly.element) {
929
+ await this.visitLeftPaddedLocal("readonly", mappedType.hasReadonly, p);
930
+ }
931
+ await this.visitMappedTypeKeysRemapping(mappedType.keysRemapping, p);
932
+ if (mappedType.suffixToken) {
933
+ await this.visitLeftPadded(mappedType.suffixToken, p);
934
+ }
935
+ if (mappedType.hasQuestionToken.element) {
936
+ await this.visitLeftPaddedLocal("?", mappedType.hasQuestionToken, p);
937
+ }
938
+ const colon = mappedType.valueType.elements[0].element.kind === java_1.J.Kind.Empty ? "" : ":";
939
+ await this.visitContainerLocal(colon, mappedType.valueType, "", "", p);
940
+ p.append("}");
941
+ await this.afterSyntax(mappedType, p);
942
+ return mappedType;
943
+ }
944
+ async visitMappedTypeKeysRemapping(mappedTypeKeys, p) {
945
+ await this.beforeSyntax(mappedTypeKeys, p);
946
+ p.append("[");
947
+ await this.visitRightPadded(mappedTypeKeys.typeParameter, p);
948
+ if (mappedTypeKeys.nameType) {
1365
949
  p.append("as");
1366
- yield this.visit(as_.right, p);
1367
- yield this.afterSyntax(as_, p);
1368
- return as_;
1369
- });
1370
- }
1371
- visitAssignment(assignment, p) {
1372
- return __awaiter(this, void 0, void 0, function* () {
1373
- yield this.beforeSyntax(assignment, p);
1374
- yield this.visit(assignment.variable, p);
1375
- yield this.visitLeftPaddedLocal("=", assignment.assignment, p);
1376
- yield this.afterSyntax(assignment, p);
1377
- return assignment;
1378
- });
1379
- }
1380
- visitPropertyAssignment(propertyAssignment, p) {
1381
- return __awaiter(this, void 0, void 0, function* () {
1382
- yield this.beforeSyntax(propertyAssignment, p);
1383
- yield this.visitRightPadded(propertyAssignment.name, p);
1384
- if (propertyAssignment.initializer) {
1385
- // if the property is not null, we should print it like `{ a: b }`
1386
- // otherwise, it is a shorthand assignment where we have stuff like `{ a }` only
1387
- if (propertyAssignment.assigmentToken === tree_1.JS.PropertyAssignment.Token.Colon) {
1388
- p.append(':');
1389
- }
1390
- else if (propertyAssignment.assigmentToken === tree_1.JS.PropertyAssignment.Token.Equals) {
1391
- p.append('=');
1392
- }
1393
- yield this.visit(propertyAssignment.initializer, p);
1394
- }
1395
- yield this.afterSyntax(propertyAssignment, p);
1396
- return propertyAssignment;
1397
- });
1398
- }
1399
- visitAssignmentOperation(assignOp, p) {
1400
- return __awaiter(this, void 0, void 0, function* () {
1401
- let keyword = "";
1402
- switch (assignOp.operator.element) {
1403
- case java_1.J.AssignmentOperation.Type.Addition:
1404
- keyword = "+=";
1405
- break;
1406
- case java_1.J.AssignmentOperation.Type.Subtraction:
1407
- keyword = "-=";
1408
- break;
1409
- case java_1.J.AssignmentOperation.Type.Multiplication:
1410
- keyword = "*=";
1411
- break;
1412
- case java_1.J.AssignmentOperation.Type.Division:
1413
- keyword = "/=";
1414
- break;
1415
- case java_1.J.AssignmentOperation.Type.Modulo:
1416
- keyword = "%=";
1417
- break;
1418
- case java_1.J.AssignmentOperation.Type.BitAnd:
1419
- keyword = "&=";
1420
- break;
1421
- case java_1.J.AssignmentOperation.Type.BitOr:
1422
- keyword = "|=";
1423
- break;
1424
- case java_1.J.AssignmentOperation.Type.BitXor:
1425
- keyword = "^=";
1426
- break;
1427
- case java_1.J.AssignmentOperation.Type.LeftShift:
1428
- keyword = "<<=";
1429
- break;
1430
- case java_1.J.AssignmentOperation.Type.RightShift:
1431
- keyword = ">>=";
1432
- break;
1433
- case java_1.J.AssignmentOperation.Type.UnsignedRightShift:
1434
- keyword = ">>>=";
1435
- break;
1436
- }
1437
- yield this.beforeSyntax(assignOp, p);
1438
- yield this.visit(assignOp.variable, p);
1439
- yield this.visitSpace(assignOp.operator.before, p);
1440
- p.append(keyword);
1441
- yield this.visit(assignOp.assignment, p);
1442
- yield this.afterSyntax(assignOp, p);
1443
- return assignOp;
1444
- });
1445
- }
1446
- visitAssignmentOperationExtensions(assignOp, p) {
1447
- return __awaiter(this, void 0, void 0, function* () {
1448
- let keyword = "";
1449
- switch (assignOp.operator.element) {
1450
- case tree_1.JS.AssignmentOperation.Type.QuestionQuestion:
1451
- keyword = "??=";
1452
- break;
1453
- case tree_1.JS.AssignmentOperation.Type.And:
1454
- keyword = "&&=";
1455
- break;
1456
- case tree_1.JS.AssignmentOperation.Type.Or:
1457
- keyword = "||=";
1458
- break;
1459
- case tree_1.JS.AssignmentOperation.Type.Power:
1460
- keyword = "**";
1461
- break;
1462
- case tree_1.JS.AssignmentOperation.Type.Exp:
1463
- keyword = "**=";
1464
- break;
1465
- }
1466
- yield this.beforeSyntax(assignOp, p);
1467
- yield this.visit(assignOp.variable, p);
1468
- yield this.visitSpace(assignOp.operator.before, p);
1469
- p.append(keyword);
1470
- yield this.visit(assignOp.assignment, p);
1471
- yield this.afterSyntax(assignOp, p);
1472
- return assignOp;
1473
- });
1474
- }
1475
- visitEnumValue(enum_, p) {
1476
- return __awaiter(this, void 0, void 0, function* () {
1477
- yield this.beforeSyntax(enum_, p);
1478
- yield this.visit(enum_.name, p);
1479
- const initializer = enum_.initializer;
1480
- if (initializer) {
1481
- yield this.visitSpace(initializer.prefix, p);
1482
- p.append("=");
1483
- // There can be only one argument
1484
- const expression = initializer.arguments.elements[0];
1485
- yield this.visitRightPadded(expression, p);
1486
- return enum_;
950
+ await this.visitRightPadded(mappedTypeKeys.nameType, p);
951
+ }
952
+ p.append("]");
953
+ await this.afterSyntax(mappedTypeKeys, p);
954
+ return mappedTypeKeys;
955
+ }
956
+ async visitMappedTypeParameter(mappedTypeParameter, p) {
957
+ await this.beforeSyntax(mappedTypeParameter, p);
958
+ await this.visit(mappedTypeParameter.name, p);
959
+ await this.visitLeftPaddedLocal("in", mappedTypeParameter.iterateType, p);
960
+ await this.afterSyntax(mappedTypeParameter, p);
961
+ return mappedTypeParameter;
962
+ }
963
+ async visitObjectBindingPattern(objectBindingPattern, p) {
964
+ await this.beforeSyntax(objectBindingPattern, p);
965
+ await this.visitNodes(objectBindingPattern.leadingAnnotations, p);
966
+ for (const m of objectBindingPattern.modifiers) {
967
+ await this.visitModifier(m, p);
968
+ }
969
+ objectBindingPattern.typeExpression && await this.visit(objectBindingPattern.typeExpression, p);
970
+ await this.visitContainerLocal("{", objectBindingPattern.bindings, ",", "}", p);
971
+ objectBindingPattern.initializer && await this.visitLeftPaddedLocal("=", objectBindingPattern.initializer, p);
972
+ await this.afterSyntax(objectBindingPattern, p);
973
+ return objectBindingPattern;
974
+ }
975
+ async visitTaggedTemplateExpression(taggedTemplateExpression, p) {
976
+ await this.beforeSyntax(taggedTemplateExpression, p);
977
+ taggedTemplateExpression.tag && await this.visitRightPadded(taggedTemplateExpression.tag, p);
978
+ taggedTemplateExpression.typeArguments && await this.visitContainerLocal("<", taggedTemplateExpression.typeArguments, ",", ">", p);
979
+ await this.visit(taggedTemplateExpression.templateExpression, p);
980
+ await this.afterSyntax(taggedTemplateExpression, p);
981
+ return taggedTemplateExpression;
982
+ }
983
+ async visitTemplateExpression(templateExpression, p) {
984
+ await this.beforeSyntax(templateExpression, p);
985
+ await this.visit(templateExpression.head, p);
986
+ await this.visitRightPaddedLocal(templateExpression.spans, "", p);
987
+ await this.afterSyntax(templateExpression, p);
988
+ return templateExpression;
989
+ }
990
+ async visitTemplateExpressionSpan(value, p) {
991
+ await this.beforeSyntax(value, p);
992
+ await this.visit(value.expression, p);
993
+ await this.visit(value.tail, p);
994
+ await this.afterSyntax(value, p);
995
+ return value;
996
+ }
997
+ async visitTuple(tuple, p) {
998
+ await this.beforeSyntax(tuple, p);
999
+ await this.visitContainerLocal("[", tuple.elements, ",", "]", p);
1000
+ await this.afterSyntax(tuple, p);
1001
+ return tuple;
1002
+ }
1003
+ async visitTypeQuery(typeQuery, p) {
1004
+ await this.beforeSyntax(typeQuery, p);
1005
+ p.append("typeof");
1006
+ await this.visit(typeQuery.typeExpression, p);
1007
+ typeQuery.typeArguments && await this.visitContainerLocal("<", typeQuery.typeArguments, ",", ">", p);
1008
+ await this.afterSyntax(typeQuery, p);
1009
+ return typeQuery;
1010
+ }
1011
+ async visitTypeOf(typeOf, p) {
1012
+ await this.beforeSyntax(typeOf, p);
1013
+ p.append("typeof");
1014
+ await this.visit(typeOf.expression, p);
1015
+ await this.afterSyntax(typeOf, p);
1016
+ return typeOf;
1017
+ }
1018
+ async visitComputedPropertyName(computedPropertyName, p) {
1019
+ await this.beforeSyntax(computedPropertyName, p);
1020
+ p.append("[");
1021
+ await this.visitRightPaddedLocalSingle(computedPropertyName.expression, "]", p);
1022
+ await this.afterSyntax(computedPropertyName, p);
1023
+ return computedPropertyName;
1024
+ }
1025
+ async visitTypeOperator(typeOperator, p) {
1026
+ await this.beforeSyntax(typeOperator, p);
1027
+ let keyword = "";
1028
+ if (typeOperator.operator === tree_1.JS.TypeOperator.Type.ReadOnly) {
1029
+ keyword = "readonly";
1030
+ }
1031
+ else if (typeOperator.operator === tree_1.JS.TypeOperator.Type.KeyOf) {
1032
+ keyword = "keyof";
1033
+ }
1034
+ else if (typeOperator.operator === tree_1.JS.TypeOperator.Type.Unique) {
1035
+ keyword = "unique";
1036
+ }
1037
+ p.append(keyword);
1038
+ await this.visitLeftPadded(typeOperator.expression, p);
1039
+ await this.afterSyntax(typeOperator, p);
1040
+ return typeOperator;
1041
+ }
1042
+ async visitTypePredicate(typePredicate, p) {
1043
+ await this.beforeSyntax(typePredicate, p);
1044
+ if (typePredicate.asserts.element) {
1045
+ await this.visitLeftPaddedLocal("asserts", typePredicate.asserts, p);
1046
+ }
1047
+ await this.visit(typePredicate.parameterName, p);
1048
+ typePredicate.expression && await this.visitLeftPaddedLocal("is", typePredicate.expression, p);
1049
+ await this.afterSyntax(typePredicate, p);
1050
+ return typePredicate;
1051
+ }
1052
+ async visitIndexSignatureDeclaration(isd, p) {
1053
+ await this.beforeSyntax(isd, p);
1054
+ for (const m of isd.modifiers) {
1055
+ await this.visitModifier(m, p);
1056
+ }
1057
+ await this.visitContainerLocal("[", isd.parameters, "", "]", p);
1058
+ await this.visitLeftPaddedLocal(":", isd.typeExpression, p);
1059
+ await this.afterSyntax(isd, p);
1060
+ return isd;
1061
+ }
1062
+ async visitAnnotation(annotation, p) {
1063
+ await this.beforeSyntax(annotation, p);
1064
+ p.append("@");
1065
+ await this.visit(annotation.annotationType, p);
1066
+ annotation.arguments && await this.visitContainerLocal("(", annotation.arguments, ",", ")", p);
1067
+ await this.afterSyntax(annotation, p);
1068
+ return annotation;
1069
+ }
1070
+ async visitNewArray(newArray, p) {
1071
+ await this.beforeSyntax(newArray, p);
1072
+ newArray.typeExpression && await this.visit(newArray.typeExpression, p);
1073
+ await this.visitNodes(newArray.dimensions, p);
1074
+ newArray.initializer && await this.visitContainerLocal("[", newArray.initializer, ",", "]", p);
1075
+ await this.afterSyntax(newArray, p);
1076
+ return newArray;
1077
+ }
1078
+ async visitNewClass(newClass, p) {
1079
+ await this.beforeSyntax(newClass, p);
1080
+ newClass.enclosing && await this.visitRightPaddedLocalSingle(newClass.enclosing, ".", p);
1081
+ await this.visitSpace(newClass.new, p);
1082
+ if (newClass.class) {
1083
+ p.append("new");
1084
+ await this.visit(newClass.class, p);
1085
+ if (!newClass.arguments.markers.markers.find(m => m.kind === java_1.J.Markers.OmitParentheses)) {
1086
+ await this.visitContainerLocal("(", newClass.arguments, ",", ")", p);
1487
1087
  }
1488
- yield this.afterSyntax(enum_, p);
1088
+ }
1089
+ newClass.body && await this.visit(newClass.body, p);
1090
+ await this.afterSyntax(newClass, p);
1091
+ return newClass;
1092
+ }
1093
+ async visitSwitch(switch_, p) {
1094
+ await this.beforeSyntax(switch_, p);
1095
+ p.append("switch");
1096
+ await this.visit(switch_.selector, p);
1097
+ await this.visit(switch_.cases, p);
1098
+ await this.afterSyntax(switch_, p);
1099
+ return switch_;
1100
+ }
1101
+ async visitCase(case_, p) {
1102
+ await this.beforeSyntax(case_, p);
1103
+ const elem = case_.caseLabels.elements[0].element;
1104
+ if (elem.kind !== java_1.J.Kind.Identifier || elem.simpleName !== "default") {
1105
+ p.append("case");
1106
+ }
1107
+ await this.visitContainerLocal("", case_.caseLabels, ",", "", p);
1108
+ await this.visitSpace(case_.statements.before, p);
1109
+ p.append(case_.type === java_1.J.Case.Type.Statement ? ":" : "->");
1110
+ await this.visitStatements(case_.statements.elements, p);
1111
+ await this.afterSyntax(case_, p);
1112
+ return case_;
1113
+ }
1114
+ async visitLabel(label, p) {
1115
+ await this.beforeSyntax(label, p);
1116
+ await this.visitRightPaddedLocalSingle(label.label, ":", p);
1117
+ await this.visit(label.statement, p);
1118
+ await this.afterSyntax(label, p);
1119
+ return label;
1120
+ }
1121
+ async visitContinue(continueStatement, p) {
1122
+ await this.beforeSyntax(continueStatement, p);
1123
+ p.append("continue");
1124
+ continueStatement.label && await this.visit(continueStatement.label, p);
1125
+ await this.afterSyntax(continueStatement, p);
1126
+ return continueStatement;
1127
+ }
1128
+ async visitBreak(breakStatement, p) {
1129
+ await this.beforeSyntax(breakStatement, p);
1130
+ p.append("break");
1131
+ breakStatement.label && await this.visit(breakStatement.label, p);
1132
+ await this.afterSyntax(breakStatement, p);
1133
+ return breakStatement;
1134
+ }
1135
+ async visitFieldAccess(fieldAccess, p) {
1136
+ await this.beforeSyntax(fieldAccess, p);
1137
+ await this.visit(fieldAccess.target, p);
1138
+ await this.visitLeftPaddedLocal(".", fieldAccess.name, p);
1139
+ await this.afterSyntax(fieldAccess, p);
1140
+ return fieldAccess;
1141
+ }
1142
+ async visitTypeLiteral(tl, p) {
1143
+ await this.beforeSyntax(tl, p);
1144
+ await this.visit(tl.members, p);
1145
+ await this.afterSyntax(tl, p);
1146
+ return tl;
1147
+ }
1148
+ async visitParentheses(parens, p) {
1149
+ await this.beforeSyntax(parens, p);
1150
+ p.append('(');
1151
+ await this.visitRightPaddedLocalSingle(parens.tree, ")", p);
1152
+ await this.afterSyntax(parens, p);
1153
+ return parens;
1154
+ }
1155
+ async visitParameterizedType(type, p) {
1156
+ await this.beforeSyntax(type, p);
1157
+ await this.visit(type.class, p);
1158
+ type.typeParameters && await this.visitContainerLocal("<", type.typeParameters, ",", ">", p);
1159
+ await this.afterSyntax(type, p);
1160
+ return type;
1161
+ }
1162
+ async visitAs(as_, p) {
1163
+ await this.beforeSyntax(as_, p);
1164
+ await this.visitRightPadded(as_.left, p);
1165
+ p.append("as");
1166
+ await this.visit(as_.right, p);
1167
+ await this.afterSyntax(as_, p);
1168
+ return as_;
1169
+ }
1170
+ async visitAssignment(assignment, p) {
1171
+ await this.beforeSyntax(assignment, p);
1172
+ await this.visit(assignment.variable, p);
1173
+ await this.visitLeftPaddedLocal("=", assignment.assignment, p);
1174
+ await this.afterSyntax(assignment, p);
1175
+ return assignment;
1176
+ }
1177
+ async visitPropertyAssignment(propertyAssignment, p) {
1178
+ await this.beforeSyntax(propertyAssignment, p);
1179
+ await this.visitRightPadded(propertyAssignment.name, p);
1180
+ if (propertyAssignment.initializer) {
1181
+ // if the property is not null, we should print it like `{ a: b }`
1182
+ // otherwise, it is a shorthand assignment where we have stuff like `{ a }` only
1183
+ if (propertyAssignment.assigmentToken === tree_1.JS.PropertyAssignment.Token.Colon) {
1184
+ p.append(':');
1185
+ }
1186
+ else if (propertyAssignment.assigmentToken === tree_1.JS.PropertyAssignment.Token.Equals) {
1187
+ p.append('=');
1188
+ }
1189
+ await this.visit(propertyAssignment.initializer, p);
1190
+ }
1191
+ await this.afterSyntax(propertyAssignment, p);
1192
+ return propertyAssignment;
1193
+ }
1194
+ async visitAssignmentOperation(assignOp, p) {
1195
+ let keyword = "";
1196
+ switch (assignOp.operator.element) {
1197
+ case java_1.J.AssignmentOperation.Type.Addition:
1198
+ keyword = "+=";
1199
+ break;
1200
+ case java_1.J.AssignmentOperation.Type.Subtraction:
1201
+ keyword = "-=";
1202
+ break;
1203
+ case java_1.J.AssignmentOperation.Type.Multiplication:
1204
+ keyword = "*=";
1205
+ break;
1206
+ case java_1.J.AssignmentOperation.Type.Division:
1207
+ keyword = "/=";
1208
+ break;
1209
+ case java_1.J.AssignmentOperation.Type.Modulo:
1210
+ keyword = "%=";
1211
+ break;
1212
+ case java_1.J.AssignmentOperation.Type.BitAnd:
1213
+ keyword = "&=";
1214
+ break;
1215
+ case java_1.J.AssignmentOperation.Type.BitOr:
1216
+ keyword = "|=";
1217
+ break;
1218
+ case java_1.J.AssignmentOperation.Type.BitXor:
1219
+ keyword = "^=";
1220
+ break;
1221
+ case java_1.J.AssignmentOperation.Type.LeftShift:
1222
+ keyword = "<<=";
1223
+ break;
1224
+ case java_1.J.AssignmentOperation.Type.RightShift:
1225
+ keyword = ">>=";
1226
+ break;
1227
+ case java_1.J.AssignmentOperation.Type.UnsignedRightShift:
1228
+ keyword = ">>>=";
1229
+ break;
1230
+ }
1231
+ await this.beforeSyntax(assignOp, p);
1232
+ await this.visit(assignOp.variable, p);
1233
+ await this.visitSpace(assignOp.operator.before, p);
1234
+ p.append(keyword);
1235
+ await this.visit(assignOp.assignment, p);
1236
+ await this.afterSyntax(assignOp, p);
1237
+ return assignOp;
1238
+ }
1239
+ async visitAssignmentOperationExtensions(assignOp, p) {
1240
+ let keyword = "";
1241
+ switch (assignOp.operator.element) {
1242
+ case tree_1.JS.AssignmentOperation.Type.QuestionQuestion:
1243
+ keyword = "??=";
1244
+ break;
1245
+ case tree_1.JS.AssignmentOperation.Type.And:
1246
+ keyword = "&&=";
1247
+ break;
1248
+ case tree_1.JS.AssignmentOperation.Type.Or:
1249
+ keyword = "||=";
1250
+ break;
1251
+ case tree_1.JS.AssignmentOperation.Type.Power:
1252
+ keyword = "**";
1253
+ break;
1254
+ case tree_1.JS.AssignmentOperation.Type.Exp:
1255
+ keyword = "**=";
1256
+ break;
1257
+ }
1258
+ await this.beforeSyntax(assignOp, p);
1259
+ await this.visit(assignOp.variable, p);
1260
+ await this.visitSpace(assignOp.operator.before, p);
1261
+ p.append(keyword);
1262
+ await this.visit(assignOp.assignment, p);
1263
+ await this.afterSyntax(assignOp, p);
1264
+ return assignOp;
1265
+ }
1266
+ async visitEnumValue(enum_, p) {
1267
+ await this.beforeSyntax(enum_, p);
1268
+ await this.visit(enum_.name, p);
1269
+ const initializer = enum_.initializer;
1270
+ if (initializer) {
1271
+ await this.visitSpace(initializer.prefix, p);
1272
+ p.append("=");
1273
+ // There can be only one argument
1274
+ const expression = initializer.arguments.elements[0];
1275
+ await this.visitRightPadded(expression, p);
1489
1276
  return enum_;
1490
- });
1277
+ }
1278
+ await this.afterSyntax(enum_, p);
1279
+ return enum_;
1280
+ }
1281
+ async visitEnumValueSet(enums, p) {
1282
+ await this.beforeSyntax(enums, p);
1283
+ await this.visitRightPaddedLocal(enums.enums, ",", p);
1284
+ if (enums.terminatedWithSemicolon) {
1285
+ p.append(",");
1286
+ }
1287
+ await this.afterSyntax(enums, p);
1288
+ return enums;
1289
+ }
1290
+ async visitBinary(binary, p) {
1291
+ let keyword = "";
1292
+ switch (binary.operator.element) {
1293
+ case java_1.J.Binary.Type.Addition:
1294
+ keyword = "+";
1295
+ break;
1296
+ case java_1.J.Binary.Type.Subtraction:
1297
+ keyword = "-";
1298
+ break;
1299
+ case java_1.J.Binary.Type.Multiplication:
1300
+ keyword = "*";
1301
+ break;
1302
+ case java_1.J.Binary.Type.Division:
1303
+ keyword = "/";
1304
+ break;
1305
+ case java_1.J.Binary.Type.Modulo:
1306
+ keyword = "%";
1307
+ break;
1308
+ case java_1.J.Binary.Type.LessThan:
1309
+ keyword = "<";
1310
+ break;
1311
+ case java_1.J.Binary.Type.GreaterThan:
1312
+ keyword = ">";
1313
+ break;
1314
+ case java_1.J.Binary.Type.LessThanOrEqual:
1315
+ keyword = "<=";
1316
+ break;
1317
+ case java_1.J.Binary.Type.GreaterThanOrEqual:
1318
+ keyword = ">=";
1319
+ break;
1320
+ case java_1.J.Binary.Type.Equal:
1321
+ keyword = "==";
1322
+ break;
1323
+ case java_1.J.Binary.Type.NotEqual:
1324
+ keyword = "!=";
1325
+ break;
1326
+ case java_1.J.Binary.Type.BitAnd:
1327
+ keyword = "&";
1328
+ break;
1329
+ case java_1.J.Binary.Type.BitOr:
1330
+ keyword = "|";
1331
+ break;
1332
+ case java_1.J.Binary.Type.BitXor:
1333
+ keyword = "^";
1334
+ break;
1335
+ case java_1.J.Binary.Type.LeftShift:
1336
+ keyword = "<<";
1337
+ break;
1338
+ case java_1.J.Binary.Type.RightShift:
1339
+ keyword = ">>";
1340
+ break;
1341
+ case java_1.J.Binary.Type.UnsignedRightShift:
1342
+ keyword = ">>>";
1343
+ break;
1344
+ case java_1.J.Binary.Type.Or:
1345
+ keyword = "||";
1346
+ break;
1347
+ case java_1.J.Binary.Type.And:
1348
+ keyword = "&&";
1349
+ break;
1350
+ }
1351
+ await this.beforeSyntax(binary, p);
1352
+ await this.visit(binary.left, p);
1353
+ await this.visitSpace(binary.operator.before, p);
1354
+ p.append(keyword);
1355
+ await this.visit(binary.right, p);
1356
+ await this.afterSyntax(binary, p);
1357
+ return binary;
1358
+ }
1359
+ async visitBinaryExtensions(binary, p) {
1360
+ await this.beforeSyntax(binary, p);
1361
+ await this.visit(binary.left, p);
1362
+ let keyword = "";
1363
+ switch (binary.operator.element) {
1364
+ case tree_1.JS.Binary.Type.IdentityEquals:
1365
+ keyword = "===";
1366
+ break;
1367
+ case tree_1.JS.Binary.Type.IdentityNotEquals:
1368
+ keyword = "!==";
1369
+ break;
1370
+ case tree_1.JS.Binary.Type.In:
1371
+ keyword = "in";
1372
+ break;
1373
+ case tree_1.JS.Binary.Type.QuestionQuestion:
1374
+ keyword = "??";
1375
+ break;
1376
+ case tree_1.JS.Binary.Type.Comma:
1377
+ keyword = ",";
1378
+ break;
1379
+ }
1380
+ await this.visitSpace(binary.operator.before, p);
1381
+ p.append(keyword);
1382
+ await this.visit(binary.right, p);
1383
+ await this.afterSyntax(binary, p);
1384
+ return binary;
1385
+ }
1386
+ async visitUnary(unary, p) {
1387
+ await this.beforeSyntax(unary, p);
1388
+ switch (unary.operator.element) {
1389
+ case java_1.J.Unary.Type.PreIncrement:
1390
+ p.append("++");
1391
+ await this.visit(unary.expression, p);
1392
+ break;
1393
+ case java_1.J.Unary.Type.PreDecrement:
1394
+ p.append("--");
1395
+ await this.visit(unary.expression, p);
1396
+ break;
1397
+ case java_1.J.Unary.Type.PostIncrement:
1398
+ await this.visit(unary.expression, p);
1399
+ await this.visitSpace(unary.operator.before, p);
1400
+ p.append("++");
1401
+ break;
1402
+ case java_1.J.Unary.Type.PostDecrement:
1403
+ await this.visit(unary.expression, p);
1404
+ await this.visitSpace(unary.operator.before, p);
1405
+ p.append("--");
1406
+ break;
1407
+ case java_1.J.Unary.Type.Positive:
1408
+ p.append('+');
1409
+ await this.visit(unary.expression, p);
1410
+ break;
1411
+ case java_1.J.Unary.Type.Negative:
1412
+ p.append('-');
1413
+ await this.visit(unary.expression, p);
1414
+ break;
1415
+ case java_1.J.Unary.Type.Complement:
1416
+ p.append('~');
1417
+ await this.visit(unary.expression, p);
1418
+ break;
1419
+ case java_1.J.Unary.Type.Not:
1420
+ default:
1421
+ p.append('!');
1422
+ await this.visit(unary.expression, p);
1423
+ }
1424
+ await this.afterSyntax(unary, p);
1425
+ return unary;
1426
+ }
1427
+ async visitUnion(union, p) {
1428
+ await this.beforeSyntax(union, p);
1429
+ await this.visitRightPaddedLocal(union.types, "|", p);
1430
+ await this.afterSyntax(union, p);
1431
+ return union;
1432
+ }
1433
+ async visitIntersection(intersection, p) {
1434
+ await this.beforeSyntax(intersection, p);
1435
+ await this.visitRightPaddedLocal(intersection.types, "&", p);
1436
+ await this.afterSyntax(intersection, p);
1437
+ return intersection;
1438
+ }
1439
+ async visitForLoop(forLoop, p) {
1440
+ await this.beforeSyntax(forLoop, p);
1441
+ p.append("for");
1442
+ const ctrl = forLoop.control;
1443
+ await this.visitSpace(ctrl.prefix, p);
1444
+ p.append('(');
1445
+ await this.visitRightPaddedLocal(ctrl.init, ",", p);
1446
+ p.append(';');
1447
+ ctrl.condition && await this.visitRightPaddedLocalSingle(ctrl.condition, ";", p);
1448
+ await this.visitRightPaddedLocal(ctrl.update, ",", p);
1449
+ p.append(')');
1450
+ await this.visitStatementLocal(forLoop.body, p);
1451
+ await this.afterSyntax(forLoop, p);
1452
+ return forLoop;
1453
+ }
1454
+ async visitForOfLoop(loop, p) {
1455
+ await this.beforeSyntax(loop, p);
1456
+ p.append("for");
1457
+ if (loop.await) {
1458
+ await this.visitSpace(loop.await, p);
1459
+ p.append("await");
1460
+ }
1461
+ const control = loop.loop.control;
1462
+ await this.visitSpace(control.prefix, p);
1463
+ p.append('(');
1464
+ await this.visitRightPadded(control.variable, p);
1465
+ p.append("of");
1466
+ await this.visitRightPadded(control.iterable, p);
1467
+ p.append(')');
1468
+ await this.visitRightPadded(loop.loop.body, p);
1469
+ await this.afterSyntax(loop, p);
1470
+ return loop;
1471
+ }
1472
+ async visitForInLoop(loop, p) {
1473
+ await this.beforeSyntax(loop, p);
1474
+ p.append("for");
1475
+ const control = loop.control;
1476
+ await this.visitSpace(control.prefix, p);
1477
+ p.append('(');
1478
+ await this.visitRightPadded(control.variable, p);
1479
+ p.append("in");
1480
+ await this.visitRightPadded(control.iterable, p);
1481
+ p.append(')');
1482
+ await this.visitRightPadded(loop.body, p);
1483
+ await this.afterSyntax(loop, p);
1484
+ return loop;
1491
1485
  }
1492
- visitEnumValueSet(enums, p) {
1493
- return __awaiter(this, void 0, void 0, function* () {
1494
- yield this.beforeSyntax(enums, p);
1495
- yield this.visitRightPaddedLocal(enums.enums, ",", p);
1496
- if (enums.terminatedWithSemicolon) {
1486
+ // ---- print utils
1487
+ async visitStatements(statements, p) {
1488
+ var _a, _b;
1489
+ const objectLiteral = ((_a = this.getParentCursor(0)) === null || _a === void 0 ? void 0 : _a.value.kind) === java_1.J.Kind.Block &&
1490
+ ((_b = this.getParentCursor(1)) === null || _b === void 0 ? void 0 : _b.value.kind) === java_1.J.Kind.NewClass;
1491
+ for (let i = 0; i < statements.length; i++) {
1492
+ const paddedStat = statements[i];
1493
+ await this.visitStatementLocal(paddedStat, p);
1494
+ if (i < statements.length - 1 && objectLiteral) {
1497
1495
  p.append(",");
1498
1496
  }
1499
- yield this.afterSyntax(enums, p);
1500
- return enums;
1501
- });
1502
- }
1503
- visitBinary(binary, p) {
1504
- return __awaiter(this, void 0, void 0, function* () {
1505
- let keyword = "";
1506
- switch (binary.operator.element) {
1507
- case java_1.J.Binary.Type.Addition:
1508
- keyword = "+";
1509
- break;
1510
- case java_1.J.Binary.Type.Subtraction:
1511
- keyword = "-";
1512
- break;
1513
- case java_1.J.Binary.Type.Multiplication:
1514
- keyword = "*";
1515
- break;
1516
- case java_1.J.Binary.Type.Division:
1517
- keyword = "/";
1518
- break;
1519
- case java_1.J.Binary.Type.Modulo:
1520
- keyword = "%";
1521
- break;
1522
- case java_1.J.Binary.Type.LessThan:
1523
- keyword = "<";
1524
- break;
1525
- case java_1.J.Binary.Type.GreaterThan:
1526
- keyword = ">";
1527
- break;
1528
- case java_1.J.Binary.Type.LessThanOrEqual:
1529
- keyword = "<=";
1530
- break;
1531
- case java_1.J.Binary.Type.GreaterThanOrEqual:
1532
- keyword = ">=";
1533
- break;
1534
- case java_1.J.Binary.Type.Equal:
1535
- keyword = "==";
1536
- break;
1537
- case java_1.J.Binary.Type.NotEqual:
1538
- keyword = "!=";
1539
- break;
1540
- case java_1.J.Binary.Type.BitAnd:
1541
- keyword = "&";
1542
- break;
1543
- case java_1.J.Binary.Type.BitOr:
1544
- keyword = "|";
1545
- break;
1546
- case java_1.J.Binary.Type.BitXor:
1547
- keyword = "^";
1548
- break;
1549
- case java_1.J.Binary.Type.LeftShift:
1550
- keyword = "<<";
1551
- break;
1552
- case java_1.J.Binary.Type.RightShift:
1553
- keyword = ">>";
1554
- break;
1555
- case java_1.J.Binary.Type.UnsignedRightShift:
1556
- keyword = ">>>";
1557
- break;
1558
- case java_1.J.Binary.Type.Or:
1559
- keyword = "||";
1560
- break;
1561
- case java_1.J.Binary.Type.And:
1562
- keyword = "&&";
1563
- break;
1564
- }
1565
- yield this.beforeSyntax(binary, p);
1566
- yield this.visit(binary.left, p);
1567
- yield this.visitSpace(binary.operator.before, p);
1568
- p.append(keyword);
1569
- yield this.visit(binary.right, p);
1570
- yield this.afterSyntax(binary, p);
1571
- return binary;
1572
- });
1573
- }
1574
- visitBinaryExtensions(binary, p) {
1575
- return __awaiter(this, void 0, void 0, function* () {
1576
- yield this.beforeSyntax(binary, p);
1577
- yield this.visit(binary.left, p);
1578
- let keyword = "";
1579
- switch (binary.operator.element) {
1580
- case tree_1.JS.Binary.Type.IdentityEquals:
1581
- keyword = "===";
1582
- break;
1583
- case tree_1.JS.Binary.Type.IdentityNotEquals:
1584
- keyword = "!==";
1585
- break;
1586
- case tree_1.JS.Binary.Type.In:
1587
- keyword = "in";
1588
- break;
1589
- case tree_1.JS.Binary.Type.QuestionQuestion:
1590
- keyword = "??";
1591
- break;
1592
- case tree_1.JS.Binary.Type.Comma:
1593
- keyword = ",";
1594
- break;
1595
- }
1596
- yield this.visitSpace(binary.operator.before, p);
1597
- p.append(keyword);
1598
- yield this.visit(binary.right, p);
1599
- yield this.afterSyntax(binary, p);
1600
- return binary;
1601
- });
1602
- }
1603
- visitUnary(unary, p) {
1604
- return __awaiter(this, void 0, void 0, function* () {
1605
- yield this.beforeSyntax(unary, p);
1606
- switch (unary.operator.element) {
1607
- case java_1.J.Unary.Type.PreIncrement:
1608
- p.append("++");
1609
- yield this.visit(unary.expression, p);
1610
- break;
1611
- case java_1.J.Unary.Type.PreDecrement:
1612
- p.append("--");
1613
- yield this.visit(unary.expression, p);
1614
- break;
1615
- case java_1.J.Unary.Type.PostIncrement:
1616
- yield this.visit(unary.expression, p);
1617
- yield this.visitSpace(unary.operator.before, p);
1618
- p.append("++");
1619
- break;
1620
- case java_1.J.Unary.Type.PostDecrement:
1621
- yield this.visit(unary.expression, p);
1622
- yield this.visitSpace(unary.operator.before, p);
1623
- p.append("--");
1624
- break;
1625
- case java_1.J.Unary.Type.Positive:
1626
- p.append('+');
1627
- yield this.visit(unary.expression, p);
1628
- break;
1629
- case java_1.J.Unary.Type.Negative:
1630
- p.append('-');
1631
- yield this.visit(unary.expression, p);
1632
- break;
1633
- case java_1.J.Unary.Type.Complement:
1634
- p.append('~');
1635
- yield this.visit(unary.expression, p);
1636
- break;
1637
- case java_1.J.Unary.Type.Not:
1638
- default:
1639
- p.append('!');
1640
- yield this.visit(unary.expression, p);
1641
- }
1642
- yield this.afterSyntax(unary, p);
1643
- return unary;
1644
- });
1645
- }
1646
- visitUnion(union, p) {
1647
- return __awaiter(this, void 0, void 0, function* () {
1648
- yield this.beforeSyntax(union, p);
1649
- yield this.visitRightPaddedLocal(union.types, "|", p);
1650
- yield this.afterSyntax(union, p);
1651
- return union;
1652
- });
1653
- }
1654
- visitIntersection(intersection, p) {
1655
- return __awaiter(this, void 0, void 0, function* () {
1656
- yield this.beforeSyntax(intersection, p);
1657
- yield this.visitRightPaddedLocal(intersection.types, "&", p);
1658
- yield this.afterSyntax(intersection, p);
1659
- return intersection;
1660
- });
1661
- }
1662
- visitForLoop(forLoop, p) {
1663
- return __awaiter(this, void 0, void 0, function* () {
1664
- yield this.beforeSyntax(forLoop, p);
1665
- p.append("for");
1666
- const ctrl = forLoop.control;
1667
- yield this.visitSpace(ctrl.prefix, p);
1668
- p.append('(');
1669
- yield this.visitRightPaddedLocal(ctrl.init, ",", p);
1670
- p.append(';');
1671
- ctrl.condition && (yield this.visitRightPaddedLocalSingle(ctrl.condition, ";", p));
1672
- yield this.visitRightPaddedLocal(ctrl.update, ",", p);
1673
- p.append(')');
1674
- yield this.visitStatementLocal(forLoop.body, p);
1675
- yield this.afterSyntax(forLoop, p);
1676
- return forLoop;
1677
- });
1678
- }
1679
- visitForOfLoop(loop, p) {
1680
- return __awaiter(this, void 0, void 0, function* () {
1681
- yield this.beforeSyntax(loop, p);
1682
- p.append("for");
1683
- if (loop.await) {
1684
- yield this.visitSpace(loop.await, p);
1685
- p.append("await");
1686
- }
1687
- const control = loop.loop.control;
1688
- yield this.visitSpace(control.prefix, p);
1689
- p.append('(');
1690
- yield this.visitRightPadded(control.variable, p);
1691
- p.append("of");
1692
- yield this.visitRightPadded(control.iterable, p);
1693
- p.append(')');
1694
- yield this.visitRightPadded(loop.loop.body, p);
1695
- yield this.afterSyntax(loop, p);
1696
- return loop;
1697
- });
1698
- }
1699
- visitForInLoop(loop, p) {
1700
- return __awaiter(this, void 0, void 0, function* () {
1701
- yield this.beforeSyntax(loop, p);
1702
- p.append("for");
1703
- const control = loop.control;
1704
- yield this.visitSpace(control.prefix, p);
1705
- p.append('(');
1706
- yield this.visitRightPadded(control.variable, p);
1707
- p.append("in");
1708
- yield this.visitRightPadded(control.iterable, p);
1709
- p.append(')');
1710
- yield this.visitRightPadded(loop.body, p);
1711
- yield this.afterSyntax(loop, p);
1712
- return loop;
1713
- });
1497
+ }
1714
1498
  }
1715
- // ---- print utils
1716
- visitStatements(statements, p) {
1717
- return __awaiter(this, void 0, void 0, function* () {
1718
- var _a, _b;
1719
- const objectLiteral = ((_a = this.getParentCursor(0)) === null || _a === void 0 ? void 0 : _a.value.kind) === java_1.J.Kind.Block &&
1720
- ((_b = this.getParentCursor(1)) === null || _b === void 0 ? void 0 : _b.value.kind) === java_1.J.Kind.NewClass;
1721
- for (let i = 0; i < statements.length; i++) {
1722
- const paddedStat = statements[i];
1723
- yield this.visitStatementLocal(paddedStat, p);
1724
- if (i < statements.length - 1 && objectLiteral) {
1725
- p.append(",");
1726
- }
1727
- }
1728
- });
1729
- }
1730
- visitStatementLocal(paddedStat, p) {
1731
- return __awaiter(this, void 0, void 0, function* () {
1732
- if (paddedStat) {
1733
- yield this.visit(paddedStat.element, p);
1734
- yield this.visitSpace(paddedStat.after, p);
1735
- yield this.visitMarkers(paddedStat.markers, p);
1736
- }
1737
- });
1499
+ async visitStatementLocal(paddedStat, p) {
1500
+ if (paddedStat) {
1501
+ await this.visit(paddedStat.element, p);
1502
+ await this.visitSpace(paddedStat.after, p);
1503
+ await this.visitMarkers(paddedStat.markers, p);
1504
+ }
1738
1505
  }
1739
1506
  getParentCursor(levels) {
1740
1507
  let cursor = this.cursor;
@@ -1743,149 +1510,123 @@ class JavaScriptPrinter extends visitor_1.JavaScriptVisitor {
1743
1510
  }
1744
1511
  return cursor;
1745
1512
  }
1746
- afterSyntax(j, p) {
1747
- return __awaiter(this, void 0, void 0, function* () {
1748
- yield this.afterSyntaxMarkers(j.markers, p);
1749
- });
1513
+ async afterSyntax(j, p) {
1514
+ await this.afterSyntaxMarkers(j.markers, p);
1750
1515
  }
1751
- afterSyntaxMarkers(markers, p) {
1752
- return __awaiter(this, void 0, void 0, function* () {
1753
- for (const marker of markers.markers) {
1754
- p.append(p.markerPrinter.afterSyntax(marker, new tree_2.Cursor(marker, this.cursor), this.JAVA_SCRIPT_MARKER_WRAPPER));
1755
- }
1756
- });
1516
+ async afterSyntaxMarkers(markers, p) {
1517
+ for (const marker of markers.markers) {
1518
+ p.append(p.markerPrinter.afterSyntax(marker, new tree_2.Cursor(marker, this.cursor), this.JAVA_SCRIPT_MARKER_WRAPPER));
1519
+ }
1757
1520
  }
1758
- beforeSyntax(j, p) {
1759
- return __awaiter(this, void 0, void 0, function* () {
1760
- yield this.beforeSyntaxExt(j.prefix, j.markers, p);
1761
- });
1521
+ async beforeSyntax(j, p) {
1522
+ await this.beforeSyntaxExt(j.prefix, j.markers, p);
1762
1523
  }
1763
- beforeSyntaxExt(prefix, markers, p) {
1764
- return __awaiter(this, void 0, void 0, function* () {
1765
- for (const marker of markers.markers) {
1766
- p.append(p.markerPrinter.beforePrefix(marker, new tree_2.Cursor(marker, this.cursor), this.JAVA_SCRIPT_MARKER_WRAPPER));
1767
- }
1768
- yield this.visitSpace(prefix, p);
1769
- yield this.visitMarkers(markers, p);
1770
- for (const marker of markers.markers) {
1771
- p.append(p.markerPrinter.beforeSyntax(marker, new tree_2.Cursor(marker, this.cursor), this.JAVA_SCRIPT_MARKER_WRAPPER));
1772
- }
1773
- });
1774
- }
1775
- visitSpace(space, p) {
1776
- return __awaiter(this, void 0, void 0, function* () {
1777
- p.append(space.whitespace);
1778
- const comments = space.comments;
1779
- for (let i = 0; i < comments.length; i++) {
1780
- const comment = comments[i];
1781
- yield this.visitMarkers(comment.markers, p);
1782
- this.printComment(comment, this.cursor, p);
1783
- p.append(comment.suffix);
1784
- }
1785
- return space;
1786
- });
1787
- }
1788
- visitRightPaddedLocal(nodes, suffixBetween, p) {
1789
- return __awaiter(this, void 0, void 0, function* () {
1790
- for (let i = 0; i < nodes.length; i++) {
1791
- const node = nodes[i];
1792
- yield this.visit(node.element, p);
1793
- yield this.visitSpace(node.after, p);
1794
- yield this.visitMarkers(node.markers, p);
1795
- if (i < nodes.length - 1) {
1796
- p.append(suffixBetween);
1797
- }
1798
- }
1799
- });
1524
+ async beforeSyntaxExt(prefix, markers, p) {
1525
+ for (const marker of markers.markers) {
1526
+ p.append(p.markerPrinter.beforePrefix(marker, new tree_2.Cursor(marker, this.cursor), this.JAVA_SCRIPT_MARKER_WRAPPER));
1527
+ }
1528
+ await this.visitSpace(prefix, p);
1529
+ await this.visitMarkers(markers, p);
1530
+ for (const marker of markers.markers) {
1531
+ p.append(p.markerPrinter.beforeSyntax(marker, new tree_2.Cursor(marker, this.cursor), this.JAVA_SCRIPT_MARKER_WRAPPER));
1532
+ }
1800
1533
  }
1801
- visitRightPadded(right, p) {
1802
- return __awaiter(this, void 0, void 0, function* () {
1803
- if ((0, tree_2.isTree)(right.element)) {
1804
- yield this.visit(right.element, p);
1805
- }
1806
- yield this.visitSpace(right.after, p);
1807
- yield this.visitMarkers(right.markers, p);
1808
- return right;
1809
- });
1810
- }
1811
- visitRightPaddedLocalSingle(node, suffix, p) {
1812
- return __awaiter(this, void 0, void 0, function* () {
1813
- if (node) {
1814
- yield this.visit(node.element, p);
1815
- yield this.visitSpace(node.after, p);
1816
- yield this.visitMarkers(node.markers, p);
1817
- p.append(suffix);
1818
- }
1819
- });
1820
- }
1821
- visitLeftPaddedLocal(prefix, leftPadded, p) {
1822
- return __awaiter(this, void 0, void 0, function* () {
1823
- if (leftPadded) {
1824
- yield this.beforeSyntaxExt(leftPadded.before, leftPadded.markers, p);
1825
- if (prefix) {
1826
- p.append(prefix);
1827
- }
1828
- if (typeof leftPadded.element === 'string') {
1829
- p.append(leftPadded.element);
1830
- }
1831
- else if (typeof leftPadded.element !== 'boolean') {
1832
- yield this.visit(leftPadded.element, p);
1833
- }
1834
- yield this.afterSyntaxMarkers(leftPadded.markers, p);
1534
+ async visitSpace(space, p) {
1535
+ p.append(space.whitespace);
1536
+ const comments = space.comments;
1537
+ for (let i = 0; i < comments.length; i++) {
1538
+ const comment = comments[i];
1539
+ await this.visitMarkers(comment.markers, p);
1540
+ this.printComment(comment, this.cursor, p);
1541
+ p.append(comment.suffix);
1542
+ }
1543
+ return space;
1544
+ }
1545
+ async visitRightPaddedLocal(nodes, suffixBetween, p) {
1546
+ for (let i = 0; i < nodes.length; i++) {
1547
+ const node = nodes[i];
1548
+ await this.visit(node.element, p);
1549
+ await this.visitSpace(node.after, p);
1550
+ await this.visitMarkers(node.markers, p);
1551
+ if (i < nodes.length - 1) {
1552
+ p.append(suffixBetween);
1835
1553
  }
1836
- });
1554
+ }
1837
1555
  }
1838
- visitContainerLocal(before, container, suffixBetween, after, p) {
1839
- return __awaiter(this, void 0, void 0, function* () {
1840
- if (!container) {
1841
- return;
1556
+ async visitRightPadded(right, p) {
1557
+ if ((0, tree_2.isTree)(right.element)) {
1558
+ await this.visit(right.element, p);
1559
+ }
1560
+ await this.visitSpace(right.after, p);
1561
+ await this.visitMarkers(right.markers, p);
1562
+ return right;
1563
+ }
1564
+ async visitRightPaddedLocalSingle(node, suffix, p) {
1565
+ if (node) {
1566
+ await this.visit(node.element, p);
1567
+ await this.visitSpace(node.after, p);
1568
+ await this.visitMarkers(node.markers, p);
1569
+ p.append(suffix);
1570
+ }
1571
+ }
1572
+ async visitLeftPaddedLocal(prefix, leftPadded, p) {
1573
+ if (leftPadded) {
1574
+ await this.beforeSyntaxExt(leftPadded.before, leftPadded.markers, p);
1575
+ if (prefix) {
1576
+ p.append(prefix);
1842
1577
  }
1843
- yield this.beforeSyntaxExt(container.before, container.markers, p);
1844
- p.append(before);
1845
- yield this.visitRightPaddedLocal(container.elements, suffixBetween, p);
1846
- yield this.afterSyntaxMarkers(container.markers, p);
1847
- p.append(after === null ? "" : after);
1848
- });
1849
- }
1850
- visitMarker(marker, p) {
1851
- return __awaiter(this, void 0, void 0, function* () {
1852
- if (marker.kind === java_1.J.Markers.Semicolon) {
1853
- p.append(';');
1578
+ if (typeof leftPadded.element === 'string') {
1579
+ p.append(leftPadded.element);
1854
1580
  }
1855
- if (marker.kind === java_1.J.Markers.TrailingComma) {
1856
- p.append(',');
1857
- yield this.visitSpace(marker.suffix, p);
1581
+ else if (typeof leftPadded.element !== 'boolean') {
1582
+ await this.visit(leftPadded.element, p);
1858
1583
  }
1859
- return marker;
1860
- });
1861
- }
1862
- preVisit(tree, p) {
1863
- return __awaiter(this, void 0, void 0, function* () {
1864
- // Note: Spread is now handled as JS.Spread AST element via visitSpread
1865
- return tree;
1866
- });
1867
- }
1868
- postVisit(tree, p) {
1869
- return __awaiter(this, void 0, void 0, function* () {
1870
- var _a, _b, _c, _d, _e, _f;
1871
- for (const marker of tree.markers.markers) {
1872
- if (marker.kind === tree_1.JS.Markers.NonNullAssertion) {
1873
- yield this.visitSpace(marker.prefix, p);
1874
- p.append("!");
1875
- }
1876
- if (marker.kind === tree_1.JS.Markers.Optional) {
1877
- yield this.visitSpace(marker.prefix, p);
1878
- if (((_b = (_a = this.cursor.parent) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.kind) !== java_1.J.Kind.MethodInvocation &&
1879
- ((_d = (_c = this.cursor.parent) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.kind) !== tree_1.JS.Kind.FunctionCall) {
1880
- p.append("?");
1881
- if (((_f = (_e = this.cursor.parent) === null || _e === void 0 ? void 0 : _e.value) === null || _f === void 0 ? void 0 : _f.kind) === java_1.J.Kind.ArrayAccess) {
1882
- p.append(".");
1883
- }
1584
+ await this.afterSyntaxMarkers(leftPadded.markers, p);
1585
+ }
1586
+ }
1587
+ async visitContainerLocal(before, container, suffixBetween, after, p) {
1588
+ if (!container) {
1589
+ return;
1590
+ }
1591
+ await this.beforeSyntaxExt(container.before, container.markers, p);
1592
+ p.append(before);
1593
+ await this.visitRightPaddedLocal(container.elements, suffixBetween, p);
1594
+ await this.afterSyntaxMarkers(container.markers, p);
1595
+ p.append(after === null ? "" : after);
1596
+ }
1597
+ async visitMarker(marker, p) {
1598
+ if (marker.kind === java_1.J.Markers.Semicolon) {
1599
+ p.append(';');
1600
+ }
1601
+ if (marker.kind === java_1.J.Markers.TrailingComma) {
1602
+ p.append(',');
1603
+ await this.visitSpace(marker.suffix, p);
1604
+ }
1605
+ return marker;
1606
+ }
1607
+ async preVisit(tree, p) {
1608
+ // Note: Spread is now handled as JS.Spread AST element via visitSpread
1609
+ return tree;
1610
+ }
1611
+ async postVisit(tree, p) {
1612
+ var _a, _b, _c, _d, _e, _f;
1613
+ for (const marker of tree.markers.markers) {
1614
+ if (marker.kind === tree_1.JS.Markers.NonNullAssertion) {
1615
+ await this.visitSpace(marker.prefix, p);
1616
+ p.append("!");
1617
+ }
1618
+ if (marker.kind === tree_1.JS.Markers.Optional) {
1619
+ await this.visitSpace(marker.prefix, p);
1620
+ if (((_b = (_a = this.cursor.parent) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.kind) !== java_1.J.Kind.MethodInvocation &&
1621
+ ((_d = (_c = this.cursor.parent) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.kind) !== tree_1.JS.Kind.FunctionCall) {
1622
+ p.append("?");
1623
+ if (((_f = (_e = this.cursor.parent) === null || _e === void 0 ? void 0 : _e.value) === null || _f === void 0 ? void 0 : _f.kind) === java_1.J.Kind.ArrayAccess) {
1624
+ p.append(".");
1884
1625
  }
1885
1626
  }
1886
1627
  }
1887
- return tree;
1888
- });
1628
+ }
1629
+ return tree;
1889
1630
  }
1890
1631
  printComment(comment, cursor, p) {
1891
1632
  for (const marker of comment.markers.markers) {
@@ -1899,30 +1640,26 @@ class JavaScriptPrinter extends visitor_1.JavaScriptVisitor {
1899
1640
  p.append(p.markerPrinter.afterSyntax(marker, new tree_2.Cursor(this, cursor), this.JAVA_SCRIPT_MARKER_WRAPPER));
1900
1641
  }
1901
1642
  }
1902
- visitNodes(nodes, p) {
1903
- return __awaiter(this, void 0, void 0, function* () {
1904
- if (nodes) {
1905
- for (const node of nodes) {
1906
- yield this.visit(node, p);
1907
- }
1643
+ async visitNodes(nodes, p) {
1644
+ if (nodes) {
1645
+ for (const node of nodes) {
1646
+ await this.visit(node, p);
1908
1647
  }
1909
- });
1910
- }
1911
- visitControlParentheses(controlParens, p) {
1912
- return __awaiter(this, void 0, void 0, function* () {
1913
- var _a;
1914
- yield this.beforeSyntax(controlParens, p);
1915
- if (((_a = this.getParentCursor(1)) === null || _a === void 0 ? void 0 : _a.value.kind) === java_1.J.Kind.TypeCast) {
1916
- p.append('<');
1917
- yield this.visitRightPaddedLocalSingle(controlParens.tree, ">", p);
1918
- }
1919
- else {
1920
- p.append('(');
1921
- yield this.visitRightPaddedLocalSingle(controlParens.tree, ")", p);
1922
- }
1923
- yield this.afterSyntax(controlParens, p);
1924
- return controlParens;
1925
- });
1648
+ }
1649
+ }
1650
+ async visitControlParentheses(controlParens, p) {
1651
+ var _a;
1652
+ await this.beforeSyntax(controlParens, p);
1653
+ if (((_a = this.getParentCursor(1)) === null || _a === void 0 ? void 0 : _a.value.kind) === java_1.J.Kind.TypeCast) {
1654
+ p.append('<');
1655
+ await this.visitRightPaddedLocalSingle(controlParens.tree, ">", p);
1656
+ }
1657
+ else {
1658
+ p.append('(');
1659
+ await this.visitRightPaddedLocalSingle(controlParens.tree, ")", p);
1660
+ }
1661
+ await this.afterSyntax(controlParens, p);
1662
+ return controlParens;
1926
1663
  }
1927
1664
  }
1928
1665
  exports.JavaScriptPrinter = JavaScriptPrinter;