@decimalturn/toml-patch 3.1.2-dev → 3.2.0-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.
Files changed (56) hide show
  1. package/dist/dev/comment-alignment.js +1 -1
  2. package/dist/dev/comment-ownership.js +1 -1
  3. package/dist/dev/cst-source.js +1 -1
  4. package/dist/dev/cst.js +11 -2
  5. package/dist/dev/cst.js.map +1 -1
  6. package/dist/dev/cursor.js +1 -1
  7. package/dist/dev/date-format.js +1 -1
  8. package/dist/dev/decode-utf8.js +1 -1
  9. package/dist/dev/diff-lite.js +123 -0
  10. package/dist/dev/diff-lite.js.map +1 -0
  11. package/dist/dev/diff.js +4 -8
  12. package/dist/dev/diff.js.map +1 -1
  13. package/dist/dev/encode-lite.js +193 -0
  14. package/dist/dev/encode-lite.js.map +1 -0
  15. package/dist/dev/escape-preference.js +33 -11
  16. package/dist/dev/escape-preference.js.map +1 -1
  17. package/dist/dev/find-by-path.js +1 -1
  18. package/dist/dev/formatter.js +9 -9
  19. package/dist/dev/formatter.js.map +1 -1
  20. package/dist/dev/generate.js +53 -39
  21. package/dist/dev/generate.js.map +1 -1
  22. package/dist/dev/inline-comma-space.js +1 -1
  23. package/dist/dev/inline-format.js +1 -1
  24. package/dist/dev/inline-layout.js +1 -1
  25. package/dist/dev/line-ending-backslash.js +1 -1
  26. package/dist/dev/literal-string.js +46 -0
  27. package/dist/dev/literal-string.js.map +1 -0
  28. package/dist/dev/location.js +1 -1
  29. package/dist/dev/parse-error.js +1 -1
  30. package/dist/dev/parse-js.js +49 -6
  31. package/dist/dev/parse-js.js.map +1 -1
  32. package/dist/dev/parse-string.js +1 -1
  33. package/dist/dev/parse-toml.js +1 -1
  34. package/dist/dev/patch-lite.js +4 -0
  35. package/dist/dev/patch-lite2.js +96 -0
  36. package/dist/dev/patch-lite2.js.map +1 -0
  37. package/dist/dev/patch.js +150 -38
  38. package/dist/dev/patch.js.map +1 -1
  39. package/dist/dev/smol-toml-date.js +61 -0
  40. package/dist/dev/smol-toml-date.js.map +1 -0
  41. package/dist/dev/to-js.js +1 -1
  42. package/dist/dev/to-toml.js +1 -1
  43. package/dist/dev/tokenizer.js +1 -1
  44. package/dist/dev/toml-document.js +1 -1
  45. package/dist/dev/toml-format.js +58 -6
  46. package/dist/dev/toml-format.js.map +1 -1
  47. package/dist/dev/toml-patch.js +1 -1
  48. package/dist/dev/traverse.js +1 -1
  49. package/dist/dev/truncate.js +1 -1
  50. package/dist/dev/update-order.js +1 -1
  51. package/dist/dev/utils.js +26 -5
  52. package/dist/dev/utils.js.map +1 -1
  53. package/dist/dev/writer.js +1 -1
  54. package/dist/patch-lite.d.ts +18 -0
  55. package/dist/toml-patch.d.ts +7 -1
  56. package/package.json +6 -1
@@ -1,4 +1,4 @@
1
- //! @decimalturn/toml-patch v3.1.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
2
  import { hasItems, isComment, isInlineArray, isInlineItem, isInlineTable, isKeyValue, isTable, isTableArray } from "./cst.js";
3
3
  import { getSpan } from "./location.js";
4
4
 
@@ -1,4 +1,4 @@
1
- //! @decimalturn/toml-patch v3.1.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
2
  import { hasItems, isComment, isDocument, isInlineArray, isInlineItem, isInlineTable, isKeyValue, isString, isTable, isTableArray } from "./cst.js";
3
3
  import { clonePosition } from "./location.js";
4
4
  import { last } from "./utils.js";
@@ -1,4 +1,4 @@
1
- //! @decimalturn/toml-patch v3.1.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
2
  import { hasItems, isInlineItem, isKeyValue, isTable, isTableArray } from "./cst.js";
3
3
 
4
4
  //#region src/cst-source.ts
package/dist/dev/cst.js CHANGED
@@ -1,4 +1,4 @@
1
- //! @decimalturn/toml-patch v3.1.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
2
  //#region src/cst.ts
