@decimalturn/toml-patch 3.3.0 → 3.3.1-dev
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/dev/comment-alignment.js +372 -0
- package/dist/dev/comment-alignment.js.map +1 -0
- package/dist/dev/comment-ownership.js +660 -0
- package/dist/dev/comment-ownership.js.map +1 -0
- package/dist/dev/cst-source.js +118 -0
- package/dist/dev/cst-source.js.map +1 -0
- package/dist/dev/cst.js +68 -0
- package/dist/dev/cst.js.map +1 -0
- package/dist/dev/cursor.js +66 -0
- package/dist/dev/cursor.js.map +1 -0
- package/dist/dev/date-format.js +287 -0
- package/dist/dev/date-format.js.map +1 -0
- package/dist/dev/decode-utf8.js +27 -0
- package/dist/dev/decode-utf8.js.map +1 -0
- package/dist/dev/diff-lite.js +108 -0
- package/dist/dev/diff-lite.js.map +1 -0
- package/dist/dev/diff.js +265 -0
- package/dist/dev/diff.js.map +1 -0
- package/dist/dev/encode-lite.js +210 -0
- package/dist/dev/encode-lite.js.map +1 -0
- package/dist/dev/escape-preference.js +166 -0
- package/dist/dev/escape-preference.js.map +1 -0
- package/dist/dev/find-by-path.js +111 -0
- package/dist/dev/find-by-path.js.map +1 -0
- package/dist/dev/formatter.js +298 -0
- package/dist/dev/formatter.js.map +1 -0
- package/dist/dev/generate.js +466 -0
- package/dist/dev/generate.js.map +1 -0
- package/dist/dev/inline-comma-space.js +13 -0
- package/dist/dev/inline-comma-space.js.map +1 -0
- package/dist/dev/inline-format.js +106 -0
- package/dist/dev/inline-format.js.map +1 -0
- package/dist/dev/inline-layout.js +107 -0
- package/dist/dev/inline-layout.js.map +1 -0
- package/dist/dev/line-ending-backslash.js +320 -0
- package/dist/dev/line-ending-backslash.js.map +1 -0
- package/dist/dev/literal-string.js +46 -0
- package/dist/dev/literal-string.js.map +1 -0
- package/dist/dev/location.js +104 -0
- package/dist/dev/location.js.map +1 -0
- package/dist/dev/parse-error.js +27 -0
- package/dist/dev/parse-error.js.map +1 -0
- package/dist/dev/parse-js.js +150 -0
- package/dist/dev/parse-js.js.map +1 -0
- package/dist/dev/parse-string.js +120 -0
- package/dist/dev/parse-string.js.map +1 -0
- package/dist/dev/parse-toml.js +714 -0
- package/dist/dev/parse-toml.js.map +1 -0
- package/dist/dev/patch-lite.js +4 -0
- package/dist/dev/patch-lite2.js +97 -0
- package/dist/dev/patch-lite2.js.map +1 -0
- package/dist/dev/patch.js +2659 -0
- package/dist/dev/patch.js.map +1 -0
- package/dist/dev/smol-toml-date.js +61 -0
- package/dist/dev/smol-toml-date.js.map +1 -0
- package/dist/dev/to-js.js +303 -0
- package/dist/dev/to-js.js.map +1 -0
- package/dist/dev/to-toml.js +874 -0
- package/dist/dev/to-toml.js.map +1 -0
- package/dist/dev/tokenizer.js +225 -0
- package/dist/dev/tokenizer.js.map +1 -0
- package/dist/dev/toml-document.js +220 -0
- package/dist/dev/toml-document.js.map +1 -0
- package/dist/dev/toml-format.js +549 -0
- package/dist/dev/toml-format.js.map +1 -0
- package/dist/dev/toml-patch.js +94 -0
- package/dist/dev/toml-patch.js.map +1 -0
- package/dist/dev/traverse.js +61 -0
- package/dist/dev/traverse.js.map +1 -0
- package/dist/dev/truncate.js +64 -0
- package/dist/dev/truncate.js.map +1 -0
- package/dist/dev/update-order.js +235 -0
- package/dist/dev/update-order.js.map +1 -0
- package/dist/dev/utils.js +302 -0
- package/dist/dev/utils.js.map +1 -0
- package/dist/dev/writer.js +758 -0
- package/dist/dev/writer.js.map +1 -0
- package/dist/patch-lite.d.ts +18 -0
- package/package.json +16 -103
- package/LICENSE +0 -22
- package/README.md +0 -203
- package/dist/toml-patch.js +0 -84
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
//! @decimalturn/toml-patch v3.3.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
|
|
2
|
+
import { hasItems, isComment, isInlineArray, isInlineItem, isInlineTable, isKeyValue, isTable, isTableArray } from "./cst.js";
|
|
3
|
+
import { getSpan } from "./location.js";
|
|
4
|
+
|
|
5
|
+
//#region src/comment-alignment.ts
|
|
6
|
+
/**
|
|
7
|
+
* @file Comment alignment helpers for the patch pipeline.
|
|
8
|
+
* @module comment-alignment
|
|
9
|
+
*
|
|
10
|
+
* Utilities for preserving and normalizing aligned inline comments during patching.
|
|
11
|
+
*
|
|
12
|
+
* This module owns the comment-column logic used by the patch pipeline:
|
|
13
|
+
* it detects whether an inline comment belongs to an aligned group, preserves
|
|
14
|
+
* that alignment when edits change value width, compensates for inline insert
|
|
15
|
+
* width deltas, and performs a final string-level normalization pass for padded
|
|
16
|
+
* aligned comment blocks.
|
|
17
|
+
*/
|
|
18
|
+
const reserved_comment_spacing = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
const original_comment_column = /* @__PURE__ */ new WeakMap();
|
|
20
|
+
/**
|
|
21
|
+
* Returns the inline comment attached to the item at the given index.
|
|
22
|
+
*
|
|
23
|
+
* An attached inline comment is the first comment that starts on the same line
|
|
24
|
+
* as the item's end position, before any later non-comment row begins.
|
|
25
|
+
*
|
|
26
|
+
* @param items Container items to inspect.
|
|
27
|
+
* @param index Index of the row whose trailing comment should be resolved.
|
|
28
|
+
* @returns The attached inline comment, if present.
|
|
29
|
+
*/
|
|
30
|
+
function getAttachedInlineComment(items, index) {
|
|
31
|
+
const commentLine = items[index].loc.end.line;
|
|
32
|
+
for (let i = index + 1; i < items.length; i++) {
|
|
33
|
+
const candidate = items[i];
|
|
34
|
+
if (isComment(candidate) && candidate.loc.start.line === commentLine) return candidate;
|
|
35
|
+
if (!isComment(candidate) && candidate.loc.start.line > commentLine) return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Finds the nearest non-comment row index in the requested direction.
|
|
40
|
+
*
|
|
41
|
+
* @param items Container items to scan.
|
|
42
|
+
* @param index Starting row index.
|
|
43
|
+
* @param direction Scan direction: `-1` for upward, `1` for downward.
|
|
44
|
+
* @returns The nearest neighboring row index, if one exists.
|
|
45
|
+
*/
|
|
46
|
+
function getNeighborRowIndex(items, index, direction) {
|
|
47
|
+
for (let i = index + direction; i >= 0 && i < items.length; i += direction) if (!isComment(items[i])) return i;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Repositions an inline comment to keep it aligned after a width change.
|
|
51
|
+
*
|
|
52
|
+
* @param comment Comment node to adjust.
|
|
53
|
+
* @param targetColumn Desired aligned column for the comment start.
|
|
54
|
+
* @param deltaColumns Horizontal width delta introduced by the edit.
|
|
55
|
+
*/
|
|
56
|
+
function applyInlineCommentColumnAdjustment(comment, targetColumn, deltaColumns) {
|
|
57
|
+
if (!original_comment_column.has(comment)) original_comment_column.set(comment, comment.loc.start.column);
|
|
58
|
+
const shiftedColumn = comment.loc.start.column + deltaColumns;
|
|
59
|
+
const adjustment = Math.max(targetColumn, shiftedColumn) - shiftedColumn;
|
|
60
|
+
if (adjustment !== 0) {
|
|
61
|
+
comment.loc.start.column += adjustment;
|
|
62
|
+
comment.loc.end.column += adjustment;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Stores the current minimum spacing between a row and its trailing comment.
|
|
67
|
+
*
|
|
68
|
+
* This data is refreshed each time it is observed so reused CST comment nodes
|
|
69
|
+
* do not retain stale spacing or column values from a previous patch run.
|
|
70
|
+
*
|
|
71
|
+
* @param row Key-value row that owns the trailing comment.
|
|
72
|
+
* @param comment Trailing inline comment attached to the row.
|
|
73
|
+
*/
|
|
74
|
+
function rememberReservedCommentSpacing(row, comment) {
|
|
75
|
+
original_comment_column.set(comment, comment.loc.start.column);
|
|
76
|
+
reserved_comment_spacing.set(comment, comment.loc.start.column - row.loc.end.column);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Preserves an aligned trailing inline comment when the row's value node is
|
|
80
|
+
* being replaced by another value node.
|
|
81
|
+
*
|
|
82
|
+
* Use this in edit flows where the patch operation has both the old value and
|
|
83
|
+
* the new value available, for example when `a = "x" # note` becomes
|
|
84
|
+
* `a = "much longer text" # note`. The function computes the width delta from
|
|
85
|
+
* `existingValue` and `replacementValue`, then repositions the same-line
|
|
86
|
+
* comment so it stays aligned with the adjacent rows that were already aligned
|
|
87
|
+
* before the edit.
|
|
88
|
+
*
|
|
89
|
+
* In short:
|
|
90
|
+
* - `preserveAlignedInlineCommentColumn` is for replacement edits
|
|
91
|
+
* - it derives `deltaColumns` itself from the old and new value spans
|
|
92
|
+
*
|
|
93
|
+
* The comment is adjusted only when the current row already belongs to a
|
|
94
|
+
* vertically aligned comment group with an immediately adjacent row above or
|
|
95
|
+
* below, and both old and new values are single-line.
|
|
96
|
+
*
|
|
97
|
+
* @param container Parent container that owns the row.
|
|
98
|
+
* @param row Key-value row being edited.
|
|
99
|
+
* @param existingValue Original value before replacement.
|
|
100
|
+
* @param replacementValue Replacement value after editing.
|
|
101
|
+
*/
|
|
102
|
+
function preserveAlignedInlineCommentColumn(container, row, existingValue, replacementValue) {
|
|
103
|
+
if (!hasItems(container)) return;
|
|
104
|
+
const items = container.items;
|
|
105
|
+
const rowIndex = items.indexOf(row);
|
|
106
|
+
if (rowIndex < 0) return;
|
|
107
|
+
const comment = getAttachedInlineComment(items, rowIndex);
|
|
108
|
+
if (!comment) return;
|
|
109
|
+
if (existingValue.loc.start.line !== existingValue.loc.end.line) return;
|
|
110
|
+
if (replacementValue.loc.start.line !== replacementValue.loc.end.line) return;
|
|
111
|
+
const currentColumn = comment.loc.start.column;
|
|
112
|
+
const currentLine = comment.loc.start.line;
|
|
113
|
+
const neighborIndexes = [getNeighborRowIndex(items, rowIndex, -1), getNeighborRowIndex(items, rowIndex, 1)];
|
|
114
|
+
let alignedColumn;
|
|
115
|
+
for (const neighborIndex of neighborIndexes) {
|
|
116
|
+
if (neighborIndex == null) continue;
|
|
117
|
+
const neighborComment = getAttachedInlineComment(items, neighborIndex);
|
|
118
|
+
if (!neighborComment) continue;
|
|
119
|
+
if (Math.abs(neighborComment.loc.start.line - currentLine) !== 1) continue;
|
|
120
|
+
if (neighborComment.loc.start.column !== currentColumn) continue;
|
|
121
|
+
alignedColumn = neighborComment.loc.start.column;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
if (alignedColumn == null) return;
|
|
125
|
+
const existingSpan = getSpan(existingValue.loc);
|
|
126
|
+
const deltaColumns = getSpan(replacementValue.loc).columns - existingSpan.columns;
|
|
127
|
+
applyInlineCommentColumnAdjustment(comment, alignedColumn, deltaColumns);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Preserves an aligned trailing inline comment when the row gets wider because
|
|
131
|
+
* content was inserted inside an inline container, but the row value node
|
|
132
|
+
* itself was not replaced.
|
|
133
|
+
*
|
|
134
|
+
* Use this in add/insert flows where the caller already knows the rendered
|
|
135
|
+
* width change, for example when inserting a new element into an inline array
|
|
136
|
+
* on a row like `a = [1, 2] # note`. In that case there is no old-vs-new row
|
|
137
|
+
* value pair available here, so the caller passes the precomputed
|
|
138
|
+
* `deltaColumns` directly.
|
|
139
|
+
*
|
|
140
|
+
* In short:
|
|
141
|
+
* - `preserveAlignedInlineCommentForDelta` is for insertion-driven width shifts
|
|
142
|
+
* - it consumes a precomputed `deltaColumns` instead of comparing two value nodes
|
|
143
|
+
*
|
|
144
|
+
* @param container Parent container that owns the row.
|
|
145
|
+
* @param row Key-value row whose trailing comment may need to move.
|
|
146
|
+
* @param deltaColumns Horizontal width delta introduced by the insertion.
|
|
147
|
+
*/
|
|
148
|
+
function preserveAlignedInlineCommentForDelta(container, row, deltaColumns) {
|
|
149
|
+
if (!hasItems(container)) return;
|
|
150
|
+
const items = container.items;
|
|
151
|
+
const rowIndex = items.indexOf(row);
|
|
152
|
+
if (rowIndex < 0) return;
|
|
153
|
+
const comment = getAttachedInlineComment(items, rowIndex);
|
|
154
|
+
if (!comment) return;
|
|
155
|
+
const currentColumn = comment.loc.start.column;
|
|
156
|
+
const currentLine = comment.loc.start.line;
|
|
157
|
+
const neighborIndexes = [getNeighborRowIndex(items, rowIndex, -1), getNeighborRowIndex(items, rowIndex, 1)];
|
|
158
|
+
for (const neighborIndex of neighborIndexes) {
|
|
159
|
+
if (neighborIndex == null) continue;
|
|
160
|
+
const neighborComment = getAttachedInlineComment(items, neighborIndex);
|
|
161
|
+
if (!neighborComment) continue;
|
|
162
|
+
if (Math.abs(neighborComment.loc.start.line - currentLine) !== 1) continue;
|
|
163
|
+
if (neighborComment.loc.start.column !== currentColumn) continue;
|
|
164
|
+
applyInlineCommentColumnAdjustment(comment, neighborComment.loc.start.column, deltaColumns);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Records baseline comment alignment metadata for a row whose value is a
|
|
170
|
+
* single-line inline table and whose internal contents are being edited.
|
|
171
|
+
*
|
|
172
|
+
* This captures the comment's current column and reserved gap (comment start
|
|
173
|
+
* minus row end) so the final normalization pass can preserve spacing
|
|
174
|
+
* expectations after nested inline-table edits.
|
|
175
|
+
*
|
|
176
|
+
* @param container Parent container that owns the row.
|
|
177
|
+
* @param row Key-value row whose trailing comment alignment metadata is refreshed.
|
|
178
|
+
* @param deltaColumns Horizontal width delta introduced by the nested edit; used
|
|
179
|
+
* only as a fast no-op guard when zero.
|
|
180
|
+
*/
|
|
181
|
+
function recordInlineTableCommentDelta(container, row, deltaColumns) {
|
|
182
|
+
if (!hasItems(container) || deltaColumns === 0) return;
|
|
183
|
+
const items = container.items;
|
|
184
|
+
const rowIndex = items.indexOf(row);
|
|
185
|
+
if (rowIndex < 0) return;
|
|
186
|
+
const comment = getAttachedInlineComment(items, rowIndex);
|
|
187
|
+
if (!comment) return;
|
|
188
|
+
rememberReservedCommentSpacing(row, comment);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Estimates the horizontal column delta caused by inserting a new inline item.
|
|
192
|
+
*
|
|
193
|
+
* The result includes the inserted value width and the comma/spacing overhead
|
|
194
|
+
* needed by the surrounding inline array or inline table formatting.
|
|
195
|
+
*
|
|
196
|
+
* @param parent Inline container receiving the new child.
|
|
197
|
+
* @param child CST node being inserted.
|
|
198
|
+
* @param index Target insertion index.
|
|
199
|
+
* @returns The number of columns added to the rendered row.
|
|
200
|
+
*/
|
|
201
|
+
function getInlineInsertColumnDelta(parent, child, index) {
|
|
202
|
+
if (!isInlineArray(parent) && !isInlineTable(parent)) return 0;
|
|
203
|
+
const childSpan = getSpan(child.loc);
|
|
204
|
+
const hasSeparatingCommaBefore = index > 0;
|
|
205
|
+
const hasSeparatingCommaAfter = index < parent.items.length;
|
|
206
|
+
const isLastElement = index === parent.items.length;
|
|
207
|
+
const hasTrailingComma = isInlineItem(child) ? child.comma : false;
|
|
208
|
+
const hasTrailingCommaSpacingBug = hasSeparatingCommaBefore && hasTrailingComma && !hasSeparatingCommaAfter && isLastElement;
|
|
209
|
+
return childSpan.columns + (hasSeparatingCommaBefore || hasSeparatingCommaAfter ? 2 : 0) + (hasTrailingComma ? 1 + (hasTrailingCommaSpacingBug ? -1 : 0) : 0);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Recursively collects comment nodes from the document and nested tables.
|
|
213
|
+
*
|
|
214
|
+
* @param node Document or table-like node to traverse.
|
|
215
|
+
* @param comments Accumulator used during recursion.
|
|
216
|
+
* @returns All discovered comment nodes.
|
|
217
|
+
*/
|
|
218
|
+
function collectComments(node, comments = []) {
|
|
219
|
+
for (const item of node.items) {
|
|
220
|
+
if (isComment(item)) {
|
|
221
|
+
comments.push(item);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (isTable(item) || isTableArray(item)) collectComments(item, comments);
|
|
225
|
+
}
|
|
226
|
+
return comments;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Collects the line numbers of single-line key-value rows whose value is a
|
|
230
|
+
* single-line inline table.
|
|
231
|
+
*
|
|
232
|
+
* @param node Document or table-like node to traverse.
|
|
233
|
+
* @param lines Accumulator used during recursion.
|
|
234
|
+
* @returns A set of row end lines for inline-table rows.
|
|
235
|
+
*/
|
|
236
|
+
function collectSingleLineInlineTableCommentLines(node, lines = /* @__PURE__ */ new Set()) {
|
|
237
|
+
for (const item of node.items) {
|
|
238
|
+
if (isKeyValue(item) && isInlineTable(item.value) && item.loc.start.line === item.loc.end.line) {
|
|
239
|
+
lines.add(item.loc.end.line);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (isTable(item) || isTableArray(item)) collectSingleLineInlineTableCommentLines(item, lines);
|
|
243
|
+
}
|
|
244
|
+
return lines;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Recomputes `loc.end` for the document/table container chain from children.
|
|
248
|
+
*
|
|
249
|
+
* Inline comment normalization can move trailing comments horizontally; this
|
|
250
|
+
* keeps parent containers' end positions consistent with their updated children.
|
|
251
|
+
*
|
|
252
|
+
* @param node Document or table-like container to normalize.
|
|
253
|
+
*/
|
|
254
|
+
function recomputeContainerEnds(node) {
|
|
255
|
+
for (const item of node.items) if (isTable(item) || isTableArray(item)) recomputeContainerEnds(item);
|
|
256
|
+
let maxLine = node.loc.end.line;
|
|
257
|
+
let maxColumn = node.loc.end.column;
|
|
258
|
+
const updateMax = (line, column) => {
|
|
259
|
+
if (line > maxLine || line === maxLine && column > maxColumn) {
|
|
260
|
+
maxLine = line;
|
|
261
|
+
maxColumn = column;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
if (isTable(node) || isTableArray(node)) updateMax(node.key.loc.end.line, node.key.loc.end.column);
|
|
265
|
+
for (const item of node.items) updateMax(item.loc.end.line, item.loc.end.column);
|
|
266
|
+
node.loc.end.line = maxLine;
|
|
267
|
+
node.loc.end.column = maxColumn;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Normalizes padded inline comment groups in the final rendered TOML string.
|
|
271
|
+
*
|
|
272
|
+
* This pass is intentionally limited to comments that already have explicit
|
|
273
|
+
* padding before `#`, which avoids disturbing compact TOML 1.1 inline-table
|
|
274
|
+
* comment styles while still restoring vertical alignment for normal row-based
|
|
275
|
+
* comment blocks.
|
|
276
|
+
*
|
|
277
|
+
* For groups touched by nested inline-table edits, the target column is derived
|
|
278
|
+
* from the widest current row plus the group's original minimum reserved gap.
|
|
279
|
+
*
|
|
280
|
+
* @param document Patched CST document whose comment locations are updated in-place.
|
|
281
|
+
* @param tomlString Rendered TOML output to normalize.
|
|
282
|
+
* @param format Active TOML formatting settings.
|
|
283
|
+
* @returns The normalized TOML string.
|
|
284
|
+
*/
|
|
285
|
+
function normalizeInlineCommentAlignmentInString(document, tomlString, format) {
|
|
286
|
+
const newLine = format.newLine;
|
|
287
|
+
const trailingMatch = tomlString.match(/(?:\r\n|\n)+$/u);
|
|
288
|
+
const trailing = trailingMatch ? trailingMatch[0] : "";
|
|
289
|
+
const body = trailing ? tomlString.slice(0, -trailing.length) : tomlString;
|
|
290
|
+
const lines = body.length ? body.split(newLine) : [];
|
|
291
|
+
const inlineTableCommentLines = collectSingleLineInlineTableCommentLines(document);
|
|
292
|
+
const resolveCommentColumn = (line, comment) => {
|
|
293
|
+
const fromLine = line.lastIndexOf(comment.raw);
|
|
294
|
+
return fromLine >= 0 ? fromLine : comment.loc.start.column;
|
|
295
|
+
};
|
|
296
|
+
const comments = collectComments(document).filter((comment) => {
|
|
297
|
+
const line = lines[comment.loc.start.line - 1] || "";
|
|
298
|
+
const commentColumn = resolveCommentColumn(line, comment);
|
|
299
|
+
const beforeComment = line.slice(0, commentColumn);
|
|
300
|
+
return beforeComment.trim().length > 0 && /\s{2,}$/u.test(beforeComment);
|
|
301
|
+
}).sort((a, b) => a.loc.start.line - b.loc.start.line);
|
|
302
|
+
const groups = [];
|
|
303
|
+
let currentGroup = [];
|
|
304
|
+
for (const comment of comments) {
|
|
305
|
+
const previous = currentGroup[currentGroup.length - 1];
|
|
306
|
+
if (!previous || comment.loc.start.line === previous.loc.start.line + 1) currentGroup.push(comment);
|
|
307
|
+
else {
|
|
308
|
+
if (currentGroup.length > 0) groups.push(currentGroup);
|
|
309
|
+
currentGroup = [comment];
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (currentGroup.length > 0) groups.push(currentGroup);
|
|
313
|
+
for (const group of groups) {
|
|
314
|
+
if (group.length < 2) continue;
|
|
315
|
+
let targetColumn = original_comment_column.get(group[0]) ?? group[0].loc.start.column;
|
|
316
|
+
const counts = /* @__PURE__ */ new Map();
|
|
317
|
+
for (const comment of group) {
|
|
318
|
+
const baselineColumn = original_comment_column.get(comment) ?? comment.loc.start.column;
|
|
319
|
+
counts.set(baselineColumn, (counts.get(baselineColumn) || 0) + 1);
|
|
320
|
+
}
|
|
321
|
+
let highestCount = 1;
|
|
322
|
+
for (const [column, count] of counts) if (count > highestCount) {
|
|
323
|
+
highestCount = count;
|
|
324
|
+
targetColumn = column;
|
|
325
|
+
}
|
|
326
|
+
const widestCodeColumn = Math.max(...group.map((comment) => {
|
|
327
|
+
const line = lines[comment.loc.start.line - 1] || "";
|
|
328
|
+
const commentColumn = resolveCommentColumn(line, comment);
|
|
329
|
+
return line.slice(0, commentColumn).trimEnd().length;
|
|
330
|
+
}));
|
|
331
|
+
let groupMinimumGap = Math.min(...group.map((comment) => {
|
|
332
|
+
const line = lines[comment.loc.start.line - 1] || "";
|
|
333
|
+
const commentColumn = resolveCommentColumn(line, comment);
|
|
334
|
+
const code = line.slice(0, commentColumn).trimEnd();
|
|
335
|
+
return Math.max(1, commentColumn - code.length);
|
|
336
|
+
}));
|
|
337
|
+
const reservedComments = group.filter((comment) => reserved_comment_spacing.has(comment));
|
|
338
|
+
const hasNonInlineTableRows = group.some((comment) => !inlineTableCommentLines.has(comment.loc.start.line));
|
|
339
|
+
if (reservedComments.length > 0 && hasNonInlineTableRows) {
|
|
340
|
+
const reservedMinimumGap = Math.min(...group.map((comment) => {
|
|
341
|
+
if (reserved_comment_spacing.has(comment)) return reserved_comment_spacing.get(comment) || 1;
|
|
342
|
+
const line = lines[comment.loc.start.line - 1] || "";
|
|
343
|
+
const commentColumn = resolveCommentColumn(line, comment);
|
|
344
|
+
const code = line.slice(0, commentColumn).trimEnd();
|
|
345
|
+
return Math.max(1, commentColumn - code.length);
|
|
346
|
+
}));
|
|
347
|
+
groupMinimumGap = Math.min(groupMinimumGap, reservedMinimumGap);
|
|
348
|
+
}
|
|
349
|
+
if (targetColumn < widestCodeColumn + 1) {
|
|
350
|
+
const requiredColumn = widestCodeColumn + groupMinimumGap;
|
|
351
|
+
targetColumn = Math.max(targetColumn, requiredColumn);
|
|
352
|
+
}
|
|
353
|
+
for (const comment of group) {
|
|
354
|
+
const lineIndex = comment.loc.start.line - 1;
|
|
355
|
+
const line = lines[lineIndex] || "";
|
|
356
|
+
const commentColumn = resolveCommentColumn(line, comment);
|
|
357
|
+
const code = line.slice(0, commentColumn).trimEnd();
|
|
358
|
+
const actualTargetColumn = Math.max(targetColumn, code.length + 1);
|
|
359
|
+
if (commentColumn !== actualTargetColumn) lines[lineIndex] = code + " ".repeat(actualTargetColumn - code.length) + comment.raw;
|
|
360
|
+
if (comment.loc.start.column !== actualTargetColumn) {
|
|
361
|
+
comment.loc.start.column = actualTargetColumn;
|
|
362
|
+
comment.loc.end.column = actualTargetColumn + comment.raw.length;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
recomputeContainerEnds(document);
|
|
367
|
+
return lines.join(newLine) + trailing;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
//#endregion
|
|
371
|
+
export { getInlineInsertColumnDelta, normalizeInlineCommentAlignmentInString, preserveAlignedInlineCommentColumn, preserveAlignedInlineCommentForDelta, recordInlineTableCommentDelta };
|
|
372
|
+
//# sourceMappingURL=comment-alignment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comment-alignment.js","names":[],"sources":["../../src/comment-alignment.ts"],"sourcesContent":["/**\n * @file Comment alignment helpers for the patch pipeline.\n * @module comment-alignment\n *\n * Utilities for preserving and normalizing aligned inline comments during patching.\n *\n * This module owns the comment-column logic used by the patch pipeline:\n * it detects whether an inline comment belongs to an aligned group, preserves\n * that alignment when edits change value width, compensates for inline insert\n * width deltas, and performs a final string-level normalization pass for padded\n * aligned comment blocks.\n */\nimport {\n Comment,\n Document,\n KeyValue,\n Table,\n TableArray,\n TreeNode,\n Value,\n hasItems,\n isComment,\n isInlineArray,\n isInlineItem,\n isInlineTable,\n isKeyValue,\n isTable,\n isTableArray\n} from './cst';\nimport { getSpan } from './location';\nimport { TomlFormat } from './toml-format';\n\nconst reserved_comment_spacing = new WeakMap<Comment, number>();\nconst original_comment_column = new WeakMap<Comment, number>();\n\n/**\n * Returns the inline comment attached to the item at the given index.\n *\n * An attached inline comment is the first comment that starts on the same line\n * as the item's end position, before any later non-comment row begins.\n *\n * @param items Container items to inspect.\n * @param index Index of the row whose trailing comment should be resolved.\n * @returns The attached inline comment, if present.\n */\nfunction getAttachedInlineComment(items: TreeNode[], index: number): Comment | undefined {\n const current = items[index];\n const commentLine = current.loc.end.line;\n\n for (let i = index + 1; i < items.length; i++) {\n const candidate = items[i];\n if (isComment(candidate) && candidate.loc.start.line === commentLine) {\n return candidate;\n }\n\n if (!isComment(candidate) && candidate.loc.start.line > commentLine) {\n return;\n }\n }\n}\n\n/**\n * Finds the nearest non-comment row index in the requested direction.\n *\n * @param items Container items to scan.\n * @param index Starting row index.\n * @param direction Scan direction: `-1` for upward, `1` for downward.\n * @returns The nearest neighboring row index, if one exists.\n */\nfunction getNeighborRowIndex(items: TreeNode[], index: number, direction: -1 | 1): number | undefined {\n for (let i = index + direction; i >= 0 && i < items.length; i += direction) {\n if (!isComment(items[i])) {\n return i;\n }\n }\n}\n\n/**\n * Repositions an inline comment to keep it aligned after a width change.\n *\n * @param comment Comment node to adjust.\n * @param targetColumn Desired aligned column for the comment start.\n * @param deltaColumns Horizontal width delta introduced by the edit.\n */\nfunction applyInlineCommentColumnAdjustment(comment: Comment, targetColumn: number, deltaColumns: number) {\n if (!original_comment_column.has(comment)) {\n original_comment_column.set(comment, comment.loc.start.column);\n }\n\n const shiftedColumn = comment.loc.start.column + deltaColumns;\n // Never pull a widened row's comment left into its own code; let the\n // normalization pass realign neighboring rows to the widened target.\n const desiredColumn = Math.max(targetColumn, shiftedColumn);\n const adjustment = desiredColumn - shiftedColumn;\n\n if (adjustment !== 0) {\n comment.loc.start.column += adjustment;\n comment.loc.end.column += adjustment;\n }\n}\n\n/**\n * Stores the current minimum spacing between a row and its trailing comment.\n *\n * This data is refreshed each time it is observed so reused CST comment nodes\n * do not retain stale spacing or column values from a previous patch run.\n *\n * @param row Key-value row that owns the trailing comment.\n * @param comment Trailing inline comment attached to the row.\n */\nfunction rememberReservedCommentSpacing(row: KeyValue, comment: Comment) {\n original_comment_column.set(comment, comment.loc.start.column);\n reserved_comment_spacing.set(comment, comment.loc.start.column - row.loc.end.column);\n}\n\n/**\n * Preserves an aligned trailing inline comment when the row's value node is\n * being replaced by another value node.\n *\n * Use this in edit flows where the patch operation has both the old value and\n * the new value available, for example when `a = \"x\" # note` becomes\n * `a = \"much longer text\" # note`. The function computes the width delta from\n * `existingValue` and `replacementValue`, then repositions the same-line\n * comment so it stays aligned with the adjacent rows that were already aligned\n * before the edit.\n *\n * In short:\n * - `preserveAlignedInlineCommentColumn` is for replacement edits\n * - it derives `deltaColumns` itself from the old and new value spans\n *\n * The comment is adjusted only when the current row already belongs to a\n * vertically aligned comment group with an immediately adjacent row above or\n * below, and both old and new values are single-line.\n *\n * @param container Parent container that owns the row.\n * @param row Key-value row being edited.\n * @param existingValue Original value before replacement.\n * @param replacementValue Replacement value after editing.\n */\nexport function preserveAlignedInlineCommentColumn(\n container: TreeNode,\n row: KeyValue,\n existingValue: TreeNode,\n replacementValue: TreeNode\n) {\n if (!hasItems(container)) return;\n\n const items = container.items as TreeNode[];\n const rowIndex = items.indexOf(row);\n if (rowIndex < 0) return;\n\n const comment = getAttachedInlineComment(items, rowIndex);\n if (!comment) return;\n\n if (existingValue.loc.start.line !== existingValue.loc.end.line) return;\n if (replacementValue.loc.start.line !== replacementValue.loc.end.line) return;\n\n const currentColumn = comment.loc.start.column;\n const currentLine = comment.loc.start.line;\n const neighborIndexes = [\n getNeighborRowIndex(items, rowIndex, -1),\n getNeighborRowIndex(items, rowIndex, 1)\n ];\n\n let alignedColumn: number | undefined;\n for (const neighborIndex of neighborIndexes) {\n if (neighborIndex == null) continue;\n\n const neighborComment = getAttachedInlineComment(items, neighborIndex);\n if (!neighborComment) continue;\n if (Math.abs(neighborComment.loc.start.line - currentLine) !== 1) continue;\n if (neighborComment.loc.start.column !== currentColumn) continue;\n\n alignedColumn = neighborComment.loc.start.column;\n break;\n }\n\n if (alignedColumn == null) return;\n\n const existingSpan = getSpan(existingValue.loc);\n const replacementSpan = getSpan(replacementValue.loc);\n const deltaColumns = replacementSpan.columns - existingSpan.columns;\n\n applyInlineCommentColumnAdjustment(comment, alignedColumn, deltaColumns);\n}\n\n/**\n * Preserves an aligned trailing inline comment when the row gets wider because\n * content was inserted inside an inline container, but the row value node\n * itself was not replaced.\n *\n * Use this in add/insert flows where the caller already knows the rendered\n * width change, for example when inserting a new element into an inline array\n * on a row like `a = [1, 2] # note`. In that case there is no old-vs-new row\n * value pair available here, so the caller passes the precomputed\n * `deltaColumns` directly.\n *\n * In short:\n * - `preserveAlignedInlineCommentForDelta` is for insertion-driven width shifts\n * - it consumes a precomputed `deltaColumns` instead of comparing two value nodes\n *\n * @param container Parent container that owns the row.\n * @param row Key-value row whose trailing comment may need to move.\n * @param deltaColumns Horizontal width delta introduced by the insertion.\n */\nexport function preserveAlignedInlineCommentForDelta(\n container: TreeNode,\n row: KeyValue,\n deltaColumns: number\n) {\n if (!hasItems(container)) return;\n\n const items = container.items as TreeNode[];\n const rowIndex = items.indexOf(row);\n if (rowIndex < 0) return;\n\n const comment = getAttachedInlineComment(items, rowIndex);\n if (!comment) return;\n\n const currentColumn = comment.loc.start.column;\n const currentLine = comment.loc.start.line;\n const neighborIndexes = [\n getNeighborRowIndex(items, rowIndex, -1),\n getNeighborRowIndex(items, rowIndex, 1)\n ];\n\n for (const neighborIndex of neighborIndexes) {\n if (neighborIndex == null) continue;\n\n const neighborComment = getAttachedInlineComment(items, neighborIndex);\n if (!neighborComment) continue;\n if (Math.abs(neighborComment.loc.start.line - currentLine) !== 1) continue;\n if (neighborComment.loc.start.column !== currentColumn) continue;\n\n applyInlineCommentColumnAdjustment(comment, neighborComment.loc.start.column, deltaColumns);\n return;\n }\n}\n\n/**\n * Records baseline comment alignment metadata for a row whose value is a\n * single-line inline table and whose internal contents are being edited.\n *\n * This captures the comment's current column and reserved gap (comment start\n * minus row end) so the final normalization pass can preserve spacing\n * expectations after nested inline-table edits.\n *\n * @param container Parent container that owns the row.\n * @param row Key-value row whose trailing comment alignment metadata is refreshed.\n * @param deltaColumns Horizontal width delta introduced by the nested edit; used\n * only as a fast no-op guard when zero.\n */\nexport function recordInlineTableCommentDelta(container: TreeNode, row: KeyValue, deltaColumns: number) {\n if (!hasItems(container) || deltaColumns === 0) return;\n\n const items = container.items as TreeNode[];\n const rowIndex = items.indexOf(row);\n if (rowIndex < 0) return;\n\n const comment = getAttachedInlineComment(items, rowIndex);\n if (!comment) return;\n\n rememberReservedCommentSpacing(row, comment);\n}\n\n/**\n * Estimates the horizontal column delta caused by inserting a new inline item.\n *\n * The result includes the inserted value width and the comma/spacing overhead\n * needed by the surrounding inline array or inline table formatting.\n *\n * @param parent Inline container receiving the new child.\n * @param child CST node being inserted.\n * @param index Target insertion index.\n * @returns The number of columns added to the rendered row.\n */\nexport function getInlineInsertColumnDelta(parent: Value, child: TreeNode, index: number): number {\n if (!isInlineArray(parent) && !isInlineTable(parent)) return 0;\n\n const childSpan = getSpan(child.loc);\n const hasSeparatingCommaBefore = index > 0;\n const hasSeparatingCommaAfter = index < parent.items.length;\n const isLastElement = index === parent.items.length;\n const hasTrailingComma = isInlineItem(child) ? child.comma : false;\n const hasTrailingCommaSpacingBug =\n hasSeparatingCommaBefore && hasTrailingComma && !hasSeparatingCommaAfter && isLastElement;\n\n return (\n childSpan.columns +\n (hasSeparatingCommaBefore || hasSeparatingCommaAfter ? 2 : 0) +\n (hasTrailingComma ? 1 + (hasTrailingCommaSpacingBug ? -1 : 0) : 0)\n );\n}\n\n/**\n * Recursively collects comment nodes from the document and nested tables.\n *\n * @param node Document or table-like node to traverse.\n * @param comments Accumulator used during recursion.\n * @returns All discovered comment nodes.\n */\nfunction collectComments(node: Document | Table | TableArray, comments: Comment[] = []): Comment[] {\n for (const item of node.items) {\n if (isComment(item)) {\n comments.push(item);\n continue;\n }\n\n if (isTable(item) || isTableArray(item)) {\n collectComments(item, comments);\n }\n }\n\n return comments;\n}\n\n/**\n * Collects the line numbers of single-line key-value rows whose value is a\n * single-line inline table.\n *\n * @param node Document or table-like node to traverse.\n * @param lines Accumulator used during recursion.\n * @returns A set of row end lines for inline-table rows.\n */\nfunction collectSingleLineInlineTableCommentLines(\n node: Document | Table | TableArray,\n lines: Set<number> = new Set()\n): Set<number> {\n for (const item of node.items) {\n if (isKeyValue(item) && isInlineTable(item.value) && item.loc.start.line === item.loc.end.line) {\n lines.add(item.loc.end.line);\n continue;\n }\n\n if (isTable(item) || isTableArray(item)) {\n collectSingleLineInlineTableCommentLines(item, lines);\n }\n }\n\n return lines;\n}\n\n/**\n * Recomputes `loc.end` for the document/table container chain from children.\n *\n * Inline comment normalization can move trailing comments horizontally; this\n * keeps parent containers' end positions consistent with their updated children.\n *\n * @param node Document or table-like container to normalize.\n */\nfunction recomputeContainerEnds(node: Document | Table | TableArray) {\n for (const item of node.items) {\n if (isTable(item) || isTableArray(item)) {\n recomputeContainerEnds(item);\n }\n }\n\n let maxLine = node.loc.end.line;\n let maxColumn = node.loc.end.column;\n\n const updateMax = (line: number, column: number) => {\n if (line > maxLine || (line === maxLine && column > maxColumn)) {\n maxLine = line;\n maxColumn = column;\n }\n };\n\n if (isTable(node) || isTableArray(node)) {\n updateMax(node.key.loc.end.line, node.key.loc.end.column);\n }\n\n for (const item of node.items) {\n updateMax(item.loc.end.line, item.loc.end.column);\n }\n\n node.loc.end.line = maxLine;\n node.loc.end.column = maxColumn;\n}\n\n/**\n * Normalizes padded inline comment groups in the final rendered TOML string.\n *\n * This pass is intentionally limited to comments that already have explicit\n * padding before `#`, which avoids disturbing compact TOML 1.1 inline-table\n * comment styles while still restoring vertical alignment for normal row-based\n * comment blocks.\n *\n * For groups touched by nested inline-table edits, the target column is derived\n * from the widest current row plus the group's original minimum reserved gap.\n *\n * @param document Patched CST document whose comment locations are updated in-place.\n * @param tomlString Rendered TOML output to normalize.\n * @param format Active TOML formatting settings.\n * @returns The normalized TOML string.\n */\nexport function normalizeInlineCommentAlignmentInString(\n document: Document,\n tomlString: string,\n format: TomlFormat\n): string {\n const newLine = format.newLine;\n const trailingMatch = tomlString.match(/(?:\\r\\n|\\n)+$/u);\n const trailing = trailingMatch ? trailingMatch[0] : '';\n const body = trailing ? tomlString.slice(0, -trailing.length) : tomlString;\n const lines = body.length ? body.split(newLine) : [];\n const inlineTableCommentLines = collectSingleLineInlineTableCommentLines(document);\n\n const resolveCommentColumn = (line: string, comment: Comment): number => {\n const fromLine = line.lastIndexOf(comment.raw);\n return fromLine >= 0 ? fromLine : comment.loc.start.column;\n };\n\n const comments = collectComments(document)\n .filter(comment => {\n const line = lines[comment.loc.start.line - 1] || '';\n const commentColumn = resolveCommentColumn(line, comment);\n const beforeComment = line.slice(0, commentColumn);\n return beforeComment.trim().length > 0 && /\\s{2,}$/u.test(beforeComment);\n })\n .sort((a, b) => a.loc.start.line - b.loc.start.line);\n\n const groups: Comment[][] = [];\n let currentGroup: Comment[] = [];\n for (const comment of comments) {\n const previous = currentGroup[currentGroup.length - 1];\n if (!previous || comment.loc.start.line === previous.loc.start.line + 1) {\n currentGroup.push(comment);\n } else {\n if (currentGroup.length > 0) {\n groups.push(currentGroup);\n }\n currentGroup = [comment];\n }\n }\n if (currentGroup.length > 0) {\n groups.push(currentGroup);\n }\n\n for (const group of groups) {\n if (group.length < 2) continue;\n\n let targetColumn = original_comment_column.get(group[0]) ?? group[0].loc.start.column;\n const counts = new Map<number, number>();\n for (const comment of group) {\n const baselineColumn = original_comment_column.get(comment) ?? comment.loc.start.column;\n counts.set(baselineColumn, (counts.get(baselineColumn) || 0) + 1);\n }\n\n let highestCount = 1;\n for (const [column, count] of counts) {\n if (count > highestCount) {\n highestCount = count;\n targetColumn = column;\n }\n }\n\n const widestCodeColumn = Math.max(\n ...group.map(comment => {\n const line = lines[comment.loc.start.line - 1] || '';\n const commentColumn = resolveCommentColumn(line, comment);\n const code = line.slice(0, commentColumn).trimEnd();\n return code.length;\n })\n );\n\n const currentGroupMinimumGap = Math.min(\n ...group.map(comment => {\n const line = lines[comment.loc.start.line - 1] || '';\n const commentColumn = resolveCommentColumn(line, comment);\n const code = line.slice(0, commentColumn).trimEnd();\n return Math.max(1, commentColumn - code.length);\n })\n );\n\n let groupMinimumGap = currentGroupMinimumGap;\n const reservedComments = group.filter(comment => reserved_comment_spacing.has(comment));\n const hasNonInlineTableRows = group.some(comment => !inlineTableCommentLines.has(comment.loc.start.line));\n if (reservedComments.length > 0 && hasNonInlineTableRows) {\n const reservedMinimumGap = Math.min(\n ...group.map(comment => {\n if (reserved_comment_spacing.has(comment)) {\n return reserved_comment_spacing.get(comment) || 1;\n }\n\n const line = lines[comment.loc.start.line - 1] || '';\n const commentColumn = resolveCommentColumn(line, comment);\n const code = line.slice(0, commentColumn).trimEnd();\n return Math.max(1, commentColumn - code.length);\n })\n );\n groupMinimumGap = Math.min(groupMinimumGap, reservedMinimumGap);\n }\n\n if (targetColumn < widestCodeColumn + 1) {\n const requiredColumn = widestCodeColumn + groupMinimumGap;\n targetColumn = Math.max(targetColumn, requiredColumn);\n }\n\n for (const comment of group) {\n const lineIndex = comment.loc.start.line - 1;\n const line = lines[lineIndex] || '';\n const commentColumn = resolveCommentColumn(line, comment);\n const code = line.slice(0, commentColumn).trimEnd();\n const actualTargetColumn = Math.max(targetColumn, code.length + 1);\n if (commentColumn !== actualTargetColumn) {\n const spaces = ' '.repeat(actualTargetColumn - code.length);\n lines[lineIndex] = code + spaces + comment.raw;\n }\n\n if (comment.loc.start.column !== actualTargetColumn) {\n comment.loc.start.column = actualTargetColumn;\n comment.loc.end.column = actualTargetColumn + comment.raw.length;\n }\n }\n }\n\n recomputeContainerEnds(document);\n\n return lines.join(newLine) + trailing;\n}"],"mappings":";;;;;;;;;;;;;;;;;AAgCA,MAAM,2CAA2B,IAAI,QAAyB;AAC9D,MAAM,0CAA0B,IAAI,QAAyB;;;;;;;;;;;AAY7D,SAAS,yBAAyB,OAAmB,OAAoC;CAEvF,MAAM,cADU,MAAM,MACK,CAAC,IAAI,IAAI;CAEpC,KAAK,IAAI,IAAI,QAAQ,GAAG,IAAI,MAAM,QAAQ,KAAK;EAC7C,MAAM,YAAY,MAAM;EACxB,IAAI,UAAU,SAAS,KAAK,UAAU,IAAI,MAAM,SAAS,aACvD,OAAO;EAGT,IAAI,CAAC,UAAU,SAAS,KAAK,UAAU,IAAI,MAAM,OAAO,aACtD;CAEJ;AACF;;;;;;;;;AAUA,SAAS,oBAAoB,OAAmB,OAAe,WAAuC;CACpG,KAAK,IAAI,IAAI,QAAQ,WAAW,KAAK,KAAK,IAAI,MAAM,QAAQ,KAAK,WAC/D,IAAI,CAAC,UAAU,MAAM,EAAE,GACrB,OAAO;AAGb;;;;;;;;AASA,SAAS,mCAAmC,SAAkB,cAAsB,cAAsB;CACxG,IAAI,CAAC,wBAAwB,IAAI,OAAO,GACtC,wBAAwB,IAAI,SAAS,QAAQ,IAAI,MAAM,MAAM;CAG/D,MAAM,gBAAgB,QAAQ,IAAI,MAAM,SAAS;CAIjD,MAAM,aADgB,KAAK,IAAI,cAAc,aACd,IAAI;CAEnC,IAAI,eAAe,GAAG;EACpB,QAAQ,IAAI,MAAM,UAAU;EAC5B,QAAQ,IAAI,IAAI,UAAU;CAC5B;AACF;;;;;;;;;;AAWA,SAAS,+BAA+B,KAAe,SAAkB;CACvE,wBAAwB,IAAI,SAAS,QAAQ,IAAI,MA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