@openrewrite/rewrite 8.69.0-20251211-160325 → 8.69.0-20251211-200238
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.
- package/dist/javascript/package-json-parser.d.ts +0 -5
- package/dist/javascript/package-json-parser.d.ts.map +1 -1
- package/dist/javascript/package-json-parser.js +2 -12
- package/dist/javascript/package-json-parser.js.map +1 -1
- package/dist/javascript/package-manager.d.ts.map +1 -1
- package/dist/javascript/package-manager.js +13 -1
- package/dist/javascript/package-manager.js.map +1 -1
- package/dist/json/parser.d.ts.map +1 -1
- package/dist/json/parser.js +355 -123
- package/dist/json/parser.js.map +1 -1
- package/dist/json/tree.d.ts +5 -1
- package/dist/json/tree.d.ts.map +1 -1
- package/dist/json/tree.js +157 -7
- package/dist/json/tree.js.map +1 -1
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +5 -1
- package/dist/print.js.map +1 -1
- package/dist/version.txt +1 -1
- package/package.json +2 -1
- package/src/javascript/package-json-parser.ts +2 -12
- package/src/javascript/package-manager.ts +13 -1
- package/src/json/parser.ts +443 -146
- package/src/json/tree.ts +159 -7
- package/src/print.ts +6 -2
package/src/json/tree.ts
CHANGED
|
@@ -98,18 +98,170 @@ export namespace Json {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
comments: [],
|
|
105
|
-
whitespace: whitespace
|
|
106
|
-
}
|
|
107
|
-
}
|
|
101
|
+
// Cache for Space objects - reuse for common whitespace patterns (flyweight pattern)
|
|
102
|
+
const spaceCache = new Map<string, Json.Space>();
|
|
103
|
+
const SPACE_CACHE_MAX_LENGTH = 100;
|
|
108
104
|
|
|
109
105
|
export const emptySpace: Json.Space = {
|
|
110
106
|
kind: Json.Kind.Space,
|
|
111
107
|
comments: [],
|
|
112
108
|
whitespace: ""
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const singleSpace: Json.Space = {
|
|
112
|
+
kind: Json.Kind.Space,
|
|
113
|
+
comments: [],
|
|
114
|
+
whitespace: " "
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Parse a formatting string into a Space object, extracting comments.
|
|
119
|
+
* Mirrors the Java Space.format() method.
|
|
120
|
+
*/
|
|
121
|
+
export function space(formatting: string): Json.Space {
|
|
122
|
+
if (formatting.length === 0) {
|
|
123
|
+
return emptySpace;
|
|
124
|
+
}
|
|
125
|
+
if (formatting === " ") {
|
|
126
|
+
return singleSpace;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Check cache first for short strings
|
|
130
|
+
const cacheable = formatting.length <= SPACE_CACHE_MAX_LENGTH;
|
|
131
|
+
if (cacheable) {
|
|
132
|
+
const cached = spaceCache.get(formatting);
|
|
133
|
+
if (cached !== undefined) {
|
|
134
|
+
return cached;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// No comment markers means simple whitespace-only Space
|
|
139
|
+
if (!formatting.includes('/')) {
|
|
140
|
+
const result: Json.Space = {
|
|
141
|
+
kind: Json.Kind.Space,
|
|
142
|
+
comments: [],
|
|
143
|
+
whitespace: formatting
|
|
144
|
+
};
|
|
145
|
+
if (cacheable) {
|
|
146
|
+
spaceCache.set(formatting, result);
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Parse comments out of the formatting string
|
|
152
|
+
let prefix = '';
|
|
153
|
+
let comment = '';
|
|
154
|
+
const comments: Json.Comment[] = [];
|
|
155
|
+
|
|
156
|
+
let inSingleLineComment = false;
|
|
157
|
+
let inMultiLineComment = false;
|
|
158
|
+
let last = '';
|
|
159
|
+
|
|
160
|
+
for (let i = 0; i < formatting.length; i++) {
|
|
161
|
+
const c = formatting[i];
|
|
162
|
+
|
|
163
|
+
if (c === '/') {
|
|
164
|
+
if (inSingleLineComment) {
|
|
165
|
+
comment += c;
|
|
166
|
+
} else if (last === '/' && !inMultiLineComment) {
|
|
167
|
+
// Start of single-line comment
|
|
168
|
+
inSingleLineComment = true;
|
|
169
|
+
comment = '';
|
|
170
|
+
prefix = prefix.slice(0, -1); // Remove the first '/'
|
|
171
|
+
} else if (last === '*' && inMultiLineComment && comment.length > 0) {
|
|
172
|
+
// End of multi-line comment
|
|
173
|
+
inMultiLineComment = false;
|
|
174
|
+
comment = comment.slice(0, -1); // Trim the last '*'
|
|
175
|
+
comments.push({
|
|
176
|
+
kind: Json.Kind.Comment,
|
|
177
|
+
multiline: true,
|
|
178
|
+
text: comment,
|
|
179
|
+
suffix: prefix.slice(0, -1),
|
|
180
|
+
markers: emptyMarkers
|
|
181
|
+
});
|
|
182
|
+
prefix = '';
|
|
183
|
+
comment = '';
|
|
184
|
+
continue;
|
|
185
|
+
} else if (inMultiLineComment) {
|
|
186
|
+
comment += c;
|
|
187
|
+
} else {
|
|
188
|
+
prefix += c;
|
|
189
|
+
}
|
|
190
|
+
} else if (c === '\r' || c === '\n') {
|
|
191
|
+
if (inSingleLineComment) {
|
|
192
|
+
// End of single-line comment
|
|
193
|
+
inSingleLineComment = false;
|
|
194
|
+
comments.push({
|
|
195
|
+
kind: Json.Kind.Comment,
|
|
196
|
+
multiline: false,
|
|
197
|
+
text: comment,
|
|
198
|
+
suffix: prefix,
|
|
199
|
+
markers: emptyMarkers
|
|
200
|
+
});
|
|
201
|
+
prefix = c;
|
|
202
|
+
comment = '';
|
|
203
|
+
} else if (!inMultiLineComment) {
|
|
204
|
+
prefix += c;
|
|
205
|
+
} else {
|
|
206
|
+
comment += c;
|
|
207
|
+
}
|
|
208
|
+
} else if (c === '*') {
|
|
209
|
+
if (inSingleLineComment) {
|
|
210
|
+
comment += c;
|
|
211
|
+
} else if (last === '/' && !inMultiLineComment) {
|
|
212
|
+
// Start of multi-line comment
|
|
213
|
+
inMultiLineComment = true;
|
|
214
|
+
comment = '';
|
|
215
|
+
} else {
|
|
216
|
+
comment += c;
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
if (inSingleLineComment || inMultiLineComment) {
|
|
220
|
+
comment += c;
|
|
221
|
+
} else {
|
|
222
|
+
prefix += c;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
last = c;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// If a file ends with a single-line comment there may be no terminating newline
|
|
229
|
+
if (comment.length > 0 || inSingleLineComment) {
|
|
230
|
+
comments.push({
|
|
231
|
+
kind: Json.Kind.Comment,
|
|
232
|
+
multiline: false,
|
|
233
|
+
text: comment,
|
|
234
|
+
suffix: prefix,
|
|
235
|
+
markers: emptyMarkers
|
|
236
|
+
});
|
|
237
|
+
prefix = '';
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Shift the whitespace on each comment forward to be a suffix of the comment before it,
|
|
241
|
+
// and the whitespace on the first comment to be the whitespace of the tree element.
|
|
242
|
+
// The remaining prefix is the suffix of the last comment.
|
|
243
|
+
let whitespace = prefix;
|
|
244
|
+
if (comments.length > 0) {
|
|
245
|
+
for (let i = comments.length - 1; i >= 0; i--) {
|
|
246
|
+
const c = comments[i];
|
|
247
|
+
const next = c.suffix;
|
|
248
|
+
comments[i] = {
|
|
249
|
+
...c,
|
|
250
|
+
suffix: whitespace
|
|
251
|
+
};
|
|
252
|
+
whitespace = next;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const result: Json.Space = {
|
|
257
|
+
kind: Json.Kind.Space,
|
|
258
|
+
comments,
|
|
259
|
+
whitespace
|
|
260
|
+
};
|
|
261
|
+
if (cacheable) {
|
|
262
|
+
spaceCache.set(formatting, result);
|
|
263
|
+
}
|
|
264
|
+
return result;
|
|
113
265
|
}
|
|
114
266
|
|
|
115
267
|
const jsonKindValues = new Set(Object.values(Json.Kind));
|
package/src/print.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {Marker, MarkersKind, SearchResult} from "./markers";
|
|
16
|
+
import {Marker, MarkersKind, Markup, SearchResult} from "./markers";
|
|
17
17
|
import {Cursor, isSourceFile, SourceFile, Tree} from "./tree";
|
|
18
18
|
import {TreeVisitor} from "./visitor";
|
|
19
19
|
import {trimIndent} from "./util";
|
|
@@ -35,7 +35,11 @@ export namespace MarkerPrinter {
|
|
|
35
35
|
let searchResult = marker as SearchResult;
|
|
36
36
|
return commentWrapper(searchResult.description == null ? "" : "(" + searchResult.description + ")");
|
|
37
37
|
} else if (marker.kind.startsWith("org.openrewrite.marker.Markup$")) {
|
|
38
|
-
|
|
38
|
+
const markup = marker as Markup;
|
|
39
|
+
const content = markup.detail
|
|
40
|
+
? `(${markup.message}: ${markup.detail})`
|
|
41
|
+
: `(${markup.message})`;
|
|
42
|
+
return commentWrapper(content);
|
|
39
43
|
}
|
|
40
44
|
return "";
|
|
41
45
|
},
|