@torpor/view 0.0.11 → 0.0.13

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 (174) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/{ServerSlotRender-AWF3bD5B.d.cts → ServerSlotRender-t1sOutne.d.cts} +1 -1
  3. package/dist/{ServerSlotRender-AWF3bD5B.d.ts → ServerSlotRender-t1sOutne.d.ts} +1 -1
  4. package/dist/{chunk-GO2L324Q.js → chunk-T6JGCJ5T.js} +5 -2
  5. package/dist/chunk-T6JGCJ5T.js.map +1 -0
  6. package/dist/compile.cjs +42 -31
  7. package/dist/compile.cjs.map +1 -1
  8. package/dist/compile.d.cts +1 -0
  9. package/dist/compile.d.ts +1 -0
  10. package/dist/compile.js +42 -31
  11. package/dist/compile.js.map +1 -1
  12. package/dist/index.cjs +4 -1
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +2 -2
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.js +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/metafile-cjs.json +1 -1
  19. package/dist/metafile-esm.json +1 -1
  20. package/dist/ssr.cjs +4 -1
  21. package/dist/ssr.cjs.map +1 -1
  22. package/dist/ssr.d.cts +2 -2
  23. package/dist/ssr.d.ts +2 -2
  24. package/dist/ssr.js +1 -1
  25. package/dist/ssr.js.map +1 -1
  26. package/package.json +6 -6
  27. package/scripts/buildTestOutput.ts +2 -121
  28. package/src/compile/build/client/buildAddFragment.ts +1 -1
  29. package/src/compile/build/client/buildAwaitNode.ts +1 -1
  30. package/src/compile/build/client/buildComponentNode.ts +1 -1
  31. package/src/compile/build/client/buildControlNode.ts +1 -1
  32. package/src/compile/build/client/buildElementNode.ts +7 -1
  33. package/src/compile/build/client/buildForNode.ts +1 -1
  34. package/src/compile/build/client/buildFragment.ts +1 -1
  35. package/src/compile/build/client/buildFragmentText.ts +7 -1
  36. package/src/compile/build/client/buildHeadNode.ts +1 -1
  37. package/src/compile/build/client/buildHtmlNode.ts +1 -1
  38. package/src/compile/build/client/buildIfNode.ts +1 -1
  39. package/src/compile/build/client/buildMount.ts +1 -1
  40. package/src/compile/build/client/buildNode.ts +1 -1
  41. package/src/compile/build/client/buildReplaceNode.ts +1 -1
  42. package/src/compile/build/client/buildRootNode.ts +1 -1
  43. package/src/compile/build/client/buildRun.ts +1 -1
  44. package/src/compile/build/client/buildScriptNode.ts +1 -1
  45. package/src/compile/build/client/buildSlotNode.ts +1 -1
  46. package/src/compile/build/client/buildSwitchNode.ts +1 -1
  47. package/src/compile/build/client/buildTextNode.ts +1 -1
  48. package/src/compile/build/client/replaceForVarNames.ts +1 -1
  49. package/src/compile/build/server/buildServerAwaitNode.ts +1 -1
  50. package/src/compile/build/server/buildServerComponentNode.ts +1 -1
  51. package/src/compile/build/server/buildServerControlNode.ts +1 -1
  52. package/src/compile/build/server/buildServerElementNode.ts +9 -1
  53. package/src/compile/build/server/buildServerForNode.ts +1 -1
  54. package/src/compile/build/server/buildServerHtmlNode.ts +1 -1
  55. package/src/compile/build/server/buildServerIfNode.ts +1 -1
  56. package/src/compile/build/server/buildServerNode.ts +5 -1
  57. package/src/compile/build/server/buildServerReplaceNode.ts +1 -1
  58. package/src/compile/build/server/buildServerRootNode.ts +5 -1
  59. package/src/compile/build/server/buildServerScriptNode.ts +1 -1
  60. package/src/compile/build/server/buildServerSlotNode.ts +1 -1
  61. package/src/compile/build/server/buildServerSpecialNode.ts +1 -1
  62. package/src/compile/build/server/buildServerSwitchNode.ts +1 -1
  63. package/src/compile/build/server/buildServerTextNode.ts +1 -1
  64. package/src/compile/build/utils/isFullyReactive.ts +1 -1
  65. package/src/compile/build/utils/isReactive.ts +1 -1
  66. package/src/compile/build/utils/isReactiveAttribute.ts +1 -1
  67. package/src/compile/parse/addSpaceElement.ts +4 -1
  68. package/src/compile/parse/parseCode.ts +4 -0
  69. package/src/compile/parse/parseControl.ts +4 -1
  70. package/src/compile/parse/parseImports.ts +1 -1
  71. package/src/compile/parse/parseMarkup.ts +1 -1
  72. package/src/compile/parse/parseStyles.ts +1 -1
  73. package/src/compile/parse/scopeStyles.ts +13 -21
  74. package/src/compile/parse/slottifyChildNodes.ts +1 -1
  75. package/src/compile/parse/utils/addError.ts +5 -1
  76. package/src/compile/parse/utils/consumeUntil.ts +1 -1
  77. package/src/compile/parse/utils/isAlphaNumeric.ts +1 -1
  78. package/src/compile/parse/utils/isAlphaNumericChar.ts +1 -1
  79. package/src/compile/parse/utils/isSpace.ts +1 -1
  80. package/src/compile/parse/utils/isSpaceChar.ts +1 -1
  81. package/src/compile/types/nodes/TemplateNode.ts +3 -0
  82. package/src/compile/utils/Builder.ts +3 -3
  83. package/src/compile/utils/trimEnd.ts +1 -1
  84. package/src/compile/utils/trimMatched.ts +1 -1
  85. package/src/compile/utils/trimQuotes.ts +1 -1
  86. package/src/compile/utils/trimStart.ts +1 -1
  87. package/src/compile/utils/trimStartAndEnd.ts +1 -1
  88. package/src/compile/utils/voidTags.ts +1 -1
  89. package/src/debug/printHtml.ts +1 -1
  90. package/src/motion/animate.ts +1 -1
  91. package/src/render/$mount.ts +1 -1
  92. package/src/render/$run.ts +1 -1
  93. package/src/render/$serverMount.ts +1 -1
  94. package/src/render/$serverRun.ts +1 -1
  95. package/src/render/$stream.ts +1 -1
  96. package/src/render/addAnimation.ts +1 -1
  97. package/src/render/addEvent.ts +1 -1
  98. package/src/render/addFragment.ts +1 -1
  99. package/src/render/applyProps.ts +1 -1
  100. package/src/render/clearRange.ts +1 -1
  101. package/src/render/createComment.ts +1 -1
  102. package/src/render/createElement.ts +1 -1
  103. package/src/render/createFragment.ts +1 -1
  104. package/src/render/createText.ts +1 -1
  105. package/src/render/flushMountEffects.ts +1 -1
  106. package/src/render/getClasses.ts +4 -1
  107. package/src/render/hydrate.ts +1 -1
  108. package/src/render/hydrateRoot.ts +1 -1
  109. package/src/render/mount.ts +1 -1
  110. package/src/render/moveRange.ts +1 -1
  111. package/src/render/popRange.ts +1 -1
  112. package/src/render/runControl.ts +1 -1
  113. package/src/render/runControlBranch.ts +1 -1
  114. package/src/render/runList.ts +1 -1
  115. package/src/render/runListItems.ts +1 -1
  116. package/src/render/setAttribute.ts +1 -1
  117. package/src/render/setDynamicElement.ts +1 -1
  118. package/src/watch/proxyGet.ts +1 -1
  119. package/src/watch/removeEffect.ts +1 -1
  120. package/src/watch/runEffect.ts +1 -1
  121. package/src/watch/symbols.ts +1 -1
  122. package/src/watch/trackEffect.ts +1 -1
  123. package/src/watch/transferEffects.ts +1 -1
  124. package/src/watch/triggerEffects.ts +1 -1
  125. package/test/bench/components/output/Bench-client.ts +0 -204
  126. package/test/bench/components/output/Bench-server.ts +0 -130
  127. package/test/bench/components/temp/Bench-client-5fee290225ae4771aa847360006123671e8f17f1.ts +208 -0
  128. package/test/bench/components/temp/Bench-server-00cefa588803c01ca4f2741c595e4f045cdd101e.ts +130 -0
  129. package/test/build-server/components/{output/IfNested-client.ts → temp/IfNested-client-979db97eea5b4595550b9b46f297f3fbc31796d2.ts} +11 -0
  130. package/test/buildHtml.ts +1 -1
  131. package/test/buildOutputFiles.ts +47 -12
  132. package/test/class/class.test.ts +29 -6
  133. package/test/class/components/Class.torp +15 -1
  134. package/test/class/components/output/Class-client.ts +10 -6
  135. package/test/class/components/output/Class-server.ts +1 -1
  136. package/test/class/components/temp/{Class-client-600bf865c14f1052d24e1c79242f837aaf5ae5e8.ts → Class-client-8c3f9e0257cc2b687e9bb7106cccbab94a4b5adf.ts} +10 -6
  137. package/test/class/components/temp/Class-server-2218c3284845fdab80d1a41ebace9a9e2ddd6fc1.ts +17 -0
  138. package/test/component/components/temp/Header-client-ac151eea86e3f6b058fab101661e13ae73864968.ts +34 -0
  139. package/test/component/components/temp/Header-server-4f10f2332f3ca7a097517cfb938ab1e6f31d68ac.ts +17 -0
  140. package/test/console/components/temp/{Console-client-254d7d4799471401334d698b1631ab1cb5b70558.ts → Console-client-2f206752ce59e59fba9bb91263b4102fd515951e.ts} +1 -1
  141. package/test/console/components/temp/Console-server-b4b15f7a0d1d2b50d87bad4870e1b8d368707c04.ts +17 -0
  142. package/test/globalSetup.ts +1 -1
  143. package/test/helpers.ts +6 -2
  144. package/test/hydrateComponent.ts +1 -1
  145. package/test/importComponent.ts +12 -40
  146. package/test/mountComponent.ts +5 -1
  147. package/test/party/components/temp/AnswerButton-client-243454cd7bf84c648f244b3587e60d01a0401039.ts +33 -0
  148. package/test/party/components/temp/AnswerButton-server-938e46c1d2510ea37454854ef527e4aa64eb8e52.ts +16 -0
  149. package/test/party/components/temp/FunnyButton-client-2e6bec8259065b5bc9ae16d1ca93dd1bd0c56b7c.ts +40 -0
  150. package/test/party/components/temp/FunnyButton-server-e8ab55e47c735f7e42c55d2b7504dfa4190a1b40.ts +32 -0
  151. package/test/party/components/temp/Time-client-7ba4ca9322af2cb88a873c812fc776760c337c64.ts +47 -0
  152. package/test/party/components/temp/Time-server-08f66c7f3f32b13de06d75fe679cf58b5727c473.ts +31 -0
  153. package/test/party/components/temp/UserProfile-client-938bcef20a2555de22aca939022a32742ac5e729.ts +51 -0
  154. package/test/party/components/temp/UserProfile-server-9df5c59b8797fa67c479bc76450104d45e6076f9.ts +22 -0
  155. package/test/party/components/temp/UserProfileContext-client-93211cdba795b8baf926f60f5b17da90701743b3.ts +44 -0
  156. package/test/party/components/temp/UserProfileContext-server-cf58767df1e2d1dde919f59de73cdd9764bbc006.ts +20 -0
  157. package/test/slots/components/temp/Article-client-741f94eab2e96655f4c9d69ccd7d9c7cc998f4ce.ts +41 -0
  158. package/test/slots/components/temp/Article-server-a6bd47a621cc213db4313eb775a52246541dd203.ts +28 -0
  159. package/test/slots/components/temp/Header-client-e2e1e7d60b48b0841cd0c20224f520330ca96458.ts +38 -0
  160. package/test/slots/components/temp/Header-server-1c195508a91c32822da22a08576c8a30c9070636.ts +22 -0
  161. package/test/slots/components/temp/List-client-0659d999cfb48b865fe5b8aaaf2a4ddac3a8a8b6.ts +76 -0
  162. package/test/slots/components/temp/List-server-4b76485a259d054187edad8aa691d80ac918ad86.ts +25 -0
  163. package/test/special-component/components/temp/BigTitle-client-881a9f84876fb3f6d994736edb253b96e71de926.ts +32 -0
  164. package/test/special-component/components/temp/BigTitle-server-9efc738f5eb131a4b859c4a99a8e255d93834e9a.ts +20 -0
  165. package/test/special-component/components/temp/SmallTitle-client-25b3097b7ae47848dd82967403faf7745fc43388.ts +32 -0
  166. package/test/special-component/components/temp/SmallTitle-server-fc105db9a91b83644d67e049ce583a3d1a61f50c.ts +20 -0
  167. package/tsconfig.json +1 -1
  168. package/tsup.config.ts +7 -2
  169. package/vitest.config.ts +2 -2
  170. package/dist/chunk-GO2L324Q.js.map +0 -1
  171. package/test/bench/components/temp/Bench-client-3efcd3b6c03c7a51368df3b8b1bdf2e7fa722432.ts +0 -126
  172. package/test/build-server/components/IfNested.d.ts +0 -18
  173. package/test/class/components/temp/Class-server-082505b03612c762384ffff329472db3f55b8097.ts +0 -17
  174. /package/test/build-server/components/{output/IfNested-server.ts → temp/IfNested-server-3c4e4b6f2162c0906cef685830219b9ea9ee985c.ts} +0 -0