3
3
  function isDocument(node) {
4
4
  return node.type === "Document";
@@ -26,9 +26,15 @@ function isKeyValue(node) {
26
26
  function isString(node) {
27
27
  return node.type === "String";
28
28
  }
29
+ function isInteger(node) {
30
+ return node.type === "Integer";
31
+ }
29
32
  function isFloat(node) {
30
33
  return node.type === "Float";
31
34
  }
35
+ function isBoolean(node) {
36
+ return node.type === "Boolean";
37
+ }
32
38
  function isDateTime(node) {
33
39
  return node.type === "DateTime";
34
40
  }
@@ -53,7 +59,10 @@ function hasItem(node) {
53
59
  function isBlock(node) {
54
60
  return isKeyValue(node) || isTable(node) || isTableArray(node) || isComment(node);
55
61
  }
62
+ function isValue(node) {
63
+ return isString(node) || isInteger(node) || isFloat(node) || isBoolean(node) || isDateTime(node) || isInlineArray(node) || isInlineTable(node);
64
+ }
56
65
 
57
66
  //#endregion
58
- export { hasItem, hasItems, isBlock, isComment, isDateTime, isDocument, isFloat, isInlineArray, isInlineItem, isInlineTable, isKeyValue, isString, isTable, isTableArray, isTableArrayKey, isTableKey };
67
+ export { hasItem, hasItems, isBlock, isBoolean, isComment, isDateTime, isDocument, isFloat, isInlineArray, isInlineItem, isInlineTable, isInteger, isKeyValue, isString, isTable, isTableArray, isTableArrayKey, isTableKey, isValue };
59
68
  //# sourceMappingURL=cst.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cst.js","names":[],"sources":["../../src/cst.ts"],"sourcesContent":["import { Location } from './location';\n\nexport enum NodeType {\n Document = 'Document',\n Table = 'Table',\n TableKey = 'TableKey',\n /**\n * Array of Tables node\n * More info: https://toml.io/en/latest#array-of-tables\n */\n TableArray = 'TableArray',\n TableArrayKey = 'TableArrayKey',\n KeyValue = 'KeyValue',\n Key = 'Key',\n String = 'String',\n Integer = 'Integer',\n Float = 'Float',\n Boolean = 'Boolean',\n DateTime = 'DateTime',\n InlineArray = 'InlineArray',\n InlineItem = 'InlineItem',\n InlineTable = 'InlineTable',\n /**\n * Comment node\n * More info: https://toml.io/en/latest#comment\n */\n Comment = 'Comment'\n}\n\n//\n// Concrete Syntax Tree\n//\n// CST nodes are used to represent TOML data\n//\nexport type CST = Iterable<Block>;\n\n//\n// Document\n//\n// Top-level document that stores CST nodes\n//\nexport interface Document extends TreeNode {\n type: NodeType.Document;\n items: Array<Block>;\n}\nexport function isDocument(node: TreeNode): node is Document {\n return node.type === NodeType.Document;\n}\n\n//\n// Table\n//\n// Top-level object\n//\n// v-------|\n// [table] |\n// b = \"c\" |\n// |\n// # note |\n// ^--|\n// [b]\n//\nexport interface Table extends TreeNode {\n type: NodeType.Table;\n key: TableKey;\n items: RowItem[];\n}\nexport function isTable(node: TreeNode): node is Table {\n return node.type === NodeType.Table;\n}\n\n//\n// TableKey\n//\n// Used to store bracket information for Table keys\n//\n// loc includes brackets\n//\n// [ key ]\n// ^-------^\n//\nexport interface TableKey extends TreeNode {\n type: NodeType.TableKey;\n item: Key;\n}\nexport function isTableKey(node: TreeNode): node is TableKey {\n return node.type === NodeType.TableKey;\n}\n\n//\n// TableArray\n//\n// Top-level array item\n//\n// v---------|\n// [[array]] |\n// a=\"b\" |\n// |\n// # details |\n// ^-|\n// [[array]]\n//\nexport interface TableArray extends TreeNode {\n type: NodeType.TableArray;\n key: TableArrayKey;\n items: RowItem[];\n}\n\n/**\n * Is a TableArray (aka Array of Tables)\n * @param node \n * @returns \n */\nexport function isTableArray(node: TreeNode): node is TableArray {\n return node.type === NodeType.TableArray;\n}\n\n//\n// TableArrayKey\n//\n// Used to store bracket information for TableArray keys\n// loc includes brackets\n//\n// [[ key ]]\n// ^---------^\n//\nexport interface TableArrayKey extends TreeNode {\n type: NodeType.TableArrayKey;\n item: Key;\n}\nexport function isTableArrayKey(node: TreeNode): node is TableArrayKey {\n return node.type === NodeType.TableArrayKey;\n}\n\n//\n// KeyValue\n//\n// Key and Value nodes, with position information on equals sign\n//\n// key=\"value\" # note\n// ^---------^\n//\nexport interface KeyValue extends TreeNode {\n type: NodeType.KeyValue;\n key: Key;\n value: Value;\n\n // Column index (0-based) of the equals sign\n equals: number;\n}\nexport function isKeyValue(node: TreeNode): node is KeyValue {\n return node.type === NodeType.KeyValue;\n}\n\n//\n// Key\n//\n// Store raw key and parts (from dots)\n//\nexport interface Key extends TreeNode {\n type: NodeType.Key;\n raw: string;\n\n // Note: Array for keys with dots\n // e.g. a.b -> raw = 'a.b', value = ['a', 'b']\n value: string[];\n}\nexport function isKey(node: TreeNode): node is Key {\n return node.type === NodeType.Key;\n}\n\n//\n// String\n//\n// loc includes quotes\n//\n// a = \"string\"\n// ^------^\n//\nexport interface String extends TreeNode {\n type: NodeType.String;\n raw: string;\n value: string;\n}\nexport function isString(node: TreeNode): node is String {\n return node.type === NodeType.String;\n}\n\n//\n// Integer\n//\nexport interface Integer extends TreeNode {\n type: NodeType.Integer;\n raw: string;\n value: number | bigint;\n}\nexport function isInteger(node: TreeNode): node is Integer {\n return node.type === NodeType.Integer;\n}\n\n//\n// Float\n//\nexport interface Float extends TreeNode {\n type: NodeType.Float;\n raw: string;\n value: number;\n /** Sign prefix for NaN values: '+' for +nan, '-' for -nan, undefined for nan */\n nanSign?: '+' | '-';\n}\nexport function isFloat(node: TreeNode): node is Float {\n return node.type === NodeType.Float;\n}\n\n//\n// Boolean\n//\nexport interface Boolean extends TreeNode {\n type: NodeType.Boolean;\n\n // Only `true` and `false` are permitted\n // -> don't need separate raw and value\n value: boolean;\n}\nexport function isBoolean(node: TreeNode): node is Boolean {\n return node.type === NodeType.Boolean;\n}\n\n//\n// DateTime\n//\n// Note: Currently, Offset Date-Time, Local Date-Time, Local Date, and Local Time\n// are handled via raw\n//\nexport interface DateTime extends TreeNode {\n type: NodeType.DateTime;\n raw: string;\n value: Date;\n}\nexport function isDateTime(node: TreeNode): node is DateTime {\n return node.type === NodeType.DateTime;\n}\n\n//\n// InlineArray\n//\nexport interface InlineArray<TItem = TreeNode> extends TreeNode {\n type: NodeType.InlineArray;\n items: InlineArrayItem<TItem>[];\n}\nexport function isInlineArray(node: TreeNode): node is InlineArray {\n return node.type === NodeType.InlineArray;\n}\n\n// InlineItem (internal CST wrapper — not a TOML spec concept)\n//\n// InlineItem is a container node that wraps each element inside an inline\n// container (InlineArray or InlineTable). It carries two responsibilities:\n//\n// 1. Tracking the comma that follows the element (comma: boolean).\n// When the element is the last one in the container, `comma` may be\n// false (no trailing comma) or true (trailing comma, TOML 1.1+).\n//\n// 2. Providing a stable \"slot\" node in the parent's .items array so that\n// the writer can apply positional offsets independently of the wrapped\n// value node itself.\n//\n// It is generic over TItem so that the two concrete subtypes can constrain\n// what they wrap:\n//\n// InlineArrayItem<TItem> — wraps any Value (scalar, array, inline table)\n// InlineTableItem — always wraps a KeyValue\n//\n// Location:\n// loc spans from the start of the wrapped value to the character just\n// before the comma (or the end of the value when there is no comma).\n//\n// [ \"a\" ,\"b\", \"c\" ]\n// ^---^ ^-^ ^-^\n//\n// { a = 1 , b = 2 }\n// ^---^ ^---^\n//\n// Note on findByPath traversal:\n// When navigating a path into an InlineArray, findByPath matches numeric\n// indices to InlineArrayItem positions. When the wrapped item is an\n// InlineTable and the path has further segments to resolve, traversal\n// continues into item.item (the InlineTable), not into the InlineItem\n// wrapper itself (which has no .items of its own).\n//\nexport interface InlineItem<TItem = TreeNode> extends TreeNode {\n type: NodeType.InlineItem;\n item: TItem;\n comma: boolean;\n}\nexport function isInlineItem(node: TreeNode): node is InlineItem {\n return node.type === NodeType.InlineItem;\n}\n\n// InlineArrayItem — semantic alias for InlineItem used as the element type of\n// InlineArray.items. It adds no fields; its existence is purely documentary:\n// naming the subtype makes the array-vs-table distinction visible in type\n// annotations without requiring an extra runtime check.\n//\n// TItem can be any Value: a scalar (String, Integer, …), a nested InlineArray,\n// or an InlineTable. The generic parameter is propagated so that typed arrays\n// such as InlineArray<String> carry their element type through to the items.\n//\n// [ \"a\" ,\"b\", \"c\" ]\n// ^---^ ^-^ ^-^ ← each element is an InlineArrayItem\n//\nexport interface InlineArrayItem<TItem = TreeNode> extends InlineItem<TItem> {}\n\n//\n// InlineTable\n//\nexport interface InlineTable extends TreeNode {\n type: NodeType.InlineTable;\n items: InlineTableItem[];\n}\nexport function isInlineTable(node: TreeNode): node is InlineTable {\n return node.type === NodeType.InlineTable;\n}\n\n// InlineTableItem — semantic alias for InlineItem<KeyValue> used as the element type\n// of InlineTable.items. It adds no fields; its existence is purely documentary:\n// naming the subtype makes the array-vs-table distinction visible in type\n// annotations without requiring an extra runtime check.\n//\n// The type parameter is fixed to KeyValue, which means the unsafe cast\n// `existing.item as KeyValue` that previously appeared in patch.ts is\n// unnecessary — the type system already guarantees it.\n//\n// { a=\"b\" , c = \"d\" }\n// ^------^ ^--------^ ← each element is an InlineTableItem\n//\nexport interface InlineTableItem extends InlineItem<KeyValue> {}\n\n//\n// Comment\n//\n// loc starts at \"#\" and goes to end of comment (trailing whitespace ignored)\n//\n// # comment here\n// ^------------^\n//\nexport interface Comment extends TreeNode {\n type: NodeType.Comment;\n raw: string;\n}\nexport function isComment(node: TreeNode): node is Comment {\n return node.type === NodeType.Comment;\n}\n\n//\n// Combinations\n//\n\n/**\n * RowItem represents items that can appear inside Table and TableArray sections.\n * These are the items that form the \"rows\" of content within table structures.\n * \n * Unlike Block items (which include Table and TableArray), RowItems can only be\n * KeyValue pairs and Comments - you cannot have nested tables within a table section.\n */\nexport type RowItem = KeyValue | Comment;\nexport function isRowItem(node: TreeNode): node is RowItem {\n return isKeyValue(node) || isComment(node);\n}\n\nexport interface WithItems extends TreeNode {\n items: TreeNode[];\n}\nexport function hasItems(node: TreeNode): node is WithItems {\n return (\n isDocument(node) ||\n isTable(node) ||\n isTableArray(node) ||\n isInlineTable(node) ||\n isInlineArray(node)\n );\n}\n\nexport interface WithItem extends TreeNode {\n item: TreeNode;\n}\nexport function hasItem(node: TreeNode): node is WithItem {\n return isTableKey(node) || isTableArrayKey(node) || isInlineItem(node);\n}\n\n/**\n * Block represents items that can appear at the root level (Document level) in TOML.\n * \n * Context and Usage:\n * - Block items are the fundamental top-level constructs in a TOML document\n * - They appear directly in Document containers and regular Table sections\n * - This is in contrast to InlineItems, which appear within inline containers\n * \n * Important Distinction:\n * - Table and TableArray can ONLY exist as Block items (they cannot appear inside inline containers)\n * - KeyValue and Comment can exist as BOTH Block items AND as InlineItems:\n * * As Block: When they appear at root level or inside regular Table sections\n * * As InlineItem: When they appear inside InlineTable or InlineArray containers\n * \n * Examples:\n * ```toml\n * # These are Block items at root level:\n * name = \"value\" # KeyValue as Block\n * # This is a comment # Comment as Block\n * [table] # Table as Block\n * [[array]] # TableArray as Block\n * \n * # These are Block items inside a Table:\n * [config]\n * setting = \"value\" # KeyValue as Block (inside Table)\n * # comment here # Comment as Block (inside Table)\n * \n * # These are InlineItems (NOT Block items):\n * array = [ \"a\", \"b\" ] # \"a\", \"b\" are InlineItems\n * table = { key = \"value\" } # key=\"value\" is InlineItem\n * ```\n * \n * Type Safety:\n * This distinction is crucial for the CST structure because:\n * - Document.items: Block[]\n * - Table.items: RowItem[] (KeyValue | Comment)\n * - TableArray.items: RowItem[] (KeyValue | Comment)\n * - InlineArray.items: InlineArrayItem[] (which extends InlineItem)\n * - InlineTable.items: InlineTableItem[] (which extends InlineItem)\n */\nexport type Block = KeyValue | Table | TableArray | Comment;\nexport function isBlock(node: TreeNode): node is Block {\n return isKeyValue(node) || isTable(node) || isTableArray(node) || isComment(node);\n}\n\nexport type Value<TInlineArrayItem = TreeNode> =\n | String\n | Integer\n | Float\n | Boolean\n | DateTime\n | InlineArray<TInlineArrayItem>\n | InlineTable;\nexport function isValue(node: TreeNode): node is Value {\n return (\n isString(node) ||\n isInteger(node) ||\n isFloat(node) ||\n isBoolean(node) ||\n isDateTime(node) ||\n isInlineArray(node) ||\n isInlineTable(node)\n );\n}\n\nexport interface TreeNode {\n type: NodeType;\n loc: Location;\n /** Absolute UTF-16 offsets into the source that produced this node. */\n readonly range?: readonly [number, number];\n /** Set on generated or mutated nodes and propagated to their ancestors. */\n dirty?: boolean;\n}\n"],"mappings":";;AA6CA,SAAgB,WAAW,MAAkC;CAC3D,OAAO,KAAK;AACd;AAoBA,SAAgB,QAAQ,MAA+B;CACrD,OAAO,KAAK;AACd;AAgBA,SAAgB,WAAW,MAAkC;CAC3D,OAAO,KAAK;AACd;;;;;;AA0BA,SAAgB,aAAa,MAAoC;CAC/D,OAAO,KAAK;AACd;AAeA,SAAgB,gBAAgB,MAAuC;CACrE,OAAO,KAAK;AACd;AAkBA,SAAgB,WAAW,MAAkC;CAC3D,OAAO,KAAK;AACd;AAgCA,SAAgB,SAAS,MAAgC;CACvD,OAAO,KAAK;AACd;AAwBA,SAAgB,QAAQ,MAA+B;CACrD,OAAO,KAAK;AACd;AA2BA,SAAgB,WAAW,MAAkC;CAC3D,OAAO,KAAK;AACd;AASA,SAAgB,cAAc,MAAqC;CACjE,OAAO,KAAK;AACd;AA2CA,SAAgB,aAAa,MAAoC;CAC/D,OAAO,KAAK;AACd;AAuBA,SAAgB,cAAc,MAAqC;CACjE,OAAO,KAAK;AACd;AA4BA,SAAgB,UAAU,MAAiC;CACzD,OAAO,KAAK;AACd;AAqBA,SAAgB,SAAS,MAAmC;CAC1D,OACE,WAAW,IAAI,KACf,QAAQ,IAAI,KACZ,aAAa,IAAI,KACjB,cAAc,IAAI,KAClB,cAAc,IAAI;AAEtB;AAKA,SAAgB,QAAQ,MAAkC;CACxD,OAAO,WAAW,IAAI,KAAK,gBAAgB,IAAI,KAAK,aAAa,IAAI;AACvE;AA2CA,SAAgB,QAAQ,MAA+B;CACrD,OAAO,WAAW,IAAI,KAAK,QAAQ,IAAI,KAAK,aAAa,IAAI,KAAK,UAAU,IAAI;AAClF"}
1
+ {"version":3,"file":"cst.js","names":[],"sources":["../../src/cst.ts"],"sourcesContent":["import { Location } from './location';\n\nexport enum NodeType {\n Document = 'Document',\n Table = 'Table',\n TableKey = 'TableKey',\n /**\n * Array of Tables node\n * More info: https://toml.io/en/latest#array-of-tables\n */\n TableArray = 'TableArray',\n TableArrayKey = 'TableArrayKey',\n KeyValue = 'KeyValue',\n Key = 'Key',\n String = 'String',\n Integer = 'Integer',\n Float = 'Float',\n Boolean = 'Boolean',\n DateTime = 'DateTime',\n InlineArray = 'InlineArray',\n InlineItem = 'InlineItem',\n InlineTable = 'InlineTable',\n /**\n * Comment node\n * More info: https://toml.io/en/latest#comment\n */\n Comment = 'Comment'\n}\n\n//\n// Concrete Syntax Tree\n//\n// CST nodes are used to represent TOML data\n//\nexport type CST = Iterable<Block>;\n\n//\n// Document\n//\n// Top-level document that stores CST nodes\n//\nexport interface Document extends TreeNode {\n type: NodeType.Document;\n items: Array<Block>;\n}\nexport function isDocument(node: TreeNode): node is Document {\n return node.type === NodeType.Document;\n}\n\n//\n// Table\n//\n// Top-level object\n//\n// v-------|\n// [table] |\n// b = \"c\" |\n// |\n// # note |\n// ^--|\n// [b]\n//\nexport interface Table extends TreeNode {\n type: NodeType.Table;\n key: TableKey;\n items: RowItem[];\n}\nexport function isTable(node: TreeNode): node is Table {\n return node.type === NodeType.Table;\n}\n\n//\n// TableKey\n//\n// Used to store bracket information for Table keys\n//\n// loc includes brackets\n//\n// [ key ]\n// ^-------^\n//\nexport interface TableKey extends TreeNode {\n type: NodeType.TableKey;\n item: Key;\n}\nexport function isTableKey(node: TreeNode): node is TableKey {\n return node.type === NodeType.TableKey;\n}\n\n//\n// TableArray\n//\n// Top-level array item\n//\n// v---------|\n// [[array]] |\n// a=\"b\" |\n// |\n// # details |\n// ^-|\n// [[array]]\n//\nexport interface TableArray extends TreeNode {\n type: NodeType.TableArray;\n key: TableArrayKey;\n items: RowItem[];\n}\n\n/**\n * Is a TableArray (aka Array of Tables)\n * @param node \n * @returns \n */\nexport function isTableArray(node: TreeNode): node is TableArray {\n return node.type === NodeType.TableArray;\n}\n\n//\n// TableArrayKey\n//\n// Used to store bracket information for TableArray keys\n// loc includes brackets\n//\n// [[ key ]]\n// ^---------^\n//\nexport interface TableArrayKey extends TreeNode {\n type: NodeType.TableArrayKey;\n item: Key;\n}\nexport function isTableArrayKey(node: TreeNode): node is TableArrayKey {\n return node.type === NodeType.TableArrayKey;\n}\n\n//\n// KeyValue\n//\n// Key and Value nodes, with position information on equals sign\n//\n// key=\"value\" # note\n// ^---------^\n//\nexport interface KeyValue extends TreeNode {\n type: NodeType.KeyValue;\n key: Key;\n value: Value;\n\n // Column index (0-based) of the equals sign\n equals: number;\n}\nexport function isKeyValue(node: TreeNode): node is KeyValue {\n return node.type === NodeType.KeyValue;\n}\n\n//\n// Key\n//\n// Store raw key and parts (from dots)\n//\nexport interface Key extends TreeNode {\n type: NodeType.Key;\n raw: string;\n\n // Note: Array for keys with dots\n // e.g. a.b -> raw = 'a.b', value = ['a', 'b']\n value: string[];\n}\nexport function isKey(node: TreeNode): node is Key {\n return node.type === NodeType.Key;\n}\n\n//\n// String\n//\n// loc includes quotes\n//\n// a = \"string\"\n// ^------^\n//\nexport interface String extends TreeNode {\n type: NodeType.String;\n raw: string;\n value: string;\n}\nexport function isString(node: TreeNode): node is String {\n return node.type === NodeType.String;\n}\n\n//\n// Integer\n//\nexport interface Integer extends TreeNode {\n type: NodeType.Integer;\n raw: string;\n value: number | bigint;\n}\nexport function isInteger(node: TreeNode): node is Integer {\n return node.type === NodeType.Integer;\n}\n\n//\n// Float\n//\nexport interface Float extends TreeNode {\n type: NodeType.Float;\n raw: string;\n value: number;\n /** Sign prefix for NaN values: '+' for +nan, '-' for -nan, undefined for nan */\n nanSign?: '+' | '-';\n}\nexport function isFloat(node: TreeNode): node is Float {\n return node.type === NodeType.Float;\n}\n\n//\n// Boolean\n//\nexport interface Boolean extends TreeNode {\n type: NodeType.Boolean;\n\n // Only `true` and `false` are permitted\n // -> don't need separate raw and value\n value: boolean;\n}\nexport function isBoolean(node: TreeNode): node is Boolean {\n return node.type === NodeType.Boolean;\n}\n\n//\n// DateTime\n//\n// Note: Currently, Offset Date-Time, Local Date-Time, Local Date, and Local Time\n// are handled via raw\n//\nexport interface DateTime extends TreeNode {\n type: NodeType.DateTime;\n raw: string;\n value: Date;\n}\nexport function isDateTime(node: TreeNode): node is DateTime {\n return node.type === NodeType.DateTime;\n}\n\n//\n// InlineArray\n//\nexport interface InlineArray<TItem = TreeNode> extends TreeNode {\n type: NodeType.InlineArray;\n items: InlineArrayItem<TItem>[];\n}\nexport function isInlineArray(node: TreeNode): node is InlineArray {\n return node.type === NodeType.InlineArray;\n}\n\n// InlineItem (internal CST wrapper — not a TOML spec concept)\n//\n// InlineItem is a container node that wraps each element inside an inline\n// container (InlineArray or InlineTable). It carries two responsibilities:\n//\n// 1. Tracking the comma that follows the element (comma: boolean).\n// When the element is the last one in the container, `comma` may be\n// false (no trailing comma) or true (trailing comma, TOML 1.1+).\n//\n// 2. Providing a stable \"slot\" node in the parent's .items array so that\n// the writer can apply positional offsets independently of the wrapped\n// value node itself.\n//\n// It is generic over TItem so that the two concrete subtypes can constrain\n// what they wrap:\n//\n// InlineArrayItem<TItem> — wraps any Value (scalar, array, inline table)\n// InlineTableItem — always wraps a KeyValue\n//\n// Location:\n// loc spans from the start of the wrapped value to the character just\n// before the comma (or the end of the value when there is no comma).\n//\n// [ \"a\" ,\"b\", \"c\" ]\n// ^---^ ^-^ ^-^\n//\n// { a = 1 , b = 2 }\n// ^---^ ^---^\n//\n// Note on findByPath traversal:\n// When navigating a path into an InlineArray, findByPath matches numeric\n// indices to InlineArrayItem positions. When the wrapped item is an\n// InlineTable and the path has further segments to resolve, traversal\n// continues into item.item (the InlineTable), not into the InlineItem\n// wrapper itself (which has no .items of its own).\n//\nexport interface InlineItem<TItem = TreeNode> extends TreeNode {\n type: NodeType.InlineItem;\n item: TItem;\n comma: boolean;\n}\nexport function isInlineItem(node: TreeNode): node is InlineItem {\n return node.type === NodeType.InlineItem;\n}\n\n// InlineArrayItem — semantic alias for InlineItem used as the element type of\n// InlineArray.items. It adds no fields; its existence is purely documentary:\n// naming the subtype makes the array-vs-table distinction visible in type\n// annotations without requiring an extra runtime check.\n//\n// TItem can be any Value: a scalar (String, Integer, …), a nested InlineArray,\n// or an InlineTable. The generic parameter is propagated so that typed arrays\n// such as InlineArray<String> carry their element type through to the items.\n//\n// [ \"a\" ,\"b\", \"c\" ]\n// ^---^ ^-^ ^-^ ← each element is an InlineArrayItem\n//\nexport interface InlineArrayItem<TItem = TreeNode> extends InlineItem<TItem> {}\n\n//\n// InlineTable\n//\nexport interface InlineTable extends TreeNode {\n type: NodeType.InlineTable;\n items: InlineTableItem[];\n}\nexport function isInlineTable(node: TreeNode): node is InlineTable {\n return node.type === NodeType.InlineTable;\n}\n\n// InlineTableItem — semantic alias for InlineItem<KeyValue> used as the element type\n// of InlineTable.items. It adds no fields; its existence is purely documentary:\n// naming the subtype makes the array-vs-table distinction visible in type\n// annotations without requiring an extra runtime check.\n//\n// The type parameter is fixed to KeyValue, which means the unsafe cast\n// `existing.item as KeyValue` that previously appeared in patch.ts is\n// unnecessary — the type system already guarantees it.\n//\n// { a=\"b\" , c = \"d\" }\n// ^------^ ^--------^ ← each element is an InlineTableItem\n//\nexport interface InlineTableItem extends InlineItem<KeyValue> {}\n\n//\n// Comment\n//\n// loc starts at \"#\" and goes to end of comment (trailing whitespace ignored)\n//\n// # comment here\n// ^------------^\n//\nexport interface Comment extends TreeNode {\n type: NodeType.Comment;\n raw: string;\n}\nexport function isComment(node: TreeNode): node is Comment {\n return node.type === NodeType.Comment;\n}\n\n//\n// Combinations\n//\n\n/**\n * RowItem represents items that can appear inside Table and TableArray sections.\n * These are the items that form the \"rows\" of content within table structures.\n * \n * Unlike Block items (which include Table and TableArray), RowItems can only be\n * KeyValue pairs and Comments - you cannot have nested tables within a table section.\n */\nexport type RowItem = KeyValue | Comment;\nexport function isRowItem(node: TreeNode): node is RowItem {\n return isKeyValue(node) || isComment(node);\n}\n\nexport interface WithItems extends TreeNode {\n items: TreeNode[];\n}\nexport function hasItems(node: TreeNode): node is WithItems {\n return (\n isDocument(node) ||\n isTable(node) ||\n isTableArray(node) ||\n isInlineTable(node) ||\n isInlineArray(node)\n );\n}\n\nexport interface WithItem extends TreeNode {\n item: TreeNode;\n}\nexport function hasItem(node: TreeNode): node is WithItem {\n return isTableKey(node) || isTableArrayKey(node) || isInlineItem(node);\n}\n\n/**\n * Block represents items that can appear at the root level (Document level) in TOML.\n * \n * Context and Usage:\n * - Block items are the fundamental top-level constructs in a TOML document\n * - They appear directly in Document containers and regular Table sections\n * - This is in contrast to InlineItems, which appear within inline containers\n * \n * Important Distinction:\n * - Table and TableArray can ONLY exist as Block items (they cannot appear inside inline containers)\n * - KeyValue and Comment can exist as BOTH Block items AND as InlineItems:\n * * As Block: When they appear at root level or inside regular Table sections\n * * As InlineItem: When they appear inside InlineTable or InlineArray containers\n * \n * Examples:\n * ```toml\n * # These are Block items at root level:\n * name = \"value\" # KeyValue as Block\n * # This is a comment # Comment as Block\n * [table] # Table as Block\n * [[array]] # TableArray as Block\n * \n * # These are Block items inside a Table:\n * [config]\n * setting = \"value\" # KeyValue as Block (inside Table)\n * # comment here # Comment as Block (inside Table)\n * \n * # These are InlineItems (NOT Block items):\n * array = [ \"a\", \"b\" ] # \"a\", \"b\" are InlineItems\n * table = { key = \"value\" } # key=\"value\" is InlineItem\n * ```\n * \n * Type Safety:\n * This distinction is crucial for the CST structure because:\n * - Document.items: Block[]\n * - Table.items: RowItem[] (KeyValue | Comment)\n * - TableArray.items: RowItem[] (KeyValue | Comment)\n * - InlineArray.items: InlineArrayItem[] (which extends InlineItem)\n * - InlineTable.items: InlineTableItem[] (which extends InlineItem)\n */\nexport type Block = KeyValue | Table | TableArray | Comment;\nexport function isBlock(node: TreeNode): node is Block {\n return isKeyValue(node) || isTable(node) || isTableArray(node) || isComment(node);\n}\n\nexport type Value<TInlineArrayItem = TreeNode> =\n | String\n | Integer\n | Float\n | Boolean\n | DateTime\n | InlineArray<TInlineArrayItem>\n | InlineTable;\nexport function isValue(node: TreeNode): node is Value {\n return (\n isString(node) ||\n isInteger(node) ||\n isFloat(node) ||\n isBoolean(node) ||\n isDateTime(node) ||\n isInlineArray(node) ||\n isInlineTable(node)\n );\n}\n\nexport interface TreeNode {\n type: NodeType;\n loc: Location;\n /** Absolute UTF-16 offsets into the source that produced this node. */\n readonly range?: readonly [number, number];\n /** Set on generated or mutated nodes and propagated to their ancestors. */\n dirty?: boolean;\n}\n"],"mappings":";;AA6CA,SAAgB,WAAW,MAAkC;CAC3D,OAAO,KAAK;AACd;AAoBA,SAAgB,QAAQ,MAA+B;CACrD,OAAO,KAAK;AACd;AAgBA,SAAgB,WAAW,MAAkC;CAC3D,OAAO,KAAK;AACd;;;;;;AA0BA,SAAgB,aAAa,MAAoC;CAC/D,OAAO,KAAK;AACd;AAeA,SAAgB,gBAAgB,MAAuC;CACrE,OAAO,KAAK;AACd;AAkBA,SAAgB,WAAW,MAAkC;CAC3D,OAAO,KAAK;AACd;AAgCA,SAAgB,SAAS,MAAgC;CACvD,OAAO,KAAK;AACd;AAUA,SAAgB,UAAU,MAAiC;CACzD,OAAO,KAAK;AACd;AAYA,SAAgB,QAAQ,MAA+B;CACrD,OAAO,KAAK;AACd;AAYA,SAAgB,UAAU,MAAiC;CACzD,OAAO,KAAK;AACd;AAaA,SAAgB,WAAW,MAAkC;CAC3D,OAAO,KAAK;AACd;AASA,SAAgB,cAAc,MAAqC;CACjE,OAAO,KAAK;AACd;AA2CA,SAAgB,aAAa,MAAoC;CAC/D,OAAO,KAAK;AACd;AAuBA,SAAgB,cAAc,MAAqC;CACjE,OAAO,KAAK;AACd;AA4BA,SAAgB,UAAU,MAAiC;CACzD,OAAO,KAAK;AACd;AAqBA,SAAgB,SAAS,MAAmC;CAC1D,OACE,WAAW,IAAI,KACf,QAAQ,IAAI,KACZ,aAAa,IAAI,KACjB,cAAc,IAAI,KAClB,cAAc,IAAI;AAEtB;AAKA,SAAgB,QAAQ,MAAkC;CACxD,OAAO,WAAW,IAAI,KAAK,gBAAgB,IAAI,KAAK,aAAa,IAAI;AACvE;AA2CA,SAAgB,QAAQ,MAA+B;CACrD,OAAO,WAAW,IAAI,KAAK,QAAQ,IAAI,KAAK,aAAa,IAAI,KAAK,UAAU,IAAI;AAClF;AAUA,SAAgB,QAAQ,MAA+B;CACrD,OACE,SAAS,IAAI,KACb,UAAU,IAAI,KACd,QAAQ,IAAI,KACZ,UAAU,IAAI,KACd,WAAW,IAAI,KACf,cAAc,IAAI,KAClB,cAAc,IAAI;AAEtB"}
@@ -1,4 +1,4 @@
1
- //! @decimalturn/toml-patch v3.1.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
2
  //#region src/cursor.ts
3
3
  /**
4
4
  * Cursor<T>
@@ -1,4 +1,4 @@
1
- //! @decimalturn/toml-patch v3.1.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
2
  //#region src/date-format.ts
3
3
  /**
4
4
  * Central module for TOML date/time format handling and custom date classes.
@@ -1,4 +1,4 @@
1
- //! @decimalturn/toml-patch v3.1.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
2
  //#region src/decode-utf8.ts
3
3
  /**
4
4
  * Decodes UTF-8 bytes in fatal mode, preserving any leading BOM.
@@ -0,0 +1,123 @@
1
+ //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
+ import { datesEqual, isNegativeNan, isObject, sameValue, stableStringify } from "./utils.js";
3
+
4
+ //#region src/diff-lite.ts
5
+ var PatchLiteError = class extends Error {
6
+ code;
7
+ path;
8
+ constructor(code, path, message) {
9
+ super(message);
10
+ this.name = "PatchLiteError";
11
+ this.code = code;
12
+ this.path = path;
13
+ }
14
+ };
15
+ /**
16
+ * Formats a path as `a.b[0].c` for error messages.
17
+ */
18
+ function formatPath(path) {
19
+ let out = "";
20
+ for (const segment of path) if (typeof segment === "number") out += `[${segment}]`;
21
+ else out += out ? `.${segment}` : segment;
22
+ return out || "(root)";
23
+ }
24
+ function isSupportedLeaf(value) {
25
+ const type = typeof value;
26
+ return type === "string" || type === "boolean" || type === "number" || type === "bigint";
27
+ }
28
+ function describe(value) {
29
+ if (value === null) return "null";
30
+ if (Array.isArray(value)) return "array";
31
+ if (value instanceof Date) return "date";
32
+ const type = typeof value;
33
+ return type === "object" ? "table" : type;
34
+ }
35
+ function sameNanSign(a, b) {
36
+ return isNegativeNan(a) === isNegativeNan(b);
37
+ }
38
+ /**
39
+ * Classifies a Date subclass by the shape of its TOML rendering, duck-typed so
40
+ * the lite bundle needs neither toml-patch's nor smol-toml's date module. The
41
+ * two packages have distinct class objects, so `instanceof` cannot be used to
42
+ * recognise them anyway.
43
+ */
44
+ function dateKind(value) {
45
+ const iso = value.toISOString();
46
+ if (/^\d{4}-\d{2}-\d{2}$/.test(iso)) return "date";
47
+ if (/^\d{2}:\d{2}:\d{2}(?:\.\d+)?$/.test(iso)) return "time";
48
+ if (/(?:[Zz]|[+-]\d{2}:\d{2})$/.test(iso)) return "offset";
49
+ return "datetime";
50
+ }
51
+ /**
52
+ * Dates are unchanged when they hold the same instant and the same TOML kind.
53
+ * Fractional seconds must not be compared by their rendered digit count:
54
+ * smol-toml always writes three digits (`.250`, `.000`) while toml-patch keeps
55
+ * the source precision (`.25`, or no suffix), so `getTime()` plus kind is used
56
+ * instead of `toISOString()`.
57
+ */
58
+ function sameDateValue(a, b) {
59
+ return a.getTime() === b.getTime() && dateKind(a) === dateKind(b);
60
+ }
61
+ /**
62
+ * Compares the existing and updated JavaScript values and returns the list of
63
+ * in-place edits. Any structural difference throws a `PatchLiteError` before
64
+ * the source is mutated.
65
+ */
66
+ function diffLite(before, after, path = []) {
67
+ if (datesEqual(before, after)) return [];
68
+ if (before instanceof Date && after instanceof Date && sameDateValue(before, after)) return [];
69
+ if (sameValue(before, after)) return [];
70
+ if (typeof before === "number" && typeof after === "number" && Number.isNaN(before) && Number.isNaN(after) && sameNanSign(before, after)) return [];
71
+ const beforeIsArray = Array.isArray(before);
72
+ const afterIsArray = Array.isArray(after);
73
+ if (beforeIsArray && afterIsArray) return compareArrays(before, after, path);
74
+ if (beforeIsArray || afterIsArray) throw new PatchLiteError("TypeChange", path, `Cannot change a ${beforeIsArray ? "array" : describe(before)} to a ${afterIsArray ? "array" : describe(after)} at ${formatPath(path)}`);
75
+ const beforeIsObject = isObject(before);
76
+ const afterIsObject = isObject(after);
77
+ if (beforeIsObject && afterIsObject) return compareObjects(before, after, path);
78
+ if (beforeIsObject || afterIsObject) throw new PatchLiteError("TypeChange", path, `Cannot change a ${beforeIsObject ? "table" : describe(before)} to a ${afterIsObject ? "table" : describe(after)} at ${formatPath(path)}`);
79
+ if (before instanceof Date && after instanceof Date) return [{
80
+ type: "Edit",
81
+ path
82
+ }];
83
+ if (before instanceof Date || after instanceof Date) throw new PatchLiteError("TypeChange", path, `Cannot change a ${describe(before)} to a ${describe(after)} at ${formatPath(path)}`);
84
+ if (!isSupportedLeaf(before) || !isSupportedLeaf(after)) throw new PatchLiteError("UnsupportedValue", path, `Unsupported value type ${describe(after)} at ${formatPath(path)}`);
85
+ return [{
86
+ type: "Edit",
87
+ path
88
+ }];
89
+ }
90
+ function compareObjects(before, after, path) {
91
+ const beforeKeys = Object.keys(before);
92
+ const afterKeys = Object.keys(after);
93
+ const afterKeySet = new Set(afterKeys);
94
+ for (const key of beforeKeys) if (!afterKeySet.has(key)) throw new PatchLiteError("RemovedKey", path.concat(key), `Cannot remove key ${formatPath(path.concat(key))}`);
95
+ const beforeKeySet = new Set(beforeKeys);
96
+ for (const key of afterKeys) if (!beforeKeySet.has(key)) throw new PatchLiteError("AddedKey", path.concat(key), `Cannot add key ${formatPath(path.concat(key))}`);
97
+ const changes = [];
98
+ for (const key of beforeKeys) {
99
+ const sub = diffLite(before[key], after[key], path.concat(key));
100
+ for (const change of sub) changes.push(change);
101
+ }
102
+ return changes;
103
+ }
104
+ function compareArrays(before, after, path) {
105
+ if (before.length !== after.length) throw new PatchLiteError("ArrayLengthChange", path, `Cannot change the length of array at ${formatPath(path)} (${before.length} to ${after.length})`);
106
+ const beforeStable = before.map(stableStringify);
107
+ const afterStable = after.map(stableStringify);
108
+ if (!beforeStable.every((value, index) => value === afterStable[index])) {
109
+ const beforeBag = beforeStable.slice().sort();
110
+ const afterBag = afterStable.slice().sort();
111
+ if (beforeBag.length === afterBag.length && beforeBag.every((value, index) => value === afterBag[index])) throw new PatchLiteError("ArrayReorder", path, `Cannot reorder array elements at ${formatPath(path)}`);
112
+ }
113
+ const changes = [];
114
+ for (let index = 0; index < before.length; index++) {
115
+ const sub = diffLite(before[index], after[index], path.concat(index));
116
+ for (const change of sub) changes.push(change);
117
+ }
118
+ return changes;
119
+ }
120
+
121
+ //#endregion
122
+ export { PatchLiteError, diffLite as default, formatPath };
123
+ //# sourceMappingURL=diff-lite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff-lite.js","names":[],"sources":["../../src/diff-lite.ts"],"sourcesContent":["import { isObject, datesEqual, stableStringify, sameValue, isNegativeNan } from './utils';\n\n/**\n * A path into a JavaScript object, mixing object keys and array indices.\n */\nexport type Path = Array<string | number>;\n\n/**\n * The only change patch-lite can apply: replacing an existing value in place.\n */\nexport interface Edit {\n type: 'Edit';\n path: Path;\n}\n\n/**\n * The unsupported operations patch-lite rejects. The code is part of the\n * public error contract so callers can branch on it without parsing messages.\n */\nexport type PatchLiteErrorCode =\n | 'AddedKey'\n | 'RemovedKey'\n | 'ArrayLengthChange'\n | 'ArrayReorder'\n | 'TypeChange'\n | 'UnsupportedValue'\n | 'UnsupportedOption';\n\nexport class PatchLiteError extends Error {\n readonly code: PatchLiteErrorCode;\n readonly path: Path;\n\n constructor(code: PatchLiteErrorCode, path: Path, message: string) {\n super(message);\n this.name = 'PatchLiteError';\n this.code = code;\n this.path = path;\n }\n}\n\n/**\n * Formats a path as `a.b[0].c` for error messages.\n */\nexport function formatPath(path: Path): string {\n let out = '';\n for (const segment of path) {\n if (typeof segment === 'number') out += `[${segment}]`;\n else out += out ? `.${segment}` : segment;\n }\n return out || '(root)';\n}\n\nfunction isSupportedLeaf(value: any): boolean {\n const type = typeof value;\n return type === 'string' || type === 'boolean' || type === 'number' || type === 'bigint';\n}\n\nfunction describe(value: any): string {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n if (value instanceof Date) return 'date';\n const type = typeof value;\n return type === 'object' ? 'table' : type;\n}\n\nfunction sameNanSign(a: number, b: number): boolean {\n return isNegativeNan(a) === isNegativeNan(b);\n}\n\n/**\n * Classifies a Date subclass by the shape of its TOML rendering, duck-typed so\n * the lite bundle needs neither toml-patch's nor smol-toml's date module. The\n * two packages have distinct class objects, so `instanceof` cannot be used to\n * recognise them anyway.\n */\nfunction dateKind(value: Date): 'date' | 'time' | 'datetime' | 'offset' {\n const iso = value.toISOString();\n if (/^\\d{4}-\\d{2}-\\d{2}$/.test(iso)) return 'date';\n if (/^\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?$/.test(iso)) return 'time';\n if (/(?:[Zz]|[+-]\\d{2}:\\d{2})$/.test(iso)) return 'offset';\n return 'datetime';\n}\n\n/**\n * Dates are unchanged when they hold the same instant and the same TOML kind.\n * Fractional seconds must not be compared by their rendered digit count:\n * smol-toml always writes three digits (`.250`, `.000`) while toml-patch keeps\n * the source precision (`.25`, or no suffix), so `getTime()` plus kind is used\n * instead of `toISOString()`.\n */\nfunction sameDateValue(a: Date, b: Date): boolean {\n return a.getTime() === b.getTime() && dateKind(a) === dateKind(b);\n}\n\n/**\n * Compares the existing and updated JavaScript values and returns the list of\n * in-place edits. Any structural difference throws a `PatchLiteError` before\n * the source is mutated.\n */\nexport default function diffLite(before: any, after: any, path: Path = []): Edit[] {\n if (datesEqual(before, after)) return [];\n\n if (before instanceof Date && after instanceof Date && sameDateValue(before, after)) {\n return [];\n }\n\n if (sameValue(before, after)) return [];\n\n if (\n typeof before === 'number' &&\n typeof after === 'number' &&\n Number.isNaN(before) &&\n Number.isNaN(after) &&\n sameNanSign(before, after)\n ) {\n return [];\n }\n\n const beforeIsArray = Array.isArray(before);\n const afterIsArray = Array.isArray(after);\n\n if (beforeIsArray && afterIsArray) {\n return compareArrays(before, after, path);\n }\n\n if (beforeIsArray || afterIsArray) {\n throw new PatchLiteError(\n 'TypeChange',\n path,\n `Cannot change a ${beforeIsArray ? 'array' : describe(before)} to a ${\n afterIsArray ? 'array' : describe(after)\n } at ${formatPath(path)}`\n );\n }\n\n const beforeIsObject = isObject(before);\n const afterIsObject = isObject(after);\n\n if (beforeIsObject && afterIsObject) {\n return compareObjects(before, after, path);\n }\n\n if (beforeIsObject || afterIsObject) {\n throw new PatchLiteError(\n 'TypeChange',\n path,\n `Cannot change a ${beforeIsObject ? 'table' : describe(before)} to a ${\n afterIsObject ? 'table' : describe(after)\n } at ${formatPath(path)}`\n );\n }\n\n if (before instanceof Date && after instanceof Date) {\n return [{ type: 'Edit', path }];\n }\n\n if (before instanceof Date || after instanceof Date) {\n throw new PatchLiteError(\n 'TypeChange',\n path,\n `Cannot change a ${describe(before)} to a ${describe(after)} at ${formatPath(path)}`\n );\n }\n\n if (!isSupportedLeaf(before) || !isSupportedLeaf(after)) {\n throw new PatchLiteError(\n 'UnsupportedValue',\n path,\n `Unsupported value type ${describe(after)} at ${formatPath(path)}`\n );\n }\n\n return [{ type: 'Edit', path }];\n}\n\nfunction compareObjects(before: any, after: any, path: Path): Edit[] {\n // Only key membership matters, not key order: patch-lite edits values by\n // path and never reorders keys, so the key order of `after` does not affect\n // the output and is intentionally ignored.\n const beforeKeys = Object.keys(before);\n const afterKeys = Object.keys(after);\n\n const afterKeySet = new Set(afterKeys);\n for (const key of beforeKeys) {\n if (!afterKeySet.has(key)) {\n throw new PatchLiteError(\n 'RemovedKey',\n path.concat(key),\n `Cannot remove key ${formatPath(path.concat(key))}`\n );\n }\n }\n\n const beforeKeySet = new Set(beforeKeys);\n for (const key of afterKeys) {\n if (!beforeKeySet.has(key)) {\n throw new PatchLiteError(\n 'AddedKey',\n path.concat(key),\n `Cannot add key ${formatPath(path.concat(key))}`\n );\n }\n }\n\n const changes: Edit[] = [];\n for (const key of beforeKeys) {\n const sub = diffLite(before[key], after[key], path.concat(key));\n for (const change of sub) changes.push(change);\n }\n return changes;\n}\n\nfunction compareArrays(before: any[], after: any[], path: Path): Edit[] {\n if (before.length !== after.length) {\n throw new PatchLiteError(\n 'ArrayLengthChange',\n path,\n `Cannot change the length of array at ${formatPath(path)} (${before.length} to ${after.length})`\n );\n }\n\n // A reorder keeps the same multiset of elements but changes their order.\n // Detect it via stable deep forms so genuine element edits still pass.\n const beforeStable = before.map(stableStringify);\n const afterStable = after.map(stableStringify);\n\n const positionsDiffer = !beforeStable.every((value, index) => value === afterStable[index]);\n if (positionsDiffer) {\n const beforeBag = beforeStable.slice().sort();\n const afterBag = afterStable.slice().sort();\n const sameElements =\n beforeBag.length === afterBag.length &&\n beforeBag.every((value, index) => value === afterBag[index]);\n\n if (sameElements) {\n throw new PatchLiteError(\n 'ArrayReorder',\n path,\n `Cannot reorder array elements at ${formatPath(path)}`\n );\n }\n }\n\n const changes: Edit[] = [];\n for (let index = 0; index < before.length; index++) {\n const sub = diffLite(before[index], after[index], path.concat(index));\n for (const change of sub) changes.push(change);\n }\n return changes;\n}\n"],"mappings":";;;;AA4BA,IAAa,iBAAb,cAAoC,MAAM;CACxC,AAAS;CACT,AAAS;CAET,YAAY,MAA0B,MAAY,SAAiB;EACjE,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;;AAKA,SAAgB,WAAW,MAAoB;CAC7C,IAAI,MAAM;CACV,KAAK,MAAM,WAAW,MACp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package/dist/dev/diff.js CHANGED
@@ -1,5 +1,5 @@
1
- //! @decimalturn/toml-patch v3.1.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
- import { datesEqual, isObject, merge, stableStringify } from "./utils.js";
1
+ //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
+ import { datesEqual, isNegativeNan, isObject, merge, sameValue, stableStringify } from "./utils.js";
3
3
 
4
4
  //#region src/diff.ts
5
5
  function isAdd(change) {
@@ -18,13 +18,9 @@ function isRename(change) {
18
18
  return change.type === "Rename";
19
19
  }
20
20
  function diff(before, after, path = [], options = {}) {
21
- if (before === after || datesEqual(before, after)) return [];
21
+ if (sameValue(before, after) || datesEqual(before, after)) return [];
22
22
  if (typeof before === "number" && typeof after === "number" && Number.isNaN(before) && Number.isNaN(after)) {
23
- const bufBefore = new Float64Array([before]);
24
- const bufAfter = new Float64Array([after]);
25
- const viewBefore = new DataView(bufBefore.buffer);
26
- const viewAfter = new DataView(bufAfter.buffer);
27
- if ((viewBefore.getUint32(4, true) & 2147483648) === (viewAfter.getUint32(4, true) & 2147483648)) return [];
23
+ if (isNegativeNan(before) === isNegativeNan(after)) return [];
28
24
  }
29
25
  if (Array.isArray(before) && Array.isArray(after)) return compareArrays(before, after, path, options);
30
26
  else if (isObject(before) && isObject(after)) return compareObjects(before, after, path, options);
@@ -1 +1 @@
1
- {"version":3,"file":"diff.js","names":[],"sources":["../../src/diff.ts"],"sourcesContent":["import { isObject, datesEqual, stableStringify, merge } from './utils';\nimport { Path } from './find-by-path';\n\nexport enum ChangeType {\n Add = 'Add',\n Edit = 'Edit',\n Remove = 'Remove',\n Move = 'Move',\n Rename = 'Rename'\n}\n\nexport interface Add {\n type: ChangeType.Add;\n path: Path;\n /** Existing sibling key that the new member must be inserted before. */\n before?: string;\n}\nexport function isAdd(change: Change): change is Add {\n return change.type === ChangeType.Add;\n}\n\nexport interface Edit {\n type: ChangeType.Edit;\n path: Path;\n}\nexport function isEdit(change: Change): change is Edit {\n return change.type === ChangeType.Edit;\n}\n\nexport interface Remove {\n type: ChangeType.Remove;\n path: Path;\n /** Internal marker for array removes whose index refers to the original array. */\n coordinate?: 'source';\n}\nexport function isRemove(change: Change): change is Remove {\n return change.type === ChangeType.Remove;\n}\n\nexport interface Move {\n type: ChangeType.Move;\n path: Path;\n from: number;\n to: number;\n /** Present only for object-key moves (updateOrder); identifies the child to place. */\n key?: string;\n}\nexport function isMove(change: Change): change is Move {\n return change.type === ChangeType.Move;\n}\n\nexport interface Rename {\n type: ChangeType.Rename;\n path: Path;\n from: string;\n to: string;\n}\nexport function isRename(change: Change): change is Rename {\n return change.type === ChangeType.Rename;\n}\n\nexport type Change = Add | Edit | Remove | Move | Rename;\n\nexport interface DiffOptions {\n /**\n * When true, `compareObjects` additionally emits Moves so that object keys end up in the\n * same order as `after`'s. Off by default: a no-options `diff()` call emits zero Moves for\n * a pure key-order permutation, which is the compatibility guarantee callers rely on. See\n * docs/PLAN-Update-Order.md.\n */\n updateOrder?: boolean;\n /** Object graph whose key order represents the caller's requested order. */\n orderSource?: any;\n}\n\nexport default function diff(before: any, after: any, path: Path = [], options: DiffOptions = {}): Change[] {\n if (before === after || datesEqual(before, after)) {\n return [];\n }\n\n // Both NaN — treat as equal only if they have the same sign bit.\n // -NaN and NaN are distinguishable via IEEE 754, so a sign change\n // from negative NaN to canonical NaN should trigger an edit.\n if (typeof before === 'number' && typeof after === 'number'\n && Number.isNaN(before) && Number.isNaN(after)) {\n const bufBefore = new Float64Array([before]);\n const bufAfter = new Float64Array([after]);\n const viewBefore = new DataView(bufBefore.buffer);\n const viewAfter = new DataView(bufAfter.buffer);\n const signBefore = viewBefore.getUint32(4, true) & 0x80000000;\n const signAfter = viewAfter.getUint32(4, true) & 0x80000000;\n if (signBefore === signAfter) return [];\n // Sign differs — fall through to produce an Edit\n }\n\n if (Array.isArray(before) && Array.isArray(after)) {\n return compareArrays(before, after, path, options);\n } else if (isObject(before) && isObject(after)) {\n return compareObjects(before, after, path, options);\n } else {\n return [\n {\n type: ChangeType.Edit,\n path\n }\n ];\n }\n}\n\nfunction compareObjects(before: any, after: any, path: Path = [], options: DiffOptions = {}): Change[] {\n let changes: Change[] = [];\n\n // 1. Get keys and stable values\n const before_keys = Object.keys(before);\n const before_stable = before_keys.map(key => stableStringify(before[key]));\n const after_keys = Object.keys(after);\n const after_stable = after_keys.map(key => stableStringify(after[key]));\n const after_stable_by_key = new Map(\n after_keys.map((key, index) => [key, after_stable[index]])\n );\n\n // Membership is tested once per key in each pass below, so these are Sets rather than the\n // key arrays: `includes` inside those loops makes the whole function quadratic in the\n // number of keys, which is felt on wide tables — a 2000-key object spent ~28ms there.\n const before_key_set = new Set(before_keys);\n const after_key_set = new Set(after_keys);\n\n // A key that disappeared is inferred to have been renamed when a key appears holding the\n // same value, since a rename is never declared — value equality is the only signal.\n //\n // Several keys can share a value, so the candidates are grouped by value and paired off in\n // order, as many as both sides can supply. Preserving comments is the point of this\n // library, so a plausible pairing is worth more than declining to guess: a renamed node is\n // edited in place and keeps its comments and formatting, whereas a remove-plus-add loses\n // them. Where the pairing is genuinely ambiguous the choice is arbitrary but harmless in\n // kind — a comment lands on one interchangeable key rather than another. Patching in\n // smaller steps removes the ambiguity for callers who care which.\n //\n // Pairing by position is what keeps it one-to-one. Matching with `indexOf` always resolved\n // to the first candidate, so every equal-valued source claimed the same target:\n // `{a:1,b:1} -> {z:1}` emitted two renames onto `z`, and the second blanked its node's\n // key, giving ` = 1` — output that does not parse. Leftovers on either side fall through\n // to Remove or Add.\n //\n // Keys present on both sides are excluded from both groups: they were not renamed and are\n // not available as targets. That is what keeps a removal whose value happens to match an\n // untouched sibling from being read as a rename onto it (issue #262).\n //\n // Tracked as from -> to because step 4 (order emission) has to follow a rename through\n // rather than treating the old name as simply gone.\n const groupByValue = (keys: string[], stables: string[], exclude: Set<string>) => {\n const groups = new Map<string, string[]>();\n keys.forEach((key, index) => {\n if (exclude.has(key)) return;\n const group = groups.get(stables[index]);\n if (group) group.push(key);\n else groups.set(stables[index], [key]);\n });\n return groups;\n };\n\n const disappeared = groupByValue(before_keys, before_stable, after_key_set);\n const appeared = groupByValue(after_keys, after_stable, before_key_set);\n\n const renamed = new Map<string, string>();\n const renameTargets = new Set<string>();\n const renameSourcesByTarget = new Map<string, string>();\n\n for (const [value, sources] of disappeared) {\n const targets = appeared.get(value);\n if (!targets) continue;\n\n const pairs = Math.min(sources.length, targets.length);\n for (let i = 0; i < pairs; i++) {\n renamed.set(sources[i], targets[i]);\n renameTargets.add(targets[i]);\n renameSourcesByTarget.set(targets[i], sources[i]);\n }\n }\n\n // 2. Check for changes, rename, and removed\n before_keys.forEach((key, index) => {\n const sub_path = path.concat(key);\n if (after_key_set.has(key)) {\n const beforeValue = before[key];\n const afterValue = after[key];\n const hasNonFiniteNumber =\n (typeof beforeValue === 'number' && !Number.isFinite(beforeValue)) ||\n (typeof afterValue === 'number' && !Number.isFinite(afterValue));\n if (options.updateOrder || hasNonFiniteNumber ||\n before_stable[index] !== after_stable_by_key.get(key)) {\n merge(changes, diff(before[key], after[key], sub_path, options));\n }\n } else if (renamed.has(key)) {\n changes.push({\n type: ChangeType.Rename,\n path,\n from: key,\n to: renamed.get(key)!\n });\n } else {\n changes.push({\n type: ChangeType.Remove,\n path: sub_path\n });\n }\n });\n\n // 3. Check for additions\n after_keys.forEach(key => {\n if (!before_key_set.has(key) && !renameTargets.has(key)) {\n const add: Add = {\n type: ChangeType.Add,\n path: path.concat(key)\n };\n\n // Adds normally append. If the caller supplied the original object whose order\n // should be honoured, anchor this add before the next member that already has a\n // slot. A rename uses its old key as the anchor because the rename runs in place.\n if (options.orderSource !== undefined) {\n let orderObject = options.orderSource;\n for (const segment of path) orderObject = orderObject?.[segment as any];\n if (isObject(orderObject)) {\n const requestedKeys = Object.keys(orderObject);\n const addedIndex = requestedKeys.indexOf(key);\n for (let i = addedIndex + 1; i < requestedKeys.length; i++) {\n const target = requestedKeys[i];\n const source = renameSourcesByTarget.get(target)\n ?? (before_key_set.has(target) ? target : undefined);\n if (source !== undefined) {\n add.before = source;\n break;\n }\n }\n }\n }\n\n changes.push(add);\n }\n });\n\n let requestedKeys = after_keys;\n if (options.orderSource !== undefined) {\n let orderObject = options.orderSource;\n for (const segment of path) orderObject = orderObject?.[segment as any];\n if (isObject(orderObject)) {\n const afterKeySet = new Set(after_keys);\n requestedKeys = Object.keys(orderObject).filter(key => afterKeySet.has(key));\n }\n }\n\n // A renamed member keeps its existing CST slot, while an added member is appended\n // by the patcher. Emit direct Adds and Renames in the updated object order so an\n // added dotted member can land before a renamed sibling without patch.ts inspecting\n // the CST or the complete change list.\n const directChanges = changes.filter(change =>\n (isAdd(change) && change.path.length === path.length + 1) ||\n (isRename(change) && change.path.length === path.length)\n );\n if (options.orderSource !== undefined && directChanges.length > 1) {\n const orderedDirectChanges = [...directChanges].sort((a, b) => {\n const aKey = isAdd(a) ? a.path[a.path.length - 1] : isRename(a) ? a.to : '';\n const bKey = isAdd(b) ? b.path[b.path.length - 1] : isRename(b) ? b.to : '';\n return requestedKeys.indexOf(aKey as string) - requestedKeys.indexOf(bKey as string);\n });\n let directIndex = 0;\n changes = changes.map(change =>\n directChanges.includes(change) ? orderedDirectChanges[directIndex++] : change\n );\n }\n\n // 4. Order emission (updateOrder only). Predict the key order the document will have\n // once Add/Remove/Rename above are applied, then walk the target order emitting a Move\n // wherever the prediction and the target disagree, splicing the prediction to match as we\n // go — the same simulate-and-splice approach compareArrays already uses for Move.\n if (options.updateOrder) {\n const sim: string[] = [];\n for (const key of before_keys) {\n if (after_key_set.has(key)) {\n if (!sim.includes(key)) sim.push(key);\n } else if (renamed.has(key)) {\n // Guard against the pre-existing spurious-rename case ({a:1,b:1} -> {b:1,x:1} emits\n // Rename a->b even though b is unchanged) pushing a duplicate into sim.\n const to = renamed.get(key)!;\n if (!sim.includes(to)) sim.push(to);\n }\n // removed -> drop\n }\n for (const key of after_keys) {\n if (!sim.includes(key)) sim.push(key); // adds append\n }\n\n after_keys.forEach((key, targetIndex) => {\n if (sim[targetIndex] === key) return;\n\n const from = sim.indexOf(key);\n changes.push({\n type: ChangeType.Move,\n path,\n from,\n to: targetIndex,\n key\n });\n\n sim.splice(from, 1);\n sim.splice(targetIndex, 0, key);\n });\n }\n\n return changes;\n}\n\n// Multiline-formatting proxies, hoisted so compareArrays doesn't rebuild them\n// per call. See the layoutSensitiveArray comment in compareArrays.\nfunction hasMultilineValue(v: any): boolean {\n if (typeof v === 'string') return v.includes('\\n');\n if (Array.isArray(v)) return v.length > 0;\n if (v !== null && typeof v === 'object' && !(v instanceof Date)) {\n const vals = Object.values(v);\n return vals.some(x => x !== null && typeof x === 'object') || vals.some(hasMultilineValue);\n }\n return false;\n}\n\nfunction hasInlineObject(value: any): boolean {\n return value !== null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date);\n}\n\nfunction hasMixedStringAndObject(values: any[]): boolean {\n return values.length > 4 && values.some(value => typeof value === 'string') && values.some(hasInlineObject);\n}\n\nfunction compareArrays(before: any[], after: any[], path: Path = [], options: DiffOptions = {}): Change[] {\n let changes: Change[] = [];\n\n // 1. Convert arrays to stable objects\n const before_stable = before.map(stableStringify);\n const after_stable = after.map(stableStringify);\n\n // The writer corrupts multiline inline content when elements are relocated\n // (moves of elements holding multiline strings drop content lines — fuzz\n // seed 4765). Only for such arrays, prefer resolving a true deletion in\n // place over drifting the element right through a chain of Moves.\n // Multiline DELIMITED strings whose content is single-line aren't visible\n // here (the diff sees only values), but nested arrays/objects are a strong\n // proxy: those are what carry such formatting, and moving them corrupts\n // their interior the same way (fuzz seed 8512). A nested array or object\n // is itself evidence of multiline formatting even when its ELEMENTS are all\n // plain scalars — the formatter freely wraps such a container across lines,\n // and the diff cannot tell from values alone (fuzz seed 40181: removing a\n // scalar above a multiline `[218561, \"…\"]` chain-moved the array and dropped\n // columns out of its tail).\n const multilineArray = before.some(hasMultilineValue) || after.some(hasMultilineValue);\n const layoutSensitiveArray = multilineArray || hasMixedStringAndObject(before) || hasMixedStringAndObject(after);\n\n // Simulation of the actual VALUES, mutated in lockstep with before_stable.\n // The \"removed -> edited in place\" branch below must diff the element the\n // move simulation left at this index, not the untouched original: after a\n // Move, `before[index]` can hold a DIFFERENT element than the one whose\n // stable form sits at `before_stable[index]`, and diffing the wrong one\n // silently drops the edit (fuzz seed 340: `['4', …, true, …]` →\n // `[true, …]` moved `true` from 4 to 0, then diffed the original\n // `before[4]` — which was `true` — against `true`, emitting nothing for\n // the leftover string).\n const before_sim = before.slice();\n\n // Elements spliced out of `before` while walking the loop (the deletion\n // branch below). Remove paths are source coordinates — indices in the\n // ORIGINAL array — because the patcher applies same-array removals in\n // descending index order (see reorder() in patch.ts), so each emitted\n // index must stay valid against the un-shifted array.\n let removedBefore = 0;\n let sameArrayAddEmitted = false;\n\n const removeChange = (index: number): Remove => {\n const change: Remove = { type: ChangeType.Remove, path: path.concat(index) };\n if (!sameArrayAddEmitted || removedBefore > 0) {\n // Non-enumerable so `coordinate` stays out of the diff output that\n // callers and tests compare: it's an internal marker for reorder().\n Object.defineProperty(change, 'coordinate', { value: 'source' });\n }\n return change;\n };\n\n // 2. Step through after array making changes to before array as-needed\n for (let index = 0; index < after_stable.length; index++) {\n const value = after_stable[index];\n const overflow = index >= before_stable.length;\n\n // Check if items are the same\n if (!overflow && before_stable[index] === value) {\n continue;\n }\n\n // Check if item has been moved -> shift into place\n const from = overflow ? -1 : before_stable.indexOf(value, index + 1);\n if (from > -1) {\n // Is `before_stable[index]` (the mismatched element at this slot) a\n // surplus duplicate — more copies surviving in `before`'s unmatched\n // suffix than `after` demands? When so, the extra copy is genuinely\n // gone from this position and a removal in place is the honest edit.\n const valueAt = before_stable[index];\n let beforeCount = 0;\n for (let i = index; i < before_stable.length; i++) {\n if (before_stable[i] === valueAt) beforeCount++;\n }\n let afterCount = 0;\n for (let i = index; i < after_stable.length; i++) {\n if (after_stable[i] === valueAt) afterCount++;\n }\n const surplusDuplicate = beforeCount > afterCount;\n\n // A true deletion in move shape: the element at this position is\n // absent from `after` entirely (or is a surplus duplicate of a value\n // that later slots still hold), while the after-value sits later in\n // `before`. Without this the element only gets resolved at the end,\n // after a chain of Moves that relocates multiline elements — and the\n // writer corrupts their content (fuzz seed 4765: removing one scalar\n // from a multiline inline array dropped a line of a multiline string;\n // fuzz seed 35943: removing one of several duplicate scalars above a\n // nested multiline array chain-moved the array and corrupted its tail).\n if (layoutSensitiveArray && (after_stable.indexOf(before_stable[index]) === -1 || surplusDuplicate)) {\n changes.push(removeChange(index + removedBefore));\n before_stable.splice(index, 1);\n before_sim.splice(index, 1);\n removedBefore++;\n index--;\n continue;\n }\n\n // A Move emitted after an in-place deletion splice: its from/to are\n // simulation coordinates, but the patcher applies ALL removes first\n // (in descending index order) — when a trailing remove follows, the\n // move's source can be pushed out of bounds (fuzz seed 8138). When\n // the displaced element is a surplus duplicate, resolve it as a\n // removal in place instead of a Move: the remaining occurrences stay\n // where they are, so nothing needs to move.\n //\n // (Redundant with the surplus-duplicate removal above when\n // `layoutSensitiveArray` is set, but kept for the non-multiline case\n // where a prior splice already shifted indices and the surplus is\n // unambiguous.)\n if (removedBefore > 0 && surplusDuplicate) {\n changes.push(removeChange(index + removedBefore));\n before_stable.splice(index, 1);\n before_sim.splice(index, 1);\n removedBefore++;\n index--;\n continue;\n }\n\n // After an in-place removal this array is one element short at this\n // slot, so the after-value found later in `before` is NOT being\n // relocated — a fresh copy is needed here. Relocating it via a Move\n // drags multiline elements through a chain that later ADDs a new copy\n // anyway, and the writer corrupts their content (fuzz seed 62263: a\n // nested array above a multiline inline table replaced by a duplicate\n // scalar emitted Remove + Move + Add and mangled the table).\n if (layoutSensitiveArray && removedBefore > 0) {\n changes.push({\n type: ChangeType.Add,\n path: path.concat(index)\n });\n sameArrayAddEmitted = true;\n before_stable.splice(index, 0, value);\n before_sim.splice(index, 0, after[index]);\n // The fresh copy is spliced in BEFORE the original (at `from`), so it\n // shifts every later sim element — including the original we just\n // declined to move — one slot right. `removedBefore` models the\n // LEFT-shift of a prior remove, so a later Remove's source index\n // (`index + removedBefore`) is off by one and removes the wrong\n // element (fuzz seed 179377: `[false, '''…''', …]` edited and trimmed\n // removed its neighbour instead of the surplus scalar). Cancelling\n // one unit of the remove shift keeps the sim↔source mapping aligned.\n removedBefore--;\n continue;\n }\n\n changes.push({\n type: ChangeType.Move,\n path,\n from,\n to: index\n });\n\n const move = before_stable.splice(from, 1);\n before_stable.splice(index, 0, ...move);\n const moveValues = before_sim.splice(from, 1);\n before_sim.splice(index, 0, ...moveValues);\n\n continue;\n }\n\n // Check if item is removed -> assume it's been edited and replace.\n //\n // `after.includes(value)` alone is not enough: when the value also\n // occurs later in the array, the element is read as \"kept\", so the\n // mismatch becomes an Add plus a chain of Moves that re-finds the\n // duplicate — a pathological diff for a plain in-place edit (fuzz seed\n // 1406: `true` → `'4'` with another `true` later emitted Add(1) + six\n // Moves + Remove(10), and the writer corrupted a multiline string).\n // A duplicate further along in `before` can serve the later `after`\n // slot, so this occurrence is surplus whenever `before`'s unmatched\n // suffix holds more copies of the value than `after`'s does — then the\n // element is genuinely gone from its position and edited in place.\n let surplus = false;\n if (!overflow) {\n const value = before_stable[index];\n let beforeCount = 0;\n for (let i = index; i < before_stable.length; i++) {\n if (before_stable[i] === value) beforeCount++;\n }\n let afterCount = 0;\n for (let i = index; i < after_stable.length; i++) {\n if (after_stable[i] === value) afterCount++;\n }\n surplus = beforeCount > afterCount;\n }\n const removed = !overflow && surplus;\n if (removed) {\n merge(changes, diff(before_sim[index], after[index], path.concat(index), options));\n before_stable[index] = value;\n before_sim[index] = after[index];\n\n continue;\n }\n\n // Add as new item and shift existing\n changes.push({\n type: ChangeType.Add,\n path: path.concat(index)\n });\n sameArrayAddEmitted = true;\n before_stable.splice(index, 0, value);\n before_sim.splice(index, 0, after[index]);\n // Same source-index bookkeeping as the refused-move Add above: splicing a\n // new element in front of the surviving suffix shifts later sim indices\n // right by one, so a later Remove's source index (`index + removedBefore`)\n // is one too far right and targets the wrong element when a prior remove\n // is still pending. Cancel one unit of the remove shift (fuzz seed\n // 208822: editing a duplicate scalar and trimming a multiline array\n // removed the multiline string instead of the plain scalar).\n if (removedBefore > 0) removedBefore--;\n }\n\n // 3. Remove any remaining overflow items\n for (let i = after_stable.length; i < before_stable.length; i++) {\n changes.push(removeChange(i + removedBefore));\n }\n\n return changes;\n}\n"],"mappings":";;;;AAiBA,SAAgB,MAAM,QAA+B;CACnD,OAAO,OAAO;AAChB;AAMA,SAAgB,OAAO,QAAgC;CACrD,OAAO,OAAO;AAChB;AAQA,SAAgB,SAAS,QAAkC;CACzD,OAAO,OAAO;AAChB;AAUA,SAAgB,OAAO,QAAgC;CACrD,OAAO,OAAO;AAChB;AAQA,SAAgB,SAAS,QAAkC;CACzD,OAAO,OAAO;AAChB;AAgBA,SAAwB,KAAK,QAAa,OAAY,OAAa,CAAC,GAAG,UAAuB,CAAC,GAAa;CAC1G,IAAI,WAAW,SAAS,WAAW,QAAQ,KAAK,GAC9C,OAAO,CAAC;CAMV,IAAI,OAAO,WAAW,YAAY,OAAO,UAAU,YAC5C,OAAO,MAAM,MAAM,KAAK,OAAO,MAAM,KAAK,GAAG;EAClD,MAAM,YAAY,IAAI,aAAa,CAAC,MAAM,CAAC;EAC3C,MAAM,WAAW,IAAI,aAAa,CAAC,KAAK,CAAC;EACzC,MAAM,aAAa,IAAI,SAAS,UAAU,MAAM;EAChD,MAAM,YAAY,IAAI,SAAS,SAAS,MAAM;EAG9C,KAFmB,WAAW,UAAU,GAAG,IAAI,IAAI,iBACjC,UAAU,UAAU,GAAG,IAAI,IAAI,aACnB,OAAO,CAAC;CAExC;CAEA,IAAI,MAAM,QAAQ,MAAM,KAAK,MAAM,QAAQ,KAAK,GAC9C,OAAO,cAAc,QAAQ,OAAO,MAAM,OAAO;MAC5C,IAAI,SAAS,MAAM,KAAK,SAAS,KAAK,GAC3C,OAAO,eAAe,QAAQ,OAAO,MAAM,OAAO;MAElD,OAAO,CACL;EACE;EACA;CACF,CACF;AAEJ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, stableStringify, merge, sameValue, isNegativeNan } from './utils';\nimport { Path } from './find-by-path';\n\nexport enum ChangeType {\n Add = 'Add',\n Edit = 'Edit',\n Remove = 'Remove',\n Move = 'Move',\n Rename = 'Rename'\n}\n\nexport interface Add {\n type: ChangeType.Add;\n path: Path;\n /** Existing sibling key that the new member must be inserted before. */\n before?: string;\n}\nexport function isAdd(change: Change): change is Add {\n return change.type === ChangeType.Add;\n}\n\nexport interface Edit {\n type: ChangeType.Edit;\n path: Path;\n}\nexport function isEdit(change: Change): change is Edit {\n return change.type === ChangeType.Edit;\n}\n\nexport interface Remove {\n type: ChangeType.Remove;\n path: Path;\n /** Internal marker for array removes whose index refers to the original array. */\n coordinate?: 'source';\n}\nexport function isRemove(change: Change): change is Remove {\n return change.type === ChangeType.Remove;\n}\n\nexport interface Move {\n type: ChangeType.Move;\n path: Path;\n from: number;\n to: number;\n /** Present only for object-key moves (updateOrder); identifies the child to place. */\n key?: string;\n}\nexport function isMove(change: Change): change is Move {\n return change.type === ChangeType.Move;\n}\n\nexport interface Rename {\n type: ChangeType.Rename;\n path: Path;\n from: string;\n to: string;\n}\nexport function isRename(change: Change): change is Rename {\n return change.type === ChangeType.Rename;\n}\n\nexport type Change = Add | Edit | Remove | Move | Rename;\n\nexport interface DiffOptions {\n /**\n * When true, `compareObjects` additionally emits Moves so that object keys end up in the\n * same order as `after`'s. Off by default: a no-options `diff()` call emits zero Moves for\n * a pure key-order permutation, which is the compatibility guarantee callers rely on. See\n * docs/PLAN-Update-Order.md.\n */\n updateOrder?: boolean;\n /** Object graph whose key order represents the caller's requested order. */\n orderSource?: any;\n}\n\nexport default function diff(before: any, after: any, path: Path = [], options: DiffOptions = {}): Change[] {\n if (sameValue(before, after) || datesEqual(before, after)) {\n return [];\n }\n\n // Both NaN — treat as equal only if they have the same sign bit.\n // -NaN and NaN are distinguishable via IEEE 754, so a sign change\n // from negative NaN to canonical NaN should trigger an edit.\n if (typeof before === 'number' && typeof after === 'number'\n && Number.isNaN(before) && Number.isNaN(after)) {\n if (isNegativeNan(before) === isNegativeNan(after)) return [];\n // Sign differs — fall through to produce an Edit\n }\n\n if (Array.isArray(before) && Array.isArray(after)) {\n return compareArrays(before, after, path, options);\n } else if (isObject(before) && isObject(after)) {\n return compareObjects(before, after, path, options);\n } else {\n return [\n {\n type: ChangeType.Edit,\n path\n }\n ];\n }\n}\n\nfunction compareObjects(before: any, after: any, path: Path = [], options: DiffOptions = {}): Change[] {\n let changes: Change[] = [];\n\n // 1. Get keys and stable values\n const before_keys = Object.keys(before);\n const before_stable = before_keys.map(key => stableStringify(before[key]));\n const after_keys = Object.keys(after);\n const after_stable = after_keys.map(key => stableStringify(after[key]));\n const after_stable_by_key = new Map(\n after_keys.map((key, index) => [key, after_stable[index]])\n );\n\n // Membership is tested once per key in each pass below, so these are Sets rather than the\n // key arrays: `includes` inside those loops makes the whole function quadratic in the\n // number of keys, which is felt on wide tables — a 2000-key object spent ~28ms there.\n const before_key_set = new Set(before_keys);\n const after_key_set = new Set(after_keys);\n\n // A key that disappeared is inferred to have been renamed when a key appears holding the\n // same value, since a rename is never declared — value equality is the only signal.\n //\n // Several keys can share a value, so the candidates are grouped by value and paired off in\n // order, as many as both sides can supply. Preserving comments is the point of this\n // library, so a plausible pairing is worth more than declining to guess: a renamed node is\n // edited in place and keeps its comments and formatting, whereas a remove-plus-add loses\n // them. Where the pairing is genuinely ambiguous the choice is arbitrary but harmless in\n // kind — a comment lands on one interchangeable key rather than another. Patching in\n // smaller steps removes the ambiguity for callers who care which.\n //\n // Pairing by position is what keeps it one-to-one. Matching with `indexOf` always resolved\n // to the first candidate, so every equal-valued source claimed the same target:\n // `{a:1,b:1} -> {z:1}` emitted two renames onto `z`, and the second blanked its node's\n // key, giving ` = 1` — output that does not parse. Leftovers on either side fall through\n // to Remove or Add.\n //\n // Keys present on both sides are excluded from both groups: they were not renamed and are\n // not available as targets. That is what keeps a removal whose value happens to match an\n // untouched sibling from being read as a rename onto it (issue #262).\n //\n // Tracked as from -> to because step 4 (order emission) has to follow a rename through\n // rather than treating the old name as simply gone.\n const groupByValue = (keys: string[], stables: string[], exclude: Set<string>) => {\n const groups = new Map<string, string[]>();\n keys.forEach((key, index) => {\n if (exclude.has(key)) return;\n const group = groups.get(stables[index]);\n if (group) group.push(key);\n else groups.set(stables[index], [key]);\n });\n return groups;\n };\n\n const disappeared = groupByValue(before_keys, before_stable, after_key_set);\n const appeared = groupByValue(after_keys, after_stable, before_key_set);\n\n const renamed = new Map<string, string>();\n const renameTargets = new Set<string>();\n const renameSourcesByTarget = new Map<string, string>();\n\n for (const [value, sources] of disappeared) {\n const targets = appeared.get(value);\n if (!targets) continue;\n\n const pairs = Math.min(sources.length, targets.length);\n for (let i = 0; i < pairs; i++) {\n renamed.set(sources[i], targets[i]);\n renameTargets.add(targets[i]);\n renameSourcesByTarget.set(targets[i], sources[i]);\n }\n }\n\n // 2. Check for changes, rename, and removed\n before_keys.forEach((key, index) => {\n const sub_path = path.concat(key);\n if (after_key_set.has(key)) {\n const beforeValue = before[key];\n const afterValue = after[key];\n const hasNonFiniteNumber =\n (typeof beforeValue === 'number' && !Number.isFinite(beforeValue)) ||\n (typeof afterValue === 'number' && !Number.isFinite(afterValue));\n if (options.updateOrder || hasNonFiniteNumber ||\n before_stable[index] !== after_stable_by_key.get(key)) {\n merge(changes, diff(before[key], after[key], sub_path, options));\n }\n } else if (renamed.has(key)) {\n changes.push({\n type: ChangeType.Rename,\n path,\n from: key,\n to: renamed.get(key)!\n });\n } else {\n changes.push({\n type: ChangeType.Remove,\n path: sub_path\n });\n }\n });\n\n // 3. Check for additions\n after_keys.forEach(key => {\n if (!before_key_set.has(key) && !renameTargets.has(key)) {\n const add: Add = {\n type: ChangeType.Add,\n path: path.concat(key)\n };\n\n // Adds normally append. If the caller supplied the original object whose order\n // should be honoured, anchor this add before the next member that already has a\n // slot. A rename uses its old key as the anchor because the rename runs in place.\n if (options.orderSource !== undefined) {\n let orderObject = options.orderSource;\n for (const segment of path) orderObject = orderObject?.[segment as any];\n if (isObject(orderObject)) {\n const requestedKeys = Object.keys(orderObject);\n const addedIndex = requestedKeys.indexOf(key);\n for (let i = addedIndex + 1; i < requestedKeys.length; i++) {\n const target = requestedKeys[i];\n const source = renameSourcesByTarget.get(target)\n ?? (before_key_set.has(target) ? target : undefined);\n if (source !== undefined) {\n add.before = source;\n break;\n }\n }\n }\n }\n\n changes.push(add);\n }\n });\n\n let requestedKeys = after_keys;\n if (options.orderSource !== undefined) {\n let orderObject = options.orderSource;\n for (const segment of path) orderObject = orderObject?.[segment as any];\n if (isObject(orderObject)) {\n const afterKeySet = new Set(after_keys);\n requestedKeys = Object.keys(orderObject).filter(key => afterKeySet.has(key));\n }\n }\n\n // A renamed member keeps its existing CST slot, while an added member is appended\n // by the patcher. Emit direct Adds and Renames in the updated object order so an\n // added dotted member can land before a renamed sibling without patch.ts inspecting\n // the CST or the complete change list.\n const directChanges = changes.filter(change =>\n (isAdd(change) && change.path.length === path.length + 1) ||\n (isRename(change) && change.path.length === path.length)\n );\n if (options.orderSource !== undefined && directChanges.length > 1) {\n const orderedDirectChanges = [...directChanges].sort((a, b) => {\n const aKey = isAdd(a) ? a.path[a.path.length - 1] : isRename(a) ? a.to : '';\n const bKey = isAdd(b) ? b.path[b.path.length - 1] : isRename(b) ? b.to : '';\n return requestedKeys.indexOf(aKey as string) - requestedKeys.indexOf(bKey as string);\n });\n let directIndex = 0;\n changes = changes.map(change =>\n directChanges.includes(change) ? orderedDirectChanges[directIndex++] : change\n );\n }\n\n // 4. Order emission (updateOrder only). Predict the key order the document will have\n // once Add/Remove/Rename above are applied, then walk the target order emitting a Move\n // wherever the prediction and the target disagree, splicing the prediction to match as we\n // go — the same simulate-and-splice approach compareArrays already uses for Move.\n if (options.updateOrder) {\n const sim: string[] = [];\n for (const key of before_keys) {\n if (after_key_set.has(key)) {\n if (!sim.includes(key)) sim.push(key);\n } else if (renamed.has(key)) {\n // Guard against the pre-existing spurious-rename case ({a:1,b:1} -> {b:1,x:1} emits\n // Rename a->b even though b is unchanged) pushing a duplicate into sim.\n const to = renamed.get(key)!;\n if (!sim.includes(to)) sim.push(to);\n }\n // removed -> drop\n }\n for (const key of after_keys) {\n if (!sim.includes(key)) sim.push(key); // adds append\n }\n\n after_keys.forEach((key, targetIndex) => {\n if (sim[targetIndex] === key) return;\n\n const from = sim.indexOf(key);\n changes.push({\n type: ChangeType.Move,\n path,\n from,\n to: targetIndex,\n key\n });\n\n sim.splice(from, 1);\n sim.splice(targetIndex, 0, key);\n });\n }\n\n return changes;\n}\n\n// Multiline-formatting proxies, hoisted so compareArrays doesn't rebuild them\n// per call. See the layoutSensitiveArray comment in compareArrays.\nfunction hasMultilineValue(v: any): boolean {\n if (typeof v === 'string') return v.includes('\\n');\n if (Array.isArray(v)) return v.length > 0;\n if (v !== null && typeof v === 'object' && !(v instanceof Date)) {\n const vals = Object.values(v);\n return vals.some(x => x !== null && typeof x === 'object') || vals.some(hasMultilineValue);\n }\n return false;\n}\n\nfunction hasInlineObject(value: any): boolean {\n return value !== null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date);\n}\n\nfunction hasMixedStringAndObject(values: any[]): boolean {\n return values.length > 4 && values.some(value => typeof value === 'string') && values.some(hasInlineObject);\n}\n\nfunction compareArrays(before: any[], after: any[], path: Path = [], options: DiffOptions = {}): Change[] {\n let changes: Change[] = [];\n\n // 1. Convert arrays to stable objects\n const before_stable = before.map(stableStringify);\n const after_stable = after.map(stableStringify);\n\n // The writer corrupts multiline inline content when elements are relocated\n // (moves of elements holding multiline strings drop content lines — fuzz\n // seed 4765). Only for such arrays, prefer resolving a true deletion in\n // place over drifting the element right through a chain of Moves.\n // Multiline DELIMITED strings whose content is single-line aren't visible\n // here (the diff sees only values), but nested arrays/objects are a strong\n // proxy: those are what carry such formatting, and moving them corrupts\n // their interior the same way (fuzz seed 8512). A nested array or object\n // is itself evidence of multiline formatting even when its ELEMENTS are all\n // plain scalars — the formatter freely wraps such a container across lines,\n // and the diff cannot tell from values alone (fuzz seed 40181: removing a\n // scalar above a multiline `[218561, \"…\"]` chain-moved the array and dropped\n // columns out of its tail).\n const multilineArray = before.some(hasMultilineValue) || after.some(hasMultilineValue);\n const layoutSensitiveArray = multilineArray || hasMixedStringAndObject(before) || hasMixedStringAndObject(after);\n\n // Simulation of the actual VALUES, mutated in lockstep with before_stable.\n // The \"removed -> edited in place\" branch below must diff the element the\n // move simulation left at this index, not the untouched original: after a\n // Move, `before[index]` can hold a DIFFERENT element than the one whose\n // stable form sits at `before_stable[index]`, and diffing the wrong one\n // silently drops the edit (fuzz seed 340: `['4', …, true, …]` →\n // `[true, …]` moved `true` from 4 to 0, then diffed the original\n // `before[4]` — which was `true` — against `true`, emitting nothing for\n // the leftover string).\n const before_sim = before.slice();\n\n // Elements spliced out of `before` while walking the loop (the deletion\n // branch below). Remove paths are source coordinates — indices in the\n // ORIGINAL array — because the patcher applies same-array removals in\n // descending index order (see reorder() in patch.ts), so each emitted\n // index must stay valid against the un-shifted array.\n let removedBefore = 0;\n let sameArrayAddEmitted = false;\n\n const removeChange = (index: number): Remove => {\n const change: Remove = { type: ChangeType.Remove, path: path.concat(index) };\n if (!sameArrayAddEmitted || removedBefore > 0) {\n // Non-enumerable so `coordinate` stays out of the diff output that\n // callers and tests compare: it's an internal marker for reorder().\n Object.defineProperty(change, 'coordinate', { value: 'source' });\n }\n return change;\n };\n\n // 2. Step through after array making changes to before array as-needed\n for (let index = 0; index < after_stable.length; index++) {\n const value = after_stable[index];\n const overflow = index >= before_stable.length;\n\n // Check if items are the same\n if (!overflow && before_stable[index] === value) {\n continue;\n }\n\n // Check if item has been moved -> shift into place\n const from = overflow ? -1 : before_stable.indexOf(value, index + 1);\n if (from > -1) {\n // Is `before_stable[index]` (the mismatched element at this slot) a\n // surplus duplicate — more copies surviving in `before`'s unmatched\n // suffix than `after` demands? When so, the extra copy is genuinely\n // gone from this position and a removal in place is the honest edit.\n const valueAt = before_stable[index];\n let beforeCount = 0;\n for (let i = index; i < before_stable.length; i++) {\n if (before_stable[i] === valueAt) beforeCount++;\n }\n let afterCount = 0;\n for (let i = index; i < after_stable.length; i++) {\n if (after_stable[i] === valueAt) afterCount++;\n }\n const surplusDuplicate = beforeCount > afterCount;\n\n // A true deletion in move shape: the element at this position is\n // absent from `after` entirely (or is a surplus duplicate of a value\n // that later slots still hold), while the after-value sits later in\n // `before`. Without this the element only gets resolved at the end,\n // after a chain of Moves that relocates multiline elements — and the\n // writer corrupts their content (fuzz seed 4765: removing one scalar\n // from a multiline inline array dropped a line of a multiline string;\n // fuzz seed 35943: removing one of several duplicate scalars above a\n // nested multiline array chain-moved the array and corrupted its tail).\n if (layoutSensitiveArray && (after_stable.indexOf(before_stable[index]) === -1 || surplusDuplicate)) {\n changes.push(removeChange(index + removedBefore));\n before_stable.splice(index, 1);\n before_sim.splice(index, 1);\n removedBefore++;\n index--;\n continue;\n }\n\n // A Move emitted after an in-place deletion splice: its from/to are\n // simulation coordinates, but the patcher applies ALL removes first\n // (in descending index order) — when a trailing remove follows, the\n // move's source can be pushed out of bounds (fuzz seed 8138). When\n // the displaced element is a surplus duplicate, resolve it as a\n // removal in place instead of a Move: the remaining occurrences stay\n // where they are, so nothing needs to move.\n //\n // (Redundant with the surplus-duplicate removal above when\n // `layoutSensitiveArray` is set, but kept for the non-multiline case\n // where a prior splice already shifted indices and the surplus is\n // unambiguous.)\n if (removedBefore > 0 && surplusDuplicate) {\n changes.push(removeChange(index + removedBefore));\n before_stable.splice(index, 1);\n before_sim.splice(index, 1);\n removedBefore++;\n index--;\n continue;\n }\n\n // After an in-place removal this array is one element short at this\n // slot, so the after-value found later in `before` is NOT being\n // relocated — a fresh copy is needed here. Relocating it via a Move\n // drags multiline elements through a chain that later ADDs a new copy\n // anyway, and the writer corrupts their content (fuzz seed 62263: a\n // nested array above a multiline inline table replaced by a duplicate\n // scalar emitted Remove + Move + Add and mangled the table).\n if (layoutSensitiveArray && removedBefore > 0) {\n changes.push({\n type: ChangeType.Add,\n path: path.concat(index)\n });\n sameArrayAddEmitted = true;\n before_stable.splice(index, 0, value);\n before_sim.splice(index, 0, after[index]);\n // The fresh copy is spliced in BEFORE the original (at `from`), so it\n // shifts every later sim element — including the original we just\n // declined to move — one slot right. `removedBefore` models the\n // LEFT-shift of a prior remove, so a later Remove's source index\n // (`index + removedBefore`) is off by one and removes the wrong\n // element (fuzz seed 179377: `[false, '''…''', …]` edited and trimmed\n // removed its neighbour instead of the surplus scalar). Cancelling\n // one unit of the remove shift keeps the sim↔source mapping aligned.\n removedBefore--;\n continue;\n }\n\n changes.push({\n type: ChangeType.Move,\n path,\n from,\n to: index\n });\n\n const move = before_stable.splice(from, 1);\n before_stable.splice(index, 0, ...move);\n const moveValues = before_sim.splice(from, 1);\n before_sim.splice(index, 0, ...moveValues);\n\n continue;\n }\n\n // Check if item is removed -> assume it's been edited and replace.\n //\n // `after.includes(value)` alone is not enough: when the value also\n // occurs later in the array, the element is read as \"kept\", so the\n // mismatch becomes an Add plus a chain of Moves that re-finds the\n // duplicate — a pathological diff for a plain in-place edit (fuzz seed\n // 1406: `true` → `'4'` with another `true` later emitted Add(1) + six\n // Moves + Remove(10), and the writer corrupted a multiline string).\n // A duplicate further along in `before` can serve the later `after`\n // slot, so this occurrence is surplus whenever `before`'s unmatched\n // suffix holds more copies of the value than `after`'s does — then the\n // element is genuinely gone from its position and edited in place.\n let surplus = false;\n if (!overflow) {\n const value = before_stable[index];\n let beforeCount = 0;\n for (let i = index; i < before_stable.length; i++) {\n if (before_stable[i] === value) beforeCount++;\n }\n let afterCount = 0;\n for (let i = index; i < after_stable.length; i++) {\n if (after_stable[i] === value) afterCount++;\n }\n surplus = beforeCount > afterCount;\n }\n const removed = !overflow && surplus;\n if (removed) {\n merge(changes, diff(before_sim[index], after[index], path.concat(index), options));\n before_stable[index] = value;\n before_sim[index] = after[index];\n\n continue;\n }\n\n // Add as new item and shift existing\n changes.push({\n type: ChangeType.Add,\n path: path.concat(index)\n });\n sameArrayAddEmitted = true;\n before_stable.splice(index, 0, value);\n before_sim.splice(index, 0, after[index]);\n // Same source-index bookkeeping as the refused-move Add above: splicing a\n // new element in front of the surviving suffix shifts later sim indices\n // right by one, so a later Remove's source index (`index + removedBefore`)\n // is one too far right and targets the wrong element when a prior remove\n // is still pending. Cancel one unit of the remove shift (fuzz seed\n // 208822: editing a duplicate scalar and trimming a multiline array\n // removed the multiline string instead of the plain scalar).\n if (removedBefore > 0) removedBefore--;\n }\n\n // 3. Remove any remaining overflow items\n for (let i = after_stable.length; i < before_stable.length; i++) {\n changes.push(removeChange(i + removedBefore));\n }\n\n return changes;\n}\n"],"mappings":";;;;AAiBA,SAAgB,MAAM,QAA+B;CACnD,OAAO,OAAO;AAChB;AAMA,SAAgB,OAAO,QAAgC;CACrD,OAAO,OAAO;AAChB;AAQA,SAAgB,SAAS,QAAkC;CACzD,OAAO,OAAO;AAChB;AAUA,SAAgB,OAAO,QAAgC;CACrD,OAAO,OAAO;AAChB;AAQA,SAAgB,SAAS,QAAkC;CACzD,OAAO,OAAO;AAChB;AAgBA,SAAwB,KAAK,QAAa,OAAY,OAAa,CAAC,GAAG,UAAuB,CAAC,GAAa;CAC1G,IAAI,UAAU,QAAQ,KAAK,KAAK,WAAW,QAAQ,KAAK,GACtD,OAAO,CAAC;CAMV,IAAI,OAAO,WAAW,YAAY,OAAO,UAAU,YAC5C,OAAO,MAAM,MAAM,KAAK,OAAO,MAAM,KAAK,GAC/C;MAAI,cAAc,MAAM,MAAM,cAAc,KAAK,GAAG,OAAO,CAAC;CAAC;CAI/D,IAAI,MAAM,QAAQ,MAAM,KAAK,MAAM,QAAQ,KAAK,GAC9C,OAAO,cAAc,QAAQ,OAAO,MAAM,OAAO;MAC5C,IAAI,SAAS,MAAM,KAAK,SAAS,KAAK,GAC3C,OAAO,eAAe,QAAQ,OAAO,MAAM,OAAO;MAElD,OAAO,CACL;EACE;EACA;CACF,CACF;AAEJ;AAEA,SAAS,eAAe,QAAa,OAAY,OAAa,CAAC,GAAG,UA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