@torpor/view 0.2.0 → 0.3.0

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 (719) hide show
  1. package/.oxlintrc.json +3 -0
  2. package/CHANGELOG.md +25 -0
  3. package/README.md +27 -26
  4. package/dist/Component-d19HOoEw.d.ts +11 -0
  5. package/dist/Component-d19HOoEw.d.ts.map +1 -0
  6. package/dist/ServerSlotRender-BiG4xB8e.d.ts +41 -0
  7. package/dist/ServerSlotRender-BiG4xB8e.d.ts.map +1 -0
  8. package/dist/compile.d.ts +202 -148
  9. package/dist/compile.d.ts.map +1 -0
  10. package/dist/compile.js +3378 -3754
  11. package/dist/compile.js.map +1 -1
  12. package/dist/formatText-B0FXBdFT.js +410 -0
  13. package/dist/formatText-B0FXBdFT.js.map +1 -0
  14. package/dist/index.d.ts +371 -171
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +819 -765
  17. package/dist/index.js.map +1 -1
  18. package/dist/ssr.d.ts +13 -8
  19. package/dist/ssr.d.ts.map +1 -0
  20. package/dist/ssr.js +18 -27
  21. package/dist/ssr.js.map +1 -1
  22. package/package.json +17 -21
  23. package/scripts/buildTestOutput.ts +1 -1
  24. package/scripts/copyToRepl.ts +9 -7
  25. package/src/ambient.d.ts +1 -0
  26. package/src/compile/build/client/BuildStatus.ts +6 -4
  27. package/src/compile/build/client/addMappedText.ts +25 -0
  28. package/src/compile/build/client/buildAddFragment.ts +26 -4
  29. package/src/compile/build/client/buildAwaitNode.ts +86 -54
  30. package/src/compile/build/client/buildCode.ts +91 -57
  31. package/src/compile/build/client/buildComponentNode.ts +20 -42
  32. package/src/compile/build/client/buildControlNode.ts +5 -4
  33. package/src/compile/build/client/buildElementNode.ts +66 -71
  34. package/src/compile/build/client/buildForNode.ts +24 -12
  35. package/src/compile/build/client/buildFragment.ts +29 -43
  36. package/src/compile/build/client/buildFragmentText.ts +27 -20
  37. package/src/compile/build/client/buildHtmlNode.ts +5 -3
  38. package/src/compile/build/client/buildIfNode.ts +44 -29
  39. package/src/compile/build/client/buildMount.ts +1 -1
  40. package/src/compile/build/client/buildNode.ts +8 -7
  41. package/src/compile/build/client/buildReplaceNode.ts +5 -3
  42. package/src/compile/build/client/buildRootNode.ts +2 -2
  43. package/src/compile/build/client/buildRun.ts +1 -1
  44. package/src/compile/build/client/buildScriptNode.ts +5 -3
  45. package/src/compile/build/client/buildSlotNode.ts +7 -23
  46. package/src/compile/build/client/buildSpecialNode.ts +10 -14
  47. package/src/compile/build/client/buildStyles.ts +53 -18
  48. package/src/compile/build/client/buildSwitchNode.ts +53 -32
  49. package/src/compile/build/client/buildTextNode.ts +31 -28
  50. package/src/compile/build/client/replaceForVarNames.ts +1 -1
  51. package/src/compile/build/client/stashRun.ts +22 -0
  52. package/src/compile/build/client/stashRunWithOffsets.ts +32 -0
  53. package/src/compile/build/server/BuildServerStatus.ts +3 -3
  54. package/src/compile/build/server/buildServerAwaitNode.ts +3 -3
  55. package/src/compile/build/server/buildServerCode.ts +57 -45
  56. package/src/compile/build/server/buildServerComponentNode.ts +10 -35
  57. package/src/compile/build/server/buildServerControlNode.ts +5 -2
  58. package/src/compile/build/server/buildServerElementNode.ts +15 -29
  59. package/src/compile/build/server/buildServerForNode.ts +3 -3
  60. package/src/compile/build/server/buildServerHtmlNode.ts +3 -3
  61. package/src/compile/build/server/buildServerIfNode.ts +3 -3
  62. package/src/compile/build/server/buildServerNode.ts +7 -6
  63. package/src/compile/build/server/buildServerReplaceNode.ts +3 -3
  64. package/src/compile/build/server/buildServerRootNode.ts +2 -2
  65. package/src/compile/build/server/buildServerScriptNode.ts +1 -1
  66. package/src/compile/build/server/buildServerSlotNode.ts +5 -21
  67. package/src/compile/build/server/buildServerSpecialNode.ts +10 -13
  68. package/src/compile/build/server/buildServerSwitchNode.ts +3 -3
  69. package/src/compile/build/server/buildServerTextNode.ts +9 -23
  70. package/src/compile/build/utils/nextVarName.ts +2 -2
  71. package/src/compile/build.ts +9 -4
  72. package/src/compile/buildType.ts +2 -2
  73. package/src/compile/parse/ParseComponentStatus.ts +24 -0
  74. package/src/compile/parse/ParseStatus.ts +6 -26
  75. package/src/compile/parse/addSpaceElement.ts +6 -5
  76. package/src/compile/parse/parseCode.ts +116 -60
  77. package/src/compile/parse/parseControl.ts +34 -32
  78. package/src/compile/parse/parseElement.ts +56 -121
  79. package/src/compile/parse/parseImports.ts +1 -1
  80. package/src/compile/parse/parseInlineScript.ts +12 -26
  81. package/src/compile/parse/parseMarkup.ts +9 -3
  82. package/src/compile/parse/parseStyles.ts +4 -4
  83. package/src/compile/parse/parseTag.ts +50 -8
  84. package/src/compile/parse/parseText.ts +96 -0
  85. package/src/compile/parse/scopeStyles.ts +9 -9
  86. package/src/compile/parse/slottifyChildNodes.ts +8 -7
  87. package/src/compile/parse/utils/accept.ts +1 -1
  88. package/src/compile/parse/utils/addError.ts +24 -6
  89. package/src/compile/parse/utils/consumeAlphaNumeric.ts +1 -1
  90. package/src/compile/parse/utils/consumeNonSpace.ts +1 -1
  91. package/src/compile/parse/utils/consumeSpace.ts +1 -1
  92. package/src/compile/parse/utils/consumeUntil.ts +1 -1
  93. package/src/compile/parse/utils/expect.ts +1 -1
  94. package/src/compile/parse.ts +1 -1
  95. package/src/compile/types/BuildResult.ts +5 -2
  96. package/src/compile/types/CompileError.ts +8 -5
  97. package/src/compile/types/Import.ts +2 -2
  98. package/src/compile/types/ParseResult.ts +4 -4
  99. package/src/compile/types/ScriptChunk.ts +6 -0
  100. package/src/compile/types/SourceMapping.ts +7 -0
  101. package/src/compile/types/SourceRange.ts +4 -0
  102. package/src/compile/types/nodes/Attribute.ts +7 -2
  103. package/src/compile/types/nodes/ControlNode.ts +8 -6
  104. package/src/compile/types/nodes/ElementNode.ts +11 -6
  105. package/src/compile/types/nodes/Fragment.ts +10 -2
  106. package/src/compile/types/nodes/NodeType.ts +3 -1
  107. package/src/compile/types/nodes/OperationType.ts +3 -1
  108. package/src/compile/types/nodes/ParentNode.ts +4 -4
  109. package/src/compile/types/nodes/RootNode.ts +5 -5
  110. package/src/compile/types/nodes/TemplateNode.ts +3 -3
  111. package/src/compile/types/nodes/TextNode.ts +5 -3
  112. package/src/compile/types/styles/Attribute.ts +2 -2
  113. package/src/compile/types/styles/Style.ts +3 -3
  114. package/src/compile/types/styles/StyleBlock.ts +3 -3
  115. package/src/compile/utils/Builder.ts +25 -11
  116. package/src/compile/utils/endOfString.ts +8 -0
  117. package/src/compile/utils/endOfTemplateString.ts +14 -0
  118. package/src/compile/{types/nodes → utils}/isComponentNode.ts +2 -2
  119. package/src/compile/utils/isControlNode.ts +6 -0
  120. package/src/compile/utils/isElementNode.ts +6 -0
  121. package/src/compile/utils/isParentNode.ts +6 -0
  122. package/src/compile/{types/nodes → utils}/isSpaceNode.ts +3 -3
  123. package/src/compile/utils/isSpecialNode.ts +6 -0
  124. package/src/compile/utils/isTextNode.ts +6 -0
  125. package/src/compile.ts +2 -2
  126. package/src/debug/printNode.ts +4 -0
  127. package/src/debug/printRanges.ts +74 -0
  128. package/src/debug/printSignalDiagram.ts +139 -0
  129. package/src/debug/printSimpleDiagram.ts +88 -0
  130. package/src/index.ts +13 -6
  131. package/src/render/$batch.ts +22 -0
  132. package/src/render/$cache.ts +34 -0
  133. package/src/render/$mount.ts +1 -1
  134. package/src/render/$peek.ts +14 -0
  135. package/src/render/$run.ts +16 -13
  136. package/src/render/$serverBatch.ts +3 -0
  137. package/src/render/$serverCache.ts +3 -0
  138. package/src/render/$serverMount.ts +1 -1
  139. package/src/render/$serverPeek.ts +3 -0
  140. package/src/render/$serverRun.ts +1 -1
  141. package/src/render/$unwrap.ts +3 -1
  142. package/src/render/$watch.ts +12 -13
  143. package/src/render/addAnimation.ts +1 -1
  144. package/src/render/addFragment.ts +15 -24
  145. package/src/render/applyProps.ts +1 -1
  146. package/src/render/buildClasses.ts +2 -2
  147. package/src/render/clearLayoutSlot.ts +1 -1
  148. package/src/render/clearRange.ts +43 -50
  149. package/src/render/context.ts +19 -48
  150. package/src/render/fillLayoutSlot.ts +3 -3
  151. package/src/render/getFragment.ts +1 -1
  152. package/src/render/hydrate.ts +9 -2
  153. package/src/render/hydrateRoot.ts +2 -2
  154. package/src/render/isCommentNode.ts +2 -2
  155. package/src/render/isFragmentNode.ts +2 -2
  156. package/src/render/isTextNode.ts +2 -2
  157. package/src/render/mount.ts +12 -4
  158. package/src/render/moveRange.ts +4 -11
  159. package/src/render/newListItem.ts +4 -4
  160. package/src/render/newRange.ts +6 -5
  161. package/src/render/nodeAnchor.ts +3 -3
  162. package/src/render/nodeCheckHydrationBreak.ts +2 -2
  163. package/src/render/nodeChild.ts +2 -2
  164. package/src/render/nodeNext.ts +1 -1
  165. package/src/render/nodeRoot.ts +8 -3
  166. package/src/render/popRange.ts +2 -2
  167. package/src/render/pushRange.ts +12 -4
  168. package/src/render/runControl.ts +1 -5
  169. package/src/render/runControlBranch.ts +10 -24
  170. package/src/render/runList.ts +6 -5
  171. package/src/render/runListItems.ts +39 -39
  172. package/src/render/setAttribute.ts +1 -1
  173. package/src/render/setDynamicElement.ts +2 -2
  174. package/src/ssr.ts +5 -2
  175. package/src/types/Animation.ts +1 -1
  176. package/src/types/BuildOptions.ts +6 -2
  177. package/src/types/Cleanup.ts +3 -1
  178. package/src/types/Component.ts +4 -2
  179. package/src/types/Computed.ts +62 -0
  180. package/src/types/Context.ts +99 -0
  181. package/src/types/Effect.ts +45 -9
  182. package/src/types/ListItem.ts +3 -3
  183. package/src/types/ProxyData.ts +6 -4
  184. package/src/types/ProxySignal.ts +28 -0
  185. package/src/types/Range.ts +10 -16
  186. package/src/types/ServerComponent.ts +4 -2
  187. package/src/types/ServerSlotRender.ts +3 -1
  188. package/src/types/SlotRender.ts +4 -2
  189. package/src/types/Subscription.ts +57 -0
  190. package/src/types/Template.ts +6 -5
  191. package/src/types/TemplateComponent.ts +7 -5
  192. package/src/types/WatchOptions.ts +8 -2
  193. package/src/types/constants.ts +14 -0
  194. package/src/watch/batchEnd.ts +17 -0
  195. package/src/watch/batchStart.ts +5 -0
  196. package/src/watch/checkComputed.ts +46 -0
  197. package/src/watch/checkEffect.ts +30 -0
  198. package/src/watch/checkSources.ts +63 -0
  199. package/src/watch/clearSources.ts +39 -0
  200. package/src/watch/clearTargets.ts +28 -0
  201. package/src/watch/deactivateSources.ts +19 -0
  202. package/src/watch/proxyGet.ts +106 -51
  203. package/src/watch/proxySet.ts +17 -13
  204. package/src/watch/runCleanups.ts +40 -0
  205. package/src/watch/runComputed.ts +36 -0
  206. package/src/watch/runEffect.ts +38 -13
  207. package/src/watch/symbols.ts +3 -1
  208. package/src/watch/trackEffect.ts +63 -15
  209. package/src/watch/trackProxyEffect.ts +21 -0
  210. package/src/watch/transferEffects.ts +66 -62
  211. package/src/watch/triggerEffects.ts +55 -18
  212. package/src/watch/updateSignal.ts +102 -0
  213. package/src/wrappers/ReactiveDate.ts +68 -0
  214. package/test/attributes/attributes.test.ts +2 -2
  215. package/test/attributes/components/output/Attributes-client.ts +8 -20
  216. package/test/attributes/components/output/Attributes-server.ts +8 -11
  217. package/test/attributes/components/temp/{Attributes-client-4620a40099e57a7fdaab895b204d85881f6dbfb7.ts → Attributes-client-9b2935d7824ba501776fdc6c48861422c15b6a12.ts} +8 -20
  218. package/test/attributes/components/temp/{Attributes-server-f4c59f5e4757ce0113907389902499efc36cfe38.ts → Attributes-server-716db6e335e5a372a34dd931e5f358ee6d1869e5.ts} +8 -11
  219. package/test/attributes/disappearing.test.ts +2 -2
  220. package/test/attributes/parse.test.ts +161 -248
  221. package/test/await/await.test.ts +2 -2
  222. package/test/await/components/Await.torp +2 -2
  223. package/test/await/components/output/Await-client.ts +25 -39
  224. package/test/await/components/output/Await-server.ts +9 -11
  225. package/test/await/components/temp/{Await-client-17b0e7c682fbff8518a440831620c1024b8be23a.ts → Await-client-e969f4bd0712acf259ddfaa5a3b3448307201fd2.ts} +25 -39
  226. package/test/await/components/temp/{Await-server-eb8d79f8abc791dd8e87f9713534cebf0eb2c854.ts → Await-server-614014fab69e234b8271088b10397cf0452d9a76.ts} +9 -11
  227. package/test/bench/components/Bench.torp +3 -3
  228. package/test/bench/components/output/Bench-client.ts +43 -252
  229. package/test/bench/components/output/Bench-server.ts +13 -26
  230. package/test/bench/components/temp/Bench-client-7f31596dafc8077370d8d90b1bb9b6e0208154e7.ts +205 -0
  231. package/test/bench/components/temp/Bench-server-341b20073668f4f2160cd2ba37847c7db15e1e0f.ts +129 -0
  232. package/test/bind/bind.test.ts +2 -2
  233. package/test/bind/component.test.ts +2 -2
  234. package/test/bind/components/output/BindComponent-client.ts +9 -19
  235. package/test/bind/components/output/BindComponent-server.ts +13 -18
  236. package/test/bind/components/output/BindText-client.ts +6 -13
  237. package/test/bind/components/output/BindText-server.ts +8 -10
  238. package/test/bind/components/temp/{BindComponent-client-a59ee6a598341c64c79be633ae7b22cb594dd0bc.ts → BindComponent-client-22eccb5354a2b0267841e015f3a2a0baf534bf89.ts} +9 -19
  239. package/test/bind/components/temp/{BindComponent-server-96120f1e75c77e02ba11ab719c225005e168d25f.ts → BindComponent-server-0da6ba90a409468fd1f7358f8198e96b7595ff80.ts} +13 -18
  240. package/test/bind/components/temp/{BindText-client-dac614203e672e51675b22a246983168a7c173ea.ts → BindText-client-7692ae1570533cc17e2186e9c7d4768529e4a2fe.ts} +6 -13
  241. package/test/bind/components/temp/{BindText-server-c713033ef787587f752fc8e6282e3a8faeee9a08.ts → BindText-server-6801c5f8e66a65405b45061bc037a011620c0591.ts} +8 -10
  242. package/test/build-server/build-server.test.ts +1 -0
  243. package/test/{if/components/temp/IfNested-client-f3045daba052e459add6e7f84e8d21ba7b0d81e4.ts → build-server/components/output/IfNested-client.ts} +23 -27
  244. package/test/{if/components/temp/IfNested-server-061ea3d56576a352be8a9db8424fae0f1d74cd36.ts → build-server/components/output/IfNested-server.ts} +6 -9
  245. package/test/build-server/components/temp/IfNested-client-eefdd449fa700b2e7326bc72df8b32ddcadf9d21.ts +88 -0
  246. package/test/build-server/components/temp/IfNested-server-7a53e4969b5dfe5073f05edbcb1b986f718bb939.ts +29 -0
  247. package/test/buildHtml.ts +2 -1
  248. package/test/buildOutputFiles.ts +3 -3
  249. package/test/child-component/child-component.test.ts +2 -2
  250. package/test/child-component/components/output/ParentChild-client.ts +9 -19
  251. package/test/child-component/components/output/ParentChild-server.ts +12 -18
  252. package/test/child-component/components/temp/{ParentChild-client-198e4ebc2ef5277ad7147f69d5879946fbe2d6ec.ts → ParentChild-client-2dfd600f7d409630d429a1d2d18c038bd08b08da.ts} +9 -19
  253. package/test/child-component/components/temp/{ParentChild-server-55e809830788ae740608136cf66664fc5434a9cd.ts → ParentChild-server-448d57c3229189c1d297d01dfb0f33646d280e90.ts} +12 -18
  254. package/test/class/class.test.ts +2 -2
  255. package/test/class/components/output/Class-client.ts +11 -29
  256. package/test/class/components/output/Class-server.ts +16 -19
  257. package/test/class/components/temp/{Class-client-7defac0b98d9c9f303670c0372e329e31823f163.ts → Class-client-5af6a50cd454ae019b2aa79457ba7ead83b8c056.ts} +11 -29
  258. package/test/class/components/temp/{Class-server-46563e9c3bf56b642ac496b60179decfd0b4e952.ts → Class-server-eb70ff01fbc7d6d53e16c3593ba021a6bf0317f9.ts} +16 -19
  259. package/test/comments/html-comments.test.ts +16 -24
  260. package/test/comments/js-block-comments.test.ts +16 -25
  261. package/test/comments/js-line-comments.test.ts +16 -25
  262. package/test/component/component.test.ts +2 -2
  263. package/test/component/components/Component.torp +1 -1
  264. package/test/component/components/output/Component-client.ts +5 -10
  265. package/test/component/components/output/Component-server.ts +7 -10
  266. package/test/component/components/output/Header-client.ts +6 -12
  267. package/test/component/components/output/Header-server.ts +7 -10
  268. package/test/component/components/temp/{Component-client-350d20784712c710929cc3ab34c6828b0ea338d8.ts → Component-client-fdc327499be0a01f987d0f2897baf022a247c77c.ts} +5 -10
  269. package/test/component/components/temp/{Component-server-2d4aa317e6c385036e07f4c3946fc18ba848c00d.ts → Component-server-f53221ac7b1c922ef10de2d1fe8fb534d0169fe7.ts} +7 -10
  270. package/test/component/components/temp/{Header-client-903877003b220272b0cb5bfd62d7d748ad46c477.ts → Header-client-6beb5770e68e6b19595e53e20bc906765fc6c260.ts} +6 -12
  271. package/test/component/components/temp/Header-server-940b0984f9b6c11f310db9200c9075ded385eda5.ts +16 -0
  272. package/test/console/components/output/Console-client.ts +5 -10
  273. package/test/console/components/output/Console-server.ts +7 -10
  274. package/test/console/components/temp/{Console-client-4fa3b3679cee88bf6151185438e36d14010944b7.ts → Console-client-2b58290ac407ebbe89a0613d64eb9cd141b99887.ts} +5 -10
  275. package/test/console/components/temp/Console-server-bde0121ce434f767435b1841fc4c24402becdba2.ts +15 -0
  276. package/test/console/console.test.ts +2 -2
  277. package/test/const/components/output/Const-client.ts +6 -11
  278. package/test/const/components/output/Const-server.ts +7 -10
  279. package/test/const/components/temp/{Const-client-b0293a037d9ed7b6ad4591c153723a3c26d46029.ts → Const-client-d1037557e7ef75a8fe06f56816e65883047e9421.ts} +6 -11
  280. package/test/const/components/temp/{Const-server-5fd2444a9ae7a676b7c4480e01e28f7f89624fdc.ts → Const-server-32ddc3617afe2324f17a4cff6c0f086df6694778.ts} +7 -10
  281. package/test/const/const.test.ts +2 -2
  282. package/test/context/components/ChildA.torp +10 -0
  283. package/test/context/components/ChildB.torp +8 -0
  284. package/test/context/components/Parent.torp +11 -0
  285. package/test/context/components/output/ChildA-client.ts +38 -0
  286. package/test/context/components/output/ChildA-server.ts +19 -0
  287. package/test/context/components/output/ChildB-client.ts +27 -0
  288. package/test/context/components/output/ChildB-server.ts +18 -0
  289. package/test/context/components/output/Parent-server.ts +31 -0
  290. package/test/context/components/temp/ChildA-client-9dea3e29ffcb82ca1779f6ff671e19b1c106fc4a.ts +38 -0
  291. package/test/context/components/temp/ChildA-server-54024d23c8241c3f475068f4fe3a3a14fd1c5870.ts +19 -0
  292. package/test/context/components/temp/ChildB-client-4b801099936c8aa013a1220f291375f67eba1acb.ts +27 -0
  293. package/test/context/components/temp/ChildB-server-f9b71341863bf869248bd406dbe8c7726a30ff90.ts +18 -0
  294. package/test/context/components/temp/Parent-client-9898b2e521527c86d69905053b6727ea8fd28166.ts +41 -0
  295. package/test/context/components/temp/Parent-server-b592ff0f516f4592e56d3a0bcb1f271ed28e812c.ts +31 -0
  296. package/test/context/context.test.ts +37 -0
  297. package/test/effects/components/output/For-client.ts +18 -19
  298. package/test/effects/components/output/For-server.ts +6 -9
  299. package/test/effects/components/output/If-client.ts +14 -18
  300. package/test/effects/components/output/If-server.ts +6 -9
  301. package/test/effects/components/output/NestedIf-client.ts +22 -25
  302. package/test/effects/components/output/NestedIf-server.ts +6 -9
  303. package/test/effects/components/temp/{For-client-268e69779d5b744377af9b30df256a453adaf183.ts → For-client-7c7d7c0dba2547f816b9bd9c6a95d6873ec00ffd.ts} +18 -19
  304. package/test/effects/components/temp/{For-server-b15b01b4daaf50fd95de790102089eb930e84e9b.ts → For-server-9e2de4efaff38ecf6c8a169c629d83c385489ca1.ts} +6 -9
  305. package/test/effects/components/temp/{If-client-4df0e6fc27a6f7d60ce056fd65df687213f3a2f9.ts → If-client-f0480a98f80b32612d12765c6838ff6db5982e82.ts} +14 -18
  306. package/test/effects/components/temp/{If-server-0a213ea232e0225d5a8ecb012ad418136b86fbe7.ts → If-server-ab409671b5d4c918047394a37b6e96b0e17063ca.ts} +6 -9
  307. package/test/effects/components/temp/{NestedIf-client-bfd381672c51febbe2f101f19afd5f6ff570ce7e.ts → NestedIf-client-702deffd158f219c5da4199b563a62cd54385a7f.ts} +22 -25
  308. package/test/effects/components/temp/{NestedIf-server-6089abc72d6208e64d1818ddb624ad5c3f236afa.ts → NestedIf-server-40f6bfd99a7e75fb4f9f874adab77e5eed97c629.ts} +6 -9
  309. package/test/effects/for-effect.test.ts +15 -15
  310. package/test/effects/if-effect.test.ts +7 -7
  311. package/test/effects/nested-if-effect.test.ts +11 -11
  312. package/test/events/components/Increment.torp +1 -1
  313. package/test/events/components/output/Increment-client.ts +7 -12
  314. package/test/events/components/output/Increment-server.ts +9 -11
  315. package/test/events/components/temp/{Increment-client-db2fd3376f12b186a4276eac470bf10b7bf2da19.ts → Increment-client-84c09711baf098c82ee226598ba7a36913616b75.ts} +7 -12
  316. package/test/events/components/temp/{Increment-server-062b9757192b84e5a6e247aa44e1e7887129293d.ts → Increment-server-e77c6b207023ac60e033ca542ee82473ef017f74.ts} +9 -11
  317. package/test/events/events.test.ts +9 -15
  318. package/test/for/components/output/For-client.ts +19 -19
  319. package/test/for/components/output/For-server.ts +7 -10
  320. package/test/for/components/output/ForEscape-client.ts +23 -37
  321. package/test/for/components/output/ForEscape-server.ts +8 -10
  322. package/test/for/components/output/ForIn-client.ts +19 -20
  323. package/test/for/components/output/ForIn-server.ts +7 -10
  324. package/test/for/components/output/ForOf-client.ts +19 -20
  325. package/test/for/components/output/ForOf-server.ts +7 -10
  326. package/test/for/components/temp/{For-client-8ecb11a2f34c81f837bffdb88598da06d8c19158.ts → For-client-2f6b4b81670b0ba31b01176b4f61ebf321e945bb.ts} +19 -19
  327. package/test/for/components/temp/{For-server-082c156a9f047995bc55f9477295d8e3262614f5.ts → For-server-5144615e53d23da5062b7169e847e0777d068738.ts} +7 -10
  328. package/test/for/components/temp/{ForEscape-client-14e7648415d967cdc57bf03d176eb6b6dddf0fb2.ts → ForEscape-client-8d0fcc940851e687173b6a9129c3d83e0fc771ef.ts} +23 -37
  329. package/test/for/components/temp/{ForEscape-server-2db43ff8397ddbb114b5bff3d88a63728184a811.ts → ForEscape-server-b359d8d3e12bac290855a1b27387ddd963562c08.ts} +8 -10
  330. package/test/for/components/temp/{ForIn-client-25cd67f246a50fc6d926a8c66aa5e106f19578a8.ts → ForIn-client-fa0614a1c7b8aa6e8819ed91a518479fd80453ae.ts} +19 -20
  331. package/test/for/components/temp/{ForIn-server-fda7a21cbb8a7ad69c48d2a8533cc13fa98d54b6.ts → ForIn-server-5fd472a7a5a5c00b384791780025a0c3bdc9c41b.ts} +7 -10
  332. package/test/for/components/temp/{ForOf-client-8f6598ccd9dc7b79aff6167b90ccea94f3029c84.ts → ForOf-client-11006c4239d9018363e582dc5b54b50477d652e7.ts} +19 -20
  333. package/test/for/components/temp/{ForOf-server-cd2b01507304e25c34030755b915f56785375de8.ts → ForOf-server-197b29abcb60412c6c8670b2d4a2e644b650faa3.ts} +7 -10
  334. package/test/for/for-escape.test.ts +2 -2
  335. package/test/for/for-in.test.ts +4 -4
  336. package/test/for/for-of.test.ts +4 -4
  337. package/test/for/for-with-key.test.ts +28 -36
  338. package/test/for/for.test.ts +2 -2
  339. package/test/function/components/Function.torp +0 -1
  340. package/test/function/components/output/Function-client.ts +6 -12
  341. package/test/function/components/output/Function-server.ts +8 -11
  342. package/test/function/components/temp/{Function-client-2068eb8ae35b3157b8eda79addde6afd9f4d7006.ts → Function-client-ec5fe7d599d6099bdfab78c2a0c8edf77a23cd9b.ts} +6 -12
  343. package/test/function/components/temp/{Function-server-4b66a728f6f1b170d678313238bdc9158356511e.ts → Function-server-fee2402b0ef4ad4c3d2779afb190ce46dbedf737.ts} +8 -11
  344. package/test/function/function.test.ts +7 -13
  345. package/test/helpers.ts +44 -9
  346. package/test/html/components/output/Html-client.ts +6 -12
  347. package/test/html/components/output/Html-server.ts +7 -10
  348. package/test/html/components/temp/{Html-client-93b0d666142c64cd651dc37f14f12884b2f30612.ts → Html-client-82ff34dcdcbdf4be1112bcb1baac8027cdc32de7.ts} +6 -12
  349. package/test/html/components/temp/Html-server-14fa484fc2a617bc0f24432a2e37e7a756f87a0f.ts +15 -0
  350. package/test/html/html.test.ts +2 -2
  351. package/test/hydrateComponent.ts +2 -2
  352. package/test/if/components/output/IfAfterIf-client.ts +21 -23
  353. package/test/if/components/output/IfAfterIf-server.ts +6 -9
  354. package/test/if/components/output/IfElse-client.ts +14 -18
  355. package/test/if/components/output/IfElse-server.ts +6 -9
  356. package/test/if/components/output/IfElseIf-client.ts +16 -22
  357. package/test/if/components/output/IfElseIf-server.ts +6 -9
  358. package/test/if/components/output/IfFalse-client.ts +13 -16
  359. package/test/if/components/output/IfFalse-server.ts +6 -9
  360. package/test/if/components/output/IfNested-client.ts +23 -27
  361. package/test/if/components/output/IfNested-server.ts +6 -9
  362. package/test/if/components/temp/{IfAfterIf-client-6b4833209a01cdad18d453839e9c8b5dad2a8510.ts → IfAfterIf-client-c1cfd21a6ace4945703ba8f46aada923a60265d9.ts} +21 -23
  363. package/test/if/components/temp/{IfAfterIf-server-3e6a3beab27821c3e53290ee72eca811814aad38.ts → IfAfterIf-server-26c9a638e3933a53208bfe66f8f37067511a28aa.ts} +6 -9
  364. package/test/if/components/temp/{IfElse-client-f7eb8e5fe5e62975a2442c4b0ff3344fa44cef69.ts → IfElse-client-06dfcacd3a5225dcb0947587bcd4fae9ec3d3c1e.ts} +14 -18
  365. package/test/if/components/temp/{IfElse-server-1b5006dfad695f257c7453a79bde3944898fbf6d.ts → IfElse-server-146b3779f85ea02a281c6042dddefa5372945fb0.ts} +6 -9
  366. package/test/if/components/temp/{IfElseIf-client-734f1b2d9133294573770c1ffc2b589273498532.ts → IfElseIf-client-26df9a728c9cb712d5ac0235b4c99885f25545b8.ts} +16 -22
  367. package/test/if/components/temp/{IfElseIf-server-11c65065e9e5640ad65cd0c37af07f1e57c4f49c.ts → IfElseIf-server-f094cdb45bc0fcd3144ca493346994b2445d2ff0.ts} +6 -9
  368. package/test/if/components/temp/{IfFalse-client-8a388cb48b4a5879d491f57d1f2551834de1e72e.ts → IfFalse-client-de6fc8e9eb222153608490e6d172e9aae9000aa1.ts} +13 -16
  369. package/test/if/components/temp/{IfFalse-server-40d07bc07e5edffd7386fb6016cd025b98175219.ts → IfFalse-server-b6d3446fd7d4219d5cb3c1009dec76870e73fa30.ts} +6 -9
  370. package/test/if/components/temp/IfNested-client-eefdd449fa700b2e7326bc72df8b32ddcadf9d21.ts +88 -0
  371. package/test/if/components/temp/IfNested-server-7a53e4969b5dfe5073f05edbcb1b986f718bb939.ts +29 -0
  372. package/test/if/else-if-true.test.ts +4 -4
  373. package/test/if/else-true.test.ts +4 -4
  374. package/test/if/if-after-if.test.ts +4 -4
  375. package/test/if/if-else-false.test.ts +4 -4
  376. package/test/if/if-else-true.test.ts +4 -4
  377. package/test/if/if-false.test.ts +4 -4
  378. package/test/if/if-nested.test.ts +4 -4
  379. package/test/imports/commented-imports.ts +1 -1
  380. package/test/imports/imports.ts +1 -1
  381. package/test/imports/multiple-imports.ts +1 -1
  382. package/test/mount/components/Mount.torp +1 -1
  383. package/test/mount/components/output/Mount-client.ts +6 -11
  384. package/test/mount/components/output/Mount-server.ts +10 -13
  385. package/test/mount/components/temp/{Mount-client-efa5c34fbfc7646e114a1a58f0814b6dff33e566.ts → Mount-client-29896228d7d0ef3692a9d13065c1bbfbe3198cdc.ts} +6 -11
  386. package/test/mount/components/temp/Mount-server-1c5aef88b8cc25b8e02851c0aa7fedffea987224.ts +22 -0
  387. package/test/mount/mount.test.ts +4 -4
  388. package/test/mountComponent.ts +1 -1
  389. package/test/on-mount/components/OnMount.torp +1 -1
  390. package/test/on-mount/components/output/OnMount-client.ts +5 -10
  391. package/test/on-mount/components/output/OnMount-server.ts +7 -10
  392. package/test/on-mount/components/temp/{OnMount-client-4bb62e8bf1fcd67798598fe03bf5455a57f0a6be.ts → OnMount-client-038f8c6bbcf0278406909d6ba5394f311924fda9.ts} +5 -10
  393. package/test/on-mount/components/temp/OnMount-server-ff4afcd976fd907c539e763d7887b38c61737be7.ts +15 -0
  394. package/test/on-mount/on-mount.test.ts +6 -6
  395. package/test/party/1-declare-state.test.ts +2 -2
  396. package/test/party/10-on-mount.test.ts +2 -2
  397. package/test/party/12-props.test.ts +2 -2
  398. package/test/party/13-emit-to-parent.test.ts +2 -2
  399. package/test/party/14-slot.test.ts +2 -2
  400. package/test/party/15-slot-fallback.test.ts +2 -2
  401. package/test/party/16-context.test.ts +2 -2
  402. package/test/party/17-input-text.test.ts +2 -2
  403. package/test/party/18-input-checkbox.test.ts +2 -2
  404. package/test/party/19-input-radio.test.ts +2 -2
  405. package/test/party/2-update-state.test.ts +2 -2
  406. package/test/party/20-input-select.test.ts +2 -2
  407. package/test/party/3-computed-state.test.ts +2 -2
  408. package/test/party/4-minimal-template.test.ts +2 -2
  409. package/test/party/5-styling.test.ts +2 -2
  410. package/test/party/6-loop.test.ts +2 -2
  411. package/test/party/7-event-click.test.ts +2 -2
  412. package/test/party/8-dom-ref.test.ts +4 -4
  413. package/test/party/9-conditional.test.ts +2 -2
  414. package/test/party/components/FunnyButton.torp +2 -2
  415. package/test/party/components/InputFocused.torp +1 -1
  416. package/test/party/components/UserProfile.torp +1 -1
  417. package/test/party/components/UserProfileApp.torp +1 -1
  418. package/test/party/components/UserProfileContextApp.torp +1 -1
  419. package/test/party/components/output/AnswerButton-client.ts +4 -10
  420. package/test/party/components/output/AnswerButton-server.ts +6 -9
  421. package/test/party/components/output/AnswerButtonApp-client.ts +6 -11
  422. package/test/party/components/output/AnswerButtonApp-server.ts +8 -10
  423. package/test/party/components/output/ColorSelect-client.ts +22 -26
  424. package/test/party/components/output/ColorSelect-server.ts +8 -10
  425. package/test/party/components/output/Colors-client.ts +19 -20
  426. package/test/party/components/output/Colors-server.ts +8 -10
  427. package/test/party/components/output/Counter-client.ts +7 -12
  428. package/test/party/components/output/Counter-server.ts +8 -10
  429. package/test/party/components/output/CssStyle-client.ts +5 -10
  430. package/test/party/components/output/CssStyle-server.ts +10 -10
  431. package/test/party/components/output/DoubleCount-client.ts +6 -11
  432. package/test/party/components/output/DoubleCount-server.ts +8 -10
  433. package/test/party/components/output/FunnyButton-client.ts +4 -10
  434. package/test/party/components/output/FunnyButton-server.ts +6 -8
  435. package/test/party/components/output/FunnyButtonApp-client.ts +7 -14
  436. package/test/party/components/output/FunnyButtonApp-server.ts +8 -12
  437. package/test/party/components/output/HelloWorld-client.ts +5 -10
  438. package/test/party/components/output/HelloWorld-server.ts +7 -10
  439. package/test/party/components/output/InputFocused-client.ts +6 -11
  440. package/test/party/components/output/InputFocused-server.ts +10 -13
  441. package/test/party/components/output/InputHello-client.ts +8 -13
  442. package/test/party/components/output/InputHello-server.ts +8 -10
  443. package/test/party/components/output/IsAvailable-client.ts +8 -13
  444. package/test/party/components/output/IsAvailable-server.ts +8 -10
  445. package/test/party/components/output/Name-client.ts +6 -11
  446. package/test/party/components/output/Name-server.ts +8 -10
  447. package/test/party/components/output/NameUpdate-client.ts +6 -11
  448. package/test/party/components/output/NameUpdate-server.ts +8 -10
  449. package/test/party/components/output/PageTitle-client.ts +6 -11
  450. package/test/party/components/output/PageTitle-server.ts +8 -10
  451. package/test/party/components/output/PickPill-client.ts +8 -13
  452. package/test/party/components/output/PickPill-server.ts +8 -10
  453. package/test/party/components/output/Time-client.ts +6 -11
  454. package/test/party/components/output/Time-server.ts +8 -10
  455. package/test/party/components/output/TrafficLight-client.ts +18 -26
  456. package/test/party/components/output/TrafficLight-server.ts +8 -10
  457. package/test/party/components/output/UserProfile-client.ts +6 -18
  458. package/test/party/components/output/UserProfile-server.ts +7 -10
  459. package/test/party/components/output/UserProfileApp-client.ts +6 -11
  460. package/test/party/components/output/UserProfileApp-server.ts +8 -11
  461. package/test/party/components/output/UserProfileContext-client.ts +7 -13
  462. package/test/party/components/output/UserProfileContext-server.ts +8 -9
  463. package/test/party/components/output/UserProfileContextApp-client.ts +7 -12
  464. package/test/party/components/output/UserProfileContextApp-server.ts +9 -11
  465. package/test/party/components/temp/{AnswerButton-client-890e28879c132eea21260eb82af832afc6a48507.ts → AnswerButton-client-df895c3e7a88fd7ede9f951fc9de2ed75c27a5cb.ts} +4 -10
  466. package/test/party/components/temp/{AnswerButton-server-01ffab9f6f92073640df2cf2cb5473407d82b24f.ts → AnswerButton-server-fa0e78b504a78d0e2dcd33a9a589f62e5b99c675.ts} +6 -9
  467. package/test/party/components/temp/{AnswerButtonApp-client-295a835cadf7e7ccec608f84ed01865dd8c73954.ts → AnswerButtonApp-client-4c05ef36b1c0e93370fb463643419928717fa701.ts} +6 -11
  468. package/test/party/components/temp/{AnswerButtonApp-server-b458692868307e6e08ad3deed9c2db542c28dee0.ts → AnswerButtonApp-server-062042691dabfa1a20d4088030c0b5bee1cd0be2.ts} +8 -10
  469. package/test/party/components/temp/{ColorSelect-client-5f74d3b38193a0c9b22317598cdbf2f56754ca2b.ts → ColorSelect-client-5db8d1b0924361fdb5efb867c14491402ec9668c.ts} +22 -26
  470. package/test/party/components/temp/{ColorSelect-server-cf0b1b533948a558e1705d9a7cca3c0b6ae8d315.ts → ColorSelect-server-8722b440cb7266a18a71b35c166be6dd6566fcec.ts} +8 -10
  471. package/test/party/components/temp/{Colors-client-806316cc5e01e8235c0b025cad34b1068addf5a5.ts → Colors-client-6d3ac693e85bdda50b8742282915997063a32769.ts} +19 -20
  472. package/test/party/components/temp/{Colors-server-b050714bfe752b88a99f6498f1b5c13abe6b56a5.ts → Colors-server-16572e26a55214c26683ce560b058b55d8c92685.ts} +8 -10
  473. package/test/party/components/temp/{Counter-client-006caeda8766cb17a161da0c6f58f006f8f16e8b.ts → Counter-client-0c604a107c5b84cdbf725f307dfe29d34f8a2cc8.ts} +7 -12
  474. package/test/party/components/temp/{Counter-server-931d36d8e4bcd114047bbfec8aa5f2fac0c2ce1e.ts → Counter-server-db18f030a6e02ab17708d6a17eb3e590965090e5.ts} +8 -10
  475. package/test/party/components/temp/{CssStyle-client-6ec06cbc4b34344234d289f6c4a9e427efff85a7.ts → CssStyle-client-2a642d115ad52539f97c051c34687b8d6d12b324.ts} +5 -10
  476. package/test/party/components/temp/CssStyle-server-0477c5497707dd9071105e5ec9045a3a7d1dd62d.ts +18 -0
  477. package/test/party/components/temp/{DoubleCount-client-6d4cf1e54368e3c6082e37c1e04f9ecde90624f2.ts → DoubleCount-client-8c85c3af12c471ea23bb702bbf5a3e240420f3ec.ts} +6 -11
  478. package/test/party/components/temp/{DoubleCount-server-8c013a97a08562deb6ad0f35e6e337203b0ddde9.ts → DoubleCount-server-5b04bb31269f9c8de6c25be427f57ab6e3d4dc19.ts} +8 -10
  479. package/test/party/components/temp/{FunnyButton-client-6d5662018a5a5529fd52ee82f7c88975b5c3355a.ts → FunnyButton-client-850dd3da0fa803c1bce5c53e88fcd2d48d279eb8.ts} +4 -10
  480. package/test/party/components/temp/{FunnyButton-server-3fd55a1e1dc71c183a6cea68e4c4693c988b7533.ts → FunnyButton-server-3df0067ec21476e7525d1c3de7099431c976f73b.ts} +6 -8
  481. package/test/party/components/temp/{FunnyButtonApp-client-1f2258b8488469d4704366bc49f5c171d8a854ae.ts → FunnyButtonApp-client-00300846d11a3d0a5a620c2ade87b935b7f0ebf8.ts} +7 -14
  482. package/test/party/components/temp/{FunnyButtonApp-server-6463d1c57adf61450d1415f0d76da4561ca3e798.ts → FunnyButtonApp-server-4cd83d2c71615fe4c905920e5ea836df4ed66c5e.ts} +8 -12
  483. package/test/party/components/temp/{HelloWorld-client-7344e400b4adb975fa8263d3081a06de0a793e57.ts → HelloWorld-client-890b311ad9a3919379acdc1d52807ea36cc9f489.ts} +5 -10
  484. package/test/party/components/temp/HelloWorld-server-e2c800d7f5cd3e772a9e5bbd7af58b00611b79d5.ts +15 -0
  485. package/test/party/components/temp/{InputFocused-client-20d755aea7dfaf1fd5e42dcade8fb7867f59ef28.ts → InputFocused-client-03527f9ceb52f66ac53887dbc884a0aa83bb7a23.ts} +6 -11
  486. package/test/party/components/temp/InputFocused-server-544a76ea64852474a3c7bf450b6fac36cbaf21c6.ts +23 -0
  487. package/test/party/components/temp/{InputHello-client-496d26bdeb6a168c4242e45f35d22e6ecbd211b9.ts → InputHello-client-f65a477624975b68b7aaa3614fbf198d4476480f.ts} +8 -13
  488. package/test/party/components/temp/{InputHello-server-a5fb3e0d8766c19d177a1f4d43d421c7da1b92ab.ts → InputHello-server-102d293d6c0fff7feda50d64bbd607df7d09393a.ts} +8 -10
  489. package/test/party/components/temp/{IsAvailable-client-491b92b5e21ebe1bbab47b2e422c35fb996b55e1.ts → IsAvailable-client-8767437fd92cf79713de5b00828e1502e38d79e3.ts} +8 -13
  490. package/test/party/components/temp/{IsAvailable-server-c0da3c019ef13617d2ab51353eb3360ddaae4189.ts → IsAvailable-server-2cf1e0d72df4bc194b5e00a1b415ba99f488525f.ts} +8 -10
  491. package/test/party/components/temp/{Name-client-62f0dab96aff130e81882099d7c0a111ba99cebd.ts → Name-client-08903a8df8bdff5288170d3c89658192956587a9.ts} +6 -11
  492. package/test/party/components/temp/{Name-server-0306b0c622d71323eb79a6b466d900380a0944f3.ts → Name-server-7d95226078ef4cd13b0ac6c5365ccbe4b8b9c0a2.ts} +8 -10
  493. package/test/party/components/temp/{NameUpdate-client-6ceb440637c99142bafcf8512eabf831c113b8c7.ts → NameUpdate-client-d65b2476c3721d2efddf9385a61433e2a2dd0d72.ts} +6 -11
  494. package/test/party/components/temp/{NameUpdate-server-a54ea11dc6b8f0b55d29ad29163cf27b9aa6ec40.ts → NameUpdate-server-9c901f861eddfde14440c2591dfafb2b1fb1993d.ts} +8 -10
  495. package/test/party/components/temp/{PageTitle-client-75fea3a37fb1213bc13f56160bb6779486b2e6e9.ts → PageTitle-client-c006df9a3e662488a1db089de53fd485c6b923e4.ts} +6 -11
  496. package/test/party/components/temp/{PageTitle-server-8b34f9af760ab39e20a60e10ee3185e70d92e42b.ts → PageTitle-server-f4676ec6feccaa03b89d52835c6635536eb885ef.ts} +8 -10
  497. package/test/party/components/temp/{PickPill-client-a1f48b5c28db87eb57f0ac1f6b4370e4b2952de7.ts → PickPill-client-af8357daf3f6633c7f451d0bddd72fefe786d5c3.ts} +8 -13
  498. package/test/party/components/temp/{PickPill-server-9596fdb8ff254cb4e1b99b714f3c5e8ea8aaa308.ts → PickPill-server-d8fb383bc25f7d26bb0153088a2ee19c765fc66b.ts} +8 -10
  499. package/test/party/components/temp/{Time-client-2013f274e90b45be3138727f2298305e1951131f.ts → Time-client-94380d45de7275a5cec98e5f58c15b74b13e9c3e.ts} +6 -11
  500. package/test/party/components/temp/{Time-server-da1cafe72c0f9a6dbf15a04dfa7282ae5187c101.ts → Time-server-3f71a83b6fd357b57e85344281454ee793024e7b.ts} +8 -10
  501. package/test/party/components/temp/{TrafficLight-client-d04c95686ec0ad8a9c54710773945e9904224d5e.ts → TrafficLight-client-12b20962b4146ef08fe0c37597441533c7699408.ts} +18 -26
  502. package/test/party/components/temp/{TrafficLight-server-6c0f66cdabfc7239b99665c3f7087462ee302e8a.ts → TrafficLight-server-625a774075633be88822f4d345e1421a77aba98a.ts} +8 -10
  503. package/test/party/components/temp/{UserProfile-client-a59466813b208664f35e6e394858c3d61e040644.ts → UserProfile-client-e5330b2c96bd8b225cb6291bc8b1d9f35c93307e.ts} +6 -18
  504. package/test/party/components/temp/{UserProfile-server-b10ec192e03dc818fe66dbd4aad14200e817e596.ts → UserProfile-server-6e89fd7f8ade8e8d64630e5da8361d7a1fa2ff5a.ts} +7 -10
  505. package/test/party/components/temp/{UserProfileApp-client-e0bfaa4ffed336c8be4b23dd81800501980c9938.ts → UserProfileApp-client-4c86e4f9a0d042f4f4811868f0146e872b17353c.ts} +6 -11
  506. package/test/party/components/temp/{UserProfileApp-server-4b308db466a80bcacd190aa71f86cf4d2b6f2873.ts → UserProfileApp-server-754d269451abf8fd04e519b8edde33d25c73ce28.ts} +8 -11
  507. package/test/party/components/temp/{UserProfileContext-client-7ef27199bd35b55b3dadd876174a2ef4b602b63f.ts → UserProfileContext-client-424131db3cc89ae4babe127b9108ffc5696c9e1d.ts} +7 -13
  508. package/test/party/components/temp/{UserProfileContext-server-df958e4fc2de2242c556ffa61ddb58aa395de50c.ts → UserProfileContext-server-e72e8ccee2703cce216f2368a1555d64acc2654c.ts} +8 -9
  509. package/test/party/components/temp/{UserProfileContextApp-client-b3ef357f481dfb940e1c726690d57567fde2dc23.ts → UserProfileContextApp-client-5f94a7ccf3e4542ea40d8046ad75eeb21005c55f.ts} +7 -12
  510. package/test/party/components/temp/{UserProfileContextApp-server-f8fe2b88db3d0dfa4dafd300006b25123cb8e3fb.ts → UserProfileContextApp-server-267ac147e0e59e53aeb6741a8cd0f3ef1216051f.ts} +9 -11
  511. package/test/preact.test.ts +2560 -0
  512. package/test/props/components/output/Reactive-client.ts +8 -17
  513. package/test/props/components/output/Reactive-server.ts +12 -16
  514. package/test/props/components/temp/{Reactive-client-21a24e3b0a76140567db8a01975317c9c0e0ad5a.ts → Reactive-client-9bc3643675fc563f96efb00bc3c4b843ba4b7f2e.ts} +8 -17
  515. package/test/props/components/temp/{Reactive-server-b6e37b5d3488ea74a260ca972906bfab30dde486.ts → Reactive-server-8a84d0fc1f375d91438d840ca9753e32d86366ac.ts} +12 -16
  516. package/test/props/reactive.test.ts +2 -2
  517. package/test/replace/components/output/Replace-client.ts +6 -14
  518. package/test/replace/components/output/Replace-server.ts +7 -9
  519. package/test/replace/components/temp/{Replace-client-aee34e2e40c6f4380b61e9c7c8df9af1897f06cc.ts → Replace-client-6f21ff3eb303bd5488d211087dc35fcf998d4e2a.ts} +6 -14
  520. package/test/replace/components/temp/{Replace-server-3521251fa687ce42af3128d22b129fe1ec6ed411.ts → Replace-server-b536cf6d792ae73aaa7f5ea04cda6858a07479f9.ts} +7 -9
  521. package/test/replace/replace.test.ts +2 -2
  522. package/test/script/script-with-comments.test.ts +14 -19
  523. package/test/script/script-with-strings.test.ts +14 -19
  524. package/test/script/script.test.ts +14 -19
  525. package/test/slots/basic-slot.test.ts +2 -2
  526. package/test/slots/components/Article.torp +3 -3
  527. package/test/slots/components/Basic.torp +1 -1
  528. package/test/slots/components/Header.torp +2 -2
  529. package/test/slots/components/Let.torp +3 -3
  530. package/test/slots/components/List.torp +1 -1
  531. package/test/slots/components/Named.torp +3 -3
  532. package/test/slots/components/Unused.torp +1 -1
  533. package/test/slots/components/output/Article-client.ts +4 -8
  534. package/test/slots/components/output/Article-server.ts +6 -8
  535. package/test/slots/components/output/Basic-client.ts +7 -14
  536. package/test/slots/components/output/Basic-server.ts +8 -12
  537. package/test/slots/components/output/Header-client.ts +4 -9
  538. package/test/slots/components/output/Header-server.ts +6 -8
  539. package/test/slots/components/output/Let-client.ts +7 -14
  540. package/test/slots/components/output/Let-server.ts +7 -11
  541. package/test/slots/components/output/List-client.ts +17 -16
  542. package/test/slots/components/output/List-server.ts +6 -8
  543. package/test/slots/components/output/Named-client.ts +9 -19
  544. package/test/slots/components/output/Named-server.ts +9 -14
  545. package/test/slots/components/output/Unused-client.ts +5 -10
  546. package/test/slots/components/output/Unused-server.ts +7 -10
  547. package/test/slots/components/temp/{Article-client-3f2da4b399f94ae8c329489e1ba0ba98196df9c5.ts → Article-client-0b674ee98ae7f85021bfb8b912f28e3c4b35e877.ts} +4 -8
  548. package/test/slots/components/temp/{Article-server-50fa458663f115c0e80a3a2846de4607d8748ecb.ts → Article-server-3db1718b70b86b456514b54ae17a597d07cc0ca9.ts} +6 -8
  549. package/test/slots/components/temp/{Basic-client-a2c4bf685d4b75d0395da427b7754c2a58374dd7.ts → Basic-client-196f7f0244dca0baeffb547eec55c089a108283d.ts} +7 -14
  550. package/test/slots/components/temp/{Basic-server-593e0ecbc8abbc90e8b06198698d244d110d97e2.ts → Basic-server-a22e6ec236b84e09d4d59c7abc4f0b22bf60f22c.ts} +8 -12
  551. package/test/slots/components/temp/{Header-client-d7418b71df5db36d58a73e909233863a6c03678b.ts → Header-client-e5c784d60469523803898ee4d8b85fb82a7b7c0b.ts} +4 -9
  552. package/test/slots/components/temp/{Header-server-d0f27afc4db322e605491e8f508e83f625e8dc38.ts → Header-server-3182d735443d9cf6a0cc7891919cc2c08df2aa8f.ts} +6 -8
  553. package/test/slots/components/temp/{Let-client-913f9dede92b68a3f4a13d1f56f99b3e08e01efe.ts → Let-client-645271fcd63cd500001c75740b22b1b387330657.ts} +7 -14
  554. package/test/slots/components/temp/{Let-server-f3c026e37c11628914c495083752d8cf285b2e85.ts → Let-server-b6d6e2012155c7533a0eb4ee0aaf00157a7d4493.ts} +7 -11
  555. package/test/slots/components/temp/{List-client-6bc2d267a8b2028a14b12b2c70feb7c6a47d6d64.ts → List-client-ee6047ac396dc0b6fce5e38af51c38093fae83a2.ts} +17 -16
  556. package/test/slots/components/temp/{List-server-8d9c174fc4b3b232f3a9fd2f59843481f023d913.ts → List-server-1ee246e864cdb31bb8f52cf4424b6ef0e9b41cf1.ts} +6 -8
  557. package/test/slots/components/temp/{Named-client-f6e7a984759ce8f50bc52dcf56f6f06cab925a80.ts → Named-client-559988562c5de1ae6017d2ad6de063f4363064b6.ts} +9 -19
  558. package/test/slots/components/temp/{Named-server-ac8d47db82d9a387c8baeee59b975bb810bad168.ts → Named-server-f2ce3d301e916ea38901a92185c25512b11d42d4.ts} +9 -14
  559. package/test/slots/components/temp/{Unused-client-ea0a096aa7a1c958f3bf807f35340b96f8a025ee.ts → Unused-client-52d1828bd28ebf7046a2e948a369563c0ea83b98.ts} +5 -10
  560. package/test/slots/components/temp/{Unused-server-1da99efc50ef70be0d9a0e5499353a17dc666936.ts → Unused-server-f5248f5cd4616c65eaf27c67385f13ed671accad.ts} +7 -10
  561. package/test/slots/let-slot.test.ts +4 -4
  562. package/test/slots/named-slot.test.ts +2 -2
  563. package/test/slots/unused-slot.test.ts +2 -2
  564. package/test/source-maps/components/Source.torp +19 -0
  565. package/test/source-maps/components/output/Source-client.ts +63 -0
  566. package/test/source-maps/components/output/Source-server.ts +26 -0
  567. package/test/source-maps/components/temp/Source-client-ae8c4811ff658c13ee8c9b9e0e53fff1b83b178b.ts +63 -0
  568. package/test/source-maps/components/temp/Source-server-70b20214c52b8820f450324943e8a1ffb0a72d5e.ts +26 -0
  569. package/test/source-maps/parse.test.ts +62 -0
  570. package/test/special-component/components/BigTitle.torp +1 -1
  571. package/test/special-component/components/Component.torp +2 -2
  572. package/test/special-component/components/SmallTitle.torp +1 -1
  573. package/test/special-component/components/output/BigTitle-client.ts +4 -8
  574. package/test/special-component/components/output/BigTitle-server.ts +6 -8
  575. package/test/special-component/components/output/Component-client.ts +7 -15
  576. package/test/special-component/components/output/Component-server.ts +8 -11
  577. package/test/special-component/components/output/SmallTitle-client.ts +4 -8
  578. package/test/special-component/components/output/SmallTitle-server.ts +6 -8
  579. package/test/special-component/components/temp/{BigTitle-client-c4bd66406d55ce83ab4491c4114d563055e1c275.ts → BigTitle-client-cb3055f809aaf17bd1fa82748d039ac3730a8d44.ts} +4 -8
  580. package/test/special-component/components/temp/{BigTitle-server-34af54c15cf575163c1ff8e63978cf5257f2347c.ts → BigTitle-server-fef9d1e1deacfde2be4469c2e63a801b2e518dff.ts} +6 -8
  581. package/test/special-component/components/temp/{Component-client-c39c66cf5274445bb863fd759e0ef223613a9f3a.ts → Component-client-0eb9553b52acce2dfa564242295a4c57a38bd540.ts} +7 -15
  582. package/test/special-component/components/temp/{Component-server-ca4a2192477db4a32ad12f1a6a14d673717b0f7b.ts → Component-server-9d0fddeff790bfb2b6cfbcd2edf677837f5b8120.ts} +8 -11
  583. package/test/special-component/components/temp/{SmallTitle-client-e4b3e51243ca4f1efca21ac0f957b81e8bc93167.ts → SmallTitle-client-5a65b233be29395e9650f57d9708a33de1279af3.ts} +4 -8
  584. package/test/special-component/components/temp/{SmallTitle-server-6c9aabb9139356397e04612b4dd9d849f871a280.ts → SmallTitle-server-11f8b6b3c613716d6a5371883a9b55434bb43ad5.ts} +6 -8
  585. package/test/special-component/special-component.test.ts +2 -2
  586. package/test/special-element/components/Element.torp +2 -2
  587. package/test/special-element/components/output/Element-client.ts +5 -11
  588. package/test/special-element/components/output/Element-server.ts +7 -10
  589. package/test/special-element/components/temp/{Element-client-c5701ed44faa4ec8ae558505063684a84cada3f2.ts → Element-client-745e610fbd5c652d327c8ac349d49d5ee4c8d9ea.ts} +5 -11
  590. package/test/special-element/components/temp/Element-server-7aef6d0ed7369aa2418183519c8320e0409a5641.ts +15 -0
  591. package/test/special-element/special-element.test.ts +2 -2
  592. package/test/special-head/components/Head.torp +2 -4
  593. package/test/special-head/components/output/Head-client.ts +8 -23
  594. package/test/special-head/components/output/Head-server.ts +5 -11
  595. package/test/special-head/components/temp/Head-client-bbbb5e712247ee41ca65a7ffd457987de5e99b3e.ts +19 -0
  596. package/test/special-head/components/temp/Head-server-c3de2e6b56aabc095380370d8bf93ae3bc7c10d9.ts +12 -0
  597. package/test/special-head/special-head.test.ts +2 -2
  598. package/test/special-self/components/output/Self-client.ts +13 -17
  599. package/test/special-self/components/output/Self-server.ts +6 -9
  600. package/test/special-self/components/temp/{Self-client-883ca81e0e44df56f2290698e8d6b9955434a2ad.ts → Self-client-dfe57df69e3677e94f7b5f3657c82602054ef19e.ts} +13 -17
  601. package/test/special-self/components/temp/{Self-server-69dac409fc984db7db97df8a30c5de6794f25655.ts → Self-server-5d135dab2b6fd4ba7fe3f56768f0725607d36bd9.ts} +6 -9
  602. package/test/special-self/special-self.test.ts +2 -2
  603. package/test/style/components/Style.torp +1 -1
  604. package/test/style/components/output/Style-client.ts +6 -12
  605. package/test/style/components/output/Style-server.ts +7 -10
  606. package/test/style/components/temp/{Style-client-ea018338497095f270308b2e73cfe6344721c6eb.ts → Style-client-9491a5aff97f118df542f976d7f7a21e7cc88c62.ts} +6 -12
  607. package/test/style/components/temp/{Style-server-99ff9867ee067760a463a8282773b2eb09aa14f7.ts → Style-server-8b8cbe1868cab30d9e34dda52921652768ada1db.ts} +7 -10
  608. package/test/style/parse.test.ts +507 -193
  609. package/test/style/style.test.ts +2 -2
  610. package/test/svg/components/Shape.torp +1 -1
  611. package/test/svg/components/output/Shape-client.ts +23 -23
  612. package/test/svg/components/output/Shape-server.ts +8 -10
  613. package/test/svg/components/temp/{Shape-client-052ea7838de07222602834de58968a3f89e6ea56.ts → Shape-client-4cc148d8b70d3750d2982360aad76b74d194b60e.ts} +23 -23
  614. package/test/svg/components/temp/Shape-server-76aaef570e067031ff39635ffe37626364c2200a.ts +23 -0
  615. package/test/svg/svg.test.ts +4 -4
  616. package/test/switch/components/output/Switch-client.ts +16 -22
  617. package/test/switch/components/output/Switch-server.ts +6 -9
  618. package/test/switch/components/temp/{Switch-client-1482e2da8fe144d3e867dfad4618e0f364b91b49.ts → Switch-client-5fc00f4d41300dc7587b113d8e53a102beca7558.ts} +16 -22
  619. package/test/switch/components/temp/{Switch-server-d709eb7a418752dd4203a8f824b78c5f308c8f47.ts → Switch-server-440f7e852145b79656c0023ddc776e4d1d077d2a.ts} +6 -9
  620. package/test/switch/switch-values.test.ts +4 -4
  621. package/test/template/basic-file.test.ts +61 -88
  622. package/test/template/empty-file.test.ts +7 -12
  623. package/test/template/errors.test.ts +64 -34
  624. package/test/text/components/output/Text-client.ts +5 -13
  625. package/test/text/components/output/Text-server.ts +6 -9
  626. package/test/text/components/temp/{Text-client-ca2d5402358fba0df1db2353eed304b0dedb7971.ts → Text-client-6c3be8a1a31a13eff86ce8b5330829cd15b07fab.ts} +5 -13
  627. package/test/text/components/temp/{Text-server-9df4606b85f044ea2b38660e799988461edacb27.ts → Text-server-ac34d47e755aa39b2d89cb44f854450c3db1ddff.ts} +6 -9
  628. package/test/text/text.test.ts +4 -4
  629. package/test/watch-array/ArrayState.ts +2 -2
  630. package/test/watch-array/array-all-functions-unkeyed.test.ts +16 -14
  631. package/test/watch-array/array-all-functions.test.ts +16 -14
  632. package/test/watch-array/array-empty.test.ts +8 -6
  633. package/test/watch-array/array-entries.test.ts +11 -9
  634. package/test/watch-array/array-indexes.test.ts +11 -9
  635. package/test/watch-array/array-pop.test.ts +10 -8
  636. package/test/watch-array/array-push.test.ts +10 -8
  637. package/test/watch-array/array-reassign.test.ts +11 -9
  638. package/test/watch-array/array-reverse.test.ts +10 -8
  639. package/test/watch-array/array-set-object.test.ts +10 -8
  640. package/test/watch-array/array-set-property.test.ts +10 -8
  641. package/test/watch-array/array-shift.test.ts +10 -8
  642. package/test/watch-array/array-sort.test.ts +11 -9
  643. package/test/watch-array/array-splice-add.test.ts +10 -8
  644. package/test/watch-array/array-splice-delete-all.test.ts +10 -8
  645. package/test/watch-array/array-splice-delete-and-add.test.ts +10 -8
  646. package/test/watch-array/array-splice-delete-end.test.ts +10 -8
  647. package/test/watch-array/array-splice-delete.test.ts +10 -8
  648. package/test/watch-array/array-swap.test.ts +10 -8
  649. package/test/watch-array/array-unshift.test.ts +10 -8
  650. package/test/watch-array/array-update-assignment.test.ts +10 -8
  651. package/test/watch-array/components/output/Array-client.ts +19 -21
  652. package/test/watch-array/components/output/Array-server.ts +7 -10
  653. package/test/watch-array/components/output/ArrayEntries-client.ts +21 -23
  654. package/test/watch-array/components/output/ArrayEntries-server.ts +7 -10
  655. package/test/watch-array/components/output/ArrayIndexes-client.ts +19 -21
  656. package/test/watch-array/components/output/ArrayIndexes-server.ts +7 -10
  657. package/test/watch-array/components/output/ArrayUnkeyed-client.ts +19 -20
  658. package/test/watch-array/components/output/ArrayUnkeyed-server.ts +7 -10
  659. package/test/watch-array/components/temp/{Array-client-d048f5c224a3f2e2729878dbb069ce15ca913e12.ts → Array-client-552f81452d33fe6dc715c9f6bb7986f06475d761.ts} +19 -21
  660. package/test/watch-array/components/temp/{Array-server-48864ed3b67cae2bcedb216865776e44cc3a1dc2.ts → Array-server-16921ef3289ecba5881fcd59e3353fbfad60d4d3.ts} +7 -10
  661. package/test/watch-array/components/temp/{ArrayEntries-client-741607b276718f5deb520e3b657dbf6abbb8081c.ts → ArrayEntries-client-736755fba2492e74812ff9c905202810de54e15a.ts} +21 -23
  662. package/test/watch-array/components/temp/{ArrayEntries-server-401a989fd5f3a093d5d1a8ef1d4fd9d5107a6be3.ts → ArrayEntries-server-ac150fc9fd18c1d9dab9b329f7703e190f5c2725.ts} +7 -10
  663. package/test/watch-array/components/temp/{ArrayIndexes-client-8ab14b254ef67dafad5228c9ec1906eb3b3babef.ts → ArrayIndexes-client-a496328fa92ffca676ab8893013a0cfec1734ad1.ts} +19 -21
  664. package/test/watch-array/components/temp/{ArrayIndexes-server-35c31a8a4597da68d39cf20bd6b90137695514de.ts → ArrayIndexes-server-e8fc511c0d27796dc1733f8cc63377f7a4511f76.ts} +7 -10
  665. package/test/watch-array/components/temp/{ArrayUnkeyed-client-9684aba82757748815b94c04bf3f8d1f98332535.ts → ArrayUnkeyed-client-5a2c5cb1fecba52653f7f35cfd07627682930c15.ts} +19 -20
  666. package/test/watch-array/components/temp/{ArrayUnkeyed-server-19f195f0cf00760c520ac4c55aef474c8eae4c41.ts → ArrayUnkeyed-server-916a5cdb7c36d95946cafdc69dca782291af24e4.ts} +7 -10
  667. package/test/watch-object/components/output/Watched-client.ts +5 -11
  668. package/test/watch-object/components/output/Watched-server.ts +6 -9
  669. package/test/watch-object/components/temp/{Watched-client-ddba353c5a94f5a874e19d6d4cc6271a04e915c0.ts → Watched-client-1f0409aa6e2c425d0319a23caec7d10ad313d579.ts} +5 -11
  670. package/test/watch-object/components/temp/{Watched-server-e8e8c15b9fb5dda4051a289e9cd75d71078b9e95.ts → Watched-server-156afd257b562162d86417f2bbf5afe1bf57de06.ts} +6 -9
  671. package/test/watch-object/watch-object.test.ts +11 -9
  672. package/{tsup.config.ts → tsdown.config.ts} +2 -4
  673. package/dist/Component-CysAnHpO.d.cts +0 -8
  674. package/dist/Component-CysAnHpO.d.ts +0 -8
  675. package/dist/ServerSlotRender-BMGG0yq3.d.cts +0 -15
  676. package/dist/ServerSlotRender-BMGG0yq3.d.ts +0 -15
  677. package/dist/chunk-EGRHWZRV.js +0 -1
  678. package/dist/chunk-EGRHWZRV.js.map +0 -1
  679. package/dist/chunk-XNO4YEJ3.js +0 -64
  680. package/dist/chunk-XNO4YEJ3.js.map +0 -1
  681. package/dist/compile.cjs +0 -4083
  682. package/dist/compile.cjs.map +0 -1
  683. package/dist/compile.d.cts +0 -156
  684. package/dist/index.cjs +0 -926
  685. package/dist/index.cjs.map +0 -1
  686. package/dist/index.d.cts +0 -211
  687. package/dist/metafile-cjs.json +0 -1
  688. package/dist/metafile-esm.json +0 -1
  689. package/dist/ssr.cjs +0 -125
  690. package/dist/ssr.cjs.map +0 -1
  691. package/dist/ssr.d.cts +0 -14
  692. package/src/compile/build/client/buildHeadNode.ts +0 -17
  693. package/src/compile/build/utils/isReactiveAttribute.ts +0 -16
  694. package/src/compile/types/nodes/isControlNode.ts +0 -6
  695. package/src/compile/types/nodes/isElementNode.ts +0 -6
  696. package/src/compile/types/nodes/isParentNode.ts +0 -6
  697. package/src/compile/types/nodes/isSpecialNode.ts +0 -6
  698. package/src/compile/types/nodes/isTextNode.ts +0 -6
  699. package/src/debug/printHtml.ts +0 -25
  700. package/src/types/ProxyPropData.ts +0 -11
  701. package/src/watch/removeEffect.ts +0 -34
  702. package/test/bench/components/temp/Bench-client-4e18421473e97bac7c24b17ba14751ce14dd187e.ts +0 -414
  703. package/test/bench/components/temp/Bench-server-4648921af9bc146718d55a7e9fc288b47a57dfda.ts +0 -142
  704. package/test/component/components/temp/Header-server-91088d2a5a543287bfdf1a24d92b66db6ccd294d.ts +0 -19
  705. package/test/console/components/temp/Console-server-7bc7f568e9c3626dca1bdafcb23186c2dbc59199.ts +0 -18
  706. package/test/dummy/components/temp/ProfilePreview-client-e57ca1ac502e0ddcb3ef376dd5ef27add70090d1.ts +0 -327
  707. package/test/dummy/components/temp/ProfilePreview-server-9d3d0f8b4f80f634db6ba97d037ab07de004b4d3.ts +0 -56
  708. package/test/html/components/temp/Html-server-4f73a2b0c5cd9b82666a99ec6a217c758d435008.ts +0 -18
  709. package/test/mount/components/temp/Mount-server-8564e4e0886ea754dfedf9a4a5fd82f0484c1d83.ts +0 -25
  710. package/test/on-mount/components/temp/OnMount-server-2ff035e067926fadc284030075aa5da69a05cf31.ts +0 -18
  711. package/test/party/components/temp/CssStyle-server-fa4bad3c82930632730e3b6b9f0e9193cab6f777.ts +0 -18
  712. package/test/party/components/temp/HelloWorld-server-50dd4393d55ecd33d5b7684c4f9ed41dfa0ceb5d.ts +0 -18
  713. package/test/party/components/temp/InputFocused-server-7b062b0dd7686ccc389c3c1a17f37e9a9bb19da9.ts +0 -26
  714. package/test/special-element/components/temp/Element-server-011a942cc147900d8e074c084297d8e81f05aa27.ts +0 -18
  715. package/test/special-head/components/temp/Head-client-967d6ea24d46308af586c7553f4658412d94716c.ts +0 -34
  716. package/test/special-head/components/temp/Head-server-7cf8212c95197ed6320b47483524d8b1b3e5ae68.ts +0 -18
  717. package/test/svg/components/temp/Shape-server-4ef7e80f09d3d4c930055d0a25184c48507e51de.ts +0 -25
  718. /package/src/compile/{build/utils → utils}/isFullyReactive.ts +0 -0
  719. /package/src/compile/{build/utils → utils}/isReactive.ts +0 -0