package/dist/ssr.cjs CHANGED
@@ -60,9 +60,12 @@ function formatText(value) {
60
60
  }
61
61
 
62
62
  // src/render/getClasses.ts
63
- function getClasses(value) {
63
+ function getClasses(value, styleHash) {
64
64
  let classes = [];
65
65
  gatherNames("", value, classes);
66
+ if (styleHash) {
67
+ classes.push(styleHash);
68
+ }
66
69
  return classes.join(" ");
67
70
  }
68
71
  function gatherNames(name, value, classes) {
package/dist/ssr.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ssr.ts","../src/render/$serverMount.ts","../src/render/$serverRun.ts","../src/render/$serverUnwrap.ts","../src/render/$serverWatch.ts","../src/render/formatAttributeText.ts","../src/render/formatText.ts","../src/render/getClasses.ts","../src/render/getStyles.ts"],"sourcesContent":["import $mount from \"./render/$serverMount\";\nimport $run from \"./render/$serverRun\";\nimport $unwrap from \"./render/$serverUnwrap\";\nimport $watch from \"./render/$serverWatch\";\nimport t_attr from \"./render/formatAttributeText\";\nimport t_fmt from \"./render/formatText\";\nimport t_class from \"./render/getClasses\";\nimport t_style from \"./render/getStyles\";\nimport { type ServerSlotRender } from \"./types/ServerSlotRender\";\n\nexport { $watch, $unwrap, $run, $mount, t_fmt, t_attr, t_class, t_style };\n\nexport type { ServerSlotRender };\n","import { type Cleanup } from \"../types/Cleanup\";\n\nexport default function $serverMount(_: () => Cleanup | void) {}\n","import { type Cleanup } from \"../types/Cleanup\";\n\nexport default function $serverRun(_: () => Cleanup | void) {}\n","export default function $serverUnwrap<T extends Record<PropertyKey, any>>(object: T): T {\n\treturn object;\n}\n","export default function $serverWatch<T extends Record<PropertyKey, any>>(object: T): T {\n\treturn object;\n}\n","export default function formatAttributeText(value: any): string {\n\treturn (value ?? \"\").toString().replaceAll('\"', \"&quot;\");\n}\n","export default function formatText(value: any): string {\n\treturn value ?? \"\";\n}\n","export default function getClasses(value: unknown): string {\n\tlet classes: string[] = [];\n\tgatherNames(\"\", value, classes);\n\treturn classes.join(\" \");\n}\n\nfunction gatherNames(name: unknown, value: unknown, classes: string[]) {\n\tif (value) {\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (let v of value) {\n\t\t\t\tgatherNames(v, v, classes);\n\t\t\t}\n\t\t} else if (typeof value === \"object\") {\n\t\t\tfor (let [n, v] of Object.entries(value)) {\n\t\t\t\tgatherNames(n, v, classes);\n\t\t\t}\n\t\t} else {\n\t\t\tclasses.push(name as string);\n\t\t}\n\t}\n}\n","export default function getStyles(value: Record<string, any>): string {\n\tlet styles: string[] = [];\n\tfor (let [n, v] of Object.entries(value)) {\n\t\tstyles.push(`${n}: ${v}`);\n\t}\n\treturn styles.join(\"; \");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEe,SAAR,aAA8B,GAAyB;AAAC;;;ACAhD,SAAR,WAA4B,GAAyB;AAAC;;;ACF9C,SAAR,cAAmE,QAAc;AACvF,SAAO;AACR;;;ACFe,SAAR,aAAkE,QAAc;AACtF,SAAO;AACR;;;ACFe,SAAR,oBAAqC,OAAoB;AAC/D,UAAQ,SAAS,IAAI,SAAS,EAAE,WAAW,KAAK,QAAQ;AACzD;;;ACFe,SAAR,WAA4B,OAAoB;AACtD,SAAO,SAAS;AACjB;;;ACFe,SAAR,WAA4B,OAAwB;AAC1D,MAAI,UAAoB,CAAC;AACzB,cAAY,IAAI,OAAO,OAAO;AAC9B,SAAO,QAAQ,KAAK,GAAG;AACxB;AAEA,SAAS,YAAY,MAAe,OAAgB,SAAmB;AACtE,MAAI,OAAO;AACV,QAAI,MAAM,QAAQ,KAAK,GAAG;AACzB,eAAS,KAAK,OAAO;AACpB,oBAAY,GAAG,GAAG,OAAO;AAAA,MAC1B;AAAA,IACD,WAAW,OAAO,UAAU,UAAU;AACrC,eAAS,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,KAAK,GAAG;AACzC,oBAAY,GAAG,GAAG,OAAO;AAAA,MAC1B;AAAA,IACD,OAAO;AACN,cAAQ,KAAK,IAAc;AAAA,IAC5B;AAAA,EACD;AACD;;;ACpBe,SAAR,UAA2B,OAAoC;AACrE,MAAI,SAAmB,CAAC;AACxB,WAAS,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,KAAK,GAAG;AACzC,WAAO,KAAK,GAAG,CAAC,KAAK,CAAC,EAAE;AAAA,EACzB;AACA,SAAO,OAAO,KAAK,IAAI;AACxB;","names":[]}
1
+ {"version":3,"sources":["../src/ssr.ts","../src/render/$serverMount.ts","../src/render/$serverRun.ts","../src/render/$serverUnwrap.ts","../src/render/$serverWatch.ts","../src/render/formatAttributeText.ts","../src/render/formatText.ts","../src/render/getClasses.ts","../src/render/getStyles.ts"],"sourcesContent":["import $mount from \"./render/$serverMount\";\nimport $run from \"./render/$serverRun\";\nimport $unwrap from \"./render/$serverUnwrap\";\nimport $watch from \"./render/$serverWatch\";\nimport t_attr from \"./render/formatAttributeText\";\nimport t_fmt from \"./render/formatText\";\nimport t_class from \"./render/getClasses\";\nimport t_style from \"./render/getStyles\";\nimport { type ServerSlotRender } from \"./types/ServerSlotRender\";\n\nexport { $watch, $unwrap, $run, $mount, t_fmt, t_attr, t_class, t_style };\n\nexport type { ServerSlotRender };\n","import { type Cleanup } from \"../types/Cleanup\";\n\nexport default function $serverMount(_: () => Cleanup | void): void {}\n","import { type Cleanup } from \"../types/Cleanup\";\n\nexport default function $serverRun(_: () => Cleanup | void): void {}\n","export default function $serverUnwrap<T extends Record<PropertyKey, any>>(object: T): T {\n\treturn object;\n}\n","export default function $serverWatch<T extends Record<PropertyKey, any>>(object: T): T {\n\treturn object;\n}\n","export default function formatAttributeText(value: any): string {\n\treturn (value ?? \"\").toString().replaceAll('\"', \"&quot;\");\n}\n","export default function formatText(value: any): string {\n\treturn value ?? \"\";\n}\n","export default function getClasses(value: unknown, styleHash?: string): string {\n\tlet classes: string[] = [];\n\tgatherNames(\"\", value, classes);\n\tif (styleHash) {\n\t\tclasses.push(styleHash);\n\t}\n\treturn classes.join(\" \");\n}\n\nfunction gatherNames(name: unknown, value: unknown, classes: string[]) {\n\tif (value) {\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (let v of value) {\n\t\t\t\tgatherNames(v, v, classes);\n\t\t\t}\n\t\t} else if (typeof value === \"object\") {\n\t\t\tfor (let [n, v] of Object.entries(value)) {\n\t\t\t\tgatherNames(n, v, classes);\n\t\t\t}\n\t\t} else {\n\t\t\tclasses.push(name as string);\n\t\t}\n\t}\n}\n","export default function getStyles(value: Record<string, any>): string {\n\tlet styles: string[] = [];\n\tfor (let [n, v] of Object.entries(value)) {\n\t\tstyles.push(`${n}: ${v}`);\n\t}\n\treturn styles.join(\"; \");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEe,SAAR,aAA8B,GAA+B;AAAC;;;ACAtD,SAAR,WAA4B,GAA+B;AAAC;;;ACFpD,SAAR,cAAmE,QAAc;AACvF,SAAO;AACR;;;ACFe,SAAR,aAAkE,QAAc;AACtF,SAAO;AACR;;;ACFe,SAAR,oBAAqC,OAAoB;AAC/D,UAAQ,SAAS,IAAI,SAAS,EAAE,WAAW,KAAK,QAAQ;AACzD;;;ACFe,SAAR,WAA4B,OAAoB;AACtD,SAAO,SAAS;AACjB;;;ACFe,SAAR,WAA4B,OAAgB,WAA4B;AAC9E,MAAI,UAAoB,CAAC;AACzB,cAAY,IAAI,OAAO,OAAO;AAC9B,MAAI,WAAW;AACd,YAAQ,KAAK,SAAS;AAAA,EACvB;AACA,SAAO,QAAQ,KAAK,GAAG;AACxB;AAEA,SAAS,YAAY,MAAe,OAAgB,SAAmB;AACtE,MAAI,OAAO;AACV,QAAI,MAAM,QAAQ,KAAK,GAAG;AACzB,eAAS,KAAK,OAAO;AACpB,oBAAY,GAAG,GAAG,OAAO;AAAA,MAC1B;AAAA,IACD,WAAW,OAAO,UAAU,UAAU;AACrC,eAAS,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,KAAK,GAAG;AACzC,oBAAY,GAAG,GAAG,OAAO;AAAA,MAC1B;AAAA,IACD,OAAO;AACN,cAAQ,KAAK,IAAc;AAAA,IAC5B;AAAA,EACD;AACD;;;ACvBe,SAAR,UAA2B,OAAoC;AACrE,MAAI,SAAmB,CAAC;AACxB,WAAS,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,KAAK,GAAG;AACzC,WAAO,KAAK,GAAG,CAAC,KAAK,CAAC,EAAE;AAAA,EACzB;AACA,SAAO,OAAO,KAAK,IAAI;AACxB;","names":[]}
package/dist/ssr.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as Cleanup } from './ServerSlotRender-AWF3bD5B.cjs';
2
- export { S as ServerSlotRender, g as t_class, f as t_fmt, a as t_style } from './ServerSlotRender-AWF3bD5B.cjs';
1
+ import { C as Cleanup } from './ServerSlotRender-t1sOutne.cjs';
2
+ export { S as ServerSlotRender, g as t_class, f as t_fmt, a as t_style } from './ServerSlotRender-t1sOutne.cjs';
3
3
 
4
4
  declare function $serverMount(_: () => Cleanup | void): void;
5
5
 
package/dist/ssr.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as Cleanup } from './ServerSlotRender-AWF3bD5B.js';
2
- export { S as ServerSlotRender, g as t_class, f as t_fmt, a as t_style } from './ServerSlotRender-AWF3bD5B.js';
1
+ import { C as Cleanup } from './ServerSlotRender-t1sOutne.js';
2
+ export { S as ServerSlotRender, g as t_class, f as t_fmt, a as t_style } from './ServerSlotRender-t1sOutne.js';
3
3
 
