@decimalturn/toml-patch 3.3.2-dev → 3.3.2-lite

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 (81) hide show
  1. package/dist/patch.js +20 -0
  2. package/package.json +6 -11
  3. package/dist/dev/comment-alignment.js +0 -372
  4. package/dist/dev/comment-alignment.js.map +0 -1
  5. package/dist/dev/comment-ownership.js +0 -673
  6. package/dist/dev/comment-ownership.js.map +0 -1
  7. package/dist/dev/cst-source.js +0 -118
  8. package/dist/dev/cst-source.js.map +0 -1
  9. package/dist/dev/cst.js +0 -68
  10. package/dist/dev/cst.js.map +0 -1
  11. package/dist/dev/cursor.js +0 -66
  12. package/dist/dev/cursor.js.map +0 -1
  13. package/dist/dev/date-format.js +0 -287
  14. package/dist/dev/date-format.js.map +0 -1
  15. package/dist/dev/decode-utf8.js +0 -27
  16. package/dist/dev/decode-utf8.js.map +0 -1
  17. package/dist/dev/diff-lite.js +0 -108
  18. package/dist/dev/diff-lite.js.map +0 -1
  19. package/dist/dev/diff.js +0 -265
  20. package/dist/dev/diff.js.map +0 -1
  21. package/dist/dev/encode-lite.js +0 -210
  22. package/dist/dev/encode-lite.js.map +0 -1
  23. package/dist/dev/escape-preference.js +0 -166
  24. package/dist/dev/escape-preference.js.map +0 -1
  25. package/dist/dev/find-by-path.js +0 -115
  26. package/dist/dev/find-by-path.js.map +0 -1
  27. package/dist/dev/formatter.js +0 -298
  28. package/dist/dev/formatter.js.map +0 -1
  29. package/dist/dev/generate.js +0 -480
  30. package/dist/dev/generate.js.map +0 -1
  31. package/dist/dev/inline-comma-space.js +0 -13
  32. package/dist/dev/inline-comma-space.js.map +0 -1
  33. package/dist/dev/inline-format.js +0 -106
  34. package/dist/dev/inline-format.js.map +0 -1
  35. package/dist/dev/inline-layout.js +0 -107
  36. package/dist/dev/inline-layout.js.map +0 -1
  37. package/dist/dev/line-ending-backslash.js +0 -320
  38. package/dist/dev/line-ending-backslash.js.map +0 -1
  39. package/dist/dev/literal-string.js +0 -46
  40. package/dist/dev/literal-string.js.map +0 -1
  41. package/dist/dev/location.js +0 -104
  42. package/dist/dev/location.js.map +0 -1
  43. package/dist/dev/parse-error.js +0 -27
  44. package/dist/dev/parse-error.js.map +0 -1
  45. package/dist/dev/parse-js.js +0 -150
  46. package/dist/dev/parse-js.js.map +0 -1
  47. package/dist/dev/parse-string.js +0 -120
  48. package/dist/dev/parse-string.js.map +0 -1
  49. package/dist/dev/parse-toml.js +0 -714
  50. package/dist/dev/parse-toml.js.map +0 -1
  51. package/dist/dev/patch-lite.js +0 -4
  52. package/dist/dev/patch-lite2.js +0 -97
  53. package/dist/dev/patch-lite2.js.map +0 -1
  54. package/dist/dev/patch.js +0 -3128
  55. package/dist/dev/patch.js.map +0 -1
  56. package/dist/dev/smol-toml-date.js +0 -61
  57. package/dist/dev/smol-toml-date.js.map +0 -1
  58. package/dist/dev/to-js.js +0 -308
  59. package/dist/dev/to-js.js.map +0 -1
  60. package/dist/dev/to-toml.js +0 -874
  61. package/dist/dev/to-toml.js.map +0 -1
  62. package/dist/dev/tokenizer.js +0 -225
  63. package/dist/dev/tokenizer.js.map +0 -1
  64. package/dist/dev/toml-document.js +0 -221
  65. package/dist/dev/toml-document.js.map +0 -1
  66. package/dist/dev/toml-format.js +0 -549
  67. package/dist/dev/toml-format.js.map +0 -1
  68. package/dist/dev/toml-patch.js +0 -94
  69. package/dist/dev/toml-patch.js.map +0 -1
  70. package/dist/dev/traverse.js +0 -61
  71. package/dist/dev/traverse.js.map +0 -1
  72. package/dist/dev/truncate.js +0 -64
  73. package/dist/dev/truncate.js.map +0 -1
  74. package/dist/dev/update-order.js +0 -235
  75. package/dist/dev/update-order.js.map +0 -1
  76. package/dist/dev/utils.js +0 -296
  77. package/dist/dev/utils.js.map +0 -1
  78. package/dist/dev/writer.js +0 -758
  79. package/dist/dev/writer.js.map +0 -1
  80. package/dist/toml-patch.d.ts +0 -564
  81. /package/dist/{patch-lite.d.ts → patch.d.ts} +0 -0
