@decimalturn/toml-patch 3.1.1-dev → 3.1.1

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 (70) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +169 -0
  3. package/dist/toml-patch.js +54 -0
  4. package/package.json +93 -11
  5. package/dist/dev/comment-alignment.js +0 -372
  6. package/dist/dev/comment-alignment.js.map +0 -1
  7. package/dist/dev/comment-ownership.js +0 -660
  8. package/dist/dev/comment-ownership.js.map +0 -1
  9. package/dist/dev/cst-source.js +0 -108
  10. package/dist/dev/cst-source.js.map +0 -1
  11. package/dist/dev/cst.js +0 -59
  12. package/dist/dev/cst.js.map +0 -1
  13. package/dist/dev/cursor.js +0 -66
  14. package/dist/dev/cursor.js.map +0 -1
  15. package/dist/dev/date-format.js +0 -196
  16. package/dist/dev/date-format.js.map +0 -1
  17. package/dist/dev/decode-utf8.js +0 -27
  18. package/dist/dev/decode-utf8.js.map +0 -1
  19. package/dist/dev/diff.js +0 -269
  20. package/dist/dev/diff.js.map +0 -1
  21. package/dist/dev/escape-preference.js +0 -144
  22. package/dist/dev/escape-preference.js.map +0 -1
  23. package/dist/dev/find-by-path.js +0 -111
  24. package/dist/dev/find-by-path.js.map +0 -1
  25. package/dist/dev/formatter.js +0 -295
  26. package/dist/dev/formatter.js.map +0 -1
  27. package/dist/dev/generate.js +0 -451
  28. package/dist/dev/generate.js.map +0 -1
  29. package/dist/dev/inline-comma-space.js +0 -13
  30. package/dist/dev/inline-comma-space.js.map +0 -1
  31. package/dist/dev/inline-format.js +0 -106
  32. package/dist/dev/inline-format.js.map +0 -1
  33. package/dist/dev/inline-layout.js +0 -107
  34. package/dist/dev/inline-layout.js.map +0 -1
  35. package/dist/dev/line-ending-backslash.js +0 -320
  36. package/dist/dev/line-ending-backslash.js.map +0 -1
  37. package/dist/dev/location.js +0 -104
  38. package/dist/dev/location.js.map +0 -1
  39. package/dist/dev/parse-error.js +0 -27
  40. package/dist/dev/parse-error.js.map +0 -1
  41. package/dist/dev/parse-js.js +0 -103
  42. package/dist/dev/parse-js.js.map +0 -1
  43. package/dist/dev/parse-string.js +0 -122
  44. package/dist/dev/parse-string.js.map +0 -1
  45. package/dist/dev/parse-toml.js +0 -677
  46. package/dist/dev/parse-toml.js.map +0 -1
  47. package/dist/dev/patch.js +0 -2537
  48. package/dist/dev/patch.js.map +0 -1
  49. package/dist/dev/to-js.js +0 -303
  50. package/dist/dev/to-js.js.map +0 -1
  51. package/dist/dev/to-toml.js +0 -569
  52. package/dist/dev/to-toml.js.map +0 -1
  53. package/dist/dev/tokenizer.js +0 -225
  54. package/dist/dev/tokenizer.js.map +0 -1
  55. package/dist/dev/toml-document.js +0 -215
  56. package/dist/dev/toml-document.js.map +0 -1
  57. package/dist/dev/toml-format.js +0 -476
  58. package/dist/dev/toml-format.js.map +0 -1
  59. package/dist/dev/toml-patch.js +0 -84
  60. package/dist/dev/toml-patch.js.map +0 -1
  61. package/dist/dev/traverse.js +0 -61
  62. package/dist/dev/traverse.js.map +0 -1
  63. package/dist/dev/truncate.js +0 -64
  64. package/dist/dev/truncate.js.map +0 -1
  65. package/dist/dev/update-order.js +0 -235
  66. package/dist/dev/update-order.js.map +0 -1
  67. package/dist/dev/utils.js +0 -223
  68. package/dist/dev/utils.js.map +0 -1
  69. package/dist/dev/writer.js +0 -758
  70. package/dist/dev/writer.js.map +0 -1
