@decimalturn/toml-patch 3.2.0-dev → 3.2.0-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 -660
  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 -196
  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 -123
  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 -193
  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 -111
  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 -465
  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 -122
  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 -96
  53. package/dist/dev/patch-lite2.js.map +0 -1
  54. package/dist/dev/patch.js +0 -2652
  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 -303
  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 -220
  65. package/dist/dev/toml-document.js.map +0 -1
  66. package/dist/dev/toml-format.js +0 -528
  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 -244
  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 -547
  81. /package/dist/{patch-lite.d.ts → patch.d.ts} +0 -0
package/dist/patch.js ADDED
@@ -0,0 +1,20 @@
1
+ //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
+ function e(e){return e.type===`Document`}function t(e){return e.type===`Table`}function n(e){return e.type===`TableArray`}function r(e){return e.type===`KeyValue`}function i(e){return e.type===`String`}function a(e){return e.type===`Integer`}function o(e){return e.type===`Float`}function s(e){return e.type===`Boolean`}function c(e){return e.type===`DateTime`}function l(e){return e.type===`InlineArray`}function u(e){return e.type===`InlineItem`}function d(e){return e.type===`InlineTable`}function f(r){return e(r)||t(r)||n(r)||d(r)||l(r)}function p(e){return i(e)||a(e)||o(e)||s(e)||c(e)||l(e)||d(e)}let m,h;function g(e){if(m===e&&h!==void 0)return h;let t=te(e);return m=e,h=t,t}function ee(){m=void 0,h=void 0}function _(e,t){let n=Array.isArray(e)?e:te(e);if(n.length===0)return{line:1,column:t};let r=0,i=n.length-1;for(;r<i;){let e=r+i>>>1;n[e]<t?r=e+1:i=e}n[r]<t&&r++;let a=r+1;return{line:a,column:t-(n[a-2]+1||0)}}function v(e,t){let n=g(e),r=n[t.line-2]===void 0?0:n[t.line-2]+1,i=n[t.line-1]||e.length;return e.substring(r,i)}function te(e){let t=[];for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r===10?t.push(n):r===13&&(e.charCodeAt(n+1)===10?(t.push(n+1),n++):t.push(n))}return t.push(e.length),t}function y(e){return{line:e.line,column:e.column}}function ne(e){return{start:y(e.start),end:y(e.end)}}var b=class extends Error{line;column;constructor(e,t,n){let r=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){let n=v(e,t),i=`${re(t.column)}^`;n&&(r+=`${n}\n${i}\n`)}r+=n,super(r),this.line=t.line,this.column=t.column}};function re(e,t=` `){return t.repeat(e)}const ie=/[\w,\d,",',+,\-,_]/;function ae(){return{reference:null,mixed:!1}}function*oe(e,t){let n=e.length,r=0,i=t??ae(),a=[],o=(e,t)=>({start:_(a,e),end:_(a,t)});for(;r<n;){let t=e.charCodeAt(r);if((t<=31||t===127)&&t!==9&&t!==13&&t!==10)throw new b(e,_(a,r),`Control char 0x${t.toString(16).toUpperCase().padStart(2,`0`)} not allowed`);if(t===13&&(r+1>=n||e.charCodeAt(r+1)!==10))throw new b(e,_(a,r),`Standalone CR; must be CRLF or LF`);if(t!==32&&t!==9&&t!==13){if(t===10)s(r);else if(t===91||t===93)yield{type:`Bracket`,raw:e[r],loc:o(r,r+1)};else if(t===123||t===125)yield{type:`Curly`,raw:e[r],loc:o(r,r+1)};else if(t===61)yield{type:`Equal`,raw:`=`,loc:o(r,r+1)};else if(t===44)yield{type:`Comma`,raw:`,`,loc:o(r,r+1)};else if(t===46)yield{type:`Dot`,raw:`.`,loc:o(r,r+1)};else if(t===35)yield c();else{let t=se(e,r,`'`)||se(e,r,`"`);t?yield l(t):yield u()}}r++}function s(t){a.push(t);let n=t>0&&e.charCodeAt(t-1)===13?`\r
3
+ `:`
4
+ `;i.reference===null?i.reference=n:i.reference!==n&&(i.mixed=!0)}function c(){let t=r;for(;r+1<n;){let t=e.charCodeAt(r+1);if(t===10||t===13)break;r++;let n=e.charCodeAt(r);if((n<=31||n===127)&&n!==9)throw new b(e,_(a,r),`Control char 0x${n.toString(16).toUpperCase().padStart(2,`0`)} not allowed`)}return{type:`Comment`,raw:e.slice(t,r+1),loc:o(t,r+1)}}function l(t){let i=r,c=t+t+t;for(r+=3;r<n;){if(se(e,r,t)){let n=3;for(;e[r+n]===t;)n++;if(n>=6)throw new b(e,_(a,r),`Invalid multiline string: ${n} consecutive ${t} characters`);if(n===3){r+=2;break}r+=n-3,r+=2;break}let i=e.charCodeAt(r);if(i===13&&(r+1>=n||e.charCodeAt(r+1)!==10))throw new b(e,_(a,r),`Standalone CR in multiline string; must be CRLF or LF`);if((i<=31||i===127)&&i!==9&&i!==10&&i!==13){let n=t===`"`?`multiline basic strings`:`multiline literal strings`,o=`0x${i.toString(16).toUpperCase().padStart(2,`0`)}`,s=``;i===0?s=`Null`:i===127&&(s=`DEL`);let c=s?`${s} (${o}) not allowed in ${n}`:`Control char ${o} not allowed in ${n}`;throw new b(e,_(a,r),c)}i===10&&s(r),r++}if(r>=n){if(t===`"`){let t=0,i=n-1;for(;i>=0&&e[i]===`\\`;)t++,i--;if(t>0&&t%2!=0)throw new b(e,_(a,r),`Unterminated multiline ${c} (possible escape issue)`)}throw new b(e,_(a,r),`Unterminated multiline ${c}`)}return{type:`Literal`,raw:e.slice(i,r+1),loc:o(i,r+1)}}function u(){let t=e[r];if(!ie.test(t))throw new b(e,_(a,r),`Unexpected char "${t}"`);let i=r,s=t===`"`,c=t===`'`;for(;r<n&&!(r+1>=n);){let t=e.charCodeAt(r+1);if(!(s||c)&&(t===32||t===9||t===10||t===13||t===44||t===46||t===93||t===125||t===61||t===35))break;if(r++,!(s||c)){let t=e.charCodeAt(r);if(t<=31||t===127)throw new b(e,_(a,r),`Control char 0x${t.toString(16).toUpperCase().padStart(2,`0`)} not allowed in unquoted value`)}if(s||c){let t=e.charCodeAt(r);if((t<=31||t===127)&&t!==9){let n=s?`basic strings`:`literal strings`,i=`0x${t.toString(16).toUpperCase().padStart(2,`0`)}`,o=``;t===10?o=`Newline`:t===13?o=`Carriage return`:t===0?o=`Null`:t===127&&(o=`DEL`);let c=o?`${o} (${i}) not allowed in ${n}`:`Control char ${i} not allowed in ${n}`;throw new b(e,_(a,r),c)}}let i=e[r];if(i===`"`&&!c&&(s=!s),i===`'`&&!s&&(c=!c),r+1>=n)break;if(s&&i===`\\`){let t=e[r+1];(t===`"`||t===`\\`)&&r++}}if(s||c)throw new b(e,_(a,i),`Expected close of string with ${s?`"`:`'`}`);return{type:`Literal`,raw:e.slice(i,r+1),loc:o(i,r+1)}}}function se(e,t,n){if(!n||e[t]!==n||e[t+1]!==n||e[t+2]!==n)return!1;if(n===`'`)return n;let r=0,i=t-1;for(;i>=0&&e[i]===`\\`;)r++,i--;return(r===0||r%2==0)&&n}const x=new Int8Array(128);x.fill(-1);for(let e=0;e<10;e++)x[48+e]=e;for(let e=0;e<6;e++)x[65+e]=10+e,x[97+e]=10+e;function S(e){let t=e.charCodeAt(0);return t<128&&x[t]!==-1}function ce(e,t){return x[e.charCodeAt(t)]<<12|x[e.charCodeAt(t+1)]<<8|x[e.charCodeAt(t+2)]<<4|x[e.charCodeAt(t+3)]}function le(e){return e.startsWith(`'''`)?de(e.slice(3,e.length-3)):e.startsWith(`'`)?e.slice(1,e.length-1):e.startsWith(`"""`)?ue(de(e.slice(3,e.length-3)),!0):e.startsWith(`"`)?ue(e.slice(1,e.length-1),!1):e}function ue(e,t){let n=e.length;if(!t&&e.indexOf(`\\`)===-1)return e;let r=[],i=0;for(let a=0;a<n;a++){if(e[a]!==`\\`)continue;if(a>i&&r.push(e.slice(i,a)),a++,a>=n)throw Error(`Trailing backslash`);let o=e[a];switch(o){case`b`:r.push(`\b`);break;case`t`:r.push(` `);break;case`n`:r.push(`
5
+ `);break;case`f`:r.push(`\f`);break;case`r`:r.push(`\r`);break;case`"`:r.push(`"`);break;case`\\`:r.push(`\\`);break;case`e`:r.push(`\x1B`);break;case`u`:{if(a+4>n||!S(e[a+1])||!S(e[a+2])||!S(e[a+3])||!S(e[a+4]))throw Error(`Invalid Unicode escape: \\u${e.slice(a+1,a+5)}`);let t=ce(e,a+1);if(t>=55296&&t<=57343)throw Error(`Invalid \\u${e.slice(a+1,a+5)}: surrogates not allowed`);r.push(String.fromCharCode(t)),a+=4;break}case`U`:{if(a+8>n)throw Error(`Invalid Unicode escape: \\U${e.slice(a+1,a+9)}`);for(let t=1;t<=8;t++)if(!S(e[a+t]))throw Error(`Invalid Unicode escape: \\U${e.slice(a+1,a+9)}`);let t=parseInt(e.slice(a+1,a+9),16);if(t>=55296&&t<=57343)throw Error(`Invalid \\U${e.slice(a+1,a+9)}: surrogates not allowed`);r.push(String.fromCodePoint(t)),a+=8;break}case`x`:{if(a+2>n||!S(e[a+1])||!S(e[a+2]))throw Error(`Invalid hex escape: \\x${e.slice(a+1,a+3)}`);let t=x[e.charCodeAt(a+1)]<<4|x[e.charCodeAt(a+2)];r.push(String.fromCharCode(t)),a+=2;break}default:if(t&&(o===`
6
+ `||o===`\r`||o===` `||o===` `)){let t=o===`
7
+ `||o===`\r`,r=a;for(;r<n&&(e[r]===` `||e[r]===` `||e[r]===`
8
+ `||e[r]===`\r`);)(e[r]===`
9
+ `||e[r]===`\r`)&&(t=!0),r++;if(!t)throw Error(`Invalid escape sequence: \\${o}`);a=r-1;break}throw Error(`Invalid escape sequence: \\${o}`)}i=a+1}return i===0?e:(i<n&&r.push(e.slice(i)),r.join(``))}function de(e){return e.charCodeAt(0)===10?e.slice(1):e.charCodeAt(0)===13&&e.charCodeAt(1)===10?e.slice(2):e}var fe=class{iterator;index;value;done;peeked;constructor(e){this.iterator=e,this.index=-1,this.value=void 0,this.done=!1,this.peeked=null}next(){if(this.done)return me();let e=this.peeked||this.iterator.next();return this.index+=1,this.value=e.value,this.done=e.done??!1,this.peeked=null,e}peek(){return this.done?me():(this.peeked||=this.iterator.next(),this.peeked)}[Symbol.iterator](){return this}};const pe=Object.freeze({value:void 0,done:!0});function me(){return pe}const he=new WeakMap;function ge(e,t){he.set(e,t)}function C(e){return{year:String(e.getUTCFullYear()).padStart(4,`0`),month:String(e.getUTCMonth()+1).padStart(2,`0`),day:String(e.getUTCDate()).padStart(2,`0`),hours:String(e.getUTCHours()).padStart(2,`0`),minutes:String(e.getUTCMinutes()).padStart(2,`0`),seconds:String(e.getUTCSeconds()).padStart(2,`0`),ms:e.getUTCMilliseconds()}}function w(e,t,n=/\.(\d+)\s*$/){if(t&&t.includes(`.`)){let r=t.match(n),i=r?r[1].length:3;return`.`+String(e).padStart(3,`0`).slice(0,i)}return e>0?`.`+String(e).padStart(3,`0`).replace(/0+$/,``):``}function _e(e){if(e===`Z`)return 0;let t=e[0]===`+`?1:-1,[n,r]=e.slice(1).split(`:`);return t*(parseInt(n)*60+parseInt(r))}var ve=class e{static IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/;static IS_TIME_ONLY=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;static IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;static IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;static IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/;static IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/;static IS_FULL_DATE=/(\d{4})-(\d+)-(\d+)/;static IS_FULL_TIME=/(\d+):(\d+)(?::(\d+))?/;static createDateWithOriginalFormat(t,n){if(e.IS_DATE_ONLY.test(n)){if(t.getUTCHours()!==0||t.getUTCMinutes()!==0||t.getUTCSeconds()!==0||t.getUTCMilliseconds()!==0){if(t instanceof O)return t;let e=t.toISOString().replace(`Z`,``);return e=e.replace(/\.000$/,``),new D(e,!1)}let e=t.toISOString().split(`T`)[0];return new T(e)}if(e.IS_TIME_ONLY.test(n)){if(t instanceof E)return t;{let e=C(t),r=w(e.ms,n);return new E(`${e.hours}:${e.minutes}:${e.seconds}${r}`,n)}}if(e.IS_LOCAL_DATETIME_T.test(n)){let e=C(t),r=w(e.ms,n);return new D(`${e.year}-${e.month}-${e.day}T${e.hours}:${e.minutes}:${e.seconds}${r}`,!1,n)}if(e.IS_LOCAL_DATETIME_SPACE.test(n)){let e=C(t),r=w(e.ms,n);return new D(`${e.year}-${e.month}-${e.day} ${e.hours}:${e.minutes}:${e.seconds}${r}`,!0,n)}if(e.IS_OFFSET_DATETIME_T.test(n)||e.IS_OFFSET_DATETIME_SPACE.test(n)){let r=n.match(/([+-]\d{2}:\d{2}|[Zz])$/),i=r?r[1]===`z`?`Z`:r[1]:`Z`,a=e.IS_OFFSET_DATETIME_SPACE.test(n),o=C(new Date(t.getTime()+_e(i)*6e4)),s=a?` `:`T`,c=w(o.ms,n,/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/);return new O(`${o.year}-${o.month}-${o.day}${s}${o.hours}:${o.minutes}:${o.seconds}${c}${i}`,a)}return t}},T=class extends Date{constructor(e){super(e)}toISOString(){let e=C(this);return`${e.year}-${e.month}-${e.day}`}},E=class extends Date{originalFormat;constructor(e,t){let n=e;/:\d{2}:\d{2}/.test(e)||(n=e+`:00`),super(`0000-01-01T${n}Z`),this.originalFormat=t}toISOString(){let e=C(this);return`${e.hours}:${e.minutes}:${e.seconds}${w(e.ms,this.originalFormat)}`}},D=class extends Date{useSpaceSeparator=!1;originalFormat;constructor(e,t=!1,n){let r=e;/\d{2}:\d{2}:\d{2}/.test(e)||(r=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,`$1:00$2`)),super(r.replace(` `,`T`)+`Z`),this.useSpaceSeparator=t,this.originalFormat=n||e}toISOString(){let e=C(this),t=this.useSpaceSeparator?` `:`T`;return`${e.year}-${e.month}-${e.day}${t}${e.hours}:${e.minutes}:${e.seconds}${w(e.ms,this.originalFormat)}`}},O=class extends Date{useSpaceSeparator=!1;originalOffset;originalFormat;constructor(e,t=!1){let n=e;/\d{2}:\d{2}:\d{2}/.test(e)||(n=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,`$1:00$2`)),super(n.replace(` `,`T`)),this.useSpaceSeparator=t,this.originalFormat=e;let r=e.match(/([+-]\d{2}:\d{2}|[Zz])$/);r&&(this.originalOffset=r[1]===`z`?`Z`:r[1])}toISOString(){if(this.originalOffset){let e=C(new Date(this.getTime()+_e(this.originalOffset)*6e4)),t=this.useSpaceSeparator?` `:`T`,n=w(e.ms,this.originalFormat,/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/);return`${e.year}-${e.month}-${e.day}${t}${e.hours}:${e.minutes}:${e.seconds}${n}${this.originalOffset}`}let e=super.toISOString();return this.useSpaceSeparator?e.replace(`T`,` `):e}};const k=ve,ye=`true`,be=/e/i,A=/_/g,xe=/^[+-]?inf$/,Se=/^[+-]?nan$/,j=/^[+-]?0x/i;function Ce(e){return e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||e===95||e===45}const M=/^[+-]?0o/i,N=/^[+-]?0b/i;function P(e,t,n){for(let r=0;r<e.length;r++)if(!Ce(e.charCodeAt(r)))throw new b(t,{line:n.line,column:n.column+r},`Invalid bare key char '${e[r]}'`)}function we(e,t,n){if(e.startsWith(`"""`)||e.startsWith(`'''`))throw new b(t,n,`Multiline strings cannot be keys`)}function F(e,t,n){try{return le(e)}catch(e){throw new b(t,n,e.message)}}function I(e,t,n,r=!0){if(e.endsWith(`_`)||(r?/^[+-]?_/.test(e):e.startsWith(`_`)))throw new b(t,n,`Underscore must be between digits`);if(/__/.test(e))throw new b(t,n,`Consecutive underscores not allowed`)}function L(e,t,n,r){let i=e.replace(A,``);if(/^[+-]?0\d/.test(i)&&!j.test(e)&&!M.test(e)&&!N.test(e))throw new b(t,n,`Leading zeros are not allowed in ${r}`)}function Te(e,t,n,r){if(/_[eE]/.test(e))throw new b(n,r,`Underscore before exponent is not allowed`);if(/[eE][+-]?_/.test(e))throw new b(n,r,`Underscore at start of exponent is not allowed`);if(/[eE][+-]?$/.test(e))throw new b(n,r,`Invalid float "${t}": incomplete exponent`);if(/[eE][+-]?.*\./.test(e))throw new b(n,r,`Invalid float "${t}": decimal point not allowed in exponent`)}function Ee(e,t,n,r,i,a){if(e.length!==2)throw new b(i,a,`"${r}": hour must be 2 digits`);if(t.length!==2)throw new b(i,a,`"${r}": minute must be 2 digits`);if(n&&n.length!==2)throw new b(i,a,`"${r}": second must be 2 digits`)}function De(e,t,n,r,i,a){if(e!==void 0){let t=parseInt(e,10);if(t<0||t>23)throw new b(i,a,`"${r}": hour must be 00-23`)}if(t!==void 0){let e=parseInt(t,10);if(e<0||e>59)throw new b(i,a,`"${r}": minute must be 00-59`)}if(n!==void 0){let e=parseInt(n,10);if(e<0||e>60)throw new b(i,a,`"${r}": second must be 00-60`)}}function Oe(e,t,n){if(j.test(e)||M.test(e)||N.test(e))return;let r=e.replace(/^[+-]/,``).replace(/_/g,``);if(!/^[0-9]+$/.test(r))throw new b(t,n,`Invalid integer "${e}"`)}function R(e,t,n,r,i,a,o){let s=r[0]+r[1].toUpperCase();if(RegExp(`^[+\\-]?`+s.replace(/([[\]])/g,`\\$1`)).test(e))throw new b(t,n,`${a} prefix must be lowercase "${r}"`);if(RegExp(`^[+\\-]?`+r+`_`,`i`).test(e))throw new b(t,n,`Underscore must be between digits`);let c=RegExp(`^[+\\-]?`+r,`i`),l=e.replace(c,``);if(!l||l===`_`||l.startsWith(`_`))throw new b(t,n,`Incomplete ${a.toLowerCase()} number`);let u=l.replace(/_/g,``);if(!i.test(u))throw new b(t,n,o??`Invalid ${a.toLowerCase()} digits`);if(/^[+-]/.test(e))throw new b(t,n,`${a} numbers cannot have a sign prefix`)}function*ke(e,t){let n=new fe(oe(e,t));try{for(;!n.next().done;){let t=B(n,e);for(let e of t)yield e}}finally{ee()}}function z(e){return{type:`Comment`,loc:e.value.loc,raw:e.value.raw}}function Ae(e,t){let n=!e.peek().done&&e.peek().value.type===`Bracket`?`TableArray`:`Table`,r=n===`Table`;if(r&&e.value.raw!==`[`)throw new b(t,e.value.loc.start,`Expected table opening "[", found ${e.value.raw}`);if(!r){let n=e.peek();if(n.done)throw new b(t,e.value.loc.start,`Expected "[[" for Array of Tables, found end of input`);if(e.value.raw!==`[`||n.value.raw!==`[`)throw new b(t,e.value.loc.start,`Expected "[[", found ${e.value.raw+n.value.raw}`);let r=e.value,i=n.value;if(r.loc.end.line!==i.loc.start.line||r.loc.end.column!==i.loc.start.column)throw new b(t,r.loc.start,`"[[" brackets must be adjacent (no whitespace)`)}let i=r?{type:`TableKey`,loc:e.value.loc}:{type:`TableArrayKey`,loc:e.value.loc};if(e.next(),n===`TableArray`&&e.next(),e.done)throw new b(t,i.loc.start,`Expected table key, reached end of file`);if(e.value.type===`Bracket`&&e.value.raw===`]`)throw new b(t,e.value.loc.start,n===`TableArray`?`Array of Tables header [[]] requires a table name`:`Table header [] requires a table name`);let a=e.value.raw;we(a,t,e.value.loc.start),a.startsWith(`"`)||a.startsWith(`'`)||P(a,t,e.value.loc.start);let o;for(o=[F(e.value.raw,t,e.value.loc.start)],i.item={type:`Key`,loc:e.value.loc,raw:e.value.raw,value:o};!e.peek().done&&e.peek().value.type===`Dot`;){e.next();let n=e.value;e.next();let r=e.value.raw;r.startsWith(`"`)||r.startsWith(`'`)||P(r,t,e.value.loc.start);let a=` `.repeat(n.loc.start.column-i.item.loc.end.column),o=` `.repeat(e.value.loc.start.column-n.loc.end.column);i.item.loc.end=e.value.loc.end,i.item.raw+=`${a}.${o}${e.value.raw}`;try{i.item.value.push(le(e.value.raw))}catch(n){let r=n;throw new b(t,e.value.loc.start,r.message)}}if(e.next(),!e.done){let n=i.loc.start.line;if(e.value.loc.start.line!==n)throw new b(t,e.value.loc.start,r?`Table header must be single-line`:`Array of Tables header must be single-line`)}if(r&&(e.done||e.value.raw!==`]`))throw new b(t,e.done?i.item.loc.end:e.value.loc.start,`Expected table closing "]", found ${e.done?`end of file`:e.value.raw}`);if(!r&&(e.done||e.peek().done||e.value.raw!==`]`||e.peek().value.raw!==`]`))throw new b(t,e.done||e.peek().done?i.item.loc.end:e.value.loc.start,`Expected "]]" closing, found ${e.done||e.peek().done?`end of file`:e.value.raw+e.peek().value.raw}`);if(!r){let n=e.value,r=e.peek().value;if(n.loc.end.line!==r.loc.start.line||n.loc.end.column!==r.loc.start.column)throw new b(t,n.loc.start,`"]]" brackets must be adjacent (no whitespace)`)}if(r||e.next(),i.loc.end=e.value.loc.end,!e.peek().done){let n=e.peek().value;if(n.loc.start.line===i.loc.end.line&&n.type!==`Comment`)throw new b(t,n.loc.start,`Extra content after ${r?`table`:`Array of Tables`} header`)}let s=[];for(;!e.peek().done&&e.peek().value.type!==`Bracket`;){e.next();let n=B(e,t);for(let e=0;e<n.length;e++)s.push(n[e])}return{type:r?`Table`:`TableArray`,loc:{start:y(i.loc.start),end:s.length?y(s[s.length-1].loc.end):y(i.loc.end)},key:i,items:s}}function je(e,t){let n=F(e.value.raw,t,e.value.loc.start);return{type:`String`,loc:e.value.loc,raw:e.value.raw,value:n}}function Me(e){return{type:`Boolean`,loc:e.value.loc,value:e.value.raw===ye}}function Ne(e,t){let n=e.value.loc,r=e.value.raw,i;if(!e.peek().done&&e.peek().value.type===`Literal`&&k.IS_FULL_DATE.test(r)&&/^\d/.test(e.peek().value.raw)&&k.IS_FULL_TIME.test(e.peek().value.raw)){let t=n.start;e.next(),n={start:t,end:e.value.loc.end},r+=` ${e.value.raw}`}if(!e.peek().done&&e.peek().value.type===`Dot`){let i=n.start;if(e.next(),e.peek().done||e.peek().value.type!==`Literal`)throw new b(t,e.value.loc.end,`Expected fractional value for DateTime`);e.next(),n={start:i,end:e.value.loc.end},r+=`.${e.value.raw}`}if(Fe(r,t,n.start),k.IS_FULL_DATE.test(r))i=k.IS_DATE_ONLY.test(r)?new T(r):k.IS_LOCAL_DATETIME_T.test(r)?new D(r,!1):k.IS_LOCAL_DATETIME_SPACE.test(r)?new D(r,!0):k.IS_OFFSET_DATETIME_T.test(r)?new O(r,!1):k.IS_OFFSET_DATETIME_SPACE.test(r)?new O(r,!0):new Date(r.replace(` `,`T`));else if(k.IS_TIME_ONLY.test(r))i=new E(r,r);else{let[e]=new Date().toISOString().split(`T`);i=new Date(`${e}T${r}`)}return{type:`DateTime`,loc:n,raw:r,value:i}}function Pe(e,t){return t===2?e%4==0&&e%100!=0||e%400==0?29:28:[31,28,31,30,31,30,31,31,30,31,30,31][t-1]}function Fe(e,t,n){if(/\.([Zz]|[+-])/.test(e))throw new b(t,n,`"${e}": fractional seconds needs digit after dot`);if(/[+-]$/.test(e))throw new b(t,n,`"${e}": offset needs HH:MM`);let r=/\d{2}:\d{2}/.test(e)?e.match(/([+-])(\d+)(:?)(\d*)$/):null;if(r){let e=r[0],i=r[2],a=r[3],o=r[4];if(a!==`:`)throw new b(t,n,`Offset "${e}": missing colon separator`);if(i.length!==2)throw new b(t,n,`Offset "${e}": hour must be 2 digits`);if(!o||o.length===0)throw new b(t,n,`Offset "${e}": minute required`);if(o.length!==2)throw new b(t,n,`Offset "${e}": minute must be 2 digits`);let s=parseInt(i,10);if(s<0||s>23)throw new b(t,n,`Offset "${e}": hour must be 00-23`);let c=parseInt(o,10);if(c<0||c>59)throw new b(t,n,`Offset "${e}": minute must be 00-59`)}if(!/^\d{4}-\d{2}-\d{2}(?:[Tt ]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})?)?$/.test(e)&&!/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/.test(e))throw/^\d{4}-\d{2}-\d{2}T$/.test(e)?new b(t,n,`"${e}": 'T' requires time component`):/^\d{4}-\d{2}-\d{2}[a-su-zA-SU-Z]/.test(e)?new b(t,n,`Invalid date "${e}": unexpected character after date`):/^\d{4}-\d{2}-\d{2}\d{2}:\d{2}/.test(e)?new b(t,n,`"${e}": missing 'T' or space separator`):new b(t,n,`Invalid datetime "${e}"`);let i=e.match(/^(\d+)-/);if(i&&i[1].length!==4)throw new b(t,n,`"${e}": year must be 4 digits`);let a=e.match(/^(\d+)-(\d+)-(\d+)/);if(a){let[,,r,i]=a;if(r.length!==2)throw new b(t,n,`"${e}": month must be 2 digits`);if(i.length!==2)throw new b(t,n,`"${e}": day must be 2 digits`)}let o=e.match(/[T ](\d+):(\d+)(?::(\d+))?/);if(o){let[,r,i,a]=o;Ee(r,i,a,e,t,n)}let s=e.match(/^(\d+):(\d+)(?::(\d+))?/);if(s&&!a){let[,r,i,a]=s;Ee(r,i,a,e,t,n)}let c=e.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/),l=e.match(/^(\d{2}):(\d{2})(?::(\d{2}))?/);if(c){let[,r,i,a,o,s,l]=c,u=parseInt(i,10);if(u<1||u>12)throw new b(t,n,`"${e}": month must be 01-12`);let d=parseInt(a,10);if(d<1||d>31)throw new b(t,n,`"${e}": day must be 01-31`);if(d>Pe(parseInt(r,10),u))throw new b(t,n,`"${e}": day ${a} invalid for ${r}-${i}`);De(o,s,l,e,t,n)}else if(l){let[,r,i,a]=l;De(r,i,a,e,t,n)}}function Ie(e,t){let n=e.value.loc,r=e.value.raw,i;if(xe.test(r))i=r.startsWith(`-`)?-1/0:1/0;else if(Se.test(r)){let e=new Float64Array(1),t=new DataView(e.buffer);r.startsWith(`-`)?(t.setUint32(0,0,!0),t.setUint32(4,4294443008,!0)):(t.setUint32(0,0,!0),t.setUint32(4,2146959360,!0)),i=e[0];let a=r.startsWith(`+`)?`+`:r.startsWith(`-`)?`-`:void 0;return{type:`Float`,loc:n,raw:r,value:i,nanSign:a}}else if(!e.peek().done&&e.peek().value.type===`Dot`){let a=n.start;{if(be.test(r)&&!j.test(r))throw new b(t,n.start,`Float "${r}": dot after exponent`);let e=r;L(e,t,n.start,`the integer part of a float`);let i=e.replace(/^[+-]/,``);if(i===``||i===`_`)throw new b(t,n.start,`Float: digit required before dot`);I(e,t,n.start)}if(e.next(),e.peek().done||e.peek().value.type!==`Literal`)throw new b(t,e.value.loc.end,`Expected fraction value for Float`);e.next(),r+=`.${e.value.raw}`,n={start:a,end:e.value.loc.end};{let n=e.value.raw;if(!/^\d/.test(n))throw new b(t,e.value.loc.start,`Float: fraction must start with digit, found "${n}"`);I(n,t,e.value.loc.start,!1),Te(n,r,t,e.value.loc.start)}i=Number(r.replace(A,``))}else{if(I(r,t,n.start),Te(r,r,t,n.start),!e.peek().done&&e.peek().value.type===`Dot`)throw new b(t,e.peek().value.loc.start,`Float "${r}.": dot after exponent`);L(r,t,n.start,`the integer part of a float`),i=Number(r.replace(A,``))}if(Number.isNaN(i)&&!Se.test(r))throw new b(t,n.start,`Invalid float "${r}"`);return{type:`Float`,loc:n,raw:r,value:i}}function Le(e,t){let n=e.value.raw,r=e.value.loc;if(/^\d{1,}-\d{1,}/.test(n)||/^\d{1,}:\d{1,}/.test(n)||/^\d{6}-\d{2}$/.test(n))throw new b(t,r.start,`Invalid integer "${n}"`);if(n===`-0`||n===`+0`)return{type:`Integer`,loc:r,raw:n,value:0};if(/^[+-]{2,}/.test(n))throw new b(t,r.start,`Double sign is not allowed in integers`);L(n,t,r.start,`decimal integers`),I(n,t,r.start),Oe(n,t,r.start);let i=10;j.test(n)?(i=16,R(n,t,r.start,`0x`,/^[0-9a-fA-F]+$/,`Hexadecimal`)):M.test(n)?(i=8,R(n,t,r.start,`0o`,/^[0-7]+$/,`Octal`,`Invalid octal digits (must be 0-7)`)):N.test(n)&&(i=2,R(n,t,r.start,`0b`,/^[01]+$/,`Binary`,`Invalid binary digits (must be 0 or 1)`));let a=parseInt(n.replace(A,``).replace(M,``).replace(N,``),i);if(Number.isNaN(a))throw new b(t,r.start,`Invalid integer "${n}"`);return{type:`Integer`,loc:r,raw:n,value:a}}function B(e,t){if(e.value.type===`Comment`)return[z(e)];if(e.value.type===`Bracket`)return[Ae(e,t)];if(e.value.type===`Literal`)return Re(e,t);throw e.value.type===`Equal`?new b(t,e.value.loc.start,`Missing key before '='`):new b(t,e.value.loc.start,`Unexpected token "${e.value.type}"`)}function Re(e,t){let n=e.value.raw;if(n.endsWith(`:`))throw new b(t,{line:e.value.loc.start.line,column:e.value.loc.start.column+[...n].length-1},`Use '=' to separate keys and values, not ':'`);we(n,t,e.value.loc.start),n.startsWith(`"`)||n.startsWith(`'`)||P(n,t,e.value.loc.start);let r;r=[F(e.value.raw,t,e.value.loc.start)];let i={type:`Key`,loc:e.value.loc,raw:e.value.raw,value:r};for(;!e.peek().done&&e.peek().value.type===`Dot`;){e.next();let n=e.value;e.next();let r=e.value.raw;we(r,t,e.value.loc.start),r.startsWith(`"`)||r.startsWith(`'`)||P(r,t,e.value.loc.start);let a=v(t,i.loc.end),o=v(t,n.loc.end),s=a.slice(i.loc.end.column,n.loc.start.column),c=o.slice(n.loc.end.column,e.value.loc.start.column);i.loc.end=e.value.loc.end,i.raw+=`${s}.${c}${e.value.raw}`,i.value.push(F(e.value.raw,t,e.value.loc.start))}if(e.next(),!e.done&&e.value.loc.start.line!==i.loc.end.line)throw new b(t,e.value.loc.start,`"=" must be on same line as key`);if(e.done||e.value.type!==`Equal`)throw!e.done&&e.value.raw===`:`?new b(t,e.value.loc.start,`Use '=' to separate keys and values, not ':'`):new b(t,e.done?i.loc.end:e.value.loc.start,`Expected "=" for key-value`);let a=e.value.loc.start.column,o=e.value.loc.start.line;if(e.next(),e.done)throw new b(t,i.loc.start,`Expected value, reached EOF`);if(e.value.loc.start.line!==o)throw new b(t,e.value.loc.start,`Value must be on same line as '='`);if(e.done)throw new b(t,i.loc.start,`Expected value for key-value`);let s=ze(e,t),c=s[0];if(!e.peek().done){let n=e.peek().value;if(n.type===`Dot`&&n.loc.start.line===c.loc.end.line&&(c.type===`Float`||c.type===`Integer`))throw new b(t,n.loc.start,`Invalid number: multiple decimal points not allowed`);if((n.type===`Literal`||n.type===`Bracket`)&&n.loc.start.line===c.loc.end.line)throw new b(t,n.loc.start,`Key/value pairs must be separated by a newline`)}return s[0]={type:`KeyValue`,key:i,value:c,loc:{start:y(i.loc.start),end:y(c.loc.end)},equals:a},s}function ze(e,t){if(e.value.type===`Literal`){let n=e.value.raw;return n[0]===`"`||n[0]===`'`?[je(e,t)]:n===ye||n===`false`?[Me(e)]:/^\d/.test(n)&&(/^\d{1,}-\d{1,}/.test(n)||/^\d{1,}:\d{1,}/.test(n))?[Ne(e,t)]:!e.peek().done&&e.peek().value.type===`Dot`||xe.test(n)||Se.test(n)||be.test(n)&&!j.test(n)?[Ie(e,t)]:[Le(e,t)]}if(e.value.type===`Curly`){let[n,r]=Ve(e,t);return[n,...r]}if(e.value.type===`Bracket`){let[n,r]=He(e,t);return[n,...r]}throw e.value.type===`Dot`?new b(t,e.value.loc.start,`Number cannot start with a dot`):new b(t,e.value.loc.start,`Unrecognized token type`)}function Be(e){for(let t=1;t<e.length;t++){let n=e[t-1],r=e[t];if(n.loc.end.line===r.loc.start.line){let e=r.loc.start.column-n.loc.end.column;if(e>=1)return e}}}function Ve(e,t){if(e.value.raw!==`{`)throw new b(t,e.value.loc.start,`Expected "{" for inline table`);let n={type:`InlineTable`,loc:e.value.loc,items:[]},r=[];for(e.next();!e.done&&(e.value.type!==`Curly`||e.value.raw!==`}`);){if(e.value.type===`Comment`){r.push(z(e)),e.next();continue}if(e.value.type===`Comma`){let r=n.items[n.items.length-1];if(!r)throw new b(t,e.value.loc.start,`Leading comma in inline table`);if(r.comma)throw new b(t,e.value.loc.start,`Consecutive commas in inline table`);r.comma=!0,r.loc.end=e.value.loc.start,e.next();continue}let i=n.items[n.items.length-1];if(i&&!i.comma)throw new b(t,e.value.loc.start,`Missing comma between inline table items`);let a=B(e,t),o=a[0];if(o.type===`KeyValue`){n.items.push({type:`InlineItem`,loc:ne(o.loc),item:o,comma:!1});for(let e=1;e<a.length;e++)r.push(a[e])}e.next()}if(e.done||e.value.type!==`Curly`||e.value.raw!==`}`)throw new b(t,e.done?n.loc.start:e.value.loc.start,`Expected "}"`);n.loc.end=e.value.loc.end;{let e=Be(n.items);e!==void 0&&ge(n,e)}return[n,r]}function He(e,t){if(e.value.raw!==`[`)throw new b(t,e.value.loc.start,`Expected "[" for inline array`);let n={type:`InlineArray`,loc:e.value.loc,items:[]},r=[];for(e.next();!e.done&&(e.value.type!==`Bracket`||e.value.raw!==`]`);){if(e.value.type===`Comma`){let r=n.items[n.items.length-1];if(!r)throw new b(t,e.value.loc.start,`Leading comma in array`);if(r.comma)throw new b(t,e.value.loc.start,`Consecutive commas in array`);r.comma=!0,r.loc.end=e.value.loc.start}else if(e.value.type===`Comment`)r.push(z(e));else{let i=n.items[n.items.length-1];if(i&&!i.comma)throw new b(t,e.value.loc.start,`Missing comma between array elements`);let a=ze(e,t),o=a[0];n.items.push({type:`InlineItem`,loc:ne(o.loc),item:o,comma:!1});for(let e=1;e<a.length;e++)r.push(a[e])}e.next()}if(e.done||e.value.type!==`Bracket`||e.value.raw!==`]`)throw new b(t,e.done?n.loc.start:e.value.loc.start,`Expected "]"`);n.loc.end=e.value.loc.end;{let e=Be(n.items);e!==void 0&&ge(n,e)}return[n,r]}function V(e){return e[e.length-1]}function H(){return Object.create(null)}function Ue(e,t){return e===t&&(typeof e!=`number`||Object.is(e,t))}const We=new DataView(new ArrayBuffer(8));function U(e){return Number.isNaN(e)?(We.setFloat64(0,e,!0),!!(We.getUint32(4,!0)&2147483648)):!1}function W(e){return Object.prototype.toString.call(e)===`[object Date]`}const Ge=new Set([`Temporal.PlainDate`,`Temporal.PlainTime`,`Temporal.PlainDateTime`,`Temporal.ZonedDateTime`,`PlainDate`,`PlainTime`,`PlainDateTime`,`ZonedDateTime`]);function G(e){var t;return typeof e==`object`&&!!e&&Ge.has((t=e.constructor)==null?void 0:t.name)&&typeof e.equals==`function`}function Ke(e){return e&&typeof e==`object`&&!W(e)&&!G(e)&&!Array.isArray(e)}function qe(e,t){return t in e}function K(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Je(e,t){return G(e)&&G(t)?e.toString()===t.toString():W(e)&&W(t)?e.toISOString()===t.toISOString():!1}function q(e){let t=[],n=new WeakSet,r=[{value:e}];for(;r.length>0;){let e=r.pop();if(`text`in e){t.push(e.text),`leave`in e&&n.delete(e.leave);continue}let i=e.value;if(Ke(i)){if(n.has(i))throw TypeError(`Cannot stableStringify a circular structure`);n.add(i);let e=Object.keys(i).sort();t.push(`{`),r.push({leave:i,text:`}`});for(let t=e.length-1;t>=0;t--){let n=e[t];t<e.length-1&&r.push({text:`,`}),r.push({value:i[n]}),r.push({text:`:`}),r.push({text:JSON.stringify(n)})}}else if(Array.isArray(i)){if(n.has(i))throw TypeError(`Cannot stableStringify a circular structure`);n.add(i),t.push(`[`),r.push({leave:i,text:`]`});for(let e=i.length-1;e>=0;e--)e<i.length-1&&r.push({text:`,`}),r.push({value:i[e]})}else if(G(i))t.push(JSON.stringify(i.toString()));else if(W(i))t.push(JSON.stringify(i.toISOString()));else if(typeof i==`bigint`)t.push(i.toString()+`n`);else if(typeof i==`number`&&!Number.isFinite(i)){let e=Number.isNaN(i)?U(i)?`-`:`+`:i<0?`-`:`+`;t.push(`${e}${String(i)}`)}else typeof i==`number`&&Object.is(i,-0)?t.push(`-0`):t.push(JSON.stringify(i))}return t.join(``)}typeof String.prototype.isWellFormed==`function`&&String.prototype.isWellFormed;function Ye(e,t=`asNeeded`){let n=e.replace(/_/g,``),r=n;if(/^[+-]?0x/i.test(n)||/^[+-]?0o/i.test(n)||/^[+-]?0b/i.test(n)){let e=n[0]===`+`||n[0]===`-`?n[0]:``;r=e+n.slice(+!!e).toLowerCase()}let i;try{i=BigInt(r)}catch{return Number(n)}return t===!0?i:t===!1||i>=BigInt(-(2**53-1))&&i<=BigInt(2**53-1)?Number(i):i}function Xe(e,t,n){for(let r of e.items){let e=r.item;if(e.value.type===`InlineTable`){let r=t.concat(e.key.value);n.add(J(r)),Xe(e.value,r,n)}}}function Ze(e){var t,n,r,i,a,o;if((t=e.constructor)!=null&&(t=t.name)!=null&&(n=t.startsWith)!=null&&n.call(t,`Temporal.`)||((r=e.constructor)==null?void 0:r.name)===`PlainDate`||((i=e.constructor)==null?void 0:i.name)===`PlainTime`||((a=e.constructor)==null?void 0:a.name)===`PlainDateTime`||((o=e.constructor)==null?void 0:o.name)===`ZonedDateTime`)return e;let s=globalThis.Temporal;if(e instanceof T)return s.PlainDate.from(e.toISOString());if(e instanceof E)return s.PlainTime.from(e.toISOString());if(e instanceof D)return s.PlainDateTime.from(e.toISOString().replace(` `,`T`));if(e instanceof O){let t=e.toISOString().replace(` `,`T`),n=t.match(/([+-]\d{2}:\d{2}|Z)$/),r=n?n[1]:`Z`,i=t.replace(/([+-]\d{2}:\d{2}|Z)$/,``),a=r===`Z`?`+00:00`:r;return s.ZonedDateTime.from(`${i}${r}[${a}]`)}return s.PlainDateTime.from(e.toISOString().replace(`Z`,``))}function Qe(e,t=``,n={}){let{integersAsBigInt:r=`asNeeded`,temporal:i=!1}=n,a=H(),o=new Set,s=new Set,c=new Set,l=new Set,u=new Set,d=a,f=[],p={tables:o,table_arrays:s,defined:c,implicit_tables:l,inline_tables:u};for(let t of e)switch(t.type){case`Table`:m(t);for(let e of t.items)e.type===`KeyValue`&&g(e);break;case`TableArray`:h(t);for(let e of t.items)e.type===`KeyValue`&&g(e);break;case`KeyValue`:g(t)}return a;function m(e){let n=e.key.item.value;try{et(a,[],n,e.type,p)}catch(n){let r=n;throw new b(t,e.key.loc.start,r.message)}let r=J(n);o.add(r),c.add(r),d=tt(a,n),f=n}function h(e){let n=e.key.item.value;try{et(a,[],n,e.type,p)}catch(n){let r=n;throw new b(t,e.key.loc.start,r.message)}let r=J(n);s.add(r),c.add(r),d=nt(a,n),f=n}function g(e){let n=e.key.value;try{et(d,f,n,e.type,p)}catch(n){let r=n;throw new b(t,e.key.loc.start,r.message)}if(n.length>1)for(let e=1;e<n.length;e++){let t=J(f.concat(n.slice(0,e)));l.add(t),c.add(t)}let a;try{a=$e(e.value,{integersAsBigInt:r,temporal:i})}catch(n){let r=n;throw new b(t,e.value.loc.start,r.message)}if(e.value.type===`InlineTable`){let t=f.concat(n);u.add(J(t)),Xe(e.value,t,u)}let o=n.length>1?tt(d,n.slice(0,-1)):d;o[V(n)]=a,c.add(J(f.concat(n)))}}function $e(e,t={}){let{integersAsBigInt:n=`asNeeded`,temporal:r=!1}=t;switch(e.type){case`InlineTable`:let t=H(),i=new Set,a=new Map;return e.items.forEach(({item:e})=>{let o=e.key.value,s=$e(e.value,{integersAsBigInt:n,temporal:r}),c=at(o),l=J(o);if(i.has(l))throw Error(`Duplicate key "${c}" in inline table`);for(let e=1;e<o.length;e++){let t=at(o.slice(0,e));if(i.has(J(o.slice(0,e))))throw Error(`Key "${c}" conflicts with key: "${t}"`)}if(a.has(l)){let e=a.get(l);throw Error(`Key "${c}" conflicts with key: "${e}"`)}i.add(l);for(let e=1;e<o.length;e++){let t=J(o.slice(0,e));a.has(t)||a.set(t,c)}let u=o.length>1?tt(t,o.slice(0,-1)):t;u[V(o)]=s}),t;case`InlineArray`:return e.items.map(e=>$e(e.item,{integersAsBigInt:n,temporal:r}));case`DateTime`:if(r){if(globalThis.Temporal===void 0)throw Error(`Temporal API is not available in this runtime. Set temporal: false or use a runtime with Temporal support.`);return Ze(e.value)}return e.value;case`String`:return e.value;case`Integer`:return Ye(e.raw,n);case`Float`:case`Boolean`:return e.value;default:throw Error(`Unrecognized value type "${e.type}"`)}}function et(e,t,n,r,i){let a=t.length>0?[...t]:[],o=Array(n.length),s=Array(n.length);for(let e=0;e<n.length;e++)a.push(n[e]),o[e]=at(a),s[e]=J(a);let c=o[n.length-1],l=s[n.length-1];if(r===`KeyValue`&&n.length>1)for(let e=1;e<n.length;e++){let t=o[e-1];if(i.inline_tables.has(s[e-1]))throw Error(`Cannot extend inline table at ${t}`)}if((r===`Table`||r===`TableArray`)&&i.inline_tables.has(l))throw Error(`Cannot extend inline table at ${c}`);if(r===`Table`||r===`TableArray`)for(let e=1;e<n.length;e++){let t=o[e-1];if(i.inline_tables.has(s[e-1]))throw Error(`Cannot extend inline table at ${t}`)}if(r===`KeyValue`&&n.length>1)for(let e=1;e<n.length;e++){let t=o[e-1];if(i.table_arrays.has(s[e-1]))throw Error(`Cannot traverse Array of Tables at ${t}`)}if((r===`Table`||r===`TableArray`)&&i.implicit_tables.has(l))throw Error(`Implicit table already defined: ${c}`);if(r===`KeyValue`&&i.implicit_tables.has(l))throw Error(`Table already defined: ${c}`);if(r===`KeyValue`&&n.length>1)for(let e=1;e<=n.length;e++){let t=o[e-1];if(i.tables.has(s[e-1]))throw Error(`Cannot extend explicit table ${t} with dotted keys`)}let u=0;for(let t of n){if(!qe(e,t))return;if(it(e[t]))throw Error(`Value already defined for ${o[u]}`);let r=o[u];if(Array.isArray(e[t])&&!i.table_arrays.has(s[u]))throw Error(`Cannot add to static array at ${r}`);let a=u++<n.length-1;e=Array.isArray(e[t])&&a?V(e[t]):e[t]}let d=c;if(e&&r===`Table`&&i.defined.has(l)||e&&r===`KeyValue`&&n.length===1&&i.defined.has(l)&&!it(e))throw Error(`Table already defined: ${d}`);if(e&&r===`TableArray`&&!i.table_arrays.has(l))throw Error(`Cannot add Array of Tables to table at ${d}`)}function tt(e,t){let n=rt(e,t.slice(0,-1)),r=V(t);return n[r]||(n[r]=H()),n[r]}function nt(e,t){let n=rt(e,t.slice(0,-1)),r=V(t);n[r]||(n[r]=[]);let i=H();return n[V(t)].push(i),i}function rt(e,t){return t.reduce((e,t)=>(e[t]||(e[t]=H()),Array.isArray(e[t])?V(e[t]):e[t]),e)}function it(e){return typeof e!=`object`&&!W(e)}function at(e){return e.join(`.`)}function J(e){return JSON.stringify(e)}var Y=class extends Error{code;path;constructor(e,t,n){super(n),this.name=`PatchLiteError`,this.code=e,this.path=t}};function X(e){let t=``;for(let n of e)t+=typeof n==`number`?`[${n}]`:t?`.${n}`:n;return t||`(root)`}function ot(e){let t=typeof e;return t===`string`||t===`boolean`||t===`number`||t===`bigint`}function Z(e){if(e===null)return`null`;if(Array.isArray(e))return`array`;if(e instanceof Date)return`date`;let t=typeof e;return t===`object`?`table`:t}function st(e,t){return U(e)===U(t)}function ct(e){let t=e.toISOString();return/^\d{4}-\d{2}-\d{2}$/.test(t)?`date`:/^\d{2}:\d{2}:\d{2}(?:\.\d+)?$/.test(t)?`time`:/(?:[Zz]|[+-]\d{2}:\d{2})$/.test(t)?`offset`:`datetime`}function lt(e,t){return e.getTime()===t.getTime()&&ct(e)===ct(t)}function ut(e,t,n=[]){if(Je(e,t)||e instanceof Date&&t instanceof Date&&lt(e,t)||Ue(e,t)||typeof e==`number`&&typeof t==`number`&&Number.isNaN(e)&&Number.isNaN(t)&&st(e,t))return[];let r=Array.isArray(e),i=Array.isArray(t);if(r&&i)return ft(e,t,n);if(r||i)throw new Y(`TypeChange`,n,`Cannot change a ${r?`array`:Z(e)} to a ${i?`array`:Z(t)} at ${X(n)}`);let a=Ke(e),o=Ke(t);if(a&&o)return dt(e,t,n);if(a||o)throw new Y(`TypeChange`,n,`Cannot change a ${a?`table`:Z(e)} to a ${o?`table`:Z(t)} at ${X(n)}`);if(e instanceof Date&&t instanceof Date)return[{type:`Edit`,path:n}];if(e instanceof Date||t instanceof Date)throw new Y(`TypeChange`,n,`Cannot change a ${Z(e)} to a ${Z(t)} at ${X(n)}`);if(!ot(e)||!ot(t))throw new Y(`UnsupportedValue`,n,`Unsupported value type ${Z(t)} at ${X(n)}`);return[{type:`Edit`,path:n}]}function dt(e,t,n){let r=Object.keys(e),i=Object.keys(t),a=new Set(i);for(let e of r)if(!a.has(e))throw new Y(`RemovedKey`,n.concat(e),`Cannot remove key ${X(n.concat(e))}`);let o=new Set(r);for(let e of i)if(!o.has(e))throw new Y(`AddedKey`,n.concat(e),`Cannot add key ${X(n.concat(e))}`);let s=[];for(let i of r){let r=ut(e[i],t[i],n.concat(i));for(let e of r)s.push(e)}return s}function ft(e,t,n){if(e.length!==t.length)throw new Y(`ArrayLengthChange`,n,`Cannot change the length of array at ${X(n)} (${e.length} to ${t.length})`);let r=e.map(q),i=t.map(q);if(!r.every((e,t)=>e===i[t])){let e=r.slice().sort(),t=i.slice().sort();if(e.length===t.length&&e.every((e,n)=>e===t[n]))throw new Y(`ArrayReorder`,n,`Cannot reorder array elements at ${X(n)}`)}let a=[];for(let r=0;r<e.length;r++){let i=ut(e[r],t[r],n.concat(r));for(let e of i)a.push(e)}return a}function pt(e){if(e.includes(`'`))return!1;for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32&&n!==9||n===127)return!1}return!0}function mt(e){if(e.includes(`'''`))return!1;for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n===13){if(e.charCodeAt(t+1)!==10)return!1}else if(n<32&&n!==9&&n!==10||n===127)return!1}return!0}function ht(e,t,n){let r=typeof e;if(r===`string`)return Ct(e,t==null?void 0:t.raw);if(r===`boolean`)return e?`true`:`false`;if(r===`bigint`)return e.toString();if(r===`number`)return Number.isFinite(e)?Number.isSafeInteger(e)&&!Object.is(e,-0)&&!o(t)?yt(e,t==null?void 0:t.raw):bt(e,o(t)?t.raw:void 0):St(e);if(e instanceof Date)return gt(e,t);throw new Y(`UnsupportedValue`,n,`Unsupported value type ${Object.prototype.toString.call(e)} at ${X(n)}`)}function gt(e,t){let n=t==null?void 0:t.raw,r=_t(e);return typeof n==`string`?ve.createDateWithOriginalFormat(r,n).toISOString():r.toISOString()}function _t(e){let t=e;if(typeof t.isDate!=`function`||typeof t.isTime!=`function`)return e;let n=e.toISOString().replace(/\.000(?=([Zz]|[+-]\d{2}:\d{2})$|$)/,``);return t.isDate()?new T(n):t.isTime()?new E(n,n):t.isLocal()?new D(n,!1):new O(n,!1)}function vt(e){if(e.startsWith(`0x`))return{radix:16,prefix:`0x`};if(e.startsWith(`0o`))return{radix:8,prefix:`0o`};if(e.startsWith(`0b`))return{radix:2,prefix:`0b`}}function yt(e,t){if(t){let n=vt(t);if(n&&e>=0){let r=n.radix===16&&/[A-F]/.test(t),i=e.toString(n.radix);return r&&(i=i.toUpperCase()),n.prefix+i}}return String(e)}function bt(e,t){if(Object.is(e,-0))return`-0.0`;if(t&&/[eE]/.test(t))return xt(e,t);let n=String(e);return/[.eE]/.test(n)?n:`${n}.0`}function xt(e,t){let n=t.slice(0,t.search(/[eE]/)),r=n.indexOf(`.`),i=r===-1?``:n.slice(r+1),a=!/[1-9]/.test(i),o=Number.isInteger(e)&&!Object.is(e,-0)&&a?i.length:0,[s,c]=e.toExponential().split(/[eE]/),l=s.includes(`.`)?s.length-s.indexOf(`.`)-1:0,u=Math.max(o,l);return`${u>0?Number(s).toFixed(u):String(Number(s))}${t.includes(`E`)?`E`:`e`}${c.replace(/^\+/,``)}`}function St(e){return Number.isNaN(e)?U(e)?`-nan`:`nan`:e>0?`inf`:`-inf`}function Q(e,t,n){return e.startsWith(t+`\r
10
+ `)?`\r
11
+ `:e.startsWith(t+`
12
+ `)?`
13
+ `:n.startsWith(`\r
14
+ `)?`\r
15
+ `:n.startsWith(`
16
+ `)?`
17
+ `:``}function Ct(e,t){if(t){if(t.startsWith(`'''`))return mt(e)?`'''`+Q(t,`'''`,e)+e+`'''`:Et(e);if(t.startsWith(`"""`))return wt(e,t);if(t.startsWith(`'`)){if(pt(e))return`'`+e+`'`;if(mt(e))return`'''`+Q(t,`'''`,e)+e+`'''`}}return Et(e)}function wt(e,t){let n=Tt(e);return`"""`+Q(t,`"""`,n)+n+`"""`}function Tt(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n],i=e.charCodeAt(n);t+=r===`\\`?`\\\\`:r===`\b`?`\\b`:r===` `?`\\t`:r===`
18
+ `?`
19
+ `:r===`\f`?`\\f`:r===`\r`?e.charCodeAt(n+1)===10?`\r`:`\\r`:i>=0&&i<=7||i===11||i>=14&&i<=31||i===127?`\\u`+i.toString(16).padStart(4,`0`).toUpperCase():r}return t.replace(/"""/g,`""\\"`)}function Et(e){let t=`"`;for(let n of e){let e=n.codePointAt(0);t+=n===`"`?`\\"`:n===`\\`?`\\\\`:n===`\b`?`\\b`:n===` `?`\\t`:n===`
20
+ `?`\\n`:n===`\f`?`\\f`:n===`\r`?`\\r`:e<32||e===127?`\\u`+e.toString(16).padStart(4,`0`).toUpperCase():n}return t+=`"`,t}function $(i,a){if(!a.length)return u(i)&&r(i.item)?i.item:i;if(r(i))return $(i.value,a);let o={},s,c;if(f(i)&&i.items.some((l,d)=>{try{let f=[];if(r(l))f=l.key.value;else if(t(l))f=l.key.item.value;else if(n(l)){f=l.key.item.value;let e=q(f);o[e]||(o[e]=0);let t=o[e]++;f=f.concat(t)}else u(l)&&r(l.item)?f=l.item.key.value:u(l)&&(f=[d]);if(f.length&&K(f,a.slice(0,f.length))){let t=a.slice(f.length);if(e(i)&&n(l)&&t.length>0){let e=l.key.item.value,r=i,a=r.items.findIndex((t,r)=>r>d&&n(t)&&K(t.key.item.value,e)),o=a===-1?r.items.length:a;s=Dt(l,t,e,r.items.slice(d+1,o))}else s=u(l)&&r(l.item)?a.length===f.length?l:$(l.item.value,t):u(l)&&a.length>f.length?$(l.item,t):$(l,t);return!0}return(r(l)||u(l)&&r(l.item))&&f.length>a.length&&K(f.slice(0,a.length),a)&&(c||=l),!1}catch{return!1}}),!s&&c&&(s=c),!s)throw Error(`Node not found at ${a.join(`.`)}`);return s}function Dt(e,r,i,a){try{return $(e,r)}catch{}let o={};for(let e of a){let a=[];if(t(e)){let t=e.key.item.value;t.length>i.length&&K(t.slice(0,i.length),i)&&(a=t.slice(i.length))}else if(n(e)){let t=e.key.item.value;if(t.length>i.length&&K(t.slice(0,i.length),i)){let e=t.slice(i.length),n=q(e);o[n]||(o[n]=0);let r=o[n]++;a=e.concat(r)}}if(a.length&&K(a,r.slice(0,a.length)))try{return $(e,r.slice(a.length))}catch{}}throw Error(`Node not found at (aot scope) ${r.join(`.`)}`)}function Ot(e){return e.charCodeAt(0)===65279}const kt=new WeakMap,At=new WeakMap;function jt(e,t){return(e[t.line-1]??e[e.length-1])+t.column}function Mt(e,t){let n=Nt(t);for(let t of e)n(t)}function Nt(e){let i=[0];for(let t=0;t<e.length;t++)e.charCodeAt(t)===10&&i.push(t+1);return a=>{let o=[a];for(;o.length>0;){let a=o.pop(),s=[jt(i,a.loc.start),jt(i,a.loc.end)];if(Object.defineProperty(a,"range",{configurable:!0,enumerable:!1,value:s}),kt.set(a,e),At.set(a,Pt(a).slice()),r(a))o.push(a.value),o.push(a.key);else if(u(a))o.push(a.item);else if(t(a)||n(a)){o.push(a.key);let e=a.items;for(let t=e.length-1;t>=0;t--)o.push(e[t])}else if(f(a)){let e=a.items;for(let t=e.length-1;t>=0;t--)o.push(e[t])}}}}function Pt(e){return r(e)?[e.key,e.value]:u(e)?[e.item]:t(e)||n(e)?[e.key,...e.items]:f(e)?e.items:[]}function Ft(e){let t=1,n=0;for(let r of e){let e=r.loc.end;(e.line>t||e.line===t&&e.column>n)&&(t=e.line,n=e.column)}return{type:`Document`,loc:{start:{line:1,column:0},end:{line:t,column:n}},items:e}}function It(e){return r(e)?e.value:u(e)?r(e.item)?e.item.value:e.item:e}function Lt(e,t){let n=e;for(let e of t)n=n==null?void 0:n[e];return n}function Rt(e,t){if(arguments.length>2&&arguments[2]!==void 0&&arguments[2]!==null)throw new Y(`UnsupportedOption`,[],`patch-lite does not support formatting options; use patch() from the main package`);let n=Ot(e),r=n?e.slice(1):e,i=Array.from(ke(r));Mt(i,r);let a=ut(Qe(i,r,{integersAsBigInt:`asNeeded`,temporal:!1}),t);if(a.length===0)return e;let o=Ft(i),s=[];for(let e of a){let n=It($(o,e.path));if(!p(n))throw Error(`Cannot locate a value at ${X(e.path)}`);let r=n.range;if(!r)throw Error(`Missing source location for value at ${X(e.path)}`);s.push({start:r[0],end:r[1],text:ht(Lt(t,e.path),n,e.path)})}s.sort((e,t)=>t.start-e.start);let c=r;for(let e of s)c=c.slice(0,e.start)+e.text+c.slice(e.end);return n?``+c:c}export{Rt as patch};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@decimalturn/toml-patch",
3
- "version": "3.2.0-dev",
4
- "description": "Patch, parse, and stringify TOML while preserving comments, whitespace and formatting.",
3
+ "version": "3.2.0-lite",
4
+ "description": "Patch, parse, and stringify TOML while preserving comments, whitespace and formatting. Lite value-editing distribution.",
5
5
  "homepage": "https://github.com/DecimalTurn/toml-patch",
6
6
  "repository": {
7
7
  "type": "git",
@@ -13,20 +13,15 @@
13
13
  "node": ">=16"
14
14
  },
15
15
  "sideEffects": false,
16
- "types": "./dist/toml-patch.d.ts",
16
+ "types": "./dist/patch.d.ts",
17
17
  "files": [
18
18
  "dist/"
19
19
  ],
20
20
  "exports": {
21
21
  ".": {
22
- "types": "./dist/toml-patch.d.ts",
23
- "import": "./dist/dev/toml-patch.js",
24
- "default": "./dist/dev/toml-patch.js"
25
- },
26
- "./patch-lite": {
27
- "types": "./dist/patch-lite.d.ts",
28
- "import": "./dist/dev/patch-lite.js",
29
- "default": "./dist/dev/patch-lite.js"
22
+ "types": "./dist/patch.d.ts",
23
+ "import": "./dist/patch.js",
24
+ "default": "./dist/patch.js"
30
25
  }
31
26
  },
32
27
  "publishConfig": {
@@ -1,372 +0,0 @@
1
- //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
- import { hasItems, isComment, isInlineArray, isInlineItem, isInlineTable, isKeyValue, isTable, isTableArray } from "./cst.js";
3
- import { getSpan } from "./location.js";
4
-
5
- //#region src/comment-alignment.ts
6
- /**
7
- * @file Comment alignment helpers for the patch pipeline.
8
- * @module comment-alignment
9
- *
10
- * Utilities for preserving and normalizing aligned inline comments during patching.
11
- *
12
- * This module owns the comment-column logic used by the patch pipeline:
13
- * it detects whether an inline comment belongs to an aligned group, preserves
14
- * that alignment when edits change value width, compensates for inline insert
15
- * width deltas, and performs a final string-level normalization pass for padded
16
- * aligned comment blocks.
17
- */
18
- const reserved_comment_spacing = /* @__PURE__ */ new WeakMap();
19
- const original_comment_column = /* @__PURE__ */ new WeakMap();
20
- /**
21
- * Returns the inline comment attached to the item at the given index.
22
- *
23
- * An attached inline comment is the first comment that starts on the same line
24
- * as the item's end position, before any later non-comment row begins.
25
- *
26
- * @param items Container items to inspect.
27
- * @param index Index of the row whose trailing comment should be resolved.
28
- * @returns The attached inline comment, if present.
29
- */
30
- function getAttachedInlineComment(items, index) {
31
- const commentLine = items[index].loc.end.line;
32
- for (let i = index + 1; i < items.length; i++) {
33
- const candidate = items[i];
34
- if (isComment(candidate) && candidate.loc.start.line === commentLine) return candidate;
35
- if (!isComment(candidate) && candidate.loc.start.line > commentLine) return;
36
- }
37
- }
38
- /**
39
- * Finds the nearest non-comment row index in the requested direction.
40
- *
41
- * @param items Container items to scan.
42
- * @param index Starting row index.
43
- * @param direction Scan direction: `-1` for upward, `1` for downward.
44
- * @returns The nearest neighboring row index, if one exists.
45
- */
46
- function getNeighborRowIndex(items, index, direction) {
47
- for (let i = index + direction; i >= 0 && i < items.length; i += direction) if (!isComment(items[i])) return i;
48
- }
49
- /**
50
- * Repositions an inline comment to keep it aligned after a width change.
51
- *
52
- * @param comment Comment node to adjust.
53
- * @param targetColumn Desired aligned column for the comment start.
54
- * @param deltaColumns Horizontal width delta introduced by the edit.
55
- */
56
- function applyInlineCommentColumnAdjustment(comment, targetColumn, deltaColumns) {
57
- if (!original_comment_column.has(comment)) original_comment_column.set(comment, comment.loc.start.column);
58
- const shiftedColumn = comment.loc.start.column + deltaColumns;
59
- const adjustment = Math.max(targetColumn, shiftedColumn) - shiftedColumn;
60
- if (adjustment !== 0) {
61
- comment.loc.start.column += adjustment;
62
- comment.loc.end.column += adjustment;
63
- }
64
- }
65
- /**
66
- * Stores the current minimum spacing between a row and its trailing comment.
67
- *
68
- * This data is refreshed each time it is observed so reused CST comment nodes
69
- * do not retain stale spacing or column values from a previous patch run.
70
- *
71
- * @param row Key-value row that owns the trailing comment.
72
- * @param comment Trailing inline comment attached to the row.
73
- */
74
- function rememberReservedCommentSpacing(row, comment) {
75
- original_comment_column.set(comment, comment.loc.start.column);
76
- reserved_comment_spacing.set(comment, comment.loc.start.column - row.loc.end.column);
77
- }
78
- /**
79
- * Preserves an aligned trailing inline comment when the row's value node is
80
- * being replaced by another value node.
81
- *
82
- * Use this in edit flows where the patch operation has both the old value and
83
- * the new value available, for example when `a = "x" # note` becomes
84
- * `a = "much longer text" # note`. The function computes the width delta from
85
- * `existingValue` and `replacementValue`, then repositions the same-line
86
- * comment so it stays aligned with the adjacent rows that were already aligned
87
- * before the edit.
88
- *
89
- * In short:
90
- * - `preserveAlignedInlineCommentColumn` is for replacement edits
91
- * - it derives `deltaColumns` itself from the old and new value spans
92
- *
93
- * The comment is adjusted only when the current row already belongs to a
94
- * vertically aligned comment group with an immediately adjacent row above or
95
- * below, and both old and new values are single-line.
96
- *
97
- * @param container Parent container that owns the row.
98
- * @param row Key-value row being edited.
99
- * @param existingValue Original value before replacement.
100
- * @param replacementValue Replacement value after editing.
101
- */
102
- function preserveAlignedInlineCommentColumn(container, row, existingValue, replacementValue) {
103
- if (!hasItems(container)) return;
104
- const items = container.items;
105
- const rowIndex = items.indexOf(row);
106
- if (rowIndex < 0) return;
107
- const comment = getAttachedInlineComment(items, rowIndex);
108
- if (!comment) return;
109
- if (existingValue.loc.start.line !== existingValue.loc.end.line) return;
110
- if (replacementValue.loc.start.line !== replacementValue.loc.end.line) return;
111
- const currentColumn = comment.loc.start.column;
112
- const currentLine = comment.loc.start.line;
113
- const neighborIndexes = [getNeighborRowIndex(items, rowIndex, -1), getNeighborRowIndex(items, rowIndex, 1)];
114
- let alignedColumn;
115
- for (const neighborIndex of neighborIndexes) {
116
- if (neighborIndex == null) continue;
117
- const neighborComment = getAttachedInlineComment(items, neighborIndex);
118
- if (!neighborComment) continue;
119
- if (Math.abs(neighborComment.loc.start.line - currentLine) !== 1) continue;
120
- if (neighborComment.loc.start.column !== currentColumn) continue;
121
- alignedColumn = neighborComment.loc.start.column;
122
- break;
123
- }
124
- if (alignedColumn == null) return;
125
- const existingSpan = getSpan(existingValue.loc);
126
- const deltaColumns = getSpan(replacementValue.loc).columns - existingSpan.columns;
127
- applyInlineCommentColumnAdjustment(comment, alignedColumn, deltaColumns);
128
- }
129
- /**
130
- * Preserves an aligned trailing inline comment when the row gets wider because
131
- * content was inserted inside an inline container, but the row value node
132
- * itself was not replaced.
133
- *
134
- * Use this in add/insert flows where the caller already knows the rendered
135
- * width change, for example when inserting a new element into an inline array
136
- * on a row like `a = [1, 2] # note`. In that case there is no old-vs-new row
137
- * value pair available here, so the caller passes the precomputed
138
- * `deltaColumns` directly.
139
- *
140
- * In short:
141
- * - `preserveAlignedInlineCommentForDelta` is for insertion-driven width shifts
142
- * - it consumes a precomputed `deltaColumns` instead of comparing two value nodes
143
- *
144
- * @param container Parent container that owns the row.
145
- * @param row Key-value row whose trailing comment may need to move.
146
- * @param deltaColumns Horizontal width delta introduced by the insertion.
147
- */
148
- function preserveAlignedInlineCommentForDelta(container, row, deltaColumns) {
149
- if (!hasItems(container)) return;
150
- const items = container.items;
151
- const rowIndex = items.indexOf(row);
152
- if (rowIndex < 0) return;
153
- const comment = getAttachedInlineComment(items, rowIndex);
154
- if (!comment) return;
155
- const currentColumn = comment.loc.start.column;
156
- const currentLine = comment.loc.start.line;
157
- const neighborIndexes = [getNeighborRowIndex(items, rowIndex, -1), getNeighborRowIndex(items, rowIndex, 1)];
158
- for (const neighborIndex of neighborIndexes) {
159
- if (neighborIndex == null) continue;
160
- const neighborComment = getAttachedInlineComment(items, neighborIndex);
161
- if (!neighborComment) continue;
162
- if (Math.abs(neighborComment.loc.start.line - currentLine) !== 1) continue;
163
- if (neighborComment.loc.start.column !== currentColumn) continue;
164
- applyInlineCommentColumnAdjustment(comment, neighborComment.loc.start.column, deltaColumns);
165
- return;
166
- }
167
- }
168
- /**
169
- * Records baseline comment alignment metadata for a row whose value is a
170
- * single-line inline table and whose internal contents are being edited.
171
- *
172
- * This captures the comment's current column and reserved gap (comment start
173
- * minus row end) so the final normalization pass can preserve spacing
174
- * expectations after nested inline-table edits.
175
- *
176
- * @param container Parent container that owns the row.
177
- * @param row Key-value row whose trailing comment alignment metadata is refreshed.
178
- * @param deltaColumns Horizontal width delta introduced by the nested edit; used
179
- * only as a fast no-op guard when zero.
180
- */
181
- function recordInlineTableCommentDelta(container, row, deltaColumns) {
182
- if (!hasItems(container) || deltaColumns === 0) return;
183
- const items = container.items;
184
- const rowIndex = items.indexOf(row);
185
- if (rowIndex < 0) return;
186
- const comment = getAttachedInlineComment(items, rowIndex);
187
- if (!comment) return;
188
- rememberReservedCommentSpacing(row, comment);
189
- }
190
- /**
191
- * Estimates the horizontal column delta caused by inserting a new inline item.
192
- *
193
- * The result includes the inserted value width and the comma/spacing overhead
194
- * needed by the surrounding inline array or inline table formatting.
195
- *
196
- * @param parent Inline container receiving the new child.
197
- * @param child CST node being inserted.
198
- * @param index Target insertion index.
199
- * @returns The number of columns added to the rendered row.
200
- */
201
- function getInlineInsertColumnDelta(parent, child, index) {
202
- if (!isInlineArray(parent) && !isInlineTable(parent)) return 0;
203
- const childSpan = getSpan(child.loc);
204
- const hasSeparatingCommaBefore = index > 0;
205
- const hasSeparatingCommaAfter = index < parent.items.length;
206
- const isLastElement = index === parent.items.length;
207
- const hasTrailingComma = isInlineItem(child) ? child.comma : false;
208
- const hasTrailingCommaSpacingBug = hasSeparatingCommaBefore && hasTrailingComma && !hasSeparatingCommaAfter && isLastElement;
209
- return childSpan.columns + (hasSeparatingCommaBefore || hasSeparatingCommaAfter ? 2 : 0) + (hasTrailingComma ? 1 + (hasTrailingCommaSpacingBug ? -1 : 0) : 0);
210
- }
211
- /**
212
- * Recursively collects comment nodes from the document and nested tables.
213
- *
214
- * @param node Document or table-like node to traverse.
215
- * @param comments Accumulator used during recursion.
216
- * @returns All discovered comment nodes.
217
- */
218
- function collectComments(node, comments = []) {
219
- for (const item of node.items) {
220
- if (isComment(item)) {
221
- comments.push(item);
222
- continue;
223
- }
224
- if (isTable(item) || isTableArray(item)) collectComments(item, comments);
225
- }
226
- return comments;
227
- }
228
- /**
229
- * Collects the line numbers of single-line key-value rows whose value is a
230
- * single-line inline table.
231
- *
232
- * @param node Document or table-like node to traverse.
233
- * @param lines Accumulator used during recursion.
234
- * @returns A set of row end lines for inline-table rows.
235
- */
236
- function collectSingleLineInlineTableCommentLines(node, lines = /* @__PURE__ */ new Set()) {
237
- for (const item of node.items) {
238
- if (isKeyValue(item) && isInlineTable(item.value) && item.loc.start.line === item.loc.end.line) {
239
- lines.add(item.loc.end.line);
240
- continue;
241
- }
242
- if (isTable(item) || isTableArray(item)) collectSingleLineInlineTableCommentLines(item, lines);
243
- }
244
- return lines;
245
- }
246
- /**
247
- * Recomputes `loc.end` for the document/table container chain from children.
248
- *
249
- * Inline comment normalization can move trailing comments horizontally; this
250
- * keeps parent containers' end positions consistent with their updated children.
251
- *
252
- * @param node Document or table-like container to normalize.
253
- */
254
- function recomputeContainerEnds(node) {
255
- for (const item of node.items) if (isTable(item) || isTableArray(item)) recomputeContainerEnds(item);
256
- let maxLine = node.loc.end.line;
257
- let maxColumn = node.loc.end.column;
258
- const updateMax = (line, column) => {
259
- if (line > maxLine || line === maxLine && column > maxColumn) {
260
- maxLine = line;
261
- maxColumn = column;
262
- }
263
- };
264
- if (isTable(node) || isTableArray(node)) updateMax(node.key.loc.end.line, node.key.loc.end.column);
265
- for (const item of node.items) updateMax(item.loc.end.line, item.loc.end.column);
266
- node.loc.end.line = maxLine;
267
- node.loc.end.column = maxColumn;
268
- }
269
- /**
270
- * Normalizes padded inline comment groups in the final rendered TOML string.
271
- *
272
- * This pass is intentionally limited to comments that already have explicit
273
- * padding before `#`, which avoids disturbing compact TOML 1.1 inline-table
274
- * comment styles while still restoring vertical alignment for normal row-based
275
- * comment blocks.
276
- *
277
- * For groups touched by nested inline-table edits, the target column is derived
278
- * from the widest current row plus the group's original minimum reserved gap.
279
- *
280
- * @param document Patched CST document whose comment locations are updated in-place.
281
- * @param tomlString Rendered TOML output to normalize.
282
- * @param format Active TOML formatting settings.
283
- * @returns The normalized TOML string.
284
- */
285
- function normalizeInlineCommentAlignmentInString(document, tomlString, format) {
286
- const newLine = format.newLine;
287
- const trailingMatch = tomlString.match(/(?:\r\n|\n)+$/u);
288
- const trailing = trailingMatch ? trailingMatch[0] : "";
289
- const body = trailing ? tomlString.slice(0, -trailing.length) : tomlString;
290
- const lines = body.length ? body.split(newLine) : [];
291
- const inlineTableCommentLines = collectSingleLineInlineTableCommentLines(document);
292
- const resolveCommentColumn = (line, comment) => {
293
- const fromLine = line.lastIndexOf(comment.raw);
294
- return fromLine >= 0 ? fromLine : comment.loc.start.column;
295
- };
296
- const comments = collectComments(document).filter((comment) => {
297
- const line = lines[comment.loc.start.line - 1] || "";
298
- const commentColumn = resolveCommentColumn(line, comment);
299
- const beforeComment = line.slice(0, commentColumn);
300
- return beforeComment.trim().length > 0 && /\s{2,}$/u.test(beforeComment);
301
- }).sort((a, b) => a.loc.start.line - b.loc.start.line);
302
- const groups = [];
303
- let currentGroup = [];
304
- for (const comment of comments) {
305
- const previous = currentGroup[currentGroup.length - 1];
306
- if (!previous || comment.loc.start.line === previous.loc.start.line + 1) currentGroup.push(comment);
307
- else {
308
- if (currentGroup.length > 0) groups.push(currentGroup);
309
- currentGroup = [comment];
310
- }
311
- }
312
- if (currentGroup.length > 0) groups.push(currentGroup);
313
- for (const group of groups) {
314
- if (group.length < 2) continue;
315
- let targetColumn = original_comment_column.get(group[0]) ?? group[0].loc.start.column;
316
- const counts = /* @__PURE__ */ new Map();
317
- for (const comment of group) {
318
- const baselineColumn = original_comment_column.get(comment) ?? comment.loc.start.column;
319
- counts.set(baselineColumn, (counts.get(baselineColumn) || 0) + 1);
320
- }
321
- let highestCount = 1;
322
- for (const [column, count] of counts) if (count > highestCount) {
323
- highestCount = count;
324
- targetColumn = column;
325
- }
326
- const widestCodeColumn = Math.max(...group.map((comment) => {
327
- const line = lines[comment.loc.start.line - 1] || "";
328
- const commentColumn = resolveCommentColumn(line, comment);
329
- return line.slice(0, commentColumn).trimEnd().length;
330
- }));
331
- let groupMinimumGap = Math.min(...group.map((comment) => {
332
- const line = lines[comment.loc.start.line - 1] || "";
333
- const commentColumn = resolveCommentColumn(line, comment);
334
- const code = line.slice(0, commentColumn).trimEnd();
335
- return Math.max(1, commentColumn - code.length);
336
- }));
337
- const reservedComments = group.filter((comment) => reserved_comment_spacing.has(comment));
338
- const hasNonInlineTableRows = group.some((comment) => !inlineTableCommentLines.has(comment.loc.start.line));
339
- if (reservedComments.length > 0 && hasNonInlineTableRows) {
340
- const reservedMinimumGap = Math.min(...group.map((comment) => {
341
- if (reserved_comment_spacing.has(comment)) return reserved_comment_spacing.get(comment) || 1;
342
- const line = lines[comment.loc.start.line - 1] || "";
343
- const commentColumn = resolveCommentColumn(line, comment);
344
- const code = line.slice(0, commentColumn).trimEnd();
345
- return Math.max(1, commentColumn - code.length);
346
- }));
347
- groupMinimumGap = Math.min(groupMinimumGap, reservedMinimumGap);
348
- }
349
- if (targetColumn < widestCodeColumn + 1) {
350
- const requiredColumn = widestCodeColumn + groupMinimumGap;
351
- targetColumn = Math.max(targetColumn, requiredColumn);
352
- }
353
- for (const comment of group) {
354
- const lineIndex = comment.loc.start.line - 1;
355
- const line = lines[lineIndex] || "";
356
- const commentColumn = resolveCommentColumn(line, comment);
357
- const code = line.slice(0, commentColumn).trimEnd();
358
- const actualTargetColumn = Math.max(targetColumn, code.length + 1);
359
- if (commentColumn !== actualTargetColumn) lines[lineIndex] = code + " ".repeat(actualTargetColumn - code.length) + comment.raw;
360
- if (comment.loc.start.column !== actualTargetColumn) {
361
- comment.loc.start.column = actualTargetColumn;
362
- comment.loc.end.column = actualTargetColumn + comment.raw.length;
363
- }
364
- }
365
- }
366
- recomputeContainerEnds(document);
367
- return lines.join(newLine) + trailing;
368
- }
369
-
370
- //#endregion
371
- export { getInlineInsertColumnDelta, normalizeInlineCommentAlignmentInString, preserveAlignedInlineCommentColumn, preserveAlignedInlineCommentForDelta, recordInlineTableCommentDelta };
372
- //# sourceMappingURL=comment-alignment.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"comment-alignment.js","names":[],"sources":["../../src/comment-alignment.ts"],"sourcesContent":["/**\n * @file Comment alignment helpers for the patch pipeline.\n * @module comment-alignment\n *\n * Utilities for preserving and normalizing aligned inline comments during patching.\n *\n * This module owns the comment-column logic used by the patch pipeline:\n * it detects whether an inline comment belongs to an aligned group, preserves\n * that alignment when edits change value width, compensates for inline insert\n * width deltas, and performs a final string-level normalization pass for padded\n * aligned comment blocks.\n */\nimport {\n Comment,\n Document,\n KeyValue,\n Table,\n TableArray,\n TreeNode,\n Value,\n hasItems,\n isComment,\n isInlineArray,\n isInlineItem,\n isInlineTable,\n isKeyValue,\n isTable,\n isTableArray\n} from './cst';\nimport { getSpan } from './location';\nimport { TomlFormat } from './toml-format';\n\nconst reserved_comment_spacing = new WeakMap<Comment, number>();\nconst original_comment_column = new WeakMap<Comment, number>();\n\n/**\n * Returns the inline comment attached to the item at the given index.\n *\n * An attached inline comment is the first comment that starts on the same line\n * as the item's end position, before any later non-comment row begins.\n *\n * @param items Container items to inspect.\n * @param index Index of the row whose trailing comment should be resolved.\n * @returns The attached inline comment, if present.\n */\nfunction getAttachedInlineComment(items: TreeNode[], index: number): Comment | undefined {\n const current = items[index];\n const commentLine = current.loc.end.line;\n\n for (let i = index + 1; i < items.length; i++) {\n const candidate = items[i];\n if (isComment(candidate) && candidate.loc.start.line === commentLine) {\n return candidate;\n }\n\n if (!isComment(candidate) && candidate.loc.start.line > commentLine) {\n return;\n }\n }\n}\n\n/**\n * Finds the nearest non-comment row index in the requested direction.\n *\n * @param items Container items to scan.\n * @param index Starting row index.\n * @param direction Scan direction: `-1` for upward, `1` for downward.\n * @returns The nearest neighboring row index, if one exists.\n */\nfunction getNeighborRowIndex(items: TreeNode[], index: number, direction: -1 | 1): number | undefined {\n for (let i = index + direction; i >= 0 && i < items.length; i += direction) {\n if (!isComment(items[i])) {\n return i;\n }\n }\n}\n\n/**\n * Repositions an inline comment to keep it aligned after a width change.\n *\n * @param comment Comment node to adjust.\n * @param targetColumn Desired aligned column for the comment start.\n * @param deltaColumns Horizontal width delta introduced by the edit.\n */\nfunction applyInlineCommentColumnAdjustment(comment: Comment, targetColumn: number, deltaColumns: number) {\n if (!original_comment_column.has(comment)) {\n original_comment_column.set(comment, comment.loc.start.column);\n }\n\n const shiftedColumn = comment.loc.start.column + deltaColumns;\n // Never pull a widened row's comment left into its own code; let the\n // normalization pass realign neighboring rows to the widened target.\n const desiredColumn = Math.max(targetColumn, shiftedColumn);\n const adjustment = desiredColumn - shiftedColumn;\n\n if (adjustment !== 0) {\n comment.loc.start.column += adjustment;\n comment.loc.end.column += adjustment;\n }\n}\n\n/**\n * Stores the current minimum spacing between a row and its trailing comment.\n *\n * This data is refreshed each time it is observed so reused CST comment nodes\n * do not retain stale spacing or column values from a previous patch run.\n *\n * @param row Key-value row that owns the trailing comment.\n * @param comment Trailing inline comment attached to the row.\n */\nfunction rememberReservedCommentSpacing(row: KeyValue, comment: Comment) {\n original_comment_column.set(comment, comment.loc.start.column);\n reserved_comment_spacing.set(comment, comment.loc.start.column - row.loc.end.column);\n}\n\n/**\n * Preserves an aligned trailing inline comment when the row's value node is\n * being replaced by another value node.\n *\n * Use this in edit flows where the patch operation has both the old value and\n * the new value available, for example when `a = \"x\" # note` becomes\n * `a = \"much longer text\" # note`. The function computes the width delta from\n * `existingValue` and `replacementValue`, then repositions the same-line\n * comment so it stays aligned with the adjacent rows that were already aligned\n * before the edit.\n *\n * In short:\n * - `preserveAlignedInlineCommentColumn` is for replacement edits\n * - it derives `deltaColumns` itself from the old and new value spans\n *\n * The comment is adjusted only when the current row already belongs to a\n * vertically aligned comment group with an immediately adjacent row above or\n * below, and both old and new values are single-line.\n *\n * @param container Parent container that owns the row.\n * @param row Key-value row being edited.\n * @param existingValue Original value before replacement.\n * @param replacementValue Replacement value after editing.\n */\nexport function preserveAlignedInlineCommentColumn(\n container: TreeNode,\n row: KeyValue,\n existingValue: TreeNode,\n replacementValue: TreeNode\n) {\n if (!hasItems(container)) return;\n\n const items = container.items as TreeNode[];\n const rowIndex = items.indexOf(row);\n if (rowIndex < 0) return;\n\n const comment = getAttachedInlineComment(items, rowIndex);\n if (!comment) return;\n\n if (existingValue.loc.start.line !== existingValue.loc.end.line) return;\n if (replacementValue.loc.start.line !== replacementValue.loc.end.line) return;\n\n const currentColumn = comment.loc.start.column;\n const currentLine = comment.loc.start.line;\n const neighborIndexes = [\n getNeighborRowIndex(items, rowIndex, -1),\n getNeighborRowIndex(items, rowIndex, 1)\n ];\n\n let alignedColumn: number | undefined;\n for (const neighborIndex of neighborIndexes) {\n if (neighborIndex == null) continue;\n\n const neighborComment = getAttachedInlineComment(items, neighborIndex);\n if (!neighborComment) continue;\n if (Math.abs(neighborComment.loc.start.line - currentLine) !== 1) continue;\n if (neighborComment.loc.start.column !== currentColumn) continue;\n\n alignedColumn = neighborComment.loc.start.column;\n break;\n }\n\n if (alignedColumn == null) return;\n\n const existingSpan = getSpan(existingValue.loc);\n const replacementSpan = getSpan(replacementValue.loc);\n const deltaColumns = replacementSpan.columns - existingSpan.columns;\n\n applyInlineCommentColumnAdjustment(comment, alignedColumn, deltaColumns);\n}\n\n/**\n * Preserves an aligned trailing inline comment when the row gets wider because\n * content was inserted inside an inline container, but the row value node\n * itself was not replaced.\n *\n * Use this in add/insert flows where the caller already knows the rendered\n * width change, for example when inserting a new element into an inline array\n * on a row like `a = [1, 2] # note`. In that case there is no old-vs-new row\n * value pair available here, so the caller passes the precomputed\n * `deltaColumns` directly.\n *\n * In short:\n * - `preserveAlignedInlineCommentForDelta` is for insertion-driven width shifts\n * - it consumes a precomputed `deltaColumns` instead of comparing two value nodes\n *\n * @param container Parent container that owns the row.\n * @param row Key-value row whose trailing comment may need to move.\n * @param deltaColumns Horizontal width delta introduced by the insertion.\n */\nexport function preserveAlignedInlineCommentForDelta(\n container: TreeNode,\n row: KeyValue,\n deltaColumns: number\n) {\n if (!hasItems(container)) return;\n\n const items = container.items as TreeNode[];\n const rowIndex = items.indexOf(row);\n if (rowIndex < 0) return;\n\n const comment = getAttachedInlineComment(items, rowIndex);\n if (!comment) return;\n\n const currentColumn = comment.loc.start.column;\n const currentLine = comment.loc.start.line;\n const neighborIndexes = [\n getNeighborRowIndex(items, rowIndex, -1),\n getNeighborRowIndex(items, rowIndex, 1)\n ];\n\n for (const neighborIndex of neighborIndexes) {\n if (neighborIndex == null) continue;\n\n const neighborComment = getAttachedInlineComment(items, neighborIndex);\n if (!neighborComment) continue;\n if (Math.abs(neighborComment.loc.start.line - currentLine) !== 1) continue;\n if (neighborComment.loc.start.column !== currentColumn) continue;\n\n applyInlineCommentColumnAdjustment(comment, neighborComment.loc.start.column, deltaColumns);\n return;\n }\n}\n\n/**\n * Records baseline comment alignment metadata for a row whose value is a\n * single-line inline table and whose internal contents are being edited.\n *\n * This captures the comment's current column and reserved gap (comment start\n * minus row end) so the final normalization pass can preserve spacing\n * expectations after nested inline-table edits.\n *\n * @param container Parent container that owns the row.\n * @param row Key-value row whose trailing comment alignment metadata is refreshed.\n * @param deltaColumns Horizontal width delta introduced by the nested edit; used\n * only as a fast no-op guard when zero.\n */\nexport function recordInlineTableCommentDelta(container: TreeNode, row: KeyValue, deltaColumns: number) {\n if (!hasItems(container) || deltaColumns === 0) return;\n\n const items = container.items as TreeNode[];\n const rowIndex = items.indexOf(row);\n if (rowIndex < 0) return;\n\n const comment = getAttachedInlineComment(items, rowIndex);\n if (!comment) return;\n\n rememberReservedCommentSpacing(row, comment);\n}\n\n/**\n * Estimates the horizontal column delta caused by inserting a new inline item.\n *\n * The result includes the inserted value width and the comma/spacing overhead\n * needed by the surrounding inline array or inline table formatting.\n *\n * @param parent Inline container receiving the new child.\n * @param child CST node being inserted.\n * @param index Target insertion index.\n * @returns The number of columns added to the rendered row.\n */\nexport function getInlineInsertColumnDelta(parent: Value, child: TreeNode, index: number): number {\n if (!isInlineArray(parent) && !isInlineTable(parent)) return 0;\n\n const childSpan = getSpan(child.loc);\n const hasSeparatingCommaBefore = index > 0;\n const hasSeparatingCommaAfter = index < parent.items.length;\n const isLastElement = index === parent.items.length;\n const hasTrailingComma = isInlineItem(child) ? child.comma : false;\n const hasTrailingCommaSpacingBug =\n hasSeparatingCommaBefore && hasTrailingComma && !hasSeparatingCommaAfter && isLastElement;\n\n return (\n childSpan.columns +\n (hasSeparatingCommaBefore || hasSeparatingCommaAfter ? 2 : 0) +\n (hasTrailingComma ? 1 + (hasTrailingCommaSpacingBug ? -1 : 0) : 0)\n );\n}\n\n/**\n * Recursively collects comment nodes from the document and nested tables.\n *\n * @param node Document or table-like node to traverse.\n * @param comments Accumulator used during recursion.\n * @returns All discovered comment nodes.\n */\nfunction collectComments(node: Document | Table | TableArray, comments: Comment[] = []): Comment[] {\n for (const item of node.items) {\n if (isComment(item)) {\n comments.push(item);\n continue;\n }\n\n if (isTable(item) || isTableArray(item)) {\n collectComments(item, comments);\n }\n }\n\n return comments;\n}\n\n/**\n * Collects the line numbers of single-line key-value rows whose value is a\n * single-line inline table.\n *\n * @param node Document or table-like node to traverse.\n * @param lines Accumulator used during recursion.\n * @returns A set of row end lines for inline-table rows.\n */\nfunction collectSingleLineInlineTableCommentLines(\n node: Document | Table | TableArray,\n lines: Set<number> = new Set()\n): Set<number> {\n for (const item of node.items) {\n if (isKeyValue(item) && isInlineTable(item.value) && item.loc.start.line === item.loc.end.line) {\n lines.add(item.loc.end.line);\n continue;\n }\n\n if (isTable(item) || isTableArray(item)) {\n collectSingleLineInlineTableCommentLines(item, lines);\n }\n }\n\n return lines;\n}\n\n/**\n * Recomputes `loc.end` for the document/table container chain from children.\n *\n * Inline comment normalization can move trailing comments horizontally; this\n * keeps parent containers' end positions consistent with their updated children.\n *\n * @param node Document or table-like container to normalize.\n */\nfunction recomputeContainerEnds(node: Document | Table | TableArray) {\n for (const item of node.items) {\n if (isTable(item) || isTableArray(item)) {\n recomputeContainerEnds(item);\n }\n }\n\n let maxLine = node.loc.end.line;\n let maxColumn = node.loc.end.column;\n\n const updateMax = (line: number, column: number) => {\n if (line > maxLine || (line === maxLine && column > maxColumn)) {\n maxLine = line;\n maxColumn = column;\n }\n };\n\n if (isTable(node) || isTableArray(node)) {\n updateMax(node.key.loc.end.line, node.key.loc.end.column);\n }\n\n for (const item of node.items) {\n updateMax(item.loc.end.line, item.loc.end.column);\n }\n\n node.loc.end.line = maxLine;\n node.loc.end.column = maxColumn;\n}\n\n/**\n * Normalizes padded inline comment groups in the final rendered TOML string.\n *\n * This pass is intentionally limited to comments that already have explicit\n * padding before `#`, which avoids disturbing compact TOML 1.1 inline-table\n * comment styles while still restoring vertical alignment for normal row-based\n * comment blocks.\n *\n * For groups touched by nested inline-table edits, the target column is derived\n * from the widest current row plus the group's original minimum reserved gap.\n *\n * @param document Patched CST document whose comment locations are updated in-place.\n * @param tomlString Rendered TOML output to normalize.\n * @param format Active TOML formatting settings.\n * @returns The normalized TOML string.\n */\nexport function normalizeInlineCommentAlignmentInString(\n document: Document,\n tomlString: string,\n format: TomlFormat\n): string {\n const newLine = format.newLine;\n const trailingMatch = tomlString.match(/(?:\\r\\n|\\n)+$/u);\n const trailing = trailingMatch ? trailingMatch[0] : '';\n const body = trailing ? tomlString.slice(0, -trailing.length) : tomlString;\n const lines = body.length ? body.split(newLine) : [];\n const inlineTableCommentLines = collectSingleLineInlineTableCommentLines(document);\n\n const resolveCommentColumn = (line: string, comment: Comment): number => {\n const fromLine = line.lastIndexOf(comment.raw);\n return fromLine >= 0 ? fromLine : comment.loc.start.column;\n };\n\n const comments = collectComments(document)\n .filter(comment => {\n const line = lines[comment.loc.start.line - 1] || '';\n const commentColumn = resolveCommentColumn(line, comment);\n const beforeComment = line.slice(0, commentColumn);\n return beforeComment.trim().length > 0 && /\\s{2,}$/u.test(beforeComment);\n })\n .sort((a, b) => a.loc.start.line - b.loc.start.line);\n\n const groups: Comment[][] = [];\n let currentGroup: Comment[] = [];\n for (const comment of comments) {\n const previous = currentGroup[currentGroup.length - 1];\n if (!previous || comment.loc.start.line === previous.loc.start.line + 1) {\n currentGroup.push(comment);\n } else {\n if (currentGroup.length > 0) {\n groups.push(currentGroup);\n }\n currentGroup = [comment];\n }\n }\n if (currentGroup.length > 0) {\n groups.push(currentGroup);\n }\n\n for (const group of groups) {\n if (group.length < 2) continue;\n\n let targetColumn = original_comment_column.get(group[0]) ?? group[0].loc.start.column;\n const counts = new Map<number, number>();\n for (const comment of group) {\n const baselineColumn = original_comment_column.get(comment) ?? comment.loc.start.column;\n counts.set(baselineColumn, (counts.get(baselineColumn) || 0) + 1);\n }\n\n let highestCount = 1;\n for (const [column, count] of counts) {\n if (count > highestCount) {\n highestCount = count;\n targetColumn = column;\n }\n }\n\n const widestCodeColumn = Math.max(\n ...group.map(comment => {\n const line = lines[comment.loc.start.line - 1] || '';\n const commentColumn = resolveCommentColumn(line, comment);\n const code = line.slice(0, commentColumn).trimEnd();\n return code.length;\n })\n );\n\n const currentGroupMinimumGap = Math.min(\n ...group.map(comment => {\n const line = lines[comment.loc.start.line - 1] || '';\n const commentColumn = resolveCommentColumn(line, comment);\n const code = line.slice(0, commentColumn).trimEnd();\n return Math.max(1, commentColumn - code.length);\n })\n );\n\n let groupMinimumGap = currentGroupMinimumGap;\n const reservedComments = group.filter(comment => reserved_comment_spacing.has(comment));\n const hasNonInlineTableRows = group.some(comment => !inlineTableCommentLines.has(comment.loc.start.line));\n if (reservedComments.length > 0 && hasNonInlineTableRows) {\n const reservedMinimumGap = Math.min(\n ...group.map(comment => {\n if (reserved_comment_spacing.has(comment)) {\n return reserved_comment_spacing.get(comment) || 1;\n }\n\n const line = lines[comment.loc.start.line - 1] || '';\n const commentColumn = resolveCommentColumn(line, comment);\n const code = line.slice(0, commentColumn).trimEnd();\n return Math.max(1, commentColumn - code.length);\n })\n );\n groupMinimumGap = Math.min(groupMinimumGap, reservedMinimumGap);\n }\n\n if (targetColumn < widestCodeColumn + 1) {\n const requiredColumn = widestCodeColumn + groupMinimumGap;\n targetColumn = Math.max(targetColumn, requiredColumn);\n }\n\n for (const comment of group) {\n const lineIndex = comment.loc.start.line - 1;\n const line = lines[lineIndex] || '';\n const commentColumn = resolveCommentColumn(line, comment);\n const code = line.slice(0, commentColumn).trimEnd();\n const actualTargetColumn = Math.max(targetColumn, code.length + 1);\n if (commentColumn !== actualTargetColumn) {\n const spaces = ' '.repeat(actualTargetColumn - code.length);\n lines[lineIndex] = code + spaces + comment.raw;\n }\n\n if (comment.loc.start.column !== actualTargetColumn) {\n comment.loc.start.column = actualTargetColumn;\n comment.loc.end.column = actualTargetColumn + comment.raw.length;\n }\n }\n }\n\n recomputeContainerEnds(document);\n\n return lines.join(newLine) + trailing;\n}"],"mappings":";;;;;;;;;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