4
4
  declare function $serverMount(_: () => Cleanup | void): void;
5
5
 
package/dist/ssr.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  formatText,
3
3
  getClasses,
4
4
  getStyles
5
- } from "./chunk-GO2L324Q.js";
5
+ } from "./chunk-T6JGCJ5T.js";
6
6
 
7
7
  // src/render/$serverMount.ts
8
8
  function $serverMount(_) {
package/dist/ssr.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/render/$serverMount.ts","../src/render/$serverRun.ts","../src/render/$serverUnwrap.ts","../src/render/$serverWatch.ts","../src/render/formatAttributeText.ts"],"sourcesContent":["import { type Cleanup } from \"../types/Cleanup\";\n\nexport default function $serverMount(_: () => Cleanup | void) {}\n","import { type Cleanup } from \"../types/Cleanup\";\n\nexport default function $serverRun(_: () => Cleanup | void) {}\n","export default function $serverUnwrap<T extends Record<PropertyKey, any>>(object: T): T {\n\treturn object;\n}\n","export default function $serverWatch<T extends Record<PropertyKey, any>>(object: T): T {\n\treturn object;\n}\n","export default function formatAttributeText(value: any): string {\n\treturn (value ?? \"\").toString().replaceAll('\"', \"&quot;\");\n}\n"],"mappings":";;;;;;;AAEe,SAAR,aAA8B,GAAyB;AAAC;;;ACAhD,SAAR,WAA4B,GAAyB;AAAC;;;ACF9C,SAAR,cAAmE,QAAc;AACvF,SAAO;AACR;;;ACFe,SAAR,aAAkE,QAAc;AACtF,SAAO;AACR;;;ACFe,SAAR,oBAAqC,OAAoB;AAC/D,UAAQ,SAAS,IAAI,SAAS,EAAE,WAAW,KAAK,QAAQ;AACzD;","names":[]}
1
+ {"version":3,"sources":["../src/render/$serverMount.ts","../src/render/$serverRun.ts","../src/render/$serverUnwrap.ts","../src/render/$serverWatch.ts","../src/render/formatAttributeText.ts"],"sourcesContent":["import { type Cleanup } from \"../types/Cleanup\";\n\nexport default function $serverMount(_: () => Cleanup | void): void {}\n","import { type Cleanup } from \"../types/Cleanup\";\n\nexport default function $serverRun(_: () => Cleanup | void): void {}\n","export default function $serverUnwrap<T extends Record<PropertyKey, any>>(object: T): T {\n\treturn object;\n}\n","export default function $serverWatch<T extends Record<PropertyKey, any>>(object: T): T {\n\treturn object;\n}\n","export default function formatAttributeText(value: any): string {\n\treturn (value ?? \"\").toString().replaceAll('\"', \"&quot;\");\n}\n"],"mappings":";;;;;;;AAEe,SAAR,aAA8B,GAA+B;AAAC;;;ACAtD,SAAR,WAA4B,GAA+B;AAAC;;;ACFpD,SAAR,cAAmE,QAAc;AACvF,SAAO;AACR;;;ACFe,SAAR,aAAkE,QAAc;AACtF,SAAO;AACR;;;ACFe,SAAR,oBAAqC,OAAoB;AAC/D,UAAQ,SAAS,IAAI,SAAS,EAAE,WAAW,KAAK,QAAQ;AACzD;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torpor/view",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "Torpor's view library, for writing and mounting components",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -35,20 +35,20 @@
35
35
  "@testing-library/user-event": "^14.6.1",
36
36
  "@trivago/prettier-plugin-sort-imports": "^5.2.2",
37
37
  "@types/jsdom": "^21.1.7",
38
- "@types/node": "^22.14.1",
38
+ "@types/node": "^22.15.17",
39
39
  "fast-glob": "^3.3.3",
40
40
  "jsdom": "^26.1.0",
41
41
  "sucrase": "^3.35.0",
42
42
  "tinybench": "^4.0.1",
43
43
  "tsup": "^8.4.0",
44
- "tsx": "^4.19.3",
44
+ "tsx": "^4.19.4",
45
45
  "typescript": "^5.8.3",
46
- "vitest": "^3.1.1"
46
+ "vitest": "^3.1.3"
47
47
  },
