@decimalturn/toml-patch 3.1.0-dev → 3.1.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 +1 -1
- package/dist/dev/comment-ownership.js +62 -62
- package/dist/dev/comment-ownership.js.map +1 -1
- package/dist/dev/cst-source.js +1 -1
- package/dist/dev/cst.js +1 -1
- package/dist/dev/cursor.js +1 -1
- package/dist/dev/date-format.js +1 -1
- package/dist/dev/decode-utf8.js +1 -1
- package/dist/dev/diff.js +1 -1
- package/dist/dev/escape-preference.js +1 -1
- package/dist/dev/find-by-path.js +1 -1
- package/dist/dev/formatter.js +1 -1
- package/dist/dev/generate.js +1 -1
- package/dist/dev/inline-comma-space.js +1 -1
- package/dist/dev/inline-format.js +1 -1
- package/dist/dev/inline-layout.js +1 -1
- package/dist/dev/line-ending-backslash.js +1 -1
- package/dist/dev/location.js +30 -3
- package/dist/dev/location.js.map +1 -1
- package/dist/dev/parse-error.js +1 -1
- package/dist/dev/parse-js.js +1 -1
- package/dist/dev/parse-string.js +1 -1
- package/dist/dev/parse-toml.js +18 -10
- package/dist/dev/parse-toml.js.map +1 -1
- package/dist/dev/patch.js +27 -27
- package/dist/dev/patch.js.map +1 -1
- package/dist/dev/to-js.js +1 -1
- package/dist/dev/to-toml.js +1 -1
- package/dist/dev/tokenizer.js +1 -1
- package/dist/dev/toml-document.js +1 -1
- package/dist/dev/toml-format.js +1 -1
- package/dist/dev/toml-patch.js +1 -1
- package/dist/dev/traverse.js +1 -1
- package/dist/dev/truncate.js +1 -1
- package/dist/dev/update-order.js +21 -21
- package/dist/dev/update-order.js.map +1 -1
- package/dist/dev/utils.js +1 -1
- package/dist/dev/writer.js +1 -1
- package/dist/toml-patch.d.ts +10 -10
- package/package.json +1 -1
package/dist/dev/patch.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! @decimalturn/toml-patch v3.1.
|
|
1
|
+
//! @decimalturn/toml-patch v3.1.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
|
|
2
2
|
import { hasItem, hasItems, isComment, isDateTime, isDocument, isFloat, isInlineArray, isInlineItem, isInlineTable, isKeyValue, isString, isTable, isTableArray } from "./cst.js";
|
|
3
3
|
import { getSpan } from "./location.js";
|
|
4
4
|
import { IS_BARE_KEY, createNewlineScanState } from "./tokenizer.js";
|
|
@@ -19,7 +19,7 @@ import toTOML, { toTOMLCursor } from "./to-toml.js";
|
|
|
19
19
|
import toJS from "./to-js.js";
|
|
20
20
|
import diff, { isAdd, isEdit, isMove, isRemove, isRename } from "./diff.js";
|
|
21
21
|
import findByPath, { findParent, tryFindByPath } from "./find-by-path.js";
|
|
22
|
-
import { findHostContainer, moveInlineElement, removeMember,
|
|
22
|
+
import { findHostContainer, moveInlineElement, removeMember, resolveGroups } from "./comment-ownership.js";
|
|
23
23
|
import { applyKeyOrderMoves } from "./update-order.js";
|
|
24
24
|
import { getInlineInsertColumnDelta, normalizeInlineCommentAlignmentInString, preserveAlignedInlineCommentColumn, preserveAlignedInlineCommentForDelta, recordInlineTableCommentDelta } from "./comment-alignment.js";
|
|
25
25
|
|
|
@@ -139,7 +139,7 @@ function applyRequestedRootKeyOrder(updated, updated_js, diffing_fmt, useTempora
|
|
|
139
139
|
* The parser's table-body loop consumes comments between consecutive [[x]] entries
|
|
140
140
|
* as trailing children of the first entry (it sees `# comment` before the next
|
|
141
141
|
* `[[x]]` header). This function promotes those trailing comments to Document-level
|
|
142
|
-
* siblings so that
|
|
142
|
+
* siblings so that resolveGroups can assign them to the correct entry.
|
|
143
143
|
*/
|
|
144
144
|
function normalizeAotEntryComments(doc) {
|
|
145
145
|
const items = doc.items;
|
|
@@ -1795,55 +1795,55 @@ function applyChanges(original, updated, changes, format, temporal = false, comm
|
|
|
1795
1795
|
} else {
|
|
1796
1796
|
normalizeAotEntryComments(original);
|
|
1797
1797
|
const fromNode = findByPath(original, change.path.concat(change.from));
|
|
1798
|
-
const
|
|
1799
|
-
const
|
|
1800
|
-
const
|
|
1798
|
+
const fromGroup = resolveGroups(original).find((s) => s.member === fromNode);
|
|
1799
|
+
const groupItems = fromGroup ? [...fromGroup.items] : [fromNode];
|
|
1800
|
+
const groupOriginalPos = groupItems.map((item) => ({
|
|
1801
1801
|
startLine: item.loc.start.line,
|
|
1802
1802
|
endLine: item.loc.end.line
|
|
1803
1803
|
}));
|
|
1804
|
-
const
|
|
1805
|
-
const
|
|
1804
|
+
const groupFirstIdx = original.items.indexOf(fromGroup ? fromGroup.items[0] : fromNode);
|
|
1805
|
+
const lastGroupEnd = groupOriginalPos[groupOriginalPos.length - 1].endLine;
|
|
1806
1806
|
let originalAfterGap;
|
|
1807
1807
|
for (let k = 0; k < original.items.length; k++) {
|
|
1808
1808
|
const item = original.items[k];
|
|
1809
|
-
if (item.loc.start.line >
|
|
1810
|
-
originalAfterGap = item.loc.start.line -
|
|
1809
|
+
if (item.loc.start.line > lastGroupEnd) {
|
|
1810
|
+
originalAfterGap = item.loc.start.line - lastGroupEnd;
|
|
1811
1811
|
break;
|
|
1812
1812
|
}
|
|
1813
1813
|
}
|
|
1814
|
-
if (originalAfterGap === void 0 &&
|
|
1815
|
-
const
|
|
1816
|
-
originalAfterGap =
|
|
1814
|
+
if (originalAfterGap === void 0 && groupFirstIdx > 0) {
|
|
1815
|
+
const beforeGroup = original.items[groupFirstIdx - 1];
|
|
1816
|
+
originalAfterGap = groupOriginalPos[0].startLine - beforeGroup.loc.end.line;
|
|
1817
1817
|
}
|
|
1818
|
-
const memberIdx =
|
|
1818
|
+
const memberIdx = fromGroup ? fromGroup.items.indexOf(fromNode) : 0;
|
|
1819
1819
|
for (let i = 0; i <= memberIdx; i++) {
|
|
1820
|
-
if (!original.items.includes(
|
|
1821
|
-
remove(original, original,
|
|
1820
|
+
if (!original.items.includes(groupItems[i])) continue;
|
|
1821
|
+
remove(original, original, groupItems[i]);
|
|
1822
1822
|
}
|
|
1823
|
-
for (let i = memberIdx + 1; i <
|
|
1824
|
-
const idx = original.items.indexOf(
|
|
1823
|
+
for (let i = memberIdx + 1; i < groupItems.length; i++) {
|
|
1824
|
+
const idx = original.items.indexOf(groupItems[i]);
|
|
1825
1825
|
if (idx >= 0) original.items.splice(idx, 1);
|
|
1826
1826
|
}
|
|
1827
1827
|
const toEntry = tryFindByPath(original, change.path.concat(change.to));
|
|
1828
1828
|
let toIndex;
|
|
1829
1829
|
let targetHasLeadingComment = false;
|
|
1830
|
-
const sourceHadLeadingComment =
|
|
1830
|
+
const sourceHadLeadingComment = fromGroup && fromGroup.items[0] !== fromNode && isComment(fromGroup.items[0]);
|
|
1831
1831
|
if (toEntry) {
|
|
1832
|
-
const
|
|
1833
|
-
targetHasLeadingComment = !!(
|
|
1834
|
-
if (targetHasLeadingComment && sourceHadLeadingComment) toIndex = original.items.indexOf(
|
|
1832
|
+
const targetGroup = resolveGroups(original).find((s) => s.member === toEntry);
|
|
1833
|
+
targetHasLeadingComment = !!(targetGroup && targetGroup.items[0] !== toEntry && isComment(targetGroup.items[0]));
|
|
1834
|
+
if (targetHasLeadingComment && sourceHadLeadingComment) toIndex = original.items.indexOf(targetGroup.items[0]);
|
|
1835
1835
|
else toIndex = original.items.indexOf(toEntry);
|
|
1836
1836
|
} else toIndex = original.items.length;
|
|
1837
1837
|
const targetPrevEnd = toIndex > 0 ? original.items[toIndex - 1].loc.end.line : 0;
|
|
1838
1838
|
const targetFirstLine = toIndex < original.items.length ? original.items[toIndex].loc.start.line : void 0;
|
|
1839
1839
|
const isCommentedSwap = targetHasLeadingComment && sourceHadLeadingComment;
|
|
1840
1840
|
let insertIdx = toIndex;
|
|
1841
|
-
for (let i = 0; i <
|
|
1842
|
-
const item =
|
|
1841
|
+
for (let i = 0; i < groupItems.length; i++) {
|
|
1842
|
+
const item = groupItems[i];
|
|
1843
1843
|
let itemLeadingLines;
|
|
1844
1844
|
if ((isCommentedSwap || sourceHadLeadingComment && toIndex > 0 && toIndex < original.items.length) && insertIdx > 0) {
|
|
1845
|
-
const prevEnd = i === 0 ? targetPrevEnd :
|
|
1846
|
-
const origLeading = i === 0 && targetFirstLine !== void 0 ? targetFirstLine - targetPrevEnd :
|
|
1845
|
+
const prevEnd = i === 0 ? targetPrevEnd : groupOriginalPos[i - 1].endLine;
|
|
1846
|
+
const origLeading = i === 0 && targetFirstLine !== void 0 ? targetFirstLine - targetPrevEnd : groupOriginalPos[i].startLine - prevEnd;
|
|
1847
1847
|
if (origLeading !== (isTable(item) || isTableArray(item) ? 2 : 1)) itemLeadingLines = origLeading;
|
|
1848
1848
|
}
|
|
1849
1849
|
insert(original, original, item, insertIdx, void 0, void 0, itemLeadingLines);
|
|
@@ -1851,7 +1851,7 @@ function applyChanges(original, updated, changes, format, temporal = false, comm
|
|
|
1851
1851
|
}
|
|
1852
1852
|
if (originalAfterGap !== void 0) {
|
|
1853
1853
|
applyWrites(original);
|
|
1854
|
-
const lastItem =
|
|
1854
|
+
const lastItem = groupItems[groupItems.length - 1];
|
|
1855
1855
|
const afterStart = original.items.indexOf(lastItem) + 1;
|
|
1856
1856
|
if (afterStart < original.items.length) {
|
|
1857
1857
|
const newGap = original.items[afterStart].loc.start.line - lastItem.loc.end.line;
|