@fluixi/compiler 1.0.0-alpha.82 → 1.0.0-alpha.84

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 (188) hide show
  1. package/dist/analyze/expr-shape.cjs +62 -1
  2. package/dist/analyze/expr-shape.d.cts +14 -0
  3. package/dist/analyze/expr-shape.mjs +41 -1
  4. package/dist/analyze/intrinsics.cjs +80 -1
  5. package/dist/analyze/intrinsics.d.cts +66 -0
  6. package/dist/analyze/intrinsics.mjs +59 -1
  7. package/dist/analyze/paren.cjs +134 -0
  8. package/dist/analyze/paren.d.cts +23 -0
  9. package/dist/analyze/paren.d.ts +24 -0
  10. package/dist/analyze/paren.d.ts.map +1 -0
  11. package/dist/analyze/paren.js +168 -0
  12. package/dist/analyze/paren.mjs +113 -0
  13. package/dist/analyze/props-destructure.cjs +226 -1
  14. package/dist/analyze/props-destructure.d.cts +83 -0
  15. package/dist/analyze/props-destructure.mjs +205 -1
  16. package/dist/analyze/reactive-bindings.cjs +190 -1
  17. package/dist/analyze/reactive-bindings.d.cts +42 -0
  18. package/dist/analyze/reactive-bindings.mjs +167 -1
  19. package/dist/analyze/reactive-expr.cjs +38 -1
  20. package/dist/analyze/reactive-expr.d.cts +38 -0
  21. package/dist/analyze/reactive-expr.mjs +17 -1
  22. package/dist/analyze/static-graph.cjs +811 -0
  23. package/dist/analyze/static-graph.d.cts +102 -0
  24. package/dist/analyze/static-graph.d.ts +103 -0
  25. package/dist/analyze/static-graph.d.ts.map +1 -0
  26. package/dist/analyze/static-graph.js +869 -0
  27. package/dist/analyze/static-graph.mjs +793 -0
  28. package/dist/babel-NRW4EFTG.mjs +636 -0
  29. package/dist/chunk-3YKZ4GNH.mjs +11 -0
  30. package/dist/chunk-EZR7NZOY.mjs +1718 -0
  31. package/dist/chunk-FSSWUXUR.mjs +16 -0
  32. package/dist/chunk-MJV3UXIL.mjs +158 -0
  33. package/dist/chunk-R2VHAZAX.mjs +1078 -0
  34. package/dist/codegen/backend.cjs +18 -1
  35. package/dist/codegen/backend.d.cts +35 -0
  36. package/dist/codegen/backends/imperative.cjs +542 -1
  37. package/dist/codegen/backends/imperative.d.cts +11 -0
  38. package/dist/codegen/backends/imperative.d.ts.map +1 -1
  39. package/dist/codegen/backends/imperative.js +68 -13
  40. package/dist/codegen/backends/imperative.mjs +519 -1
  41. package/dist/codegen/contract.cjs +52 -1
  42. package/dist/codegen/contract.d.cts +24 -0
  43. package/dist/codegen/contract.mjs +31 -1
  44. package/dist/codegen/partial-template.cjs +176 -1
  45. package/dist/codegen/partial-template.d.cts +61 -0
  46. package/dist/codegen/partial-template.mjs +153 -1
  47. package/dist/codegen/serialize-static.cjs +125 -1
  48. package/dist/codegen/serialize-static.d.cts +38 -0
  49. package/dist/codegen/serialize-static.d.ts +16 -0
  50. package/dist/codegen/serialize-static.d.ts.map +1 -1
  51. package/dist/codegen/serialize-static.js +25 -0
  52. package/dist/codegen/serialize-static.mjs +104 -1
  53. package/dist/frontend/babel/build-ir-lit.cjs +1509 -1
  54. package/dist/frontend/babel/build-ir-lit.d.cts +26 -0
  55. package/dist/frontend/babel/build-ir-lit.mjs +1478 -1
  56. package/dist/frontend/babel/build-ir.cjs +1524 -1
  57. package/dist/frontend/babel/build-ir.d.cts +35 -0
  58. package/dist/frontend/babel/build-ir.mjs +1495 -1
  59. package/dist/frontend/babel/index.cjs +2186 -1
  60. package/dist/frontend/babel/index.d.cts +33 -0
  61. package/dist/frontend/babel/index.mjs +2156 -1
  62. package/dist/frontend/babel/lower-template.cjs +1507 -1
  63. package/dist/frontend/babel/lower-template.d.cts +23 -0
  64. package/dist/frontend/babel/lower-template.mjs +1478 -1
  65. package/dist/frontend/babel/plugin.cjs +2132 -1
  66. package/dist/frontend/babel/plugin.d.cts +95 -0
  67. package/dist/frontend/babel/plugin.mjs +2103 -1
  68. package/dist/frontend/babel/server-functions.cjs +110 -1
  69. package/dist/frontend/babel/server-functions.d.cts +10 -0
  70. package/dist/frontend/babel/server-functions.mjs +89 -1
  71. package/dist/frontend/babel/types.cjs +18 -1
  72. package/dist/frontend/babel/types.d.cts +33 -0
  73. package/dist/frontend/types.cjs +18 -1
  74. package/dist/frontend/types.d.cts +25 -0
  75. package/dist/frontend/vocabulary.cjs +98 -0
  76. package/dist/frontend/vocabulary.d.cts +79 -0
  77. package/dist/frontend/vocabulary.d.ts +80 -0
  78. package/dist/frontend/vocabulary.d.ts.map +1 -0
  79. package/dist/frontend/vocabulary.js +124 -0
  80. package/dist/frontend/vocabulary.mjs +77 -0
  81. package/dist/index.cjs +1594 -13
  82. package/dist/index.d.cts +27 -0
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +3 -0
  85. package/dist/index.mjs +1574 -13
  86. package/dist/integrations.cjs +4307 -25
  87. package/dist/integrations.d.cts +215 -0
  88. package/dist/integrations.d.ts +16 -0
  89. package/dist/integrations.d.ts.map +1 -1
  90. package/dist/integrations.js +21 -2
  91. package/dist/integrations.mjs +531 -17
  92. package/dist/ir/nodes.cjs +18 -1
  93. package/dist/ir/nodes.d.cts +168 -0
  94. package/dist/ir/nodes.d.ts +46 -0
  95. package/dist/ir/nodes.d.ts.map +1 -1
  96. package/dist/lower/compile-template.cjs +1356 -1
  97. package/dist/lower/compile-template.d.cts +69 -0
  98. package/dist/lower/compile-template.d.ts +12 -0
  99. package/dist/lower/compile-template.d.ts.map +1 -1
  100. package/dist/lower/compile-template.js +5 -1
  101. package/dist/lower/compile-template.mjs +1336 -1
  102. package/dist/lower/jsx.cjs +529 -1
  103. package/dist/lower/jsx.d.cts +25 -0
  104. package/dist/lower/jsx.d.ts +2 -0
  105. package/dist/lower/jsx.d.ts.map +1 -1
  106. package/dist/lower/jsx.js +27 -4
  107. package/dist/lower/jsx.mjs +506 -1
  108. package/dist/lower/template.cjs +1061 -1
  109. package/dist/lower/template.d.cts +53 -0
  110. package/dist/lower/template.d.ts +14 -1
  111. package/dist/lower/template.d.ts.map +1 -1
  112. package/dist/lower/template.js +106 -19
  113. package/dist/lower/template.mjs +1042 -1
  114. package/dist/lower/text.cjs +42 -1
  115. package/dist/lower/text.d.cts +10 -0
  116. package/dist/lower/text.mjs +21 -1
  117. package/dist/optimize/analyze-static.cjs +112 -1
  118. package/dist/optimize/analyze-static.d.cts +39 -0
  119. package/dist/optimize/analyze-static.mjs +91 -1
  120. package/dist/optimize/collapse-strategies.cjs +90 -1
  121. package/dist/optimize/collapse-strategies.d.cts +30 -0
  122. package/dist/optimize/collapse-strategies.mjs +67 -1
  123. package/dist/options.cjs +33 -1
  124. package/dist/options.d.cts +39 -0
  125. package/dist/options.mjs +12 -1
  126. package/dist/resolve/builtins.cjs +73 -1
  127. package/dist/resolve/builtins.d.cts +68 -0
  128. package/dist/resolve/builtins.mjs +53 -1
  129. package/dist/resolve/component-globals.cjs +233 -13
  130. package/dist/resolve/component-globals.d.cts +80 -0
  131. package/dist/resolve/component-globals.mjs +210 -13
  132. package/dist/resolve/component-resolver.cjs +80 -1
  133. package/dist/resolve/component-resolver.d.cts +68 -0
  134. package/dist/resolve/component-resolver.mjs +59 -1
  135. package/dist/resolve/load-directive.cjs +93 -1
  136. package/dist/resolve/load-directive.d.cts +53 -0
  137. package/dist/resolve/load-directive.mjs +72 -1
  138. package/dist/resolve/resolve-ir.cjs +108 -1
  139. package/dist/resolve/resolve-ir.d.cts +53 -0
  140. package/dist/resolve/resolve-ir.mjs +85 -1
  141. package/dist/resolve/write-globals.cjs +318 -13
  142. package/dist/resolve/write-globals.d.cts +30 -0
  143. package/dist/resolve/write-globals.mjs +297 -13
  144. package/dist/server-fns-4ZXN6DYU.mjs +78 -0
  145. package/dist/server-functions-V6D6DRIA.mjs +82 -0
  146. package/dist/transform/bindings.cjs +71 -1
  147. package/dist/transform/bindings.d.cts +16 -0
  148. package/dist/transform/bindings.mjs +50 -1
  149. package/dist/transform/index.cjs +2732 -8
  150. package/dist/transform/index.d.cts +15 -0
  151. package/dist/transform/index.mjs +3773 -17
  152. package/dist/transform/intrinsics.cjs +216 -3
  153. package/dist/transform/intrinsics.d.cts +21 -0
  154. package/dist/transform/intrinsics.mjs +193 -3
  155. package/dist/transform/props.cjs +441 -3
  156. package/dist/transform/props.d.cts +45 -0
  157. package/dist/transform/props.mjs +1482 -12
  158. package/dist/transform/server-fn-id.cjs +35 -1
  159. package/dist/transform/server-fn-id.d.cts +9 -0
  160. package/dist/transform/server-fn-id.mjs +14 -1
  161. package/dist/transform/server-fns.cjs +114 -2
  162. package/dist/transform/server-fns.d.cts +12 -0
  163. package/dist/transform/server-fns.mjs +1155 -11
  164. package/dist/transform/source-locations.cjs +330 -0
  165. package/dist/transform/source-locations.d.cts +43 -0
  166. package/dist/transform/source-locations.d.ts +44 -0
  167. package/dist/transform/source-locations.d.ts.map +1 -0
  168. package/dist/transform/source-locations.js +238 -0
  169. package/dist/transform/source-locations.mjs +307 -0
  170. package/dist/transform/templates.cjs +2701 -7
  171. package/dist/transform/templates.d.cts +69 -0
  172. package/dist/transform/templates.d.ts +12 -4
  173. package/dist/transform/templates.d.ts.map +1 -1
  174. package/dist/transform/templates.js +72 -7
  175. package/dist/transform/templates.mjs +3743 -16
  176. package/dist/transform-BT4MMASR.mjs +893 -0
  177. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  178. package/package.json +6 -5
  179. package/dist/babel-4JUDAR2G.mjs +0 -1
  180. package/dist/chunk-3SAEGOMQ.mjs +0 -1
  181. package/dist/chunk-IBRM4W7I.mjs +0 -10
  182. package/dist/chunk-OHHZCYIQ.mjs +0 -1
  183. package/dist/chunk-PVR2SN3B.mjs +0 -1
  184. package/dist/chunk-QUIYULS2.mjs +0 -1
  185. package/dist/chunk-YR3SAEO7.mjs +0 -1
  186. package/dist/server-fns-6QM243HC.mjs +0 -2
  187. package/dist/server-functions-E3LKCZ4R.mjs +0 -1
  188. package/dist/transform-5WC4FWJE.mjs +0 -8
