@openrewrite/rewrite 8.69.0-20251211-200238 → 8.69.0-20251212-132620
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/cli/cli-utils.d.ts.map +1 -1
- package/dist/cli/cli-utils.js +110 -71
- package/dist/cli/cli-utils.js.map +1 -1
- package/dist/javascript/package-manager.d.ts +72 -1
- package/dist/javascript/package-manager.d.ts.map +1 -1
- package/dist/javascript/package-manager.js +160 -1
- package/dist/javascript/package-manager.js.map +1 -1
- package/dist/javascript/recipes/add-dependency.d.ts.map +1 -1
- package/dist/javascript/recipes/add-dependency.js +11 -8
- package/dist/javascript/recipes/add-dependency.js.map +1 -1
- package/dist/javascript/recipes/upgrade-dependency-version.d.ts.map +1 -1
- package/dist/javascript/recipes/upgrade-dependency-version.js +11 -8
- package/dist/javascript/recipes/upgrade-dependency-version.js.map +1 -1
- package/dist/javascript/recipes/upgrade-transitive-dependency-version.d.ts.map +1 -1
- package/dist/javascript/recipes/upgrade-transitive-dependency-version.js +11 -8
- package/dist/javascript/recipes/upgrade-transitive-dependency-version.js.map +1 -1
- package/dist/rpc/request/get-languages.d.ts.map +1 -1
- package/dist/rpc/request/get-languages.js +1 -0
- package/dist/rpc/request/get-languages.js.map +1 -1
- package/dist/rpc/server.d.ts +1 -0
- package/dist/rpc/server.d.ts.map +1 -1
- package/dist/rpc/server.js +1 -0
- package/dist/rpc/server.js.map +1 -1
- package/dist/version.txt +1 -1
- package/dist/yaml/index.d.ts +6 -0
- package/dist/yaml/index.d.ts.map +1 -0
- package/dist/yaml/index.js +37 -0
- package/dist/yaml/index.js.map +1 -0
- package/dist/yaml/parser.d.ts +6 -0
- package/dist/yaml/parser.d.ts.map +1 -0
- package/dist/yaml/parser.js +803 -0
- package/dist/yaml/parser.js.map +1 -0
- package/dist/yaml/print.d.ts +2 -0
- package/dist/yaml/print.d.ts.map +1 -0
- package/dist/yaml/print.js +234 -0
- package/dist/yaml/print.js.map +1 -0
- package/dist/yaml/rpc.d.ts +2 -0
- package/dist/yaml/rpc.d.ts.map +1 -0
- package/dist/yaml/rpc.js +264 -0
- package/dist/yaml/rpc.js.map +1 -0
- package/dist/yaml/tree.d.ts +188 -0
- package/dist/yaml/tree.d.ts.map +1 -0
- package/dist/yaml/tree.js +117 -0
- package/dist/yaml/tree.js.map +1 -0
- package/dist/yaml/visitor.d.ts +19 -0
- package/dist/yaml/visitor.d.ts.map +1 -0
- package/dist/yaml/visitor.js +170 -0
- package/dist/yaml/visitor.js.map +1 -0
- package/package.json +5 -1
- package/src/cli/cli-utils.ts +112 -35
- package/src/javascript/package-manager.ts +166 -2
- package/src/javascript/recipes/add-dependency.ts +16 -10
- package/src/javascript/recipes/upgrade-dependency-version.ts +16 -10
- package/src/javascript/recipes/upgrade-transitive-dependency-version.ts +15 -9
- package/src/rpc/request/get-languages.ts +1 -0
- package/src/rpc/server.ts +1 -0
- package/src/yaml/index.ts +21 -0
- package/src/yaml/parser.ts +850 -0
- package/src/yaml/print.ts +212 -0
- package/src/yaml/rpc.ts +248 -0
- package/src/yaml/tree.ts +281 -0
- package/src/yaml/visitor.ts +146 -0
|
@@ -0,0 +1,803 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
3
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
4
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
5
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
6
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
7
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
8
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
9
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
10
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
11
|
+
function fulfill(value) { resume("next", value); }
|
|
12
|
+
function reject(value) { resume("throw", value); }
|
|
13
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.YamlParser = void 0;
|
|
17
|
+
/*
|
|
18
|
+
* Copyright 2025 the original author or authors.
|
|
19
|
+
* <p>
|
|
20
|
+
* Licensed under the Moderne Source Available License (the "License");
|
|
21
|
+
* you may not use this file except in compliance with the License.
|
|
22
|
+
* You may obtain a copy of the License at
|
|
23
|
+
* <p>
|
|
24
|
+
* https://docs.moderne.io/licensing/moderne-source-available-license
|
|
25
|
+
* <p>
|
|
26
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
* See the License for the specific language governing permissions and
|
|
30
|
+
* limitations under the License.
|
|
31
|
+
*/
|
|
32
|
+
const markers_1 = require("../markers");
|
|
33
|
+
const parser_1 = require("../parser");
|
|
34
|
+
const uuid_1 = require("../uuid");
|
|
35
|
+
const tree_1 = require("./tree");
|
|
36
|
+
const parse_error_1 = require("../parse-error");
|
|
37
|
+
const yaml_1 = require("yaml");
|
|
38
|
+
class YamlParser extends parser_1.Parser {
|
|
39
|
+
parse(...sourcePaths) {
|
|
40
|
+
return __asyncGenerator(this, arguments, function* parse_1() {
|
|
41
|
+
for (const sourcePath of sourcePaths) {
|
|
42
|
+
const text = (0, parser_1.parserInputRead)(sourcePath);
|
|
43
|
+
try {
|
|
44
|
+
yield yield __await(Object.assign(Object.assign({}, new YamlCstReader(text).parse()), { sourcePath: this.relativePath(sourcePath) }));
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
// Return a ParseError for files that can't be parsed
|
|
48
|
+
const parseError = {
|
|
49
|
+
kind: parse_error_1.ParseErrorKind,
|
|
50
|
+
id: (0, uuid_1.randomId)(),
|
|
51
|
+
markers: (0, markers_1.markers)({
|
|
52
|
+
kind: markers_1.MarkersKind.ParseExceptionResult,
|
|
53
|
+
id: (0, uuid_1.randomId)(),
|
|
54
|
+
parserType: "YamlParser",
|
|
55
|
+
exceptionType: e.name || "Error",
|
|
56
|
+
message: e.message || "Unknown parse error"
|
|
57
|
+
}),
|
|
58
|
+
sourcePath: this.relativePath(sourcePath),
|
|
59
|
+
text
|
|
60
|
+
};
|
|
61
|
+
yield yield __await(parseError);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.YamlParser = YamlParser;
|
|
68
|
+
/**
|
|
69
|
+
* Converts YAML CST from the 'yaml' package to our Yaml AST.
|
|
70
|
+
* The CST preserves all whitespace, comments, and formatting.
|
|
71
|
+
*/
|
|
72
|
+
class YamlCstReader {
|
|
73
|
+
constructor(source) {
|
|
74
|
+
const parser = new yaml_1.Parser();
|
|
75
|
+
this.cstTokens = [...parser.parse(source)];
|
|
76
|
+
}
|
|
77
|
+
parse() {
|
|
78
|
+
const documents = [];
|
|
79
|
+
let pendingPrefix = "";
|
|
80
|
+
for (let i = 0; i < this.cstTokens.length; i++) {
|
|
81
|
+
const token = this.cstTokens[i];
|
|
82
|
+
if (token.type === 'document') {
|
|
83
|
+
const cstDoc = token;
|
|
84
|
+
// Check if next token is doc-end
|
|
85
|
+
const nextToken = this.cstTokens[i + 1];
|
|
86
|
+
let docEnd;
|
|
87
|
+
if ((nextToken === null || nextToken === void 0 ? void 0 : nextToken.type) === 'doc-end') {
|
|
88
|
+
docEnd = nextToken;
|
|
89
|
+
i++; // Skip the doc-end in the main loop
|
|
90
|
+
}
|
|
91
|
+
const { doc, afterEnd } = this.convertDocument(cstDoc, docEnd, pendingPrefix);
|
|
92
|
+
documents.push(doc);
|
|
93
|
+
pendingPrefix = afterEnd; // Content after ... becomes next doc's prefix
|
|
94
|
+
}
|
|
95
|
+
else if (token.type === 'doc-end') {
|
|
96
|
+
// Standalone doc-end without preceding document
|
|
97
|
+
const docEnd = token;
|
|
98
|
+
pendingPrefix += this.concatenateSources(docEnd.end || []);
|
|
99
|
+
}
|
|
100
|
+
else if (token.type === 'comment' || token.type === 'newline' || token.type === 'space') {
|
|
101
|
+
// Content before document (comments, whitespace) becomes document prefix
|
|
102
|
+
pendingPrefix += token.source;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
kind: tree_1.Yaml.Kind.Documents,
|
|
107
|
+
id: (0, uuid_1.randomId)(),
|
|
108
|
+
prefix: "",
|
|
109
|
+
markers: markers_1.emptyMarkers,
|
|
110
|
+
documents,
|
|
111
|
+
suffix: undefined
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
convertDocument(cstDoc, cstDocEnd, pendingPrefix = "") {
|
|
115
|
+
// Extract prefix from document start tokens
|
|
116
|
+
// The document prefix is content BEFORE the --- marker
|
|
117
|
+
// Content AFTER --- goes into the block's first entry
|
|
118
|
+
const startTokens = cstDoc.start || [];
|
|
119
|
+
let prefix = pendingPrefix; // Content before this document
|
|
120
|
+
let explicit = false;
|
|
121
|
+
let afterDocStart = ""; // Content after ---
|
|
122
|
+
let seenDocStart = false;
|
|
123
|
+
for (const token of startTokens) {
|
|
124
|
+
if (token.type === 'doc-start') {
|
|
125
|
+
explicit = true;
|
|
126
|
+
seenDocStart = true;
|
|
127
|
+
}
|
|
128
|
+
else if (seenDocStart) {
|
|
129
|
+
// Content after --- goes into block's prefix
|
|
130
|
+
afterDocStart += token.source;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
// Content before --- goes into document prefix
|
|
134
|
+
prefix += token.source;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Convert the document body and get trailing content
|
|
138
|
+
let block;
|
|
139
|
+
let trailing = "";
|
|
140
|
+
if (cstDoc.value) {
|
|
141
|
+
const result = this.convertTokenWithTrailing(cstDoc.value);
|
|
142
|
+
block = result.node;
|
|
143
|
+
trailing = result.trailing;
|
|
144
|
+
// Prepend the whitespace after --- to the block
|
|
145
|
+
if (afterDocStart) {
|
|
146
|
+
block = this.prependWhitespaceToValue(block, afterDocStart);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
block = this.createEmptyScalar(afterDocStart);
|
|
151
|
+
}
|
|
152
|
+
// Convert document end, passing the trailing content from block
|
|
153
|
+
const { end, afterEnd } = this.convertDocumentEnd(cstDoc.end, cstDocEnd, trailing);
|
|
154
|
+
return {
|
|
155
|
+
doc: {
|
|
156
|
+
kind: tree_1.Yaml.Kind.Document,
|
|
157
|
+
id: (0, uuid_1.randomId)(),
|
|
158
|
+
prefix,
|
|
159
|
+
markers: markers_1.emptyMarkers,
|
|
160
|
+
explicit,
|
|
161
|
+
block,
|
|
162
|
+
end
|
|
163
|
+
},
|
|
164
|
+
afterEnd
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
convertDocumentEnd(docEndTokens, cstDocEnd, trailing = "") {
|
|
168
|
+
// Prefix is the trailing content from the block, plus any content before ...
|
|
169
|
+
let prefix = trailing;
|
|
170
|
+
let explicit = false;
|
|
171
|
+
let afterEnd = "";
|
|
172
|
+
// Content after the document body (before ... if present)
|
|
173
|
+
if (docEndTokens) {
|
|
174
|
+
prefix += this.concatenateSources(docEndTokens);
|
|
175
|
+
}
|
|
176
|
+
// Explicit document end marker (...)
|
|
177
|
+
if (cstDocEnd) {
|
|
178
|
+
explicit = true;
|
|
179
|
+
// cstDocEnd.end contains tokens AFTER the ... marker - these become next doc's prefix
|
|
180
|
+
if (cstDocEnd.end) {
|
|
181
|
+
afterEnd = this.concatenateSources(cstDocEnd.end);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
end: {
|
|
186
|
+
kind: tree_1.Yaml.Kind.DocumentEnd,
|
|
187
|
+
id: (0, uuid_1.randomId)(),
|
|
188
|
+
prefix,
|
|
189
|
+
markers: markers_1.emptyMarkers,
|
|
190
|
+
explicit
|
|
191
|
+
},
|
|
192
|
+
afterEnd
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
convertTokenWithTrailing(token) {
|
|
196
|
+
switch (token.type) {
|
|
197
|
+
case 'block-map':
|
|
198
|
+
return this.convertBlockMapWithTrailing(token);
|
|
199
|
+
case 'block-seq':
|
|
200
|
+
return this.convertBlockSequenceWithTrailing(token);
|
|
201
|
+
case 'flow-collection':
|
|
202
|
+
return this.convertFlowCollectionWithTrailing(token);
|
|
203
|
+
case 'scalar':
|
|
204
|
+
case 'single-quoted-scalar':
|
|
205
|
+
case 'double-quoted-scalar':
|
|
206
|
+
return this.convertFlowScalarWithTrailing(token);
|
|
207
|
+
case 'block-scalar':
|
|
208
|
+
return this.convertBlockScalarWithTrailing(token);
|
|
209
|
+
case 'alias':
|
|
210
|
+
return this.convertAliasWithTrailing(token);
|
|
211
|
+
default:
|
|
212
|
+
// For unknown types, create an empty scalar
|
|
213
|
+
return { node: this.createEmptyScalar(), trailing: "" };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
convertBlockMapWithTrailing(cst) {
|
|
217
|
+
const entries = [];
|
|
218
|
+
let pendingPrefix = "";
|
|
219
|
+
for (const item of cst.items) {
|
|
220
|
+
if (item.key !== undefined || item.value !== undefined) {
|
|
221
|
+
const entry = this.convertMappingEntry(item, pendingPrefix);
|
|
222
|
+
entries.push(entry.entry);
|
|
223
|
+
pendingPrefix = entry.trailingContent;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
// Entry with no key or value - capture start tokens (comments, whitespace)
|
|
227
|
+
// into pending prefix for the next entry or as trailing content
|
|
228
|
+
pendingPrefix += this.concatenateSources(item.start || []);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
node: {
|
|
233
|
+
kind: tree_1.Yaml.Kind.Mapping,
|
|
234
|
+
id: (0, uuid_1.randomId)(),
|
|
235
|
+
prefix: "",
|
|
236
|
+
markers: markers_1.emptyMarkers,
|
|
237
|
+
openingBracePrefix: undefined, // Block map has no braces
|
|
238
|
+
entries,
|
|
239
|
+
closingBracePrefix: undefined,
|
|
240
|
+
anchor: undefined,
|
|
241
|
+
tag: undefined
|
|
242
|
+
},
|
|
243
|
+
trailing: pendingPrefix // Trailing content from last entry
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
convertMappingEntry(item, pendingPrefix = "") {
|
|
247
|
+
// Prefix comes from start tokens plus any pending prefix from previous entry's trailing content
|
|
248
|
+
const prefix = pendingPrefix + this.concatenateSources(item.start || []);
|
|
249
|
+
// Convert key and get its trailing content
|
|
250
|
+
let keyTrailing = "";
|
|
251
|
+
let key;
|
|
252
|
+
if (item.key) {
|
|
253
|
+
const keyResult = this.convertTokenWithTrailing(item.key);
|
|
254
|
+
key = keyResult.node;
|
|
255
|
+
keyTrailing = keyResult.trailing;
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
key = this.createEmptyScalar();
|
|
259
|
+
}
|
|
260
|
+
// Extract whitespace before ':' and any anchor/tag after it
|
|
261
|
+
let beforeMappingValueIndicator = keyTrailing;
|
|
262
|
+
let anchorForValue;
|
|
263
|
+
let tagForValue;
|
|
264
|
+
let afterColonWhitespace = "";
|
|
265
|
+
let seenColon = false;
|
|
266
|
+
if (item.sep) {
|
|
267
|
+
const sepTokens = item.sep;
|
|
268
|
+
for (let i = 0; i < sepTokens.length; i++) {
|
|
269
|
+
const sepToken = sepTokens[i];
|
|
270
|
+
if (sepToken.type === 'map-value-ind') {
|
|
271
|
+
seenColon = true;
|
|
272
|
+
}
|
|
273
|
+
else if (!seenColon) {
|
|
274
|
+
// Before the ':'
|
|
275
|
+
beforeMappingValueIndicator += sepToken.source;
|
|
276
|
+
}
|
|
277
|
+
else if (sepToken.type === 'anchor') {
|
|
278
|
+
// Collect all remaining tokens after anchor as postfix
|
|
279
|
+
let postfix = "";
|
|
280
|
+
for (let j = i + 1; j < sepTokens.length; j++) {
|
|
281
|
+
const nextToken = sepTokens[j];
|
|
282
|
+
if (nextToken.type === 'tag') {
|
|
283
|
+
tagForValue = this.parseTagTokenWithSuffix(nextToken.source, postfix, sepTokens, j + 1);
|
|
284
|
+
postfix = "";
|
|
285
|
+
break; // Tag handler consumed remaining tokens
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
postfix += nextToken.source;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
anchorForValue = {
|
|
292
|
+
kind: tree_1.Yaml.Kind.Anchor,
|
|
293
|
+
id: (0, uuid_1.randomId)(),
|
|
294
|
+
prefix: afterColonWhitespace,
|
|
295
|
+
markers: markers_1.emptyMarkers,
|
|
296
|
+
postfix,
|
|
297
|
+
key: sepToken.source.substring(1) // Remove &
|
|
298
|
+
};
|
|
299
|
+
afterColonWhitespace = "";
|
|
300
|
+
break; // We've consumed all remaining tokens
|
|
301
|
+
}
|
|
302
|
+
else if (sepToken.type === 'tag') {
|
|
303
|
+
// Parse tag with its suffix (whitespace after the tag)
|
|
304
|
+
tagForValue = this.parseTagTokenWithSuffix(sepToken.source, afterColonWhitespace, sepTokens, i + 1);
|
|
305
|
+
afterColonWhitespace = ""; // Remaining whitespace is in tag suffix, not value prefix
|
|
306
|
+
break; // Tag handler consumed remaining tokens
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
// After the ':'
|
|
310
|
+
afterColonWhitespace += sepToken.source;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// Convert value
|
|
315
|
+
let value;
|
|
316
|
+
let valueTrailing = "";
|
|
317
|
+
if (item.value) {
|
|
318
|
+
const valueResult = this.convertTokenWithTrailing(item.value);
|
|
319
|
+
value = valueResult.node;
|
|
320
|
+
valueTrailing = valueResult.trailing;
|
|
321
|
+
// Apply anchor and tag if found in separator
|
|
322
|
+
if (anchorForValue && 'anchor' in value) {
|
|
323
|
+
value = Object.assign(Object.assign({}, value), { anchor: anchorForValue });
|
|
324
|
+
}
|
|
325
|
+
if (tagForValue && 'tag' in value) {
|
|
326
|
+
value = Object.assign(Object.assign({}, value), { tag: tagForValue });
|
|
327
|
+
}
|
|
328
|
+
// Prepend accumulated whitespace based on value type
|
|
329
|
+
if (afterColonWhitespace) {
|
|
330
|
+
value = this.prependWhitespaceToValue(value, afterColonWhitespace);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
value = this.createEmptyScalar(afterColonWhitespace);
|
|
335
|
+
}
|
|
336
|
+
return {
|
|
337
|
+
entry: {
|
|
338
|
+
kind: tree_1.Yaml.Kind.MappingEntry,
|
|
339
|
+
id: (0, uuid_1.randomId)(),
|
|
340
|
+
prefix,
|
|
341
|
+
markers: markers_1.emptyMarkers,
|
|
342
|
+
key,
|
|
343
|
+
beforeMappingValueIndicator,
|
|
344
|
+
value
|
|
345
|
+
},
|
|
346
|
+
trailingContent: valueTrailing
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
convertBlockSequenceWithTrailing(cst) {
|
|
350
|
+
const entries = [];
|
|
351
|
+
let pendingPrefix = "";
|
|
352
|
+
for (const item of cst.items) {
|
|
353
|
+
const result = this.convertSequenceEntry(item, true, pendingPrefix);
|
|
354
|
+
entries.push(result.entry);
|
|
355
|
+
pendingPrefix = result.trailingContent;
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
node: {
|
|
359
|
+
kind: tree_1.Yaml.Kind.Sequence,
|
|
360
|
+
id: (0, uuid_1.randomId)(),
|
|
361
|
+
prefix: "",
|
|
362
|
+
markers: markers_1.emptyMarkers,
|
|
363
|
+
openingBracketPrefix: undefined, // Block sequence has no brackets
|
|
364
|
+
entries,
|
|
365
|
+
closingBracketPrefix: undefined,
|
|
366
|
+
anchor: undefined,
|
|
367
|
+
tag: undefined
|
|
368
|
+
},
|
|
369
|
+
trailing: pendingPrefix // Trailing content from last entry
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
convertSequenceEntry(item, dash, pendingPrefix = "") {
|
|
373
|
+
// Build prefix from start tokens, but exclude the dash indicator itself
|
|
374
|
+
let prefix = pendingPrefix;
|
|
375
|
+
let afterDashSpace = "";
|
|
376
|
+
let seenDash = false;
|
|
377
|
+
for (const token of item.start || []) {
|
|
378
|
+
if (token.type === 'seq-item-ind') {
|
|
379
|
+
seenDash = true;
|
|
380
|
+
}
|
|
381
|
+
else if (seenDash) {
|
|
382
|
+
afterDashSpace += token.source;
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
prefix += token.source;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
// Convert value
|
|
389
|
+
let block;
|
|
390
|
+
let trailing = "";
|
|
391
|
+
if (item.value) {
|
|
392
|
+
const valueResult = this.convertTokenWithTrailing(item.value);
|
|
393
|
+
block = valueResult.node;
|
|
394
|
+
trailing = valueResult.trailing;
|
|
395
|
+
// Prepend the space after dash to the block's prefix
|
|
396
|
+
block = Object.assign(Object.assign({}, block), { prefix: afterDashSpace + block.prefix });
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
block = this.createEmptyScalar(afterDashSpace);
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
entry: {
|
|
403
|
+
kind: tree_1.Yaml.Kind.SequenceEntry,
|
|
404
|
+
id: (0, uuid_1.randomId)(),
|
|
405
|
+
prefix,
|
|
406
|
+
markers: markers_1.emptyMarkers,
|
|
407
|
+
block,
|
|
408
|
+
dash,
|
|
409
|
+
trailingCommaPrefix: undefined // Block sequence has no commas
|
|
410
|
+
},
|
|
411
|
+
trailingContent: trailing
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
convertFlowCollectionWithTrailing(cst) {
|
|
415
|
+
const isMap = cst.start.source === '{';
|
|
416
|
+
const openingPrefix = "";
|
|
417
|
+
// End tokens include closing bracket/brace plus any trailing content
|
|
418
|
+
// We need to separate the closing delimiter from trailing whitespace
|
|
419
|
+
const endTokens = cst.end || [];
|
|
420
|
+
let closingPrefix = "";
|
|
421
|
+
let trailing = "";
|
|
422
|
+
let seenClosing = false;
|
|
423
|
+
for (const token of endTokens) {
|
|
424
|
+
if (token.type === 'flow-map-end' || token.type === 'flow-seq-end') {
|
|
425
|
+
seenClosing = true;
|
|
426
|
+
}
|
|
427
|
+
else if (seenClosing) {
|
|
428
|
+
trailing += token.source;
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
closingPrefix += token.source;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
if (isMap) {
|
|
435
|
+
const entries = [];
|
|
436
|
+
let pendingPrefix = "";
|
|
437
|
+
for (const item of cst.items) {
|
|
438
|
+
if (item.key !== undefined || item.value !== undefined) {
|
|
439
|
+
const result = this.convertFlowMappingEntry(item, pendingPrefix);
|
|
440
|
+
entries.push(result.entry);
|
|
441
|
+
pendingPrefix = result.trailingContent;
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
// Empty item (trailing comma) - capture start tokens including the comma
|
|
445
|
+
pendingPrefix += this.concatenateSources(item.start || []);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
// Trailing content from last entry becomes part of closing brace prefix
|
|
449
|
+
const finalClosingPrefix = pendingPrefix + closingPrefix;
|
|
450
|
+
return {
|
|
451
|
+
node: {
|
|
452
|
+
kind: tree_1.Yaml.Kind.Mapping,
|
|
453
|
+
id: (0, uuid_1.randomId)(),
|
|
454
|
+
prefix: "",
|
|
455
|
+
markers: markers_1.emptyMarkers,
|
|
456
|
+
openingBracePrefix: openingPrefix,
|
|
457
|
+
entries,
|
|
458
|
+
closingBracePrefix: finalClosingPrefix,
|
|
459
|
+
anchor: undefined,
|
|
460
|
+
tag: undefined
|
|
461
|
+
},
|
|
462
|
+
trailing
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
// Flow sequence [a, b, c]
|
|
467
|
+
const entries = [];
|
|
468
|
+
let pendingPrefix = "";
|
|
469
|
+
for (let i = 0; i < cst.items.length; i++) {
|
|
470
|
+
const item = cst.items[i];
|
|
471
|
+
const isLast = i === cst.items.length - 1;
|
|
472
|
+
const result = this.convertFlowSequenceEntry(item, isLast, pendingPrefix);
|
|
473
|
+
entries.push(result.entry);
|
|
474
|
+
pendingPrefix = result.trailingContent;
|
|
475
|
+
}
|
|
476
|
+
// Trailing content from last entry becomes part of closing bracket prefix
|
|
477
|
+
const finalClosingPrefix = pendingPrefix + closingPrefix;
|
|
478
|
+
return {
|
|
479
|
+
node: {
|
|
480
|
+
kind: tree_1.Yaml.Kind.Sequence,
|
|
481
|
+
id: (0, uuid_1.randomId)(),
|
|
482
|
+
prefix: "",
|
|
483
|
+
markers: markers_1.emptyMarkers,
|
|
484
|
+
openingBracketPrefix: openingPrefix,
|
|
485
|
+
entries,
|
|
486
|
+
closingBracketPrefix: finalClosingPrefix,
|
|
487
|
+
anchor: undefined,
|
|
488
|
+
tag: undefined
|
|
489
|
+
},
|
|
490
|
+
trailing
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
convertFlowMappingEntry(item, pendingPrefix) {
|
|
495
|
+
const prefix = pendingPrefix + this.concatenateSources(item.start || []);
|
|
496
|
+
let keyTrailing = "";
|
|
497
|
+
let key;
|
|
498
|
+
if (item.key) {
|
|
499
|
+
const keyResult = this.convertTokenWithTrailing(item.key);
|
|
500
|
+
key = keyResult.node;
|
|
501
|
+
keyTrailing = keyResult.trailing;
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
key = this.createEmptyScalar();
|
|
505
|
+
}
|
|
506
|
+
let beforeMappingValueIndicator = keyTrailing;
|
|
507
|
+
let afterColonSpace = "";
|
|
508
|
+
let seenColon = false;
|
|
509
|
+
if (item.sep) {
|
|
510
|
+
for (const token of item.sep) {
|
|
511
|
+
if (token.type === 'map-value-ind') {
|
|
512
|
+
seenColon = true;
|
|
513
|
+
}
|
|
514
|
+
else if (seenColon) {
|
|
515
|
+
afterColonSpace += token.source;
|
|
516
|
+
}
|
|
517
|
+
else if (token.type === 'comma') {
|
|
518
|
+
// This is the comma after the entry, not before
|
|
519
|
+
// Skip it as we handle comma separately
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
beforeMappingValueIndicator += token.source;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
let value;
|
|
527
|
+
let valueTrailing = "";
|
|
528
|
+
if (item.value) {
|
|
529
|
+
const valueResult = this.convertTokenWithTrailing(item.value);
|
|
530
|
+
value = valueResult.node;
|
|
531
|
+
valueTrailing = valueResult.trailing;
|
|
532
|
+
value = Object.assign(Object.assign({}, value), { prefix: afterColonSpace + value.prefix });
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
value = this.createEmptyScalar(afterColonSpace);
|
|
536
|
+
}
|
|
537
|
+
return {
|
|
538
|
+
entry: {
|
|
539
|
+
kind: tree_1.Yaml.Kind.MappingEntry,
|
|
540
|
+
id: (0, uuid_1.randomId)(),
|
|
541
|
+
prefix,
|
|
542
|
+
markers: markers_1.emptyMarkers,
|
|
543
|
+
key,
|
|
544
|
+
beforeMappingValueIndicator,
|
|
545
|
+
value
|
|
546
|
+
},
|
|
547
|
+
trailingContent: valueTrailing
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
convertFlowSequenceEntry(item, isLast, pendingPrefix) {
|
|
551
|
+
// Start tokens may include comma from previous item
|
|
552
|
+
let prefix = pendingPrefix;
|
|
553
|
+
let hasComma = false;
|
|
554
|
+
for (const token of item.start || []) {
|
|
555
|
+
if (token.type === 'comma') {
|
|
556
|
+
hasComma = true;
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
prefix += token.source;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
let block;
|
|
563
|
+
let trailing = "";
|
|
564
|
+
if (item.value) {
|
|
565
|
+
const valueResult = this.convertTokenWithTrailing(item.value);
|
|
566
|
+
block = valueResult.node;
|
|
567
|
+
trailing = valueResult.trailing;
|
|
568
|
+
}
|
|
569
|
+
else if (item.key !== undefined) {
|
|
570
|
+
// Flow sequence can contain mapping entries: [a: 1, b: 2]
|
|
571
|
+
const entryResult = this.convertFlowMappingEntry(item, "");
|
|
572
|
+
block = {
|
|
573
|
+
kind: tree_1.Yaml.Kind.Mapping,
|
|
574
|
+
id: (0, uuid_1.randomId)(),
|
|
575
|
+
prefix: "",
|
|
576
|
+
markers: markers_1.emptyMarkers,
|
|
577
|
+
openingBracePrefix: undefined,
|
|
578
|
+
entries: [entryResult.entry],
|
|
579
|
+
closingBracePrefix: undefined,
|
|
580
|
+
anchor: undefined,
|
|
581
|
+
tag: undefined
|
|
582
|
+
};
|
|
583
|
+
trailing = entryResult.trailingContent;
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
block = this.createEmptyScalar();
|
|
587
|
+
}
|
|
588
|
+
// Trailing comma prefix captures space after value before comma
|
|
589
|
+
let trailingCommaPrefix;
|
|
590
|
+
if (!isLast) {
|
|
591
|
+
trailingCommaPrefix = trailing;
|
|
592
|
+
trailing = "";
|
|
593
|
+
}
|
|
594
|
+
return {
|
|
595
|
+
entry: {
|
|
596
|
+
kind: tree_1.Yaml.Kind.SequenceEntry,
|
|
597
|
+
id: (0, uuid_1.randomId)(),
|
|
598
|
+
prefix,
|
|
599
|
+
markers: markers_1.emptyMarkers,
|
|
600
|
+
block,
|
|
601
|
+
dash: false, // Flow sequences don't use dashes
|
|
602
|
+
trailingCommaPrefix
|
|
603
|
+
},
|
|
604
|
+
trailingContent: trailing
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
convertFlowScalarWithTrailing(cst) {
|
|
608
|
+
var _a;
|
|
609
|
+
const resolved = yaml_1.CST.resolveAsScalar(cst);
|
|
610
|
+
const value = (_a = resolved === null || resolved === void 0 ? void 0 : resolved.value) !== null && _a !== void 0 ? _a : "";
|
|
611
|
+
// Determine scalar style
|
|
612
|
+
let style;
|
|
613
|
+
switch (cst.type) {
|
|
614
|
+
case 'single-quoted-scalar':
|
|
615
|
+
style = tree_1.Yaml.ScalarStyle.SINGLE_QUOTED;
|
|
616
|
+
break;
|
|
617
|
+
case 'double-quoted-scalar':
|
|
618
|
+
style = tree_1.Yaml.ScalarStyle.DOUBLE_QUOTED;
|
|
619
|
+
break;
|
|
620
|
+
default:
|
|
621
|
+
style = tree_1.Yaml.ScalarStyle.PLAIN;
|
|
622
|
+
}
|
|
623
|
+
// End tokens contain trailing whitespace/newlines
|
|
624
|
+
const trailing = this.concatenateSources(cst.end || []);
|
|
625
|
+
return {
|
|
626
|
+
node: {
|
|
627
|
+
kind: tree_1.Yaml.Kind.Scalar,
|
|
628
|
+
id: (0, uuid_1.randomId)(),
|
|
629
|
+
prefix: "",
|
|
630
|
+
markers: markers_1.emptyMarkers,
|
|
631
|
+
style,
|
|
632
|
+
anchor: undefined,
|
|
633
|
+
tag: undefined,
|
|
634
|
+
value
|
|
635
|
+
},
|
|
636
|
+
trailing
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
convertBlockScalarWithTrailing(cst) {
|
|
640
|
+
// Use CST.stringify to get the exact original source including header
|
|
641
|
+
const fullSource = yaml_1.CST.stringify(cst);
|
|
642
|
+
// Determine style from the first character (| or >)
|
|
643
|
+
const headerChar = fullSource.charAt(0);
|
|
644
|
+
const style = headerChar === '|' ? tree_1.Yaml.ScalarStyle.LITERAL : tree_1.Yaml.ScalarStyle.FOLDED;
|
|
645
|
+
// The value is everything after the header indicator (| or >)
|
|
646
|
+
const value = fullSource.substring(1);
|
|
647
|
+
// Extract anchor and tag from props if present
|
|
648
|
+
let anchor;
|
|
649
|
+
let tag;
|
|
650
|
+
for (const prop of cst.props || []) {
|
|
651
|
+
if ('type' in prop) {
|
|
652
|
+
const propTyped = prop;
|
|
653
|
+
if (propTyped.type === 'anchor') {
|
|
654
|
+
anchor = this.parseAnchorToken(propTyped.source, "");
|
|
655
|
+
}
|
|
656
|
+
else if (propTyped.type === 'tag') {
|
|
657
|
+
tag = this.parseTagToken(propTyped.source, "");
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
return {
|
|
662
|
+
node: {
|
|
663
|
+
kind: tree_1.Yaml.Kind.Scalar,
|
|
664
|
+
id: (0, uuid_1.randomId)(),
|
|
665
|
+
prefix: "",
|
|
666
|
+
markers: markers_1.emptyMarkers,
|
|
667
|
+
style,
|
|
668
|
+
anchor,
|
|
669
|
+
tag,
|
|
670
|
+
value
|
|
671
|
+
},
|
|
672
|
+
trailing: "" // Block scalars don't have separate end tokens
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
convertAliasWithTrailing(cst) {
|
|
676
|
+
// Alias source is like "*anchorName"
|
|
677
|
+
const key = cst.source.substring(1); // Remove the *
|
|
678
|
+
const anchor = {
|
|
679
|
+
kind: tree_1.Yaml.Kind.Anchor,
|
|
680
|
+
id: (0, uuid_1.randomId)(),
|
|
681
|
+
prefix: "",
|
|
682
|
+
markers: markers_1.emptyMarkers,
|
|
683
|
+
postfix: "",
|
|
684
|
+
key
|
|
685
|
+
};
|
|
686
|
+
// End tokens contain trailing whitespace
|
|
687
|
+
const trailing = this.concatenateSources(cst.end || []);
|
|
688
|
+
return {
|
|
689
|
+
node: {
|
|
690
|
+
kind: tree_1.Yaml.Kind.Alias,
|
|
691
|
+
id: (0, uuid_1.randomId)(),
|
|
692
|
+
prefix: "",
|
|
693
|
+
markers: markers_1.emptyMarkers,
|
|
694
|
+
anchor
|
|
695
|
+
},
|
|
696
|
+
trailing
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
parseAnchorToken(source, prefix) {
|
|
700
|
+
// Anchor source is like "&anchorName"
|
|
701
|
+
const key = source.substring(1); // Remove the &
|
|
702
|
+
return {
|
|
703
|
+
kind: tree_1.Yaml.Kind.Anchor,
|
|
704
|
+
id: (0, uuid_1.randomId)(),
|
|
705
|
+
prefix,
|
|
706
|
+
markers: markers_1.emptyMarkers,
|
|
707
|
+
postfix: "",
|
|
708
|
+
key
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
parseTagToken(source, prefix) {
|
|
712
|
+
return this.parseTagTokenWithSuffix(source, prefix, [], 0);
|
|
713
|
+
}
|
|
714
|
+
parseTagTokenWithSuffix(source, prefix, remainingTokens, startIndex) {
|
|
715
|
+
let name;
|
|
716
|
+
let tagKind;
|
|
717
|
+
if (source.startsWith('!<') && source.endsWith('>')) {
|
|
718
|
+
// Explicit global tag: !<tag:yaml.org,2002:str>
|
|
719
|
+
name = source.substring(2, source.length - 1);
|
|
720
|
+
tagKind = tree_1.Yaml.TagKind.EXPLICIT_GLOBAL;
|
|
721
|
+
}
|
|
722
|
+
else if (source.startsWith('!!')) {
|
|
723
|
+
// Implicit global tag: !!str
|
|
724
|
+
name = source.substring(2);
|
|
725
|
+
tagKind = tree_1.Yaml.TagKind.IMPLICIT_GLOBAL;
|
|
726
|
+
}
|
|
727
|
+
else {
|
|
728
|
+
// Local tag: !custom
|
|
729
|
+
name = source.substring(1);
|
|
730
|
+
tagKind = tree_1.Yaml.TagKind.LOCAL;
|
|
731
|
+
}
|
|
732
|
+
// Collect remaining tokens as suffix (whitespace after the tag)
|
|
733
|
+
let suffix = "";
|
|
734
|
+
for (let i = startIndex; i < remainingTokens.length; i++) {
|
|
735
|
+
suffix += remainingTokens[i].source;
|
|
736
|
+
}
|
|
737
|
+
return {
|
|
738
|
+
kind: tree_1.Yaml.Kind.Tag,
|
|
739
|
+
id: (0, uuid_1.randomId)(),
|
|
740
|
+
prefix,
|
|
741
|
+
markers: markers_1.emptyMarkers,
|
|
742
|
+
name,
|
|
743
|
+
suffix,
|
|
744
|
+
tagKind
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
createEmptyScalar(prefix = "") {
|
|
748
|
+
return {
|
|
749
|
+
kind: tree_1.Yaml.Kind.Scalar,
|
|
750
|
+
id: (0, uuid_1.randomId)(),
|
|
751
|
+
prefix,
|
|
752
|
+
markers: markers_1.emptyMarkers,
|
|
753
|
+
style: tree_1.Yaml.ScalarStyle.PLAIN,
|
|
754
|
+
anchor: undefined,
|
|
755
|
+
tag: undefined,
|
|
756
|
+
value: ""
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Prepends whitespace to a value node in the appropriate location based on its type.
|
|
761
|
+
* - For Scalars and Aliases: prepend to prefix
|
|
762
|
+
* - For flow Mappings (with braces): prepend to openingBracePrefix
|
|
763
|
+
* - For flow Sequences (with brackets): prepend to openingBracketPrefix
|
|
764
|
+
* - For block Mappings/Sequences: prepend to first entry's prefix
|
|
765
|
+
*/
|
|
766
|
+
prependWhitespaceToValue(value, whitespace) {
|
|
767
|
+
if (value.kind === tree_1.Yaml.Kind.Scalar || value.kind === tree_1.Yaml.Kind.Alias) {
|
|
768
|
+
return Object.assign(Object.assign({}, value), { prefix: whitespace + value.prefix });
|
|
769
|
+
}
|
|
770
|
+
if (value.kind === tree_1.Yaml.Kind.Mapping) {
|
|
771
|
+
const mapping = value;
|
|
772
|
+
if (mapping.openingBracePrefix !== undefined) {
|
|
773
|
+
// Flow mapping: prepend to opening brace prefix
|
|
774
|
+
return Object.assign(Object.assign({}, mapping), { openingBracePrefix: whitespace + mapping.openingBracePrefix });
|
|
775
|
+
}
|
|
776
|
+
else if (mapping.entries.length > 0) {
|
|
777
|
+
// Block mapping: prepend to first entry's prefix
|
|
778
|
+
const firstEntry = mapping.entries[0];
|
|
779
|
+
const updatedFirstEntry = Object.assign(Object.assign({}, firstEntry), { prefix: whitespace + firstEntry.prefix });
|
|
780
|
+
return Object.assign(Object.assign({}, mapping), { entries: [updatedFirstEntry, ...mapping.entries.slice(1)] });
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
if (value.kind === tree_1.Yaml.Kind.Sequence) {
|
|
784
|
+
const sequence = value;
|
|
785
|
+
if (sequence.openingBracketPrefix !== undefined) {
|
|
786
|
+
// Flow sequence: prepend to opening bracket prefix
|
|
787
|
+
return Object.assign(Object.assign({}, sequence), { openingBracketPrefix: whitespace + sequence.openingBracketPrefix });
|
|
788
|
+
}
|
|
789
|
+
else if (sequence.entries.length > 0) {
|
|
790
|
+
// Block sequence: prepend to first entry's prefix
|
|
791
|
+
const firstEntry = sequence.entries[0];
|
|
792
|
+
const updatedFirstEntry = Object.assign(Object.assign({}, firstEntry), { prefix: whitespace + firstEntry.prefix });
|
|
793
|
+
return Object.assign(Object.assign({}, sequence), { entries: [updatedFirstEntry, ...sequence.entries.slice(1)] });
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
// Fallback: prepend to prefix (shouldn't normally reach here)
|
|
797
|
+
return Object.assign(Object.assign({}, value), { prefix: whitespace + value.prefix });
|
|
798
|
+
}
|
|
799
|
+
concatenateSources(tokens) {
|
|
800
|
+
return tokens.map(t => t.source).join('');
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
//# sourceMappingURL=parser.js.map
|