48
48
  "scripts": {
49
- "build": "tsup && tsx ./scripts/copyToRepl.ts",
49
+ "build": "tsc --noEmit && tsup && tsx ./scripts/copyToRepl.ts",
50
50
  "build:watch": "tsup --watch",
51
- "check": "tsc -p tsconfig.json --noEmit",
51
+ "check": "tsc --noEmit",
52
52
  "test": "vitest",
53
53
  "test:build": "tsx ./scripts/buildTestOutput.ts",
54
54
  "bench": "tsx ./bench/bench.ts",
@@ -1,9 +1,6 @@
1
1
  import fg from "fast-glob";
2
- import { existsSync, promises as fs } from "node:fs";
3
2
  import path from "node:path";
4
- import { buildType } from "../src/compile";
5
- import build from "../src/compile/build";
6
- import parse from "../src/compile/parse";
3
+ import { buildFiles } from "../test/buildOutputFiles";
7
4
 
8
5
  async function run() {
9
6
  console.log("Building test output files");
@@ -11,124 +8,8 @@ async function run() {
11
8
  absolute: true,
12
9
  cwd: path.resolve("./test"),
13
10
  });
14
- await Promise.all(files.sort().map((f) => buildOutputFiles(f)));
11
+ await Promise.all(files.sort().map((f) => buildFiles(f)));
15
12
  console.log("Done\n");
16
13
  }