@@ -1,61 +0,0 @@
1
- //! @decimalturn/toml-patch v3.3.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
- import { LocalDate, LocalDateTime, LocalTime, OffsetDateTime } from "./date-format.js";
3
-
4
- //#region src/smol-toml-date.ts
5
- /*!
6
- * Copyright (c) Squirrel Chat et al., All rights reserved.
7
- * SPDX-License-Identifier: BSD-3-Clause
8
- *
9
- * Redistribution and use in source and binary forms, with or without
10
- * modification, are permitted provided that the following conditions are met:
11
- *
12
- * 1. Redistributions of source code must retain the above copyright notice, this
13
- * list of conditions and the following disclaimer.
14
- * 2. Redistributions in binary form must reproduce the above copyright notice,
15
- * this list of conditions and the following disclaimer in the
16
- * documentation and/or other materials provided with the distribution.
17
- * 3. Neither the name of the copyright holder nor the names of its contributors
18
- * may be used to endorse or promote products derived from this software without
19
- * specific prior written permission.
20
- *
21
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
- /**
33
- * True when `value` is a smol-toml `TomlDate` instance.
34
- *
35
- * Duck-typed rather than `instanceof TomlDate`: the caller's object was parsed
36
- * by the smol-toml package, whose `TomlDate` is a different class object than
37
- * this vendored copy, so `instanceof` would never match. The `isDate` /
38
- * `isTime` / `isDateTime` methods only exist on smol-toml's date class, which
39
- * is what distinguishes it from toml-patch's own date classes.
40
- */
41
- function isSmolTomlDate(value) {
42
- return value instanceof Date && typeof value.isDate === "function" && typeof value.isTime === "function" && typeof value.isDateTime === "function";
43
- }
44
- /**
45
- * Converts a smol-toml `TomlDate` into the equivalent toml-patch date class.
46
- *
47
- * smol-toml always renders a zero-fraction time or datetime with a trailing
48
- * `.000`, while toml-patch omits it. Stripping it gives the canonical form
49
- * that compares equal to a value parsed from TOML source without a fraction.
50
- */
51
- function smolTomlDateToNative(value) {
52
- const canonical = value.toISOString().replace(/\.000(?=([Zz]|[+-]\d{2}:\d{2})$|$)/, "");
53
- if (value.isDate()) return new LocalDate(canonical);
54
- if (value.isTime()) return new LocalTime(canonical, canonical);
55
- if (value.isLocal()) return new LocalDateTime(canonical, false);
56
- return new OffsetDateTime(canonical, false);
57
- }
58
-
59
- //#endregion
60
- export { isSmolTomlDate, smolTomlDateToNative };
61
- //# sourceMappingURL=smol-toml-date.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"smol-toml-date.js","names":[],"sources":["../../src/smol-toml-date.ts"],"sourcesContent":["/*!\n * Copyright (c) Squirrel Chat et al., All rights reserved.\n * SPDX-License-Identifier: BSD-3-Clause\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * 3. Neither the name of the copyright holder nor the names of its contributors\n * may be used to endorse or promote products derived from this software without\n * specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n// Vendored from smol-toml (https://github.com/squirrelchat/smol-toml),\n// src/date.ts. Kept in the regular package so values produced by smol-toml's\n// parser can be recognised by type. The lite distribution duck-types these\n// values instead of importing this module, to stay small.\n\nimport { LocalDate, LocalTime, LocalDateTime, OffsetDateTime } from './date-format';\n\ntype Offset = string | null\n\nconst DATE_TIME_RE = /^(\\d{4}-\\d{2}-\\d{2})?[T ]?(?:(\\d{2}):\\d{2}(?::\\d{2}(?:\\.\\d+)?)?)?(Z|[-+]\\d{2}:\\d{2})?$/i\n\nexport class TomlDate extends Date {\n\t#hasDate = false\n\t#hasTime = false\n\t#offset: Offset = null\n\n\tconstructor(date: string | Date) {\n\t\tlet hasDate = true\n\t\tlet hasTime = true\n\t\tlet offset: Offset = 'Z'\n\n\t\tif (typeof date === 'string') {\n\t\t\tconst match = date.match(DATE_TIME_RE)\n\t\t\tif (match) {\n\t\t\t\tif (!match[1]) {\n\t\t\t\t\thasDate = false\n\t\t\t\t\tdate = `0000-01-01T${date}`\n\t\t\t\t}\n\n\t\t\t\thasTime = !!match[2]\n\t\t\t\t// Make sure to use T instead of a space. Breaks in case of extreme values otherwise.\n\t\t\t\tif (hasTime && date[10] === ' ') {\n\t\t\t\t\tdate = date.replace(' ', 'T')\n\t\t\t\t}\n\t\t\t\t// Do not allow rollover hours.\n\t\t\t\tif (match[2] && +match[2] > 23) {\n\t\t\t\t\tdate = ''\n\t\t\t\t} else {\n\t\t\t\t\toffset = match[3] || null\n\t\t\t\t\tdate = date.toUpperCase()\n\t\t\t\t\tif (!offset && hasTime) date += 'Z'\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdate = ''\n\t\t\t}\n\t\t}\n\n\t\tsuper(date)\n\t\tif (!isNaN(this.getTime())) {\n\t\t\tthis.#hasDate = hasDate\n\t\t\tthis.#hasTime = hasTime\n\t\t\tthis.#offset = offset\n\t\t}\n\t}\n\n\tisDateTime() {\n\t\treturn this.#hasDate && this.#hasTime\n\t}\n\n\tisLocal() {\n\t\treturn !this.#hasDate || !this.#hasTime || !this.#offset\n\t}\n\n\tisDate() {\n\t\treturn this.#hasDate && !this.#hasTime\n\t}\n\n\tisTime() {\n\t\treturn this.#hasTime && !this.#hasDate\n\t}\n\n\tisValid() {\n\t\treturn this.#hasDate || this.#hasTime\n\t}\n\n\toverride toISOString() {\n\t\tconst iso = super.toISOString()\n\n\t\t// Local Date\n\t\tif (this.isDate())\n\t\t\treturn iso.slice(0, 10)\n\n\t\t// Local Time\n\t\tif (this.isTime())\n\t\t\treturn iso.slice(11, 23)\n\n\t\t// Local DateTime\n\t\tif (this.#offset === null)\n\t\t\treturn iso.slice(0, -1)\n\n\t\t// Offset DateTime\n\t\tif (this.#offset === 'Z')\n\t\t\treturn iso\n\n\t\t// This part is quite annoying: JS strips the original timezone from the ISO string representation\n\t\t// Instead of using a \"modified\" date and \"Z\", we restore the representation \"as authored\"\n\n\t\tlet offset = (+(this.#offset.slice(1, 3)) * 60) + +(this.#offset.slice(4, 6))\n\t\toffset = this.#offset[0] === '-' ? offset : -offset\n\n\t\tconst offsetDate = new Date(this.getTime() - (offset * 60e3))\n\t\treturn offsetDate.toISOString().slice(0, -1) + this.#offset\n\t}\n\n\tstatic wrapAsOffsetDateTime(jsDate: Date, offset = 'Z') {\n\t\tconst date = new TomlDate(jsDate)\n\t\tdate.#offset = offset\n\t\treturn date\n\t}\n\n\tstatic wrapAsLocalDateTime(jsDate: Date) {\n\t\tconst date = new TomlDate(jsDate)\n\t\tdate.#offset = null\n\t\treturn date\n\t}\n\n\tstatic wrapAsLocalDate(jsDate: Date) {\n\t\tconst date = new TomlDate(jsDate)\n\t\tdate.#hasTime = false\n\t\tdate.#offset = null\n\t\treturn date\n\t}\n\n\tstatic wrapAsLocalTime(jsDate: Date) {\n\t\tconst date = new TomlDate(jsDate)\n\t\tdate.#hasDate = false\n\t\tdate.#offset = null\n\t\treturn date\n\t}\n}\n\n/**\n * True when `value` is a smol-toml `TomlDate` instance.\n *\n * Duck-typed rather than `instanceof TomlDate`: the caller's object was parsed\n * by the smol-toml package, whose `TomlDate` is a different class object than\n * this vendored copy, so `instanceof` would never match. The `isDate` /\n * `isTime` / `isDateTime` methods only exist on smol-toml's date class, which\n * is what distinguishes it from toml-patch's own date classes.\n */\nexport function isSmolTomlDate(value: unknown): value is TomlDate {\n return (\n value instanceof Date &&\n typeof (value as any).isDate === 'function' &&\n typeof (value as any).isTime === 'function' &&\n typeof (value as any).isDateTime === 'function'\n );\n}\n\n/**\n * Converts a smol-toml `TomlDate` into the equivalent toml-patch date class.\n *\n * smol-toml always renders a zero-fraction time or datetime with a trailing\n * `.000`, while toml-patch omits it. Stripping it gives the canonical form\n * that compares equal to a value parsed from TOML source without a fraction.\n */\nexport function smolTomlDateToNative(\n value: TomlDate\n): LocalDate | LocalTime | LocalDateTime | OffsetDateTime {\n const canonical = value.toISOString().replace(/\\.000(?=([Zz]|[+-]\\d{2}:\\d{2})$|$)/, '');\n\n if (value.isDate()) {\n return new LocalDate(canonical);\n }\n if (value.isTime()) {\n return new LocalTime(canonical, canonical);\n }\n if (value.isLocal()) {\n return new LocalDateTime(canonical, false);\n }\n return new OffsetDateTime(canonical, false);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwKA,SAAgB,eAAe,OAAmC;CAChE,OACE,iBAAiB,QACjB,OAAQ,MAAc,WAAW,cACjC,OAAQ,MAAc,WAAW,cACjC,OAAQ,MAAc,eAAe;AAEzC;;;;;;;;AASA,SAAgB,qBACd,OACwD;CACxD,MAAM,YAAY,MAAM,YAAY,CAAC,CAAC,QAAQ,sCAAsC,EAAE;CAEtF,IAAI,MAAM,OAAO,GACf,OAAO,IAAI,UAAU,SAAS;CAEhC,IAAI,MAAM,OAAO,GACf,OAAO,IAAI,UAAU,WAAW,SAAS;CAE3C,IAAI,MAAM,QAAQ,GAChB,OAAO,IAAI,cAAc,WAAW,KAAK;CAE3C,OAAO,IAAI,eAAe,WAAW,KAAK;AAC5C"}
package/dist/dev/to-js.js DELETED
@@ -1,308 +0,0 @@
1
- //! @decimalturn/toml-patch v3.3.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
- import ParseError from "./parse-error.js";
3
- import { LocalDate, LocalDateTime, LocalTime, OffsetDateTime } from "./date-format.js";
4
- import { blank, last } from "./utils.js";
5
-
6
- //#region src/to-js.ts
7
- function integerFromRaw(raw, mode = "asNeeded") {
8
- const compact = raw.replace(/_/g, "");
9
- let normalized = compact;
10
- if (/^[+-]?0x/i.test(compact) || /^[+-]?0o/i.test(compact) || /^[+-]?0b/i.test(compact)) {
11
- const sign = compact[0] === "+" || compact[0] === "-" ? compact[0] : "";
12
- normalized = sign + compact.slice(sign ? 1 : 0).toLowerCase();
13
- }
14
- let big;
15
- try {
16
- big = BigInt(normalized);
17
- } catch {
18
- return Number(compact);
19
- }
20
- if (mode === true) return big;
21
- if (mode === false) return Number(big);
22
- if (big >= BigInt(Number.MIN_SAFE_INTEGER) && big <= BigInt(Number.MAX_SAFE_INTEGER)) return Number(big);
23
- return big;
24
- }
25
- /**
26
- * Recursively tracks nested inline tables as immutable path metadata.
27
- */
28
- function trackNestedInlineTables(inlineTable, basePath, root) {
29
- for (const item of inlineTable.items) {
30
- const keyValue = item.item;
31
- if (keyValue.value.type === "InlineTable") {
32
- const fullPath = basePath.concat(keyValue.key.value);
33
- resolvePathState(root, fullPath, true).kind = "inline";
34
- trackNestedInlineTables(keyValue.value, fullPath, root);
35
- }
36
- }
37
- }
38
- /**
39
- * Converts a custom Date subclass value to the corresponding Temporal object.
40
- * Does NOT check for Temporal availability — callers must guard that.
41
- */
42
- function dateValueToTemporal(value) {
43
- var _value$constructor, _value$constructor$st, _value$constructor2, _value$constructor3, _value$constructor4, _value$constructor5;
44
- if (((_value$constructor = value.constructor) === null || _value$constructor === void 0 || (_value$constructor = _value$constructor.name) === null || _value$constructor === void 0 || (_value$constructor$st = _value$constructor.startsWith) === null || _value$constructor$st === void 0 ? void 0 : _value$constructor$st.call(_value$constructor, "Temporal.")) || ((_value$constructor2 = value.constructor) === null || _value$constructor2 === void 0 ? void 0 : _value$constructor2.name) === "PlainDate" || ((_value$constructor3 = value.constructor) === null || _value$constructor3 === void 0 ? void 0 : _value$constructor3.name) === "PlainTime" || ((_value$constructor4 = value.constructor) === null || _value$constructor4 === void 0 ? void 0 : _value$constructor4.name) === "PlainDateTime" || ((_value$constructor5 = value.constructor) === null || _value$constructor5 === void 0 ? void 0 : _value$constructor5.name) === "ZonedDateTime") return value;
45
- const T = globalThis.Temporal;
46
- if (value instanceof LocalDate) return T.PlainDate.from(value.toISOString());
47
- if (value instanceof LocalTime) return T.PlainTime.from(value.toISOString());
48
- if (value instanceof LocalDateTime) return T.PlainDateTime.from(value.toISOString().replace(" ", "T"));
49
- if (value instanceof OffsetDateTime) {
50
- const iso = value.toISOString().replace(" ", "T");
51
- const offsetMatch = iso.match(/([+-]\d{2}:\d{2}|Z)$/);
52
- const offset = offsetMatch ? offsetMatch[1] : "Z";
53
- const plainIso = iso.replace(/([+-]\d{2}:\d{2}|Z)$/, "");
54
- const tz = offset === "Z" ? "+00:00" : offset;
55
- return T.ZonedDateTime.from(`${plainIso}${offset}[${tz}]`);
56
- }
57
- return T.PlainDateTime.from(value.toISOString().replace("Z", ""));
58
- }
59
- /**
60
- * Converts the given CST to a JavaScript object.
61
- *
62
- * @param cst The Concrete Syntax Tree to convert.
63
- * @param input The original input string (used for error reporting).
64
- * @param opts.integersAsBigInt Controls integer representation.
65
- * @param opts.temporal When true, date/time values are returned as Temporal objects.
66
- * @returns The JavaScript object representation of the CST.
67
- */
68
- function toJS(cst, input = "", opts = {}) {
69
- const { integersAsBigInt = "asNeeded", temporal = false } = opts;
70
- const result = blank();
71
- const pathState = createPathState();
72
- let active = result;
73
- let active_path = [];
74
- for (const block of cst) switch (block.type) {
75
- case "Table":
76
- handleTable(block);
77
- for (const item of block.items) if (item.type === "KeyValue") handleKeyValue(item);
78
- break;
79
- case "TableArray":
80
- handleTableArray(block);
81
- for (const item of block.items) if (item.type === "KeyValue") handleKeyValue(item);
82
- break;
83
- case "KeyValue": handleKeyValue(block);
84
- }
85
- return result;
86
- function handleTable(node) {
87
- const key = node.key.item.value;
88
- try {
89
- validateKey(pathState, [], key, node.type);
90
- } catch (err) {
91
- throw new ParseError(input, node.key.loc.start, err.message);
92
- }
93
- resolvePathState(pathState, key, true).kind = "explicit";
94
- active = ensureTable(result, key);
95
- active_path = key;
96
- }
97
- function handleTableArray(node) {
98
- const key = node.key.item.value;
99
- try {
100
- validateKey(pathState, [], key, node.type);
101
- } catch (err) {
102
- throw new ParseError(input, node.key.loc.start, err.message);
103
- }
104
- const arrayState = resolvePathState(pathState, key, true);
105
- arrayState.kind = "table-array";
106
- arrayState.entries.push(createPathState());
107
- active = ensureTableArray(result, key);
108
- active_path = key;
109
- }
110
- function handleKeyValue(node) {
111
- const key = node.key.value;
112
- try {
113
- validateKey(pathState, active_path, key, node.type);
114
- } catch (err) {
115
- throw new ParseError(input, node.key.loc.start, err.message);
116
- }
117
- if (key.length > 1) for (let index = 1; index < key.length; index++) {
118
- const implicit = resolvePathState(pathState, active_path.concat(key.slice(0, index)), true);
119
- if (implicit.kind === "undefined") implicit.kind = "implicit";
120
- }
121
- let value;
122
- try {
123
- value = toValue(node.value, {
124
- integersAsBigInt,
125
- temporal
126
- });
127
- } catch (err) {
128
- throw new ParseError(input, node.value.loc.start, err.message);
129
- }
130
- const fullPath = active_path.concat(key);
131
- if (node.value.type === "InlineTable") {
132
- resolvePathState(pathState, fullPath, true).kind = "inline";
133
- trackNestedInlineTables(node.value, fullPath, pathState);
134
- } else {
135
- const valueState = resolvePathState(pathState, fullPath, true);
136
- valueState.kind = node.value.type === "InlineArray" ? "array" : node.value.type === "DateTime" ? "date" : "value";
137
- if (node.value.type === "DateTime") valueState.runtimeValue = value;
138
- }
139
- const target = key.length > 1 ? ensureTable(active, key.slice(0, -1)) : active;
140
- target[last(key)] = value;
141
- }
142
- }
143
- /**
144
- * Converts a TOML CST value node to a JavaScript value.
145
- * @param node The TOML CST value node.
146
- * @param opts Options object:
147
- * @param opts.integersAsBigInt Controls integer representation (`'asNeeded'` | `true` | `false`).
148
- * @param opts.temporal When `true`, date/time values are returned as Temporal objects
149
- * @returns The corresponding JavaScript value.
150
- */
151
- function toValue(node, opts = {}) {
152
- const { integersAsBigInt = "asNeeded", temporal = false } = opts;
153
- switch (node.type) {
154
- case "InlineTable":
155
- const result = blank();
156
- const defined_keys = /* @__PURE__ */ new Set();
157
- const defined_prefixes = /* @__PURE__ */ new Map();
158
- node.items.forEach(({ item }) => {
159
- const key = item.key.value;
160
- const value = toValue(item.value, {
161
- integersAsBigInt,
162
- temporal
163
- });
164
- const full_key = joinKey(key);
165
- const encoded_key = encodeKey(key);
166
- if (defined_keys.has(encoded_key)) throw new Error(`Duplicate key "${full_key}" in inline table`);
167
- for (let i = 1; i < key.length; i++) {
168
- const prefix = joinKey(key.slice(0, i));
169
- if (defined_keys.has(encodeKey(key.slice(0, i)))) throw new Error(`Key "${full_key}" conflicts with key: "${prefix}"`);
170
- }
171
- if (defined_prefixes.has(encoded_key)) {
172
- const existing = defined_prefixes.get(encoded_key);
173
- throw new Error(`Key "${full_key}" conflicts with key: "${existing}"`);
174
- }
175
- defined_keys.add(encoded_key);
176
- for (let i = 1; i < key.length; i++) {
177
- const encoded_prefix = encodeKey(key.slice(0, i));
178
- if (!defined_prefixes.has(encoded_prefix)) defined_prefixes.set(encoded_prefix, full_key);
179
- }
180
- const target = key.length > 1 ? ensureTable(result, key.slice(0, -1)) : result;
181
- target[last(key)] = value;
182
- });
183
- return result;
184
- case "InlineArray": return node.items.map((item) => toValue(item.item, {
185
- integersAsBigInt,
186
- temporal
187
- }));
188
- case "DateTime":
189
- if (temporal) {
190
- if (typeof globalThis.Temporal === "undefined") throw new Error("Temporal API is not available in this runtime. Set temporal: false or use a runtime with Temporal support.");
191
- return dateValueToTemporal(node.value);
192
- }
193
- return node.value;
194
- case "String": return node.value;
195
- case "Integer": return integerFromRaw(node.raw, integersAsBigInt);
196
- case "Float":
197
- case "Boolean": return node.value;
198
- default: throw new Error(`Unrecognized value type "${node.type}"`);
199
- }
200
- }
201
- function validateKey(root, prefix, key, type) {
202
- const fullPath = prefix.concat(key);
203
- const fullName = joinKey(fullPath);
204
- const target = resolvePathState(root, fullPath);
205
- for (let index = 0; index < fullPath.length - 1; index++) {
206
- const path = fullPath.slice(0, index + 1);
207
- const node = resolvePathState(root, path);
208
- const nextSegment = fullPath[index + 1];
209
- const runtimeValue = node.runtimeValue;
210
- if (node.kind === "date" && !node.children.has(nextSegment) && runtimeValue !== null && typeof runtimeValue === "object" && nextSegment in runtimeValue) throw new Error(`Value already defined for ${joinKey(path.concat(nextSegment))}`);
211
- }
212
- if (type === "KeyValue") {
213
- if (key.length > 1) {
214
- for (let index = 1; index < key.length; index++) {
215
- const path = prefix.concat(key.slice(0, index));
216
- const node = resolvePathState(root, path);
217
- const name = joinKey(path);
218
- if (node.kind === "inline") throw new Error(`Cannot extend inline table at ${name}`);
219
- if (node.kind === "array") throw new Error(`Cannot add to static array at ${name}`);
220
- if (node.kind === "table-array") throw new Error(`Cannot traverse Array of Tables at ${name}`);
221
- if (node.kind === "value") throw new Error(`Value already defined for ${name}`);
222
- }
223
- for (let index = prefix.length + 1; index <= fullPath.length; index++) {
224
- const path = fullPath.slice(0, index);
225
- if (resolvePathState(root, path).kind === "explicit") throw new Error(`Cannot extend explicit table ${joinKey(path)} with dotted keys`);
226
- }
227
- }
228
- if (target.kind === "implicit" || target.kind === "explicit") throw new Error(`Table already defined: ${fullName}`);
229
- if (target.kind === "table-array") throw new Error(`Table already defined: ${fullName}`);
230
- if (target.kind === "value" || target.kind === "date" || target.kind === "inline") throw new Error(`Value already defined for ${fullName}`);
231
- if (target.kind === "array") throw new Error(`Cannot add to static array at ${fullName}`);
232
- return;
233
- }
234
- for (let index = 1; index < fullPath.length; index++) {
235
- const path = fullPath.slice(0, index);
236
- const node = resolvePathState(root, path);
237
- const name = joinKey(path);
238
- if (node.kind === "inline") throw new Error(`Cannot extend inline table at ${name}`);
239
- if (node.kind === "array") throw new Error(`Cannot add to static array at ${name}`);
240
- if (node.kind === "value") throw new Error(`Value already defined for ${name}`);
241
- }
242
- if (target.kind === "inline") throw new Error(`Cannot extend inline table at ${fullName}`);
243
- if (target.kind === "implicit") throw new Error(`Implicit table already defined: ${fullName}`);
244
- if (target.kind === "array") throw new Error(`Cannot add to static array at ${fullName}`);
245
- if (type === "Table") {
246
- if (target.kind === "explicit" || target.kind === "table-array") throw new Error(`Table already defined: ${fullName}`);
247
- if (target.kind === "value" || target.kind === "date") throw new Error(`Value already defined for ${fullName}`);
248
- } else if (target.kind !== "undefined" && target.kind !== "table-array" || target.kind === "undefined" && target.children.size > 0) throw new Error(`Cannot add Array of Tables to table at ${fullName}`);
249
- }
250
- function ensureTable(object, key) {
251
- const target = ensure(object, key.slice(0, -1));
252
- const last_key = last(key);
253
- if (!target[last_key]) target[last_key] = blank();
254
- return target[last_key];
255
- }
256
- function ensureTableArray(object, key) {
257
- const target = ensure(object, key.slice(0, -1));
258
- const last_key = last(key);
259
- if (!target[last_key]) target[last_key] = [];
260
- const next = blank();
261
- target[last(key)].push(next);
262
- return next;
263
- }
264
- function ensure(object, keys) {
265
- return keys.reduce((active, subkey) => {
266
- if (!active[subkey]) active[subkey] = blank();
267
- return Array.isArray(active[subkey]) ? last(active[subkey]) : active[subkey];
268
- }, object);
269
- }
270
- function joinKey(key) {
271
- return key.join(".");
272
- }
273
- /**
274
- * Unambiguous encoding of a key path for use as a `Set`/`Map` key.
275
- *
276
- * A plain `key.join('.')` collides for distinct key paths: `["", ""]` (an
277
- * empty-string key nested in an empty-string table) and the single literal
278
- * segment `["."]` both join to `.`, so a nested empty-key inline table is
279
- * wrongly rejected when a `["."]` table header follows (fuzz seed 65682).
280
- */
281
- function encodeKey(key) {
282
- return JSON.stringify(key);
283
- }
284
- function createPathState() {
285
- return {
286
- kind: "undefined",
287
- children: /* @__PURE__ */ new Map(),
288
- entries: []
289
- };
290
- }
291
- function resolvePathState(root, path, create = false) {
292
- let node = root;
293
- for (const segment of path) {
294
- if (node.kind === "table-array") node = node.entries[node.entries.length - 1] ?? node;
295
- let child = node.children.get(segment);
296
- if (!child && create) {
297
- child = createPathState();
298
- node.children.set(segment, child);
299
- }
300
- if (!child) return createPathState();
301
- node = child;
302
- }
303
- return node;
304
- }
305
-
306
- //#endregion
307
- export { toJS as default, toValue };
308
- //# sourceMappingURL=to-js.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"to-js.js","names":[],"sources":["../../src/to-js.ts"],"sourcesContent":["import { Value, NodeType, TreeNode, CST, InlineTable, Table, TableArray, KeyValue } from './cst';\nimport { last, blank } from './utils';\nimport ParseError from './parse-error';\nimport { IntegersAsBigInt } from './parse-options';\nimport { LocalDate, LocalTime, LocalDateTime, OffsetDateTime } from './date-format';\n\nfunction integerFromRaw(raw: string, mode: IntegersAsBigInt = 'asNeeded'): number | bigint {\n const compact = raw.replace(/_/g, '');\n let normalized = compact;\n\n if (/^[+-]?0x/i.test(compact) || /^[+-]?0o/i.test(compact) || /^[+-]?0b/i.test(compact)) {\n const sign = compact[0] === '+' || compact[0] === '-' ? compact[0] : '';\n const body = compact.slice(sign ? 1 : 0);\n normalized = sign + body.toLowerCase();\n }\n\n let big: bigint | undefined;\n try {\n big = BigInt(normalized);\n } catch {\n // Some integer-valued JS numbers can be stringified in scientific notation\n // (e.g. \"5e+22\"). BigInt cannot parse that syntax, so preserve behavior\n // by coercing back to Number instead of throwing.\n return Number(compact);\n }\n\n if (mode === true) {\n return big;\n }\n if (mode === false) {\n return Number(big);\n }\n // 'asNeeded': return number when safe, bigint otherwise\n if (big >= BigInt(Number.MIN_SAFE_INTEGER) && big <= BigInt(Number.MAX_SAFE_INTEGER)) {\n return Number(big);\n }\n return big;\n}\n\n/**\n * Recursively tracks nested inline tables as immutable path metadata.\n */\nfunction trackNestedInlineTables(inlineTable: InlineTable, basePath: string[], root: PathState) {\n for (const item of inlineTable.items) {\n const keyValue = item.item;\n if (keyValue.value.type === NodeType.InlineTable) {\n const fullPath = basePath.concat(keyValue.key.value);\n resolvePathState(root, fullPath, true).kind = 'inline';\n trackNestedInlineTables(keyValue.value, fullPath, root);\n }\n }\n}\n\n/**\n * Converts a custom Date subclass value to the corresponding Temporal object.\n * Does NOT check for Temporal availability — callers must guard that.\n */\nfunction dateValueToTemporal(value: Date): any {\n // If the value is already a Temporal object (e.g. from a CST generated by\n // parseJS with Temporal input), return it directly — no conversion needed.\n if (value.constructor?.name?.startsWith?.('Temporal.') ||\n value.constructor?.name === 'PlainDate' ||\n value.constructor?.name === 'PlainTime' ||\n value.constructor?.name === 'PlainDateTime' ||\n value.constructor?.name === 'ZonedDateTime') {\n return value;\n }\n\n const T = (globalThis as any).Temporal;\n // LocalDate → Temporal.PlainDate\n if (value instanceof LocalDate) {\n return T.PlainDate.from(value.toISOString());\n }\n // LocalTime → Temporal.PlainTime\n if (value instanceof LocalTime) {\n return T.PlainTime.from(value.toISOString());\n }\n // LocalDateTime → Temporal.PlainDateTime\n if (value instanceof LocalDateTime) {\n // toISOString() uses a space separator when the original TOML did\n // (useSpaceSeparator flag). Temporal.from() requires T.\n return T.PlainDateTime.from(value.toISOString().replace(' ', 'T'));\n }\n // OffsetDateTime → Temporal.ZonedDateTime\n if (value instanceof OffsetDateTime) {\n // Same: toISOString() uses a space separator when the original TOML did.\n // Normalize to T before extracting the offset and calling .from().\n const iso = value.toISOString().replace(' ', 'T');\n const offsetMatch = iso.match(/([+-]\\d{2}:\\d{2}|Z)$/);\n const offset = offsetMatch ? offsetMatch[1] : 'Z';\n const plainIso = iso.replace(/([+-]\\d{2}:\\d{2}|Z)$/, '');\n const tz = offset === 'Z' ? '+00:00' : offset;\n return T.ZonedDateTime.from(`${plainIso}${offset}[${tz}]`);\n }\n // Fallback: native Date or unrecognized Date subclass → Temporal.PlainDateTime\n return T.PlainDateTime.from(value.toISOString().replace('Z', ''));\n}\n\n/**\n * Converts the given CST to a JavaScript object.\n * \n * @param cst The Concrete Syntax Tree to convert.\n * @param input The original input string (used for error reporting).\n * @param opts.integersAsBigInt Controls integer representation.\n * @param opts.temporal When true, date/time values are returned as Temporal objects.\n * @returns The JavaScript object representation of the CST.\n */\nexport default function toJS(\n cst: CST,\n input: string = '',\n opts: { integersAsBigInt?: IntegersAsBigInt; temporal?: boolean } = {}\n): any {\n const { integersAsBigInt = 'asNeeded', temporal = false } = opts;\n const result = blank();\n const pathState = createPathState();\n let active: any = result;\n let active_path: string[] = [];\n\n for (const block of cst) {\n switch (block.type) {\n case NodeType.Table:\n handleTable(block as Table);\n for (const item of (block as Table).items) {\n if (item.type === NodeType.KeyValue) handleKeyValue(item as KeyValue);\n }\n break;\n case NodeType.TableArray:\n handleTableArray(block as TableArray);\n for (const item of (block as TableArray).items) {\n if (item.type === NodeType.KeyValue) handleKeyValue(item as KeyValue);\n }\n break;\n case NodeType.KeyValue:\n handleKeyValue(block as KeyValue);\n break;\n }\n }\n\n return result;\n\n function handleTable(node: Table) {\n const key = node.key.item.value;\n try {\n validateKey(pathState, [], key, node.type);\n } catch (err) {\n throw new ParseError(input, node.key.loc.start, (err as Error).message);\n }\n resolvePathState(pathState, key, true).kind = 'explicit';\n active = ensureTable(result, key);\n active_path = key;\n }\n\n function handleTableArray(node: TableArray) {\n const key = node.key.item.value;\n try {\n validateKey(pathState, [], key, node.type);\n } catch (err) {\n throw new ParseError(input, node.key.loc.start, (err as Error).message);\n }\n\n const arrayState = resolvePathState(pathState, key, true);\n arrayState.kind = 'table-array';\n arrayState.entries.push(createPathState());\n active = ensureTableArray(result, key);\n active_path = key;\n }\n\n function handleKeyValue(node: KeyValue) {\n const key = node.key.value;\n try {\n validateKey(pathState, active_path, key, node.type);\n } catch (err) {\n throw new ParseError(input, node.key.loc.start, (err as Error).message);\n }\n\n if (key.length > 1) {\n for (let index = 1; index < key.length; index++) {\n const implicit = resolvePathState(pathState, active_path.concat(key.slice(0, index)), true);\n if (implicit.kind === 'undefined') implicit.kind = 'implicit';\n }\n }\n\n let value;\n try {\n value = toValue(node.value, { integersAsBigInt, temporal });\n } catch (err) {\n throw new ParseError(input, node.value.loc.start, (err as Error).message);\n }\n\n const fullPath = active_path.concat(key);\n if (node.value.type === NodeType.InlineTable) {\n resolvePathState(pathState, fullPath, true).kind = 'inline';\n trackNestedInlineTables(node.value, fullPath, pathState);\n } else {\n const valueState = resolvePathState(pathState, fullPath, true);\n valueState.kind =\n node.value.type === NodeType.InlineArray\n ? 'array'\n : node.value.type === NodeType.DateTime\n ? 'date'\n : 'value';\n if (node.value.type === NodeType.DateTime) valueState.runtimeValue = value;\n }\n\n const target = key.length > 1 ? ensureTable(active, key.slice(0, -1)) : active;\n target[last(key)!] = value;\n }\n}\n\n/**\n * Converts a TOML CST value node to a JavaScript value.\n * @param node The TOML CST value node.\n * @param opts Options object:\n * @param opts.integersAsBigInt Controls integer representation (`'asNeeded'` | `true` | `false`).\n * @param opts.temporal When `true`, date/time values are returned as Temporal objects\n * @returns The corresponding JavaScript value.\n */\nexport function toValue(\n node: Value,\n opts: { integersAsBigInt?: IntegersAsBigInt; temporal?: boolean } = {}\n): any {\n const { integersAsBigInt = 'asNeeded', temporal = false } = opts;\n switch (node.type) {\n case NodeType.InlineTable:\n const result = blank();\n const defined_keys = new Set<string>();\n const defined_prefixes = new Map<string, string>(); // prefix -> one of the full keys that uses it\n\n node.items.forEach(({ item }) => {\n const key = item.key.value;\n const value = toValue(item.value, { integersAsBigInt, temporal });\n\n // Check for duplicate keys and conflicting key paths. Set lookups use\n // the unambiguous encodeKey form; messages use the `.`-joined display.\n const full_key = joinKey(key);\n const encoded_key = encodeKey(key);\n\n // Check if this exact key was already defined\n if (defined_keys.has(encoded_key)) {\n throw new Error(`Duplicate key \"${full_key}\" in inline table`);\n }\n \n // Check if any prefix of this key conflicts with an existing key\n // e.g., if \"a.b\" is defined, we can't later define \"a.b.c\" (would overwrite the value)\n for (let i = 1; i < key.length; i++) {\n const prefix = joinKey(key.slice(0, i));\n if (defined_keys.has(encodeKey(key.slice(0, i)))) {\n throw new Error(`Key \"${full_key}\" conflicts with key: \"${prefix}\"`);\n }\n }\n \n // Check if this key is a prefix of an already defined key\n // e.g., if \"a.b.c\" is defined, we can't later define \"a.b\" (would overwrite the table)\n if (defined_prefixes.has(encoded_key)) {\n const existing = defined_prefixes.get(encoded_key)!;\n throw new Error(`Key \"${full_key}\" conflicts with key: \"${existing}\"`);\n }\n \n defined_keys.add(encoded_key);\n \n // Track all prefixes of this key\n for (let i = 1; i < key.length; i++) {\n const encoded_prefix = encodeKey(key.slice(0, i));\n if (!defined_prefixes.has(encoded_prefix)) {\n defined_prefixes.set(encoded_prefix, full_key);\n }\n }\n\n const target = key.length > 1 ? ensureTable(result, key.slice(0, -1)) : result;\n target[last(key)!] = value;\n });\n\n return result;\n\n case NodeType.InlineArray:\n return node.items.map(item => toValue(item.item as Value, { integersAsBigInt, temporal }));\n\n case NodeType.DateTime:\n if (temporal) {\n if (typeof (globalThis as any).Temporal === 'undefined') {\n throw new Error(\n 'Temporal API is not available in this runtime. ' +\n 'Set temporal: false or use a runtime with Temporal support.'\n );\n }\n return dateValueToTemporal(node.value);\n }\n // Preserve TOML date/time custom classes so format is retained when\n // round-tripping through stringify() (e.g. date-only, time-only, local vs offset).\n // These classes extend Date, so JS users can still treat them as Dates.\n return node.value;\n\n case NodeType.String:\n return node.value;\n\n case NodeType.Integer:\n return integerFromRaw(node.raw, integersAsBigInt);\n\n case NodeType.Float:\n case NodeType.Boolean:\n return node.value;\n\n default:\n throw new Error(`Unrecognized value type \"${(node as TreeNode).type}\"`);\n }\n}\n\nfunction validateKey(\n root: PathState,\n prefix: string[],\n key: string[],\n type: NodeType.Table | NodeType.TableArray | NodeType.KeyValue\n) {\n const fullPath = prefix.concat(key);\n const fullName = joinKey(fullPath);\n const target = resolvePathState(root, fullPath);\n\n for (let index = 0; index < fullPath.length - 1; index++) {\n const path = fullPath.slice(0, index + 1);\n const node = resolvePathState(root, path);\n const nextSegment = fullPath[index + 1];\n const runtimeValue = node.runtimeValue;\n if (\n node.kind === 'date'\n && !node.children.has(nextSegment)\n && runtimeValue !== null\n && typeof runtimeValue === 'object'\n && nextSegment in runtimeValue\n ) {\n throw new Error(`Value already defined for ${joinKey(path.concat(nextSegment))}`);\n }\n }\n\n if (type === NodeType.KeyValue) {\n if (key.length > 1) {\n for (let index = 1; index < key.length; index++) {\n const path = prefix.concat(key.slice(0, index));\n const node = resolvePathState(root, path);\n const name = joinKey(path);\n if (node.kind === 'inline') throw new Error(`Cannot extend inline table at ${name}`);\n if (node.kind === 'array') throw new Error(`Cannot add to static array at ${name}`);\n if (node.kind === 'table-array') throw new Error(`Cannot traverse Array of Tables at ${name}`);\n if (node.kind === 'value') throw new Error(`Value already defined for ${name}`);\n }\n for (let index = prefix.length + 1; index <= fullPath.length; index++) {\n const path = fullPath.slice(0, index);\n if (resolvePathState(root, path).kind === 'explicit') {\n throw new Error(`Cannot extend explicit table ${joinKey(path)} with dotted keys`);\n }\n }\n }\n if (target.kind === 'implicit' || target.kind === 'explicit') {\n throw new Error(`Table already defined: ${fullName}`);\n }\n if (target.kind === 'table-array') throw new Error(`Table already defined: ${fullName}`);\n if (target.kind === 'value' || target.kind === 'date' || target.kind === 'inline') {\n throw new Error(`Value already defined for ${fullName}`);\n }\n if (target.kind === 'array') throw new Error(`Cannot add to static array at ${fullName}`);\n return;\n }\n\n for (let index = 1; index < fullPath.length; index++) {\n const path = fullPath.slice(0, index);\n const node = resolvePathState(root, path);\n const name = joinKey(path);\n if (node.kind === 'inline') throw new Error(`Cannot extend inline table at ${name}`);\n if (node.kind === 'array') throw new Error(`Cannot add to static array at ${name}`);\n if (node.kind === 'value') throw new Error(`Value already defined for ${name}`);\n }\n\n if (target.kind === 'inline') throw new Error(`Cannot extend inline table at ${fullName}`);\n if (target.kind === 'implicit') throw new Error(`Implicit table already defined: ${fullName}`);\n if (target.kind === 'array') throw new Error(`Cannot add to static array at ${fullName}`);\n if (type === NodeType.Table) {\n if (target.kind === 'explicit' || target.kind === 'table-array') {\n throw new Error(`Table already defined: ${fullName}`);\n }\n if (target.kind === 'value' || target.kind === 'date') {\n throw new Error(`Value already defined for ${fullName}`);\n }\n } else if (\n (target.kind !== 'undefined' && target.kind !== 'table-array')\n || (target.kind === 'undefined' && target.children.size > 0)\n ) {\n throw new Error(`Cannot add Array of Tables to table at ${fullName}`);\n }\n}\n\nfunction ensureTable(object: any, key: string[]): any {\n const target = ensure(object, key.slice(0, -1));\n const last_key = last(key)!;\n if (!target[last_key]) {\n target[last_key] = blank();\n }\n\n return target[last_key];\n}\n\nfunction ensureTableArray(object: any, key: string[]): any {\n const target = ensure(object, key.slice(0, -1));\n const last_key = last(key)!;\n if (!target[last_key]) {\n target[last_key] = [];\n }\n\n const next = blank();\n target[last(key)!].push(next);\n\n return next;\n}\n\nfunction ensure(object: any, keys: string[]): any {\n return keys.reduce((active, subkey) => {\n if (!active[subkey]) {\n active[subkey] = blank();\n }\n return Array.isArray(active[subkey]) ? last(active[subkey]) : active[subkey];\n }, object);\n}\n\nfunction joinKey(key: string[]): string {\n return key.join('.');\n}\n\n/**\n * Unambiguous encoding of a key path for use as a `Set`/`Map` key.\n *\n * A plain `key.join('.')` collides for distinct key paths: `[\"\", \"\"]` (an\n * empty-string key nested in an empty-string table) and the single literal\n * segment `[\".\"]` both join to `.`, so a nested empty-key inline table is\n * wrongly rejected when a `[\".\"]` table header follows (fuzz seed 65682).\n */\nfunction encodeKey(key: string[]): string {\n return JSON.stringify(key);\n}\n\ntype PathStateKind = 'undefined' | 'implicit' | 'explicit' | 'value' | 'date' | 'array' | 'inline' | 'table-array';\n\ntype PathState = {\n kind: PathStateKind;\n children: Map<string, PathState>;\n entries: PathState[];\n runtimeValue?: unknown;\n};\n\nfunction createPathState(): PathState {\n return { kind: 'undefined', children: new Map(), entries: [] };\n}\n\nfunction resolvePathState(root: PathState, path: string[], create = false): PathState {\n let node = root;\n for (const segment of path) {\n if (node.kind === 'table-array') node = node.entries[node.entries.length - 1] ?? node;\n let child = node.children.get(segment);\n if (!child && create) {\n child = createPathState();\n node.children.set(segment, child);\n }\n if (!child) return createPathState();\n node = child;\n }\n return node;\n}\n"],"mappings":";;;;;;AAMA,SAAS,eAAe,KAAa,OAAyB,YAA6B;CACzF,MAAM,UAAU,IAAI,QAAQ,MAAM,EAAE;CACpC,IAAI,aAAa;CAEjB,IAAI,YAAY,KAAK,OAAO,KAAK,YAAY,KAAK,OAAO,KAAK,YAAY,KAAK,OAAO,GAAG;EACvF,MAAM,OAAO,QAAQ,OAAO,OAAO,QAAQ,OAAO,MAAM,QAAQ,KAAK;EAErE,aAAa,OADA,QAAQ,MAAM,OAAO,IAAI,CACf,CAAC,CAAC,YAAY;CACvC;CAEA,IAAI;CACJ,IAAI;EACF,MAAM,OAAO,UAAU;CACzB,QAAQ;EAIN,OAAO,OAAO,OAAO;CACvB;CAEA,I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