@openrewrite/rewrite 8.72.2 → 8.72.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.prettierFormat = exports.BlankLinesVisitor = exports.WrappingAndBracesVisitor = exports.SpacesVisitor = exports.AutoformatVisitor = exports.autoFormat = exports.maybeAutoFormat = exports.MinimumViableSpacingVisitor = exports.NormalizeWhitespaceVisitor = exports.TabsAndIndentsVisitor = void 0;
13
4
  /*
@@ -42,14 +33,14 @@ var normalize_whitespace_visitor_2 = require("./normalize-whitespace-visitor");
42
33
  Object.defineProperty(exports, "NormalizeWhitespaceVisitor", { enumerable: true, get: function () { return normalize_whitespace_visitor_2.NormalizeWhitespaceVisitor; } });
43
34
  var minimum_viable_spacing_visitor_2 = require("./minimum-viable-spacing-visitor");
44
35
  Object.defineProperty(exports, "MinimumViableSpacingVisitor", { enumerable: true, get: function () { return minimum_viable_spacing_visitor_2.MinimumViableSpacingVisitor; } });
45
- const maybeAutoFormat = (before, after, p, stopAfter, parent) => __awaiter(void 0, void 0, void 0, function* () {
36
+ const maybeAutoFormat = async (before, after, p, stopAfter, parent) => {
46
37
  if (before !== after) {
47
38
  return (0, exports.autoFormat)(after, p, stopAfter, parent);
48
39
  }
49
40
  return after;
50
- });
41
+ };
51
42
  exports.maybeAutoFormat = maybeAutoFormat;
52
- const autoFormat = (j, p, stopAfter, parent, styles) => __awaiter(void 0, void 0, void 0, function* () { return yield new AutoformatVisitor(stopAfter, styles).visit(j, p, parent); });
43
+ const autoFormat = async (j, p, stopAfter, parent, styles) => await new AutoformatVisitor(stopAfter, styles).visit(j, p, parent);
53
44
  exports.autoFormat = autoFormat;
54
45
  /**
55
46
  * Formats JavaScript/TypeScript code using a comprehensive set of formatting rules.
@@ -68,31 +59,29 @@ class AutoformatVisitor extends visitor_1.JavaScriptVisitor {
68
59
  this.stopAfter = stopAfter;
69
60
  this.styles = styles;
70
61
  }
71
- visit(tree, p, cursor) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- // Check for PrettierStyle in styles array or as marker on source file
74
- // If found, delegate entirely to Prettier (skip other formatting visitors)
75
- const prettierStyle = (0, prettier_format_1.getPrettierStyle)(tree, cursor, this.styles);
76
- if (prettierStyle) {
77
- return (0, prettier_format_1.applyPrettierFormatting)(tree, prettierStyle, p, cursor, this.stopAfter);
78
- }
79
- const visitors = [
80
- new normalize_whitespace_visitor_1.NormalizeWhitespaceVisitor(this.stopAfter),
81
- new minimum_viable_spacing_visitor_1.MinimumViableSpacingVisitor(this.stopAfter),
82
- new BlankLinesVisitor((0, style_1.getStyle)(style_1.StyleKind.BlankLinesStyle, tree, this.styles), this.stopAfter),
83
- new WrappingAndBracesVisitor((0, style_1.getStyle)(style_1.StyleKind.WrappingAndBracesStyle, tree, this.styles), this.stopAfter),
84
- new SpacesVisitor((0, style_1.getStyle)(style_1.StyleKind.SpacesStyle, tree, this.styles), this.stopAfter),
85
- new tabs_and_indents_visitor_1.TabsAndIndentsVisitor((0, style_1.getStyle)(style_1.StyleKind.TabsAndIndentsStyle, tree, this.styles), this.stopAfter),
86
- ];
87
- let t = tree;
88
- for (const visitor of visitors) {
89
- t = yield visitor.visit(t, p, cursor);
90
- if (t === undefined) {
91
- return undefined;
92
- }
62
+ async visit(tree, p, cursor) {
63
+ // Check for PrettierStyle in styles array or as marker on source file
64
+ // If found, delegate entirely to Prettier (skip other formatting visitors)
65
+ const prettierStyle = (0, prettier_format_1.getPrettierStyle)(tree, cursor, this.styles);
66
+ if (prettierStyle) {
67
+ return (0, prettier_format_1.applyPrettierFormatting)(tree, prettierStyle, p, cursor, this.stopAfter);
68
+ }
69
+ const visitors = [
70
+ new normalize_whitespace_visitor_1.NormalizeWhitespaceVisitor(this.stopAfter),
71
+ new minimum_viable_spacing_visitor_1.MinimumViableSpacingVisitor(this.stopAfter),
72
+ new BlankLinesVisitor((0, style_1.getStyle)(style_1.StyleKind.BlankLinesStyle, tree, this.styles), this.stopAfter),
73
+ new WrappingAndBracesVisitor((0, style_1.getStyle)(style_1.StyleKind.WrappingAndBracesStyle, tree, this.styles), this.stopAfter),
74
+ new SpacesVisitor((0, style_1.getStyle)(style_1.StyleKind.SpacesStyle, tree, this.styles), this.stopAfter),
75
+ new tabs_and_indents_visitor_1.TabsAndIndentsVisitor((0, style_1.getStyle)(style_1.StyleKind.TabsAndIndentsStyle, tree, this.styles), this.stopAfter),
76
+ ];
77
+ let t = tree;
78
+ for (const visitor of visitors) {
79
+ t = await visitor.visit(t, p, cursor);
80
+ if (t === undefined) {
81
+ return undefined;
93
82
  }
94
- return t;
95
- });
83
+ }
84
+ return t;
96
85
  }
97
86
  }
98
87
  exports.AutoformatVisitor = AutoformatVisitor;
@@ -102,479 +91,440 @@ class SpacesVisitor extends visitor_1.JavaScriptVisitor {
102
91
  this.style = style;
103
92
  this.stopAfter = stopAfter;
104
93
  }
105
- visit(tree, p, parent) {
106
- const _super = Object.create(null, {
107
- visit: { get: () => super.visit }
108
- });
109
- return __awaiter(this, void 0, void 0, function* () {
110
- var _a;
111
- if (((_a = this.cursor) === null || _a === void 0 ? void 0 : _a.getNearestMessage("stop")) != null) {
112
- return tree;
113
- }
114
- return _super.visit.call(this, tree, p, parent);
115
- });
94
+ async visit(tree, p, parent) {
95
+ var _a;
96
+ if (((_a = this.cursor) === null || _a === void 0 ? void 0 : _a.getNearestMessage("stop")) != null) {
97
+ return tree;
98
+ }
99
+ return super.visit(tree, p, parent);
116
100
  }
117
- postVisit(tree, p) {
118
- const _super = Object.create(null, {
119
- postVisit: { get: () => super.postVisit }
120
- });
121
- return __awaiter(this, void 0, void 0, function* () {
122
- var _a;
123
- if (this.stopAfter != null && (0, tree_2.isScope)(this.stopAfter, tree)) {
124
- (_a = this.cursor) === null || _a === void 0 ? void 0 : _a.root.messages.set("stop", true);
125
- }
126
- return _super.postVisit.call(this, tree, p);
127
- });
101
+ async postVisit(tree, p) {
102
+ var _a;
103
+ if (this.stopAfter != null && (0, tree_2.isScope)(this.stopAfter, tree)) {
104
+ (_a = this.cursor) === null || _a === void 0 ? void 0 : _a.root.messages.set("stop", true);
105
+ }
106
+ return super.postVisit(tree, p);
128
107
  }
129
- visitAlias(alias, p) {
130
- const _super = Object.create(null, {
131
- visitAlias: { get: () => super.visitAlias }
132
- });
133
- return __awaiter(this, void 0, void 0, function* () {
134
- const ret = yield _super.visitAlias.call(this, alias, p);
135
- return (0, mutative_1.create)(ret, draft => {
136
- draft.propertyName.after.whitespace = " ";
137
- });
108
+ async visitAlias(alias, p) {
109
+ const ret = await super.visitAlias(alias, p);
110
+ return (0, mutative_1.create)(ret, draft => {
111
+ draft.propertyName.after.whitespace = " ";
138
112
  });
139
113
  }
140
- visitArrayAccess(arrayAccess, p) {
141
- const _super = Object.create(null, {
142
- visitArrayAccess: { get: () => super.visitArrayAccess }
143
- });
144
- return __awaiter(this, void 0, void 0, function* () {
145
- const ret = yield _super.visitArrayAccess.call(this, arrayAccess, p);
146
- return (0, mutative_1.create)(ret, draft => {
147
- // Preserve newlines - only modify if no newlines present
148
- if (!draft.dimension.index.element.prefix.whitespace.includes("\n")) {
149
- draft.dimension.index.element.prefix.whitespace = this.style.within.arrayBrackets ? " " : "";
150
- }
151
- if (!draft.dimension.index.after.whitespace.includes("\n")) {
152
- draft.dimension.index.after.whitespace = this.style.within.arrayBrackets ? " " : "";
153
- }
154
- });
114
+ async visitArrayAccess(arrayAccess, p) {
115
+ const ret = await super.visitArrayAccess(arrayAccess, p);
116
+ return (0, mutative_1.create)(ret, draft => {
117
+ // Preserve newlines - only modify if no newlines present
118
+ if (!draft.dimension.index.element.prefix.whitespace.includes("\n")) {
119
+ draft.dimension.index.element.prefix.whitespace = this.style.within.arrayBrackets ? " " : "";
120
+ }
121
+ if (!draft.dimension.index.after.whitespace.includes("\n")) {
122
+ draft.dimension.index.after.whitespace = this.style.within.arrayBrackets ? " " : "";
123
+ }
155
124
  });
156
125
  }
157
- visitAssignment(assignment, p) {
158
- const _super = Object.create(null, {
159
- visitAssignment: { get: () => super.visitAssignment }
160
- });
161
- return __awaiter(this, void 0, void 0, function* () {
162
- const ret = yield _super.visitAssignment.call(this, assignment, p);
163
- return (0, mutative_1.create)(ret, draft => {
164
- // Preserve newlines - only modify if no newlines present
165
- if (!draft.assignment.before.whitespace.includes("\n")) {
166
- draft.assignment.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
167
- }
168
- if (!draft.assignment.element.prefix.whitespace.includes("\n")) {
169
- draft.assignment.element.prefix.whitespace = this.style.aroundOperators.assignment ? " " : "";
170
- }
171
- });
126
+ async visitAssignment(assignment, p) {
127
+ const ret = await super.visitAssignment(assignment, p);
128
+ return (0, mutative_1.create)(ret, draft => {
129
+ // Preserve newlines - only modify if no newlines present
130
+ if (!draft.assignment.before.whitespace.includes("\n")) {
131
+ draft.assignment.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
132
+ }
133
+ if (!draft.assignment.element.prefix.whitespace.includes("\n")) {
134
+ draft.assignment.element.prefix.whitespace = this.style.aroundOperators.assignment ? " " : "";
135
+ }
172
136
  });
173
137
  }
174
- visitBinary(binary, p) {
175
- const _super = Object.create(null, {
176
- visitBinary: { get: () => super.visitBinary }
177
- });
178
- return __awaiter(this, void 0, void 0, function* () {
179
- const ret = yield _super.visitBinary.call(this, binary, p);
180
- let property = false;
181
- switch (ret.operator.element.valueOf()) {
182
- case java_1.J.Binary.Type.And:
183
- case java_1.J.Binary.Type.Or:
184
- property = this.style.aroundOperators.logical;
185
- break;
186
- case java_1.J.Binary.Type.Equal:
187
- case java_1.J.Binary.Type.NotEqual:
188
- property = this.style.aroundOperators.equality;
189
- break;
190
- case java_1.J.Binary.Type.LessThan:
191
- case java_1.J.Binary.Type.LessThanOrEqual:
192
- case java_1.J.Binary.Type.GreaterThan:
193
- case java_1.J.Binary.Type.GreaterThanOrEqual:
194
- property = this.style.aroundOperators.relational;
195
- break;
196
- case java_1.J.Binary.Type.BitAnd:
197
- case java_1.J.Binary.Type.BitOr:
198
- case java_1.J.Binary.Type.BitXor:
199
- property = this.style.aroundOperators.bitwise;
200
- break;
201
- case java_1.J.Binary.Type.Addition:
202
- case java_1.J.Binary.Type.Subtraction:
203
- property = this.style.aroundOperators.additive;
204
- break;
205
- case java_1.J.Binary.Type.Multiplication:
206
- case java_1.J.Binary.Type.Division:
207
- case java_1.J.Binary.Type.Modulo:
208
- property = this.style.aroundOperators.multiplicative;
209
- break;
210
- case java_1.J.Binary.Type.LeftShift:
211
- case java_1.J.Binary.Type.RightShift:
212
- case java_1.J.Binary.Type.UnsignedRightShift:
213
- property = this.style.aroundOperators.shift;
214
- break;
215
- default:
216
- throw new Error("Unsupported operator type " + ret.operator.element.valueOf());
138
+ async visitBinary(binary, p) {
139
+ const ret = await super.visitBinary(binary, p);
140
+ let property = false;
141
+ switch (ret.operator.element.valueOf()) {
142
+ case java_1.J.Binary.Type.And:
143
+ case java_1.J.Binary.Type.Or:
144
+ property = this.style.aroundOperators.logical;
145
+ break;
146
+ case java_1.J.Binary.Type.Equal:
147
+ case java_1.J.Binary.Type.NotEqual:
148
+ property = this.style.aroundOperators.equality;
149
+ break;
150
+ case java_1.J.Binary.Type.LessThan:
151
+ case java_1.J.Binary.Type.LessThanOrEqual:
152
+ case java_1.J.Binary.Type.GreaterThan:
153
+ case java_1.J.Binary.Type.GreaterThanOrEqual:
154
+ property = this.style.aroundOperators.relational;
155
+ break;
156
+ case java_1.J.Binary.Type.BitAnd:
157
+ case java_1.J.Binary.Type.BitOr:
158
+ case java_1.J.Binary.Type.BitXor:
159
+ property = this.style.aroundOperators.bitwise;
160
+ break;
161
+ case java_1.J.Binary.Type.Addition:
162
+ case java_1.J.Binary.Type.Subtraction:
163
+ property = this.style.aroundOperators.additive;
164
+ break;
165
+ case java_1.J.Binary.Type.Multiplication:
166
+ case java_1.J.Binary.Type.Division:
167
+ case java_1.J.Binary.Type.Modulo:
168
+ property = this.style.aroundOperators.multiplicative;
169
+ break;
170
+ case java_1.J.Binary.Type.LeftShift:
171
+ case java_1.J.Binary.Type.RightShift:
172
+ case java_1.J.Binary.Type.UnsignedRightShift:
173
+ property = this.style.aroundOperators.shift;
174
+ break;
175
+ default:
176
+ throw new Error("Unsupported operator type " + ret.operator.element.valueOf());
177
+ }
178
+ return (0, mutative_1.create)(ret, draft => {
179
+ // Preserve newlines - only modify if no newlines present
180
+ if (!draft.operator.before.whitespace.includes("\n")) {
181
+ draft.operator.before.whitespace = property ? " " : "";
182
+ }
183
+ if (!draft.right.prefix.whitespace.includes("\n")) {
184
+ draft.right.prefix.whitespace = property ? " " : "";
217
185
  }
218
- return (0, mutative_1.create)(ret, draft => {
219
- // Preserve newlines - only modify if no newlines present
220
- if (!draft.operator.before.whitespace.includes("\n")) {
221
- draft.operator.before.whitespace = property ? " " : "";
222
- }
223
- if (!draft.right.prefix.whitespace.includes("\n")) {
224
- draft.right.prefix.whitespace = property ? " " : "";
225
- }
226
- });
227
186
  });
228
187
  }
229
- visitCase(aCase, p) {
230
- const _super = Object.create(null, {
231
- visitCase: { get: () => super.visitCase }
232
- });
233
- return __awaiter(this, void 0, void 0, function* () {
234
- const ret = yield _super.visitCase.call(this, aCase, p);
235
- return ret && (0, mutative_1.create)(ret, draft => {
236
- if (draft.caseLabels.elements[0].element.kind != java_1.J.Kind.Identifier || draft.caseLabels.elements[0].element.simpleName != "default") {
237
- // Preserve newlines - only set to space if no newline exists
238
- if (!draft.caseLabels.before.whitespace.includes("\n")) {
239
- draft.caseLabels.before.whitespace = " ";
240
- }
188
+ async visitCase(aCase, p) {
189
+ const ret = await super.visitCase(aCase, p);
190
+ return ret && (0, mutative_1.create)(ret, draft => {
191
+ if (draft.caseLabels.elements[0].element.kind != java_1.J.Kind.Identifier || draft.caseLabels.elements[0].element.simpleName != "default") {
192
+ // Preserve newlines - only set to space if no newline exists
193
+ if (!draft.caseLabels.before.whitespace.includes("\n")) {
194
+ draft.caseLabels.before.whitespace = " ";
241
195
  }
242
- });
243
- });
244
- }
245
- visitClassDeclaration(classDecl, p) {
246
- const _super = Object.create(null, {
247
- visitClassDeclaration: { get: () => super.visitClassDeclaration }
248
- });
249
- return __awaiter(this, void 0, void 0, function* () {
250
- const ret = yield _super.visitClassDeclaration.call(this, classDecl, p);
251
- // TODO typeParameters - IntelliJ doesn't seem to provide a setting for angleBrackets spacing for Typescript (while it does for Java),
252
- // thus we either introduce our own setting or just enforce the natural spacing with no setting
253
- return (0, mutative_1.create)(ret, draft => {
254
- draft.body.prefix.whitespace = this.style.beforeLeftBrace.classInterfaceModuleLeftBrace ? " " : "";
255
- });
196
+ }
256
197
  });
257
198
  }
258
- visitContainer(container, p) {
259
- const _super = Object.create(null, {
260
- visitContainer: { get: () => super.visitContainer }
261
- });
262
- return __awaiter(this, void 0, void 0, function* () {
263
- const ret = yield _super.visitContainer.call(this, container, p);
264
- return (0, mutative_1.create)(ret, draft => {
265
- if (draft.elements.length > 0) {
266
- // Apply beforeComma rule to all elements except the last
267
- // (last element's after is before closing bracket, not a comma)
268
- for (let i = 0; i < draft.elements.length - 1; i++) {
269
- const afterWs = draft.elements[i].after.whitespace;
270
- // Preserve newlines - only adjust when on same line
271
- if (!afterWs.includes("\n")) {
272
- draft.elements[i].after.whitespace = this.style.other.beforeComma ? " " : "";
273
- }
199
+ async visitClassDeclaration(classDecl, p) {
200
+ const ret = await super.visitClassDeclaration(classDecl, p);
201
+ // TODO typeParameters - IntelliJ doesn't seem to provide a setting for angleBrackets spacing for Typescript (while it does for Java),
202
+ // thus we either introduce our own setting or just enforce the natural spacing with no setting
203
+ return (0, mutative_1.create)(ret, draft => {
204
+ draft.body.prefix.whitespace = this.style.beforeLeftBrace.classInterfaceModuleLeftBrace ? " " : "";
205
+ });
206
+ }
207
+ async visitContainer(container, p) {
208
+ const ret = await super.visitContainer(container, p);
209
+ return (0, mutative_1.create)(ret, draft => {
210
+ if (draft.elements.length > 0) {
211
+ // Apply beforeComma rule to all elements except the last
212
+ // (last element's after is before closing bracket, not a comma)
213
+ for (let i = 0; i < draft.elements.length - 1; i++) {
214
+ const afterWs = draft.elements[i].after.whitespace;
215
+ // Preserve newlines - only adjust when on same line
216
+ if (!afterWs.includes("\n")) {
217
+ draft.elements[i].after.whitespace = this.style.other.beforeComma ? " " : "";
274
218
  }
275
219
  }
276
- if (draft.elements.length > 1) {
277
- // Apply afterComma rule to elements after the first
278
- for (let i = 1; i < draft.elements.length; i++) {
279
- const currentWs = draft.elements[i].element.prefix.whitespace;
280
- // Preserve original newlines - only adjust spacing when elements are on same line
281
- if (!currentWs.includes("\n")) {
282
- draft.elements[i].element.prefix.whitespace = this.style.other.afterComma ? " " : "";
283
- }
220
+ }
221
+ if (draft.elements.length > 1) {
222
+ // Apply afterComma rule to elements after the first
223
+ for (let i = 1; i < draft.elements.length; i++) {
224
+ const currentWs = draft.elements[i].element.prefix.whitespace;
225
+ // Preserve original newlines - only adjust spacing when elements are on same line
226
+ if (!currentWs.includes("\n")) {
227
+ draft.elements[i].element.prefix.whitespace = this.style.other.afterComma ? " " : "";
284
228
  }
285
229
  }
286
- });
230
+ }
287
231
  });
288
232
  }
289
- visitExportDeclaration(exportDeclaration, p) {
290
- const _super = Object.create(null, {
291
- visitExportDeclaration: { get: () => super.visitExportDeclaration }
292
- });
293
- return __awaiter(this, void 0, void 0, function* () {
294
- const ret = yield _super.visitExportDeclaration.call(this, exportDeclaration, p);
295
- return (0, mutative_1.create)(ret, draft => {
296
- if (draft.exportClause) {
297
- draft.exportClause.prefix.whitespace = " ";
298
- if (draft.exportClause.kind == tree_1.JS.Kind.NamedExports) {
299
- const ne = draft.exportClause;
300
- if (ne.elements.elements.length > 0) {
301
- // Check if this is a multi-line export (any element's prefix has a newline)
302
- const isMultiLine = ne.elements.elements.some(e => e.element.prefix.whitespace.includes("\n"));
303
- if (!isMultiLine) {
304
- // Single-line: adjust brace spacing
305
- ne.elements.elements[0].element.prefix.whitespace = this.style.within.es6ImportExportBraces ? " " : "";
306
- ne.elements.elements[ne.elements.elements.length - 1].after.whitespace = this.style.within.es6ImportExportBraces ? " " : "";
307
- }
308
- else {
309
- // Multi-line: apply beforeComma rule to last element's after (for trailing commas)
310
- // If it has only spaces (no newline), it's the space before a trailing comma
311
- const lastAfter = ne.elements.elements[ne.elements.elements.length - 1].after.whitespace;
312
- if (!lastAfter.includes("\n") && lastAfter.trim() === "") {
313
- ne.elements.elements[ne.elements.elements.length - 1].after.whitespace = this.style.other.beforeComma ? " " : "";
314
- }
233
+ async visitExportDeclaration(exportDeclaration, p) {
234
+ const ret = await super.visitExportDeclaration(exportDeclaration, p);
235
+ return (0, mutative_1.create)(ret, draft => {
236
+ if (draft.exportClause) {
237
+ draft.exportClause.prefix.whitespace = " ";
238
+ if (draft.exportClause.kind == tree_1.JS.Kind.NamedExports) {
239
+ const ne = draft.exportClause;
240
+ if (ne.elements.elements.length > 0) {
241
+ // Check if this is a multi-line export (any element's prefix has a newline)
242
+ const isMultiLine = ne.elements.elements.some(e => e.element.prefix.whitespace.includes("\n"));
243
+ if (!isMultiLine) {
244
+ // Single-line: adjust brace spacing
245
+ ne.elements.elements[0].element.prefix.whitespace = this.style.within.es6ImportExportBraces ? " " : "";
246
+ ne.elements.elements[ne.elements.elements.length - 1].after.whitespace = this.style.within.es6ImportExportBraces ? " " : "";
247
+ }
248
+ else {
249
+ // Multi-line: apply beforeComma rule to last element's after (for trailing commas)
250
+ // If it has only spaces (no newline), it's the space before a trailing comma
251
+ const lastAfter = ne.elements.elements[ne.elements.elements.length - 1].after.whitespace;
252
+ if (!lastAfter.includes("\n") && lastAfter.trim() === "") {
253
+ ne.elements.elements[ne.elements.elements.length - 1].after.whitespace = this.style.other.beforeComma ? " " : "";
315
254
  }
316
255
  }
317
256
  }
318
257
  }
319
- draft.typeOnly.before.whitespace = draft.typeOnly.element ? " " : "";
320
- if (draft.moduleSpecifier) {
321
- draft.moduleSpecifier.before.whitespace = " ";
322
- draft.moduleSpecifier.element.prefix.whitespace = " ";
323
- }
324
- });
258
+ }
259
+ draft.typeOnly.before.whitespace = draft.typeOnly.element ? " " : "";
260
+ if (draft.moduleSpecifier) {
261
+ draft.moduleSpecifier.before.whitespace = " ";
262
+ draft.moduleSpecifier.element.prefix.whitespace = " ";
263
+ }
325
264
  });
326
265
  }
327
- visitForLoop(forLoop, p) {
328
- const _super = Object.create(null, {
329
- visitForLoop: { get: () => super.visitForLoop }
330
- });
331
- return __awaiter(this, void 0, void 0, function* () {
332
- const ret = yield _super.visitForLoop.call(this, forLoop, p);
333
- return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
334
- draft.control.prefix.whitespace = this.style.beforeParentheses.forParentheses ? " " : "";
335
- draft.control.init = yield Promise.all(draft.control.init.map((oneInit, index) => __awaiter(this, void 0, void 0, function* () {
336
- if (oneInit.element.kind === java_1.J.Kind.VariableDeclarations) {
337
- const vd = oneInit.element;
338
- if (vd.modifiers && vd.modifiers.length > 0) {
339
- vd.modifiers[0].prefix.whitespace = "";
340
- }
266
+ async visitForLoop(forLoop, p) {
267
+ const ret = await super.visitForLoop(forLoop, p);
268
+ return (0, visitor_2.produceAsync)(ret, async (draft) => {
269
+ draft.control.prefix.whitespace = this.style.beforeParentheses.forParentheses ? " " : "";
270
+ draft.control.init = await Promise.all(draft.control.init.map(async (oneInit, index) => {
271
+ if (oneInit.element.kind === java_1.J.Kind.VariableDeclarations) {
272
+ const vd = oneInit.element;
273
+ if (vd.modifiers && vd.modifiers.length > 0) {
274
+ vd.modifiers[0].prefix.whitespace = "";
341
275
  }
342
- oneInit.after.whitespace = "";
343
- this.spaceBeforeRightPaddedElementDraft(oneInit, index === 0 ? this.style.within.forParentheses : true);
344
- return oneInit;
345
- })));
346
- if (draft.control.condition) {
347
- draft.control.condition.element.prefix.whitespace = " ";
348
- draft.control.condition.after.whitespace = this.style.other.beforeForSemicolon ? " " : "";
349
276
  }
350
- draft.control.update.forEach((oneUpdate, index) => {
351
- oneUpdate.element.prefix.whitespace = " ";
352
- oneUpdate.after.whitespace = (index === draft.control.update.length - 1 ? this.style.within.forParentheses : this.style.other.beforeForSemicolon) ? " " : "";
353
- });
354
- this.spaceBeforeRightPaddedElementDraft(draft.body, this.style.beforeLeftBrace.forLeftBrace);
355
- this.spaceAfterRightPaddedDraft(draft.body, false);
277
+ oneInit.after.whitespace = "";
278
+ this.spaceBeforeRightPaddedElementDraft(oneInit, index === 0 ? this.style.within.forParentheses : true);
279
+ return oneInit;
356
280
  }));
357
- });
358
- }
359
- visitIf(iff, p) {
360
- const _super = Object.create(null, {
361
- visitIf: { get: () => super.visitIf }
362
- });
363
- return __awaiter(this, void 0, void 0, function* () {
364
- const ret = yield _super.visitIf.call(this, iff, p);
365
- return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
366
- this.spaceBeforeDraft(draft.ifCondition, this.style.beforeParentheses.ifParentheses);
367
- this.spaceBeforeRightPaddedElementDraft(draft.ifCondition.tree, this.style.within.ifParentheses);
368
- this.spaceAfterRightPaddedDraft(draft.ifCondition.tree, this.style.within.ifParentheses);
369
- this.spaceBeforeRightPaddedElementDraft(draft.thenPart, this.style.beforeLeftBrace.ifLeftBrace);
370
- this.spaceAfterRightPaddedDraft(draft.thenPart, false);
371
- }));
372
- });
373
- }
374
- visitImportDeclaration(jsImport, p) {
375
- const _super = Object.create(null, {
376
- visitImportDeclaration: { get: () => super.visitImportDeclaration }
377
- });
378
- return __awaiter(this, void 0, void 0, function* () {
379
- const ret = yield _super.visitImportDeclaration.call(this, jsImport, p);
380
- return (0, mutative_1.create)(ret, draft => {
381
- if (draft.importClause) {
382
- // Space after 'import' keyword:
383
- // - If there's a default import (name), space goes in importClause.prefix
384
- // - If typeOnly (import type ...), space goes in importClause.prefix (before 'type')
385
- // - If only namedBindings (no default, no type), space goes in namedBindings.prefix (importClause.prefix is empty)
386
- const hasDefaultImport = !!draft.importClause.name;
387
- draft.importClause.prefix.whitespace = (hasDefaultImport || draft.importClause.typeOnly) ? " " : "";
388
- if (draft.importClause.name) {
389
- // For import equals declarations (import X = Y), use assignment spacing
390
- // For regular imports (import X from 'Y'), no space after name
391
- draft.importClause.name.after.whitespace = draft.initializer
392
- ? (this.style.aroundOperators.assignment ? " " : "")
393
- : "";
394
- }
395
- if (draft.importClause.namedBindings) {
396
- // Space before namedBindings - always needed
397
- draft.importClause.namedBindings.prefix.whitespace = " ";
398
- if (draft.importClause.namedBindings.kind == tree_1.JS.Kind.NamedImports) {
399
- const ni = draft.importClause.namedBindings;
400
- // Check if this is a multi-line import (any element's prefix has a newline)
401
- const isMultiLine = ni.elements.elements.some(e => e.element.prefix.whitespace.includes("\n"));
402
- if (!isMultiLine) {
403
- // Single-line: adjust brace spacing
404
- ni.elements.elements[0].element.prefix.whitespace = this.style.within.es6ImportExportBraces ? " " : "";
405
- ni.elements.elements[ni.elements.elements.length - 1].after.whitespace = this.style.within.es6ImportExportBraces ? " " : "";
406
- }
407
- else {
408
- // Multi-line: apply beforeComma rule to last element's after (for trailing commas)
409
- // If it has only spaces (no newline), it's the space before a trailing comma
410
- const lastAfter = ni.elements.elements[ni.elements.elements.length - 1].after.whitespace;
411
- if (!lastAfter.includes("\n") && lastAfter.trim() === "") {
412
- ni.elements.elements[ni.elements.elements.length - 1].after.whitespace = this.style.other.beforeComma ? " " : "";
413
- }
281
+ if (draft.control.condition) {
282
+ draft.control.condition.element.prefix.whitespace = " ";
283
+ draft.control.condition.after.whitespace = this.style.other.beforeForSemicolon ? " " : "";
284
+ }
285
+ draft.control.update.forEach((oneUpdate, index) => {
286
+ oneUpdate.element.prefix.whitespace = " ";
287
+ oneUpdate.after.whitespace = (index === draft.control.update.length - 1 ? this.style.within.forParentheses : this.style.other.beforeForSemicolon) ? " " : "";
288
+ });
289
+ this.spaceBeforeRightPaddedElementDraft(draft.body, this.style.beforeLeftBrace.forLeftBrace);
290
+ this.spaceAfterRightPaddedDraft(draft.body, false);
291
+ });
292
+ }
293
+ async visitIf(iff, p) {
294
+ const ret = await super.visitIf(iff, p);
295
+ return (0, visitor_2.produceAsync)(ret, async (draft) => {
296
+ this.spaceBeforeDraft(draft.ifCondition, this.style.beforeParentheses.ifParentheses);
297
+ this.spaceBeforeRightPaddedElementDraft(draft.ifCondition.tree, this.style.within.ifParentheses);
298
+ this.spaceAfterRightPaddedDraft(draft.ifCondition.tree, this.style.within.ifParentheses);
299
+ this.spaceBeforeRightPaddedElementDraft(draft.thenPart, this.style.beforeLeftBrace.ifLeftBrace);
300
+ this.spaceAfterRightPaddedDraft(draft.thenPart, false);
301
+ });
302
+ }
303
+ async visitImportDeclaration(jsImport, p) {
304
+ const ret = await super.visitImportDeclaration(jsImport, p);
305
+ return (0, mutative_1.create)(ret, draft => {
306
+ if (draft.importClause) {
307
+ // Space after 'import' keyword:
308
+ // - If there's a default import (name), space goes in importClause.prefix
309
+ // - If typeOnly (import type ...), space goes in importClause.prefix (before 'type')
310
+ // - If only namedBindings (no default, no type), space goes in namedBindings.prefix (importClause.prefix is empty)
311
+ const hasDefaultImport = !!draft.importClause.name;
312
+ draft.importClause.prefix.whitespace = (hasDefaultImport || draft.importClause.typeOnly) ? " " : "";
313
+ if (draft.importClause.name) {
314
+ // For import equals declarations (import X = Y), use assignment spacing
315
+ // For regular imports (import X from 'Y'), no space after name
316
+ draft.importClause.name.after.whitespace = draft.initializer
317
+ ? (this.style.aroundOperators.assignment ? " " : "")
318
+ : "";
319
+ }
320
+ if (draft.importClause.namedBindings) {
321
+ // Space before namedBindings - always needed
322
+ draft.importClause.namedBindings.prefix.whitespace = " ";
323
+ if (draft.importClause.namedBindings.kind == tree_1.JS.Kind.NamedImports) {
324
+ const ni = draft.importClause.namedBindings;
325
+ // Check if this is a multi-line import (any element's prefix has a newline)
326
+ const isMultiLine = ni.elements.elements.some(e => e.element.prefix.whitespace.includes("\n"));
327
+ if (!isMultiLine) {
328
+ // Single-line: adjust brace spacing
329
+ ni.elements.elements[0].element.prefix.whitespace = this.style.within.es6ImportExportBraces ? " " : "";
330
+ ni.elements.elements[ni.elements.elements.length - 1].after.whitespace = this.style.within.es6ImportExportBraces ? " " : "";
331
+ }
332
+ else {
333
+ // Multi-line: apply beforeComma rule to last element's after (for trailing commas)
334
+ // If it has only spaces (no newline), it's the space before a trailing comma
335
+ const lastAfter = ni.elements.elements[ni.elements.elements.length - 1].after.whitespace;
336
+ if (!lastAfter.includes("\n") && lastAfter.trim() === "") {
337
+ ni.elements.elements[ni.elements.elements.length - 1].after.whitespace = this.style.other.beforeComma ? " " : "";
414
338
  }
415
339
  }
416
340
  }
417
341
  }
418
- if (draft.moduleSpecifier) {
419
- draft.moduleSpecifier.before.whitespace = " ";
420
- draft.moduleSpecifier.element.prefix.whitespace = draft.importClause ? " " : "";
421
- }
422
- });
423
- });
424
- }
425
- visitIndexSignatureDeclaration(indexSignatureDeclaration, p) {
426
- const _super = Object.create(null, {
427
- visitIndexSignatureDeclaration: { get: () => super.visitIndexSignatureDeclaration }
428
- });
429
- return __awaiter(this, void 0, void 0, function* () {
430
- const ret = yield _super.visitIndexSignatureDeclaration.call(this, indexSignatureDeclaration, p);
431
- return (0, mutative_1.create)(ret, draft => {
432
- draft.typeExpression.before.whitespace = this.style.other.beforeTypeReferenceColon ? " " : "";
433
- draft.typeExpression.element.prefix.whitespace = this.style.other.afterTypeReferenceColon ? " " : "";
434
- });
342
+ }
343
+ if (draft.moduleSpecifier) {
344
+ draft.moduleSpecifier.before.whitespace = " ";
345
+ draft.moduleSpecifier.element.prefix.whitespace = draft.importClause ? " " : "";
346
+ }
435
347
  });
436
348
  }
437
- visitMethodDeclaration(methodDecl, p) {
438
- const _super = Object.create(null, {
439
- visitMethodDeclaration: { get: () => super.visitMethodDeclaration }
440
- });
441
- return __awaiter(this, void 0, void 0, function* () {
442
- const ret = yield _super.visitMethodDeclaration.call(this, methodDecl, p);
443
- return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
444
- if (draft.body) {
445
- this.spaceBeforeDraft(draft.body, this.style.beforeLeftBrace.functionLeftBrace);
446
- }
447
- if (draft.parameters.elements.length > 0 && draft.parameters.elements[0].element.kind != java_1.J.Kind.Empty) {
448
- draft.parameters.elements.forEach((param, index) => {
449
- this.spaceAfterRightPaddedDraft(param, index === draft.parameters.elements.length - 1 ? this.style.within.functionDeclarationParentheses : this.style.other.beforeComma);
450
- this.spaceBeforeDraft(param.element, index === 0 ? this.style.within.functionDeclarationParentheses : this.style.other.afterComma);
451
- param.element.variables[0].element.name.prefix.whitespace = "";
452
- param.element.variables[0].after.whitespace = "";
453
- });
454
- }
455
- else if (draft.parameters.elements.length == 1) {
456
- this.spaceBeforeRightPaddedElementDraft(draft.parameters.elements[0], this.style.within.functionDeclarationParentheses);
457
- this.spaceAfterRightPaddedDraft(draft.parameters.elements[0], false);
458
- }
459
- this.spaceBeforeContainerDraft(draft.parameters, this.style.beforeParentheses.functionDeclarationParentheses);
460
- // Handle generator asterisk spacing
461
- // - space before * is in the Generator marker's prefix
462
- // - space after * is in the method name's prefix
463
- const generatorIndex = ret.markers.markers.findIndex(m => m.kind === tree_1.JS.Markers.Generator);
464
- if (generatorIndex >= 0) {
465
- const generator = draft.markers.markers[generatorIndex];
466
- generator.prefix.whitespace = this.style.other.beforeAsteriskInGenerator ? " " : "";
467
- draft.name.prefix.whitespace = this.style.other.afterAsteriskInGenerator ? " " : "";
468
- }
469
- // TODO typeParameters handling - see visitClassDeclaration
470
- }));
349
+ async visitIndexSignatureDeclaration(indexSignatureDeclaration, p) {
350
+ const ret = await super.visitIndexSignatureDeclaration(indexSignatureDeclaration, p);
351
+ return (0, mutative_1.create)(ret, draft => {
352
+ draft.typeExpression.before.whitespace = this.style.other.beforeTypeReferenceColon ? " " : "";
353
+ draft.typeExpression.element.prefix.whitespace = this.style.other.afterTypeReferenceColon ? " " : "";
471
354
  });
472
355
  }
473
- visitMethodInvocation(methodInv, p) {
474
- const _super = Object.create(null, {
475
- visitMethodInvocation: { get: () => super.visitMethodInvocation }
476
- });
477
- return __awaiter(this, void 0, void 0, function* () {
478
- const ret = yield _super.visitMethodInvocation.call(this, methodInv, p);
479
- return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
480
- if (draft.select) {
481
- this.spaceBeforeContainerDraft(draft.arguments, this.style.beforeParentheses.functionCallParentheses);
482
- }
483
- if (ret.arguments.elements.length > 0 && ret.arguments.elements[0].element.kind != java_1.J.Kind.Empty) {
484
- draft.arguments.elements.forEach((arg, index) => {
485
- this.spaceAfterRightPaddedDraft(arg, index === draft.arguments.elements.length - 1 ? this.style.within.functionCallParentheses : this.style.other.beforeComma);
486
- this.spaceBeforeDraft(arg.element, index === 0 ? this.style.within.functionCallParentheses : this.style.other.afterComma);
487
- });
488
- }
489
- else if (ret.arguments.elements.length == 1) {
490
- this.spaceBeforeRightPaddedElementDraft(draft.arguments.elements[0], this.style.within.functionCallParentheses);
491
- this.spaceAfterRightPaddedDraft(draft.arguments.elements[0], false);
492
- }
493
- // TODO typeParameters handling - see visitClassDeclaration
494
- }));
356
+ async visitMethodDeclaration(methodDecl, p) {
357
+ const ret = await super.visitMethodDeclaration(methodDecl, p);
358
+ return (0, visitor_2.produceAsync)(ret, async (draft) => {
359
+ if (draft.body) {
360
+ this.spaceBeforeDraft(draft.body, this.style.beforeLeftBrace.functionLeftBrace);
361
+ }
362
+ if (draft.parameters.elements.length > 0 && draft.parameters.elements[0].element.kind != java_1.J.Kind.Empty) {
363
+ draft.parameters.elements.forEach((param, index) => {
364
+ this.spaceAfterRightPaddedDraft(param, index === draft.parameters.elements.length - 1 ? this.style.within.functionDeclarationParentheses : this.style.other.beforeComma);
365
+ this.spaceBeforeDraft(param.element, index === 0 ? this.style.within.functionDeclarationParentheses : this.style.other.afterComma);
366
+ param.element.variables[0].element.name.prefix.whitespace = "";
367
+ param.element.variables[0].after.whitespace = "";
368
+ });
369
+ }
370
+ else if (draft.parameters.elements.length == 1) {
371
+ this.spaceBeforeRightPaddedElementDraft(draft.parameters.elements[0], this.style.within.functionDeclarationParentheses);
372
+ this.spaceAfterRightPaddedDraft(draft.parameters.elements[0], false);
373
+ }
374
+ this.spaceBeforeContainerDraft(draft.parameters, this.style.beforeParentheses.functionDeclarationParentheses);
375
+ // Handle generator asterisk spacing
376
+ // - space before * is in the Generator marker's prefix
377
+ // - space after * is in the method name's prefix
378
+ const generatorIndex = ret.markers.markers.findIndex(m => m.kind === tree_1.JS.Markers.Generator);
379
+ if (generatorIndex >= 0) {
380
+ const generator = draft.markers.markers[generatorIndex];
381
+ generator.prefix.whitespace = this.style.other.beforeAsteriskInGenerator ? " " : "";
382
+ draft.name.prefix.whitespace = this.style.other.afterAsteriskInGenerator ? " " : "";
383
+ }
384
+ // TODO typeParameters handling - see visitClassDeclaration
495
385
  });
496
386
  }
497
- visitPropertyAssignment(propertyAssignment, p) {
498
- const _super = Object.create(null, {
499
- visitPropertyAssignment: { get: () => super.visitPropertyAssignment }
500
- });
501
- return __awaiter(this, void 0, void 0, function* () {
502
- const pa = yield _super.visitPropertyAssignment.call(this, propertyAssignment, p);
503
- // Only adjust the space before the colon/equals if there's an initializer (not a shorthand property)
504
- if (pa.initializer) {
505
- return (0, visitor_2.produceAsync)(pa, draft => {
506
- draft.name.after.whitespace = this.style.other.beforePropertyNameValueSeparator ? " " : "";
387
+ async visitMethodInvocation(methodInv, p) {
388
+ const ret = await super.visitMethodInvocation(methodInv, p);
389
+ return (0, visitor_2.produceAsync)(ret, async (draft) => {
390
+ if (draft.select) {
391
+ this.spaceBeforeContainerDraft(draft.arguments, this.style.beforeParentheses.functionCallParentheses);
392
+ }
393
+ if (ret.arguments.elements.length > 0 && ret.arguments.elements[0].element.kind != java_1.J.Kind.Empty) {
394
+ draft.arguments.elements.forEach((arg, index) => {
395
+ this.spaceAfterRightPaddedDraft(arg, index === draft.arguments.elements.length - 1 ? this.style.within.functionCallParentheses : this.style.other.beforeComma);
396
+ this.spaceBeforeDraft(arg.element, index === 0 ? this.style.within.functionCallParentheses : this.style.other.afterComma);
507
397
  });
508
398
  }
509
- return pa;
399
+ else if (ret.arguments.elements.length == 1) {
400
+ this.spaceBeforeRightPaddedElementDraft(draft.arguments.elements[0], this.style.within.functionCallParentheses);
401
+ this.spaceAfterRightPaddedDraft(draft.arguments.elements[0], false);
402
+ }
403
+ // TODO typeParameters handling - see visitClassDeclaration
510
404
  });
511
405
  }
512
- visitSwitch(switchNode, p) {
513
- const _super = Object.create(null, {
514
- visitSwitch: { get: () => super.visitSwitch }
515
- });
516
- return __awaiter(this, void 0, void 0, function* () {
517
- const ret = yield _super.visitSwitch.call(this, switchNode, p);
518
- return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
519
- this.spaceBeforeDraft(draft.selector, this.style.beforeParentheses.switchParentheses);
520
- this.spaceBeforeRightPaddedElementDraft(draft.selector.tree, this.style.within.switchParentheses);
521
- this.spaceAfterRightPaddedDraft(draft.selector.tree, this.style.within.switchParentheses);
522
- this.spaceBeforeDraft(draft.cases, this.style.beforeLeftBrace.switchLeftBrace);
523
- for (const case_ of draft.cases.statements) {
524
- if (case_.element.kind === java_1.J.Kind.Case) {
525
- case_.element.caseLabels.elements[0].after.whitespace = "";
526
- }
406
+ async visitPropertyAssignment(propertyAssignment, p) {
407
+ const pa = await super.visitPropertyAssignment(propertyAssignment, p);
408
+ // Only adjust the space before the colon/equals if there's an initializer (not a shorthand property)
409
+ if (pa.initializer) {
410
+ return (0, visitor_2.produceAsync)(pa, draft => {
411
+ draft.name.after.whitespace = this.style.other.beforePropertyNameValueSeparator ? " " : "";
412
+ });
413
+ }
414
+ return pa;
415
+ }
416
+ async visitSwitch(switchNode, p) {
417
+ const ret = await super.visitSwitch(switchNode, p);
418
+ return (0, visitor_2.produceAsync)(ret, async (draft) => {
419
+ this.spaceBeforeDraft(draft.selector, this.style.beforeParentheses.switchParentheses);
420
+ this.spaceBeforeRightPaddedElementDraft(draft.selector.tree, this.style.within.switchParentheses);
421
+ this.spaceAfterRightPaddedDraft(draft.selector.tree, this.style.within.switchParentheses);
422
+ this.spaceBeforeDraft(draft.cases, this.style.beforeLeftBrace.switchLeftBrace);
423
+ for (const case_ of draft.cases.statements) {
424
+ if (case_.element.kind === java_1.J.Kind.Case) {
425
+ case_.element.caseLabels.elements[0].after.whitespace = "";
527
426
  }
528
- }));
427
+ }
529
428
  });
530
429
  }
531
- visitTernary(ternary, p) {
532
- const _super = Object.create(null, {
533
- visitTernary: { get: () => super.visitTernary }
430
+ async visitTernary(ternary, p) {
431
+ const ret = await super.visitTernary(ternary, p);
432
+ return (0, visitor_2.produceAsync)(ret, async (draft) => {
433
+ this.spaceBeforeLeftPaddedElementDraft(draft.truePart, this.style.ternaryOperator.beforeQuestionMark, this.style.ternaryOperator.afterQuestionMark);
434
+ this.spaceBeforeLeftPaddedElementDraft(draft.falsePart, this.style.ternaryOperator.beforeColon, this.style.ternaryOperator.afterColon);
435
+ });
436
+ }
437
+ async visitTry(try_, p) {
438
+ const ret = await super.visitTry(try_, p);
439
+ return (0, visitor_2.produceAsync)(ret, async (draft) => {
440
+ draft.body.prefix.whitespace = this.style.beforeLeftBrace.tryLeftBrace ? " " : "";
441
+ draft.catches.forEach(catch_ => {
442
+ this.spaceBeforeDraft(catch_, this.style.beforeKeywords.catchKeyword);
443
+ catch_.parameter.prefix.whitespace = this.style.beforeParentheses.catchParentheses ? " " : "";
444
+ this.spaceBeforeRightPaddedElementDraft(catch_.parameter.tree, this.style.within.catchParentheses);
445
+ this.spaceAfterRightPaddedDraft(catch_.parameter.tree, this.style.within.catchParentheses);
446
+ if (catch_.parameter.tree.element.variables.length > 0) {
447
+ catch_.parameter.tree.element.variables[catch_.parameter.tree.element.variables.length - 1].after.whitespace = "";
448
+ }
449
+ catch_.body.prefix.whitespace = this.style.beforeLeftBrace.catchLeftBrace ? " " : "";
450
+ });
451
+ if (draft.finally) {
452
+ this.spaceBeforeLeftPaddedElementDraft(draft.finally, this.style.beforeKeywords.finallyKeyword, this.style.beforeLeftBrace.finallyLeftBrace);
453
+ }
534
454
  });
535
- return __awaiter(this, void 0, void 0, function* () {
536
- const ret = yield _super.visitTernary.call(this, ternary, p);
537
- return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
538
- this.spaceBeforeLeftPaddedElementDraft(draft.truePart, this.style.ternaryOperator.beforeQuestionMark, this.style.ternaryOperator.afterQuestionMark);
539
- this.spaceBeforeLeftPaddedElementDraft(draft.falsePart, this.style.ternaryOperator.beforeColon, this.style.ternaryOperator.afterColon);
540
- }));
455
+ }
456
+ async visitTypeDeclaration(typeDeclaration, p) {
457
+ const ret = await super.visitTypeDeclaration(typeDeclaration, p);
458
+ return (0, mutative_1.create)(ret, draft => {
459
+ if (draft.modifiers.length > 0) {
460
+ draft.name.before.whitespace = " ";
461
+ }
462
+ draft.name.element.prefix.whitespace = " ";
463
+ // Preserve newlines - only modify if no newlines present
464
+ if (!draft.initializer.before.whitespace.includes("\n")) {
465
+ draft.initializer.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
466
+ }
467
+ if (!draft.initializer.element.prefix.whitespace.includes("\n")) {
468
+ draft.initializer.element.prefix.whitespace = this.style.aroundOperators.assignment ? " " : "";
469
+ }
541
470
  });
542
471
  }
543
- visitTry(try_, p) {
544
- const _super = Object.create(null, {
545
- visitTry: { get: () => super.visitTry }
472
+ async visitTypeInfo(typeInfo, p) {
473
+ const ret = await super.visitTypeInfo(typeInfo, p);
474
+ return (0, visitor_2.produceAsync)(ret, async (draft) => {
475
+ draft.prefix.whitespace = this.style.other.beforeTypeReferenceColon ? " " : "";
476
+ this.spaceBeforeDraft(draft.typeIdentifier, this.style.other.afterTypeReferenceColon);
546
477
  });
547
- return __awaiter(this, void 0, void 0, function* () {
548
- const ret = yield _super.visitTry.call(this, try_, p);
549
- return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
550
- draft.body.prefix.whitespace = this.style.beforeLeftBrace.tryLeftBrace ? " " : "";
551
- draft.catches.forEach(catch_ => {
552
- this.spaceBeforeDraft(catch_, this.style.beforeKeywords.catchKeyword);
553
- catch_.parameter.prefix.whitespace = this.style.beforeParentheses.catchParentheses ? " " : "";
554
- this.spaceBeforeRightPaddedElementDraft(catch_.parameter.tree, this.style.within.catchParentheses);
555
- this.spaceAfterRightPaddedDraft(catch_.parameter.tree, this.style.within.catchParentheses);
556
- if (catch_.parameter.tree.element.variables.length > 0) {
557
- catch_.parameter.tree.element.variables[catch_.parameter.tree.element.variables.length - 1].after.whitespace = "";
558
- }
559
- catch_.body.prefix.whitespace = this.style.beforeLeftBrace.catchLeftBrace ? " " : "";
478
+ }
479
+ async visitTypeLiteral(typeLiteral, p) {
480
+ const ret = await super.visitTypeLiteral(typeLiteral, p);
481
+ // Apply objectLiteralTypeBraces spacing for single-line type literals
482
+ if (ret.members && ret.members.statements.length > 0) {
483
+ const stmts = ret.members.statements;
484
+ const isSingleLine = !ret.members.end.whitespace.includes("\n") &&
485
+ stmts.every(s => !s.element.prefix.whitespace.includes("\n"));
486
+ if (isSingleLine) {
487
+ return (0, mutative_1.create)(ret, draft => {
488
+ const space = this.style.within.objectLiteralTypeBraces ? " " : "";
489
+ draft.members.statements[0].element.prefix.whitespace = space;
490
+ // For type literals, the space before } is in members.end, not in last statement's after
491
+ draft.members.end.whitespace = space;
560
492
  });
561
- if (draft.finally) {
562
- this.spaceBeforeLeftPaddedElementDraft(draft.finally, this.style.beforeKeywords.finallyKeyword, this.style.beforeLeftBrace.finallyLeftBrace);
563
- }
564
- }));
493
+ }
494
+ }
495
+ return ret;
496
+ }
497
+ async visitUnary(unary, p) {
498
+ const ret = await super.visitUnary(unary, p);
499
+ return (0, mutative_1.create)(ret, draft => {
500
+ const spacing = this.style.aroundOperators.unary;
501
+ switch (draft.operator.element) {
502
+ case java_1.J.Unary.Type.Not:
503
+ draft.expression.prefix.whitespace = this.style.aroundOperators.afterUnaryNotAndNotNull ? " " : "";
504
+ break;
505
+ case java_1.J.Unary.Type.PreIncrement:
506
+ case java_1.J.Unary.Type.PreDecrement:
507
+ case java_1.J.Unary.Type.Negative:
508
+ case java_1.J.Unary.Type.Positive:
509
+ case java_1.J.Unary.Type.Complement:
510
+ draft.expression.prefix.whitespace = spacing ? " " : "";
511
+ break;
512
+ case java_1.J.Unary.Type.PostIncrement:
513
+ case java_1.J.Unary.Type.PostDecrement:
514
+ // postfix: don't add space after operand
515
+ break;
516
+ }
565
517
  });
566
518
  }
567
- visitTypeDeclaration(typeDeclaration, p) {
568
- const _super = Object.create(null, {
569
- visitTypeDeclaration: { get: () => super.visitTypeDeclaration }
570
- });
571
- return __awaiter(this, void 0, void 0, function* () {
572
- const ret = yield _super.visitTypeDeclaration.call(this, typeDeclaration, p);
573
- return (0, mutative_1.create)(ret, draft => {
574
- if (draft.modifiers.length > 0) {
575
- draft.name.before.whitespace = " ";
576
- }
577
- draft.name.element.prefix.whitespace = " ";
519
+ async visitVariable(variable, p) {
520
+ var _a, _b;
521
+ const ret = await super.visitVariable(variable, p);
522
+ if (((_b = (_a = variable.initializer) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.kind) == tree_1.JS.Kind.StatementExpression
523
+ && variable.initializer.element.statement.kind == java_1.J.Kind.MethodDeclaration) {
524
+ return ret;
525
+ }
526
+ return (0, visitor_2.produceAsync)(ret, async (draft) => {
527
+ if (draft.initializer) {
578
528
  // Preserve newlines - only modify if no newlines present
579
529
  if (!draft.initializer.before.whitespace.includes("\n")) {
580
530
  draft.initializer.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
@@ -582,136 +532,40 @@ class SpacesVisitor extends visitor_1.JavaScriptVisitor {
582
532
  if (!draft.initializer.element.prefix.whitespace.includes("\n")) {
583
533
  draft.initializer.element.prefix.whitespace = this.style.aroundOperators.assignment ? " " : "";
584
534
  }
585
- });
586
- });
587
- }
588
- visitTypeInfo(typeInfo, p) {
589
- const _super = Object.create(null, {
590
- visitTypeInfo: { get: () => super.visitTypeInfo }
591
- });
592
- return __awaiter(this, void 0, void 0, function* () {
593
- const ret = yield _super.visitTypeInfo.call(this, typeInfo, p);
594
- return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
595
- draft.prefix.whitespace = this.style.other.beforeTypeReferenceColon ? " " : "";
596
- this.spaceBeforeDraft(draft.typeIdentifier, this.style.other.afterTypeReferenceColon);
597
- }));
598
- });
599
- }
600
- visitTypeLiteral(typeLiteral, p) {
601
- const _super = Object.create(null, {
602
- visitTypeLiteral: { get: () => super.visitTypeLiteral }
603
- });
604
- return __awaiter(this, void 0, void 0, function* () {
605
- const ret = yield _super.visitTypeLiteral.call(this, typeLiteral, p);
606
- // Apply objectLiteralTypeBraces spacing for single-line type literals
607
- if (ret.members && ret.members.statements.length > 0) {
608
- const stmts = ret.members.statements;
609
- const isSingleLine = !ret.members.end.whitespace.includes("\n") &&
610
- stmts.every(s => !s.element.prefix.whitespace.includes("\n"));
611
- if (isSingleLine) {
612
- return (0, mutative_1.create)(ret, draft => {
613
- const space = this.style.within.objectLiteralTypeBraces ? " " : "";
614
- draft.members.statements[0].element.prefix.whitespace = space;
615
- // For type literals, the space before } is in members.end, not in last statement's after
616
- draft.members.end.whitespace = space;
617
- });
618
- }
619
535
  }
620
- return ret;
621
536
  });
622
537
  }
623
- visitUnary(unary, p) {
624
- const _super = Object.create(null, {
625
- visitUnary: { get: () => super.visitUnary }
626
- });
627
- return __awaiter(this, void 0, void 0, function* () {
628
- const ret = yield _super.visitUnary.call(this, unary, p);
629
- return (0, mutative_1.create)(ret, draft => {
630
- const spacing = this.style.aroundOperators.unary;
631
- switch (draft.operator.element) {
632
- case java_1.J.Unary.Type.Not:
633
- draft.expression.prefix.whitespace = this.style.aroundOperators.afterUnaryNotAndNotNull ? " " : "";
634
- break;
635
- case java_1.J.Unary.Type.PreIncrement:
636
- case java_1.J.Unary.Type.PreDecrement:
637
- case java_1.J.Unary.Type.Negative:
638
- case java_1.J.Unary.Type.Positive:
639
- case java_1.J.Unary.Type.Complement:
640
- draft.expression.prefix.whitespace = spacing ? " " : "";
641
- break;
642
- case java_1.J.Unary.Type.PostIncrement:
643
- case java_1.J.Unary.Type.PostDecrement:
644
- // postfix: don't add space after operand
645
- break;
646
- }
647
- });
648
- });
649
- }
650
- visitVariable(variable, p) {
651
- const _super = Object.create(null, {
652
- visitVariable: { get: () => super.visitVariable }
653
- });
654
- return __awaiter(this, void 0, void 0, function* () {
655
- var _a, _b;
656
- const ret = yield _super.visitVariable.call(this, variable, p);
657
- if (((_b = (_a = variable.initializer) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.kind) == tree_1.JS.Kind.StatementExpression
658
- && variable.initializer.element.statement.kind == java_1.J.Kind.MethodDeclaration) {
659
- return ret;
660
- }
661
- return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
662
- if (draft.initializer) {
663
- // Preserve newlines - only modify if no newlines present
664
- if (!draft.initializer.before.whitespace.includes("\n")) {
665
- draft.initializer.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
666
- }
667
- if (!draft.initializer.element.prefix.whitespace.includes("\n")) {
668
- draft.initializer.element.prefix.whitespace = this.style.aroundOperators.assignment ? " " : "";
538
+ async visitWhileLoop(whileLoop, p) {
539
+ const ret = await super.visitWhileLoop(whileLoop, p);
540
+ return (0, visitor_2.produceAsync)(ret, async (draft) => {
541
+ this.spaceBeforeRightPaddedElementDraft(draft.body, this.style.beforeLeftBrace.whileLeftBrace);
542
+ this.spaceAfterRightPaddedDraft(draft.body, false);
543
+ this.spaceBeforeDraft(draft.condition, this.style.beforeParentheses.whileParentheses);
544
+ this.spaceBeforeRightPaddedElementDraft(draft.condition.tree, this.style.within.whileParentheses);
545
+ this.spaceAfterRightPaddedDraft(draft.condition.tree, this.style.within.whileParentheses);
546
+ });
547
+ }
548
+ async visitTypeParameter(typeParam, p) {
549
+ const ret = await super.visitTypeParameter(typeParam, p);
550
+ return (0, mutative_1.create)(ret, draft => {
551
+ if (draft.bounds && draft.bounds.elements.length >= 2) {
552
+ const constraintType = draft.bounds.elements[0];
553
+ const defaultType = draft.bounds.elements[1];
554
+ const hasConstraint = constraintType.element.kind !== java_1.J.Kind.Empty;
555
+ const hasDefault = defaultType.element.kind !== java_1.J.Kind.Empty;
556
+ if (hasConstraint) {
557
+ // Space before '=' for default type (in the `after` of constraint type)
558
+ if (hasDefault && !constraintType.after.whitespace.includes("\n")) {
559
+ constraintType.after.whitespace = this.style.aroundOperators.assignment ? " " : "";
669
560
  }
670
561
  }
671
- }));
672
- });
673
- }
674
- visitWhileLoop(whileLoop, p) {
675
- const _super = Object.create(null, {
676
- visitWhileLoop: { get: () => super.visitWhileLoop }
677
- });
678
- return __awaiter(this, void 0, void 0, function* () {
679
- const ret = yield _super.visitWhileLoop.call(this, whileLoop, p);
680
- return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
681
- this.spaceBeforeRightPaddedElementDraft(draft.body, this.style.beforeLeftBrace.whileLeftBrace);
682
- this.spaceAfterRightPaddedDraft(draft.body, false);
683
- this.spaceBeforeDraft(draft.condition, this.style.beforeParentheses.whileParentheses);
684
- this.spaceBeforeRightPaddedElementDraft(draft.condition.tree, this.style.within.whileParentheses);
685
- this.spaceAfterRightPaddedDraft(draft.condition.tree, this.style.within.whileParentheses);
686
- }));
687
- });
688
- }
689
- visitTypeParameter(typeParam, p) {
690
- const _super = Object.create(null, {
691
- visitTypeParameter: { get: () => super.visitTypeParameter }
692
- });
693
- return __awaiter(this, void 0, void 0, function* () {
694
- const ret = yield _super.visitTypeParameter.call(this, typeParam, p);
695
- return (0, mutative_1.create)(ret, draft => {
696
- if (draft.bounds && draft.bounds.elements.length >= 2) {
697
- const constraintType = draft.bounds.elements[0];
698
- const defaultType = draft.bounds.elements[1];
699
- const hasConstraint = constraintType.element.kind !== java_1.J.Kind.Empty;
700
- const hasDefault = defaultType.element.kind !== java_1.J.Kind.Empty;
701
- if (hasConstraint) {
702
- // Space before '=' for default type (in the `after` of constraint type)
703
- if (hasDefault && !constraintType.after.whitespace.includes("\n")) {
704
- constraintType.after.whitespace = this.style.aroundOperators.assignment ? " " : "";
705
- }
706
- }
707
- else if (hasDefault) {
708
- // No constraint, just default: space before '=' is in bounds.before
709
- if (!draft.bounds.before.whitespace.includes("\n")) {
710
- draft.bounds.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
711
- }
562
+ else if (hasDefault) {
563
+ // No constraint, just default: space before '=' is in bounds.before
564
+ if (!draft.bounds.before.whitespace.includes("\n")) {
565
+ draft.bounds.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
712
566
  }
713
567
  }
714
- });
568
+ }
715
569
  });
716
570
  }
717
571
  /**
@@ -804,33 +658,28 @@ class SpacesVisitor extends visitor_1.JavaScriptVisitor {
804
658
  static isNotSingleSpace(str) {
805
659
  return this.isOnlySpaces(str) && str !== " ";
806
660
  }
807
- visitNewClass(newClass, p) {
808
- const _super = Object.create(null, {
809
- visitNewClass: { get: () => super.visitNewClass }
810
- });
811
- return __awaiter(this, void 0, void 0, function* () {
812
- const ret = yield _super.visitNewClass.call(this, newClass, p);
813
- // Only handle object literals (NewClass with no class/constructor)
814
- if (ret.class) {
815
- return ret;
816
- }
817
- // Handle object literal brace spacing: { foo: 1 } vs {foo: 1}
818
- if (ret.body && ret.body.statements.length > 0) {
819
- return (0, mutative_1.create)(ret, draft => {
820
- const stmts = draft.body.statements;
821
- // Check if this is a multi-line object literal
822
- const isMultiLine = stmts.some(s => s.element.prefix.whitespace.includes("\n")) ||
823
- draft.body.end.whitespace.includes("\n");
824
- if (!isMultiLine) {
825
- // Single-line: apply objectLiteralBraces spacing
826
- const space = this.style.within.objectLiteralBraces ? " " : "";
827
- stmts[0].element.prefix.whitespace = space;
828
- draft.body.end.whitespace = space;
829
- }
830
- });
831
- }
661
+ async visitNewClass(newClass, p) {
662
+ const ret = await super.visitNewClass(newClass, p);
663
+ // Only handle object literals (NewClass with no class/constructor)
664
+ if (ret.class) {
832
665
  return ret;
833
- });
666
+ }
667
+ // Handle object literal brace spacing: { foo: 1 } vs {foo: 1}
668
+ if (ret.body && ret.body.statements.length > 0) {
669
+ return (0, mutative_1.create)(ret, draft => {
670
+ const stmts = draft.body.statements;
671
+ // Check if this is a multi-line object literal
672
+ const isMultiLine = stmts.some(s => s.element.prefix.whitespace.includes("\n")) ||
673
+ draft.body.end.whitespace.includes("\n");
674
+ if (!isMultiLine) {
675
+ // Single-line: apply objectLiteralBraces spacing
676
+ const space = this.style.within.objectLiteralBraces ? " " : "";
677
+ stmts[0].element.prefix.whitespace = space;
678
+ draft.body.end.whitespace = space;
679
+ }
680
+ });
681
+ }
682
+ return ret;
834
683
  }
835
684
  }
836
685
  exports.SpacesVisitor = SpacesVisitor;
@@ -840,190 +689,150 @@ class WrappingAndBracesVisitor extends visitor_1.JavaScriptVisitor {
840
689
  this.style = style;
841
690
  this.stopAfter = stopAfter;
842
691
  }
843
- visit(tree, p, parent) {
844
- const _super = Object.create(null, {
845
- visit: { get: () => super.visit }
846
- });
847
- return __awaiter(this, void 0, void 0, function* () {
848
- var _a;
849
- if (((_a = this.cursor) === null || _a === void 0 ? void 0 : _a.getNearestMessage("stop")) != null) {
850
- return tree;
851
- }
852
- return _super.visit.call(this, tree, p, parent);
853
- });
854
- }
855
- postVisit(tree, p) {
856
- const _super = Object.create(null, {
857
- postVisit: { get: () => super.postVisit }
858
- });
859
- return __awaiter(this, void 0, void 0, function* () {
860
- var _a;
861
- if (this.stopAfter != null && (0, tree_2.isScope)(this.stopAfter, tree)) {
862
- (_a = this.cursor) === null || _a === void 0 ? void 0 : _a.root.messages.set("stop", true);
863
- }
864
- return _super.postVisit.call(this, tree, p);
865
- });
692
+ async visit(tree, p, parent) {
693
+ var _a;
694
+ if (((_a = this.cursor) === null || _a === void 0 ? void 0 : _a.getNearestMessage("stop")) != null) {
695
+ return tree;
696
+ }
697
+ return super.visit(tree, p, parent);
866
698
  }
867
- visitVariableDeclarations(multiVariable, p) {
868
- const _super = Object.create(null, {
869
- visitVariableDeclarations: { get: () => super.visitVariableDeclarations }
870
- });
871
- return __awaiter(this, void 0, void 0, function* () {
872
- var _a;
873
- const v = yield _super.visitVariableDeclarations.call(this, multiVariable, p);
874
- const parent = (_a = this.cursor.parentTree()) === null || _a === void 0 ? void 0 : _a.value;
875
- if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Block) {
876
- return (0, mutative_1.create)(v, draft => {
877
- draft.leadingAnnotations = this.withNewlines(draft.leadingAnnotations);
878
- if (draft.leadingAnnotations.length > 0) {
879
- if (draft.modifiers.length > 0) {
880
- draft.modifiers = this.withNewlineModifiers(draft.modifiers);
881
- }
882
- else if (draft.typeExpression && !draft.typeExpression.prefix.whitespace.includes("\n")) {
883
- draft.typeExpression.prefix.whitespace = "\n" + draft.typeExpression.prefix.whitespace;
884
- }
885
- }
886
- });
887
- }
888
- return v;
889
- });
699
+ async postVisit(tree, p) {
700
+ var _a;
701
+ if (this.stopAfter != null && (0, tree_2.isScope)(this.stopAfter, tree)) {
702
+ (_a = this.cursor) === null || _a === void 0 ? void 0 : _a.root.messages.set("stop", true);
703
+ }
704
+ return super.postVisit(tree, p);
890
705
  }
891
- visitMethodDeclaration(method, p) {
892
- const _super = Object.create(null, {
893
- visitMethodDeclaration: { get: () => super.visitMethodDeclaration }
894
- });
895
- return __awaiter(this, void 0, void 0, function* () {
896
- const m = yield _super.visitMethodDeclaration.call(this, method, p);
897
- return (0, mutative_1.create)(m, draft => {
706
+ async visitVariableDeclarations(multiVariable, p) {
707
+ var _a;
708
+ const v = await super.visitVariableDeclarations(multiVariable, p);
709
+ const parent = (_a = this.cursor.parentTree()) === null || _a === void 0 ? void 0 : _a.value;
710
+ if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Block) {
711
+ return (0, mutative_1.create)(v, draft => {
898
712
  draft.leadingAnnotations = this.withNewlines(draft.leadingAnnotations);
899
713
  if (draft.leadingAnnotations.length > 0) {
900
714
  if (draft.modifiers.length > 0) {
901
715
  draft.modifiers = this.withNewlineModifiers(draft.modifiers);
902
716
  }
903
- else if (draft.typeParameters && !draft.typeParameters.prefix.whitespace.includes("\n")) {
904
- draft.typeParameters.prefix.whitespace = "\n" + draft.typeParameters.prefix.whitespace;
905
- }
906
- else if (draft.returnTypeExpression && !draft.returnTypeExpression.prefix.whitespace.includes("\n")) {
907
- draft.returnTypeExpression.prefix.whitespace = "\n" + draft.returnTypeExpression.prefix.whitespace;
908
- }
909
- else if (!draft.name.prefix.whitespace.includes("\n")) {
910
- draft.name.prefix.whitespace = "\n" + draft.name.prefix.whitespace;
717
+ else if (draft.typeExpression && !draft.typeExpression.prefix.whitespace.includes("\n")) {
718
+ draft.typeExpression.prefix.whitespace = "\n" + draft.typeExpression.prefix.whitespace;
911
719
  }
912
720
  }
913
721
  });
914
- });
722
+ }
723
+ return v;
915
724
  }
916
- visitElse(elsePart, p) {
917
- const _super = Object.create(null, {
918
- visitElse: { get: () => super.visitElse }
919
- });
920
- return __awaiter(this, void 0, void 0, function* () {
921
- const e = yield _super.visitElse.call(this, elsePart, p);
922
- const hasBody = e.body.element.kind === java_1.J.Kind.Block || e.body.element.kind === java_1.J.Kind.If;
923
- return (0, mutative_1.create)(e, draft => {
924
- if (hasBody) {
925
- const shouldHaveNewline = this.style.ifStatement.elseOnNewLine;
926
- const hasNewline = draft.prefix.whitespace.includes("\n");
927
- if (shouldHaveNewline && !hasNewline) {
928
- draft.prefix.whitespace = "\n" + draft.prefix.whitespace;
929
- }
930
- else if (!shouldHaveNewline && hasNewline) {
931
- draft.prefix.whitespace = "";
932
- }
725
+ async visitMethodDeclaration(method, p) {
726
+ const m = await super.visitMethodDeclaration(method, p);
727
+ return (0, mutative_1.create)(m, draft => {
728
+ draft.leadingAnnotations = this.withNewlines(draft.leadingAnnotations);
729
+ if (draft.leadingAnnotations.length > 0) {
730
+ if (draft.modifiers.length > 0) {
731
+ draft.modifiers = this.withNewlineModifiers(draft.modifiers);
933
732
  }
934
- });
733
+ else if (draft.typeParameters && !draft.typeParameters.prefix.whitespace.includes("\n")) {
734
+ draft.typeParameters.prefix.whitespace = "\n" + draft.typeParameters.prefix.whitespace;
735
+ }
736
+ else if (draft.returnTypeExpression && !draft.returnTypeExpression.prefix.whitespace.includes("\n")) {
737
+ draft.returnTypeExpression.prefix.whitespace = "\n" + draft.returnTypeExpression.prefix.whitespace;
738
+ }
739
+ else if (!draft.name.prefix.whitespace.includes("\n")) {
740
+ draft.name.prefix.whitespace = "\n" + draft.name.prefix.whitespace;
741
+ }
742
+ }
935
743
  });
936
744
  }
937
- visitClassDeclaration(classDecl, p) {
938
- const _super = Object.create(null, {
939
- visitClassDeclaration: { get: () => super.visitClassDeclaration }
745
+ async visitElse(elsePart, p) {
746
+ const e = await super.visitElse(elsePart, p);
747
+ const hasBody = e.body.element.kind === java_1.J.Kind.Block || e.body.element.kind === java_1.J.Kind.If;
748
+ return (0, mutative_1.create)(e, draft => {
749
+ if (hasBody) {
750
+ const shouldHaveNewline = this.style.ifStatement.elseOnNewLine;
751
+ const hasNewline = draft.prefix.whitespace.includes("\n");
752
+ if (shouldHaveNewline && !hasNewline) {
753
+ draft.prefix.whitespace = "\n" + draft.prefix.whitespace;
754
+ }
755
+ else if (!shouldHaveNewline && hasNewline) {
756
+ draft.prefix.whitespace = "";
757
+ }
758
+ }
940
759
  });
941
- return __awaiter(this, void 0, void 0, function* () {
942
- const j = yield _super.visitClassDeclaration.call(this, classDecl, p);
943
- return (0, mutative_1.create)(j, draft => {
944
- draft.leadingAnnotations = this.withNewlines(draft.leadingAnnotations);
945
- if (draft.leadingAnnotations.length > 0) {
946
- if (draft.modifiers.length > 0) {
947
- draft.modifiers = this.withNewlineModifiers(draft.modifiers);
948
- }
949
- else {
950
- const kind = draft.classKind;
951
- if (!kind.prefix.whitespace.includes("\n")) {
952
- kind.prefix.whitespace = "\n" + kind.prefix.whitespace;
953
- }
760
+ }
761
+ async visitClassDeclaration(classDecl, p) {
762
+ const j = await super.visitClassDeclaration(classDecl, p);
763
+ return (0, mutative_1.create)(j, draft => {
764
+ draft.leadingAnnotations = this.withNewlines(draft.leadingAnnotations);
765
+ if (draft.leadingAnnotations.length > 0) {
766
+ if (draft.modifiers.length > 0) {
767
+ draft.modifiers = this.withNewlineModifiers(draft.modifiers);
768
+ }
769
+ else {
770
+ const kind = draft.classKind;
771
+ if (!kind.prefix.whitespace.includes("\n")) {
772
+ kind.prefix.whitespace = "\n" + kind.prefix.whitespace;
954
773
  }
955
774
  }
956
- });
775
+ }
957
776
  });
958
777
  }
959
- visitBlock(block, p) {
960
- const _super = Object.create(null, {
961
- visitBlock: { get: () => super.visitBlock }
962
- });
963
- return __awaiter(this, void 0, void 0, function* () {
964
- const b = yield _super.visitBlock.call(this, block, p);
965
- return (0, mutative_1.create)(b, draft => {
966
- var _a;
967
- const parentKind = (_a = this.cursor.parent) === null || _a === void 0 ? void 0 : _a.value.kind;
968
- // Check if this is a "simple" block (empty or contains only a single J.Empty)
969
- const isSimpleBlock = draft.statements.length === 0 ||
970
- (draft.statements.length === 1 && draft.statements[0].element.kind === java_1.J.Kind.Empty);
971
- // Helper to format block on one line
972
- const formatOnOneLine = () => {
973
- // Format as {} - remove any newlines from end whitespace
974
- if (draft.end.whitespace.includes("\n")) {
975
- draft.end.whitespace = draft.end.whitespace.replace(/\n\s*/g, "");
976
- }
977
- // Also remove newlines from statement padding if there's a J.Empty
978
- if (draft.statements.length === 1) {
979
- if (draft.statements[0].element.prefix.whitespace.includes("\n")) {
980
- draft.statements[0].element.prefix.whitespace = "";
981
- }
982
- if (draft.statements[0].after.whitespace.includes("\n")) {
983
- draft.statements[0].after.whitespace = "";
984
- }
778
+ async visitBlock(block, p) {
779
+ const b = await super.visitBlock(block, p);
780
+ return (0, mutative_1.create)(b, draft => {
781
+ var _a;
782
+ const parentKind = (_a = this.cursor.parent) === null || _a === void 0 ? void 0 : _a.value.kind;
783
+ // Check if this is a "simple" block (empty or contains only a single J.Empty)
784
+ const isSimpleBlock = draft.statements.length === 0 ||
785
+ (draft.statements.length === 1 && draft.statements[0].element.kind === java_1.J.Kind.Empty);
786
+ // Helper to format block on one line
787
+ const formatOnOneLine = () => {
788
+ // Format as {} - remove any newlines from end whitespace
789
+ if (draft.end.whitespace.includes("\n")) {
790
+ draft.end.whitespace = draft.end.whitespace.replace(/\n\s*/g, "");
791
+ }
792
+ // Also remove newlines from statement padding if there's a J.Empty
793
+ if (draft.statements.length === 1) {
794
+ if (draft.statements[0].element.prefix.whitespace.includes("\n")) {
795
+ draft.statements[0].element.prefix.whitespace = "";
985
796
  }
986
- };
987
- // Object literals and type literals: always format empty ones as {} on single line
988
- if (parentKind === java_1.J.Kind.NewClass || parentKind === tree_1.JS.Kind.TypeLiteral) {
989
- if (isSimpleBlock) {
990
- formatOnOneLine();
797
+ if (draft.statements[0].after.whitespace.includes("\n")) {
798
+ draft.statements[0].after.whitespace = "";
991
799
  }
992
- return;
993
800
  }
801
+ };
802
+ // Object literals and type literals: always format empty ones as {} on single line
803
+ if (parentKind === java_1.J.Kind.NewClass || parentKind === tree_1.JS.Kind.TypeLiteral) {
994
804
  if (isSimpleBlock) {
995
- // Determine which style option applies based on parent
996
- const isMethodOrFunctionBody = parentKind === java_1.J.Kind.Lambda ||
997
- parentKind === java_1.J.Kind.MethodDeclaration;
998
- const keepInOneLine = isMethodOrFunctionBody
999
- ? this.style.keepWhenReformatting.simpleMethodsInOneLine
1000
- : this.style.keepWhenReformatting.simpleBlocksInOneLine;
1001
- if (keepInOneLine) {
1002
- formatOnOneLine();
1003
- }
1004
- else {
1005
- // Format with newline between { and }
1006
- if (!draft.end.whitespace.includes("\n")) {
1007
- draft.end = this.withNewlineSpace(draft.end);
1008
- }
1009
- }
805
+ formatOnOneLine();
806
+ }
807
+ return;
808
+ }
809
+ if (isSimpleBlock) {
810
+ // Determine which style option applies based on parent
811
+ const isMethodOrFunctionBody = parentKind === java_1.J.Kind.Lambda ||
812
+ parentKind === java_1.J.Kind.MethodDeclaration;
813
+ const keepInOneLine = isMethodOrFunctionBody
814
+ ? this.style.keepWhenReformatting.simpleMethodsInOneLine
815
+ : this.style.keepWhenReformatting.simpleBlocksInOneLine;
816
+ if (keepInOneLine) {
817
+ formatOnOneLine();
1010
818
  }
1011
819
  else {
1012
- // Non-simple blocks: ensure closing brace is on its own line
1013
- if (!draft.end.whitespace.includes("\n") && !draft.statements[draft.statements.length - 1].after.whitespace.includes("\n")) {
820
+ // Format with newline between { and }
821
+ if (!draft.end.whitespace.includes("\n")) {
1014
822
  draft.end = this.withNewlineSpace(draft.end);
1015
823
  }
1016
824
  }
1017
- });
825
+ }
826
+ else {
827
+ // Non-simple blocks: ensure closing brace is on its own line
828
+ if (!draft.end.whitespace.includes("\n") && !draft.statements[draft.statements.length - 1].after.whitespace.includes("\n")) {
829
+ draft.end = this.withNewlineSpace(draft.end);
830
+ }
831
+ }
1018
832
  });
1019
833
  }
1020
- visitSwitch(aSwitch, p) {
1021
- const _super = Object.create(null, {
1022
- visitSwitch: { get: () => super.visitSwitch }
1023
- });
1024
- return __awaiter(this, void 0, void 0, function* () {
1025
- return _super.visitSwitch.call(this, aSwitch, p);
1026
- });
834
+ async visitSwitch(aSwitch, p) {
835
+ return super.visitSwitch(aSwitch, p);
1027
836
  }
1028
837
  withNewlines(list) {
1029
838
  return list.map((a, index) => {
@@ -1070,161 +879,131 @@ class BlankLinesVisitor extends visitor_1.JavaScriptVisitor {
1070
879
  this.style = style;
1071
880
  this.stopAfter = stopAfter;
1072
881
  }
1073
- preVisit(tree, p) {
1074
- const _super = Object.create(null, {
1075
- preVisit: { get: () => super.preVisit }
1076
- });
1077
- return __awaiter(this, void 0, void 0, function* () {
882
+ async preVisit(tree, p) {
883
+ var _a, _b, _c;
884
+ let ret = await super.preVisit(tree, p);
885
+ if (ret.kind === tree_1.JS.Kind.CompilationUnit) {
886
+ ret = (0, mutative_1.create)(ret, draft => {
887
+ if (draft.prefix.comments.length == 0) {
888
+ draft.prefix.whitespace = "";
889
+ }
890
+ });
891
+ }
892
+ if (ret.kind === java_1.J.Kind.MethodDeclaration
893
+ && ((_c = (_b = (_a = this.cursor.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.value.kind) === java_1.J.Kind.ClassDeclaration) {
894
+ ret = (0, mutative_1.create)(ret, draft => {
895
+ this.ensurePrefixHasNewLine(draft);
896
+ });
897
+ }
898
+ return ret;
899
+ }
900
+ async visit(tree, p, cursor) {
901
+ var _a;
902
+ if (((_a = this.cursor) === null || _a === void 0 ? void 0 : _a.getNearestMessage("stop")) != null) {
903
+ return tree;
904
+ }
905
+ return super.visit(tree, p, cursor);
906
+ }
907
+ async visitClassDeclaration(classDecl, p) {
908
+ let ret = await super.visitClassDeclaration(classDecl, p);
909
+ if (!ret.body)
910
+ return ret;
911
+ return (0, mutative_1.create)(ret, draft => {
1078
912
  var _a, _b, _c;
1079
- let ret = yield _super.preVisit.call(this, tree, p);
1080
- if (ret.kind === tree_1.JS.Kind.CompilationUnit) {
1081
- ret = (0, mutative_1.create)(ret, draft => {
1082
- if (draft.prefix.comments.length == 0) {
1083
- draft.prefix.whitespace = "";
913
+ const statements = draft.body.statements;
914
+ if (statements.length > 0) {
915
+ this.keepMaximumBlankLines(draft.body.statements[0].element, 0);
916
+ const isInterface = draft.classKind.type === java_1.J.ClassDeclaration.Kind.Type.Interface;
917
+ for (let i = 1; i < statements.length; i++) {
918
+ const previousElement = statements[i - 1].element;
919
+ let currentElement = statements[i].element;
920
+ if (previousElement.kind == java_1.J.Kind.VariableDeclarations || currentElement.kind == java_1.J.Kind.VariableDeclarations) {
921
+ const fieldBlankLines = isInterface
922
+ ? (_a = this.style.minimum.aroundFieldInInterface) !== null && _a !== void 0 ? _a : 0
923
+ : this.style.minimum.aroundField;
924
+ this.minimumBlankLines(currentElement, fieldBlankLines);
1084
925
  }
1085
- });
1086
- }
1087
- if (ret.kind === java_1.J.Kind.MethodDeclaration
1088
- && ((_c = (_b = (_a = this.cursor.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.value.kind) === java_1.J.Kind.ClassDeclaration) {
1089
- ret = (0, mutative_1.create)(ret, draft => {
1090
- this.ensurePrefixHasNewLine(draft);
1091
- });
926
+ if (previousElement.kind == java_1.J.Kind.MethodDeclaration || currentElement.kind == java_1.J.Kind.MethodDeclaration) {
927
+ const methodBlankLines = isInterface
928
+ ? (_b = this.style.minimum.aroundMethodInInterface) !== null && _b !== void 0 ? _b : 0
929
+ : this.style.minimum.aroundMethod;
930
+ this.minimumBlankLines(currentElement, methodBlankLines);
931
+ }
932
+ this.keepMaximumBlankLines(currentElement, this.style.keepMaximum.inCode);
933
+ draft.body.statements[i].element = currentElement;
934
+ }
1092
935
  }
1093
- return ret;
1094
- });
1095
- }
1096
- visit(tree, p, cursor) {
1097
- const _super = Object.create(null, {
1098
- visit: { get: () => super.visit }
1099
- });
1100
- return __awaiter(this, void 0, void 0, function* () {
1101
- var _a;
1102
- if (((_a = this.cursor) === null || _a === void 0 ? void 0 : _a.getNearestMessage("stop")) != null) {
1103
- return tree;
936
+ const cu = this.cursor.firstEnclosing((x) => x.kind === tree_1.JS.Kind.CompilationUnit);
937
+ const topLevelIndex = cu === null || cu === void 0 ? void 0 : cu.statements.findIndex(s => s.element.id == draft.id);
938
+ if (topLevelIndex !== undefined) {
939
+ const isImportJustBeforeThis = topLevelIndex > 0 && (cu === null || cu === void 0 ? void 0 : cu.statements[topLevelIndex - 1].element.kind) === tree_1.JS.Kind.Import;
940
+ if (isImportJustBeforeThis) {
941
+ this.minimumBlankLines(draft, (_c = this.style.minimum.afterImports) !== null && _c !== void 0 ? _c : 0);
942
+ }
943
+ if (topLevelIndex > 0) {
944
+ this.minimumBlankLines(draft, this.style.minimum.aroundClass);
945
+ }
946
+ this.keepMaximumBlankLines(draft, this.style.keepMaximum.inCode);
1104
947
  }
1105
- return _super.visit.call(this, tree, p, cursor);
1106
948
  });
1107
949
  }
1108
- visitClassDeclaration(classDecl, p) {
1109
- const _super = Object.create(null, {
1110
- visitClassDeclaration: { get: () => super.visitClassDeclaration }
1111
- });
1112
- return __awaiter(this, void 0, void 0, function* () {
1113
- let ret = yield _super.visitClassDeclaration.call(this, classDecl, p);
1114
- if (!ret.body)
1115
- return ret;
1116
- return (0, mutative_1.create)(ret, draft => {
1117
- var _a, _b, _c;
1118
- const statements = draft.body.statements;
1119
- if (statements.length > 0) {
1120
- this.keepMaximumBlankLines(draft.body.statements[0].element, 0);
1121
- const isInterface = draft.classKind.type === java_1.J.ClassDeclaration.Kind.Type.Interface;
1122
- for (let i = 1; i < statements.length; i++) {
1123
- const previousElement = statements[i - 1].element;
1124
- let currentElement = statements[i].element;
1125
- if (previousElement.kind == java_1.J.Kind.VariableDeclarations || currentElement.kind == java_1.J.Kind.VariableDeclarations) {
1126
- const fieldBlankLines = isInterface
1127
- ? (_a = this.style.minimum.aroundFieldInInterface) !== null && _a !== void 0 ? _a : 0
1128
- : this.style.minimum.aroundField;
1129
- this.minimumBlankLines(currentElement, fieldBlankLines);
1130
- }
1131
- if (previousElement.kind == java_1.J.Kind.MethodDeclaration || currentElement.kind == java_1.J.Kind.MethodDeclaration) {
1132
- const methodBlankLines = isInterface
1133
- ? (_b = this.style.minimum.aroundMethodInInterface) !== null && _b !== void 0 ? _b : 0
1134
- : this.style.minimum.aroundMethod;
1135
- this.minimumBlankLines(currentElement, methodBlankLines);
1136
- }
1137
- this.keepMaximumBlankLines(currentElement, this.style.keepMaximum.inCode);
1138
- draft.body.statements[i].element = currentElement;
950
+ async visitStatement(statement, p) {
951
+ var _a, _b, _c;
952
+ const ret = await super.visitStatement(statement, p);
953
+ const parent = (_a = this.cursor.parentTree()) === null || _a === void 0 ? void 0 : _a.value;
954
+ const grandparent = (_c = (_b = this.cursor.parentTree()) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.value;
955
+ return (0, mutative_1.create)(ret, draft => {
956
+ var _a, _b;
957
+ if ((grandparent === null || grandparent === void 0 ? void 0 : grandparent.kind) === java_1.J.Kind.ClassDeclaration && (parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Block) {
958
+ const classDecl = grandparent;
959
+ const block = parent;
960
+ const isFirst = block.statements.length > 0 && block.statements[0].element.id === draft.id;
961
+ if (!isFirst) {
962
+ if (draft.kind === java_1.J.Kind.VariableDeclarations) {
963
+ const declMax = classDecl.classKind.type === java_1.J.ClassDeclaration.Kind.Type.Interface
964
+ ? (_a = this.style.minimum.aroundFieldInInterface) !== null && _a !== void 0 ? _a : 0
965
+ : this.style.minimum.aroundField;
966
+ this.minimumBlankLines(draft, declMax);
1139
967
  }
1140
- }
1141
- const cu = this.cursor.firstEnclosing((x) => x.kind === tree_1.JS.Kind.CompilationUnit);
1142
- const topLevelIndex = cu === null || cu === void 0 ? void 0 : cu.statements.findIndex(s => s.element.id == draft.id);
1143
- if (topLevelIndex !== undefined) {
1144
- const isImportJustBeforeThis = topLevelIndex > 0 && (cu === null || cu === void 0 ? void 0 : cu.statements[topLevelIndex - 1].element.kind) === tree_1.JS.Kind.Import;
1145
- if (isImportJustBeforeThis) {
1146
- this.minimumBlankLines(draft, (_c = this.style.minimum.afterImports) !== null && _c !== void 0 ? _c : 0);
968
+ else if (draft.kind === java_1.J.Kind.MethodDeclaration) {
969
+ const declMax = classDecl.classKind.type === java_1.J.ClassDeclaration.Kind.Type.Interface
970
+ ? (_b = this.style.minimum.aroundMethodInInterface) !== null && _b !== void 0 ? _b : 0
971
+ : this.style.minimum.aroundMethod;
972
+ this.minimumBlankLines(draft, declMax);
973
+ }
974
+ else if (draft.kind === java_1.J.Kind.Block) {
975
+ this.minimumBlankLines(draft, this.style.minimum.aroundFunction);
1147
976
  }
1148
- if (topLevelIndex > 0) {
977
+ else if (draft.kind === java_1.J.Kind.ClassDeclaration) {
1149
978
  this.minimumBlankLines(draft, this.style.minimum.aroundClass);
1150
979
  }
1151
980
  this.keepMaximumBlankLines(draft, this.style.keepMaximum.inCode);
1152
981
  }
1153
- });
1154
- });
1155
- }
1156
- visitStatement(statement, p) {
1157
- const _super = Object.create(null, {
1158
- visitStatement: { get: () => super.visitStatement }
1159
- });
1160
- return __awaiter(this, void 0, void 0, function* () {
1161
- var _a, _b, _c;
1162
- const ret = yield _super.visitStatement.call(this, statement, p);
1163
- const parent = (_a = this.cursor.parentTree()) === null || _a === void 0 ? void 0 : _a.value;
1164
- const grandparent = (_c = (_b = this.cursor.parentTree()) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.value;
1165
- return (0, mutative_1.create)(ret, draft => {
1166
- var _a, _b;
1167
- if ((grandparent === null || grandparent === void 0 ? void 0 : grandparent.kind) === java_1.J.Kind.ClassDeclaration && (parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Block) {
1168
- const classDecl = grandparent;
1169
- const block = parent;
1170
- const isFirst = block.statements.length > 0 && block.statements[0].element.id === draft.id;
1171
- if (!isFirst) {
1172
- if (draft.kind === java_1.J.Kind.VariableDeclarations) {
1173
- const declMax = classDecl.classKind.type === java_1.J.ClassDeclaration.Kind.Type.Interface
1174
- ? (_a = this.style.minimum.aroundFieldInInterface) !== null && _a !== void 0 ? _a : 0
1175
- : this.style.minimum.aroundField;
1176
- this.minimumBlankLines(draft, declMax);
1177
- }
1178
- else if (draft.kind === java_1.J.Kind.MethodDeclaration) {
1179
- const declMax = classDecl.classKind.type === java_1.J.ClassDeclaration.Kind.Type.Interface
1180
- ? (_b = this.style.minimum.aroundMethodInInterface) !== null && _b !== void 0 ? _b : 0
1181
- : this.style.minimum.aroundMethod;
1182
- this.minimumBlankLines(draft, declMax);
1183
- }
1184
- else if (draft.kind === java_1.J.Kind.Block) {
1185
- this.minimumBlankLines(draft, this.style.minimum.aroundFunction);
1186
- }
1187
- else if (draft.kind === java_1.J.Kind.ClassDeclaration) {
1188
- this.minimumBlankLines(draft, this.style.minimum.aroundClass);
1189
- }
1190
- this.keepMaximumBlankLines(draft, this.style.keepMaximum.inCode);
1191
- }
1192
- }
1193
- else if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Block && (grandparent === null || grandparent === void 0 ? void 0 : grandparent.kind) !== java_1.J.Kind.NewClass && (grandparent === null || grandparent === void 0 ? void 0 : grandparent.kind) !== tree_1.JS.Kind.TypeLiteral ||
1194
- ((parent === null || parent === void 0 ? void 0 : parent.kind) === tree_1.JS.Kind.CompilationUnit && parent.statements[0].element.id != draft.id) ||
1195
- ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Case && this.isInsideCaseStatements(parent, draft))) {
1196
- if (draft.kind != java_1.J.Kind.Case) {
1197
- this.ensurePrefixHasNewLine(draft);
1198
- }
982
+ }
983
+ else if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Block && (grandparent === null || grandparent === void 0 ? void 0 : grandparent.kind) !== java_1.J.Kind.NewClass && (grandparent === null || grandparent === void 0 ? void 0 : grandparent.kind) !== tree_1.JS.Kind.TypeLiteral ||
984
+ ((parent === null || parent === void 0 ? void 0 : parent.kind) === tree_1.JS.Kind.CompilationUnit && parent.statements[0].element.id != draft.id) ||
985
+ ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Case && this.isInsideCaseStatements(parent, draft))) {
986
+ if (draft.kind != java_1.J.Kind.Case) {
987
+ this.ensurePrefixHasNewLine(draft);
1199
988
  }
1200
- });
989
+ }
1201
990
  });
1202
991
  }
1203
- visitBlock(block, p) {
1204
- const _super = Object.create(null, {
1205
- visitBlock: { get: () => super.visitBlock }
1206
- });
1207
- return __awaiter(this, void 0, void 0, function* () {
1208
- const b = yield _super.visitBlock.call(this, block, p);
1209
- return (0, mutative_1.create)(b, draft => {
1210
- var _a;
1211
- const parentKind = (_a = this.cursor.parent) === null || _a === void 0 ? void 0 : _a.value.kind;
1212
- // Skip newline for object literals (NewClass) and type literals (TypeLiteral)
1213
- if (parentKind != java_1.J.Kind.NewClass && parentKind != tree_1.JS.Kind.TypeLiteral) {
1214
- draft.end = (0, java_1.replaceLastWhitespace)(draft.end, ws => ws.includes("\n") ? ws : ws.replace(/[ \t]+$/, '') + "\n");
1215
- }
1216
- });
992
+ async visitBlock(block, p) {
993
+ const b = await super.visitBlock(block, p);
994
+ return (0, mutative_1.create)(b, draft => {
995
+ var _a;
996
+ const parentKind = (_a = this.cursor.parent) === null || _a === void 0 ? void 0 : _a.value.kind;
997
+ // Skip newline for object literals (NewClass) and type literals (TypeLiteral)
998
+ if (parentKind != java_1.J.Kind.NewClass && parentKind != tree_1.JS.Kind.TypeLiteral) {
999
+ draft.end = (0, java_1.replaceLastWhitespace)(draft.end, ws => ws.includes("\n") ? ws : ws.replace(/[ \t]+$/, '') + "\n");
1000
+ }
1217
1001
  });
1218
1002
  }
1219
- visitEnumValue(enumValue, p) {
1220
- const _super = Object.create(null, {
1221
- visitEnumValue: { get: () => super.visitEnumValue }
1222
- });
1223
- return __awaiter(this, void 0, void 0, function* () {
1224
- const e = yield _super.visitEnumValue.call(this, enumValue, p);
1225
- this.keepMaximumBlankLines(e, this.style.keepMaximum.inCode);
1226
- return e;
1227
- });
1003
+ async visitEnumValue(enumValue, p) {
1004
+ const e = await super.visitEnumValue(enumValue, p);
1005
+ this.keepMaximumBlankLines(e, this.style.keepMaximum.inCode);
1006
+ return e;
1228
1007
  }
1229
1008
  /**
1230
1009
  * Check if a statement is inside a Case's statements container or body,
@@ -1281,17 +1060,12 @@ class BlankLinesVisitor extends visitor_1.JavaScriptVisitor {
1281
1060
  static countNewlines(s) {
1282
1061
  return [...s].filter(c => c === "\n").length;
1283
1062
  }
1284
- postVisit(tree, p) {
1285
- const _super = Object.create(null, {
1286
- postVisit: { get: () => super.postVisit }
1287
- });
1288
- return __awaiter(this, void 0, void 0, function* () {
1289
- var _a;
1290
- if (this.stopAfter != null && (0, tree_2.isScope)(this.stopAfter, tree)) {
1291
- (_a = this.cursor) === null || _a === void 0 ? void 0 : _a.root.messages.set("stop", true);
1292
- }
1293
- return _super.postVisit.call(this, tree, p);
1294
- });
1063
+ async postVisit(tree, p) {
1064
+ var _a;
1065
+ if (this.stopAfter != null && (0, tree_2.isScope)(this.stopAfter, tree)) {
1066
+ (_a = this.cursor) === null || _a === void 0 ? void 0 : _a.root.messages.set("stop", true);
1067
+ }
1068
+ return super.postVisit(tree, p);
1295
1069
  }
1296
1070
  }
1297
1071
  exports.BlankLinesVisitor = BlankLinesVisitor;