17
14
 
18
- async function buildOutputFiles(file: string) {
19
- //console.log(`Building files for ${file.substring(path.resolve("./test").length)}`);
20
-
21
- const source = await fs.readFile(file, "utf8");
22
- const parsed = parse(source);
23
- if (parsed.ok && parsed.template) {
24
- let serverCode = formatCode(build(parsed.template, { server: true }).code, "server");
25
- let clientCode = formatCode(build(parsed.template).code, "client");
26
-
27
- let typesCode = buildType(parsed.template);
28
- await fs.writeFile(file.replace(".torp", ".d.ts"), typesCode);
29
-
30
- let outputFile = file.replace("/components/", "/components/output/");
31
- if (!existsSync(path.dirname(outputFile))) {
32
- await fs.mkdir(path.dirname(outputFile));
33
- }
34
- await fs.writeFile(outputFile.replace(".torp", "-server.ts"), serverCode);
35
- await fs.writeFile(outputFile.replace(".torp", "-client.ts"), clientCode);
36
- } else {
37
- // Just log the message and continue with output/testing
38
- console.log("Parse failed for " + file);
39
- }
40
- }
41
-
42
15
  run();
43
-
44
- function formatCode(code: string, suffix: string): string {
45
- // Replace imports from the built @torpor/view to the source code, so that
46
- // a) we don't have to build @torpor/view before testing, and
47
- // b) we have access to the same global context object in test and component code
48
- for (let imp in importsMap) {
49
- code = code.replace(imp, importsMap[imp]);
50
- }
51
-
52
- // Replace component imports with JS imports
53
- code = code.replaceAll(/import (.+?) from ['"](.+?).torp['"]/g, `import $1 from "$2-${suffix}"`);
54
-
55
- return code;
56
- }
57
-
58
- // HACK: We could probably be smarter about this
59
- const importsMap: Record<string, string> = {
60
- 'import { $watch } from "@torpor/view";': 'import $watch from "../../../../src/render/$watch";',
61
- 'import { $unwrap } from "@torpor/view";':
62
- 'import $unwrap from "../../../../src/render/$unwrap";',
63
- 'import { $run } from "@torpor/view";': 'import $run from "../../../../src/render/$run";',
64
- 'import { $mount } from "@torpor/view";': 'import $mount from "../../../../src/render/$mount";',
65
- 'import { t_flush } from "@torpor/view";':
66
- 'import t_flush from "../../../../src/render/flushMountEffects";',
67
- 'import { t_range } from "@torpor/view";':
68
- 'import t_range from "../../../../src/render/newRange";',
69
- 'import { t_push_range } from "@torpor/view";':
70
- 'import t_push_range from "../../../../src/render/pushRange";',
71
- 'import { t_pop_range } from "@torpor/view";':
72
- 'import t_pop_range from "../../../../src/render/popRange";',
73
- 'import { t_run_control } from "@torpor/view";':
74
- 'import t_run_control from "../../../../src/render/runControl";',
75
- 'import { t_run_branch } from "@torpor/view";':
76
- 'import t_run_branch from "../../../../src/render/runControlBranch";',
77
- 'import { t_list_item } from "@torpor/view";':
78
- 'import t_list_item from "../../../../src/render/newListItem";',
79
- 'import { t_run_list } from "@torpor/view";':
80
- 'import t_run_list from "../../../../src/render/runList";',
81
- 'import { t_add_fragment } from "@torpor/view";':
82
- 'import t_add_fragment from "../../../../src/render/addFragment";',
83
- 'import { t_apply_props } from "@torpor/view";':
84
- 'import t_apply_props from "../../../../src/render/applyProps";',
85
- 'import { t_attribute } from "@torpor/view";':
86
- 'import t_attribute from "../../../../src/render/setAttribute";',
87
- 'import { t_class } from "@torpor/view";':
88
- 'import t_class from "../../../../src/render/getClasses";',
89
- 'import { t_style } from "@torpor/view";':
90
- 'import t_style from "../../../../src/render/getStyles";',
91
- 'import { t_dynamic } from "@torpor/view";':
92
- 'import t_dynamic from "../../../../src/render/setDynamicElement";',
93
- 'import { t_fmt } from "@torpor/view";': 'import t_fmt from "../../../../src/render/formatText";',
94
- 'import { t_fragment } from "@torpor/view";':
95
- 'import t_fragment from "../../../../src/render/getFragment";',
96
- 'import { t_event } from "@torpor/view";':
97
- 'import t_event from "../../../../src/render/addEvent";',
98
- 'import { t_animate } from "@torpor/view";':
99
- 'import t_animate from "../../../../src/render/addAnimation";',
100
- 'import { t_root } from "@torpor/view";': 'import t_root from "../../../../src/render/nodeRoot";',
101
- 'import { t_anchor } from "@torpor/view";':
102
- 'import t_anchor from "../../../../src/render/nodeAnchor";',
103
- 'import { t_child } from "@torpor/view";':
104
- 'import t_child from "../../../../src/render/nodeChild";',
105
- 'import { t_next } from "@torpor/view";': 'import t_next from "../../../../src/render/nodeNext";',
106
- 'import { t_frg } from "@torpor/view";':
107
- 'import t_frg from "../../../../src/render/createFragment";',
108
- 'import { t_elm } from "@torpor/view";':
109
- 'import t_elm from "../../../../src/render/createElement";',
110
- 'import { t_txt } from "@torpor/view";': 'import t_txt from "../../../../src/render/createText";',
111
- 'import { t_cmt } from "@torpor/view";':
112
- 'import t_cmt from "../../../../src/render/createComment";',
113
- 'import { type ListItem } from "@torpor/view";':
114
- 'import { type ListItem } from "../../../../src/types/ListItem";',
115
- 'import { type SlotRender } from "@torpor/view";':
116
- 'import { type SlotRender } from "../../../../src/types/SlotRender";',
117
- 'import { $watch } from "@torpor/view/ssr";':
118
- 'import $watch from "../../../../src/render/$watch";',
119
- 'import { $unwrap } from "@torpor/view/ssr";':
120
- 'import $unwrap from "../../../../src/render/$unwrap";',
121
- 'import { $run } from "@torpor/view/ssr";': 'import $run from "../../../../src/render/$run";',
122
- 'import { $mount } from "@torpor/view/ssr";':
123
- 'import $mount from "../../../../src/render/$mount";',
124
- 'import { t_fmt } from "@torpor/view/ssr";':
125
- 'import t_fmt from "../../../../src/render/formatText";',
126
- 'import { t_attr } from "@torpor/view/ssr";':
127
- 'import t_attr from "../../../../src/render/formatAttributeText";',
128
- 'import { t_class } from "@torpor/view/ssr";':
129
- 'import t_class from "../../../../src/render/getClasses";',
130
- 'import { t_style } from "@torpor/view/ssr";':
131
- 'import t_style from "../../../../src/render/getStyles";',
132
- 'import { type ServerSlotRender } from "@torpor/view/ssr";':
133
- 'import { type ServerSlotRender } from "../../../../src/types/ServerSlotRender";',
134
- };
@@ -10,7 +10,7 @@ export default function buildAddFragment(
10
10
  b: Builder,
11
11
  parentName: string,
12
12
  anchorName: string,
13
- ) {
13
+ ): void {
14
14
  if (node.fragment) {
15
15
  const fragment = node.fragment;
16
16
  const fragmentName = `t_fragment_${fragment.number}`;
@@ -8,7 +8,7 @@ import buildAddFragment from "./buildAddFragment";
8
8
  import buildFragment from "./buildFragment";
9
9
  import buildNode from "./buildNode";
10
10
 
11
- export default function buildAwaitNode(node: ControlNode, status: BuildStatus, b: Builder) {
11
+ export default function buildAwaitNode(node: ControlNode, status: BuildStatus, b: Builder): void {
12
12
  const awaitParentName = node.parentName!;
13
13
  const awaitAnchorName = node.varName!;
14
14
  const awaitRangeName = nextVarName("await_range", status);
@@ -17,7 +17,7 @@ export default function buildComponentNode(
17
17
  status: BuildStatus,
18
18
  b: Builder,
19
19
  root = false,
20
- ) {
20
+ ): void {
21
21
  b.append("");
22
22
  b.append("/* @component */");
23
23
 
@@ -9,7 +9,7 @@ import buildReplaceNode from "./buildReplaceNode";
9
9
  import buildScriptNode from "./buildScriptNode";
10
10
  import buildSwitchNode from "./buildSwitchNode";
11
11
 
12
- export default function buildControlNode(node: ControlNode, status: BuildStatus, b: Builder) {
12
+ export default function buildControlNode(node: ControlNode, status: BuildStatus, b: Builder): void {
13
13
  switch (node.operation) {
14
14
  case "@if group": {
15
15
  buildIfNode(node, status, b);
@@ -21,7 +21,7 @@ export default function buildElementNode(
21
21
  b: Builder,
22
22
  parentName: string,
23
23
  root = false,
24
- ) {
24
+ ): void {
25
25
  if (status.inHead) {
26
26
  if (node.tagName === "title") {
27
27
  buildTitleNode(node, status, b);
@@ -202,9 +202,15 @@ function buildElementAttributes(
202
202
  } else if (name.startsWith(":transition")) {
203
203
  buildTransitionAttribute(node, varName, name, value, status, b);
204
204
  } else if (name === "class") {
205
+ if (node.scopeStyles) {
206
+ value += `+ "torp-${status.styleHash}"`;
207
+ }
205
208
  buildRun("setClassName", `${varName}.className = ${value};`, status, b);
206
209
  } else if (name === ":class") {
207
210
  status.imports.add("t_class");
211
+ if (node.scopeStyles) {
212
+ value += `, "torp-${status.styleHash}"`;
213
+ }
208
214
  buildRun("setClasses", `${varName}.className = t_class(${value});`, status, b);
209
215
  } else if (name === ":style") {
210
216
  status.imports.add("t_style");
@@ -13,7 +13,7 @@ const forLoopRegex = /for\s*\((.+?);.*?;.*?\)/;
13
13
  const forLoopVarsRegex = /(?:let\s+|var\s+){0,1}([^\s,;+=]+)(?:\s*=\s*[^,;]+){0,1}/g;
14
14
  const forOfRegex = /for\s*\(\s*(?:let\s*|var\s*){0,1}(.+?)\s+(?:of|in).*?\)/;
15
15
 
16
- export default function buildForNode(node: ControlNode, status: BuildStatus, b: Builder) {
16
+ export default function buildForNode(node: ControlNode, status: BuildStatus, b: Builder): void {
17
17
  const forParentName = node.parentName!;
18
18
  const forAnchorName = node.varName!;
19
19
 
@@ -31,7 +31,7 @@ export default function buildFragment(
31
31
  b: Builder,
32
32
  parentName: string,
33
33
  anchorName: string,
34
- ) {
34
+ ): void {
35
35
  if (node.fragment) {
36
36
  const fragment = node.fragment;
37
37
  const fragmentName = `t_fragment_${fragment.number}`;
@@ -6,6 +6,7 @@ import { type RootNode } from "../../types/nodes/RootNode";
6
6
  import { type TemplateNode } from "../../types/nodes/TemplateNode";
7
7
  import { type TextNode } from "../../types/nodes/TextNode";
8
8
  import Builder from "../../utils/Builder";
9
+ import trimQuotes from "../../utils/trimQuotes";
9
10
  import isReactive from "../utils/isReactive";
10
11
  import { type BuildStatus } from "./BuildStatus";
11
12
 
@@ -16,7 +17,7 @@ export default function buildFragmentText(
16
17
  node: RootNode | ControlNode,
17
18
  status: BuildStatus,
18
19
  b: Builder,
19
- ) {
20
+ ): void {
20
21
  const fragments: Fragment[] = [];
21
22
  buildNodeFragmentText(node, status, fragments);
22
23
 
@@ -155,6 +156,11 @@ function buildElementFragmentText(
155
156
  if (a.name.startsWith("data-")) {
156
157
  return `${a.name}=""`;
157
158
  }
159
+ } else if (a.name === "class" && node.scopeStyles) {
160
+ let value = a.value
161
+ ? `"${trimQuotes(a.value)} torp-${status.styleHash}"`
162
+ : `"torp-${status.styleHash}"`;
163
+ return `${a.name}=${value}`;
158
164
  } else {
159
165
  return `${a.name}${a.value != null ? `=${a.value}` : ""}`;
160
166
  }
@@ -3,7 +3,7 @@ import Builder from "../../utils/Builder";
3
3
  import { type BuildStatus } from "./BuildStatus";
4
4
  import buildNode from "./buildNode";
5
5
 
6
- export default function buildHeadNode(node: ElementNode, status: BuildStatus, b: Builder) {
6
+ export default function buildHeadNode(node: ElementNode, status: BuildStatus, b: Builder): void {
7
7
  b.append("");
8
8
  b.append("/* @head */");
9
9
 
@@ -4,7 +4,7 @@ import nextVarName from "../utils/nextVarName";
4
4
  import { type BuildStatus } from "./BuildStatus";
5
5
  import buildAddFragment from "./buildAddFragment";
6
6
 
7
- export default function buildHtmlNode(node: ControlNode, status: BuildStatus, b: Builder) {
7
+ export default function buildHtmlNode(node: ControlNode, status: BuildStatus, b: Builder): void {
8
8
  const htmlAnchorName = node.varName!;
9
9
  const htmlParentName = node.parentName || htmlAnchorName + ".parentNode";
10
10
  const htmlRangeName = nextVarName("html_range", status);
@@ -9,7 +9,7 @@ import buildNode from "./buildNode";
9
9
 
10
10
  // TODO: Are there too many branches for ifs etc?
11
11
 
12
- export default function buildIfNode(node: ControlNode, status: BuildStatus, b: Builder) {
12
+ export default function buildIfNode(node: ControlNode, status: BuildStatus, b: Builder): void {
13
13
  const ifAnchorName = node.varName!;
14
14
  const ifParentName = node.parentName || ifAnchorName + ".parentNode";
15
15
  const ifRangeName = nextVarName("if_range", status);
@@ -7,7 +7,7 @@ export default function buildMount(
7
7
  functionBody: string,
8
8
  status: BuildStatus,
9
9
  b: Builder,
10
- ) {
10
+ ): void {
11
11
  functionBody = replaceForVarNames(functionBody, status);
12
12
 
13
13
  status.imports.add("$mount");
@@ -19,7 +19,7 @@ export default function buildNode(
19
19
  parentName: string,
20
20
  anchorName: string,
21
21
  root = false,
22
- ) {
22
+ ): void {
23
23
  // Nodes with anchors will have been handled when their containing fragment
24
24
  // was built so we want to skip them here
25
25
  if (node.handled) {
@@ -6,7 +6,7 @@ import buildAddFragment from "./buildAddFragment";
6
6
  import buildFragment from "./buildFragment";
7
7
  import buildNode from "./buildNode";
8
8
 
9
- export default function buildReplaceNode(node: ControlNode, status: BuildStatus, b: Builder) {
9
+ export default function buildReplaceNode(node: ControlNode, status: BuildStatus, b: Builder): void {
10
10
  const replaceAnchorName = node.varName!;
11
11
  const replaceParentName = node.parentName || replaceAnchorName + ".parentNode";
12
12
  const replaceRangeName = nextVarName("replace_range", status);
@@ -11,7 +11,7 @@ export default function buildRootNode(
11
11
  b: Builder,
12
12
  parentName: string,
13
13
  anchorName: string,
14
- ) {
14
+ ): void {
15
15
  buildFragment(node, status, b, parentName, anchorName);
16
16
 
17
17
  status.fragmentStack.push({
@@ -7,7 +7,7 @@ export default function buildRun(
7
7
  functionBody: string,
8
8
  status: BuildStatus,
9
9
  b: Builder,
10
- ) {
10
+ ): void {
11
11
  functionBody = replaceForVarNames(functionBody, status);
12
12
 
13
13
  status.imports.add("$run");
@@ -1,7 +1,7 @@
1
1
  import { type ControlNode } from "../../types/nodes/ControlNode";
2
2
  import Builder from "../../utils/Builder";
3
3
 
4
- export default function buildScriptNode(node: ControlNode, b: Builder) {
4
+ export default function buildScriptNode(node: ControlNode, b: Builder): void {
5
5
  b.append(`/* ${node.operation} */`);
6
6
  b.append(`${maybeAppend(node.statement, ";")}`);
7
7
  }
@@ -11,7 +11,7 @@ import buildFragment from "./buildFragment";
11
11
  import buildNode from "./buildNode";
12
12
  import buildRun from "./buildRun";
13
13
 
14
- export default function buildSlotNode(node: ElementNode, status: BuildStatus, b: Builder) {
14
+ export default function buildSlotNode(node: ElementNode, status: BuildStatus, b: Builder): void {
15
15
  // If there's a slot, build that, otherwise build the default nodes
16
16
  let slotName = node.attributes.find((a) => a.name === "name")?.value;
17
17
  slotName = slotName ? trimQuotes(slotName) : "_";
@@ -7,7 +7,7 @@ import buildAddFragment from "./buildAddFragment";
7
7
  import buildFragment from "./buildFragment";
8
8
  import buildNode from "./buildNode";
9
9
 
10
- export default function buildSwitchNode(node: ControlNode, status: BuildStatus, b: Builder) {
10
+ export default function buildSwitchNode(node: ControlNode, status: BuildStatus, b: Builder): void {
11
11
  const switchParentName = node.parentName!;
12
12
  const switchAnchorName = node.varName!;
13
13
  const switchRangeName = nextVarName("switch_range", status);
@@ -3,7 +3,7 @@ import Builder from "../../utils/Builder";
3
3
  import { type BuildStatus } from "./BuildStatus";
4
4
  import buildRun from "./buildRun";
5
5
 
6
- export default function buildTextNode(node: TextNode, status: BuildStatus, b: Builder) {
6
+ export default function buildTextNode(node: TextNode, status: BuildStatus, b: Builder): void {
7
7
  let content = node.content || "";
8
8
 
9
9
  if (!status.preserveWhitespace) {
@@ -3,7 +3,7 @@ import type { BuildStatus } from "./BuildStatus";
3
3
  /**
4
4
  * Variables used within a for loop need to be retrieved from the loop data.
5
5
  */
6
- export default function replaceForVarNames(value: string, status: BuildStatus) {
6
+ export default function replaceForVarNames(value: string, status: BuildStatus): string {
7
7
  // HACK: If a value from a for loop is used in the function body,
8
8
  // get it from the loop data to trigger an update when it is changed
9
9
  for (let varName of status.forVarNames) {
@@ -13,7 +13,7 @@ export default function buildServerAwaitNode(
13
13
  node: ControlNode,
14
14
  status: BuildServerStatus,
15
15
  b: Builder,
16
- ) {
16
+ ): void {
17
17
  // Surround the entire control statement with bracketed comments, so that we
18
18
  // can skip to the end to set the anchor node when hydrating
19
19
  status.output += HYDRATION_START_COMMENT;
@@ -14,7 +14,7 @@ export default function buildServerComponentNode(
14
14
  node: ElementNode,
15
15
  status: BuildServerStatus,
16
16
  b: Builder,
17
- ) {
17
+ ): void {
18
18
  if (status.output) {
19
19
  b.append(`$output += \`${status.output}\`;`);
20
20
  status.output = "";
@@ -13,7 +13,7 @@ export default function buildServerControlNode(
13
13
  node: ControlNode,
14
14
  status: BuildServerStatus,
15
15
  b: Builder,
16
- ) {
16
+ ): void {
17
17
  switch (node.operation) {
18
18
  case "@if group": {
19
19
  buildServerIfNode(node, status, b);
@@ -11,7 +11,7 @@ export default function buildServerElementNode(
11
11
  node: ElementNode,
12
12
  status: BuildServerStatus,
13
13
  b: Builder,
14
- ) {
14
+ ): void {
15
15
  let attributes = buildElementAttributes(node, status);
16
16
  if (attributes.length) {
17
17
  attributes = " " + attributes;
@@ -94,6 +94,9 @@ function buildElementAttributes(node: ElementNode, status: BuildServerStatus) {
94
94
  attributes.push(`${propName}="\${${valueOrDefault}}"`);
95
95
  } else if (name === ":class") {
96
96
  status.imports.add("t_class");
97
+ if (node.scopeStyles) {
98
+ value += `, "torp-${status.styleHash}"`;
99
+ }
97
100
  attributes.push(`class="\${t_class(${value})}"`);
98
101
  } else if (name === ":style") {
99
102
  status.imports.add("t_style");
@@ -110,6 +113,11 @@ function buildElementAttributes(node: ElementNode, status: BuildServerStatus) {
110
113
  attributes.push(
111
114
  `${name}="${trimQuotes(value).replaceAll("{", "${t_attr(").replaceAll("}", ")}")}"`,
112
115
  );
116
+ } else if (name === "class" && node.scopeStyles) {
117
+ value = value
118
+ ? `"${trimQuotes(value)} torp-${status.styleHash}"`
119
+ : `"torp-${status.styleHash}"`;
120
+ attributes.push(`${name}="${trimQuotes(value).replaceAll('"', "&quot;")}"`);
113
121
  } else if (value != null) {
114
122
  // Just set the attribute
115
123
  // TODO: Probably check if it's a boolean attribute e.g. disabled
@@ -14,7 +14,7 @@ export default function buildServerForNode(
14
14
  node: ControlNode,
15
15
  status: BuildServerStatus,
16
16
  b: Builder,
17
- ) {
17
+ ): void {
18
18
  // Surround the entire control statement with bracketed comments, so that we
19
19
  // can skip to the end to set the anchor node when hydrating
20
20
  status.output += HYDRATION_START_COMMENT;
@@ -7,7 +7,7 @@ import { type ControlNode } from "../../types/nodes/ControlNode";
7
7
  import isControlNode from "../../types/nodes/isControlNode";
8
8
  import { type BuildServerStatus } from "./BuildServerStatus";
9
9
 
10
- export default function buildServerHtmlNode(node: ControlNode, status: BuildServerStatus) {
10
+ export default function buildServerHtmlNode(node: ControlNode, status: BuildServerStatus): void {
11
11
  // Surround the entire control statement with bracketed comments, so that we
12
12
  // can skip to the end to set the anchor node when hydrating
13
13
  status.output += HYDRATION_START_COMMENT;
@@ -13,7 +13,7 @@ export default function buildServerIfNode(
13
13
  node: ControlNode,
14
14
  status: BuildServerStatus,
15
15
  b: Builder,
16
- ) {
16
+ ): void {
17
17
  // Surround the entire control statement with bracketed comments, so that we
18
18
  // can skip to the end to set the anchor node when hydrating
19
19
  status.output += HYDRATION_START_COMMENT;
@@ -12,7 +12,11 @@ import buildServerRootNode from "./buildServerRootNode";
12
12
  import buildServerSpecialNode from "./buildServerSpecialNode";
13
13
  import buildServerTextNode from "./buildServerTextNode";
14
14
 
15
- export default function buildServerNode(node: TemplateNode, status: BuildServerStatus, b: Builder) {
15
+ export default function buildServerNode(
16
+ node: TemplateNode,
17
+ status: BuildServerStatus,
18
+ b: Builder,
19
+ ): void {
16
20
  switch (node.type) {
17
21
  case "root": {
18
22
  buildServerRootNode(node as RootNode, status, b);
@@ -13,7 +13,7 @@ export default function buildServerReplaceNode(
13
13
  node: ControlNode,
14
14
  status: BuildServerStatus,
15
15
  b: Builder,
16
- ) {
16
+ ): void {
17
17
  // Surround the entire control statement with bracketed comments, so that we
18
18
  // can skip to the end to set the anchor node when hydrating
19
19
  status.output += HYDRATION_START_COMMENT;
@@ -3,6 +3,10 @@ import Builder from "../../utils/Builder";
3
3
  import { type BuildServerStatus } from "./BuildServerStatus";
4
4
  import buildServerNode from "./buildServerNode";
5
5
 
6
- export default function buildServerRootNode(node: RootNode, status: BuildServerStatus, b: Builder) {
6
+ export default function buildServerRootNode(
7
+ node: RootNode,
8
+ status: BuildServerStatus,
9
+ b: Builder,
10
+ ): void {
7
11
  buildServerNode(node.children[0], status, b);
8
12
  }