@@ -1,12 +1,1482 @@
1
- import{parse as se}from"@babel/parser";var W=44,z=59,_="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",D=new Uint8Array(64),H=new Uint8Array(128);for(let s=0;s<_.length;s++){let e=_.charCodeAt(s);D[s]=e,H[e]=s}function b(s,e,t){let n=e-t;n=n<0?-n<<1|1:n<<1;do{let i=n&31;n>>>=5,n>0&&(i|=32),s.write(D[i])}while(n>0);return e}var j=1024*16,A=typeof TextDecoder<"u"?new TextDecoder:typeof Buffer<"u"?{decode(s){return Buffer.from(s.buffer,s.byteOffset,s.byteLength).toString()}}:{decode(s){let e="";for(let t=0;t<s.length;t++)e+=String.fromCharCode(s[t]);return e}},Y=class{constructor(){this.pos=0,this.out="",this.buffer=new Uint8Array(j)}write(s){let{buffer:e}=this;e[this.pos++]=s,this.pos===j&&(this.out+=A.decode(e),this.pos=0)}flush(){let{buffer:s,out:e,pos:t}=this;return t>0?e+A.decode(s.subarray(0,t)):e}};function $(s){let e=new Y,t=0,n=0,i=0,r=0;for(let o=0;o<s.length;o++){let a=s[o];if(o>0&&e.write(z),a.length===0)continue;let l=0;for(let u=0;u<a.length;u++){let h=a[u];u>0&&e.write(W),l=b(e,h[0],l),h.length!==1&&(t=b(e,h[1],t),n=b(e,h[2],n),i=b(e,h[3],i),h.length!==4&&(r=b(e,h[4],r)))}}return e.flush()}var C=class s{constructor(e){this.bits=e instanceof s?e.bits.slice():[]}add(e){this.bits[e>>5]|=1<<(e&31)}has(e){return!!(this.bits[e>>5]&1<<(e&31))}},x=class s{constructor(e,t,n){this.start=e,this.end=t,this.original=n,this.intro="",this.outro="",this.content=n,this.storeName=!1,this.edited=!1,this.previous=null,this.next=null}appendLeft(e){this.outro+=e}appendRight(e){this.intro=this.intro+e}clone(){let e=new s(this.start,this.end,this.original);return e.intro=this.intro,e.outro=this.outro,e.content=this.content,e.storeName=this.storeName,e.edited=this.edited,e}contains(e){return this.start<e&&e<this.end}eachNext(e){let t=this;for(;t;)e(t),t=t.next}eachPrevious(e){let t=this;for(;t;)e(t),t=t.previous}edit(e,t,n){return this.content=e,n||(this.intro="",this.outro=""),this.storeName=t,this.edited=!0,this}prependLeft(e){this.outro=e+this.outro}prependRight(e){this.intro=e+this.intro}reset(){this.intro="",this.outro="",this.edited&&(this.content=this.original,this.storeName=!1,this.edited=!1)}split(e){let t=e-this.start,n=this.original.slice(0,t),i=this.original.slice(t);this.original=n;let r=new s(e,this.end,i);return r.outro=this.outro,this.outro="",this.end=e,this.edited?(r.edit("",!1),this.content=""):this.content=n,r.next=this.next,r.next&&(r.next.previous=r),r.previous=this,this.next=r,r}toString(){return this.intro+this.content+this.outro}trimEnd(e){if(this.outro=this.outro.replace(e,""),this.outro.length)return!0;let t=this.content.replace(e,"");if(t.length)return t!==this.content&&(this.split(this.start+t.length).edit("",void 0,!0),this.edited&&this.edit(t,this.storeName,!0)),!0;if(this.edit("",void 0,!0),this.intro=this.intro.replace(e,""),this.intro.length)return!0}trimStart(e){if(this.intro=this.intro.replace(e,""),this.intro.length)return!0;let t=this.content.replace(e,"");if(t.length){if(t!==this.content){let n=this.split(this.end-t.length);this.edited&&n.edit(t,this.storeName,!0),this.edit("",void 0,!0)}return!0}else if(this.edit("",void 0,!0),this.outro=this.outro.replace(e,""),this.outro.length)return!0}};function Z(){return typeof globalThis<"u"&&typeof globalThis.btoa=="function"?s=>globalThis.btoa(unescape(encodeURIComponent(s))):typeof Buffer=="function"?s=>Buffer.from(s,"utf-8").toString("base64"):()=>{throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.")}}var K=Z(),k=class{constructor(e){this.version=3,this.file=e.file,this.sources=e.sources,this.sourcesContent=e.sourcesContent,this.names=e.names,this.mappings=$(e.mappings),typeof e.x_google_ignoreList<"u"&&(this.x_google_ignoreList=e.x_google_ignoreList),typeof e.debugId<"u"&&(this.debugId=e.debugId)}toString(){return JSON.stringify(this)}toUrl(){return"data:application/json;charset=utf-8;base64,"+K(this.toString())}};function Q(s){let e=s.split(`
2
- `),t=e.filter(r=>/^\t+/.test(r)),n=e.filter(r=>/^ {2,}/.test(r));if(t.length===0&&n.length===0)return null;if(t.length>=n.length)return" ";let i=n.reduce((r,o)=>{let a=/^ +/.exec(o)[0].length;return Math.min(a,r)},1/0);return new Array(i+1).join(" ")}function X(s,e){let t=s.split(/[/\\]/),n=e.split(/[/\\]/);for(t.pop();t[0]===n[0];)t.shift(),n.shift();if(t.length){let i=t.length;for(;i--;)t[i]=".."}return t.concat(n).join("/")}var V=Object.prototype.toString;function ee(s){return V.call(s)==="[object Object]"}function B(s){let e=s.split(`
3
- `),t=[];for(let n=0,i=0;n<e.length;n++)t.push(i),i+=e[n].length+1;return function(i){let r=0,o=t.length;for(;r<o;){let u=r+o>>1;i<t[u]?o=u:r=u+1}let a=r-1,l=i-t[a];return{line:a,column:l}}}var te=/\w/,L=class{constructor(e){this.hires=e,this.generatedCodeLine=0,this.generatedCodeColumn=0,this.raw=[],this.rawSegments=this.raw[this.generatedCodeLine]=[],this.pending=null}addEdit(e,t,n,i){if(t.length){let r=t.length-1,o=t.indexOf(`
4
- `,0),a=-1;for(;o>=0&&r>o;){let u=[this.generatedCodeColumn,e,n.line,n.column];i>=0&&u.push(i),this.rawSegments.push(u),this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,a=o,o=t.indexOf(`
5
- `,o+1)}let l=[this.generatedCodeColumn,e,n.line,n.column];i>=0&&l.push(i),this.rawSegments.push(l),this.advance(t.slice(a+1))}else this.pending&&(this.rawSegments.push(this.pending),this.advance(t));this.pending=null}addUneditedChunk(e,t,n,i,r){let o=t.start,a=!0,l=!1;for(;o<t.end;){if(n[o]===`
6
- `)i.line+=1,i.column=0,this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,a=!0,l=!1;else{if(this.hires||a||r.has(o)){let u=[this.generatedCodeColumn,e,i.line,i.column];this.hires==="boundary"?te.test(n[o])?l||(this.rawSegments.push(u),l=!0):(this.rawSegments.push(u),l=!1):this.rawSegments.push(u)}i.column+=1,this.generatedCodeColumn+=1,a=!1}o+=1}this.pending=null}advance(e){if(!e)return;let t=e.split(`
7
- `);if(t.length>1){for(let n=0;n<t.length-1;n++)this.generatedCodeLine++,this.raw[this.generatedCodeLine]=this.rawSegments=[];this.generatedCodeColumn=0}this.generatedCodeColumn+=t[t.length-1].length}},y=`
8
- `,w={insertLeft:!1,insertRight:!1,storeName:!1},N=class s{constructor(e,t={}){let n=new x(0,e.length,e);Object.defineProperties(this,{original:{writable:!0,value:e},outro:{writable:!0,value:""},intro:{writable:!0,value:""},firstChunk:{writable:!0,value:n},lastChunk:{writable:!0,value:n},lastSearchedChunk:{writable:!0,value:n},byStart:{writable:!0,value:{}},byEnd:{writable:!0,value:{}},filename:{writable:!0,value:t.filename},indentExclusionRanges:{writable:!0,value:t.indentExclusionRanges},sourcemapLocations:{writable:!0,value:new C},storedNames:{writable:!0,value:{}},indentStr:{writable:!0,value:void 0},ignoreList:{writable:!0,value:t.ignoreList},offset:{writable:!0,value:t.offset||0}}),this.byStart[0]=n,this.byEnd[e.length]=n}addSourcemapLocation(e){this.sourcemapLocations.add(e)}append(e){if(typeof e!="string")throw new TypeError("outro content must be a string");return this.outro+=e,this}appendLeft(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let n=this.byEnd[e];return n?n.appendLeft(t):this.intro+=t,this}appendRight(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let n=this.byStart[e];return n?n.appendRight(t):this.outro+=t,this}clone(){let e=new s(this.original,{filename:this.filename,offset:this.offset}),t=this.firstChunk,n=e.firstChunk=e.lastSearchedChunk=t.clone();for(;t;){e.byStart[n.start]=n,e.byEnd[n.end]=n;let i=t.next,r=i&&i.clone();r&&(n.next=r,r.previous=n,n=r),t=i}return e.lastChunk=n,this.indentExclusionRanges&&(e.indentExclusionRanges=this.indentExclusionRanges.slice()),e.sourcemapLocations=new C(this.sourcemapLocations),e.intro=this.intro,e.outro=this.outro,e}generateDecodedMap(e){e=e||{};let t=0,n=Object.keys(this.storedNames),i=new L(e.hires),r=B(this.original);return this.intro&&i.advance(this.intro),this.firstChunk.eachNext(o=>{let a=r(o.start);o.intro.length&&i.advance(o.intro),o.edited?i.addEdit(t,o.content,a,o.storeName?n.indexOf(o.original):-1):i.addUneditedChunk(t,o,this.original,a,this.sourcemapLocations),o.outro.length&&i.advance(o.outro)}),this.outro&&i.advance(this.outro),{file:e.file?e.file.split(/[/\\]/).pop():void 0,sources:[e.source?X(e.file||"",e.source):e.file||""],sourcesContent:e.includeContent?[this.original]:void 0,names:n,mappings:i.raw,x_google_ignoreList:this.ignoreList?[t]:void 0}}generateMap(e){return new k(this.generateDecodedMap(e))}_ensureindentStr(){this.indentStr===void 0&&(this.indentStr=Q(this.original))}_getRawIndentString(){return this._ensureindentStr(),this.indentStr}getIndentString(){return this._ensureindentStr(),this.indentStr===null?" ":this.indentStr}indent(e,t){let n=/^[^\r\n]/gm;if(ee(e)&&(t=e,e=void 0),e===void 0&&(this._ensureindentStr(),e=this.indentStr||" "),e==="")return this;t=t||{};let i={};t.exclude&&(typeof t.exclude[0]=="number"?[t.exclude]:t.exclude).forEach(h=>{for(let f=h[0];f<h[1];f+=1)i[f]=!0});let r=t.indentStart!==!1,o=u=>r?`${e}${u}`:(r=!0,u);this.intro=this.intro.replace(n,o);let a=0,l=this.firstChunk;for(;l;){let u=l.end;if(l.edited)i[a]||(l.content=l.content.replace(n,o),l.content.length&&(r=l.content[l.content.length-1]===`
9
- `));else for(a=l.start;a<u;){if(!i[a]){let h=this.original[a];h===`
10
- `?r=!0:h!=="\r"&&r&&(r=!1,a===l.start||(this._splitChunk(l,a),l=l.next),l.prependRight(e))}a+=1}a=l.end,l=l.next}return this.outro=this.outro.replace(n,o),this}insert(){throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)")}insertLeft(e,t){return w.insertLeft||(console.warn("magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"),w.insertLeft=!0),this.appendLeft(e,t)}insertRight(e,t){return w.insertRight||(console.warn("magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"),w.insertRight=!0),this.prependRight(e,t)}move(e,t,n){if(e=e+this.offset,t=t+this.offset,n=n+this.offset,n>=e&&n<=t)throw new Error("Cannot move a selection inside itself");this._split(e),this._split(t),this._split(n);let i=this.byStart[e],r=this.byEnd[t],o=i.previous,a=r.next,l=this.byStart[n];if(!l&&r===this.lastChunk)return this;let u=l?l.previous:this.lastChunk;return o&&(o.next=a),a&&(a.previous=o),u&&(u.next=i),l&&(l.previous=r),i.previous||(this.firstChunk=r.next),r.next||(this.lastChunk=i.previous,this.lastChunk.next=null),i.previous=u,r.next=l||null,u||(this.firstChunk=i),l||(this.lastChunk=r),this}overwrite(e,t,n,i){return i=i||{},this.update(e,t,n,{...i,overwrite:!i.contentOnly})}update(e,t,n,i){if(e=e+this.offset,t=t+this.offset,typeof n!="string")throw new TypeError("replacement content must be a string");if(this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(t>this.original.length)throw new Error("end is out of bounds");if(e===t)throw new Error("Cannot overwrite a zero-length range – use appendLeft or prependRight instead");this._split(e),this._split(t),i===!0&&(w.storeName||(console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"),w.storeName=!0),i={storeName:!0});let r=i!==void 0?i.storeName:!1,o=i!==void 0?i.overwrite:!1;if(r){let u=this.original.slice(e,t);Object.defineProperty(this.storedNames,u,{writable:!0,value:!0,enumerable:!0})}let a=this.byStart[e],l=this.byEnd[t];if(a){let u=a;for(;u!==l;){if(u.next!==this.byStart[u.end])throw new Error("Cannot overwrite across a split point");u=u.next,u.edit("",!1)}a.edit(n,r,!o)}else{let u=new x(e,t,"").edit(n,r);l.next=u,u.previous=l}return this}prepend(e){if(typeof e!="string")throw new TypeError("outro content must be a string");return this.intro=e+this.intro,this}prependLeft(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let n=this.byEnd[e];return n?n.prependLeft(t):this.intro=t+this.intro,this}prependRight(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let n=this.byStart[e];return n?n.prependRight(t):this.outro=t+this.outro,this}remove(e,t){if(e=e+this.offset,t=t+this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(e===t)return this;if(e<0||t>this.original.length)throw new Error("Character is out of bounds");if(e>t)throw new Error("end must be greater than start");this._split(e),this._split(t);let n=this.byStart[e];for(;n;)n.intro="",n.outro="",n.edit(""),n=t>n.end?this.byStart[n.end]:null;return this}reset(e,t){if(e=e+this.offset,t=t+this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(e===t)return this;if(e<0||t>this.original.length)throw new Error("Character is out of bounds");if(e>t)throw new Error("end must be greater than start");this._split(e),this._split(t);let n=this.byStart[e];for(;n;)n.reset(),n=t>n.end?this.byStart[n.end]:null;return this}lastChar(){if(this.outro.length)return this.outro[this.outro.length-1];let e=this.lastChunk;do{if(e.outro.length)return e.outro[e.outro.length-1];if(e.content.length)return e.content[e.content.length-1];if(e.intro.length)return e.intro[e.intro.length-1]}while(e=e.previous);return this.intro.length?this.intro[this.intro.length-1]:""}lastLine(){let e=this.outro.lastIndexOf(y);if(e!==-1)return this.outro.substr(e+1);let t=this.outro,n=this.lastChunk;do{if(n.outro.length>0){if(e=n.outro.lastIndexOf(y),e!==-1)return n.outro.substr(e+1)+t;t=n.outro+t}if(n.content.length>0){if(e=n.content.lastIndexOf(y),e!==-1)return n.content.substr(e+1)+t;t=n.content+t}if(n.intro.length>0){if(e=n.intro.lastIndexOf(y),e!==-1)return n.intro.substr(e+1)+t;t=n.intro+t}}while(n=n.previous);return e=this.intro.lastIndexOf(y),e!==-1?this.intro.substr(e+1)+t:this.intro+t}slice(e=0,t=this.original.length-this.offset){if(e=e+this.offset,t=t+this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}let n="",i=this.firstChunk;for(;i&&(i.start>e||i.end<=e);){if(i.start<t&&i.end>=t)return n;i=i.next}if(i&&i.edited&&i.start!==e)throw new Error(`Cannot use replaced character ${e} as slice start anchor.`);let r=i;for(;i;){i.intro&&(r!==i||i.start===e)&&(n+=i.intro);let o=i.start<t&&i.end>=t;if(o&&i.edited&&i.end!==t)throw new Error(`Cannot use replaced character ${t} as slice end anchor.`);let a=r===i?e-i.start:0,l=o?i.content.length+t-i.end:i.content.length;if(n+=i.content.slice(a,l),i.outro&&(!o||i.end===t)&&(n+=i.outro),o)break;i=i.next}return n}snip(e,t){let n=this.clone();return n.remove(0,e),n.remove(t,n.original.length),n}_split(e){if(this.byStart[e]||this.byEnd[e])return;let t=this.lastSearchedChunk,n=t,i=e>t.end;for(;t;){if(t.contains(e))return this._splitChunk(t,e);if(t=i?this.byStart[t.end]:this.byEnd[t.start],t===n)return;n=t}}_splitChunk(e,t){if(e.edited&&e.content.length){let i=B(this.original)(t);throw new Error(`Cannot split a chunk that has already been edited (${i.line}:${i.column} – "${e.original}")`)}let n=e.split(t);return this.byEnd[t]=e,this.byStart[t]=n,this.byEnd[n.end]=n,e===this.lastChunk&&(this.lastChunk=n),this.lastSearchedChunk=e,!0}toString(){let e=this.intro,t=this.firstChunk;for(;t;)e+=t.toString(),t=t.next;return e+this.outro}isEmpty(){let e=this.firstChunk;do if(e.intro.length&&e.intro.trim()||e.content.length&&e.content.trim()||e.outro.length&&e.outro.trim())return!1;while(e=e.next);return!0}length(){let e=this.firstChunk,t=0;do t+=e.intro.length+e.content.length+e.outro.length;while(e=e.next);return t}trimLines(){return this.trim("[\\r\\n]")}trim(e){return this.trimStart(e).trimEnd(e)}trimEndAborted(e){let t=new RegExp((e||"\\s")+"+$");if(this.outro=this.outro.replace(t,""),this.outro.length)return!0;let n=this.lastChunk;do{let i=n.end,r=n.trimEnd(t);if(n.end!==i&&(this.lastChunk===n&&(this.lastChunk=n.next),this.byEnd[n.end]=n,this.byStart[n.next.start]=n.next,this.byEnd[n.next.end]=n.next),r)return!0;n=n.previous}while(n);return!1}trimEnd(e){return this.trimEndAborted(e),this}trimStartAborted(e){let t=new RegExp("^"+(e||"\\s")+"+");if(this.intro=this.intro.replace(t,""),this.intro.length)return!0;let n=this.firstChunk;do{let i=n.end,r=n.trimStart(t);if(n.end!==i&&(n===this.lastChunk&&(this.lastChunk=n.next),this.byEnd[n.end]=n,this.byStart[n.next.start]=n.next,this.byEnd[n.next.end]=n.next),r)return!0;n=n.next}while(n);return!1}trimStart(e){return this.trimStartAborted(e),this}hasChanged(){return this.original!==this.toString()}_replaceRegexp(e,t){function n(r,o){return typeof t=="string"?t.replace(/\$(\$|&|\d+)/g,(a,l)=>l==="$"?"$":l==="&"?r[0]:+l<r.length?r[+l]:`$${l}`):t(...r,r.index,o,r.groups)}function i(r,o){let a,l=[];for(;a=r.exec(o);)l.push(a);return l}if(e.global)i(e,this.original).forEach(o=>{if(o.index!=null){let a=n(o,this.original);a!==o[0]&&this.overwrite(o.index,o.index+o[0].length,a)}});else{let r=this.original.match(e);if(r&&r.index!=null){let o=n(r,this.original);o!==r[0]&&this.overwrite(r.index,r.index+r[0].length,o)}}return this}_replaceString(e,t){let{original:n}=this,i=n.indexOf(e);return i!==-1&&(typeof t=="function"&&(t=t(e,i,n)),e!==t&&this.overwrite(i,i+e.length,t)),this}replace(e,t){return typeof e=="string"?this._replaceString(e,t):this._replaceRegexp(e,t)}_replaceAllString(e,t){let{original:n}=this,i=e.length;for(let r=n.indexOf(e);r!==-1;r=n.indexOf(e,r+i)){let o=n.slice(r,r+i),a=t;typeof t=="function"&&(a=t(o,r,n)),o!==a&&this.overwrite(r,r+i,a)}return this}replaceAll(e,t){if(typeof e=="string")return this._replaceAllString(e,t);if(!e.global)throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");return this._replaceRegexp(e,t)}};function g(s,e){if(s)switch(s.type){case"Identifier":e.add(s.name);return;case"ObjectPattern":for(let t of s.properties)t.type==="RestElement"?g(t.argument,e):g(t.value,e);return;case"ArrayPattern":for(let t of s.elements)g(t,e);return;case"AssignmentPattern":g(s.left,e);return;case"RestElement":g(s.argument,e);return}}function R(s){switch(s.type){case"StringLiteral":case"NumericLiteral":case"BooleanLiteral":case"NullLiteral":case"BigIntLiteral":case"RegExpLiteral":case"Identifier":return!0;case"Literal":return!0;case"TemplateLiteral":return s.expressions.every(R);case"UnaryExpression":return R(s.argument);case"MemberExpression":return!1;default:return!1}}function v(s,e){if(!(!s||typeof s!="object")){e(s);for(let t of Object.keys(s)){if(t==="loc"||t==="range"||t==="leadingComments"||t==="trailingComments")continue;let n=s[t];if(Array.isArray(n))for(let i of n)i&&typeof i=="object"&&v(i,e);else n&&typeof n=="object"&&typeof n.type=="string"&&v(n,e)}}}function ne(s){let e=new Set;return v(s,t=>{if(t.type==="AssignmentExpression")g(t.left,e);else if(t.type==="UpdateExpression"){let n=t.argument;n?.type==="Identifier"&&e.add(n.name)}}),e}function ie(s,e){let t=new Set,n=i=>{let r=new Set;g(i,r);for(let o of r)e.has(o)&&t.add(o)};return v(s,i=>{switch(i.type){case"VariableDeclarator":n(i.id);return;case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":n(i.id);for(let r of i.params??[])n(r);return;case"CatchClause":n(i.param);return;case"ClassDeclaration":case"ClassExpression":n(i.id);return}}),t}function M(s,e,t){for(let n of s.properties??[]){if(n.type==="RestElement"){let h=n.argument;if(h?.type!=="Identifier"||e.length>0){let f=new Set;g(h,f);for(let E of f)t.bails.push({name:E,reason:"rest"});continue}t.rest={name:h.name,keys:[]};continue}if(n.computed){let h=new Set;g(n.value,h);for(let f of h)t.bails.push({name:f,reason:"computed"});continue}let i=n.key,r=i.type==="Identifier"?i.name:i.value,o=n.value,a;o.type==="AssignmentPattern"&&(a=o.right,o=o.left);let l=[...e,r];if(o.type==="Identifier"){if(a&&!R(a)){t.bails.push({name:o.name,reason:"unsafe-default"});continue}t.reads.push({name:o.name,path:l,...a?{fallback:a}:{}});continue}if(o.type==="ObjectPattern"){if(a){let h=new Set;g(o,h);for(let f of h)t.bails.push({name:f,reason:"unsafe-default"});continue}M(o,l,t);continue}let u=new Set;g(o,u);for(let h of u)t.bails.push({name:h,reason:"computed"})}}function T(s,e){let t={reads:[],bails:[]};if(s?.type!=="ObjectPattern"||(M(s,[],t),t.rest&&(e?.type!=="BlockStatement"?(t.bails.push({name:t.rest.name,reason:"rest"}),delete t.rest):t.rest.keys=(s.properties??[]).filter(a=>a.type!=="RestElement"&&!a.computed).map(a=>{let l=a.key;return l.type==="Identifier"?l.name:l.value})),t.reads.length===0&&!t.rest))return t;let n=new Set(t.reads.map(a=>a.name));t.rest&&n.add(t.rest.name);let i=ne(e),r=ie(e,n),o=[];for(let a of t.reads)i.has(a.name)?t.bails.push({name:a.name,reason:"reassigned"}):r.has(a.name)?t.bails.push({name:a.name,reason:"shadowed"}):o.push(a);return t.reads=o,t.rest&&i.has(t.rest.name)?(t.bails.push({name:t.rest.name,reason:"reassigned"}),delete t.rest):t.rest&&r.has(t.rest.name)&&(t.bails.push({name:t.rest.name,reason:"shadowed"}),delete t.rest),t}function F(s){switch(s){case"rest":return"this rest element cannot be served by splitProps, and copying the props into a plain object would lose the getters";case"computed":return"the property is not known until it runs";case"reassigned":return"the binding is assigned to, and props are read-only";case"shadowed":return"an inner scope binds the same name";case"unsafe-default":return"the default would have to run again on every read"}}function m(s,e){if(s)switch(s.type){case"Identifier":e.add(s.name);return;case"ObjectPattern":for(let t of s.properties)t.type==="RestElement"?m(t.argument,e):m(t.value,e);return;case"ArrayPattern":for(let t of s.elements)m(t,e);return;case"AssignmentPattern":m(s.left,e);return;case"RestElement":m(s.argument,e);return}}function U(s,e){switch(s.type){case"ImportDeclaration":for(let t of s.specifiers)m(t.local,e);return;case"VariableDeclaration":for(let t of s.declarations)m(t.id,e);return;case"FunctionDeclaration":case"ClassDeclaration":m(s.id,e);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":s.declaration&&U(s.declaration,e);return}}function q(s){let e=new Set;for(let t of s.body)U(t,e);return e}function S(s,e,t=null){if(!(!s||typeof s!="object"||typeof s.type!="string")&&!s.type.startsWith("TS")&&e(s,t)!==!1)for(let n of Object.keys(s)){if(n==="loc"||n==="leadingComments"||n==="trailingComments")continue;let i=s[n];if(Array.isArray(i))for(let r of i)S(r,e,s);else i&&typeof i=="object"&&S(i,e,s)}}function G(s){return!!s&&s[0]>="A"&&s[0]<="Z"}function re(s){let e=[];return S(s,t=>{if(t.type==="FunctionDeclaration"&&G(t.id?.name)){e.push(t);return}if(t.type==="VariableDeclarator"&&G(t.id?.name)){let n=t.init;n&&(n.type==="ArrowFunctionExpression"||n.type==="FunctionExpression")&&e.push(n)}}),e}function oe(s){let e=new Set;return S(s,t=>{t.type==="Identifier"&&e.add(t.name)}),e}function ae(s,e){if(!e)return!0;switch(e.type){case"MemberExpression":case"OptionalMemberExpression":return!(e.property===s&&!e.computed);case"ObjectProperty":case"ObjectMethod":case"ClassProperty":case"ClassMethod":return!(e.key===s&&!e.computed);case"LabeledStatement":case"BreakStatement":case"ContinueStatement":return e.label!==s;case"ImportSpecifier":case"ExportSpecifier":return!1;default:return!0}}function le(s,e,t={}){let n=[],i=[],r=new Set;for(let o of re(s)){let a=o.params?.[0];if(a?.type!=="ObjectPattern")continue;let l=T(a,o.body);for(let c of l.bails)i.push({name:c.name,reason:c.reason,message:F(c.reason),start:a.start});if(l.bails.length>0||l.reads.length===0&&!l.rest)continue;let u=oe(o),h=t.parameterName??"props";for(;u.has(h);)h=`_${h}`;let f=new Map;for(let c of l.reads){let d=`${h}.${c.path.join(".")}`,p=c.fallback;f.set(c.name,p?`(${d} === undefined ? ${e.slice(p.start,p.end)} : ${d})`:d)}let E=a.typeAnnotation;if(n.push({start:a.start,end:E?.start??a.end,code:h}),l.rest){let c=l.rest.keys.map(p=>JSON.stringify(p)).join(", "),d=o.body;n.push({start:d.start+1,end:d.start+1,code:`
11
- const [, ${l.rest.name}] = splitProps(${h}, [${c}]);`}),r.add("splitProps")}let I=[];S(o.body,(c,d)=>{if(c.type!=="Identifier")return;let p=f.get(c.name);if(!p)return;let P=d?.type==="ObjectProperty"&&d.shorthand&&d.value===c;if(!P&&!ae(c,d))return;let O=l.reads.find(J=>J.name===c.name).path;I.push({node:c,parent:P?d:null,text:p,property:O[O.length-1]})});for(let c of I)c.parent?n.push({start:c.parent.start,end:c.parent.end,code:`${c.node.name}: ${c.text}`}):n.push({start:c.node.start,end:c.node.end,code:c.text}),ue(c.node,h,c.property)}return{edits:n,diagnostics:i,used:r}}function ue(s,e,t){s.type="MemberExpression",s.computed=!1,s.optional=!1,s.object={type:"Identifier",name:e,start:s.start,end:s.start},s.property={type:"Identifier",name:t,start:s.end,end:s.end},delete s.name}function Se(s,e="module.tsx",t={}){let n=se(s,{sourceType:"module",plugins:["typescript","jsx"],errorRecovery:!0}),{edits:i,diagnostics:r,used:o}=le(n.program,s,t),a=new N(s);for(let l of i)l.start===l.end?a.appendLeft(l.start,l.code):a.overwrite(l.start,l.end,l.code);return o.has("splitProps")&&!q(n.program).has("splitProps")&&a.prepend(`import { splitProps } from ${JSON.stringify(t.runtimeModule??"@fluixi/dom")};
12
- `),{code:a.toString(),map:a.generateMap({source:e,includeContent:!0,hires:!0}),diagnostics:r,rewritten:i.filter(l=>l.code!==(t.parameterName??"props")).length}}export{le as collectPropsEdits,Se as transformProps};
1
+ // src/transform/props.ts
2
+ import { parse } from "@babel/parser";
3
+
4
+ // ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
5
+ var comma = ",".charCodeAt(0);
6
+ var semicolon = ";".charCodeAt(0);
7
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
8
+ var intToChar = new Uint8Array(64);
9
+ var charToInt = new Uint8Array(128);
10
+ for (let i = 0; i < chars.length; i++) {
11
+ const c = chars.charCodeAt(i);
12
+ intToChar[i] = c;
13
+ charToInt[c] = i;
14
+ }
15
+ function encodeInteger(builder, num, relative) {
16
+ let delta = num - relative;
17
+ delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
18
+ do {
19
+ let clamped = delta & 31;
20
+ delta >>>= 5;
21
+ if (delta > 0) clamped |= 32;
22
+ builder.write(intToChar[clamped]);
23
+ } while (delta > 0);
24
+ return num;
25
+ }
26
+ var bufLength = 1024 * 16;
27
+ var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
28
+ decode(buf) {
29
+ const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
30
+ return out.toString();
31
+ }
32
+ } : {
33
+ decode(buf) {
34
+ let out = "";
35
+ for (let i = 0; i < buf.length; i++) {
36
+ out += String.fromCharCode(buf[i]);
37
+ }
38
+ return out;
39
+ }
40
+ };
41
+ var StringWriter = class {
42
+ constructor() {
43
+ this.pos = 0;
44
+ this.out = "";
45
+ this.buffer = new Uint8Array(bufLength);
46
+ }
47
+ write(v) {
48
+ const { buffer } = this;
49
+ buffer[this.pos++] = v;
50
+ if (this.pos === bufLength) {
51
+ this.out += td.decode(buffer);
52
+ this.pos = 0;
53
+ }
54
+ }
55
+ flush() {
56
+ const { buffer, out, pos } = this;
57
+ return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
58
+ }
59
+ };
60
+ function encode(decoded) {
61
+ const writer = new StringWriter();
62
+ let sourcesIndex = 0;
63
+ let sourceLine = 0;
64
+ let sourceColumn = 0;
65
+ let namesIndex = 0;
66
+ for (let i = 0; i < decoded.length; i++) {
67
+ const line = decoded[i];
68
+ if (i > 0) writer.write(semicolon);
69
+ if (line.length === 0) continue;
70
+ let genColumn = 0;
71
+ for (let j = 0; j < line.length; j++) {
72
+ const segment = line[j];
73
+ if (j > 0) writer.write(comma);
74
+ genColumn = encodeInteger(writer, segment[0], genColumn);
75
+ if (segment.length === 1) continue;
76
+ sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
77
+ sourceLine = encodeInteger(writer, segment[2], sourceLine);
78
+ sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
79
+ if (segment.length === 4) continue;
80
+ namesIndex = encodeInteger(writer, segment[4], namesIndex);
81
+ }
82
+ }
83
+ return writer.flush();
84
+ }
85
+
86
+ // ../../node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs
87
+ var BitSet = class _BitSet {
88
+ constructor(arg) {
89
+ this.bits = arg instanceof _BitSet ? arg.bits.slice() : [];
90
+ }
91
+ add(n2) {
92
+ this.bits[n2 >> 5] |= 1 << (n2 & 31);
93
+ }
94
+ has(n2) {
95
+ return !!(this.bits[n2 >> 5] & 1 << (n2 & 31));
96
+ }
97
+ };
98
+ var Chunk = class _Chunk {
99
+ constructor(start, end, content) {
100
+ this.start = start;
101
+ this.end = end;
102
+ this.original = content;
103
+ this.intro = "";
104
+ this.outro = "";
105
+ this.content = content;
106
+ this.storeName = false;
107
+ this.edited = false;
108
+ {
109
+ this.previous = null;
110
+ this.next = null;
111
+ }
112
+ }
113
+ appendLeft(content) {
114
+ this.outro += content;
115
+ }
116
+ appendRight(content) {
117
+ this.intro = this.intro + content;
118
+ }
119
+ clone() {
120
+ const chunk = new _Chunk(this.start, this.end, this.original);
121
+ chunk.intro = this.intro;
122
+ chunk.outro = this.outro;
123
+ chunk.content = this.content;
124
+ chunk.storeName = this.storeName;
125
+ chunk.edited = this.edited;
126
+ return chunk;
127
+ }
128
+ contains(index) {
129
+ return this.start < index && index < this.end;
130
+ }
131
+ eachNext(fn) {
132
+ let chunk = this;
133
+ while (chunk) {
134
+ fn(chunk);
135
+ chunk = chunk.next;
136
+ }
137
+ }
138
+ eachPrevious(fn) {
139
+ let chunk = this;
140
+ while (chunk) {
141
+ fn(chunk);
142
+ chunk = chunk.previous;
143
+ }
144
+ }
145
+ edit(content, storeName, contentOnly) {
146
+ this.content = content;
147
+ if (!contentOnly) {
148
+ this.intro = "";
149
+ this.outro = "";
150
+ }
151
+ this.storeName = storeName;
152
+ this.edited = true;
153
+ return this;
154
+ }
155
+ prependLeft(content) {
156
+ this.outro = content + this.outro;
157
+ }
158
+ prependRight(content) {
159
+ this.intro = content + this.intro;
160
+ }
161
+ reset() {
162
+ this.intro = "";
163
+ this.outro = "";
164
+ if (this.edited) {
165
+ this.content = this.original;
166
+ this.storeName = false;
167
+ this.edited = false;
168
+ }
169
+ }
170
+ split(index) {
171
+ const sliceIndex = index - this.start;
172
+ const originalBefore = this.original.slice(0, sliceIndex);
173
+ const originalAfter = this.original.slice(sliceIndex);
174
+ this.original = originalBefore;
175
+ const newChunk = new _Chunk(index, this.end, originalAfter);
176
+ newChunk.outro = this.outro;
177
+ this.outro = "";
178
+ this.end = index;
179
+ if (this.edited) {
180
+ newChunk.edit("", false);
181
+ this.content = "";
182
+ } else {
183
+ this.content = originalBefore;
184
+ }
185
+ newChunk.next = this.next;
186
+ if (newChunk.next) newChunk.next.previous = newChunk;
187
+ newChunk.previous = this;
188
+ this.next = newChunk;
189
+ return newChunk;
190
+ }
191
+ toString() {
192
+ return this.intro + this.content + this.outro;
193
+ }
194
+ trimEnd(rx) {
195
+ this.outro = this.outro.replace(rx, "");
196
+ if (this.outro.length) return true;
197
+ const trimmed = this.content.replace(rx, "");
198
+ if (trimmed.length) {
199
+ if (trimmed !== this.content) {
200
+ this.split(this.start + trimmed.length).edit("", void 0, true);
201
+ if (this.edited) {
202
+ this.edit(trimmed, this.storeName, true);
203
+ }
204
+ }
205
+ return true;
206
+ } else {
207
+ this.edit("", void 0, true);
208
+ this.intro = this.intro.replace(rx, "");
209
+ if (this.intro.length) return true;
210
+ }
211
+ }
212
+ trimStart(rx) {
213
+ this.intro = this.intro.replace(rx, "");
214
+ if (this.intro.length) return true;
215
+ const trimmed = this.content.replace(rx, "");
216
+ if (trimmed.length) {
217
+ if (trimmed !== this.content) {
218
+ const newChunk = this.split(this.end - trimmed.length);
219
+ if (this.edited) {
220
+ newChunk.edit(trimmed, this.storeName, true);
221
+ }
222
+ this.edit("", void 0, true);
223
+ }
224
+ return true;
225
+ } else {
226
+ this.edit("", void 0, true);
227
+ this.outro = this.outro.replace(rx, "");
228
+ if (this.outro.length) return true;
229
+ }
230
+ }
231
+ };
232
+ function getBtoa() {
233
+ if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") {
234
+ return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
235
+ } else if (typeof Buffer === "function") {
236
+ return (str) => Buffer.from(str, "utf-8").toString("base64");
237
+ } else {
238
+ return () => {
239
+ throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
240
+ };
241
+ }
242
+ }
243
+ var btoa = /* @__PURE__ */ getBtoa();
244
+ var SourceMap = class {
245
+ constructor(properties) {
246
+ this.version = 3;
247
+ this.file = properties.file;
248
+ this.sources = properties.sources;
249
+ this.sourcesContent = properties.sourcesContent;
250
+ this.names = properties.names;
251
+ this.mappings = encode(properties.mappings);
252
+ if (typeof properties.x_google_ignoreList !== "undefined") {
253
+ this.x_google_ignoreList = properties.x_google_ignoreList;
254
+ }
255
+ if (typeof properties.debugId !== "undefined") {
256
+ this.debugId = properties.debugId;
257
+ }
258
+ }
259
+ toString() {
260
+ return JSON.stringify(this);
261
+ }
262
+ toUrl() {
263
+ return "data:application/json;charset=utf-8;base64," + btoa(this.toString());
264
+ }
265
+ };
266
+ function guessIndent(code) {
267
+ const lines = code.split("\n");
268
+ const tabbed = lines.filter((line) => /^\t+/.test(line));
269
+ const spaced = lines.filter((line) => /^ {2,}/.test(line));
270
+ if (tabbed.length === 0 && spaced.length === 0) {
271
+ return null;
272
+ }
273
+ if (tabbed.length >= spaced.length) {
274
+ return " ";
275
+ }
276
+ const min = spaced.reduce((previous, current) => {
277
+ const numSpaces = /^ +/.exec(current)[0].length;
278
+ return Math.min(numSpaces, previous);
279
+ }, Infinity);
280
+ return new Array(min + 1).join(" ");
281
+ }
282
+ function getRelativePath(from, to) {
283
+ const fromParts = from.split(/[/\\]/);
284
+ const toParts = to.split(/[/\\]/);
285
+ fromParts.pop();
286
+ while (fromParts[0] === toParts[0]) {
287
+ fromParts.shift();
288
+ toParts.shift();
289
+ }
290
+ if (fromParts.length) {
291
+ let i = fromParts.length;
292
+ while (i--) fromParts[i] = "..";
293
+ }
294
+ return fromParts.concat(toParts).join("/");
295
+ }
296
+ var toString = Object.prototype.toString;
297
+ function isObject(thing) {
298
+ return toString.call(thing) === "[object Object]";
299
+ }
300
+ function getLocator(source) {
301
+ const originalLines = source.split("\n");
302
+ const lineOffsets = [];
303
+ for (let i = 0, pos = 0; i < originalLines.length; i++) {
304
+ lineOffsets.push(pos);
305
+ pos += originalLines[i].length + 1;
306
+ }
307
+ return function locate(index) {
308
+ let i = 0;
309
+ let j = lineOffsets.length;
310
+ while (i < j) {
311
+ const m = i + j >> 1;
312
+ if (index < lineOffsets[m]) {
313
+ j = m;
314
+ } else {
315
+ i = m + 1;
316
+ }
317
+ }
318
+ const line = i - 1;
319
+ const column = index - lineOffsets[line];
320
+ return { line, column };
321
+ };
322
+ }
323
+ var wordRegex = /\w/;
324
+ var Mappings = class {
325
+ constructor(hires) {
326
+ this.hires = hires;
327
+ this.generatedCodeLine = 0;
328
+ this.generatedCodeColumn = 0;
329
+ this.raw = [];
330
+ this.rawSegments = this.raw[this.generatedCodeLine] = [];
331
+ this.pending = null;
332
+ }
333
+ addEdit(sourceIndex, content, loc, nameIndex) {
334
+ if (content.length) {
335
+ const contentLengthMinusOne = content.length - 1;
336
+ let contentLineEnd = content.indexOf("\n", 0);
337
+ let previousContentLineEnd = -1;
338
+ while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
339
+ const segment2 = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
340
+ if (nameIndex >= 0) {
341
+ segment2.push(nameIndex);
342
+ }
343
+ this.rawSegments.push(segment2);
344
+ this.generatedCodeLine += 1;
345
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
346
+ this.generatedCodeColumn = 0;
347
+ previousContentLineEnd = contentLineEnd;
348
+ contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
349
+ }
350
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
351
+ if (nameIndex >= 0) {
352
+ segment.push(nameIndex);
353
+ }
354
+ this.rawSegments.push(segment);
355
+ this.advance(content.slice(previousContentLineEnd + 1));
356
+ } else if (this.pending) {
357
+ this.rawSegments.push(this.pending);
358
+ this.advance(content);
359
+ }
360
+ this.pending = null;
361
+ }
362
+ addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
363
+ let originalCharIndex = chunk.start;
364
+ let first = true;
365
+ let charInHiresBoundary = false;
366
+ while (originalCharIndex < chunk.end) {
367
+ if (original[originalCharIndex] === "\n") {
368
+ loc.line += 1;
369
+ loc.column = 0;
370
+ this.generatedCodeLine += 1;
371
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
372
+ this.generatedCodeColumn = 0;
373
+ first = true;
374
+ charInHiresBoundary = false;
375
+ } else {
376
+ if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
377
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
378
+ if (this.hires === "boundary") {
379
+ if (wordRegex.test(original[originalCharIndex])) {
380
+ if (!charInHiresBoundary) {
381
+ this.rawSegments.push(segment);
382
+ charInHiresBoundary = true;
383
+ }
384
+ } else {
385
+ this.rawSegments.push(segment);
386
+ charInHiresBoundary = false;
387
+ }
388
+ } else {
389
+ this.rawSegments.push(segment);
390
+ }
391
+ }
392
+ loc.column += 1;
393
+ this.generatedCodeColumn += 1;
394
+ first = false;
395
+ }
396
+ originalCharIndex += 1;
397
+ }
398
+ this.pending = null;
399
+ }
400
+ advance(str) {
401
+ if (!str) return;
402
+ const lines = str.split("\n");
403
+ if (lines.length > 1) {
404
+ for (let i = 0; i < lines.length - 1; i++) {
405
+ this.generatedCodeLine++;
406
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
407
+ }
408
+ this.generatedCodeColumn = 0;
409
+ }
410
+ this.generatedCodeColumn += lines[lines.length - 1].length;
411
+ }
412
+ };
413
+ var n = "\n";
414
+ var warned = {
415
+ insertLeft: false,
416
+ insertRight: false,
417
+ storeName: false
418
+ };
419
+ var MagicString = class _MagicString {
420
+ constructor(string, options = {}) {
421
+ const chunk = new Chunk(0, string.length, string);
422
+ Object.defineProperties(this, {
423
+ original: { writable: true, value: string },
424
+ outro: { writable: true, value: "" },
425
+ intro: { writable: true, value: "" },
426
+ firstChunk: { writable: true, value: chunk },
427
+ lastChunk: { writable: true, value: chunk },
428
+ lastSearchedChunk: { writable: true, value: chunk },
429
+ byStart: { writable: true, value: {} },
430
+ byEnd: { writable: true, value: {} },
431
+ filename: { writable: true, value: options.filename },
432
+ indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
433
+ sourcemapLocations: { writable: true, value: new BitSet() },
434
+ storedNames: { writable: true, value: {} },
435
+ indentStr: { writable: true, value: void 0 },
436
+ ignoreList: { writable: true, value: options.ignoreList },
437
+ offset: { writable: true, value: options.offset || 0 }
438
+ });
439
+ this.byStart[0] = chunk;
440
+ this.byEnd[string.length] = chunk;
441
+ }
442
+ addSourcemapLocation(char) {
443
+ this.sourcemapLocations.add(char);
444
+ }
445
+ append(content) {
446
+ if (typeof content !== "string") throw new TypeError("outro content must be a string");
447
+ this.outro += content;
448
+ return this;
449
+ }
450
+ appendLeft(index, content) {
451
+ index = index + this.offset;
452
+ if (typeof content !== "string") throw new TypeError("inserted content must be a string");
453
+ this._split(index);
454
+ const chunk = this.byEnd[index];
455
+ if (chunk) {
456
+ chunk.appendLeft(content);
457
+ } else {
458
+ this.intro += content;
459
+ }
460
+ return this;
461
+ }
462
+ appendRight(index, content) {
463
+ index = index + this.offset;
464
+ if (typeof content !== "string") throw new TypeError("inserted content must be a string");
465
+ this._split(index);
466
+ const chunk = this.byStart[index];
467
+ if (chunk) {
468
+ chunk.appendRight(content);
469
+ } else {
470
+ this.outro += content;
471
+ }
472
+ return this;
473
+ }
474
+ clone() {
475
+ const cloned = new _MagicString(this.original, { filename: this.filename, offset: this.offset });
476
+ let originalChunk = this.firstChunk;
477
+ let clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
478
+ while (originalChunk) {
479
+ cloned.byStart[clonedChunk.start] = clonedChunk;
480
+ cloned.byEnd[clonedChunk.end] = clonedChunk;
481
+ const nextOriginalChunk = originalChunk.next;
482
+ const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
483
+ if (nextClonedChunk) {
484
+ clonedChunk.next = nextClonedChunk;
485
+ nextClonedChunk.previous = clonedChunk;
486
+ clonedChunk = nextClonedChunk;
487
+ }
488
+ originalChunk = nextOriginalChunk;
489
+ }
490
+ cloned.lastChunk = clonedChunk;
491
+ if (this.indentExclusionRanges) {
492
+ cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
493
+ }
494
+ cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
495
+ cloned.intro = this.intro;
496
+ cloned.outro = this.outro;
497
+ return cloned;
498
+ }
499
+ generateDecodedMap(options) {
500
+ options = options || {};
501
+ const sourceIndex = 0;
502
+ const names = Object.keys(this.storedNames);
503
+ const mappings = new Mappings(options.hires);
504
+ const locate = getLocator(this.original);
505
+ if (this.intro) {
506
+ mappings.advance(this.intro);
507
+ }
508
+ this.firstChunk.eachNext((chunk) => {
509
+ const loc = locate(chunk.start);
510
+ if (chunk.intro.length) mappings.advance(chunk.intro);
511
+ if (chunk.edited) {
512
+ mappings.addEdit(
513
+ sourceIndex,
514
+ chunk.content,
515
+ loc,
516
+ chunk.storeName ? names.indexOf(chunk.original) : -1
517
+ );
518
+ } else {
519
+ mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
520
+ }
521
+ if (chunk.outro.length) mappings.advance(chunk.outro);
522
+ });
523
+ if (this.outro) {
524
+ mappings.advance(this.outro);
525
+ }
526
+ return {
527
+ file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
528
+ sources: [
529
+ options.source ? getRelativePath(options.file || "", options.source) : options.file || ""
530
+ ],
531
+ sourcesContent: options.includeContent ? [this.original] : void 0,
532
+ names,
533
+ mappings: mappings.raw,
534
+ x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
535
+ };
536
+ }
537
+ generateMap(options) {
538
+ return new SourceMap(this.generateDecodedMap(options));
539
+ }
540
+ _ensureindentStr() {
541
+ if (this.indentStr === void 0) {
542
+ this.indentStr = guessIndent(this.original);
543
+ }
544
+ }
545
+ _getRawIndentString() {
546
+ this._ensureindentStr();
547
+ return this.indentStr;
548
+ }
549
+ getIndentString() {
550
+ this._ensureindentStr();
551
+ return this.indentStr === null ? " " : this.indentStr;
552
+ }
553
+ indent(indentStr, options) {
554
+ const pattern = /^[^\r\n]/gm;
555
+ if (isObject(indentStr)) {
556
+ options = indentStr;
557
+ indentStr = void 0;
558
+ }
559
+ if (indentStr === void 0) {
560
+ this._ensureindentStr();
561
+ indentStr = this.indentStr || " ";
562
+ }
563
+ if (indentStr === "") return this;
564
+ options = options || {};
565
+ const isExcluded = {};
566
+ if (options.exclude) {
567
+ const exclusions = typeof options.exclude[0] === "number" ? [options.exclude] : options.exclude;
568
+ exclusions.forEach((exclusion) => {
569
+ for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
570
+ isExcluded[i] = true;
571
+ }
572
+ });
573
+ }
574
+ let shouldIndentNextCharacter = options.indentStart !== false;
575
+ const replacer = (match) => {
576
+ if (shouldIndentNextCharacter) return `${indentStr}${match}`;
577
+ shouldIndentNextCharacter = true;
578
+ return match;
579
+ };
580
+ this.intro = this.intro.replace(pattern, replacer);
581
+ let charIndex = 0;
582
+ let chunk = this.firstChunk;
583
+ while (chunk) {
584
+ const end = chunk.end;
585
+ if (chunk.edited) {
586
+ if (!isExcluded[charIndex]) {
587
+ chunk.content = chunk.content.replace(pattern, replacer);
588
+ if (chunk.content.length) {
589
+ shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
590
+ }
591
+ }
592
+ } else {
593
+ charIndex = chunk.start;
594
+ while (charIndex < end) {
595
+ if (!isExcluded[charIndex]) {
596
+ const char = this.original[charIndex];
597
+ if (char === "\n") {
598
+ shouldIndentNextCharacter = true;
599
+ } else if (char !== "\r" && shouldIndentNextCharacter) {
600
+ shouldIndentNextCharacter = false;
601
+ if (charIndex === chunk.start) {
602
+ chunk.prependRight(indentStr);
603
+ } else {
604
+ this._splitChunk(chunk, charIndex);
605
+ chunk = chunk.next;
606
+ chunk.prependRight(indentStr);
607
+ }
608
+ }
609
+ }
610
+ charIndex += 1;
611
+ }
612
+ }
613
+ charIndex = chunk.end;
614
+ chunk = chunk.next;
615
+ }
616
+ this.outro = this.outro.replace(pattern, replacer);
617
+ return this;
618
+ }
619
+ insert() {
620
+ throw new Error(
621
+ "magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)"
622
+ );
623
+ }
624
+ insertLeft(index, content) {
625
+ if (!warned.insertLeft) {
626
+ console.warn(
627
+ "magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"
628
+ );
629
+ warned.insertLeft = true;
630
+ }
631
+ return this.appendLeft(index, content);
632
+ }
633
+ insertRight(index, content) {
634
+ if (!warned.insertRight) {
635
+ console.warn(
636
+ "magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"
637
+ );
638
+ warned.insertRight = true;
639
+ }
640
+ return this.prependRight(index, content);
641
+ }
642
+ move(start, end, index) {
643
+ start = start + this.offset;
644
+ end = end + this.offset;
645
+ index = index + this.offset;
646
+ if (index >= start && index <= end) throw new Error("Cannot move a selection inside itself");
647
+ this._split(start);
648
+ this._split(end);
649
+ this._split(index);
650
+ const first = this.byStart[start];
651
+ const last = this.byEnd[end];
652
+ const oldLeft = first.previous;
653
+ const oldRight = last.next;
654
+ const newRight = this.byStart[index];
655
+ if (!newRight && last === this.lastChunk) return this;
656
+ const newLeft = newRight ? newRight.previous : this.lastChunk;
657
+ if (oldLeft) oldLeft.next = oldRight;
658
+ if (oldRight) oldRight.previous = oldLeft;
659
+ if (newLeft) newLeft.next = first;
660
+ if (newRight) newRight.previous = last;
661
+ if (!first.previous) this.firstChunk = last.next;
662
+ if (!last.next) {
663
+ this.lastChunk = first.previous;
664
+ this.lastChunk.next = null;
665
+ }
666
+ first.previous = newLeft;
667
+ last.next = newRight || null;
668
+ if (!newLeft) this.firstChunk = first;
669
+ if (!newRight) this.lastChunk = last;
670
+ return this;
671
+ }
672
+ overwrite(start, end, content, options) {
673
+ options = options || {};
674
+ return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
675
+ }
676
+ update(start, end, content, options) {
677
+ start = start + this.offset;
678
+ end = end + this.offset;
679
+ if (typeof content !== "string") throw new TypeError("replacement content must be a string");
680
+ if (this.original.length !== 0) {
681
+ while (start < 0) start += this.original.length;
682
+ while (end < 0) end += this.original.length;
683
+ }
684
+ if (end > this.original.length) throw new Error("end is out of bounds");
685
+ if (start === end)
686
+ throw new Error(
687
+ "Cannot overwrite a zero-length range – use appendLeft or prependRight instead"
688
+ );
689
+ this._split(start);
690
+ this._split(end);
691
+ if (options === true) {
692
+ if (!warned.storeName) {
693
+ console.warn(
694
+ "The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"
695
+ );
696
+ warned.storeName = true;
697
+ }
698
+ options = { storeName: true };
699
+ }
700
+ const storeName = options !== void 0 ? options.storeName : false;
701
+ const overwrite = options !== void 0 ? options.overwrite : false;
702
+ if (storeName) {
703
+ const original = this.original.slice(start, end);
704
+ Object.defineProperty(this.storedNames, original, {
705
+ writable: true,
706
+ value: true,
707
+ enumerable: true
708
+ });
709
+ }
710
+ const first = this.byStart[start];
711
+ const last = this.byEnd[end];
712
+ if (first) {
713
+ let chunk = first;
714
+ while (chunk !== last) {
715
+ if (chunk.next !== this.byStart[chunk.end]) {
716
+ throw new Error("Cannot overwrite across a split point");
717
+ }
718
+ chunk = chunk.next;
719
+ chunk.edit("", false);
720
+ }
721
+ first.edit(content, storeName, !overwrite);
722
+ } else {
723
+ const newChunk = new Chunk(start, end, "").edit(content, storeName);
724
+ last.next = newChunk;
725
+ newChunk.previous = last;
726
+ }
727
+ return this;
728
+ }
729
+ prepend(content) {
730
+ if (typeof content !== "string") throw new TypeError("outro content must be a string");
731
+ this.intro = content + this.intro;
732
+ return this;
733
+ }
734
+ prependLeft(index, content) {
735
+ index = index + this.offset;
736
+ if (typeof content !== "string") throw new TypeError("inserted content must be a string");
737
+ this._split(index);
738
+ const chunk = this.byEnd[index];
739
+ if (chunk) {
740
+ chunk.prependLeft(content);
741
+ } else {
742
+ this.intro = content + this.intro;
743
+ }
744
+ return this;
745
+ }
746
+ prependRight(index, content) {
747
+ index = index + this.offset;
748
+ if (typeof content !== "string") throw new TypeError("inserted content must be a string");
749
+ this._split(index);
750
+ const chunk = this.byStart[index];
751
+ if (chunk) {
752
+ chunk.prependRight(content);
753
+ } else {
754
+ this.outro = content + this.outro;
755
+ }
756
+ return this;
757
+ }
758
+ remove(start, end) {
759
+ start = start + this.offset;
760
+ end = end + this.offset;
761
+ if (this.original.length !== 0) {
762
+ while (start < 0) start += this.original.length;
763
+ while (end < 0) end += this.original.length;
764
+ }
765
+ if (start === end) return this;
766
+ if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
767
+ if (start > end) throw new Error("end must be greater than start");
768
+ this._split(start);
769
+ this._split(end);
770
+ let chunk = this.byStart[start];
771
+ while (chunk) {
772
+ chunk.intro = "";
773
+ chunk.outro = "";
774
+ chunk.edit("");
775
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
776
+ }
777
+ return this;
778
+ }
779
+ reset(start, end) {
780
+ start = start + this.offset;
781
+ end = end + this.offset;
782
+ if (this.original.length !== 0) {
783
+ while (start < 0) start += this.original.length;
784
+ while (end < 0) end += this.original.length;
785
+ }
786
+ if (start === end) return this;
787
+ if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
788
+ if (start > end) throw new Error("end must be greater than start");
789
+ this._split(start);
790
+ this._split(end);
791
+ let chunk = this.byStart[start];
792
+ while (chunk) {
793
+ chunk.reset();
794
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
795
+ }
796
+ return this;
797
+ }
798
+ lastChar() {
799
+ if (this.outro.length) return this.outro[this.outro.length - 1];
800
+ let chunk = this.lastChunk;
801
+ do {
802
+ if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
803
+ if (chunk.content.length) return chunk.content[chunk.content.length - 1];
804
+ if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
805
+ } while (chunk = chunk.previous);
806
+ if (this.intro.length) return this.intro[this.intro.length - 1];
807
+ return "";
808
+ }
809
+ lastLine() {
810
+ let lineIndex = this.outro.lastIndexOf(n);
811
+ if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
812
+ let lineStr = this.outro;
813
+ let chunk = this.lastChunk;
814
+ do {
815
+ if (chunk.outro.length > 0) {
816
+ lineIndex = chunk.outro.lastIndexOf(n);
817
+ if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
818
+ lineStr = chunk.outro + lineStr;
819
+ }
820
+ if (chunk.content.length > 0) {
821
+ lineIndex = chunk.content.lastIndexOf(n);
822
+ if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
823
+ lineStr = chunk.content + lineStr;
824
+ }
825
+ if (chunk.intro.length > 0) {
826
+ lineIndex = chunk.intro.lastIndexOf(n);
827
+ if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
828
+ lineStr = chunk.intro + lineStr;
829
+ }
830
+ } while (chunk = chunk.previous);
831
+ lineIndex = this.intro.lastIndexOf(n);
832
+ if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
833
+ return this.intro + lineStr;
834
+ }
835
+ slice(start = 0, end = this.original.length - this.offset) {
836
+ start = start + this.offset;
837
+ end = end + this.offset;
838
+ if (this.original.length !== 0) {
839
+ while (start < 0) start += this.original.length;
840
+ while (end < 0) end += this.original.length;
841
+ }
842
+ let result = "";
843
+ let chunk = this.firstChunk;
844
+ while (chunk && (chunk.start > start || chunk.end <= start)) {
845
+ if (chunk.start < end && chunk.end >= end) {
846
+ return result;
847
+ }
848
+ chunk = chunk.next;
849
+ }
850
+ if (chunk && chunk.edited && chunk.start !== start)
851
+ throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
852
+ const startChunk = chunk;
853
+ while (chunk) {
854
+ if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
855
+ result += chunk.intro;
856
+ }
857
+ const containsEnd = chunk.start < end && chunk.end >= end;
858
+ if (containsEnd && chunk.edited && chunk.end !== end)
859
+ throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
860
+ const sliceStart = startChunk === chunk ? start - chunk.start : 0;
861
+ const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
862
+ result += chunk.content.slice(sliceStart, sliceEnd);
863
+ if (chunk.outro && (!containsEnd || chunk.end === end)) {
864
+ result += chunk.outro;
865
+ }
866
+ if (containsEnd) {
867
+ break;
868
+ }
869
+ chunk = chunk.next;
870
+ }
871
+ return result;
872
+ }
873
+ // TODO deprecate this? not really very useful
874
+ snip(start, end) {
875
+ const clone = this.clone();
876
+ clone.remove(0, start);
877
+ clone.remove(end, clone.original.length);
878
+ return clone;
879
+ }
880
+ _split(index) {
881
+ if (this.byStart[index] || this.byEnd[index]) return;
882
+ let chunk = this.lastSearchedChunk;
883
+ let previousChunk = chunk;
884
+ const searchForward = index > chunk.end;
885
+ while (chunk) {
886
+ if (chunk.contains(index)) return this._splitChunk(chunk, index);
887
+ chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
888
+ if (chunk === previousChunk) return;
889
+ previousChunk = chunk;
890
+ }
891
+ }
892
+ _splitChunk(chunk, index) {
893
+ if (chunk.edited && chunk.content.length) {
894
+ const loc = getLocator(this.original)(index);
895
+ throw new Error(
896
+ `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`
897
+ );
898
+ }
899
+ const newChunk = chunk.split(index);
900
+ this.byEnd[index] = chunk;
901
+ this.byStart[index] = newChunk;
902
+ this.byEnd[newChunk.end] = newChunk;
903
+ if (chunk === this.lastChunk) this.lastChunk = newChunk;
904
+ this.lastSearchedChunk = chunk;
905
+ return true;
906
+ }
907
+ toString() {
908
+ let str = this.intro;
909
+ let chunk = this.firstChunk;
910
+ while (chunk) {
911
+ str += chunk.toString();
912
+ chunk = chunk.next;
913
+ }
914
+ return str + this.outro;
915
+ }
916
+ isEmpty() {
917
+ let chunk = this.firstChunk;
918
+ do {
919
+ if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim())
920
+ return false;
921
+ } while (chunk = chunk.next);
922
+ return true;
923
+ }
924
+ length() {
925
+ let chunk = this.firstChunk;
926
+ let length = 0;
927
+ do {
928
+ length += chunk.intro.length + chunk.content.length + chunk.outro.length;
929
+ } while (chunk = chunk.next);
930
+ return length;
931
+ }
932
+ trimLines() {
933
+ return this.trim("[\\r\\n]");
934
+ }
935
+ trim(charType) {
936
+ return this.trimStart(charType).trimEnd(charType);
937
+ }
938
+ trimEndAborted(charType) {
939
+ const rx = new RegExp((charType || "\\s") + "+$");
940
+ this.outro = this.outro.replace(rx, "");
941
+ if (this.outro.length) return true;
942
+ let chunk = this.lastChunk;
943
+ do {
944
+ const end = chunk.end;
945
+ const aborted = chunk.trimEnd(rx);
946
+ if (chunk.end !== end) {
947
+ if (this.lastChunk === chunk) {
948
+ this.lastChunk = chunk.next;
949
+ }
950
+ this.byEnd[chunk.end] = chunk;
951
+ this.byStart[chunk.next.start] = chunk.next;
952
+ this.byEnd[chunk.next.end] = chunk.next;
953
+ }
954
+ if (aborted) return true;
955
+ chunk = chunk.previous;
956
+ } while (chunk);
957
+ return false;
958
+ }
959
+ trimEnd(charType) {
960
+ this.trimEndAborted(charType);
961
+ return this;
962
+ }
963
+ trimStartAborted(charType) {
964
+ const rx = new RegExp("^" + (charType || "\\s") + "+");
965
+ this.intro = this.intro.replace(rx, "");
966
+ if (this.intro.length) return true;
967
+ let chunk = this.firstChunk;
968
+ do {
969
+ const end = chunk.end;
970
+ const aborted = chunk.trimStart(rx);
971
+ if (chunk.end !== end) {
972
+ if (chunk === this.lastChunk) this.lastChunk = chunk.next;
973
+ this.byEnd[chunk.end] = chunk;
974
+ this.byStart[chunk.next.start] = chunk.next;
975
+ this.byEnd[chunk.next.end] = chunk.next;
976
+ }
977
+ if (aborted) return true;
978
+ chunk = chunk.next;
979
+ } while (chunk);
980
+ return false;
981
+ }
982
+ trimStart(charType) {
983
+ this.trimStartAborted(charType);
984
+ return this;
985
+ }
986
+ hasChanged() {
987
+ return this.original !== this.toString();
988
+ }
989
+ _replaceRegexp(searchValue, replacement) {
990
+ function getReplacement(match, str) {
991
+ if (typeof replacement === "string") {
992
+ return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
993
+ if (i === "$") return "$";
994
+ if (i === "&") return match[0];
995
+ const num = +i;
996
+ if (num < match.length) return match[+i];
997
+ return `$${i}`;
998
+ });
999
+ } else {
1000
+ return replacement(...match, match.index, str, match.groups);
1001
+ }
1002
+ }
1003
+ function matchAll(re, str) {
1004
+ let match;
1005
+ const matches = [];
1006
+ while (match = re.exec(str)) {
1007
+ matches.push(match);
1008
+ }
1009
+ return matches;
1010
+ }
1011
+ if (searchValue.global) {
1012
+ const matches = matchAll(searchValue, this.original);
1013
+ matches.forEach((match) => {
1014
+ if (match.index != null) {
1015
+ const replacement2 = getReplacement(match, this.original);
1016
+ if (replacement2 !== match[0]) {
1017
+ this.overwrite(match.index, match.index + match[0].length, replacement2);
1018
+ }
1019
+ }
1020
+ });
1021
+ } else {
1022
+ const match = this.original.match(searchValue);
1023
+ if (match && match.index != null) {
1024
+ const replacement2 = getReplacement(match, this.original);
1025
+ if (replacement2 !== match[0]) {
1026
+ this.overwrite(match.index, match.index + match[0].length, replacement2);
1027
+ }
1028
+ }
1029
+ }
1030
+ return this;
1031
+ }
1032
+ _replaceString(string, replacement) {
1033
+ const { original } = this;
1034
+ const index = original.indexOf(string);
1035
+ if (index !== -1) {
1036
+ if (typeof replacement === "function") {
1037
+ replacement = replacement(string, index, original);
1038
+ }
1039
+ if (string !== replacement) {
1040
+ this.overwrite(index, index + string.length, replacement);
1041
+ }
1042
+ }
1043
+ return this;
1044
+ }
1045
+ replace(searchValue, replacement) {
1046
+ if (typeof searchValue === "string") {
1047
+ return this._replaceString(searchValue, replacement);
1048
+ }
1049
+ return this._replaceRegexp(searchValue, replacement);
1050
+ }
1051
+ _replaceAllString(string, replacement) {
1052
+ const { original } = this;
1053
+ const stringLength = string.length;
1054
+ for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
1055
+ const previous = original.slice(index, index + stringLength);
1056
+ let _replacement = replacement;
1057
+ if (typeof replacement === "function") {
1058
+ _replacement = replacement(previous, index, original);
1059
+ }
1060
+ if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
1061
+ }
1062
+ return this;
1063
+ }
1064
+ replaceAll(searchValue, replacement) {
1065
+ if (typeof searchValue === "string") {
1066
+ return this._replaceAllString(searchValue, replacement);
1067
+ }
1068
+ if (!searchValue.global) {
1069
+ throw new TypeError(
1070
+ "MagicString.prototype.replaceAll called with a non-global RegExp argument"
1071
+ );
1072
+ }
1073
+ return this._replaceRegexp(searchValue, replacement);
1074
+ }
1075
+ };
1076
+
1077
+ // src/analyze/props-destructure.ts
1078
+ function patternNames(node, out) {
1079
+ if (!node) return;
1080
+ switch (node.type) {
1081
+ case "Identifier":
1082
+ out.add(node.name);
1083
+ return;
1084
+ case "ObjectPattern":
1085
+ for (const p of node.properties) {
1086
+ if (p.type === "RestElement") patternNames(p.argument, out);
1087
+ else patternNames(p.value, out);
1088
+ }
1089
+ return;
1090
+ case "ArrayPattern":
1091
+ for (const e of node.elements) patternNames(e, out);
1092
+ return;
1093
+ case "AssignmentPattern":
1094
+ patternNames(node.left, out);
1095
+ return;
1096
+ case "RestElement":
1097
+ patternNames(node.argument, out);
1098
+ return;
1099
+ }
1100
+ }
1101
+ function isSafeDefault(node) {
1102
+ switch (node.type) {
1103
+ case "StringLiteral":
1104
+ case "NumericLiteral":
1105
+ case "BooleanLiteral":
1106
+ case "NullLiteral":
1107
+ case "BigIntLiteral":
1108
+ case "RegExpLiteral":
1109
+ case "Identifier":
1110
+ return true;
1111
+ // ESTree spells every literal as `Literal`; both shapes reach this analysis.
1112
+ case "Literal":
1113
+ return true;
1114
+ case "TemplateLiteral":
1115
+ return node.expressions.every(isSafeDefault);
1116
+ case "UnaryExpression":
1117
+ return isSafeDefault(node.argument);
1118
+ case "MemberExpression":
1119
+ return false;
1120
+ default:
1121
+ return false;
1122
+ }
1123
+ }
1124
+ function walk(root, visit) {
1125
+ if (!root || typeof root !== "object") return;
1126
+ visit(root);
1127
+ for (const key of Object.keys(root)) {
1128
+ if (key === "loc" || key === "range" || key === "leadingComments" || key === "trailingComments") continue;
1129
+ const value = root[key];
1130
+ if (Array.isArray(value)) {
1131
+ for (const item of value) if (item && typeof item === "object") walk(item, visit);
1132
+ } else if (value && typeof value === "object" && typeof value.type === "string") {
1133
+ walk(value, visit);
1134
+ }
1135
+ }
1136
+ }
1137
+ function reassignedNames(body) {
1138
+ const written = /* @__PURE__ */ new Set();
1139
+ walk(body, (node) => {
1140
+ if (node.type === "AssignmentExpression") patternNames(node.left, written);
1141
+ else if (node.type === "UpdateExpression") {
1142
+ const arg = node.argument;
1143
+ if (arg?.type === "Identifier") written.add(arg.name);
1144
+ }
1145
+ });
1146
+ return written;
1147
+ }
1148
+ function shadowedNames(body, candidates) {
1149
+ const shadowed = /* @__PURE__ */ new Set();
1150
+ const note = (node) => {
1151
+ const names = /* @__PURE__ */ new Set();
1152
+ patternNames(node, names);
1153
+ for (const n2 of names) if (candidates.has(n2)) shadowed.add(n2);
1154
+ };
1155
+ walk(body, (node) => {
1156
+ switch (node.type) {
1157
+ case "VariableDeclarator":
1158
+ note(node.id);
1159
+ return;
1160
+ case "FunctionDeclaration":
1161
+ case "FunctionExpression":
1162
+ case "ArrowFunctionExpression":
1163
+ note(node.id);
1164
+ for (const p of node.params ?? []) note(p);
1165
+ return;
1166
+ case "CatchClause":
1167
+ note(node.param);
1168
+ return;
1169
+ case "ClassDeclaration":
1170
+ case "ClassExpression":
1171
+ note(node.id);
1172
+ return;
1173
+ }
1174
+ });
1175
+ return shadowed;
1176
+ }
1177
+ function collect(pattern, path, plan) {
1178
+ for (const property of pattern.properties ?? []) {
1179
+ if (property.type === "RestElement") {
1180
+ const argument = property.argument;
1181
+ if (argument?.type !== "Identifier" || path.length > 0) {
1182
+ const names2 = /* @__PURE__ */ new Set();
1183
+ patternNames(argument, names2);
1184
+ for (const name of names2) plan.bails.push({ name, reason: "rest" });
1185
+ continue;
1186
+ }
1187
+ plan.rest = { name: argument.name, keys: [] };
1188
+ continue;
1189
+ }
1190
+ if (property.computed) {
1191
+ const names2 = /* @__PURE__ */ new Set();
1192
+ patternNames(property.value, names2);
1193
+ for (const name of names2) plan.bails.push({ name, reason: "computed" });
1194
+ continue;
1195
+ }
1196
+ const key = property.key;
1197
+ const propertyName = key.type === "Identifier" ? key.name : key.value;
1198
+ let value = property.value;
1199
+ let fallback;
1200
+ if (value.type === "AssignmentPattern") {
1201
+ fallback = value.right;
1202
+ value = value.left;
1203
+ }
1204
+ const here = [...path, propertyName];
1205
+ if (value.type === "Identifier") {
1206
+ if (fallback && !isSafeDefault(fallback)) {
1207
+ plan.bails.push({ name: value.name, reason: "unsafe-default" });
1208
+ continue;
1209
+ }
1210
+ plan.reads.push({ name: value.name, path: here, ...fallback ? { fallback } : {} });
1211
+ continue;
1212
+ }
1213
+ if (value.type === "ObjectPattern") {
1214
+ if (fallback) {
1215
+ const names2 = /* @__PURE__ */ new Set();
1216
+ patternNames(value, names2);
1217
+ for (const name of names2) plan.bails.push({ name, reason: "unsafe-default" });
1218
+ continue;
1219
+ }
1220
+ collect(value, here, plan);
1221
+ continue;
1222
+ }
1223
+ const names = /* @__PURE__ */ new Set();
1224
+ patternNames(value, names);
1225
+ for (const name of names) plan.bails.push({ name, reason: "computed" });
1226
+ }
1227
+ }
1228
+ function planPropsDestructure(pattern, body) {
1229
+ const plan = { reads: [], bails: [] };
1230
+ if (pattern?.type !== "ObjectPattern") return plan;
1231
+ collect(pattern, [], plan);
1232
+ if (plan.rest) {
1233
+ if (body?.type !== "BlockStatement") {
1234
+ plan.bails.push({ name: plan.rest.name, reason: "rest" });
1235
+ delete plan.rest;
1236
+ } else {
1237
+ plan.rest.keys = (pattern.properties ?? []).filter((p) => p.type !== "RestElement" && !p.computed).map((p) => {
1238
+ const key = p.key;
1239
+ return key.type === "Identifier" ? key.name : key.value;
1240
+ });
1241
+ }
1242
+ }
1243
+ if (plan.reads.length === 0 && !plan.rest) return plan;
1244
+ const candidates = new Set(plan.reads.map((r) => r.name));
1245
+ if (plan.rest) candidates.add(plan.rest.name);
1246
+ const written = reassignedNames(body);
1247
+ const shadowed = shadowedNames(body, candidates);
1248
+ const kept = [];
1249
+ for (const read of plan.reads) {
1250
+ if (written.has(read.name)) plan.bails.push({ name: read.name, reason: "reassigned" });
1251
+ else if (shadowed.has(read.name)) plan.bails.push({ name: read.name, reason: "shadowed" });
1252
+ else kept.push(read);
1253
+ }
1254
+ plan.reads = kept;
1255
+ if (plan.rest && written.has(plan.rest.name)) {
1256
+ plan.bails.push({ name: plan.rest.name, reason: "reassigned" });
1257
+ delete plan.rest;
1258
+ } else if (plan.rest && shadowed.has(plan.rest.name)) {
1259
+ plan.bails.push({ name: plan.rest.name, reason: "shadowed" });
1260
+ delete plan.rest;
1261
+ }
1262
+ return plan;
1263
+ }
1264
+ function explainBail(reason) {
1265
+ switch (reason) {
1266
+ case "rest":
1267
+ return "this rest element cannot be served by splitProps, and copying the props into a plain object would lose the getters";
1268
+ case "computed":
1269
+ return "the property is not known until it runs";
1270
+ case "reassigned":
1271
+ return "the binding is assigned to, and props are read-only";
1272
+ case "shadowed":
1273
+ return "an inner scope binds the same name";
1274
+ case "unsafe-default":
1275
+ return "the default would have to run again on every read";
1276
+ }
1277
+ }
1278
+
1279
+ // src/transform/bindings.ts
1280
+ function patternNames2(node, out) {
1281
+ if (!node) return;
1282
+ switch (node.type) {
1283
+ case "Identifier":
1284
+ out.add(node.name);
1285
+ return;
1286
+ case "ObjectPattern":
1287
+ for (const p of node.properties) {
1288
+ if (p.type === "RestElement") patternNames2(p.argument, out);
1289
+ else patternNames2(p.value, out);
1290
+ }
1291
+ return;
1292
+ case "ArrayPattern":
1293
+ for (const e of node.elements) patternNames2(e, out);
1294
+ return;
1295
+ case "AssignmentPattern":
1296
+ patternNames2(node.left, out);
1297
+ return;
1298
+ case "RestElement":
1299
+ patternNames2(node.argument, out);
1300
+ return;
1301
+ }
1302
+ }
1303
+ function declared(node, out) {
1304
+ switch (node.type) {
1305
+ case "ImportDeclaration":
1306
+ for (const s of node.specifiers) patternNames2(s.local, out);
1307
+ return;
1308
+ case "VariableDeclaration":
1309
+ for (const d of node.declarations) patternNames2(d.id, out);
1310
+ return;
1311
+ case "FunctionDeclaration":
1312
+ case "ClassDeclaration":
1313
+ patternNames2(node.id, out);
1314
+ return;
1315
+ case "ExportNamedDeclaration":
1316
+ case "ExportDefaultDeclaration":
1317
+ if (node.declaration) declared(node.declaration, out);
1318
+ return;
1319
+ }
1320
+ }
1321
+ function moduleBindings(program) {
1322
+ const names = /* @__PURE__ */ new Set();
1323
+ for (const statement of program.body) declared(statement, names);
1324
+ return names;
1325
+ }
1326
+
1327
+ // src/transform/props.ts
1328
+ function walk2(root, visit, parent = null) {
1329
+ if (!root || typeof root !== "object" || typeof root.type !== "string") return;
1330
+ if (root.type.startsWith("TS")) return;
1331
+ if (visit(root, parent) === false) return;
1332
+ for (const key of Object.keys(root)) {
1333
+ if (key === "loc" || key === "leadingComments" || key === "trailingComments") continue;
1334
+ const value = root[key];
1335
+ if (Array.isArray(value)) {
1336
+ for (const item of value) walk2(item, visit, root);
1337
+ } else if (value && typeof value === "object") {
1338
+ walk2(value, visit, root);
1339
+ }
1340
+ }
1341
+ }
1342
+ function isComponentName(name) {
1343
+ return !!name && name[0] >= "A" && name[0] <= "Z";
1344
+ }
1345
+ function componentFunctions(program) {
1346
+ const found = [];
1347
+ walk2(program, (node) => {
1348
+ if (node.type === "FunctionDeclaration" && isComponentName(node.id?.name)) {
1349
+ found.push(node);
1350
+ return;
1351
+ }
1352
+ if (node.type === "VariableDeclarator" && isComponentName(node.id?.name)) {
1353
+ const init = node.init;
1354
+ if (init && (init.type === "ArrowFunctionExpression" || init.type === "FunctionExpression")) found.push(init);
1355
+ }
1356
+ });
1357
+ return found;
1358
+ }
1359
+ function usedNames(fn) {
1360
+ const names = /* @__PURE__ */ new Set();
1361
+ walk2(fn, (node) => {
1362
+ if (node.type === "Identifier") names.add(node.name);
1363
+ });
1364
+ return names;
1365
+ }
1366
+ function isReferencePosition(node, parent) {
1367
+ if (!parent) return true;
1368
+ switch (parent.type) {
1369
+ case "MemberExpression":
1370
+ case "OptionalMemberExpression":
1371
+ return !(parent.property === node && !parent.computed);
1372
+ case "ObjectProperty":
1373
+ case "ObjectMethod":
1374
+ case "ClassProperty":
1375
+ case "ClassMethod":
1376
+ return !(parent.key === node && !parent.computed);
1377
+ case "LabeledStatement":
1378
+ case "BreakStatement":
1379
+ case "ContinueStatement":
1380
+ return parent.label !== node;
1381
+ case "ImportSpecifier":
1382
+ case "ExportSpecifier":
1383
+ return false;
1384
+ default:
1385
+ return true;
1386
+ }
1387
+ }
1388
+ function collectPropsEdits(program, code, options = {}) {
1389
+ const edits = [];
1390
+ const diagnostics = [];
1391
+ const used = /* @__PURE__ */ new Set();
1392
+ for (const fn of componentFunctions(program)) {
1393
+ const pattern = fn.params?.[0];
1394
+ if (pattern?.type !== "ObjectPattern") continue;
1395
+ const plan = planPropsDestructure(pattern, fn.body);
1396
+ for (const b of plan.bails) {
1397
+ diagnostics.push({ name: b.name, reason: b.reason, message: explainBail(b.reason), start: pattern.start });
1398
+ }
1399
+ if (plan.bails.length > 0) continue;
1400
+ if (plan.reads.length === 0 && !plan.rest) continue;
1401
+ const taken = usedNames(fn);
1402
+ let parameter = options.parameterName ?? "props";
1403
+ while (taken.has(parameter)) parameter = `_${parameter}`;
1404
+ const replacement = /* @__PURE__ */ new Map();
1405
+ for (const read of plan.reads) {
1406
+ const access = `${parameter}.${read.path.join(".")}`;
1407
+ const fallback = read.fallback;
1408
+ replacement.set(
1409
+ read.name,
1410
+ fallback ? `(${access} === undefined ? ${code.slice(fallback.start, fallback.end)} : ${access})` : access
1411
+ );
1412
+ }
1413
+ const annotation = pattern.typeAnnotation;
1414
+ edits.push({ start: pattern.start, end: annotation?.start ?? pattern.end, code: parameter });
1415
+ if (plan.rest) {
1416
+ const keys = plan.rest.keys.map((k) => JSON.stringify(k)).join(", ");
1417
+ const body = fn.body;
1418
+ edits.push({
1419
+ start: body.start + 1,
1420
+ end: body.start + 1,
1421
+ code: `
1422
+ const [, ${plan.rest.name}] = splitProps(${parameter}, [${keys}]);`
1423
+ });
1424
+ used.add("splitProps");
1425
+ }
1426
+ const matches = [];
1427
+ walk2(fn.body, (node, parent) => {
1428
+ if (node.type !== "Identifier") return void 0;
1429
+ const text = replacement.get(node.name);
1430
+ if (!text) return void 0;
1431
+ const shorthand = parent?.type === "ObjectProperty" && parent.shorthand && parent.value === node;
1432
+ if (!shorthand && !isReferencePosition(node, parent)) return void 0;
1433
+ const path = plan.reads.find((r) => r.name === node.name).path;
1434
+ matches.push({ node, parent: shorthand ? parent : null, text, property: path[path.length - 1] });
1435
+ return void 0;
1436
+ });
1437
+ for (const match of matches) {
1438
+ if (match.parent) {
1439
+ edits.push({ start: match.parent.start, end: match.parent.end, code: `${match.node.name}: ${match.text}` });
1440
+ } else {
1441
+ edits.push({ start: match.node.start, end: match.node.end, code: match.text });
1442
+ }
1443
+ asMemberRead(match.node, parameter, match.property);
1444
+ }
1445
+ }
1446
+ return { edits, diagnostics, used };
1447
+ }
1448
+ function asMemberRead(node, parameter, property) {
1449
+ node.type = "MemberExpression";
1450
+ node.computed = false;
1451
+ node.optional = false;
1452
+ node.object = { type: "Identifier", name: parameter, start: node.start, end: node.start };
1453
+ node.property = { type: "Identifier", name: property, start: node.end, end: node.end };
1454
+ delete node["name"];
1455
+ }
1456
+ function transformProps(code, filename = "module.tsx", options = {}) {
1457
+ const ast = parse(code, {
1458
+ sourceType: "module",
1459
+ plugins: ["typescript", "jsx"],
1460
+ errorRecovery: true
1461
+ });
1462
+ const { edits, diagnostics, used } = collectPropsEdits(ast.program, code, options);
1463
+ const source = new MagicString(code);
1464
+ for (const e of edits) {
1465
+ if (e.start === e.end) source.appendLeft(e.start, e.code);
1466
+ else source.overwrite(e.start, e.end, e.code);
1467
+ }
1468
+ if (used.has("splitProps") && !moduleBindings(ast.program).has("splitProps")) {
1469
+ source.prepend(`import { splitProps } from ${JSON.stringify(options.runtimeModule ?? "@fluixi/dom")};
1470
+ `);
1471
+ }
1472
+ return {
1473
+ code: source.toString(),
1474
+ map: source.generateMap({ source: filename, includeContent: true, hires: true }),
1475
+ diagnostics,
1476
+ rewritten: edits.filter((e) => e.code !== (options.parameterName ?? "props")).length
1477
+ };
1478
+ }
1479
+ export {
1480
+ collectPropsEdits,
1481
+ transformProps
1482
+ };