@@ -1,569 +0,0 @@
1
- //! @decimalturn/toml-patch v3.1.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
- import { hasItem, hasItems, isInlineArray, isInlineItem, isInlineTable, isKeyValue, isTable, isTableArray } from "./cst.js";
3
- import { getCommaSpace } from "./inline-comma-space.js";
4
- import { getNodeSource, originalFirstChildStartedAfterOpener, sourceStructureUnchanged } from "./cst-source.js";
5
- import { isIterable } from "./utils.js";
6
- import { isGeneratedNestedTable, isGeneratedNestedTableHost, isPreservedMultilineEmpty } from "./inline-format.js";
7
-
8
- //#region src/to-toml.ts
9
- const BY_NEW_LINE = /(\r\n|\n)/g;
10
- /**
11
- * Converts a Concrete Syntax Tree (CST) back to TOML format string.
12
- *
13
- * This function traverses the CST and reconstructs the original TOML document
14
- * by writing each node's raw content to the appropriate location coordinates.
15
- * It preserves the original formatting, spacing, and structure of the TOML file.
16
- *
17
- * @param cst - The Concrete Syntax Tree representing the parsed TOML document
18
- * @param format - The formatting options to use for the output
19
- * @returns The reconstructed TOML document as a string
20
- *
21
- * @example
22
- * ```typescript
23
- * const tomlString = toTOML(cst, TomlFormat.default());
24
- * ```
25
- */
26
- function toTOML(cst, format) {
27
- const lines = [];
28
- const closingPosition = (container) => {
29
- const position = {
30
- line: container.loc.end.line,
31
- column: container.loc.end.column - 1
32
- };
33
- const last = container.items[container.items.length - 1];
34
- if (last && (last.loc.end.line > position.line || last.loc.end.line === position.line && last.loc.end.column > position.column)) {
35
- position.line = last.loc.end.line;
36
- position.column = last.loc.end.column + (last.comma ? 1 : 0);
37
- }
38
- return position;
39
- };
40
- function emitNode(node) {
41
- switch (node.type) {
42
- case "Document":
43
- for (let i = 0; i < node.items.length; i++) emitNode(node.items[i]);
44
- break;
45
- case "Table": {
46
- const tbl = node;
47
- emitNode(tbl.key);
48
- for (let i = 0; i < tbl.items.length; i++) emitNode(tbl.items[i]);
49
- break;
50
- }
51
- case "TableKey": {
52
- const tk = node;
53
- write(lines, tk.loc, "[" + tk.item.raw + "]");
54
- break;
55
- }
56
- case "TableArray": {
57
- const ta = node;
58
- emitNode(ta.key);
59
- for (let i = 0; i < ta.items.length; i++) emitNode(ta.items[i]);
60
- break;
61
- }
62
- case "TableArrayKey": {
63
- const tak = node;
64
- write(lines, tak.loc, "[[" + tak.item.raw + "]]");
65
- break;
66
- }
67
- case "KeyValue": {
68
- const kv = node;
69
- const line = kv.loc.start.line;
70
- writeSingle(lines, line, kv.equals, "=");
71
- emitNode(kv.key);
72
- emitNode(kv.value);
73
- break;
74
- }
75
- case "Key":
76
- write(lines, node.loc, node.raw);
77
- break;
78
- case "String":
79
- write(lines, node.loc, node.raw);
80
- break;
81
- case "Integer":
82
- write(lines, node.loc, node.raw);
83
- break;
84
- case "Float":
85
- write(lines, node.loc, node.raw);
86
- break;
87
- case "Boolean":
88
- write(lines, node.loc, node.value.toString());
89
- break;
90
- case "DateTime":
91
- write(lines, node.loc, node.raw);
92
- break;
93
- case "InlineArray": {
94
- const ia = node;
95
- const { start } = ia.loc;
96
- const closing = closingPosition(ia);
97
- writeSingle(lines, start.line, start.column, "[");
98
- writeSingle(lines, closing.line, closing.column, "]");
99
- for (let i = 0; i < ia.items.length; i++) emitNode(ia.items[i]);
100
- break;
101
- }
102
- case "InlineTable": {
103
- const it = node;
104
- const { start } = it.loc;
105
- const closing = closingPosition(it);
106
- writeSingle(lines, start.line, start.column, "{");
107
- writeSingle(lines, closing.line, closing.column, "}");
108
- for (let i = 0; i < it.items.length; i++) emitNode(it.items[i]);
109
- break;
110
- }
111
- case "InlineItem": {
112
- const ii = node;
113
- emitNode(ii.item);
114
- if (ii.comma) {
115
- const end = ii.loc.end;
116
- writeSingle(lines, end.line, end.column, ",");
117
- }
118
- break;
119
- }
120
- case "Comment":
121
- write(lines, node.loc, node.raw);
122
- break;
123
- default: {
124
- const type = node.type;
125
- throw new Error(`toTOML: Unrecognized node type: ${String(type)}`);
126
- }
127
- }
128
- }
129
- if (isIterable(cst)) for (const item of cst) emitNode(item);
130
- else emitNode(cst);
131
- if (format.useTabsForIndentation) {
132
- const contentLines = /* @__PURE__ */ new Set();
133
- const collectStringLines = (node) => {
134
- if (node.type === "String" && node.loc.end.line > node.loc.start.line) for (let l = node.loc.start.line + 1; l <= node.loc.end.line; l++) contentLines.add(l);
135
- if (hasItems(node)) for (const item of node.items) collectStringLines(item);
136
- if (isKeyValue(node)) collectStringLines(node.value);
137
- if (isInlineItem(node)) collectStringLines(node.item);
138
- };
139
- if (isIterable(cst)) for (const item of cst) collectStringLines(item);
140
- else collectStringLines(cst);
141
- for (let i = 0; i < lines.length; i++) {
142
- if (contentLines.has(i + 1)) continue;
143
- const line = lines[i];
144
- const match = line.match(/^( +)/);
145
- if (match) {
146
- const leadingSpaces = match[1];
147
- const leadingTabs = " ".repeat(leadingSpaces.length);
148
- lines[i] = leadingTabs + line.substring(leadingSpaces.length);
149
- }
150
- }
151
- }
152
- return lines.join(format.newLine) + format.newLine.repeat(format.trailingNewline);
153
- }
154
- /**
155
- * Source-aware emitter used while CST ranges replace coordinate painting.
156
- * Clean nodes copy their original text. Dirty nodes emit in structural order,
157
- * so a stale coordinate can add whitespace but cannot overwrite later text.
158
- */
159
- function toTOMLCursor(cst, format) {
160
- const roots = isIterable(cst) ? Array.from(cst) : [cst];
161
- const chunks = [];
162
- const copiedRanges = [];
163
- const hostedComments = [];
164
- const consumedComments = /* @__PURE__ */ new WeakSet();
165
- let line = 1;
166
- let column = 0;
167
- const collectComments = (node) => {
168
- if (node.type === "Comment") hostedComments.push(node);
169
- if (isKeyValue(node)) collectComments(node.value);
170
- else if (isInlineItem(node)) collectComments(node.item);
171
- else if (node.type === "Table" || node.type === "TableArray") for (const item of node.items) collectComments(item);
172
- else if (hasItems(node)) for (const item of node.items) collectComments(item);
173
- };
174
- for (const root of roots) collectComments(root);
175
- const blockLevelInlineContainers = /* @__PURE__ */ new WeakSet();
176
- const markBlockLevelInlineContainers = (items) => {
177
- for (const item of items) if (isKeyValue(item)) {
178
- const value = item.value;
179
- if (isInlineTable(value) || isInlineArray(value)) blockLevelInlineContainers.add(value);
180
- } else if (isTable(item) || isTableArray(item)) markBlockLevelInlineContainers(item.items);
181
- };
182
- markBlockLevelInlineContainers(roots);
183
- const indentation = (width) => (format.useTabsForIndentation ? " " : " ").repeat(width);
184
- const append = (text) => {
185
- if (text.length === 0) return;
186
- chunks.push(text);
187
- const parts = text.split(/\r\n|\n/);
188
- if (parts.length === 1) column += text.length;
189
- else {
190
- line += parts.length - 1;
191
- column = parts[parts.length - 1].length;
192
- }
193
- };
194
- const advanceTo = (targetLine, targetColumn) => {
195
- if (targetLine > line) {
196
- append(format.newLine.repeat(targetLine - line));
197
- if (targetColumn > 0) append(indentation(targetColumn));
198
- } else if (targetLine === line && targetColumn > column) append(column === 0 ? indentation(targetColumn) : " ".repeat(targetColumn - column));
199
- else if (chunks.length > 0 && (targetLine < line || targetLine === line && targetColumn < column)) {
200
- append(format.newLine);
201
- if (targetColumn > 0) append(indentation(targetColumn));
202
- }
203
- };
204
- const leafText = (node) => {
205
- switch (node.type) {
206
- case "Key": return node.raw;
207
- case "String": return node.raw;
208
- case "Integer": return node.raw;
209
- case "Float": return node.raw;
210
- case "Boolean": return node.value.toString();
211
- case "DateTime": return node.raw;
212
- case "Comment": return node.raw;
213
- default: return;
214
- }
215
- };
216
- const directChildren = (node) => {
217
- if (isKeyValue(node)) return [node.key, node.value];
218
- if (isInlineItem(node)) return [node.item];
219
- if (hasItem(node)) return [node.item];
220
- if (node.type === "Table" || node.type === "TableArray") {
221
- const table = node;
222
- return [table.key, ...table.items];
223
- }
224
- return hasItems(node) ? node.items : [];
225
- };
226
- const sourceSubtreeReusable = (node) => {
227
- const pending = [node];
228
- while (pending.length > 0) {
229
- const current = pending.pop();
230
- if (current.dirty) return false;
231
- const text = leafText(current);
232
- if (text !== void 0) {
233
- const source = getNodeSource(current);
234
- if (!source || !current.range || source.slice(current.range[0], current.range[1]) !== text) return false;
235
- } else if (!sourceStructureUnchanged(current)) return false;
236
- pending.push(...directChildren(current));
237
- }
238
- return true;
239
- };
240
- const canCopyWholeNode = (node) => node.type !== "Document" && node.type !== "InlineItem" && node.type !== "TableKey" && node.type !== "TableArrayKey" && (leafText(node) !== void 0 || sourceStructureUnchanged(node));
241
- const appendRelativeGap = (from, to, absoluteIndent = false) => {
242
- if (to.line > from.line) {
243
- append(format.newLine.repeat(to.line - from.line));
244
- if (to.column > 0) append(absoluteIndent ? " ".repeat(to.column) : indentation(to.column));
245
- } else if (to.line === from.line && to.column > from.column) append(" ".repeat(to.column - from.column));
246
- };
247
- const sourceGap = (container, previous, current) => {
248
- var _previous$range, _current$range;
249
- const source = getNodeSource(container);
250
- if (!source || !container.range) return void 0;
251
- if (isInlineArray(container) && isGeneratedNestedTableHost(container) && (!current || previous && !previous.range || current && !current.range)) return void 0;
252
- if (previous && getNodeSource(previous) !== source) return void 0;
253
- if (current && getNodeSource(current) !== source) return void 0;
254
- const start = (previous === null || previous === void 0 || (_previous$range = previous.range) === null || _previous$range === void 0 ? void 0 : _previous$range[1]) ?? container.range[0] + 1;
255
- const end = (current === null || current === void 0 || (_current$range = current.range) === null || _current$range === void 0 ? void 0 : _current$range[0]) ?? container.range[1] - 1;
256
- if (start === void 0 || end === void 0 || end < start) return void 0;
257
- let gap = source.slice(start, end);
258
- if ((previous === null || previous === void 0 ? void 0 : previous.comma) && gap.startsWith(",")) gap = gap.slice(1);
259
- if (!/^[\t \r\n]*$/.test(gap)) return void 0;
260
- return gap;
261
- };
262
- const commentBelongsTo = (comment, container) => {
263
- const source = getNodeSource(container);
264
- return source !== void 0 && getNodeSource(comment) === source && container.range !== void 0 && comment.range !== void 0 && comment.range[0] >= container.range[0] && comment.range[1] <= container.range[1];
265
- };
266
- const emitInlineItems = (container) => {
267
- const generatedMultilineTable = isInlineTable(container) && isGeneratedNestedTable(container);
268
- let previous;
269
- for (const current of container.items) {
270
- let from = previous ? {
271
- line: previous.loc.end.line,
272
- column: previous.loc.end.column + (previous.comma ? 1 : 0)
273
- } : {
274
- line: container.loc.start.line,
275
- column: container.loc.start.column + 1
276
- };
277
- const commentsBefore = hostedComments.filter((comment) => !consumedComments.has(comment) && commentBelongsTo(comment, container) && comment.loc.start.line >= from.line && comment.loc.end.line <= current.loc.start.line && (comment.loc.start.line > from.line || comment.loc.start.column >= from.column) && (comment.loc.end.line < current.loc.start.line || comment.loc.end.column <= current.loc.start.column) && comment.loc.start.line >= container.loc.start.line && comment.loc.end.line <= container.loc.end.line).sort((left, right) => left.loc.start.line - right.loc.start.line || left.loc.start.column - right.loc.start.column);
278
- if (commentsBefore.length > 0) {
279
- for (const comment of commentsBefore) {
280
- appendRelativeGap(from, comment.loc.start);
281
- append(comment.raw);
282
- consumedComments.add(comment);
283
- from = comment.loc.end;
284
- }
285
- appendRelativeGap(from, current.loc.start);
286
- } else {
287
- const gap = sourceGap(container, previous, current);
288
- if (gap !== void 0) append(gap);
289
- else {
290
- const crossSource = getNodeSource(current) !== getNodeSource(container);
291
- if (previous && crossSource && current.loc.start.line === previous.loc.end.line) {
292
- const commaGap = getCommaSpace(container) ?? 2;
293
- const wantedSpaces = Math.max(0, commaGap - 1);
294
- if (wantedSpaces > 0) append(" ".repeat(wantedSpaces));
295
- } else appendRelativeGap(from, current.loc.start, generatedMultilineTable);
296
- }
297
- }
298
- emitNode(current, false);
299
- for (const comment of hostedComments) {
300
- if (consumedComments.has(comment)) continue;
301
- if (!commentBelongsTo(comment, container)) continue;
302
- if (comment.loc.start.line !== current.loc.end.line) continue;
303
- if (comment.loc.start.column < current.loc.end.column) continue;
304
- if (comment.loc.start.line < container.loc.start.line || comment.loc.end.line > container.loc.end.line) continue;
305
- const separatorEnd = current.loc.end.column + (current.comma ? 1 : 0);
306
- if (comment.loc.start.column > separatorEnd) append(" ".repeat(comment.loc.start.column - separatorEnd));
307
- append(comment.raw);
308
- consumedComments.add(comment);
309
- }
310
- previous = current;
311
- }
312
- let trailingFrom = previous ? {
313
- line: previous.loc.end.line,
314
- column: previous.loc.end.column + (previous.comma ? 1 : 0)
315
- } : {
316
- line: container.loc.start.line,
317
- column: container.loc.start.column + 1
318
- };
319
- const trailingComments = hostedComments.filter((comment) => !consumedComments.has(comment) && commentBelongsTo(comment, container) && comment.loc.start.line >= trailingFrom.line && comment.loc.end.line <= container.loc.end.line).sort((left, right) => left.loc.start.line - right.loc.start.line || left.loc.start.column - right.loc.start.column);
320
- if (trailingComments.length > 0) {
321
- for (const comment of trailingComments) {
322
- appendRelativeGap(trailingFrom, comment.loc.start);
323
- append(comment.raw);
324
- consumedComments.add(comment);
325
- trailingFrom = comment.loc.end;
326
- }
327
- appendRelativeGap(trailingFrom, {
328
- line: container.loc.end.line,
329
- column: container.loc.end.column - 1
330
- });
331
- } else {
332
- const trailingGap = sourceGap(container, previous, void 0);
333
- if (trailingGap !== void 0) append(trailingGap);
334
- else if (previous) {
335
- if (generatedMultilineTable && previous.comma) append(" ");
336
- appendRelativeGap(trailingFrom, {
337
- line: container.loc.end.line,
338
- column: container.loc.end.column - 1
339
- }, generatedMultilineTable);
340
- } else {
341
- const source = getNodeSource(container);
342
- if (source && container.range) {
343
- const original = source.slice(container.range[0], container.range[1]);
344
- const lastNewline = Math.max(original.lastIndexOf("\n"), original.lastIndexOf("\r"));
345
- const keepClosingRow = blockLevelInlineContainers.has(container) || isPreservedMultilineEmpty(container);
346
- if (lastNewline !== -1 && keepClosingRow && originalFirstChildStartedAfterOpener(container)) {
347
- var _original$slice$match;
348
- const closingIndent = ((_original$slice$match = original.slice(lastNewline + 1, -1).match(/^[\t ]*/)) === null || _original$slice$match === void 0 ? void 0 : _original$slice$match[0]) ?? "";
349
- append(format.newLine + closingIndent);
350
- }
351
- }
352
- }
353
- }
354
- };
355
- const emitNode = (node, place = true) => {
356
- if (node.type === "Comment" && consumedComments.has(node)) return;
357
- const source = getNodeSource(node);
358
- if (source !== void 0 && node.range && copiedRanges.some((copied) => copied.source === source && copied.start <= node.range[0] && copied.end >= node.range[1])) return;
359
- if (canCopyWholeNode(node) && sourceSubtreeReusable(node) && node.range && source !== void 0) {
360
- const slice = source.slice(node.range[0], node.range[1]);
361
- const expectedLeaf = leafText(node);
362
- if (expectedLeaf === void 0 || expectedLeaf === slice) {
363
- if (place) advanceTo(node.loc.start.line, node.loc.start.column);
364
- append(slice);
365
- copiedRanges.push({
366
- source,
367
- start: node.range[0],
368
- end: node.range[1]
369
- });
370
- return;
371
- }
372
- }
373
- switch (node.type) {
374
- case "Document":
375
- for (const item of node.items) emitNode(item);
376
- break;
377
- case "Table": {
378
- const table = node;
379
- emitNode(table.key, place);
380
- for (const item of table.items) emitNode(item);
381
- break;
382
- }
383
- case "TableKey": {
384
- const tableKey = node;
385
- if (place) advanceTo(tableKey.loc.start.line, tableKey.loc.start.column);
386
- append(`[${tableKey.item.raw}]`);
387
- break;
388
- }
389
- case "TableArray": {
390
- const tableArray = node;
391
- emitNode(tableArray.key, place);
392
- for (const item of tableArray.items) emitNode(item);
393
- break;
394
- }
395
- case "TableArrayKey": {
396
- const tableArrayKey = node;
397
- if (place) advanceTo(tableArrayKey.loc.start.line, tableArrayKey.loc.start.column);
398
- append(`[[${tableArrayKey.item.raw}]]`);
399
- break;
400
- }
401
- case "KeyValue": {
402
- const keyValue = node;
403
- if (place) advanceTo(keyValue.loc.start.line, keyValue.loc.start.column);
404
- emitNode(keyValue.key, false);
405
- appendRelativeGap(keyValue.key.loc.end, {
406
- line: keyValue.loc.start.line,
407
- column: keyValue.equals
408
- });
409
- append("=");
410
- appendRelativeGap({
411
- line: keyValue.loc.start.line,
412
- column: keyValue.equals + 1
413
- }, keyValue.value.loc.start);
414
- emitNode(keyValue.value, false);
415
- break;
416
- }
417
- case "Key":
418
- if (place) advanceTo(node.loc.start.line, node.loc.start.column);
419
- append(node.raw);
420
- break;
421
- case "String":
422
- if (place) advanceTo(node.loc.start.line, node.loc.start.column);
423
- append(node.raw);
424
- break;
425
- case "Integer":
426
- if (place) advanceTo(node.loc.start.line, node.loc.start.column);
427
- append(node.raw);
428
- break;
429
- case "Float":
430
- if (place) advanceTo(node.loc.start.line, node.loc.start.column);
431
- append(node.raw);
432
- break;
433
- case "Boolean":
434
- if (place) advanceTo(node.loc.start.line, node.loc.start.column);
435
- append(node.value.toString());
436
- break;
437
- case "DateTime":
438
- if (place) advanceTo(node.loc.start.line, node.loc.start.column);
439
- append(node.raw);
440
- break;
441
- case "InlineArray": {
442
- const array = node;
443
- if (place) advanceTo(array.loc.start.line, array.loc.start.column);
444
- append("[");
445
- emitInlineItems(array);
446
- append("]");
447
- break;
448
- }
449
- case "InlineTable": {
450
- const table = node;
451
- if (place) advanceTo(table.loc.start.line, table.loc.start.column);
452
- append("{");
453
- emitInlineItems(table);
454
- append("}");
455
- break;
456
- }
457
- case "InlineItem": {
458
- const item = node;
459
- emitNode(item.item, false);
460
- if (item.comma) {
461
- const source = getNodeSource(item);
462
- if (source && item.range && item.item.range && getNodeSource(item.item) === source) {
463
- const beforeComma = source.slice(item.item.range[1], item.range[1]);
464
- if (/^[\t ]*$/.test(beforeComma)) append(beforeComma);
465
- }
466
- append(",");
467
- }
468
- break;
469
- }
470
- case "Comment":
471
- if (place) advanceTo(node.loc.start.line, node.loc.start.column);
472
- append(node.raw);
473
- break;
474
- default: throw new Error(`toTOMLCursor: Unrecognized node type: ${String(node.type)}`);
475
- }
476
- };
477
- for (const root of roots) emitNode(root);
478
- return chunks.join("").replace(/\r\n|\n/g, format.newLine) + format.newLine.repeat(format.trailingNewline);
479
- }
480
- /**
481
- * Writes raw string content to specific location coordinates within a lines array.
482
- *
483
- * This function is responsible for placing TOML content at precise positions within
484
- * the output lines, handling multi-line content and preserving existing content
485
- * around the target location.
486
- *
487
- * @param lines - Array of string lines representing the TOML document being built.
488
- * Lines are 1-indexed but stored in 0-indexed array.
489
- * @param loc - Location object specifying where to write the content, containing:
490
- * - start: { line: number, column: number } - Starting position (1-indexed line, 0-indexed column)
491
- * - end: { line: number, column: number } - Ending position (1-indexed line, 0-indexed column)
492
- * @param raw - The raw string content to write at the specified location.
493
- * Can contain multiple lines separated by \n or \r\n.
494
- *
495
- * @throws {Error} When there's a mismatch between location span and raw string line count
496
- * @throws {Error} When attempting to write to an uninitialized line
497
- *
498
- * @example
499
- * ```typescript
500
- * const lines = ['', ''];
501
- * const location = { start: { line: 1, column: 0 }, end: { line: 1, column: 3 } };
502
- * write(lines, location, 'key');
503
- * // Result: lines[0] becomes 'key'
504
- * ```
505
- */
506
- function write(lines, loc, raw) {
507
- if (loc.start.line === loc.end.line) {
508
- const line = getLine(lines, loc.start.line);
509
- const existingBefore = line.substring(0, loc.start.column);
510
- const before = existingBefore.length < loc.start.column ? existingBefore.padEnd(loc.start.column, " ") : existingBefore;
511
- const after = line.substring(loc.end.column);
512
- lines[loc.start.line - 1] = before + raw + after;
513
- return;
514
- }
515
- const raw_lines = raw.split(BY_NEW_LINE).filter((line) => line !== "\n" && line !== "\r\n");
516
- const expected_lines = loc.end.line - loc.start.line + 1;
517
- if (raw_lines.length !== expected_lines) throw new Error(`Mismatch between location and raw string, expected ${expected_lines} lines for "${raw}"`);
518
- for (let i = loc.start.line; i <= loc.end.line; i++) {
519
- const line = getLine(lines, i);
520
- const is_start_line = i === loc.start.line;
521
- const is_end_line = i === loc.end.line;
522
- let before = "";
523
- if (is_start_line) {
524
- const existingBefore = line.substring(0, loc.start.column);
525
- if (existingBefore.length < loc.start.column) before = existingBefore.padEnd(loc.start.column, " ");
526
- else before = existingBefore;
527
- }
528
- const after = is_end_line ? line.substring(loc.end.column) : "";
529
- lines[i - 1] = before + raw_lines[i - loc.start.line] + after;
530
- }
531
- }
532
- /**
533
- * Fast path for writing a single character at a specific position.
534
- * Avoids creating temporary Location objects.
535
- */
536
- function writeSingle(lines, lineNum, column, char) {
537
- const line = getLine(lines, lineNum);
538
- const before = line.length < column ? line.padEnd(column, " ") : line.substring(0, column);
539
- const after = line.substring(column + 1);
540
- lines[lineNum - 1] = before + char + after;
541
- }
542
- /**
543
- * Safely retrieves a line from the lines array, initializing empty lines as needed.
544
- *
545
- * This helper function handles the conversion between 1-indexed line numbers (used in locations)
546
- * and 0-indexed array positions. It ensures that accessing a line that doesn't exist yet
547
- * will initialize all preceding lines with empty strings.
548
- *
549
- * @param lines - Array of string lines representing the document
550
- * @param index - 1-indexed line number to retrieve
551
- * @returns The line content as a string, or empty string for new lines
552
- *
553
- * @example
554
- * ```typescript
555
- * const lines = ['first line'];
556
- * const line = getLine(lines, 3); // Initializes lines[1] and lines[2] as empty strings
557
- * // lines becomes ['first line', '', '']
558
- * ```
559
- */
560
- function getLine(lines, index) {
561
- if (!lines[index - 1]) {
562
- for (let i = 0; i < index; i++) if (!lines[i]) lines[i] = "";
563
- }
564
- return lines[index - 1];
565
- }
566
-
567
- //#endregion
568
- export { toTOML as default, toTOMLCursor };
569
- //# sourceMappingURL=to-toml.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"to-toml.js","names":[],"sources":["../../src/to-toml.ts"],"sourcesContent":["import {\n getNodeSource,\n originalFirstChildStartedAfterOpener,\n sourceStructureUnchanged\n} from './cst-source';\nimport {\n NodeType,\n CST,\n TreeNode,\n Document,\n Table,\n TableKey,\n TableArray,\n TableArrayKey,\n KeyValue,\n Key,\n String as StringNode,\n Integer,\n Float,\n Boolean as BooleanNode,\n DateTime,\n InlineArray,\n InlineTable,\n InlineItem,\n Comment,\n hasItems,\n hasItem,\n isKeyValue,\n isInlineItem,\n isTable,\n isTableArray,\n isInlineTable,\n isInlineArray\n} from './cst';\nimport { Location } from './location';\nimport { SPACE } from './tokenizer';\nimport { TomlFormat } from './toml-format';\nimport { isIterable } from './utils';\nimport { getCommaSpace } from './inline-comma-space';\nimport { isGeneratedNestedTable, isGeneratedNestedTableHost, isPreservedMultilineEmpty } from './inline-format';\n\nconst BY_NEW_LINE = /(\\r\\n|\\n)/g;\n\n/**\n * Converts a Concrete Syntax Tree (CST) back to TOML format string.\n * \n * This function traverses the CST and reconstructs the original TOML document\n * by writing each node's raw content to the appropriate location coordinates.\n * It preserves the original formatting, spacing, and structure of the TOML file.\n * \n * @param cst - The Concrete Syntax Tree representing the parsed TOML document\n * @param format - The formatting options to use for the output\n * @returns The reconstructed TOML document as a string\n * \n * @example\n * ```typescript\n * const tomlString = toTOML(cst, TomlFormat.default());\n * ```\n */\nexport default function toTOML(cst: CST, format: TomlFormat): string {\n\n const lines: string[] = [];\n\n // Inline traversal for monomorphic property access (avoids generic traverse\n // visitor dispatch which causes megamorphic inline cache misses in V8)\n const closingPosition = (container: InlineArray | InlineTable): { line: number; column: number } => {\n const position = {\n line: container.loc.end.line,\n column: container.loc.end.column - 1\n };\n const last = container.items[container.items.length - 1];\n if (last && (last.loc.end.line > position.line ||\n (last.loc.end.line === position.line && last.loc.end.column > position.column))) {\n position.line = last.loc.end.line;\n position.column = last.loc.end.column + (last.comma ? 1 : 0);\n }\n return position;\n };\n\n function emitNode(node: TreeNode) {\n switch (node.type) {\n case NodeType.Document:\n for (let i = 0; i < (node as Document).items.length; i++)\n emitNode((node as Document).items[i]);\n break;\n\n case NodeType.Table: {\n const tbl = node as Table;\n emitNode(tbl.key);\n for (let i = 0; i < tbl.items.length; i++) emitNode(tbl.items[i]);\n break;\n }\n case NodeType.TableKey: {\n const tk = node as TableKey;\n // Emit \"[key]\" in one write instead of three (bracket, key, bracket).\n write(lines, tk.loc, '[' + tk.item.raw + ']');\n break;\n }\n\n case NodeType.TableArray: {\n const ta = node as TableArray;\n emitNode(ta.key);\n for (let i = 0; i < ta.items.length; i++) emitNode(ta.items[i]);\n break;\n }\n case NodeType.TableArrayKey: {\n const tak = node as TableArrayKey;\n // Emit \"[[key]]\" in one write instead of three.\n write(lines, tak.loc, '[[' + tak.item.raw + ']]');\n break;\n }\n\n case NodeType.KeyValue: {\n const kv = node as KeyValue;\n const line = kv.loc.start.line;\n writeSingle(lines, line, kv.equals, '=');\n emitNode(kv.key);\n emitNode(kv.value);\n break;\n }\n\n case NodeType.Key:\n write(lines, node.loc, (node as Key).raw);\n break;\n\n case NodeType.String:\n write(lines, node.loc, (node as StringNode).raw);\n break;\n case NodeType.Integer:\n write(lines, node.loc, (node as Integer).raw);\n break;\n case NodeType.Float:\n write(lines, node.loc, (node as Float).raw);\n break;\n case NodeType.Boolean:\n write(lines, node.loc, (node as BooleanNode).value.toString());\n break;\n case NodeType.DateTime:\n write(lines, node.loc, (node as DateTime).raw);\n break;\n\n case NodeType.InlineArray: {\n const ia = node as InlineArray;\n const { start } = ia.loc;\n const closing = closingPosition(ia);\n writeSingle(lines, start.line, start.column, '[');\n writeSingle(lines, closing.line, closing.column, ']');\n for (let i = 0; i < ia.items.length; i++) emitNode(ia.items[i]);\n break;\n }\n case NodeType.InlineTable: {\n const it = node as InlineTable;\n const { start } = it.loc;\n const closing = closingPosition(it);\n writeSingle(lines, start.line, start.column, '{');\n writeSingle(lines, closing.line, closing.column, '}');\n for (let i = 0; i < it.items.length; i++) emitNode(it.items[i]);\n break;\n }\n case NodeType.InlineItem: {\n const ii = node as InlineItem;\n emitNode(ii.item);\n if (ii.comma) {\n const end = ii.loc.end;\n writeSingle(lines, end.line, end.column, ',');\n }\n break;\n }\n\n case NodeType.Comment:\n write(lines, node.loc, (node as Comment).raw);\n break;\n default: {\n // Preserve original behavior: throw on unrecognized node types\n // to catch bugs when new node types are added or invalid nodes appear.\n const type = (node as any).type;\n throw new Error(`toTOML: Unrecognized node type: ${String(type)}`);\n }\n }\n }\n\n // Handle both Document nodes and bare iterables (document.items)\n if (isIterable(cst)) {\n for (const item of cst) emitNode(item as TreeNode);\n } else {\n emitNode(cst as unknown as TreeNode);\n }\n\n // Post-process: convert leading spaces to tabs if useTabsForIndentation is enabled\n if (format.useTabsForIndentation) {\n // Lines belonging to multiline string literals are VALUE content — the\n // indentation there is part of the string and must not be converted\n // (fuzz seed 70). The opening-delimiter line may carry structural\n // indentation, but every line from the first content line through the\n // closing delimiter is untouchable.\n const contentLines = new Set<number>();\n const collectStringLines = (node: TreeNode) => {\n if (node.type === NodeType.String && node.loc.end.line > node.loc.start.line) {\n for (let l = node.loc.start.line + 1; l <= node.loc.end.line; l++) {\n contentLines.add(l);\n }\n }\n if (hasItems(node)) {\n for (const item of node.items as TreeNode[]) collectStringLines(item);\n }\n if (isKeyValue(node)) collectStringLines(node.value);\n if (isInlineItem(node)) collectStringLines(node.item);\n };\n if (isIterable(cst)) {\n for (const item of cst) collectStringLines(item as TreeNode);\n } else {\n collectStringLines(cst as unknown as TreeNode);\n }\n\n for (let i = 0; i < lines.length; i++) {\n if (contentLines.has(i + 1)) continue;\n const line = lines[i];\n // Find the leading whitespace\n const match = line.match(/^( +)/);\n if (match) {\n const leadingSpaces = match[1];\n // Replace entire leading space sequence with equivalent tabs\n // Each space becomes a tab (preserving the visual width)\n const leadingTabs = '\\t'.repeat(leadingSpaces.length);\n lines[i] = leadingTabs + line.substring(leadingSpaces.length);\n }\n }\n }\n\n return lines.join(format.newLine) + format.newLine.repeat(format.trailingNewline);\n}\n\n/**\n * Source-aware emitter used while CST ranges replace coordinate painting.\n * Clean nodes copy their original text. Dirty nodes emit in structural order,\n * so a stale coordinate can add whitespace but cannot overwrite later text.\n */\nexport function toTOMLCursor(cst: CST, format: TomlFormat): string {\n const roots = isIterable(cst)\n ? Array.from(cst as Iterable<TreeNode>)\n : [cst as unknown as TreeNode];\n const chunks: string[] = [];\n const copiedRanges: Array<{ source: string; start: number; end: number }> = [];\n const hostedComments: Comment[] = [];\n const consumedComments = new WeakSet<Comment>();\n let line = 1;\n let column = 0;\n\n const collectComments = (node: TreeNode): void => {\n if (node.type === NodeType.Comment) hostedComments.push(node as Comment);\n if (isKeyValue(node)) collectComments(node.value);\n else if (isInlineItem(node)) collectComments(node.item);\n else if (node.type === NodeType.Table || node.type === NodeType.TableArray) {\n for (const item of (node as Table | TableArray).items) collectComments(item);\n } else if (hasItems(node)) {\n for (const item of node.items as TreeNode[]) collectComments(item);\n }\n };\n for (const root of roots) collectComments(root);\n\n // Inline containers that are direct values of block-level key-values\n // (Document, Table or TableArray). When such a container is emptied, its\n // multiline closing bracket is preserved. Nested containers keep it too when\n // writer.remove() marked them as emptied from an interior row\n // (markPreservedMultilineEmpty); any other emptied container tightens to a\n // single line.\n const blockLevelInlineContainers = new WeakSet<InlineTable | InlineArray>();\n const markBlockLevelInlineContainers = (items: TreeNode[]): void => {\n for (const item of items) {\n if (isKeyValue(item)) {\n const value = item.value;\n if (isInlineTable(value) || isInlineArray(value)) {\n blockLevelInlineContainers.add(value);\n }\n } else if (isTable(item) || isTableArray(item)) {\n markBlockLevelInlineContainers((item as Table | TableArray).items as TreeNode[]);\n }\n }\n };\n markBlockLevelInlineContainers(roots);\n\n const indentation = (width: number): string =>\n (format.useTabsForIndentation ? '\\t' : SPACE).repeat(width);\n\n const append = (text: string): void => {\n if (text.length === 0) return;\n chunks.push(text);\n const parts = text.split(/\\r\\n|\\n/);\n if (parts.length === 1) {\n column += text.length;\n } else {\n line += parts.length - 1;\n column = parts[parts.length - 1].length;\n }\n };\n\n const advanceTo = (targetLine: number, targetColumn: number): void => {\n if (targetLine > line) {\n append(format.newLine.repeat(targetLine - line));\n if (targetColumn > 0) append(indentation(targetColumn));\n } else if (targetLine === line && targetColumn > column) {\n // At the start of a line the gap up to the node is leading indentation,\n // so it must follow the document's tab/spaces preference rather than\n // always padding with spaces (a tab-indented first line would otherwise\n // be re-emitted with a space).\n append(column === 0 ? indentation(targetColumn) : SPACE.repeat(targetColumn - column));\n } else if (chunks.length > 0 &&\n (targetLine < line || (targetLine === line && targetColumn < column))) {\n append(format.newLine);\n if (targetColumn > 0) append(indentation(targetColumn));\n }\n };\n\n const leafText = (node: TreeNode): string | undefined => {\n switch (node.type) {\n case NodeType.Key: return (node as Key).raw;\n case NodeType.String: return (node as StringNode).raw;\n case NodeType.Integer: return (node as Integer).raw;\n case NodeType.Float: return (node as Float).raw;\n case NodeType.Boolean: return (node as BooleanNode).value.toString();\n case NodeType.DateTime: return (node as DateTime).raw;\n case NodeType.Comment: return (node as Comment).raw;\n default: return undefined;\n }\n };\n\n const directChildren = (node: TreeNode): TreeNode[] => {\n if (isKeyValue(node)) return [node.key, node.value];\n if (isInlineItem(node)) return [node.item];\n if (hasItem(node)) return [node.item];\n if (node.type === NodeType.Table || node.type === NodeType.TableArray) {\n const table = node as Table | TableArray;\n return [table.key, ...table.items];\n }\n return hasItems(node) ? node.items as TreeNode[] : [];\n };\n\n const sourceSubtreeReusable = (node: TreeNode): boolean => {\n const pending = [node];\n while (pending.length > 0) {\n const current = pending.pop()!;\n if (current.dirty) return false;\n const text = leafText(current);\n if (text !== undefined) {\n const source = getNodeSource(current);\n if (!source || !current.range || source.slice(current.range[0], current.range[1]) !== text) {\n return false;\n }\n } else if (!sourceStructureUnchanged(current)) {\n return false;\n }\n pending.push(...directChildren(current));\n }\n return true;\n };\n\n const canCopyWholeNode = (node: TreeNode): boolean =>\n node.type !== NodeType.Document &&\n node.type !== NodeType.InlineItem &&\n node.type !== NodeType.TableKey &&\n node.type !== NodeType.TableArrayKey &&\n (leafText(node) !== undefined || sourceStructureUnchanged(node));\n\n const appendRelativeGap = (\n from: { line: number; column: number },\n to: { line: number; column: number },\n absoluteIndent = false\n ): void => {\n if (to.line > from.line) {\n append(format.newLine.repeat(to.line - from.line));\n if (to.column > 0) append(absoluteIndent ? SPACE.repeat(to.column) : indentation(to.column));\n } else if (to.line === from.line && to.column > from.column) {\n append(SPACE.repeat(to.column - from.column));\n }\n };\n\n const sourceGap = (\n container: InlineArray | InlineTable,\n previous: InlineItem | undefined,\n current: InlineItem | undefined\n ): string | undefined => {\n const source = getNodeSource(container);\n if (!source || !container.range) return undefined;\n if (isInlineArray(container) && isGeneratedNestedTableHost(container) &&\n (!current || (previous && !previous.range) || (current && !current.range))) return undefined;\n if (previous && getNodeSource(previous) !== source) return undefined;\n if (current && getNodeSource(current) !== source) return undefined;\n const start = previous?.range?.[1] ?? container.range[0] + 1;\n const end = current?.range?.[0] ?? container.range[1] - 1;\n if (start === undefined || end === undefined || end < start) return undefined;\n\n let gap = source.slice(start, end);\n if (previous?.comma && gap.startsWith(',')) gap = gap.slice(1);\n if (!/^[\\t \\r\\n]*$/.test(gap)) return undefined;\n return gap;\n };\n\n const commentBelongsTo = (comment: Comment, container: InlineArray | InlineTable): boolean => {\n const source = getNodeSource(container);\n return source !== undefined &&\n getNodeSource(comment) === source &&\n container.range !== undefined &&\n comment.range !== undefined &&\n comment.range[0] >= container.range[0] &&\n comment.range[1] <= container.range[1];\n };\n\n const emitInlineItems = (container: InlineArray | InlineTable): void => {\n const generatedMultilineTable = isInlineTable(container) && isGeneratedNestedTable(container);\n let previous: InlineItem | undefined;\n for (const current of container.items as InlineItem[]) {\n let from = previous\n ? {\n line: previous.loc.end.line,\n column: previous.loc.end.column + (previous.comma ? 1 : 0)\n }\n : {\n line: container.loc.start.line,\n column: container.loc.start.column + 1\n };\n const commentsBefore = hostedComments\n .filter(comment => !consumedComments.has(comment) && commentBelongsTo(comment, container) &&\n comment.loc.start.line >= from.line &&\n comment.loc.end.line <= current.loc.start.line &&\n (comment.loc.start.line > from.line || comment.loc.start.column >= from.column) &&\n (comment.loc.end.line < current.loc.start.line || comment.loc.end.column <= current.loc.start.column) &&\n comment.loc.start.line >= container.loc.start.line &&\n comment.loc.end.line <= container.loc.end.line)\n .sort((left, right) =>\n left.loc.start.line - right.loc.start.line ||\n left.loc.start.column - right.loc.start.column);\n\n if (commentsBefore.length > 0) {\n for (const comment of commentsBefore) {\n appendRelativeGap(from, comment.loc.start);\n append(comment.raw);\n consumedComments.add(comment);\n from = comment.loc.end;\n }\n appendRelativeGap(from, current.loc.start);\n } else {\n const gap = sourceGap(container, previous, current);\n if (gap !== undefined) {\n append(gap);\n } else {\n const crossSource = getNodeSource(current) !== getNodeSource(container);\n if (previous && crossSource && current.loc.start.line === previous.loc.end.line) {\n const commaGap = getCommaSpace(container) ?? 2;\n const wantedSpaces = Math.max(0, commaGap - 1);\n if (wantedSpaces > 0) append(SPACE.repeat(wantedSpaces));\n } else {\n appendRelativeGap(from, current.loc.start, generatedMultilineTable);\n }\n }\n }\n emitNode(current, false);\n for (const comment of hostedComments) {\n if (consumedComments.has(comment)) continue;\n if (!commentBelongsTo(comment, container)) continue;\n if (comment.loc.start.line !== current.loc.end.line) continue;\n if (comment.loc.start.column < current.loc.end.column) continue;\n if (comment.loc.start.line < container.loc.start.line ||\n comment.loc.end.line > container.loc.end.line) continue;\n const separatorEnd = current.loc.end.column + (current.comma ? 1 : 0);\n if (comment.loc.start.column > separatorEnd) {\n append(SPACE.repeat(comment.loc.start.column - separatorEnd));\n }\n append(comment.raw);\n consumedComments.add(comment);\n }\n previous = current;\n }\n\n let trailingFrom = previous\n ? {\n line: previous.loc.end.line,\n column: previous.loc.end.column + (previous.comma ? 1 : 0)\n }\n : { line: container.loc.start.line, column: container.loc.start.column + 1 };\n const trailingComments = hostedComments\n .filter(comment => !consumedComments.has(comment) && commentBelongsTo(comment, container) &&\n comment.loc.start.line >= trailingFrom.line &&\n comment.loc.end.line <= container.loc.end.line)\n .sort((left, right) =>\n left.loc.start.line - right.loc.start.line ||\n left.loc.start.column - right.loc.start.column);\n if (trailingComments.length > 0) {\n for (const comment of trailingComments) {\n appendRelativeGap(trailingFrom, comment.loc.start);\n append(comment.raw);\n consumedComments.add(comment);\n trailingFrom = comment.loc.end;\n }\n appendRelativeGap(trailingFrom, {\n line: container.loc.end.line,\n column: container.loc.end.column - 1\n });\n } else {\n const trailingGap = sourceGap(container, previous, undefined);\n if (trailingGap !== undefined) append(trailingGap);\n else if (previous) {\n if (generatedMultilineTable && previous.comma) append(SPACE);\n appendRelativeGap(trailingFrom, {\n line: container.loc.end.line,\n column: container.loc.end.column - 1\n }, generatedMultilineTable);\n }\n else {\n const source = getNodeSource(container);\n if (source && container.range) {\n const original = source.slice(container.range[0], container.range[1]);\n const lastNewline = Math.max(original.lastIndexOf('\\n'), original.lastIndexOf('\\r'));\n const keepClosingRow = blockLevelInlineContainers.has(container) ||\n isPreservedMultilineEmpty(container);\n if (lastNewline !== -1 && keepClosingRow && originalFirstChildStartedAfterOpener(container)) {\n const closingIndent = original.slice(lastNewline + 1, -1).match(/^[\\t ]*/)?.[0] ?? '';\n append(format.newLine + closingIndent);\n }\n }\n }\n }\n };\n\n const emitNode = (node: TreeNode, place = true): void => {\n if (node.type === NodeType.Comment && consumedComments.has(node as Comment)) return;\n const source = getNodeSource(node);\n if (source !== undefined && node.range && copiedRanges.some(copied =>\n copied.source === source && copied.start <= node.range![0] && copied.end >= node.range![1]\n )) {\n return;\n }\n if (canCopyWholeNode(node) && sourceSubtreeReusable(node) && node.range && source !== undefined) {\n const slice = source.slice(node.range[0], node.range[1]);\n const expectedLeaf = leafText(node);\n if (expectedLeaf === undefined || expectedLeaf === slice) {\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append(slice);\n copiedRanges.push({ source, start: node.range[0], end: node.range[1] });\n return;\n }\n }\n\n switch (node.type) {\n case NodeType.Document:\n for (const item of (node as Document).items) emitNode(item);\n break;\n case NodeType.Table: {\n const table = node as Table;\n emitNode(table.key, place);\n for (const item of table.items) emitNode(item);\n break;\n }\n case NodeType.TableKey: {\n const tableKey = node as TableKey;\n if (place) advanceTo(tableKey.loc.start.line, tableKey.loc.start.column);\n append(`[${tableKey.item.raw}]`);\n break;\n }\n case NodeType.TableArray: {\n const tableArray = node as TableArray;\n emitNode(tableArray.key, place);\n for (const item of tableArray.items) emitNode(item);\n break;\n }\n case NodeType.TableArrayKey: {\n const tableArrayKey = node as TableArrayKey;\n if (place) advanceTo(tableArrayKey.loc.start.line, tableArrayKey.loc.start.column);\n append(`[[${tableArrayKey.item.raw}]]`);\n break;\n }\n case NodeType.KeyValue: {\n const keyValue = node as KeyValue;\n if (place) advanceTo(keyValue.loc.start.line, keyValue.loc.start.column);\n emitNode(keyValue.key, false);\n appendRelativeGap(keyValue.key.loc.end, {\n line: keyValue.loc.start.line,\n column: keyValue.equals\n });\n append('=');\n appendRelativeGap({ line: keyValue.loc.start.line, column: keyValue.equals + 1 }, keyValue.value.loc.start);\n emitNode(keyValue.value, false);\n break;\n }\n case NodeType.Key:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as Key).raw);\n break;\n case NodeType.String:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as StringNode).raw);\n break;\n case NodeType.Integer:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as Integer).raw);\n break;\n case NodeType.Float:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as Float).raw);\n break;\n case NodeType.Boolean:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as BooleanNode).value.toString());\n break;\n case NodeType.DateTime:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as DateTime).raw);\n break;\n case NodeType.InlineArray: {\n const array = node as InlineArray;\n if (place) advanceTo(array.loc.start.line, array.loc.start.column);\n append('[');\n emitInlineItems(array);\n append(']');\n break;\n }\n case NodeType.InlineTable: {\n const table = node as InlineTable;\n if (place) advanceTo(table.loc.start.line, table.loc.start.column);\n append('{');\n emitInlineItems(table);\n append('}');\n break;\n }\n case NodeType.InlineItem: {\n const item = node as InlineItem;\n emitNode(item.item, false);\n if (item.comma) {\n const source = getNodeSource(item);\n if (source && item.range && item.item.range && getNodeSource(item.item) === source) {\n const beforeComma = source.slice(item.item.range[1], item.range[1]);\n if (/^[\\t ]*$/.test(beforeComma)) append(beforeComma);\n }\n append(',');\n }\n break;\n }\n case NodeType.Comment:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as Comment).raw);\n break;\n default:\n throw new Error(`toTOMLCursor: Unrecognized node type: ${String((node as any).type)}`);\n }\n };\n\n for (const root of roots) emitNode(root);\n\n const output = chunks.join('').replace(/\\r\\n|\\n/g, format.newLine);\n return output + format.newLine.repeat(format.trailingNewline);\n}\n\n/**\n * Writes raw string content to specific location coordinates within a lines array.\n * \n * This function is responsible for placing TOML content at precise positions within\n * the output lines, handling multi-line content and preserving existing content\n * around the target location.\n * \n * @param lines - Array of string lines representing the TOML document being built.\n * Lines are 1-indexed but stored in 0-indexed array.\n * @param loc - Location object specifying where to write the content, containing:\n * - start: { line: number, column: number } - Starting position (1-indexed line, 0-indexed column)\n * - end: { line: number, column: number } - Ending position (1-indexed line, 0-indexed column)\n * @param raw - The raw string content to write at the specified location.\n * Can contain multiple lines separated by \\n or \\r\\n.\n * \n * @throws {Error} When there's a mismatch between location span and raw string line count\n * @throws {Error} When attempting to write to an uninitialized line\n * \n * @example\n * ```typescript\n * const lines = ['', ''];\n * const location = { start: { line: 1, column: 0 }, end: { line: 1, column: 3 } };\n * write(lines, location, 'key');\n * // Result: lines[0] becomes 'key'\n * ```\n */\nfunction write(lines: string[], loc: Location, raw: string) {\n // Fast path for single-line content (the vast majority of nodes).\n // Avoids the regex split + filter that allocates two temporary arrays.\n if (loc.start.line === loc.end.line) {\n const line = getLine(lines, loc.start.line);\n\n const existingBefore = line.substring(0, loc.start.column);\n const before = existingBefore.length < loc.start.column\n ? existingBefore.padEnd(loc.start.column, SPACE)\n : existingBefore;\n const after = line.substring(loc.end.column);\n\n lines[loc.start.line - 1] = before + raw + after;\n return;\n }\n\n // Multi-line path: split and filter newline separators\n const raw_lines = raw.split(BY_NEW_LINE).filter(line => line !== '\\n' && line !== '\\r\\n');\n const expected_lines = loc.end.line - loc.start.line + 1;\n\n if (raw_lines.length !== expected_lines) {\n throw new Error(\n `Mismatch between location and raw string, expected ${expected_lines} lines for \"${raw}\"`\n );\n }\n\n for (let i = loc.start.line; i <= loc.end.line; i++) {\n const line = getLine(lines, i);\n\n const is_start_line = i === loc.start.line;\n const is_end_line = i === loc.end.line;\n\n let before = '';\n if (is_start_line) {\n const existingBefore = line.substring(0, loc.start.column);\n if (existingBefore.length < loc.start.column) {\n // Need to pad - always use spaces during write phase\n // Tab conversion happens in post-processing for leading indentation only\n before = existingBefore.padEnd(loc.start.column, SPACE);\n } else {\n before = existingBefore;\n }\n }\n const after = is_end_line ? line.substring(loc.end.column) : '';\n\n lines[i - 1] = before + raw_lines[i - loc.start.line] + after;\n }\n}\n\n/**\n * Fast path for writing a single character at a specific position.\n * Avoids creating temporary Location objects.\n */\nfunction writeSingle(lines: string[], lineNum: number, column: number, char: string) {\n const line = getLine(lines, lineNum);\n const before = line.length < column\n ? line.padEnd(column, SPACE)\n : line.substring(0, column);\n const after = line.substring(column + 1);\n lines[lineNum - 1] = before + char + after;\n}\n\n/**\n * Safely retrieves a line from the lines array, initializing empty lines as needed.\n * \n * This helper function handles the conversion between 1-indexed line numbers (used in locations)\n * and 0-indexed array positions. It ensures that accessing a line that doesn't exist yet\n * will initialize all preceding lines with empty strings.\n * \n * @param lines - Array of string lines representing the document\n * @param index - 1-indexed line number to retrieve\n * @returns The line content as a string, or empty string for new lines\n * \n * @example\n * ```typescript\n * const lines = ['first line'];\n * const line = getLine(lines, 3); // Initializes lines[1] and lines[2] as empty strings\n * // lines becomes ['first line', '', '']\n * ```\n */\nfunction getLine(lines: string[], index: number): string {\n if (!lines[index - 1]) {\n for (let i = 0; i < index; i++) {\n if (!lines[i]) lines[i] = '';\n }\n }\n\n return lines[index - 1];\n}\n"],"mappings":";;;;;;;;AAyCA,MAAM,cAAc;;;;;;;;;;;;;;;;;AAkBpB,SAAwB,OAAO,KAAU,QAA4B;CAEnE,MAAM,QAAkB,CAAC;CAIzB,MAAM,mBAAmB,cAA2E;EAClG,MAAM,WAAW;GACf,MAAM,UAAU,IAAI,IAAI;GACxB,QAAQ,UAAU,IAAI,IAAI,SAAS;EACrC;EACA,MAAM,OAAO,UAAU,MAAM,UAAU,MAAM,SAAS;EACtD,IAAI,SAAS,KAAK,IAAI,IAAI,OAAO,SAAS,QACrC,KAAK,IAAI,IAAI,SAAS,SAAS,QAAQ,KAAK,IAAI,IAAI,SAAS,SAAS,SAAU;GACnF,SAAS,OAAO,KAAK,IAAI,IAAI;GAC7B,SAAS,SAAS,KAAK,IAAI,IAAI,UAAU,KAAK,QAAQ,IAAI;EAC5D;EACA,OAAO;CACT;CAEA,SAAS,SAAS,MAAgB;EAChC,QAAQ,KAAK,MAAb;GACE;IACE,KAAK,IAAI,IAAI,GAAG,IAAK,KAAkB,MAAM,QAAQ,KACnD,SAAU,KAAkB,MAAM,EAAE;IACtC;GAEF,cAAqB;IACnB,MAAM,MAAM;IACZ,SAAS,IAAI,GAAG;IAChB,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,MAAM,QAAQ,KAAK,SAAS,IAAI,MAAM,EAAE;IAChE;GACF;GACA,iBAAwB;IACtB,MAAM,KAAK;IAEX,MAAM,OAAO,GAAG,KAAK,MAAM,GAAG,KAAK,MAAM,GAAG;IAC5C;GACF;GA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