package/dist/compile.cjs DELETED
@@ -1,4083 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/compile.ts
21
- var compile_exports = {};
22
- __export(compile_exports, {
23
- build: () => build,
24
- buildType: () => buildType,
25
- parse: () => parse
26
- });
27
- module.exports = __toCommonJS(compile_exports);
28
-
29
- // src/compile/utils/Builder.ts
30
- var Builder = class {
31
- #text = "";
32
- #space = 0;
33
- prepend(text) {
34
- this.#text = text + "\n" + this.#text;
35
- }
36
- append(text) {
37
- text = text.trim();
38
- let i = 0;
39
- while (i < text.length) {
40
- while (text[i] === " " || text[i] === " ") {
41
- i++;
42
- }
43
- if (text[i] === ";") {
44
- i++;
45
- } else if (text[i] === "\n") {
46
- this.#text += "\n";
47
- } else {
48
- if (text[i] === "}" || text[i] === ")" || text[i] === "]") {
49
- this.#space -= 1;
50
- }
51
- this.#text += " ".repeat(Math.max(0, this.#space));
52
- const start = i;
53
- while (i < text.length && text[i] !== "\n") {
54
- if (text[i] === "`") {
55
- i++;
56
- let level = 0;
57
- while (i < text.length && !(text[i] === "`" && text[i - 1] !== "\\" && level === 0)) {
58
- if (text[i] === "{" && (level > 0 || text[i - 1] === "$")) {
59
- level += 1;
60
- } else if (text[i] === "}" && level > 0) {
61
- level -= 1;
62
- }
63
- i++;
64
- }
65
- }
66
- i++;
67
- }
68
- const line = text.substring(start, i + 1);
69
- if (line.startsWith("*")) {
70
- this.#text += " ";
71
- }
72
- this.#text += line;
73
- if (text[i - 1] === "{" || text[i - 1] === "(" || text[i - 1] === "[") {
74
- this.#space += 1;
75
- }
76
- }
77
- i++;
78
- }
79
- if (!this.#text.endsWith("\n\n")) {
80
- this.#text += "\n";
81
- }
82
- }
83
- toString() {
84
- return this.#text;
85
- }
86
- };
87
-
88
- // src/compile/types/comments.ts
89
- var ANCHOR_COMMENT = "<!>";
90
- var HYDRATION_START_COMMENT = "<![>";
91
- var HYDRATION_END_COMMENT = "<!]>";
92
- var HYDRATION_BREAK_COMMENT = "<!^>";
93
-
94
- // src/compile/utils/trimQuotes.ts
95
- function trimQuotes(text) {
96
- let start = 0;
97
- let end = text.length;
98
- while (text[start] === "'" && text[end - 1] === "'" || text[start] === '"' && text[end - 1] === '"' || text[start] === "`" && text[end - 1] === "`") {
99
- start += 1;
100
- end -= 1;
101
- }
102
- return text.substring(start, end);
103
- }
104
-
105
- // src/compile/build/utils/isReactive.ts
106
- function isReactive(text) {
107
- return text.includes("{") && text.includes("}");
108
- }
109
-
110
- // src/compile/build/client/buildFragmentText.ts
111
- function buildFragmentText(node, status, b) {
112
- const fragments = [];
113
- buildNodeFragmentText(node, status, fragments);
114
- if (fragments.length) {
115
- b.append(`const t_fragments: DocumentFragment[] = [];`);
116
- }
117
- }
118
- function buildNodeFragmentText(node, status, fragments, currentFragment) {
119
- switch (node.type) {
120
- case "root": {
121
- buildRootFragmentText(node, status, fragments);
122
- break;
123
- }
124
- case "control": {
125
- buildControlFragmentText(node, status, fragments, currentFragment);
126
- break;
127
- }
128
- case "component": {
129
- buildComponentFragmentText(node, status, fragments, currentFragment);
130
- break;
131
- }
132
- case "element": {
133
- let ns = node.tagName === "svg";
134
- if (ns) status.ns = true;
135
- buildElementFragmentText(node, status, fragments, currentFragment);
136
- if (ns) status.ns = false;
137
- break;
138
- }
139
- case "text": {
140
- const content = node.content;
141
- if (currentFragment) {
142
- currentFragment.text += isReactive(content) ? "#" : content;
143
- }
144
- break;
145
- }
146
- case "special": {
147
- buildSpecialFragmentText(node, status, fragments, currentFragment);
148
- break;
149
- }
150
- }
151
- }
152
- function buildRootFragmentText(node, status, fragments) {
153
- node.fragment = { number: fragments.length, text: "", ns: status.ns, events: [], animations: [] };
154
- fragments.push(node.fragment);
155
- for (let child of node.children) {
156
- buildNodeFragmentText(child, status, fragments, node.fragment);
157
- }
158
- }
159
- function buildControlFragmentText(node, status, fragments, currentFragment) {
160
- switch (node.operation) {
161
- case "@if group":
162
- case "@switch group":
163
- case "@for group":
164
- case "@await group":
165
- case "@replace group":
166
- case "@html group": {
167
- currentFragment.text += ANCHOR_COMMENT;
168
- for (let child of node.children) {
169
- buildNodeFragmentText(child, status, fragments, currentFragment);
170
- }
171
- break;
172
- }
173
- default: {
174
- node.fragment = {
175
- number: fragments.length,
176
- text: "",
177
- ns: status.ns,
178
- events: [],
179
- animations: []
180
- };
181
- fragments.push(node.fragment);
182
- for (let child of node.children) {
183
- buildNodeFragmentText(child, status, fragments, node.fragment);
184
- }
185
- break;
186
- }
187
- }
188
- }
189
- function buildComponentFragmentText(node, status, fragments, currentFragment) {
190
- currentFragment.text += ANCHOR_COMMENT;
191
- if (node.children.length) {
192
- node.fragment = {
193
- number: fragments.length,
194
- text: "",
195
- ns: status.ns,
196
- events: [],
197
- animations: []
198
- };
199
- fragments.push(node.fragment);
200
- for (let child of node.children) {
201
- buildNodeFragmentText(child, status, fragments, node.fragment);
202
- }
203
- }
204
- }
205
- function buildElementFragmentText(node, status, fragments, currentFragment) {
206
- let needsClass = node.scopeStyles;
207
- currentFragment.text += `<${node.tagName}`;
208
- let attributesText = node.attributes.filter((a) => !a.name.startsWith("on") && !a.name.includes(":")).map((a) => {
209
- if (a.value && isReactive(a.value) && !a.name.includes(":")) {
210
- if (a.name.startsWith("data-")) {
211
- return `${a.name}=""`;
212
- }
213
- } else if (a.name === "class" && node.scopeStyles) {
214
- needsClass = false;
215
- let value = a.value ? `"${trimQuotes(a.value)} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
216
- return `${a.name}=${value}`;
217
- } else {
218
- return `${a.name}${a.value != null ? `=${a.value}` : ""}`;
219
- }
220
- }).filter(Boolean).join(" ");
221
- if (attributesText) {
222
- currentFragment.text += " " + attributesText;
223
- }
224
- if (needsClass) {
225
- currentFragment.text += ` class="torp-${status.styleHash}"`;
226
- }
227
- currentFragment.text += ">";
228
- for (let child of node.children) {
229
- buildNodeFragmentText(child, status, fragments, currentFragment);
230
- }
231
- currentFragment.text += `</${node.tagName}>`;
232
- }
233
- function buildSpecialFragmentText(node, status, fragments, currentFragment) {
234
- switch (node.tagName) {
235
- case ":slot": {
236
- currentFragment.text += ANCHOR_COMMENT;
237
- for (let child of node.children) {
238
- buildNodeFragmentText(child, status, fragments, node.fragment);
239
- }
240
- break;
241
- }
242
- case ":fill": {
243
- node.fragment = {
244
- number: fragments.length,
245
- text: "",
246
- ns: status.ns,
247
- events: [],
248
- animations: []
249
- };
250
- fragments.push(node.fragment);
251
- for (let child of node.children) {
252
- buildNodeFragmentText(child, status, fragments, node.fragment);
253
- }
254
- break;
255
- }
256
- case ":element": {
257
- buildComponentFragmentText(node, status, fragments, currentFragment);
258
- break;
259
- }
260
- case ":component": {
261
- buildComponentFragmentText(node, status, fragments, currentFragment);
262
- break;
263
- }
264
- case ":head": {
265
- break;
266
- }
267
- default: {
268
- throw new Error(`Invalid special node: ${node.tagName}`);
269
- }
270
- }
271
- }
272
-
273
- // src/compile/types/nodes/isSpecialNode.ts
274
- function isSpecialNode(node) {
275
- return node.type === "special";
276
- }
277
-
278
- // src/compile/utils/trimMatched.ts
279
- function trimMatched(text, startChar, endChar) {
280
- let start = 0;
281
- let end = text.length;
282
- while (text[start] === startChar && text[end - 1] === endChar) {
283
- start += 1;
284
- end -= 1;
285
- }
286
- return text.substring(start, end);
287
- }
288
-
289
- // src/compile/build/utils/isFullyReactive.ts
290
- function isFullyReactive(text) {
291
- return text.trim().startsWith("{") && text.trim().endsWith("}");
292
- }
293
-
294
- // src/compile/build/utils/nextVarName.ts
295
- function nextVarName(name, status) {
296
- if (!status.varNames[name]) {
297
- status.varNames[name] = 1;
298
- }
299
- let varName = `t_${name}_${status.varNames[name]}`;
300
- status.varNames[name] += 1;
301
- return varName;
302
- }
303
-
304
- // src/compile/build/client/buildAddFragment.ts
305
- function buildAddFragment(node, status, b, parentName, anchorName) {
306
- if (node.fragment) {
307
- const fragment = node.fragment;
308
- const fragmentName = `t_fragment_${fragment.number}`;
309
- status.imports.add("t_add_fragment");
310
- let params = [fragmentName, parentName, anchorName];
311
- if (fragment.endVarName) {
312
- params.push(fragment.endVarName);
313
- }
314
- b.append(`t_add_fragment(${params.join(", ")});`);
315
- if (fragment.endVarName) {
316
- status.imports.add("t_next");
317
- b.append(`t_next(${fragment.endVarName});`);
318
- }
319
- }
320
- }
321
-
322
- // src/compile/parse/utils/isSpaceChar.ts
323
- function isSpaceChar(text, index) {
324
- let code = text.charCodeAt(index);
325
- return code === 32 || code >= 9 && code <= 13;
326
- }
327
-
328
- // src/compile/parse/utils/isSpace.ts
329
- function isSpace(text) {
330
- for (let i = 0; i < text.length; i++) {
331
- if (!isSpaceChar(text, i)) {
332
- return false;
333
- }
334
- }
335
- return true;
336
- }
337
-
338
- // src/compile/types/nodes/isControlNode.ts
339
- function isControlNode(node) {
340
- return node.type === "control";
341
- }
342
-
343
- // src/compile/types/nodes/isElementNode.ts
344
- function isElementNode(node) {
345
- return node.type === "element";
346
- }
347
-
348
- // src/compile/types/nodes/isTextNode.ts
349
- function isTextNode(node) {
350
- return node.type === "text";
351
- }
352
-
353
- // src/compile/build/utils/isReactiveAttribute.ts
354
- function isReactiveAttribute(name, value) {
355
- return isFullyReactive(name) || isReactive(value) || name.startsWith("on");
356
- }
357
-
358
- // src/compile/build/client/buildFragment.ts
359
- function buildFragment(node, status, b, parentName, anchorName) {
360
- if (node.fragment) {
361
- const fragment = node.fragment;
362
- const fragmentName = `t_fragment_${fragment.number}`;
363
- if (status.options?.useCreateElement) {
364
- let fragmentPath = { parent: null, type: "fragment", children: [] };
365
- let varPaths = /* @__PURE__ */ new Map();
366
- declareFragmentVars(
367
- node.fragment,
368
- node,
369
- fragmentPath,
370
- status,
371
- b,
372
- parentName,
373
- anchorName,
374
- varPaths,
375
- false,
376
- true
377
- );
378
- fragmentPath.children.length = 0;
379
- varPaths.clear();
380
- status.imports.add("t_frg");
381
- b.append(`const ${fragmentName} = t_frg([`);
382
- declareFragmentVars(
383
- node.fragment,
384
- node,
385
- fragmentPath,
386
- status,
387
- b,
388
- parentName,
389
- anchorName,
390
- varPaths,
391
- false,
392
- false
393
- );
394
- b.append(`]);`);
395
- } else {
396
- status.imports.add("t_fragment");
397
- const fragmentText = fragment.text.replaceAll("`", "\\`").replaceAll(/\s+/g, " ");
398
- b.append(
399
- `const ${fragmentName} = t_fragment($parent.ownerDocument!, t_fragments, ${fragment.number}, \`${fragmentText}\`${fragment.ns ? ", true" : ""});`
400
- );
401
- let fragmentPath = { parent: null, type: "fragment", children: [] };
402
- let varPaths = /* @__PURE__ */ new Map();
403
- maybeAddRootNodeDeclaration(node, fragment, fragmentName, status, b, varPaths);
404
- declareFragmentVars(
405
- node.fragment,
406
- node,
407
- fragmentPath,
408
- status,
409
- b,
410
- parentName,
411
- anchorName,
412
- varPaths,
413
- false,
414
- true
415
- );
416
- }
417
- }
418
- }
419
- function maybeAddRootNodeDeclaration(node, fragment, fragmentName, status, b, varPaths) {
420
- if (!node.children.length) return;
421
- let firstNode = node.children[0];
422
- let firstNodeIsLastNode = node.children.length === 1;
423
- if (isControlNode(firstNode) && firstNode.operation.endsWith(" group") || isElementNode(firstNode) && elementNodeNeedsDeclaration(firstNode, true, firstNodeIsLastNode) || isTextNode(firstNode) && textNodeNeedsDeclaration(firstNode, true, firstNodeIsLastNode)) {
424
- } else {
425
- status.imports.add("t_root");
426
- const rootName = `t_root_${fragment.number}`;
427
- const params = [fragmentName];
428
- if (firstNode.type === "text") {
429
- params.push("true");
430
- }
431
- const rootPath = `t_root(${params.join(", ")})`;
432
- b.append("// @ts-ignore");
433
- b.append(`const ${rootName} = ${rootPath};`);
434
- varPaths.set(`t_root(${fragmentName})`, rootName);
435
- printDebug(rootName, status, b);
436
- }
437
- }
438
- function declareFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, lastChild, declare) {
439
- switch (node.type) {
440
- case "root": {
441
- declareRootFragmentVars(
442
- fragment,
443
- node,
444
- path,
445
- status,
446
- b,
447
- parentName,
448
- anchorName,
449
- varPaths,
450
- declare
451
- );
452
- break;
453
- }
454
- case "control": {
455
- declareControlFragmentVars(
456
- fragment,
457
- node,
458
- path,
459
- status,
460
- b,
461
- parentName,
462
- anchorName,
463
- varPaths,
464
- declare
465
- );
466
- break;
467
- }
468
- case "component": {
469
- declareComponentFragmentVars(
470
- fragment,
471
- node,
472
- path,
473
- status,
474
- b,
475
- parentName,
476
- anchorName,
477
- varPaths,
478
- declare
479
- );
480
- break;
481
- }
482
- case "element": {
483
- declareElementFragmentVars(
484
- fragment,
485
- node,
486
- path,
487
- status,
488
- b,
489
- parentName,
490
- anchorName,
491
- varPaths,
492
- lastChild,
493
- declare
494
- );
495
- break;
496
- }
497
- case "text": {
498
- declareTextFragmentVars(
499
- fragment,
500
- node,
501
- path,
502
- status,
503
- b,
504
- varPaths,
505
- lastChild,
506
- declare
507
- );
508
- break;
509
- }
510
- case "special": {
511
- declareSpecialFragmentVars(
512
- fragment,
513
- node,
514
- path,
515
- status,
516
- b,
517
- parentName,
518
- anchorName,
519
- varPaths,
520
- lastChild,
521
- declare
522
- );
523
- break;
524
- }
525
- default: {
526
- throw new Error(`Invalid node type: ${node.type}`);
527
- }
528
- }
529
- }
530
- function declareRootFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare) {
531
- for (let [i, child] of node.children.entries()) {
532
- declareFragmentVars(
533
- fragment,
534
- child,
535
- path,
536
- status,
537
- b,
538
- parentName,
539
- anchorName,
540
- varPaths,
541
- i === node.children.length - 1,
542
- declare
543
- );
544
- }
545
- }
546
- function declareControlFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare) {
547
- switch (node.operation) {
548
- case "@if group":
549
- case "@switch group":
550
- case "@for group":
551
- case "@await group":
552
- case "@replace group":
553
- case "@html group": {
554
- const operation = node.operation.substring(1).replace(" group", "");
555
- declareParentAndAnchorFragmentVars(
556
- fragment,
557
- node,
558
- path,
559
- status,
560
- b,
561
- parentName,
562
- anchorName,
563
- varPaths,
564
- operation,
565
- declare
566
- );
567
- break;
568
- }
569
- default: {
570
- for (let [i, child] of node.children.entries()) {
571
- declareFragmentVars(
572
- fragment,
573
- child,
574
- path,
575
- status,
576
- b,
577
- parentName,
578
- anchorName,
579
- varPaths,
580
- i === node.children.length - 1,
581
- declare
582
- );
583
- }
584
- break;
585
- }
586
- }
587
- }
588
- function declareComponentFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare) {
589
- declareParentAndAnchorFragmentVars(
590
- fragment,
591
- node,
592
- path,
593
- status,
594
- b,
595
- parentName,
596
- anchorName,
597
- varPaths,
598
- "comp",
599
- declare
600
- );
601
- }
602
- function elementTypeName(node) {
603
- switch (node.tagName.toLowerCase()) {
604
- case "div":
605
- case "input":
606
- return `HTML${node.tagName.substring(0, 1).toUpperCase() + node.tagName.substring(1)}Element`;
607
- case "textarea":
608
- return "HTMLTextAreaElement";
609
- }
610
- return "HTMLElement";
611
- }
612
- function declareElementFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, lastChild, declare) {
613
- const tagName = node.tagName === ":element" ? "element" : node.tagName;
614
- let elementPath = { parent: path, type: tagName, children: [] };
615
- path.children.push(elementPath);
616
- const topLevel = !path.parent;
617
- const declareVariable = elementNodeNeedsDeclaration(node, topLevel, lastChild);
618
- if (declare) {
619
- if (declareVariable) {
620
- node.varName = nextVarName(tagName, status);
621
- if (topLevel) {
622
- fragment.endVarName = node.varName;
623
- }
624
- const varPath = getFragmentVarPath(fragment, status, node.varName, elementPath, varPaths);
625
- if (status.options?.useCreateElement) {
626
- b.append(`let ${node.varName};`);
627
- } else {
628
- if (node.tagName === ":element") {
629
- b.append(`let ${node.varName} = ${varPath} as ${elementTypeName(node)};`);
630
- } else {
631
- if (topLevel && lastChild) {
632
- b.append("// @ts-ignore");
633
- }
634
- b.append(`const ${node.varName} = ${varPath} as ${elementTypeName(node)};`);
635
- printDebug(node.varName, status, b);
636
- }
637
- }
638
- }
639
- }
640
- let childParentName = node.children.find((c) => !!c.parentName)?.parentName;
641
- if (!declare) {
642
- let attributes = node.attributes.filter((a) => !a.name.startsWith("on") && !a.name.includes(":")).map((a) => {
643
- if (a.value && isReactive(a.value)) {
644
- return `"${a.name}": "#"`;
645
- } else if (a.value) {
646
- return `"${a.name}": "${trimQuotes(a.value) || a.name}"`;
647
- } else {
648
- return `"${a.name}": true"`;
649
- }
650
- }).join(", ");
651
- status.imports.add("t_elm");
652
- if (declareVariable) {
653
- b.append(
654
- `(${childParentName ? `${childParentName} = ` : ""}${node.varName} = t_elm("${node.tagName}", {${attributes}}, [`
655
- );
656
- } else if (childParentName) {
657
- b.append(`(${childParentName} = t_elm("${node.tagName}", {${attributes}}, [`);
658
- } else {
659
- b.append(`t_elm("${node.tagName}", {${attributes}}, [`);
660
- }
661
- }
662
- for (let [i, child] of node.children.entries()) {
663
- declareFragmentVars(
664
- fragment,
665
- child,
666
- elementPath,
667
- status,
668
- b,
669
- parentName,
670
- anchorName,
671
- varPaths,
672
- i === node.children.length - 1,
673
- declare
674
- );
675
- }
676
- if (!declare) {
677
- if (declareVariable || childParentName) {
678
- b.append("])),");
679
- } else {
680
- b.append("]),");
681
- }
682
- }
683
- }
684
- function elementNodeNeedsDeclaration(node, topLevel, lastChild) {
685
- const hasReactiveAttribute = node.attributes.some(
686
- (a) => a.value && isReactiveAttribute(a.name, a.value)
687
- );
688
- const isDynamicElement = node.tagName === ":element" && node.attributes.find((a) => a.name === "self");
689
- return hasReactiveAttribute || isDynamicElement || topLevel && lastChild;
690
- }
691
- function declareTextFragmentVars(fragment, node, path, status, b, varPaths, lastChild, declare) {
692
- const lastType = path.children[path.children.length - 1]?.type;
693
- if (lastType === "text" || lastType === "space") {
694
- return;
695
- }
696
- let textPath = { parent: path, type: isSpace(node.content) ? "space" : "text", children: [] };
697
- path.children.push(textPath);
698
- const topLevel = !path.parent;
699
- const declareVariable = textNodeNeedsDeclaration(node, topLevel, lastChild);
700
- if (declare) {
701
- if (declareVariable) {
702
- node.varName = nextVarName("text", status);
703
- if (topLevel) {
704
- fragment.endVarName = node.varName;
705
- }
706
- const varPath = getFragmentVarPath(fragment, status, node.varName, textPath, varPaths);
707
- if (status.options?.useCreateElement) {
708
- b.append(`let ${node.varName};`);
709
- } else {
710
- if (topLevel && lastChild) {
711
- b.append("// @ts-ignore");
712
- }
713
- b.append(`const ${node.varName} = ${varPath};`);
714
- printDebug(node.varName, status, b);
715
- }
716
- }
717
- } else {
718
- status.imports.add("t_txt");
719
- if (declareVariable) {
720
- b.append(`(${node.varName} = t_txt(" ")),`);
721
- } else {
722
- b.append(`t_txt("${node.content}"),`);
723
- }
724
- }
725
- }
726
- function textNodeNeedsDeclaration(node, topLevel, lastChild) {
727
- return isReactive(node.content) || topLevel && lastChild;
728
- }
729
- function declareSpecialFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, lastChild, declare) {
730
- if (node.tagName === ":slot") {
731
- declareParentAndAnchorFragmentVars(
732
- fragment,
733
- node,
734
- path,
735
- status,
736
- b,
737
- parentName,
738
- anchorName,
739
- varPaths,
740
- "slot",
741
- declare
742
- );
743
- }
744
- switch (node.tagName) {
745
- case ":slot":
746
- case ":fill": {
747
- for (let [i, child] of node.children.entries()) {
748
- declareFragmentVars(
749
- fragment,
750
- child,
751
- path,
752
- status,
753
- b,
754
- parentName,
755
- anchorName,
756
- varPaths,
757
- i === node.children.length - 1,
758
- declare
759
- );
760
- }
761
- break;
762
- }
763
- case ":element": {
764
- declareElementFragmentVars(
765
- fragment,
766
- node,
767
- path,
768
- status,
769
- b,
770
- parentName,
771
- anchorName,
772
- varPaths,
773
- lastChild,
774
- declare
775
- );
776
- break;
777
- }
778
- case ":component": {
779
- declareComponentFragmentVars(
780
- fragment,
781
- node,
782
- path,
783
- status,
784
- b,
785
- parentName,
786
- anchorName,
787
- varPaths,
788
- declare
789
- );
790
- break;
791
- }
792
- case ":head": {
793
- break;
794
- }
795
- default: {
796
- throw new Error(`Invalid special node: ${node.tagName}`);
797
- }
798
- }
799
- }
800
- function declareParentAndAnchorFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, name, declare) {
801
- const topLevel = !path.parent;
802
- if (topLevel) {
803
- node.parentName = `t_fragment_${fragment.number}`;
804
- } else {
805
- const parentPath = path;
806
- const oldChildren = parentPath.children;
807
- parentPath.children = [];
808
- const parentVarPath = getFragmentVarPath(fragment, status, "?", parentPath, varPaths);
809
- parentPath.children = oldChildren;
810
- if (varPaths.has(parentVarPath)) {
811
- node.parentName = varPaths.get(parentVarPath);
812
- } else {
813
- if (declare) {
814
- node.parentName = nextVarName(`${name}_parent`, status);
815
- if (status.options?.useCreateElement) {
816
- b.append(`let ${node.parentName} as HTMLElement;`);
817
- } else {
818
- b.append(`const ${node.parentName} = ${parentVarPath} as HTMLElement;`);
819
- printDebug(node.parentName, status, b);
820
- }
821
- varPaths.set(parentVarPath, node.parentName);
822
- } else {
823
- }
824
- }
825
- }
826
- if (declare) {
827
- const anchorPath = { parent: path, type: "#", children: [] };
828
- path.children.push(anchorPath);
829
- node.varName = nextVarName(`${name}_anchor`, status);
830
- const anchorVarPath = getFragmentVarPath(fragment, status, node.varName, anchorPath, varPaths);
831
- if (status.options?.useCreateElement) {
832
- b.append(`let ${node.varName};`);
833
- } else {
834
- status.imports.add("t_anchor");
835
- b.append(`let ${node.varName} = t_anchor(${anchorVarPath}) as HTMLElement;`);
836
- printDebug(node.varName, status, b);
837
- }
838
- } else {
839
- status.imports.add("t_cmt");
840
- b.append(`(${node.varName} = t_cmt()),`);
841
- }
842
- buildNode(node, status, b, parentName, anchorName);
843
- node.handled = true;
844
- }
845
- function getFragmentVarPath(fragment, status, name, path, varPaths) {
846
- let node = path;
847
- while (node.parent) {
848
- node = node.parent;
849
- }
850
- let varName = `t_fragment_${fragment.number}`;
851
- let varPath = getFragmentVarPathPart(node, varName, status, true);
852
- for (let [existingPath, existingName] of varPaths) {
853
- if (varPath.includes(existingPath)) {
854
- varPath = varPath.replace(existingPath, existingName);
855
- }
856
- }
857
- if (name !== "?") {
858
- varPaths.set(varPath, name);
859
- varPaths.set(name, name);
860
- }
861
- while (varPath.includes("t_next(t_next(")) {
862
- status.imports.add("t_skip");
863
- const match = varPath.match(/(t_next\(){2,}/)[0];
864
- const count = match.length / "t_next(".length;
865
- const pos = varPath.indexOf("t_next(t_next(");
866
- const head = varPath.substring(0, pos);
867
- let level = 0;
868
- let end = 0;
869
- for (let i = pos + match.length; i < varPath.length; i++) {
870
- if (varPath[i] === "(") {
871
- level++;
872
- } else if (varPath[i] === ")") {
873
- if (level === 0) {
874
- end = i;
875
- break;
876
- } else {
877
- level--;
878
- }
879
- }
880
- }
881
- const tail = varPath.substring(end + count);
882
- const param = varPath.substring(pos + match.length, end);
883
- varPath = `${head}t_skip(${param}, ${count})${tail}`;
884
- }
885
- varPath = varPath.replaceAll("t_next_text", "t_next");
886
- return varPath;
887
- }
888
- function getFragmentVarPathPart(path, varPath, status, root = false) {
889
- if (root) {
890
- status.imports.add("t_root");
891
- varPath = `t_root(${varPath})`;
892
- } else {
893
- status.imports.add("t_child");
894
- varPath = `t_child(${varPath})`;
895
- }
896
- for (let [i, child] of path.children.entries()) {
897
- if (i > 0) {
898
- if (child.type === "text" || child.type === "space") {
899
- varPath = `t_next_text(${varPath}, true)`;
900
- } else {
901
- status.imports.add("t_next");
902
- varPath = `t_next(${varPath})`;
903
- }
904
- }
905
- if (i === path.children.length - 1 && child.children.length) {
906
- varPath = getFragmentVarPathPart(child, varPath, status);
907
- }
908
- }
909
- return varPath;
910
- }
911
- var debug = false;
912
- function printDebug(varName, status, b) {
913
- if (debug) {
914
- status.imports.add("t_print");
915
- b.append(`console.log("${varName}:", t_print(${varName}));`);
916
- }
917
- }
918
-
919
- // src/compile/build/client/replaceForVarNames.ts
920
- function replaceForVarNames(value, status) {
921
- for (let varName of status.forVarNames) {
922
- value = value.replaceAll(
923
- new RegExp(`(^|\\s|\\(|\\[|\\{)${varName}($|\\s|\\.|\\(|\\)|\\[|\\]|\\}|;)`, "g"),
924
- `$1t_item.data.${varName}$2`
925
- );
926
- }
927
- return value;
928
- }
929
-
930
- // src/compile/build/client/buildRun.ts
931
- function buildRun(functionName, functionBody, status, b) {
932
- functionBody = replaceForVarNames(functionBody, status);
933
- status.imports.add("$run");
934
- b.append(`$run(function ${functionName}() {`);
935
- b.append(functionBody);
936
- b.append("});");
937
- }
938
-
939
- // src/compile/build/client/buildComponentNode.ts
940
- function buildComponentNode(node, status, b, root = false) {
941
- b.append("");
942
- b.append("/* @component */");
943
- const componentHasProps = node.attributes.length || root;
944
- const propsName = componentHasProps ? nextVarName("props", status) : "undefined";
945
- if (componentHasProps) {
946
- status.imports.add("$watch");
947
- b.append(`const ${propsName}: any = $watch({});`);
948
- for (let { name, value } of node.attributes) {
949
- if (name === "self" && node.tagName === ":component") {
950
- } else if (name.startsWith("{") && name.endsWith("}")) {
951
- name = name.substring(1, name.length - 1);
952
- const propName = name.split(".").at(-1);
953
- buildRun("setProp", `${propsName}["${propName}"] = ${name};`, status, b);
954
- } else if (name.startsWith("&") && value != null && isFullyReactive(value)) {
955
- name = name.substring(1);
956
- value = value.substring(1, value.length - 1);
957
- buildRun("setProp", `${propsName}["${name}"] = ${value};`, status, b);
958
- buildRun("setBinding", `${value} = ${propsName}["${name}"];`, status, b);
959
- } else if ((name === "class" || name === ":class") && value != null) {
960
- status.imports.add("t_class");
961
- if (isFullyReactive(value)) {
962
- value = value.substring(1, value.length - 1);
963
- }
964
- const params = [value];
965
- if (node.scopeStyles) {
966
- params.push(`"torp-${status.styleHash}"`);
967
- }
968
- buildRun("setClasses", `${propsName}["class"] = t_class(${params.join(", ")});`, status, b);
969
- } else if ((name === "style" || name === ":style") && value != null) {
970
- status.imports.add("t_style");
971
- if (isFullyReactive(value)) {
972
- value = value.substring(1, value.length - 1);
973
- }
974
- buildRun("setStyles", `${propsName}["style"] = t_style(${value});`, status, b);
975
- } else if (value != null) {
976
- let fullyReactive = isFullyReactive(value);
977
- let partlyReactive = isReactive(value);
978
- if (fullyReactive) {
979
- value = value.substring(1, value.length - 1);
980
- } else if (partlyReactive) {
981
- value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
982
- }
983
- const setProp = `${propsName}["${name}"] = ${value};`;
984
- if (fullyReactive || partlyReactive) {
985
- buildRun("setProp", setProp, status, b);
986
- } else {
987
- b.append(setProp);
988
- }
989
- } else {
990
- b.append(`${propsName}["${name}"] = true;`);
991
- }
992
- }
993
- if (root) {
994
- status.imports.add("$run");
995
- b.append(`
996
- if ($props) {
997
- const propNames = [${status.props.map((p) => `'${p}'`).join(", ")}];
998
- for (let name of Object.keys($props)) {
999
- if (!name.startsWith("$") && !propNames.includes(name)) {
1000
- $run(() => ${propsName}[name] = $props[name]);
1001
- }
1002
- }
1003
- }`);
1004
- }
1005
- }
1006
- const componentHasSlots = node.children.length;
1007
- const slotsName = componentHasSlots ? nextVarName("slots", status) : "undefined";
1008
- if (componentHasSlots) {
1009
- b.append(`const ${slotsName}: Record<string, SlotRender> = {};`);
1010
- for (let slot of node.children) {
1011
- if (isSpecialNode(slot)) {
1012
- const nameAttribute = slot.attributes.find((a) => a.name === "name");
1013
- const slotName = nameAttribute?.value ? trimQuotes(nameAttribute.value) : "_";
1014
- const slotParams = [
1015
- "$sparent: ParentNode",
1016
- "$sanchor: Node | null",
1017
- "//@ts-ignore\n$sprops?: Record<PropertyKey, any>",
1018
- "//@ts-ignore\n$context?: Record<PropertyKey, any>"
1019
- ];
1020
- b.append(`${slotsName}["${slotName}"] = (
1021
- ${slotParams.join(",\n")}
1022
- ) => {`);
1023
- buildFragment(slot, status, b, "$sparent", "$sanchor");
1024
- status.fragmentStack.push({
1025
- fragment: slot.fragment,
1026
- path: ""
1027
- });
1028
- for (let child of slot.children) {
1029
- buildNode(child, status, b, "$sparent", "$sanchor");
1030
- }
1031
- status.fragmentStack.pop();
1032
- buildAddFragment(slot, status, b, "$sparent", "$sanchor");
1033
- b.append(`}`);
1034
- }
1035
- }
1036
- }
1037
- const compParentName = node.parentName;
1038
- const compAnchorName = node.varName;
1039
- let renderParams = `${compParentName}, ${compAnchorName}, ${propsName}, $context`;
1040
- if (slotsName !== "undefined") {
1041
- renderParams += `, ${slotsName}`;
1042
- }
1043
- let componentName = node.tagName;
1044
- if (componentName === ":component") {
1045
- let selfAttribute = node.attributes.find((a) => a.name === "self");
1046
- if (selfAttribute && selfAttribute.value) {
1047
- componentName = trimMatched(selfAttribute.value, "{", "}");
1048
- }
1049
- }
1050
- b.append(`${componentName}(${renderParams});`);
1051
- b.append("");
1052
- }
1053
-
1054
- // src/compile/build/client/buildAwaitNode.ts
1055
- function buildAwaitNode(node, status, b) {
1056
- const awaitParentName = node.parentName;
1057
- const awaitAnchorName = node.varName;
1058
- const awaitRangeName = nextVarName("await_range", status);
1059
- const awaitTokenName = nextVarName("await_token", status);
1060
- const oldRangeName = nextVarName("old_range", status);
1061
- const branches = node.children.filter((n) => isControlNode(n));
1062
- let awaitBranch = branches.find((n) => n.operation === "@await");
1063
- if (!awaitBranch) {
1064
- }
1065
- let thenBranch = branches.find((n) => n.operation === "@then");
1066
- if (!thenBranch) {
1067
- thenBranch = {
1068
- type: "control",
1069
- operation: "@then",
1070
- statement: "then",
1071
- children: []
1072
- };
1073
- }
1074
- let catchBranch = branches.find((n) => n.operation === "@catch");
1075
- if (!catchBranch) {
1076
- catchBranch = {
1077
- type: "control",
1078
- operation: "@catch",
1079
- statement: "catch",
1080
- children: []
1081
- };
1082
- }
1083
- const awaiterName = trimMatched(awaitBranch.statement.substring("await".length).trim(), "(", ")");
1084
- const thenVar = trimMatched(thenBranch.statement.substring("then".length).trim(), "(", ")");
1085
- const catchVar = trimMatched(catchBranch.statement.substring("catch".length).trim(), "(", ")");
1086
- status.imports.add("t_range");
1087
- status.imports.add("t_run_control");
1088
- b.append("");
1089
- b.append(`
1090
- /* @await */
1091
- const ${awaitRangeName} = t_range();
1092
- ${awaitRangeName}.index = -1;
1093
- let ${awaitTokenName} = 0;
1094
- t_run_control(${awaitRangeName}, ${awaitAnchorName}, (t_before) => {
1095
- ${awaitTokenName}++;`);
1096
- buildAwaitBranch(awaitBranch, status, b, awaitParentName, awaitRangeName, 0);
1097
- status.imports.add("t_push_range");
1098
- status.imports.add("t_pop_range");
1099
- b.append(`
1100
- ((token) => {
1101
- ${awaiterName}
1102
- .then((${thenVar}) => {
1103
- if (token === ${awaitTokenName}) {
1104
- let ${oldRangeName} = t_push_range(${awaitRangeName});`);
1105
- buildAwaitBranch(thenBranch, status, b, awaitParentName, awaitRangeName, 1);
1106
- b.append(`t_pop_range(${oldRangeName});
1107
- }
1108
- })
1109
- .catch((${catchVar}) => {
1110
- if (token === ${awaitTokenName}) {
1111
- let ${oldRangeName} = t_push_range(${awaitRangeName});`);
1112
- buildAwaitBranch(catchBranch, status, b, awaitParentName, awaitRangeName, 2);
1113
- b.append(`t_pop_range(${oldRangeName});
1114
- }
1115
- });
1116
- })(${awaitTokenName});
1117
- });`);
1118
- b.append("");
1119
- }
1120
- function buildAwaitBranch(node, status, b, parentName, rangeName, index) {
1121
- status.imports.add("t_run_branch");
1122
- b.append(`t_run_branch(${rangeName}, ${index}, () => {`);
1123
- buildFragment(node, status, b, parentName, "t_before");
1124
- status.fragmentStack.push({
1125
- fragment: node.fragment,
1126
- path: ""
1127
- });
1128
- for (let child of node.children) {
1129
- buildNode(child, status, b, parentName, "t_before");
1130
- }
1131
- status.fragmentStack.pop();
1132
- buildAddFragment(node, status, b, parentName, "t_before");
1133
- b.append(`});`);
1134
- }
1135
-
1136
- // src/compile/utils/trimEnd.ts
1137
- function trimEnd(text, char) {
1138
- let end = text.length;
1139
- while (text[end - 1] === char) {
1140
- end -= 1;
1141
- }
1142
- return text.substring(0, end);
1143
- }
1144
-
1145
- // src/compile/build/client/buildForNode.ts
1146
- var forLoopRegex = /for\s*\((.+?);.*?;.*?\)/;
1147
- var forLoopVarsRegex = /(?:let\s+|var\s+){0,1}([^\s,;+=]+)(?:\s*=\s*[^,;]+){0,1}/g;
1148
- var forOfRegex = /for\s*\(\s*(?:let\s*|var\s*){0,1}(.+?)\s+(?:of|in).*?\)/;
1149
- function buildForNode(node, status, b) {
1150
- const forParentName = node.parentName;
1151
- const forAnchorName = node.varName;
1152
- node = node.children[0];
1153
- const forVarNames = [];
1154
- const forIndexMatch = node.statement.match(forLoopRegex);
1155
- if (forIndexMatch) {
1156
- const forVarMatches = forIndexMatch[1].matchAll(forLoopVarsRegex);
1157
- for (let match of forVarMatches) {
1158
- forVarNames.push(match[1]);
1159
- }
1160
- } else {
1161
- const forOfMatch = node.statement.match(forOfRegex);
1162
- if (forOfMatch) {
1163
- const match = forOfMatch[1];
1164
- if (match.startsWith("{") && match.endsWith("}") || match.startsWith("[") && match.endsWith("]")) {
1165
- forVarNames.push(
1166
- ...trimMatched(trimMatched(match, "{", "}"), "[", "]").split(",").map((m) => m.trim())
1167
- );
1168
- } else {
1169
- forVarNames.push(match);
1170
- }
1171
- }
1172
- }
1173
- const forRangeName = nextVarName("for_range", status);
1174
- const key = node.children.find(
1175
- (n) => n.type === "control" && n.operation === "@key"
1176
- );
1177
- let keyStatement = key ? key.statement : "";
1178
- if (keyStatement) {
1179
- keyStatement = trimEnd(keyStatement.substring(keyStatement.indexOf("=") + 1).trim(), ";");
1180
- }
1181
- status.imports.add("t_range");
1182
- status.imports.add("t_run_list");
1183
- status.imports.add("t_list_item");
1184
- status.imports.add("ListItem");
1185
- b.append("");
1186
- b.append(`
1187
- /* @for */
1188
- let ${forRangeName} = t_range();
1189
- t_run_list(
1190
- ${forRangeName},
1191
- ${forParentName},
1192
- ${forAnchorName},
1193
- function createNewItems() {
1194
- let t_new_items: ListItem[] = [];
1195
- ${node.statement} {
1196
- t_new_items.push(t_list_item({ ${forVarNames.join(",\n")} }${keyStatement ? `, ${keyStatement}` : ""}));
1197
- /*t_new_items.push({
1198
- ${keyStatement ? `key: ${keyStatement},` : ";"}
1199
- data: { ${forVarNames.join(",\n")} }
1200
- });*/
1201
- }
1202
- return t_new_items;
1203
- },
1204
- function createListItem(t_item, t_before) {`);
1205
- status.forVarNames = forVarNames;
1206
- buildForItem(node, status, b, forParentName);
1207
- status.forVarNames = [];
1208
- b.append(`}`);
1209
- b.append(`);`);
1210
- b.append("");
1211
- }
1212
- function buildForItem(node, status, b, parentName) {
1213
- const oldRangeName = nextVarName("old_range", status);
1214
- status.imports.add("t_push_range");
1215
- b.append(`let ${oldRangeName} = t_push_range(t_item, true);`);
1216
- buildFragment(node, status, b, parentName, "t_before");
1217
- status.fragmentStack.push({
1218
- fragment: node.fragment,
1219
- path: ""
1220
- });
1221
- for (let child of node.children) {
1222
- if (isControlNode(child) && child.operation === "@key") {
1223
- continue;
1224
- }
1225
- buildNode(child, status, b, parentName, "t_before");
1226
- }
1227
- status.fragmentStack.pop();
1228
- buildAddFragment(node, status, b, parentName, "t_before");
1229
- status.imports.add("t_pop_range");
1230
- b.append(`t_pop_range(${oldRangeName});`);
1231
- }
1232
-
1233
- // src/compile/build/client/buildHtmlNode.ts
1234
- function buildHtmlNode(node, status, b) {
1235
- const htmlAnchorName = node.varName;
1236
- const htmlParentName = node.parentName || htmlAnchorName + ".parentNode";
1237
- const htmlRangeName = nextVarName("html_range", status);
1238
- node = node.children[0];
1239
- status.imports.add("t_range");
1240
- status.imports.add("t_run_control");
1241
- b.append("");
1242
- b.append(`
1243
- /* @html */
1244
- const ${htmlRangeName} = t_range();
1245
- t_run_control(${htmlRangeName}, ${htmlAnchorName}, (t_before) => {`);
1246
- buildHtmlBranch(node, status, b, htmlParentName, htmlRangeName);
1247
- b.append("});");
1248
- b.append("");
1249
- }
1250
- function buildHtmlBranch(node, status, b, parentName, rangeName) {
1251
- status.imports.add("t_run_branch");
1252
- b.append(`${node.statement};`);
1253
- b.append(`t_run_branch(${rangeName}, -1, () => {`);
1254
- const templateName = nextVarName("template", status);
1255
- const fragmentName = `t_fragment_${node.fragment.number}`;
1256
- b.append(`const ${templateName} = document.createElement("template");`);
1257
- b.append(`${templateName}.innerHTML = ${node.statement};`);
1258
- b.append(`let ${fragmentName} = ${templateName}.content.cloneNode(true) as DocumentFragment;`);
1259
- buildAddFragment(node, status, b, parentName, "t_before");
1260
- b.append(`});`);
1261
- }
1262
-
1263
- // src/compile/build/client/buildIfNode.ts
1264
- function buildIfNode(node, status, b) {
1265
- const ifAnchorName = node.varName;
1266
- const ifParentName = node.parentName || ifAnchorName + ".parentNode";
1267
- const ifRangeName = nextVarName("if_range", status);
1268
- const branches = node.children.filter((n) => isControlNode(n));
1269
- if (branches.findIndex((n) => n.operation === "@else") === -1) {
1270
- const elseBranch = {
1271
- type: "control",
1272
- operation: "@else",
1273
- statement: "else",
1274
- children: []
1275
- };
1276
- branches.push(elseBranch);
1277
- }
1278
- status.imports.add("t_range");
1279
- status.imports.add("t_run_control");
1280
- b.append("");
1281
- b.append(`
1282
- /* @if */
1283
- const ${ifRangeName} = t_range();
1284
- t_run_control(${ifRangeName}, ${ifAnchorName}, (t_before) => {`);
1285
- for (let [i, branch] of branches.entries()) {
1286
- buildIfBranch(branch, status, b, ifParentName, ifRangeName, i);
1287
- }
1288
- b.append("});");
1289
- b.append("");
1290
- }
1291
- function buildIfBranch(node, status, b, parentName, rangeName, index) {
1292
- status.imports.add("t_run_branch");
1293
- b.append(`${replaceForVarNames(node.statement, status)} {`);
1294
- b.append(`t_run_branch(${rangeName}, ${index}, () => {`);
1295
- buildFragment(node, status, b, parentName, "t_before");
1296
- status.fragmentStack.push({
1297
- fragment: node.fragment,
1298
- path: ""
1299
- });
1300
- for (let child of node.children) {
1301
- buildNode(child, status, b, parentName, "t_before");
1302
- }
1303
- status.fragmentStack.pop();
1304
- buildAddFragment(node, status, b, parentName, "t_before");
1305
- b.append(`});`);
1306
- b.append(`}`);
1307
- }
1308
-
1309
- // src/compile/build/client/buildReplaceNode.ts
1310
- function buildReplaceNode(node, status, b) {
1311
- const replaceAnchorName = node.varName;
1312
- const replaceParentName = node.parentName || replaceAnchorName + ".parentNode";
1313
- const replaceRangeName = nextVarName("replace_range", status);
1314
- node = node.children[0];
1315
- status.imports.add("t_range");
1316
- status.imports.add("t_run_control");
1317
- b.append("");
1318
- b.append(`
1319
- /* @replace */
1320
- const ${replaceRangeName} = t_range();
1321
- t_run_control(${replaceRangeName}, ${replaceAnchorName}, (t_before) => {`);
1322
- buildReplaceBranch(node, status, b, replaceParentName, replaceRangeName);
1323
- b.append("});");
1324
- b.append("");
1325
- }
1326
- function buildReplaceBranch(node, status, b, parentName, rangeName) {
1327
- status.imports.add("t_run_branch");
1328
- b.append(`${replaceForVarNames(node.statement, status)};`);
1329
- b.append(`t_run_branch(${rangeName}, -1, () => {`);
1330
- buildFragment(node, status, b, parentName, "t_before");
1331
- status.fragmentStack.push({
1332
- fragment: node.fragment,
1333
- path: ""
1334
- });
1335
- for (let child of node.children) {
1336
- buildNode(child, status, b, parentName, "t_before");
1337
- }
1338
- status.fragmentStack.pop();
1339
- buildAddFragment(node, status, b, parentName, "t_before");
1340
- b.append(`});`);
1341
- }
1342
-
1343
- // src/compile/build/client/buildScriptNode.ts
1344
- function buildScriptNode(node, b) {
1345
- b.append(`/* ${node.operation} */`);
1346
- b.append(`${maybeAppend(node.statement, ";")}`);
1347
- }
1348
- function maybeAppend(text, end) {
1349
- if (!text.endsWith(end)) {
1350
- text += end;
1351
- }
1352
- return text;
1353
- }
1354
-
1355
- // src/compile/build/client/buildSwitchNode.ts
1356
- function buildSwitchNode(node, status, b) {
1357
- const switchParentName = node.parentName;
1358
- const switchAnchorName = node.varName;
1359
- const switchRangeName = nextVarName("switch_range", status);
1360
- const branches = node.children.filter((n) => isControlNode(n));
1361
- if (branches.findIndex((n) => n.operation === "@default") === -1) {
1362
- const defaultBranch = {
1363
- type: "control",
1364
- operation: "@default",
1365
- statement: "default",
1366
- children: []
1367
- };
1368
- branches.push(defaultBranch);
1369
- }
1370
- status.imports.add("t_range");
1371
- status.imports.add("t_run_control");
1372
- b.append("");
1373
- b.append(`
1374
- /* @switch */
1375
- const ${switchRangeName} = t_range();
1376
- t_run_control(${switchRangeName}, ${switchAnchorName}, (t_before) => {
1377
- ${node.statement} {`);
1378
- for (let [i, branch] of branches.entries()) {
1379
- buildSwitchBranch(branch, status, b, switchParentName, switchRangeName, i);
1380
- }
1381
- b.append(`}
1382
- });`);
1383
- b.append("");
1384
- }
1385
- function buildSwitchBranch(node, status, b, parentName, rangeName, index) {
1386
- status.imports.add("t_run_branch");
1387
- b.append(`${replaceForVarNames(node.statement, status)} {`);
1388
- b.append(`t_run_branch(${rangeName}, ${index}, () => {`);
1389
- buildFragment(node, status, b, parentName, "t_before");
1390
- status.fragmentStack.push({
1391
- fragment: node.fragment,
1392
- path: ""
1393
- });
1394
- for (let child of node.children) {
1395
- buildNode(child, status, b, parentName, "t_before");
1396
- }
1397
- status.fragmentStack.pop();
1398
- buildAddFragment(node, status, b, parentName, "t_before");
1399
- b.append(`});`);
1400
- b.append(`break;`);
1401
- b.append(`}`);
1402
- }
1403
-
1404
- // src/compile/build/client/buildControlNode.ts
1405
- function buildControlNode(node, status, b) {
1406
- switch (node.operation) {
1407
- case "@if group": {
1408
- buildIfNode(node, status, b);
1409
- break;
1410
- }
1411
- case "@if":
1412
- case "@else if":
1413
- case "@else": {
1414
- break;
1415
- }
1416
- case "@switch group": {
1417
- buildSwitchNode(node, status, b);
1418
- break;
1419
- }
1420
- case "@case":
1421
- case "@default": {
1422
- break;
1423
- }
1424
- case "@for group": {
1425
- buildForNode(node, status, b);
1426
- break;
1427
- }
1428
- case "@for":
1429
- case "@key": {
1430
- break;
1431
- }
1432
- case "@await group": {
1433
- buildAwaitNode(node, status, b);
1434
- break;
1435
- }
1436
- case "@await":
1437
- case "@then":
1438
- case "@catch": {
1439
- break;
1440
- }
1441
- case "@replace group": {
1442
- buildReplaceNode(node, status, b);
1443
- break;
1444
- }
1445
- case "@replace": {
1446
- break;
1447
- }
1448
- case "@html group": {
1449
- buildHtmlNode(node, status, b);
1450
- break;
1451
- }
1452
- case "@html": {
1453
- break;
1454
- }
1455
- case "@const":
1456
- case "@console":
1457
- case "@debugger": {
1458
- buildScriptNode(node, b);
1459
- break;
1460
- }
1461
- case "@function":
1462
- case "@async function": {
1463
- b.append("");
1464
- buildScriptNode(node, b);
1465
- b.append("");
1466
- break;
1467
- }
1468
- default: {
1469
- throw new Error(`Invalid operation: ${node.operation}`);
1470
- }
1471
- }
1472
- }
1473
-
1474
- // src/compile/build/client/buildMount.ts
1475
- function buildMount(functionName, functionBody, status, b) {
1476
- functionBody = replaceForVarNames(functionBody, status);
1477
- status.imports.add("$mount");
1478
- b.append(`$mount(function ${functionName}() {`);
1479
- b.append(functionBody);
1480
- b.append("});");
1481
- }
1482
-
1483
- // src/compile/build/client/buildElementNode.ts
1484
- function buildElementNode(node, status, b, parentName, root = false) {
1485
- if (status.inHead) {
1486
- if (node.tagName === "title") {
1487
- buildTitleNode(node, status, b);
1488
- return;
1489
- } else {
1490
- buildHeadNode(node, status, b);
1491
- return;
1492
- }
1493
- }
1494
- const varName = node.varName;
1495
- if (varName) {
1496
- if (node.tagName === ":element") {
1497
- buildDynamicElementNode(node, status, b);
1498
- }
1499
- if (root) {
1500
- }
1501
- buildElementAttributes(node, varName, status, b);
1502
- }
1503
- const oldPreserveWhitespace = status.preserveWhitespace;
1504
- status.preserveWhitespace = ["code", "pre"].includes(node.tagName);
1505
- for (let child of node.children) {
1506
- buildNode(child, status, b, parentName, "null");
1507
- }
1508
- status.preserveWhitespace = oldPreserveWhitespace;
1509
- }
1510
- function buildDynamicElementNode(node, status, b) {
1511
- let selfAttribute = node.attributes.find((a) => a.name === "self");
1512
- if (selfAttribute && selfAttribute.value) {
1513
- status.imports.add("$run");
1514
- status.imports.add("t_dynamic");
1515
- let selfValue = trimMatched(selfAttribute.value, "{", "}");
1516
- b.append(`$run(function setDynamic() {`);
1517
- b.append(`${node.varName} = t_dynamic(${node.varName}, ${selfValue});`);
1518
- let parentName = node.varName;
1519
- buildFragment(node, status, b, parentName, "null");
1520
- status.fragmentStack.push({
1521
- fragment: node.fragment,
1522
- path: ""
1523
- });
1524
- for (let child of node.children) {
1525
- buildNode(child, status, b, parentName, "null");
1526
- }
1527
- status.fragmentStack.pop();
1528
- buildAddFragment(node, status, b, parentName, "null");
1529
- b.append(`});`);
1530
- }
1531
- }
1532
- function buildTitleNode(node, status, b) {
1533
- let content = node.children[0].content || "";
1534
- content = content.replace(/\s+/g, " ");
1535
- let reactiveStarted = false;
1536
- let reactiveCount = 0;
1537
- for (let i = 0; i < content.length; i++) {
1538
- if (content[i] === "{") {
1539
- reactiveStarted = true;
1540
- } else if (content[i] === "}") {
1541
- if (reactiveStarted) {
1542
- reactiveCount += 1;
1543
- reactiveStarted = false;
1544
- }
1545
- }
1546
- }
1547
- if (reactiveCount) {
1548
- status.imports.add("t_fmt");
1549
- if (reactiveCount === 1 && content.startsWith("{") && content.endsWith("}")) {
1550
- content = `t_fmt(${content.substring(1, content.length - 1)})`;
1551
- } else {
1552
- content = `\`${content.replaceAll("{", "${t_fmt(").replaceAll("}", ")}")}\``;
1553
- }
1554
- } else {
1555
- content = `"${content}"`;
1556
- }
1557
- status.imports.add("$run");
1558
- b.append(`
1559
- $run(function runTitle() {
1560
- const t_old_title = document.title;
1561
- document.title = ${content};
1562
- return () => document.title = t_old_title;
1563
- });`);
1564
- }
1565
- function buildHeadNode(node, status, b) {
1566
- status.imports.add("$run");
1567
- b.append(`
1568
- $run(function runHead() {
1569
- const t_headel = document.createElement("${node.tagName}");
1570
- document.getElementsByTagName("head")[0].appendChild(t_headel);`);
1571
- for (let { name, value } of node.attributes) {
1572
- if (name.startsWith("{") && name.endsWith("}")) {
1573
- name = name.substring(1, name.length - 1);
1574
- const propName = name.split(".").at(-1);
1575
- buildRun("setAttribute", `t_headel.setAttribute("${propName}", ${name});`, status, b);
1576
- } else if (value != null && isReactive(value)) {
1577
- if (isFullyReactive(value)) {
1578
- value = value.substring(1, value.length - 1);
1579
- } else {
1580
- value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
1581
- }
1582
- status.imports.add("t_attribute");
1583
- buildRun("setAttribute", `t_attribute(t_headel, "${name}", ${value});`, status, b);
1584
- } else if (value != null) {
1585
- status.imports.add("t_attribute");
1586
- b.append(`t_attribute(t_headel, "${name}", ${value});`);
1587
- }
1588
- }
1589
- b.append(`
1590
- });`);
1591
- }
1592
- function buildElementAttributes(node, varName, status, b) {
1593
- const refAttribute = node.attributes.find((a) => a.name === "&ref");
1594
- if (refAttribute) {
1595
- let value = refAttribute.value;
1596
- if (value != null && isFullyReactive(value)) {
1597
- value = value.substring(1, value.length - 1);
1598
- b.append(`${value} = ${varName};`);
1599
- }
1600
- }
1601
- for (let { name, value } of node.attributes) {
1602
- if (name === "self" && node.tagName === ":element") {
1603
- } else if (name === "&ref") {
1604
- } else if (name.startsWith("{") && name.endsWith("}")) {
1605
- name = name.substring(1, name.length - 1);
1606
- const propName = name.split(".").at(-1);
1607
- buildRun("setAttribute", `${varName}.setAttribute("${propName}", ${name});`, status, b);
1608
- } else if (value != null && isReactive(value)) {
1609
- if (isFullyReactive(value)) {
1610
- value = value.substring(1, value.length - 1);
1611
- } else {
1612
- value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
1613
- }
1614
- if (name === "&group") {
1615
- buildBindGroupAttribute(node, varName, value, status, b);
1616
- } else if (name === "&value" || name === "&checked") {
1617
- buildBindAttribute(node, varName, name, value, status, b);
1618
- } else if (name === ":onmount") {
1619
- buildMount("elMount", `return (${trimEnd(value.trim(), ";")})(${varName});`, status, b);
1620
- } else if (name.startsWith("on")) {
1621
- buildEventAttribute(varName, name, value, status, b);
1622
- } else if (name.startsWith(":transition")) {
1623
- buildTransitionAttribute(node, varName, name, value, status, b);
1624
- } else if (name === "class" || name === ":class") {
1625
- status.imports.add("t_class");
1626
- const params = [value];
1627
- if (node.scopeStyles) {
1628
- params.push(`"torp-${status.styleHash}"`);
1629
- }
1630
- buildRun("setClasses", `${varName}.className = t_class(${params.join(", ")});`, status, b);
1631
- } else if (name === ":style") {
1632
- status.imports.add("t_style");
1633
- buildRun("setStyles", `${varName}.setAttribute("style", t_style(${value}));`, status, b);
1634
- } else if (name.includes("-")) {
1635
- status.imports.add("t_attribute");
1636
- buildRun("setDataAttribute", `t_attribute(${varName}, "${name}", ${value});`, status, b);
1637
- } else {
1638
- status.imports.add("t_attribute");
1639
- buildRun("setAttribute", `t_attribute(${varName}, "${name}", ${value});`, status, b);
1640
- }
1641
- }
1642
- }
1643
- }
1644
- function buildBindGroupAttribute(node, varName, value, status, b) {
1645
- value = replaceForVarNames(value, status);
1646
- let eventName = "change";
1647
- let inputValue = node.attributes.find((a) => a.name === "value")?.value;
1648
- let set = `${value} == ${inputValue}`;
1649
- let propName = "checked";
1650
- const setAttribute = `${varName}.${propName} = ${set}`;
1651
- buildRun("setBinding", `${setAttribute};`, status, b);
1652
- status.imports.add("t_event");
1653
- b.append(`t_event(${varName}, "${eventName}", (e) => {
1654
- if (e.target.${propName}) ${value} = ${inputValue};
1655
- });`);
1656
- }
1657
- function buildBindAttribute(node, varName, name, value, status, b) {
1658
- value = replaceForVarNames(value, status);
1659
- let eventName = "input";
1660
- let defaultValue = '""';
1661
- let inputValue = "e.target.value";
1662
- if (node.tagName === "input") {
1663
- let typeAttribute = node.attributes.find((a) => a.name === "type");
1664
- if (typeAttribute && typeAttribute.value) {
1665
- switch (trimQuotes(typeAttribute.value)) {
1666
- case "number": {
1667
- defaultValue = "0";
1668
- inputValue = "Number(e.target.value)";
1669
- break;
1670
- }
1671
- case "checkbox": {
1672
- defaultValue = "false";
1673
- inputValue = "e.target.checked";
1674
- break;
1675
- }
1676
- case "radio": {
1677
- eventName = "change";
1678
- inputValue = "e.target.value";
1679
- break;
1680
- }
1681
- }
1682
- }
1683
- } else if (node.tagName === "select") {
1684
- eventName = "change";
1685
- }
1686
- let set = `${value} || ${defaultValue}`;
1687
- const propName = name.substring(1);
1688
- const setAttribute = `${varName}.${propName} = ${set}`;
1689
- buildRun("setBinding", `${setAttribute};`, status, b);
1690
- status.imports.add("t_event");
1691
- b.append(`t_event(${varName}, "${eventName}", (e) => ${value} = ${inputValue});`);
1692
- }
1693
- function buildEventAttribute(varName, name, value, status, b) {
1694
- value = replaceForVarNames(value, status);
1695
- const eventName = name.substring(2);
1696
- status.imports.add("t_event");
1697
- b.append(`t_event(${varName}, "${eventName}", ${value});`);
1698
- }
1699
- function buildTransitionAttribute(node, varName, name, value, status, b) {
1700
- value = replaceForVarNames(value, status);
1701
- status.imports.add("t_animate");
1702
- let entryVarName = nextVarName("trans_in", status);
1703
- let exitVarName = nextVarName("trans_out", status);
1704
- if (name === ":transition") {
1705
- b.append(`const ${entryVarName} = ${getAnimationDetails(value)};`);
1706
- b.append(`const ${exitVarName} = ${entryVarName};`);
1707
- b.append(`t_animate(${varName}, ${entryVarName}, ${exitVarName});`);
1708
- } else if (name === ":transition-in") {
1709
- let outAttribute = node.attributes.find((a) => a.name === ":transition-out");
1710
- if (outAttribute && outAttribute.value) {
1711
- let outValue = trimMatched(outAttribute.value, "{", "}");
1712
- b.append(`const ${entryVarName} = ${getAnimationDetails(value)};`);
1713
- b.append(`const ${exitVarName} = ${getAnimationDetails(outValue)};`);
1714
- b.append(`t_animate(${varName}, ${entryVarName}, ${exitVarName});`);
1715
- } else {
1716
- b.append(`const ${entryVarName} = ${getAnimationDetails(value)};`);
1717
- b.append(`t_animate(${varName}, ${entryVarName});`);
1718
- }
1719
- } else if (name === ":transition-out") {
1720
- let inAttribute = node.attributes.find((a) => a.name === ":transition-in");
1721
- if (inAttribute) {
1722
- return;
1723
- } else {
1724
- b.append(`const ${exitVarName} = ${getAnimationDetails(value)};`);
1725
- b.append(`t_animate(${varName}, null, ${entryVarName});`);
1726
- }
1727
- } else {
1728
- }
1729
- }
1730
- function getAnimationDetails(value) {
1731
- let parts = [];
1732
- let start = 0;
1733
- let squareCount = 0;
1734
- let curlyCount = 0;
1735
- for (let i = 0; i < value.length; i++) {
1736
- let char = value[i];
1737
- switch (char) {
1738
- case ",":
1739
- if (squareCount === 0 && curlyCount === 0) {
1740
- parts.push(value.substring(start, i));
1741
- start = i + 1;
1742
- }
1743
- break;
1744
- case "[":
1745
- squareCount += 1;
1746
- break;
1747
- case "]":
1748
- squareCount -= 1;
1749
- break;
1750
- case "{":
1751
- curlyCount += 1;
1752
- break;
1753
- case "}":
1754
- curlyCount -= 1;
1755
- break;
1756
- }
1757
- }
1758
- parts.push(value.substring(start));
1759
- let keyframes = parts[0]?.trim();
1760
- let options = parts[1]?.trim();
1761
- return `{ ${[`keyframes: ${keyframes}`, options ? `options: ${options}` : null].filter(Boolean).join(", ")} }`;
1762
- }
1763
-
1764
- // src/compile/build/client/buildRootNode.ts
1765
- function buildRootNode(node, status, b, parentName, anchorName) {
1766
- buildFragment(node, status, b, parentName, anchorName);
1767
- status.fragmentStack.push({
1768
- fragment: node.fragment,
1769
- path: "0:ch/"
1770
- });
1771
- for (let child of node.children) {
1772
- buildNode(child, status, b, parentName, anchorName, true);
1773
- }
1774
- status.fragmentStack.pop();
1775
- buildAddFragment(node, status, b, parentName, anchorName);
1776
- }
1777
-
1778
- // src/compile/build/client/buildHeadNode.ts
1779
- function buildHeadNode2(node, status, b) {
1780
- b.append("");
1781
- b.append("/* @head */");
1782
- status.inHead = true;
1783
- for (let child of node.children) {
1784
- buildNode(child, status, b, "undefined", "undefined");
1785
- }
1786
- status.inHead = false;
1787
- b.append("");
1788
- }
1789
-
1790
- // src/compile/build/client/buildSlotNode.ts
1791
- function buildSlotNode(node, status, b) {
1792
- let slotName = node.attributes.find((a) => a.name === "name")?.value;
1793
- slotName = slotName ? trimQuotes(slotName) : "_";
1794
- const propsName = nextVarName("sprops", status);
1795
- const slotAttributes = node.attributes.filter((a) => a.name !== "name");
1796
- const slotHasProps = slotAttributes.length;
1797
- if (slotHasProps) {
1798
- status.imports.add("$watch");
1799
- b.append(`const ${propsName} = $watch({});`);
1800
- for (let { name, value } of slotAttributes) {
1801
- if (name.startsWith("{") && name.endsWith("}")) {
1802
- name = name.substring(1, name.length - 1);
1803
- const propName = name.split(".").at(-1);
1804
- buildRun("setProp", `${propsName}["${propName}"] = ${name};`, status, b);
1805
- } else if (value != null) {
1806
- let fullyReactive = isFullyReactive(value);
1807
- let partlyReactive = isReactive(value);
1808
- if (fullyReactive) {
1809
- value = value.substring(1, value.length - 1);
1810
- } else if (partlyReactive) {
1811
- value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
1812
- }
1813
- const setProp = `${propsName}["${name}"] = ${value}`;
1814
- if (fullyReactive || partlyReactive) {
1815
- buildRun("setProp", `${setProp};`, status, b);
1816
- } else {
1817
- b.append(`${setProp};`);
1818
- }
1819
- } else {
1820
- b.append(`${propsName}["${name}"] = true;`);
1821
- }
1822
- }
1823
- }
1824
- const slotParentName = node.parentName;
1825
- const slotAnchorName = node.varName;
1826
- b.append(`if ($slots && $slots["${slotName}"]) {`);
1827
- let params = [slotParentName, slotAnchorName, slotHasProps ? propsName : "undefined", "$context"];
1828
- b.append(`$slots["${slotName}"](${params.join(", ")})`);
1829
- const fill = node.children.find((c) => isSpecialNode(c) && c.tagName === ":fill");
1830
- if (fill && isSpecialNode(fill) && fill.children.length) {
1831
- b.append(`} else {`);
1832
- buildFragment(fill, status, b, slotParentName, slotAnchorName);
1833
- status.fragmentStack.push({
1834
- fragment: fill.fragment,
1835
- path: "0:ch/"
1836
- });
1837
- for (let child of fill.children) {
1838
- buildNode(child, status, b, slotParentName, slotAnchorName);
1839
- }
1840
- status.fragmentStack.pop();
1841
- buildAddFragment(fill, status, b, slotParentName, slotAnchorName);
1842
- }
1843
- b.append(`}`);
1844
- }
1845
-
1846
- // src/compile/build/client/buildSpecialNode.ts
1847
- function buildSpecialNode(node, status, b, parentName, root = false) {
1848
- switch (node.tagName) {
1849
- case ":slot": {
1850
- buildSlotNode(node, status, b);
1851
- break;
1852
- }
1853
- case ":element": {
1854
- buildElementNode(node, status, b, parentName, root);
1855
- break;
1856
- }
1857
- case ":component": {
1858
- buildComponentNode(node, status, b, root);
1859
- break;
1860
- }
1861
- case ":head": {
1862
- buildHeadNode2(node, status, b);
1863
- break;
1864
- }
1865
- case ":fill": {
1866
- break;
1867
- }
1868
- default: {
1869
- throw new Error(`Invalid special node: ${node.tagName}`);
1870
- }
1871
- }
1872
- return "";
1873
- }
1874
-
1875
- // src/compile/build/client/buildTextNode.ts
1876
- function buildTextNode(node, status, b) {
1877
- let content = node.content || "";
1878
- if (!status.preserveWhitespace) {
1879
- content = content.replaceAll(/\s+/g, " ");
1880
- }
1881
- let textContent = "";
1882
- let reactiveCount = 0;
1883
- let level = 0;
1884
- let maxLevel = 0;
1885
- for (let i = 0; i < content.length; i++) {
1886
- const char = content[i];
1887
- const nextChar = content[i + 1];
1888
- if (char === "{") {
1889
- level++;
1890
- maxLevel = Math.max(level, maxLevel);
1891
- if (level === 1) {
1892
- reactiveCount += 1;
1893
- textContent += "${t_fmt(";
1894
- continue;
1895
- }
1896
- } else if (char === "}") {
1897
- level--;
1898
- if (level === 0) {
1899
- textContent += ")";
1900
- }
1901
- } else if (char === "`" && level === 0) {
1902
- textContent += "\\";
1903
- } else if (level > 0) {
1904
- if (char === "/" && nextChar === "/") {
1905
- let start = i;
1906
- i = content.indexOf("\n", i);
1907
- textContent += content.substring(start, i + 1);
1908
- continue;
1909
- } else if (char === "/" && nextChar === "*") {
1910
- let start = i;
1911
- i = content.indexOf("*/", i) + 1;
1912
- textContent += content.substring(start, i + 1);
1913
- continue;
1914
- } else if (char === '"' || char === "'") {
1915
- let start = i;
1916
- for (let j = i + 1; j < content.length; j++) {
1917
- if (content[j] === char && content[j - 1] !== "\\") {
1918
- i = j;
1919
- textContent += content.substring(start, i + 1);
1920
- break;
1921
- }
1922
- }
1923
- continue;
1924
- } else if (char === "`") {
1925
- let start = i;
1926
- let level2 = 0;
1927
- for (let j = i + 1; j < content.length; j++) {
1928
- if (content[j] === char && content[j - 1] !== "\\" && level2 === 0) {
1929
- i = j;
1930
- textContent += content.substring(start, i + 1);
1931
- break;
1932
- } else if (content[j] === "{" && (level2 > 0 || content[j - 1] === "$")) {
1933
- level2 += 1;
1934
- } else if (content[j] === "}" && level2 > 0) {
1935
- level2 -= 1;
1936
- }
1937
- }
1938
- continue;
1939
- }
1940
- }
1941
- textContent += content[i];
1942
- }
1943
- if (maxLevel) {
1944
- if (reactiveCount === 1 && content.startsWith("{") && content.endsWith("}")) {
1945
- textContent = textContent.substring(2, textContent.length - 1);
1946
- } else {
1947
- textContent = `\`${textContent}\``;
1948
- }
1949
- status.imports.add("t_fmt");
1950
- buildRun("setTextContent", `${node.varName}.textContent = ${textContent};`, status, b);
1951
- }
1952
- }
1953
-
1954
- // src/compile/build/client/buildNode.ts
1955
- function buildNode(node, status, b, parentName, anchorName, root = false) {
1956
- if (node.handled) {
1957
- node.handled = false;
1958
- return;
1959
- }
1960
- switch (node.type) {
1961
- case "root": {
1962
- buildRootNode(node, status, b, parentName, anchorName);
1963
- break;
1964
- }
1965
- case "control": {
1966
- buildControlNode(node, status, b);
1967
- break;
1968
- }
1969
- case "component": {
1970
- buildComponentNode(node, status, b, root);
1971
- break;
1972
- }
1973
- case "element": {
1974
- buildElementNode(node, status, b, parentName, root);
1975
- break;
1976
- }
1977
- case "text": {
1978
- buildTextNode(node, status, b);
1979
- break;
1980
- }
1981
- case "special": {
1982
- buildSpecialNode(node, status, b, parentName, root);
1983
- break;
1984
- }
1985
- default: {
1986
- throw new Error(`Invalid node type: ${node.type}`);
1987
- }
1988
- }
1989
- }
1990
-
1991
- // src/compile/build/client/buildCode.ts
1992
- var importsMap = {
1993
- $watch: 'import { $watch } from "${folder}";',
1994
- $unwrap: 'import { $unwrap } from "${folder}";',
1995
- $run: 'import { $run } from "${folder}";',
1996
- $mount: 'import { $mount } from "${folder}";',
1997
- t_range: 'import { t_range } from "${folder}";',
1998
- t_push_range: 'import { t_push_range } from "${folder}";',
1999
- t_pop_range: 'import { t_pop_range } from "${folder}";',
2000
- t_run_control: 'import { t_run_control } from "${folder}";',
2001
- t_run_branch: 'import { t_run_branch } from "${folder}";',
2002
- t_list_item: 'import { t_list_item } from "${folder}";',
2003
- t_run_list: 'import { t_run_list } from "${folder}";',
2004
- t_add_fragment: 'import { t_add_fragment } from "${folder}";',
2005
- t_apply_props: 'import { t_apply_props } from "${folder}";',
2006
- t_class: 'import { t_class } from "${folder}";',
2007
- t_style: 'import { t_style } from "${folder}";',
2008
- t_attribute: 'import { t_attribute } from "${folder}";',
2009
- t_dynamic: 'import { t_dynamic } from "${folder}";',
2010
- t_fmt: 'import { t_fmt } from "${folder}";',
2011
- t_fragment: 'import { t_fragment } from "${folder}";',
2012
- t_event: 'import { t_event } from "${folder}";',
2013
- t_animate: 'import { t_animate } from "${folder}";',
2014
- t_root: 'import { t_root } from "${folder}";',
2015
- t_anchor: 'import { t_anchor } from "${folder}";',
2016
- t_child: 'import { t_child } from "${folder}";',
2017
- t_next: 'import { t_next } from "${folder}";',
2018
- t_skip: 'import { t_skip } from "${folder}";',
2019
- t_frg: 'import { t_frg } from "${folder}";',
2020
- t_elm: 'import { t_elm } from "${folder}";',
2021
- t_txt: 'import { t_txt } from "${folder}";',
2022
- t_cmt: 'import { t_cmt } from "${folder}";',
2023
- t_print: 'import { t_print } from "${folder}";',
2024
- ListItem: 'import { type ListItem } from "${folder}";',
2025
- SlotRender: 'import { type SlotRender } from "${folder}";'
2026
- };
2027
- function buildCode(template, options) {
2028
- let b = new Builder();
2029
- let imports = /* @__PURE__ */ new Set();
2030
- imports.add("SlotRender");
2031
- buildTemplate(template, imports, b);
2032
- if (imports.size) {
2033
- b.prepend("");
2034
- for (let imp of Array.from(imports).sort().reverse()) {
2035
- imp = importsMap[imp] || imp;
2036
- b.prepend(imp.replace("${folder}", options?.renderFolder || "@torpor/view"));
2037
- }
2038
- }
2039
- return b.toString();
2040
- }
2041
- function buildTemplate(template, imports, b) {
2042
- let script = template.script || "";
2043
- if (/\$watch\b/.test(script)) imports.add("$watch");
2044
- if (/\$unwrap\b/.test(script)) imports.add("$unwrap");
2045
- if (/\$run\b/.test(script)) imports.add("$run");
2046
- if (/\$mount\b/.test(script)) imports.add("$mount");
2047
- let currentIndex = 0;
2048
- let current = template.components[0];
2049
- let marker = 0;
2050
- for (let i = 0; i < script.length; i++) {
2051
- if (script.substring(i, i + "/* @params */".length) === "/* @params */") {
2052
- b.append(script.substring(marker, i));
2053
- let params = [
2054
- "$parent: ParentNode",
2055
- "$anchor: Node | null",
2056
- current.params ?? `${current.props?.length ? "$props" : "// @ts-ignore\n$props?"}: Record<PropertyKey, any>`,
2057
- `${current.contextProps?.length ? "" : "// @ts-ignore\n"}$context?: Record<PropertyKey, any>`,
2058
- `${current.slotProps?.length ? "" : "// @ts-ignore\n"}$slots?: Record<string, SlotRender>`
2059
- ];
2060
- b.append(params.join(",\n"));
2061
- marker = i + "/* @params */".length;
2062
- } else if (script.substring(i, i + "/* @start */".length) === "/* @start */") {
2063
- b.append(script.substring(marker, i));
2064
- if (current.props?.length) {
2065
- imports.add("$watch");
2066
- b.append(`$props ??= $watch({});`);
2067
- }
2068
- if (current.contextProps?.length) {
2069
- b.append(`$context = Object.assign({}, $context);`);
2070
- }
2071
- b.append("");
2072
- marker = i + "/* @start */".length;
2073
- } else if (script.substring(i, i + "/* @render */".length) === "/* @render */") {
2074
- b.append(script.substring(marker, i));
2075
- if (current.markup) {
2076
- const status = {
2077
- imports,
2078
- props: current.props || [],
2079
- contextProps: current.contextProps || [],
2080
- slotProps: current.slotProps || [],
2081
- styleHash: current.style?.hash || "",
2082
- varNames: {},
2083
- fragmentStack: [],
2084
- forVarNames: [],
2085
- ns: false,
2086
- preserveWhitespace: false
2087
- };
2088
- b.append("");
2089
- b.append("/* User interface */");
2090
- buildFragmentText(current.markup, status, b);
2091
- b.append("");
2092
- buildNode(current.markup, status, b, "$parent", "$anchor", true);
2093
- }
2094
- marker = i + "/* @render */".length;
2095
- } else if (script.substring(i, i + "/* @end */".length) === "/* @end */") {
2096
- b.append(script.substring(marker, i));
2097
- currentIndex += 1;
2098
- current = template.components[currentIndex];
2099
- marker = i + "/* @end */".length;
2100
- }
2101
- }
2102
- b.append(script.substring(marker));
2103
- }
2104
-
2105
- // src/compile/build/client/buildStyles.ts
2106
- function buildStyles(style, styleHash) {
2107
- const b = new Builder();
2108
- for (let block of style.blocks) {
2109
- buildStyleBlock(block, b, styleHash);
2110
- }
2111
- return b.toString();
2112
- }
2113
- var globalStyleRegex = /\:global\((.+)\)/;
2114
- function buildStyleBlock(block, b, styleHash) {
2115
- if (block.selector.startsWith("@")) {
2116
- b.append(`${block.selector} {`);
2117
- } else {
2118
- const selectors = block.selector.split(/([\s*,>+~])/).filter((s) => !!s.trim()).map((s) => {
2119
- if (s.length === 1 && "*,>+~".includes(s)) {
2120
- return s;
2121
- } else if (globalStyleRegex.test(s)) {
2122
- return s.match(globalStyleRegex)[1];
2123
- } else {
2124
- return `${s}.torp-${styleHash}`;
2125
- }
2126
- });
2127
- b.append(`${selectors.join(" ")} {`);
2128
- }
2129
- for (let attribute of block.attributes) {
2130
- buildStyleAttribute(attribute, b);
2131
- }
2132
- for (let child of block.children) {
2133
- buildStyleBlock(child, b, styleHash);
2134
- }
2135
- b.append(`}`);
2136
- }
2137
- function buildStyleAttribute(attribute, b) {
2138
- b.append(`${attribute.name}: ${attribute.value};`);
2139
- }
2140
-
2141
- // src/compile/build/server/buildServerComponentNode.ts
2142
- function buildServerComponentNode(node, status, b) {
2143
- status.output += HYDRATION_START_COMMENT;
2144
- if (status.output) {
2145
- b.append(`t_body += \`${status.output}\`;`);
2146
- status.output = "";
2147
- }
2148
- const componentHasProps = node.attributes.length;
2149
- const propsName = componentHasProps ? nextVarName("props", status) : "undefined";
2150
- if (componentHasProps) {
2151
- b.append(`const ${propsName}: any = {};`);
2152
- for (let { name, value } of node.attributes) {
2153
- if (name.startsWith("{") && name.endsWith("}")) {
2154
- name = name.substring(1, name.length - 1);
2155
- const propName = name.split(".").at(-1);
2156
- b.append(`${propsName}["${propName}"] = ${name};`);
2157
- } else if ((name === "class" || name === ":class") && value != null) {
2158
- status.imports.add("t_class");
2159
- if (isFullyReactive(value)) {
2160
- value = value.substring(1, value.length - 1);
2161
- }
2162
- const params = [value];
2163
- if (node.scopeStyles) {
2164
- params.push(`"torp-${status.styleHash}"`);
2165
- }
2166
- b.append(`${propsName}["class"] = t_class(${params.join(", ")});`);
2167
- } else if ((name === "style" || name === ":style") && value != null) {
2168
- status.imports.add("t_style");
2169
- if (isFullyReactive(value)) {
2170
- value = value.substring(1, value.length - 1);
2171
- }
2172
- b.append(`${propsName}["style"] = t_style(${value});`);
2173
- } else if (value != null) {
2174
- let fullyReactive = isFullyReactive(value);
2175
- let partlyReactive = isReactive(value);
2176
- if (fullyReactive) {
2177
- value = value.substring(1, value.length - 1);
2178
- } else if (partlyReactive) {
2179
- value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
2180
- }
2181
- b.append(`${propsName}["${name}"] = ${value};`);
2182
- } else {
2183
- b.append(`${propsName}["${name}"] = true;`);
2184
- }
2185
- }
2186
- }
2187
- const componentHasSlots = node.children.length;
2188
- const slotsName = componentHasSlots ? nextVarName("slots", status) : "undefined";
2189
- if (componentHasSlots) {
2190
- b.append(`const ${slotsName}: Record<string, ServerSlotRender> = {};`);
2191
- for (let slot of node.children) {
2192
- if (isSpecialNode(slot)) {
2193
- const nameAttribute = slot.attributes.find((a) => a.name === "name");
2194
- const slotName = nameAttribute?.value ? trimQuotes(nameAttribute.value) : "_";
2195
- const slotParams = [
2196
- "// @ts-ignore\n$sprops?: Record<PropertyKey, any>",
2197
- "// @ts-ignore\n$context?: Record<PropertyKey, any>"
2198
- ];
2199
- b.append(`${slotsName}["${slotName}"] = (
2200
- ${slotParams.join(",\n")}
2201
- ) => {`);
2202
- b.append(`let t_body = "";`);
2203
- for (let child of slot.children) {
2204
- buildServerNode(child, status, b);
2205
- }
2206
- if (status.output) {
2207
- b.append(`t_body += \`${status.output}\`;`);
2208
- status.output = "";
2209
- }
2210
- b.append("return t_body;");
2211
- b.append(`}`);
2212
- }
2213
- }
2214
- }
2215
- let componentName = node.tagName;
2216
- if (componentName === ":component") {
2217
- let selfAttribute = node.attributes.find((a) => a.name === "self");
2218
- if (selfAttribute && selfAttribute.value) {
2219
- componentName = trimMatched(selfAttribute.value, "{", "}");
2220
- }
2221
- }
2222
- let renderParams = `${propsName}, $context`;
2223
- if (slotsName !== "undefined") {
2224
- renderParams += `, ${slotsName}`;
2225
- }
2226
- b.append("");
2227
- const componentResult = nextVarName("comp", status);
2228
- b.append(`const ${componentResult} = ${componentName}(${renderParams});`);
2229
- b.append(`t_body += ${componentResult}.body;`);
2230
- b.append(`t_head += ${componentResult}.head;`);
2231
- status.output += HYDRATION_END_COMMENT;
2232
- status.output += ANCHOR_COMMENT;
2233
- }
2234
-
2235
- // src/compile/build/server/buildServerAwaitNode.ts
2236
- function buildServerAwaitNode(node, status, b) {
2237
- status.output += HYDRATION_START_COMMENT;
2238
- if (status.output) {
2239
- b.append(`t_body += \`${status.output}\`;`);
2240
- status.output = "";
2241
- }
2242
- for (let branch of node.children) {
2243
- if (isControlNode(branch) && branch.operation === "@await") {
2244
- buildServerAwaitBranch(branch, status, b);
2245
- }
2246
- }
2247
- status.output += HYDRATION_END_COMMENT;
2248
- status.output += ANCHOR_COMMENT;
2249
- }
2250
- function buildServerAwaitBranch(node, status, b) {
2251
- for (let child of node.children) {
2252
- buildServerNode(child, status, b);
2253
- }
2254
- if (status.output) {
2255
- b.append(`t_body += \`${status.output}\`;`);
2256
- status.output = "";
2257
- }
2258
- }
2259
-
2260
- // src/compile/build/server/buildServerForNode.ts
2261
- function buildServerForNode(node, status, b) {
2262
- status.output += HYDRATION_START_COMMENT;
2263
- if (status.output) {
2264
- b.append(`t_body += \`${status.output}\`;`);
2265
- status.output = "";
2266
- }
2267
- for (let branch of node.children) {
2268
- if (isControlNode(branch)) {
2269
- buildServerForBranch(branch, status, b);
2270
- }
2271
- }
2272
- status.output += HYDRATION_END_COMMENT;
2273
- status.output += ANCHOR_COMMENT;
2274
- }
2275
- function buildServerForBranch(node, status, b) {
2276
- b.append(`${node.statement} {`);
2277
- status.output += HYDRATION_BREAK_COMMENT;
2278
- for (let child of node.children) {
2279
- buildServerNode(child, status, b);
2280
- }
2281
- if (status.output) {
2282
- b.append(`t_body += \`${status.output}\`;`);
2283
- status.output = "";
2284
- }
2285
- b.append("}");
2286
- }
2287
-
2288
- // src/compile/build/server/buildServerHtmlNode.ts
2289
- function buildServerHtmlNode(node, status) {
2290
- status.output += HYDRATION_START_COMMENT;
2291
- for (let branch of node.children) {
2292
- if (isControlNode(branch)) {
2293
- status.output += `\${${branch.statement}}`;
2294
- }
2295
- }
2296
- status.output += HYDRATION_END_COMMENT;
2297
- status.output += ANCHOR_COMMENT;
2298
- }
2299
-
2300
- // src/compile/build/server/buildServerIfNode.ts
2301
- function buildServerIfNode(node, status, b) {
2302
- status.output += HYDRATION_START_COMMENT;
2303
- if (status.output) {
2304
- b.append(`t_body += \`${status.output}\`;`);
2305
- status.output = "";
2306
- }
2307
- for (let branch of node.children) {
2308
- if (isControlNode(branch)) {
2309
- buildServerIfBranch(branch, status, b);
2310
- }
2311
- }
2312
- status.output += HYDRATION_END_COMMENT;
2313
- status.output += ANCHOR_COMMENT;
2314
- }
2315
- function buildServerIfBranch(node, status, b) {
2316
- b.append(`${node.statement} {`);
2317
- status.output += HYDRATION_BREAK_COMMENT;
2318
- for (let child of node.children) {
2319
- buildServerNode(child, status, b);
2320
- }
2321
- if (status.output) {
2322
- b.append(`t_body += \`${status.output}\`;`);
2323
- status.output = "";
2324
- }
2325
- b.append("}");
2326
- }
2327
-
2328
- // src/compile/build/server/buildServerReplaceNode.ts
2329
- function buildServerReplaceNode(node, status, b) {
2330
- status.output += HYDRATION_START_COMMENT;
2331
- if (status.output) {
2332
- b.append(`t_body += \`${status.output}\`;`);
2333
- status.output = "";
2334
- }
2335
- for (let branch of node.children) {
2336
- if (isControlNode(branch)) {
2337
- buildServerReplaceBranch(branch, status, b);
2338
- }
2339
- }
2340
- status.output += HYDRATION_END_COMMENT;
2341
- status.output += ANCHOR_COMMENT;
2342
- }
2343
- function buildServerReplaceBranch(node, status, b) {
2344
- b.append(`${node.statement};`);
2345
- for (let child of node.children) {
2346
- buildServerNode(child, status, b);
2347
- }
2348
- if (status.output) {
2349
- b.append(`t_body += \`${status.output}\`;`);
2350
- status.output = "";
2351
- }
2352
- }
2353
-
2354
- // src/compile/build/server/buildServerScriptNode.ts
2355
- function buildServerScriptNode(node, b) {
2356
- b.append(`${maybeAppend2(node.statement, ";")}`);
2357
- }
2358
- function maybeAppend2(text, end) {
2359
- if (!text.endsWith(end)) {
2360
- text += end;
2361
- }
2362
- return text;
2363
- }
2364
-
2365
- // src/compile/build/server/buildServerSwitchNode.ts
2366
- function buildServerSwitchNode(node, status, b) {
2367
- status.output += HYDRATION_START_COMMENT;
2368
- if (status.output) {
2369
- b.append(`t_body += \`${status.output}\`;`);
2370
- status.output = "";
2371
- }
2372
- b.append(`${node.statement} {`);
2373
- for (let branch of node.children.filter((c) => isControlNode(c))) {
2374
- if (isControlNode(branch)) {
2375
- buildServerSwitchBranch(branch, status, b);
2376
- }
2377
- }
2378
- b.append("}");
2379
- status.output += HYDRATION_END_COMMENT;
2380
- status.output += ANCHOR_COMMENT;
2381
- }
2382
- function buildServerSwitchBranch(node, status, b) {
2383
- b.append(`${node.statement} {`);
2384
- status.output += HYDRATION_BREAK_COMMENT;
2385
- for (let child of node.children) {
2386
- buildServerNode(child, status, b);
2387
- }
2388
- if (status.output) {
2389
- b.append(`t_body += \`${status.output}\`;`);
2390
- status.output = "";
2391
- }
2392
- b.append("break;");
2393
- b.append("}");
2394
- }
2395
-
2396
- // src/compile/build/server/buildServerControlNode.ts
2397
- function buildServerControlNode(node, status, b) {
2398
- switch (node.operation) {
2399
- case "@if group": {
2400
- buildServerIfNode(node, status, b);
2401
- break;
2402
- }
2403
- case "@if":
2404
- case "@else if":
2405
- case "@else": {
2406
- break;
2407
- }
2408
- case "@switch group": {
2409
- buildServerSwitchNode(node, status, b);
2410
- break;
2411
- }
2412
- case "@case":
2413
- case "@default": {
2414
- break;
2415
- }
2416
- case "@for group": {
2417
- buildServerForNode(node, status, b);
2418
- break;
2419
- }
2420
- case "@for":
2421
- case "@key": {
2422
- break;
2423
- }
2424
- case "@await group": {
2425
- buildServerAwaitNode(node, status, b);
2426
- break;
2427
- }
2428
- case "@await":
2429
- case "@then":
2430
- case "@catch": {
2431
- break;
2432
- }
2433
- case "@replace group": {
2434
- buildServerReplaceNode(node, status, b);
2435
- break;
2436
- }
2437
- case "@replace": {
2438
- break;
2439
- }
2440
- case "@html group": {
2441
- buildServerHtmlNode(node, status);
2442
- break;
2443
- }
2444
- case "@html": {
2445
- break;
2446
- }
2447
- case "@const": {
2448
- if (status.output) {
2449
- b.append(`t_body += \`${status.output}\`;`);
2450
- status.output = "";
2451
- }
2452
- buildServerScriptNode(node, b);
2453
- break;
2454
- }
2455
- case "@function":
2456
- case "@async function": {
2457
- if (status.output) {
2458
- b.append(`t_body += \`${status.output}\`;`);
2459
- status.output = "";
2460
- }
2461
- b.append("");
2462
- buildServerScriptNode(node, b);
2463
- b.append("");
2464
- break;
2465
- }
2466
- case "@console":
2467
- case "@debugger": {
2468
- break;
2469
- }
2470
- default: {
2471
- throw new Error(`Invalid operation: ${node.operation}`);
2472
- }
2473
- }
2474
- }
2475
-
2476
- // src/compile/utils/voidTags.ts
2477
- var voidTags = [
2478
- "area",
2479
- "base",
2480
- "br",
2481
- "col",
2482
- "embed",
2483
- "hr",
2484
- "img",
2485
- "input",
2486
- "link",
2487
- "meta",
2488
- "param",
2489
- "source",
2490
- "track",
2491
- "wbr"
2492
- ];
2493
- var voidTags_default = voidTags;
2494
-
2495
- // src/compile/build/server/buildServerElementNode.ts
2496
- function buildServerElementNode(node, status, b) {
2497
- let attributes = buildElementAttributes2(node, status);
2498
- if (attributes.length) {
2499
- attributes = " " + attributes;
2500
- }
2501
- let tagName = node.tagName;
2502
- if (tagName === ":element") {
2503
- let selfAttribute = node.attributes.find((a) => a.name === "self");
2504
- if (selfAttribute) {
2505
- tagName = `$${selfAttribute.value}`;
2506
- }
2507
- }
2508
- status.output += `<${tagName}${attributes}>`;
2509
- if (!voidTags_default.includes(tagName)) {
2510
- const oldPreserveWhitespace = status.preserveWhitespace;
2511
- status.preserveWhitespace = ["pre", "code"].includes(tagName);
2512
- for (let child of node.children) {
2513
- buildServerNode(child, status, b);
2514
- }
2515
- status.preserveWhitespace = oldPreserveWhitespace;
2516
- status.output += `</${tagName}>`;
2517
- }
2518
- }
2519
- function buildElementAttributes2(node, status) {
2520
- let needsClass = node.scopeStyles;
2521
- let attributes = [];
2522
- for (let { name, value } of node.attributes) {
2523
- if (name === "self" && node.tagName === ":element") {
2524
- } else if (name.startsWith("on") || name.startsWith(":on")) {
2525
- } else if (name.startsWith(":transition") && value) {
2526
- value = value.substring(1, value.length - 1).trim();
2527
- value = value.split(",")[0].trim();
2528
- if (value.startsWith("[")) {
2529
- value = value.substring(1);
2530
- } else {
2531
- value = value + "[0]";
2532
- }
2533
- attributes.push(
2534
- `style="\${Object.entries(${value}).map(([k, v]) => \`\${k}: \${v}\`).join("; ")}"`
2535
- );
2536
- } else if (name.startsWith("{") && name.endsWith("}")) {
2537
- name = name.substring(1, name.length - 1);
2538
- const propName = name.split(".").at(-1);
2539
- status.imports.add("t_attr");
2540
- attributes.push(`${propName}="\${t_attr(${name})}"`);
2541
- } else if (value != null && isFullyReactive(value)) {
2542
- value = value.substring(1, value.length - 1);
2543
- if (name === "&ref" || name === "&value" || name === "&checked" || name === "&group") {
2544
- let defaultValue = "";
2545
- let typeAttribute = node.attributes.find((a) => a.name === "type");
2546
- if (typeAttribute && typeAttribute.value) {
2547
- switch (trimQuotes(typeAttribute.value)) {
2548
- case "number": {
2549
- defaultValue = "0";
2550
- break;
2551
- }
2552
- case "checkbox": {
2553
- defaultValue = "false";
2554
- break;
2555
- }
2556
- }
2557
- }
2558
- if (!defaultValue) {
2559
- status.imports.add("t_attr");
2560
- value = `t_attr(${value})`;
2561
- defaultValue = '""';
2562
- }
2563
- let valueOrDefault = `${value} || ${defaultValue}`;
2564
- const propName = name.substring(1);
2565
- attributes.push(`${propName}="\${${valueOrDefault}}"`);
2566
- } else if (name === "class" || name === ":class") {
2567
- status.imports.add("t_class");
2568
- let params = [value];
2569
- if (node.scopeStyles) {
2570
- params.push(`"torp-${status.styleHash}"`);
2571
- needsClass = false;
2572
- }
2573
- attributes.push(`class="\${t_class(${params.join(", ")})}"`);
2574
- } else if (name === "style" || name === ":style") {
2575
- status.imports.add("t_style");
2576
- attributes.push(`style="\${t_style(${value})}"`);
2577
- } else {
2578
- status.imports.add("t_attr");
2579
- attributes.push(`\${${value} ? \`${name}="\${t_attr(${value})}"\` : ''}`);
2580
- }
2581
- } else if (value != null && isReactive(value)) {
2582
- status.imports.add("t_attr");
2583
- attributes.push(
2584
- `${name}="${trimQuotes(value).replaceAll("{", "${t_attr(").replaceAll("}", ")}")}"`
2585
- );
2586
- } else if (name === "class" && node.scopeStyles) {
2587
- value = value ? `"${trimQuotes(value)} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
2588
- attributes.push(`${name}="${trimQuotes(value).replaceAll('"', "&quot;")}"`);
2589
- needsClass = false;
2590
- } else if (value != null) {
2591
- attributes.push(`${name}="${trimQuotes(value).replaceAll('"', "&quot;")}"`);
2592
- } else {
2593
- attributes.push(`${name}`);
2594
- }
2595
- }
2596
- if (needsClass) {
2597
- attributes.push(`class="torp-${status.styleHash}"`);
2598
- }
2599
- return attributes.join(" ");
2600
- }
2601
-
2602
- // src/compile/build/server/buildServerRootNode.ts
2603
- function buildServerRootNode(node, status, b) {
2604
- for (let child of node.children) {
2605
- buildServerNode(child, status, b);
2606
- }
2607
- }
2608
-
2609
- // src/compile/build/server/buildServerSlotNode.ts
2610
- function buildServerSlotNode(node, status, b) {
2611
- status.output += HYDRATION_START_COMMENT;
2612
- if (status.output) {
2613
- b.append(`t_body += \`${status.output}\`;`);
2614
- status.output = "";
2615
- }
2616
- let slotName = node.attributes.find((a) => a.name === "name")?.value;
2617
- slotName = slotName ? trimQuotes(slotName) : "_";
2618
- const propsName = nextVarName("sprops", status);
2619
- const slotAttributes = node.attributes.filter((a) => a.name !== "name");
2620
- const slotHasProps = slotAttributes.length;
2621
- if (slotHasProps) {
2622
- b.append(`const ${propsName}: any = {};`);
2623
- for (let { name, value } of slotAttributes) {
2624
- if (name.startsWith("{") && name.endsWith("}")) {
2625
- name = name.substring(1, name.length - 1);
2626
- const propName = name.split(".").at(-1);
2627
- b.append(`${propsName}["${propName}"] = ${name};`);
2628
- } else if (value != null) {
2629
- let fullyReactive = isFullyReactive(value);
2630
- let partlyReactive = isReactive(value);
2631
- if (fullyReactive) {
2632
- value = value.substring(1, value.length - 1);
2633
- } else if (partlyReactive) {
2634
- value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
2635
- }
2636
- b.append(`${propsName}["${name}"] = ${value};`);
2637
- } else {
2638
- b.append(`${propsName}["${name}"] = true;`);
2639
- }
2640
- }
2641
- }
2642
- b.append(`if ($slots && $slots["${slotName}"]) {`);
2643
- b.append(`t_body += $slots["${slotName}"](${slotHasProps ? propsName : "undefined"}, $context);`);
2644
- const fill = node.children.find((c) => isSpecialNode(c) && c.tagName === ":fill");
2645
- if (fill && isSpecialNode(fill) && fill.children.length) {
2646
- b.append(`} else {`);
2647
- for (let child of fill.children) {
2648
- buildServerNode(child, status, b);
2649
- }
2650
- if (status.output) {
2651
- b.append(`t_body += \`${status.output}\`;`);
2652
- status.output = "";
2653
- }
2654
- }
2655
- b.append(`}`);
2656
- status.output += HYDRATION_END_COMMENT;
2657
- status.output += ANCHOR_COMMENT;
2658
- }
2659
-
2660
- // src/compile/build/server/buildServerSpecialNode.ts
2661
- function buildServerSpecialNode(node, status, b) {
2662
- switch (node.tagName) {
2663
- case ":slot": {
2664
- buildServerSlotNode(node, status, b);
2665
- break;
2666
- }
2667
- case ":element": {
2668
- buildServerElementNode(node, status, b);
2669
- break;
2670
- }
2671
- case ":component": {
2672
- buildServerComponentNode(node, status, b);
2673
- break;
2674
- }
2675
- case ":head": {
2676
- break;
2677
- }
2678
- case ":fill": {
2679
- break;
2680
- }
2681
- default: {
2682
- throw new Error(`Invalid special node: ${node.tagName}`);
2683
- }
2684
- }
2685
- }
2686
-
2687
- // src/compile/build/server/buildServerTextNode.ts
2688
- function buildServerTextNode(node, status) {
2689
- let content = node.content || "";
2690
- if (!status.preserveWhitespace) {
2691
- content = content.replaceAll(/\s+/g, " ");
2692
- }
2693
- let level = 0;
2694
- for (let i = 0; i < content.length; i++) {
2695
- const char = content[i];
2696
- const nextChar = content[i + 1];
2697
- if (char === "{") {
2698
- level++;
2699
- if (level === 1) {
2700
- status.imports.add("t_fmt");
2701
- status.output += "${t_fmt(";
2702
- continue;
2703
- }
2704
- } else if (char === "}") {
2705
- level--;
2706
- if (level === 0) {
2707
- status.output += ")";
2708
- }
2709
- } else if (char === "`" && level === 0) {
2710
- status.output += "\\";
2711
- } else if (level > 0) {
2712
- if (char === "/" && nextChar === "/") {
2713
- let start = i;
2714
- i = content.indexOf("\n", i);
2715
- status.output += escapeHtml(content.substring(start, i + 1));
2716
- continue;
2717
- } else if (char === "/" && nextChar === "*") {
2718
- let start = i;
2719
- i = content.indexOf("*/", i) + 1;
2720
- status.output += escapeHtml(content.substring(start, i + 1));
2721
- continue;
2722
- } else if (char === '"' || char === "'") {
2723
- let start = i;
2724
- for (let j = i + 1; j < content.length; j++) {
2725
- if (content[j] === char && content[j - 1] !== "\\") {
2726
- i = j;
2727
- status.output += escapeHtml(content.substring(start, i + 1));
2728
- break;
2729
- }
2730
- }
2731
- continue;
2732
- } else if (char === "`") {
2733
- let start = i;
2734
- let level2 = 0;
2735
- for (let j = i + 1; j < content.length; j++) {
2736
- if (content[j] === char && content[j - 1] !== "\\" && level2 === 0) {
2737
- i = j;
2738
- status.output += escapeHtml(content.substring(start, i + 1));
2739
- break;
2740
- } else if (content[j] === "{" && (level2 > 0 || content[j - 1] === "$")) {
2741
- level2 += 1;
2742
- } else if (content[j] === "}" && level2 > 0) {
2743
- level2 -= 1;
2744
- }
2745
- }
2746
- continue;
2747
- }
2748
- }
2749
- status.output += char;
2750
- }
2751
- }
2752
- function escapeHtml(text) {
2753
- return text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
2754
- }
2755
-
2756
- // src/compile/build/server/buildServerNode.ts
2757
- function buildServerNode(node, status, b) {
2758
- switch (node.type) {
2759
- case "root": {
2760
- buildServerRootNode(node, status, b);
2761
- break;
2762
- }
2763
- case "control": {
2764
- buildServerControlNode(node, status, b);
2765
- break;
2766
- }
2767
- case "component": {
2768
- buildServerComponentNode(node, status, b);
2769
- break;
2770
- }
2771
- case "element": {
2772
- buildServerElementNode(node, status, b);
2773
- break;
2774
- }
2775
- case "text": {
2776
- buildServerTextNode(node, status);
2777
- break;
2778
- }
2779
- case "special": {
2780
- buildServerSpecialNode(node, status, b);
2781
- break;
2782
- }
2783
- default: {
2784
- throw new Error(`Invalid node type: ${node.type}`);
2785
- }
2786
- }
2787
- }
2788
-
2789
- // src/compile/build/server/buildServerCode.ts
2790
- var importsMap2 = {
2791
- $watch: 'import { $watch } from "${folder}";',
2792
- $unwrap: 'import { $unwrap } from "${folder}";',
2793
- $run: 'import { $run } from "${folder}";',
2794
- $mount: 'import { $mount } from "${folder}";',
2795
- t_fmt: 'import { t_fmt } from "${folder}";',
2796
- t_attr: 'import { t_attr } from "${folder}";',
2797
- t_class: 'import { t_class } from "${folder}";',
2798
- t_style: 'import { t_style } from "${folder}";',
2799
- ServerSlotRender: 'import { type ServerSlotRender } from "${folder}";'
2800
- };
2801
- function buildServerCode(template, options) {
2802
- let b = new Builder();
2803
- let imports = /* @__PURE__ */ new Set();
2804
- imports.add("ServerSlotRender");
2805
- buildServerTemplate(template, imports, b, options);
2806
- if (imports.size) {
2807
- b.prepend("");
2808
- for (let imp of Array.from(imports).sort().reverse()) {
2809
- imp = importsMap2[imp] || imp;
2810
- b.prepend(imp.replace("${folder}", options?.renderFolder || "@torpor/view/ssr"));
2811
- }
2812
- }
2813
- return b.toString();
2814
- }
2815
- function buildServerTemplate(template, imports, b, options) {
2816
- let script = template.script || "";
2817
- if (/\$watch\b/.test(script)) imports.add("$watch");
2818
- if (/\$unwrap\b/.test(script)) imports.add("$unwrap");
2819
- if (/\$run\b/.test(script)) imports.add("$run");
2820
- if (/\$mount\b/.test(script)) imports.add("$mount");
2821
- let currentIndex = 0;
2822
- let current = template.components[0];
2823
- let marker = 0;
2824
- for (let i = 0; i < script.length; i++) {
2825
- if (script.substring(i, i + "/* @params */".length) === "/* @params */") {
2826
- b.append(script.substring(marker, i));
2827
- let params = [
2828
- current.params ?? `${current.props?.length ? "$props" : "// @ts-ignore\n$props?"}: Record<PropertyKey, any>`,
2829
- `${current.contextProps?.length ? "" : "// @ts-ignore\n"}$context?: Record<PropertyKey, any>`,
2830
- `${current.slotProps?.length ? "" : "// @ts-ignore\n"}$slots?: Record<string, ServerSlotRender>`
2831
- ];
2832
- b.append(params.join(",\n"));
2833
- marker = i + "/* @params */".length;
2834
- } else if (script.substring(i, i + "/* @start */".length) === "/* @start */") {
2835
- b.append(script.substring(marker, i));
2836
- if (current.props?.length) {
2837
- b.append(`$props ??= {};`);
2838
- }
2839
- if (current.contextProps?.length) {
2840
- b.append(`$context = Object.assign({}, $context);`);
2841
- }
2842
- marker = i + "/* @start */".length;
2843
- } else if (script.substring(i, i + "/* @render */".length) === "/* @render */") {
2844
- b.append(script.substring(marker, i));
2845
- if (current.markup) {
2846
- const status = {
2847
- imports,
2848
- output: "",
2849
- styleHash: current.style?.hash || "",
2850
- varNames: {},
2851
- preserveWhitespace: false,
2852
- options
2853
- };
2854
- b.append("");
2855
- b.append("/* User interface */");
2856
- b.append(`let t_body = "";`);
2857
- if (current.style) {
2858
- const styles = buildStyles(current.style, current.style.hash).replaceAll('"', '\\"').replaceAll(/\s+/g, " ");
2859
- b.append(`let t_head = "<style id='${current.style.hash}'>${styles}</style>";
2860
- `);
2861
- } else {
2862
- b.append(`let t_head = "";`);
2863
- }
2864
- buildServerNode(current.markup, status, b);
2865
- if (status.output) {
2866
- b.append(`t_body += \`${status.output}\`;`);
2867
- status.output = "";
2868
- }
2869
- }
2870
- marker = i + "/* @render */".length;
2871
- } else if (script.substring(i, i + "/* @end */".length) === "/* @end */") {
2872
- b.append(script.substring(marker, i));
2873
- b.append(`return { body: t_body, head: t_head };`);
2874
- currentIndex += 1;
2875
- current = template.components[currentIndex];
2876
- marker = i + "/* @end */".length;
2877
- }
2878
- }
2879
- b.append(script.substring(marker));
2880
- }
2881
-
2882
- // src/compile/build.ts
2883
- function build(template, options) {
2884
- let code = options?.server ? buildServerCode(template, options) : buildCode(template, options);
2885
- let styles = template.components.map(
2886
- (c) => c.style ? { style: buildStyles(c.style, c.style.hash), hash: c.style.hash } : void 0
2887
- ).filter((c) => c !== void 0);
2888
- return {
2889
- code,
2890
- styles
2891
- };
2892
- }
2893
-
2894
- // src/compile/buildType.ts
2895
- function buildType(template, options) {
2896
- let b = new Builder();
2897
- b.append(`import { type SlotRender } from "${options?.renderFolder || "@torpor/view"}";`);
2898
- for (let component of template.components) {
2899
- b.append("");
2900
- b.append(`
2901
- /**
2902
- * Mounts or hydrates the component into the supplied parent node.
2903
- * @param $parent -- The parent node.
2904
- * @param $anchor -- The node to mount the component before.
2905
- * @param $props -- The values that have been passed into the component as properties.
2906
- * @param $context -- Values that have been passed into the component from its ancestors.
2907
- * @param $slots -- Functions for rendering children into slot nodes within the component.
2908
- */
2909
- ${component.default ? "declare" : "export declare"} function ${component.name}(
2910
- $parent: ParentNode,
2911
- $anchor: Node | null,
2912
- ${component.params || "$props?: Record<PropertyKey, any>"},
2913
- $context?: Record<PropertyKey, any>,
2914
- $slots?: Record<string, SlotRender>,
2915
- ): void;
2916
- `);
2917
- if (component.default) {
2918
- b.append(`export default ${component.name};`);
2919
- }
2920
- }
2921
- return b.toString();
2922
- }
2923
-
2924
- // src/compile/types/nodes/isSpaceNode.ts
2925
- function isSpaceNode(node) {
2926
- return isTextNode(node) && isSpace(node.content);
2927
- }
2928
-
2929
- // src/compile/utils/trimStart.ts
2930
- function trimStart(text, char) {
2931
- let start = 0;
2932
- while (text[start] === char) {
2933
- start += 1;
2934
- }
2935
- return text.substring(start);
2936
- }
2937
-
2938
- // src/compile/parse/utils/consumeSpace.ts
2939
- function consumeSpace(status) {
2940
- const start = status.i;
2941
- for (status.i; status.i < status.source.length; status.i++) {
2942
- if (!isSpaceChar(status.source, status.i)) {
2943
- return status.source.substring(start, status.i);
2944
- }
2945
- }
2946
- return "";
2947
- }
2948
-
2949
- // src/compile/parse/addSpaceElement.ts
2950
- function addSpaceElement(parent, status) {
2951
- const content = consumeSpace(status);
2952
- if (content) {
2953
- const previousNode = parent.children[parent.children.length - 1];
2954
- if (previousNode && isTextNode(previousNode)) {
2955
- previousNode.content += content;
2956
- } else {
2957
- const space = {
2958
- type: "text",
2959
- content
2960
- };
2961
- parent.children.push(space);
2962
- }
2963
- }
2964
- }
2965
-
2966
- // src/compile/parse/utils/accept.ts
2967
- function accept(value, status, advance = true) {
2968
- const check = status.source.substring(status.i, status.i + value.length);
2969
- if (check == value) {
2970
- status.i += advance ? value.length : 0;
2971
- return true;
2972
- }
2973
- return false;
2974
- }
2975
-
2976
- // src/compile/parse/parseInlineScript.ts
2977
- function parseInlineScript(status) {
2978
- const start = status.i;
2979
- let braceCount = 0;
2980
- while (status.i < status.source.length) {
2981
- if (accept("{", status)) {
2982
- braceCount += 1;
2983
- } else if (accept("}", status)) {
2984
- if (braceCount > 0) {
2985
- braceCount -= 1;
2986
- } else {
2987
- return status.source.substring(start, status.i - 1);
2988
- }
2989
- } else if (accept('"', status) || accept("'", status)) {
2990
- const char = status.source[status.i - 1];
2991
- for (let j = status.i; j < status.source.length; j++) {
2992
- if (status.source[j] === char && status.source[j - 1] !== "\\") {
2993
- status.i = j + 1;
2994
- break;
2995
- }
2996
- }
2997
- } else if (accept("`", status)) {
2998
- const char = status.source[status.i - 1];
2999
- let level2 = 0;
3000
- for (let j = status.i; j < status.source.length; j++) {
3001
- if (status.source[j] === char && status.source[j - 1] !== "\\" && level2 === 0) {
3002
- status.i = j + 1;
3003
- break;
3004
- } else if (status.source[j] === "{" && (level2 > 0 || status.source[j - 1] === "$")) {
3005
- level2 += 1;
3006
- } else if (status.source[j] === "}" && level2 > 0) {
3007
- level2 -= 1;
3008
- }
3009
- }
3010
- } else if (accept("//", status)) {
3011
- status.i = status.source.indexOf("\n", status.i) + 1;
3012
- } else if (accept("/*", status)) {
3013
- status.i = status.source.indexOf("*/", status.i) + 2;
3014
- } else {
3015
- status.i += 1;
3016
- }
3017
- }
3018
- return "";
3019
- }
3020
-
3021
- // src/compile/parse/utils/isAlphaNumericChar.ts
3022
- function isAlphaNumericChar(text, index) {
3023
- let code = text.charCodeAt(index);
3024
- return (
3025
- // 0-9
3026
- code > 47 && code < 58 || // A-Z
3027
- code > 64 && code < 91 || // a-z
3028
- code > 96 && code < 123
3029
- );
3030
- }
3031
-
3032
- // src/compile/parse/utils/consumeAlphaNumeric.ts
3033
- function consumeAlphaNumeric(status) {
3034
- const start = status.i;
3035
- for (status.i; status.i < status.source.length; status.i++) {
3036
- if (!isAlphaNumericChar(status.source, status.i)) {
3037
- return status.source.substring(start, status.i);
3038
- }
3039
- }
3040
- return "";
3041
- }
3042
-
3043
- // src/compile/parse/utils/consumeUntil.ts
3044
- function consumeUntil(chars, status) {
3045
- const start = status.i;
3046
- for (status.i; status.i < status.source.length; status.i++) {
3047
- if (chars.includes(status.source[status.i])) {
3048
- return status.source.substring(start, status.i);
3049
- }
3050
- }
3051
- return "";
3052
- }
3053
-
3054
- // src/compile/parse/parseTag.ts
3055
- function parseTag(status) {
3056
- accept("<", status);
3057
- let closeTag = accept("/", status);
3058
- consumeSpace(status);
3059
- let special = accept(":", status);
3060
- let tagName = consumeAlphaNumeric(status);
3061
- if (special) {
3062
- tagName = ":" + tagName;
3063
- }
3064
- if (closeTag) {
3065
- tagName = "/" + tagName;
3066
- }
3067
- consumeSpace(status);
3068
- let attributes = parseTagAttributes(status);
3069
- let selfClosed = false;
3070
- if (accept("/>", status)) {
3071
- selfClosed = true;
3072
- } else {
3073
- accept(">", status);
3074
- }
3075
- if (closeTag) {
3076
- selfClosed = true;
3077
- }
3078
- return {
3079
- type: special ? "special" : "element",
3080
- tagName,
3081
- selfClosed: selfClosed || void 0,
3082
- closed: selfClosed || void 0,
3083
- attributes,
3084
- children: []
3085
- };
3086
- }
3087
- function parseTagAttributes(status) {
3088
- let attributes = [];
3089
- while (status.i < status.source.length) {
3090
- consumeSpace(status);
3091
- if (accept("@//", status)) {
3092
- status.i = status.source.indexOf("\n", status.i) + 1;
3093
- } else if (accept("@/*", status)) {
3094
- status.i = status.source.indexOf("*/", status.i) + 2;
3095
- } else if (accept("/>", status, false) || accept(">", status, false)) {
3096
- break;
3097
- } else {
3098
- const attribute = parseAttribute(status);
3099
- attributes.push(attribute);
3100
- }
3101
- }
3102
- return attributes;
3103
- }
3104
- function parseAttribute(status) {
3105
- let name = consumeUntil("= \r\n/>", status);
3106
- let value = void 0;
3107
- consumeSpace(status);
3108
- if (accept("=", status)) {
3109
- consumeSpace(status);
3110
- value = parseAttributeValue(status);
3111
- }
3112
- return { name, value };
3113
- }
3114
- function parseAttributeValue(status) {
3115
- if (accept('"', status)) {
3116
- const value = consumeUntil('"', status);
3117
- accept('"', status);
3118
- return `"${value}"`;
3119
- } else if (accept("'", status)) {
3120
- const value = consumeUntil("'", status);
3121
- accept("'", status);
3122
- return `'${value}'`;
3123
- } else if (accept("{", status)) {
3124
- const value = parseInlineScript(status);
3125
- return `{${value}}`;
3126
- } else {
3127
- let value = consumeUntil(" \r\n>", status);
3128
- if (status.source.substring(status.i - 1, status.i + 1) === "/>") {
3129
- value = value.substring(0, value.length - 1);
3130
- status.i -= 1;
3131
- }
3132
- return value;
3133
- }
3134
- }
3135
-
3136
- // src/compile/parse/slottifyChildNodes.ts
3137
- function slottifyChildNodes(node) {
3138
- const nonFillNodes = node.children.filter((c) => !isFillNode(c));
3139
- if (nonFillNodes.length) {
3140
- let defaultFillNode = node.children.find(
3141
- (n) => isFillNode(n) && !n.attributes.find((a) => a.name === "name")
3142
- );
3143
- if (!defaultFillNode) {
3144
- defaultFillNode = {
3145
- type: "special",
3146
- tagName: ":fill",
3147
- attributes: [],
3148
- children: nonFillNodes
3149
- };
3150
- node.children.unshift(defaultFillNode);
3151
- }
3152
- }
3153
- node.children = node.children.filter((c) => isFillNode(c));
3154
- }
3155
- function isFillNode(n) {
3156
- return isSpecialNode(n) && n.tagName === ":fill";
3157
- }
3158
-
3159
- // src/compile/parse/utils/addError.ts
3160
- function addError(status, message, start = status.i) {
3161
- let line = 1;
3162
- let lastLineStart = 0;
3163
- for (let i = 0; i < start; i++) {
3164
- if (status.source[i] === "\n") {
3165
- line += 1;
3166
- lastLineStart = i + 1;
3167
- }
3168
- }
3169
- let column = start - lastLineStart;
3170
- status.errors.push({ message, start, line, column });
3171
- }
3172
-
3173
- // src/compile/parse/parseElement.ts
3174
- function parseElement(status) {
3175
- const start = status.i;
3176
- const element = parseTag(status);
3177
- if (element.tagName.startsWith("/")) {
3178
- addError(status, `Non matching close tag: ${element.tagName.substring(1)}`, start);
3179
- return element;
3180
- }
3181
- if (voidTags_default.includes(element.tagName)) {
3182
- checkVoidElement(status, element);
3183
- }
3184
- if (!element.selfClosed && !voidTags_default.includes(element.tagName)) {
3185
- const current = status.components[status.components.length - 1];
3186
- current.stack ??= [];
3187
- current.stack.push(element);
3188
- while (status.i < status.source.length) {
3189
- addSpaceElement(element, status);
3190
- if (accept("}", status, false)) {
3191
- break;
3192
- } else if (accept("<!--", status)) {
3193
- status.i = status.source.indexOf("-->", status.i) + 3;
3194
- } else if (accept("@//", status)) {
3195
- status.i = status.source.indexOf("\n", status.i) + 1;
3196
- } else if (accept("@/*", status)) {
3197
- status.i = status.source.indexOf("*/", status.i) + 2;
3198
- } else if (accept("</", status, false)) {
3199
- if (checkCloseTag(status, element, current)) {
3200
- break;
3201
- }
3202
- } else if (accept("<", status, false)) {
3203
- const child = parseElement(status);
3204
- element.children.push(child);
3205
- } else if (accept("@", status, false)) {
3206
- parseControl(status, element);
3207
- } else {
3208
- parseText(status, element);
3209
- }
3210
- }
3211
- current.stack.pop();
3212
- }
3213
- if (!element.tagName.startsWith(":") && /[A-Z]/.test(element.tagName[0])) {
3214
- element.type = "component";
3215
- slottifyChildNodes(element);
3216
- }
3217
- if (isSpecialNode(element)) {
3218
- if (element.tagName === ":slot") {
3219
- slottifyChildNodes(element);
3220
- const current = status.components[status.components.length - 1];
3221
- current.slotProps ??= [];
3222
- current.slotProps.push(element.attributes.find((a) => a.name === "name")?.name ?? "default");
3223
- } else if (element.tagName === ":component") {
3224
- const selfAttribute = element.attributes.find((a) => a.name === "self");
3225
- if (selfAttribute && selfAttribute.value) {
3226
- element.type = "component";
3227
- slottifyChildNodes(element);
3228
- const selfValue = trimMatched(selfAttribute.value, "{", "}");
3229
- const replace = {
3230
- type: "control",
3231
- operation: "@replace",
3232
- statement: selfValue,
3233
- children: [element]
3234
- };
3235
- const replaceGroup = {
3236
- type: "control",
3237
- operation: "@replace group",
3238
- statement: selfValue,
3239
- children: [replace]
3240
- };
3241
- return replaceGroup;
3242
- } else {
3243
- addError(status, ":component element must have a self attribute", start);
3244
- }
3245
- }
3246
- }
3247
- if (!element.closed && !voidTags_default.includes(element.tagName)) {
3248
- addError(status, `Unclosed non-void element: ${element.tagName}`, start);
3249
- }
3250
- return element;
3251
- }
3252
- function parseText(status, element) {
3253
- const start = status.i;
3254
- let end = -1;
3255
- for (let j = status.i; j < status.source.length; j++) {
3256
- if (status.source[j] === "}") {
3257
- end = j;
3258
- } else if (status.source[j] === "{") {
3259
- let level = 0;
3260
- for (let k = j; k < status.source.length; k++) {
3261
- const char = status.source[k];
3262
- const nextChar = status.source[k + 1];
3263
- if (char === "/" && nextChar === "/") {
3264
- k = status.source.indexOf("\n", k);
3265
- } else if (char === "/" && nextChar === "*") {
3266
- k = status.source.indexOf("*/", k) + 1;
3267
- } else if (char === '"' || char === "'") {
3268
- for (let l = k + 1; l < status.source.length; l++) {
3269
- if (status.source[l] === char && status.source[l - 1] !== "\\") {
3270
- k = l;
3271
- break;
3272
- }
3273
- }
3274
- } else if (char === "`") {
3275
- let level2 = 0;
3276
- for (let l = k + 1; l < status.source.length; l++) {
3277
- if (status.source[l] === char && status.source[l - 1] !== "\\" && level2 === 0) {
3278
- k = l;
3279
- break;
3280
- } else if (status.source[l] === "{" && (level2 > 0 || status.source[l - 1] === "$")) {
3281
- level2 += 1;
3282
- } else if (status.source[l] === "}" && level2 > 0) {
3283
- level2 -= 1;
3284
- }
3285
- }
3286
- } else if (char === "{") {
3287
- level += 1;
3288
- } else if (char === "}") {
3289
- level -= 1;
3290
- if (level === 0) {
3291
- j = k;
3292
- break;
3293
- }
3294
- }
3295
- }
3296
- } else if (status.source[j] === "<") {
3297
- end = j;
3298
- } else if (status.source[j] === "@") {
3299
- for (let k = j - 1; k > status.i; k--) {
3300
- if (status.source[k] === "\n") {
3301
- end = j;
3302
- break;
3303
- } else if (!isSpaceChar(status.source, k)) {
3304
- break;
3305
- }
3306
- }
3307
- }
3308
- if (end !== -1) {
3309
- break;
3310
- }
3311
- }
3312
- if (end !== -1) {
3313
- const content = status.source.substring(start, end).trimEnd();
3314
- const spaceContent = status.source.substring(start + content.length, end);
3315
- if (content || spaceContent) {
3316
- const previousNode = element.children[element.children.length - 1];
3317
- if (previousNode && isTextNode(previousNode)) {
3318
- previousNode.content += content + spaceContent;
3319
- } else {
3320
- const text = {
3321
- type: "text",
3322
- content: content + spaceContent
3323
- };
3324
- element.children.push(text);
3325
- }
3326
- }
3327
- status.i = end;
3328
- } else {
3329
- status.i += 1;
3330
- }
3331
- }
3332
- function checkVoidElement(status, element) {
3333
- let i = status.i;
3334
- consumeSpace(status);
3335
- if (accept("</", status)) {
3336
- consumeSpace(status);
3337
- if (accept(element.tagName, status)) {
3338
- addError(status, `Closed void element: ${element.tagName}`, i);
3339
- consumeSpace(status);
3340
- accept(">", status);
3341
- return;
3342
- }
3343
- }
3344
- status.i = i;
3345
- }
3346
- function checkCloseTag(status, element, current) {
3347
- const start = status.i;
3348
- accept("</", status);
3349
- consumeSpace(status);
3350
- let special = accept(":", status);
3351
- let closingTagName = consumeAlphaNumeric(status);
3352
- if (special) {
3353
- closingTagName = ":" + closingTagName;
3354
- }
3355
- consumeSpace(status);
3356
- accept(">", status);
3357
- let found = false;
3358
- if (current.stack) {
3359
- for (let i = current.stack.length - 1; i >= 0; i--) {
3360
- if (closingTagName === current.stack[i].tagName) {
3361
- current.stack[i].closed = true;
3362
- found = true;
3363
- break;
3364
- }
3365
- }
3366
- }
3367
- if (!found) {
3368
- addError(
3369
- status,
3370
- `Non matching close tag: ${closingTagName} (expected ${element.tagName})`,
3371
- start
3372
- );
3373
- }
3374
- return found;
3375
- }
3376
-
3377
- // src/compile/parse/parseControl.ts
3378
- var controlOperations = [
3379
- "@if",
3380
- "@else",
3381
- "@for",
3382
- "@key",
3383
- "@switch",
3384
- "@case",
3385
- "@default",
3386
- "@await",
3387
- "@then",
3388
- "@catch",
3389
- "@replace",
3390
- "@html",
3391
- "@const",
3392
- "@console",
3393
- "@debugger",
3394
- "@function",
3395
- "@async function"
3396
- ];
3397
- var standaloneOperations = [
3398
- "@key",
3399
- "@html",
3400
- "@const",
3401
- "@console",
3402
- "@debugger",
3403
- "@function",
3404
- "@async function"
3405
- ];
3406
- function parseControl(status, parentNode) {
3407
- const node = parseControlOpen(status);
3408
- if (!node) {
3409
- return;
3410
- }
3411
- if (standaloneOperations.includes(node.operation)) {
3412
- wrangleControlNode(node, parentNode);
3413
- return;
3414
- }
3415
- while (status.i < status.source.length) {
3416
- addSpaceElement(node, status);
3417
- if (accept("}", status)) {
3418
- break;
3419
- } else if (accept("<", status, false)) {
3420
- const child = parseElement(status);
3421
- node.children.push(child);
3422
- } else if (accept("@//", status)) {
3423
- status.i = status.source.indexOf("\n", status.i) + 1;
3424
- } else if (accept("@/*", status)) {
3425
- status.i = status.source.indexOf("*/", status.i) + 2;
3426
- } else if (accept("@", status, false)) {
3427
- parseControl(status, node);
3428
- } else if (accept("case", status, false) || accept("key", status, false)) {
3429
- parseControl(status, node);
3430
- } else {
3431
- const char = status.source[status.i];
3432
- addError(status, `Unexpected token in control block: ${char}`, status.i);
3433
- break;
3434
- }
3435
- }
3436
- wrangleControlNode(node, parentNode);
3437
- parseControlBranches(status, parentNode);
3438
- }
3439
- function parseControlOpen(status) {
3440
- const start = status.i;
3441
- let operation = "";
3442
- for (status.i; status.i < status.source.length; status.i++) {
3443
- const char = status.source[status.i];
3444
- if (isSpaceChar(status.source, status.i) && operation !== "@async" || accept(":", status) && operation === "default" || accept(".", status) && operation === "@console" || accept("(", status, false) && operation === "@html") {
3445
- break;
3446
- }
3447
- operation += char;
3448
- }
3449
- if (!operation.startsWith("@")) {
3450
- operation = "@" + operation;
3451
- }
3452
- let statement = "";
3453
- if (controlOperations.includes(operation)) {
3454
- statement = parseControlStatement(start, operation, status);
3455
- if (operation === "@function" || operation === "@async function") {
3456
- statement += ` {${parseInlineScript(status)}}`;
3457
- accept("}", status);
3458
- }
3459
- if (operation === "@replace" || operation === "@html") {
3460
- statement = trimMatched(statement.substring(statement.indexOf("(")).trim(), "(", ")");
3461
- }
3462
- } else {
3463
- addError(status, `Unknown operation: ${operation}`, status.i);
3464
- return null;
3465
- }
3466
- return {
3467
- type: "control",
3468
- operation,
3469
- statement,
3470
- children: []
3471
- };
3472
- }
3473
- function parseControlStatement(start, operation, status) {
3474
- let parenCount = 0;
3475
- while (status.i < status.source.length) {
3476
- if (accept("(", status)) {
3477
- parenCount += 1;
3478
- } else if (accept(")", status)) {
3479
- parenCount -= 1;
3480
- } else if (accept("{", status) || accept("\n", status) && standaloneOperations.includes(operation)) {
3481
- if (parenCount === 0) {
3482
- return trimStart(status.source.substring(start, status.i - 1).trim(), "@");
3483
- }
3484
- } else if (accept('"', status) || accept("'", status)) {
3485
- const char = status.source[status.i - 1];
3486
- for (let j = status.i + 1; j < status.source.length; j++) {
3487
- if (status.source[j] === char && status.source[j - 1] !== "\\") {
3488
- status.i = j + 1;
3489
- break;
3490
- }
3491
- }
3492
- } else if (accept("`", status)) {
3493
- let level2 = 0;
3494
- for (let j = status.i + 1; j < status.source.length; j++) {
3495
- if (status.source[j] === "`" && status.source[j - 1] !== "\\" && level2 === 0) {
3496
- status.i = j + 1;
3497
- break;
3498
- } else if (status.source[j] === "{" && (level2 > 0 || status.source[j - 1] === "$")) {
3499
- level2 += 1;
3500
- } else if (status.source[j] === "}" && level2 > 0) {
3501
- level2 -= 1;
3502
- }
3503
- }
3504
- } else if (accept("//", status)) {
3505
- status.i = status.source.indexOf("\n", status.i) + 1;
3506
- } else if (accept("/*", status)) {
3507
- status.i = status.source.indexOf("*/", status.i) + 2;
3508
- } else {
3509
- status.i += 1;
3510
- }
3511
- }
3512
- return "";
3513
- }
3514
- function wrangleControlNode(node, parentNode) {
3515
- if (node.operation === "@if") {
3516
- const ifGroup = {
3517
- type: "control",
3518
- operation: "@if group",
3519
- statement: "",
3520
- children: [node]
3521
- };
3522
- parentNode.children.push(ifGroup);
3523
- } else if (node.operation === "@else") {
3524
- if (/^else\s+if/.test(node.statement)) {
3525
- node.operation = "@else if";
3526
- }
3527
- for (let i = parentNode.children.length - 1; i >= 0; i--) {
3528
- const lastChild = parentNode.children[i];
3529
- if (isControlNode(lastChild) && lastChild.operation === "@if group") {
3530
- lastChild.children.push(node);
3531
- break;
3532
- }
3533
- }
3534
- } else if (node.operation === "@for") {
3535
- const forGroup = {
3536
- type: "control",
3537
- operation: "@for group",
3538
- statement: "",
3539
- children: [node]
3540
- };
3541
- parentNode.children.push(forGroup);
3542
- } else if (node.operation === "@switch") {
3543
- node.operation = "@switch group";
3544
- parentNode.children.push(node);
3545
- } else if (node.operation === "@await") {
3546
- const awaitGroup = {
3547
- type: "control",
3548
- operation: "@await group",
3549
- statement: "",
3550
- children: [node]
3551
- };
3552
- parentNode.children.push(awaitGroup);
3553
- } else if (node.operation === "@then" || node.operation === "@catch") {
3554
- for (let i = parentNode.children.length - 1; i >= 0; i--) {
3555
- const lastChild = parentNode.children[i];
3556
- if (isControlNode(lastChild) && lastChild.operation === "@await group") {
3557
- lastChild.children.push(node);
3558
- break;
3559
- }
3560
- }
3561
- } else if (node.operation === "@replace") {
3562
- const replaceGroup = {
3563
- type: "control",
3564
- operation: "@replace group",
3565
- statement: "",
3566
- children: [node]
3567
- };
3568
- parentNode.children.push(replaceGroup);
3569
- } else if (node.operation === "@html") {
3570
- const htmlGroup = {
3571
- type: "control",
3572
- operation: "@html group",
3573
- statement: "",
3574
- children: [node]
3575
- };
3576
- parentNode.children.push(htmlGroup);
3577
- } else {
3578
- parentNode.children.push(node);
3579
- }
3580
- }
3581
- function parseControlBranches(status, parentNode) {
3582
- let gotAnotherBranch = true;
3583
- while (gotAnotherBranch) {
3584
- let start = status.i;
3585
- status.i += 1;
3586
- consumeSpace(status);
3587
- if (accept("else", status, false) || accept("case", status, false) || accept("default", status, false) || accept("then", status, false) || accept("catch", status, false)) {
3588
- parseControl(status, parentNode);
3589
- } else {
3590
- gotAnotherBranch = false;
3591
- status.i = start;
3592
- }
3593
- }
3594
- }
3595
-
3596
- // src/compile/parse/parseMarkup.ts
3597
- function parseMarkup(status, source) {
3598
- const current = status.components.at(-1);
3599
- if (!current) return;
3600
- while (status.i < source.length) {
3601
- if (accept("}", status, false)) {
3602
- return;
3603
- } else if (accept("<!--", status)) {
3604
- status.i = status.source.indexOf("-->", status.i) + 3;
3605
- } else if (accept("@//", status)) {
3606
- status.i = status.source.indexOf("\n", status.i) + 1;
3607
- } else if (accept("@/*", status)) {
3608
- status.i = status.source.indexOf("*/", status.i) + 2;
3609
- } else if (isSpaceChar(status.source, status.i)) {
3610
- current.markup ??= { type: "root", children: [] };
3611
- const text = { type: "text", content: consumeSpace(status) };
3612
- current.markup.children.push(text);
3613
- } else if (accept("<", status, false)) {
3614
- current.markup ??= { type: "root", children: [] };
3615
- const element = parseElement(status);
3616
- current.markup.children.push(element);
3617
- } else if (accept("@", status, false)) {
3618
- current.markup ??= { type: "root", children: [] };
3619
- parseControl(status, current.markup);
3620
- } else {
3621
- status.i += 1;
3622
- }
3623
- }
3624
- }
3625
-
3626
- // src/compile/utils/hash.ts
3627
- var returnRegex = /\r/g;
3628
- function hash(input) {
3629
- input = input.replace(returnRegex, "");
3630
- let hash2 = 5381;
3631
- let i = input.length;
3632
- while (i--) {
3633
- hash2 = (hash2 << 5) - hash2 ^ input.charCodeAt(i);
3634
- }
3635
- return (hash2 >>> 0).toString(36);
3636
- }
3637
-
3638
- // src/compile/parse/utils/expect.ts
3639
- function expect(value, status, advance = true) {
3640
- if (status.i < status.source.length) {
3641
- if (status.source.substring(status.i, status.i + value.length) == value) {
3642
- status.i += advance ? value.length : 0;
3643
- return true;
3644
- } else {
3645
- addError(status, `Expected ${value}`);
3646
- }
3647
- } else {
3648
- addError(status, "Expected token");
3649
- }
3650
- return false;
3651
- }
3652
-
3653
- // src/compile/parse/parseStyles.ts
3654
- function parseStyles(source, status) {
3655
- const current = status.components.at(-1);
3656
- if (!current) return;
3657
- current.style = {
3658
- global: false,
3659
- blocks: [],
3660
- hash: hash(source)
3661
- };
3662
- const styleStatus = {
3663
- source,
3664
- i: 0,
3665
- marker: 0,
3666
- level: 0,
3667
- imports: [],
3668
- script: "",
3669
- components: [],
3670
- errors: []
3671
- };
3672
- while (styleStatus.i < styleStatus.source.length) {
3673
- if (isSpaceChar(styleStatus.source, styleStatus.i)) {
3674
- consumeSpace(styleStatus);
3675
- } else {
3676
- const block = parseStyleBlock(styleStatus);
3677
- if (block) {
3678
- current.style.blocks.push(block);
3679
- } else {
3680
- break;
3681
- }
3682
- }
3683
- }
3684
- status.errors = status.errors.concat(styleStatus.errors);
3685
- }
3686
- function parseStyleBlock(status) {
3687
- const selector = consumeUntil("{", status).trim();
3688
- if (expect("{", status)) {
3689
- const block = {
3690
- selector,
3691
- attributes: [],
3692
- children: []
3693
- };
3694
- consumeSpace(status);
3695
- while (status.source[status.i] !== "}") {
3696
- let nextColon = status.source.indexOf(":", status.i);
3697
- if (nextColon === -1) nextColon = status.source.length;
3698
- let nextOpenBrace = status.source.indexOf("{", status.i);
3699
- if (nextOpenBrace === -1) nextOpenBrace = status.source.length;
3700
- if (nextColon < nextOpenBrace) {
3701
- const attribute = parseStyleAttribute(status);
3702
- block.attributes.push(attribute);
3703
- } else if (nextOpenBrace < nextColon) {
3704
- const child = parseStyleBlock(status);
3705
- if (child) {
3706
- block.children.push(child);
3707
- } else {
3708
- break;
3709
- }
3710
- } else {
3711
- return block;
3712
- }
3713
- consumeSpace(status);
3714
- }
3715
- accept("}", status);
3716
- return block;
3717
- }
3718
- }
3719
- function parseStyleAttribute(status) {
3720
- const name = consumeUntil(":", status).trim();
3721
- accept(":", status);
3722
- const value = consumeUntil(";", status).trim();
3723
- accept(";", status);
3724
- return {
3725
- name,
3726
- value
3727
- };
3728
- }
3729
-
3730
- // src/compile/types/nodes/isComponentNode.ts
3731
- function isComponentNode(node) {
3732
- return node.type === "component";
3733
- }
3734
-
3735
- // src/compile/types/nodes/isParentNode.ts
3736
- function isParentNode(node) {
3737
- return "children" in node;
3738
- }
3739
-
3740
- // src/compile/parse/scopeStyles.ts
3741
- function scopeStyles(status) {
3742
- let selectors = [];
3743
- for (let component of status.components) {
3744
- if (component.style && component.markup) {
3745
- for (let block of component.style.blocks) {
3746
- collectStyleSelectors(block, selectors);
3747
- }
3748
- scopeStylesOnNode(component.markup, selectors);
3749
- }
3750
- }
3751
- }
3752
- function scopeStylesOnNode(node, selectors) {
3753
- if (isElementNode(node) || isComponentNode(node)) {
3754
- let scopeStyles2 = selectors.includes(node.tagName);
3755
- if (!scopeStyles2) {
3756
- for (let a of node.attributes) {
3757
- if (a.name === "class" || a.name === ":class") {
3758
- scopeStyles2 = true;
3759
- } else if (a.name === "id" && a.value) {
3760
- scopeStyles2 = selectors.includes(`#${trimQuotes(a.value)}`);
3761
- } else if (a.name === "class" && a.value) {
3762
- scopeStyles2 = selectors.includes(`.${trimQuotes(a.value)}`);
3763
- }
3764
- if (scopeStyles2) {
3765
- break;
3766
- }
3767
- }
3768
- }
3769
- node.scopeStyles = scopeStyles2;
3770
- }
3771
- if (isParentNode(node)) {
3772
- for (let child of node.children) {
3773
- scopeStylesOnNode(child, selectors);
3774
- }
3775
- }
3776
- }
3777
- function collectStyleSelectors(block, selectors) {
3778
- for (let s of block.selector.split(/[\s*,>+~]/)) {
3779
- selectors.push(s);
3780
- }
3781
- }
3782
-
3783
- // src/compile/parse/parseCode.ts
3784
- function parseCode(source) {
3785
- const status = {
3786
- source,
3787
- i: 0,
3788
- marker: 0,
3789
- level: 0,
3790
- imports: [],
3791
- script: "",
3792
- components: [],
3793
- errors: []
3794
- };
3795
- for (status.i; status.i < source.length; status.i++) {
3796
- if (consumeScriptComments(status)) {
3797
- } else if (status.source[status.i] === "{") {
3798
- status.level += 1;
3799
- } else if (status.source[status.i] === "}") {
3800
- status.level -= 1;
3801
- if (status.level === 0) {
3802
- parseComponentEnd(status);
3803
- }
3804
- } else if (accept("function", status)) {
3805
- if (consumeSpace(status)) {
3806
- if (/[A-Z]/.test(source[status.i])) {
3807
- parseComponentStart(status);
3808
- } else {
3809
- status.i--;
3810
- }
3811
- }
3812
- } else if (accept("const", status)) {
3813
- if (consumeSpace(status)) {
3814
- if (/[A-Z]/.test(source[status.i])) {
3815
- const start = status.i;
3816
- consumeAlphaNumeric(status);
3817
- consumeSpace(status);
3818
- if (accept("=", status)) {
3819
- consumeSpace(status);
3820
- if (accept("(", status, false)) {
3821
- status.i = start;
3822
- parseComponentStart(status);
3823
- }
3824
- }
3825
- } else {
3826
- status.i--;
3827
- }
3828
- }
3829
- } else if (accept("export", status)) {
3830
- const start = status.i;
3831
- if (consumeSpace(status) && accept("default", status) && consumeSpace(status) && accept("(", status, false)) {
3832
- parseComponentStart(status);
3833
- } else {
3834
- status.i = start;
3835
- }
3836
- } else if (accept("@render", status, false)) {
3837
- parseComponentRender(status);
3838
- } else if (accept("@style", status, false)) {
3839
- parseComponentStyle(status);
3840
- }
3841
- }
3842
- status.script += source.substring(status.marker, source.length);
3843
- scopeStyles(status);
3844
- const ok = !status.errors.length;
3845
- if (!ok) {
3846
- status.errors = status.errors.sort((a, b) => a.start - b.start);
3847
- }
3848
- return {
3849
- ok,
3850
- errors: status.errors,
3851
- template: ok ? {
3852
- imports: status.imports,
3853
- script: status.script,
3854
- components: status.components.map((c) => {
3855
- return {
3856
- start: c.start,
3857
- name: c.name,
3858
- default: c.default,
3859
- params: c.params,
3860
- markup: c.markup,
3861
- style: c.style,
3862
- props: c.props,
3863
- contextProps: c.contextProps,
3864
- slotProps: c.slotProps
3865
- };
3866
- })
3867
- } : void 0
3868
- };
3869
- }
3870
- function parseComponentStart(status) {
3871
- let source = status.source.substring(0, status.i);
3872
- let def = /export\s+default\s+(function\s+|const\s+)*$/.test(source);
3873
- let isConst = /const\s+$/.test(source);
3874
- let isAnon = /export default\s+$/.test(source);
3875
- status.components.push({
3876
- start: status.i,
3877
- name: consumeAlphaNumeric(status),
3878
- default: def
3879
- });
3880
- const current = status.components.at(-1);
3881
- if (!current) return;
3882
- let start = -1;
3883
- let end = -1;
3884
- let level = 0;
3885
- for (status.i; status.i < status.source.length; status.i++) {
3886
- const char = status.source[status.i];
3887
- if (consumeScriptComments(status)) {
3888
- } else if (char === "(") {
3889
- level += 1;
3890
- if (start === -1) {
3891
- start = status.i + 1;
3892
- }
3893
- } else if (char === ")") {
3894
- level -= 1;
3895
- if (level === 0) {
3896
- end = status.i;
3897
- break;
3898
- }
3899
- }
3900
- }
3901
- status.script += status.source.substring(status.marker, start) + "/* @params */";
3902
- current.params = status.source.substring(start, end).trim() || void 0;
3903
- status.marker = end;
3904
- status.i = status.marker;
3905
- accept(")", status);
3906
- consumeSpace(status);
3907
- if (isConst || isAnon) {
3908
- accept("=>", status);
3909
- consumeSpace(status);
3910
- }
3911
- accept("{", status);
3912
- status.level += 1;
3913
- const space = consumeSpace(status);
3914
- status.script += status.source.substring(status.marker, status.i) + "/* @start */" + space;
3915
- status.marker = status.i;
3916
- status.i -= 1;
3917
- }
3918
- function parseComponentRender(status) {
3919
- const current = status.components.at(-1);
3920
- if (!current) return;
3921
- if (current.markup) {
3922
- addError(status, `Multiple @render sections`, status.i);
3923
- }
3924
- status.script += status.source.substring(status.marker, status.i) + "/* @render */";
3925
- accept("@render", status);
3926
- consumeSpace(status);
3927
- if (accept("{", status)) {
3928
- parseMarkup(status, status.source);
3929
- accept("}", status);
3930
- }
3931
- status.marker = status.i;
3932
- }
3933
- function parseComponentStyle(status) {
3934
- const current = status.components.at(-1);
3935
- if (!current) return;
3936
- if (current.style) {
3937
- addError(status, `Multiple @style sections`, status.i);
3938
- }
3939
- status.script += status.source.substring(status.marker, status.i);
3940
- let start = -1;
3941
- let end = status.source.length;
3942
- let level = 0;
3943
- let styleSource = "";
3944
- for (; status.i < status.source.length; status.i++) {
3945
- const char = status.source[status.i];
3946
- const nextChar = status.source[status.i + 1];
3947
- if (char === "/" && nextChar === "/") {
3948
- status.i = status.source.indexOf("\n", status.i);
3949
- } else if (char === "/" && nextChar === "*") {
3950
- status.i = status.source.indexOf("*/", status.i) + 1;
3951
- } else if (char === '"' || char === "'") {
3952
- styleSource += char;
3953
- for (let j = status.i + 1; j < status.source.length; j++) {
3954
- styleSource += status.source[j];
3955
- if (status.source[j] === char && status.source[j - 1] !== "\\") {
3956
- status.i = j;
3957
- break;
3958
- }
3959
- }
3960
- } else if (char === "`") {
3961
- styleSource += char;
3962
- let level2 = 0;
3963
- for (let j = status.i + 1; j < status.source.length; j++) {
3964
- styleSource += status.source[j];
3965
- if (status.source[j] === char && status.source[j - 1] !== "\\" && level2 === 0) {
3966
- status.i = j;
3967
- break;
3968
- } else if (status.source[j] === "{" && (level2 > 0 || status.source[j - 1] === "$")) {
3969
- level2 += 1;
3970
- } else if (status.source[j] === "}" && level2 > 0) {
3971
- level2 -= 1;
3972
- }
3973
- }
3974
- } else if (char === "{") {
3975
- level += 1;
3976
- if (start === -1) {
3977
- start = status.i + 1;
3978
- } else {
3979
- styleSource += char;
3980
- }
3981
- } else if (char === "}") {
3982
- level -= 1;
3983
- if (level === 0) {
3984
- end = status.i - 1;
3985
- break;
3986
- } else {
3987
- styleSource += char;
3988
- }
3989
- } else {
3990
- if (start !== -1) {
3991
- styleSource += char;
3992
- }
3993
- }
3994
- }
3995
- status.i = start;
3996
- parseStyles(styleSource.trim(), status);
3997
- status.i = end + 2;
3998
- status.marker = status.i;
3999
- }
4000
- function parseComponentEnd(status) {
4001
- const current = status.components.at(-1);
4002
- if (!current) return;
4003
- status.script += status.source.substring(status.marker, status.i);
4004
- if (status.script.endsWith("\n")) {
4005
- status.script += " /* @end */\n";
4006
- } else {
4007
- status.script += "/* @end */";
4008
- }
4009
- const componentSource = status.source.substring(current.start || 0, status.i);
4010
- current.props = getPropsUsage(componentSource);
4011
- current.contextProps = getContextUsage(componentSource);
4012
- if (current.markup && isElementNode(current.markup.children[0]) && current.markup.children[0].tagName === "html" && isSpaceNode(current.markup.children[0].children[0])) {
4013
- current.markup.children.splice(1, 1);
4014
- }
4015
- status.marker = status.i;
4016
- }
4017
- function getPropsUsage(source) {
4018
- const propsMatches = source.matchAll(/\$props\s*(?:\.([\d\w]+)|\[([^\]]+)\])/g);
4019
- const props = [];
4020
- for (let match of propsMatches) {
4021
- const name = trimQuotes(match[1] || match[2]);
4022
- if (!props.includes(name)) {
4023
- props.push(name);
4024
- }
4025
- }
4026
- return props.length ? props : void 0;
4027
- }
4028
- function getContextUsage(source) {
4029
- const contextsMatches = source.matchAll(/\$context\s*(?:\.([\d\w]+)|\[([^\]]+)\])/g);
4030
- const contexts = [];
4031
- for (let match of contextsMatches) {
4032
- const name = trimQuotes(match[1] || match[2]);
4033
- if (!contexts.includes(name)) {
4034
- contexts.push(name);
4035
- }
4036
- }
4037
- return contexts.length ? contexts : void 0;
4038
- }
4039
- function consumeScriptComments(status) {
4040
- const char = status.source[status.i];
4041
- const nextChar = status.source[status.i + 1];
4042
- if (char === "/" && nextChar === "/") {
4043
- status.i = status.source.indexOf("\n", status.i);
4044
- return true;
4045
- } else if (char === "/" && nextChar === "*") {
4046
- status.i = status.source.indexOf("*/", status.i) + 1;
4047
- return true;
4048
- } else if (char === '"' || char === "'") {
4049
- for (let j = status.i + 1; j < status.source.length; j++) {
4050
- if (status.source[j] === char && status.source[j - 1] !== "\\") {
4051
- status.i = j;
4052
- break;
4053
- }
4054
- }
4055
- return true;
4056
- } else if (char === "`") {
4057
- let level2 = 0;
4058
- for (let j = status.i + 1; j < status.source.length; j++) {
4059
- if (status.source[j] === char && status.source[j - 1] !== "\\" && level2 === 0) {
4060
- status.i = j;
4061
- break;
4062
- } else if (status.source[j] === "{" && (level2 > 0 || status.source[j - 1] === "$")) {
4063
- level2 += 1;
4064
- } else if (status.source[j] === "}" && level2 > 0) {
4065
- level2 -= 1;
4066
- }
4067
- }
4068
- return true;
4069
- }
4070
- return false;
4071
- }
4072
-
4073
- // src/compile/parse.ts
4074
- function parse(source) {
4075
- return parseCode(source);
4076
- }
4077
- // Annotate the CommonJS export names for ESM import in node:
4078
- 0 && (module.exports = {
4079
- build,
4080
- buildType,
4081
- parse
4082
- });
4083
- //# sourceMappingURL=compile.cjs.map