@builder.io/mitosis 0.0.56-1 → 0.0.56-101

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 (394) hide show
  1. package/dist/src/__tests__/angular.test.js +5 -13
  2. package/dist/src/__tests__/builder.test.js +3 -3
  3. package/dist/src/__tests__/data/advanced-ref.raw.d.ts +4 -0
  4. package/dist/src/__tests__/data/advanced-ref.raw.jsx +39 -0
  5. package/dist/src/__tests__/data/basic-child-component.raw.d.ts +1 -0
  6. package/dist/src/__tests__/data/basic-child-component.raw.jsx +21 -0
  7. package/dist/src/__tests__/data/basic-context.raw.d.ts +1 -0
  8. package/dist/src/__tests__/data/basic-context.raw.jsx +29 -0
  9. package/dist/src/__tests__/data/basic-custom-mitosis-package.raw.d.ts +1 -0
  10. package/dist/src/__tests__/data/basic-custom-mitosis-package.raw.jsx +10 -0
  11. package/dist/src/__tests__/data/basic-for-show.raw.d.ts +1 -0
  12. package/dist/src/__tests__/data/basic-for-show.raw.jsx +20 -0
  13. package/dist/src/__tests__/data/basic-for.raw.d.ts +1 -0
  14. package/dist/src/__tests__/data/basic-for.raw.jsx +23 -0
  15. package/dist/src/__tests__/data/basic-forwardRef-metadata.raw.d.ts +5 -0
  16. package/dist/src/__tests__/data/basic-forwardRef-metadata.raw.jsx +17 -0
  17. package/dist/src/__tests__/data/basic-forwardRef.raw.d.ts +5 -0
  18. package/dist/src/__tests__/data/basic-forwardRef.raw.jsx +14 -0
  19. package/dist/src/__tests__/data/basic-onChange.raw.d.ts +1 -0
  20. package/dist/src/__tests__/data/basic-onChange.raw.jsx +17 -0
  21. package/dist/src/__tests__/data/basic-onMount-update.raw.d.ts +5 -0
  22. package/dist/src/__tests__/data/basic-onMount-update.raw.jsx +17 -0
  23. package/dist/src/__tests__/data/basic-onUpdate-return.raw.d.ts +1 -0
  24. package/dist/src/__tests__/data/basic-onUpdate-return.raw.jsx +24 -0
  25. package/dist/src/__tests__/data/basic-outputs-meta.raw.d.ts +1 -0
  26. package/dist/src/__tests__/data/basic-outputs-meta.raw.jsx +17 -0
  27. package/dist/src/__tests__/data/basic-outputs.raw.d.ts +1 -0
  28. package/dist/src/__tests__/data/basic-outputs.raw.jsx +14 -0
  29. package/dist/src/__tests__/data/basic-preserve-export-or-local-statement.raw.d.ts +6 -0
  30. package/dist/src/__tests__/data/basic-preserve-export-or-local-statement.raw.jsx +14 -0
  31. package/dist/src/__tests__/data/basic-props-destructure.raw.d.ts +6 -0
  32. package/dist/src/__tests__/data/basic-props-destructure.raw.jsx +14 -0
  33. package/dist/src/__tests__/data/basic-props.raw.d.ts +6 -0
  34. package/dist/src/__tests__/data/basic-props.raw.jsx +13 -0
  35. package/dist/src/__tests__/data/basic-ref-assignment.raw.d.ts +4 -0
  36. package/dist/src/__tests__/data/basic-ref-assignment.raw.jsx +15 -0
  37. package/dist/src/__tests__/data/basic-ref-usePrevious.raw.d.ts +5 -0
  38. package/dist/src/__tests__/data/basic-ref-usePrevious.raw.jsx +35 -0
  39. package/dist/src/__tests__/data/basic-ref.raw.d.ts +4 -0
  40. package/dist/src/__tests__/data/basic-ref.raw.jsx +36 -0
  41. package/dist/src/__tests__/data/basic.raw.d.ts +6 -1
  42. package/dist/src/__tests__/data/basic.raw.jsx +13 -4
  43. package/dist/src/__tests__/data/blocks/button-with-metadata.raw.d.ts +1 -1
  44. package/dist/src/__tests__/data/blocks/button.raw.d.ts +1 -1
  45. package/dist/src/__tests__/data/blocks/classname-jsx.raw.d.ts +7 -0
  46. package/dist/src/__tests__/data/blocks/classname-jsx.raw.jsx +15 -0
  47. package/dist/src/__tests__/data/blocks/columns.raw.d.ts +1 -1
  48. package/dist/src/__tests__/data/blocks/columns.raw.jsx +1 -1
  49. package/dist/src/__tests__/data/blocks/content-slot-html.raw.d.ts +7 -0
  50. package/dist/src/__tests__/data/blocks/content-slot-html.raw.jsx +15 -0
  51. package/dist/src/__tests__/data/blocks/content-slot-jsx.raw.d.ts +6 -0
  52. package/dist/src/__tests__/data/blocks/content-slot-jsx.raw.jsx +12 -0
  53. package/dist/src/__tests__/data/blocks/custom-code.raw.d.ts +1 -1
  54. package/dist/src/__tests__/data/blocks/custom-code.raw.jsx +3 -7
  55. package/dist/src/__tests__/data/blocks/embed.raw.d.ts +1 -1
  56. package/dist/src/__tests__/data/blocks/embed.raw.jsx +3 -7
  57. package/dist/src/__tests__/data/blocks/form.raw.d.ts +1 -1
  58. package/dist/src/__tests__/data/blocks/form.raw.jsx +8 -8
  59. package/dist/src/__tests__/data/blocks/image.raw.d.ts +2 -2
  60. package/dist/src/__tests__/data/blocks/image.raw.jsx +9 -10
  61. package/dist/src/__tests__/data/blocks/img-state.raw.d.ts +1 -0
  62. package/dist/src/__tests__/data/blocks/img-state.raw.jsx +17 -0
  63. package/dist/src/__tests__/data/blocks/img.raw.d.ts +1 -1
  64. package/dist/src/__tests__/data/blocks/input.raw.d.ts +1 -1
  65. package/dist/src/__tests__/data/blocks/input.raw.jsx +1 -3
  66. package/dist/src/__tests__/data/blocks/multiple-onUpdate.raw.d.ts +1 -1
  67. package/dist/src/__tests__/data/blocks/multiple-onUpdateWithDeps.raw.d.ts +1 -1
  68. package/dist/src/__tests__/data/blocks/multiple-onUpdateWithDeps.raw.jsx +7 -1
  69. package/dist/src/__tests__/data/blocks/onInit-onMount.raw.d.ts +1 -0
  70. package/dist/src/__tests__/data/blocks/onInit-onMount.raw.jsx +13 -0
  71. package/dist/src/__tests__/data/blocks/onInit.raw.d.ts +8 -0
  72. package/dist/src/__tests__/data/blocks/onInit.raw.jsx +20 -0
  73. package/dist/src/__tests__/data/blocks/onMount.raw.d.ts +1 -1
  74. package/dist/src/__tests__/data/blocks/onUpdate.raw.d.ts +1 -1
  75. package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.d.ts +1 -1
  76. package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.jsx +1 -1
  77. package/dist/src/__tests__/data/blocks/raw-text.raw.d.ts +1 -1
  78. package/dist/src/__tests__/data/blocks/rootShow.raw.d.ts +1 -1
  79. package/dist/src/__tests__/data/blocks/section-state.raw.d.ts +6 -0
  80. package/dist/src/__tests__/data/blocks/section-state.raw.jsx +17 -0
  81. package/dist/src/__tests__/data/blocks/section.raw.d.ts +1 -1
  82. package/dist/src/__tests__/data/blocks/select.raw.d.ts +1 -1
  83. package/dist/src/__tests__/data/blocks/select.raw.jsx +1 -3
  84. package/dist/src/__tests__/data/blocks/self-referencing-component-with-children.raw.d.ts +1 -1
  85. package/dist/src/__tests__/data/blocks/self-referencing-component.raw.d.ts +1 -1
  86. package/dist/src/__tests__/data/blocks/shadow-dom.raw.d.ts +1 -1
  87. package/dist/src/__tests__/data/blocks/shadow-dom.raw.jsx +2 -4
  88. package/dist/src/__tests__/data/blocks/slot-html.raw.d.ts +5 -0
  89. package/dist/src/__tests__/data/blocks/slot-html.raw.jsx +15 -0
  90. package/dist/src/__tests__/data/blocks/slot-jsx.raw.d.ts +5 -0
  91. package/dist/src/__tests__/data/blocks/slot-jsx.raw.jsx +12 -0
  92. package/dist/src/__tests__/data/blocks/stamped-io.raw.d.ts +1 -1
  93. package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +4 -5
  94. package/dist/src/__tests__/data/blocks/submit-button.raw.d.ts +1 -1
  95. package/dist/src/__tests__/data/blocks/text.raw.d.ts +1 -1
  96. package/dist/src/__tests__/data/blocks/text.raw.jsx +3 -1
  97. package/dist/src/__tests__/data/blocks/textarea.raw.d.ts +1 -1
  98. package/dist/src/__tests__/data/blocks/video.raw.d.ts +1 -1
  99. package/dist/src/__tests__/data/blocks/video.raw.jsx +1 -1
  100. package/dist/src/__tests__/data/context/component-with-context.lite.d.ts +3 -1
  101. package/dist/src/__tests__/data/context/component-with-context.lite.jsx +7 -2
  102. package/dist/src/__tests__/data/default-props/default-props.raw.d.ts +7 -0
  103. package/dist/src/__tests__/data/default-props/default-props.raw.jsx +23 -0
  104. package/dist/src/__tests__/data/jsx-json.spec.d.ts +2 -0
  105. package/dist/src/__tests__/data/jsx-json.spec.js +10226 -0
  106. package/dist/src/__tests__/data/nested-styles.lite.d.ts +1 -0
  107. package/dist/src/__tests__/data/nested-styles.lite.jsx +20 -0
  108. package/dist/src/__tests__/data/show/nested-show.raw.d.ts +6 -0
  109. package/dist/src/__tests__/data/show/nested-show.raw.jsx +11 -0
  110. package/dist/src/__tests__/data/show/show-with-for.raw.d.ts +6 -0
  111. package/dist/src/__tests__/data/show/show-with-for.raw.jsx +9 -0
  112. package/dist/src/__tests__/data/styles/class-and-className.raw.d.ts +1 -0
  113. package/dist/src/__tests__/data/styles/class-and-className.raw.jsx +10 -0
  114. package/dist/src/__tests__/data/styles/class.raw.d.ts +1 -0
  115. package/dist/src/__tests__/data/styles/class.raw.jsx +10 -0
  116. package/dist/src/__tests__/data/styles/className.raw.d.ts +1 -0
  117. package/dist/src/__tests__/data/styles/className.raw.jsx +10 -0
  118. package/dist/src/__tests__/data/styles/classState.raw.d.ts +1 -0
  119. package/dist/src/__tests__/data/styles/classState.raw.jsx +13 -0
  120. package/dist/src/__tests__/data/types/component-props-interface.raw.d.ts +6 -0
  121. package/dist/src/__tests__/data/types/component-props-interface.raw.jsx +6 -0
  122. package/dist/src/__tests__/data/types/component-props-type.raw.d.ts +6 -0
  123. package/dist/src/__tests__/data/types/component-props-type.raw.jsx +6 -0
  124. package/dist/src/__tests__/data/types/component-with-default-values-types.raw.d.ts +5 -0
  125. package/dist/src/__tests__/data/types/component-with-default-values-types.raw.jsx +9 -0
  126. package/dist/src/__tests__/data/types/foo-type.d.ts +1 -0
  127. package/dist/src/{jsx-types.js → __tests__/data/types/foo-type.js} +0 -0
  128. package/dist/src/__tests__/data/types/preserve-typing.raw.d.ts +8 -0
  129. package/dist/src/__tests__/data/types/preserve-typing.raw.jsx +6 -0
  130. package/dist/src/__tests__/data/types/type-dependency.raw.d.ts +7 -0
  131. package/dist/src/__tests__/data/types/type-dependency.raw.jsx +6 -0
  132. package/dist/src/__tests__/data/types/type-export.lite.d.ts +3 -0
  133. package/dist/src/__tests__/data/types/type-export.lite.jsx +6 -0
  134. package/dist/src/__tests__/hash-code.test.d.ts +1 -0
  135. package/dist/src/__tests__/hash-code.test.js +11 -0
  136. package/dist/src/__tests__/html.test.js +2 -13
  137. package/dist/src/__tests__/liquid.test.js +2 -103
  138. package/dist/src/__tests__/lit.test.d.ts +1 -0
  139. package/dist/src/__tests__/lit.test.js +7 -0
  140. package/dist/src/__tests__/marko.test.d.ts +1 -0
  141. package/dist/src/__tests__/marko.test.js +14 -0
  142. package/dist/src/__tests__/parse-jsx.test.js +28 -0
  143. package/dist/src/__tests__/qwik/convert-method-to-function.test.d.ts +1 -0
  144. package/dist/src/__tests__/qwik/convert-method-to-function.test.js +37 -0
  145. package/dist/src/__tests__/qwik/src-generator.test.d.ts +1 -0
  146. package/dist/src/__tests__/qwik/src-generator.test.js +65 -0
  147. package/dist/src/__tests__/qwik.directive.test.js +1 -0
  148. package/dist/src/__tests__/qwik.test.js +54 -23
  149. package/dist/src/__tests__/react-native.test.js +3 -136
  150. package/dist/src/__tests__/react.test.js +9 -136
  151. package/dist/src/__tests__/shared.d.ts +3 -0
  152. package/dist/src/__tests__/shared.js +308 -0
  153. package/dist/src/__tests__/solid.test.js +5 -97
  154. package/dist/src/__tests__/stencil.test.js +3 -98
  155. package/dist/src/__tests__/styles.test.d.ts +1 -0
  156. package/dist/src/__tests__/styles.test.js +23 -0
  157. package/dist/src/__tests__/svelte.test.js +2 -31
  158. package/dist/src/__tests__/vue.test.js +2 -134
  159. package/dist/src/__tests__/webcomponent.test.js +8 -5
  160. package/dist/src/constants/hooks.d.ts +7 -0
  161. package/dist/src/constants/hooks.js +10 -0
  162. package/dist/src/flow.d.ts +6 -0
  163. package/dist/src/flow.js +6 -2
  164. package/dist/src/generators/angular.d.ts +10 -2
  165. package/dist/src/generators/angular.js +245 -47
  166. package/dist/src/generators/builder.d.ts +2 -2
  167. package/dist/src/generators/builder.js +26 -29
  168. package/dist/src/generators/context/{react copy.d.ts → qwik.d.ts} +2 -2
  169. package/dist/src/generators/context/{react copy.js → qwik.js} +4 -5
  170. package/dist/src/generators/context/react.js +1 -1
  171. package/dist/src/generators/context/solid.js +1 -1
  172. package/dist/src/generators/context/svelte.d.ts +1 -1
  173. package/dist/src/generators/context/svelte.js +1 -1
  174. package/dist/src/generators/helpers/context.js +1 -2
  175. package/dist/src/generators/html.d.ts +1 -1
  176. package/dist/src/generators/html.js +365 -108
  177. package/dist/src/generators/liquid.d.ts +1 -1
  178. package/dist/src/generators/liquid.js +18 -25
  179. package/dist/src/generators/lit/collect-class-string.d.ts +2 -0
  180. package/dist/src/generators/lit/collect-class-string.js +43 -0
  181. package/dist/src/generators/lit/generate.d.ts +5 -0
  182. package/dist/src/generators/lit/generate.js +223 -0
  183. package/dist/src/generators/lit/index.d.ts +1 -0
  184. package/dist/src/generators/lit/index.js +17 -0
  185. package/dist/src/generators/marko/generate.d.ts +21 -0
  186. package/dist/src/generators/marko/generate.js +289 -0
  187. package/dist/src/generators/marko/index.d.ts +1 -0
  188. package/dist/src/generators/marko/index.js +17 -0
  189. package/dist/src/generators/mitosis.d.ts +1 -1
  190. package/dist/src/generators/mitosis.js +39 -34
  191. package/dist/src/generators/qwik/add-prevent-default.d.ts +7 -0
  192. package/dist/src/generators/qwik/add-prevent-default.js +32 -0
  193. package/dist/src/generators/qwik/component-generator.d.ts +4 -0
  194. package/dist/src/generators/qwik/component-generator.js +311 -0
  195. package/dist/src/generators/qwik/component.d.ts +1 -0
  196. package/dist/src/generators/qwik/component.js +68 -36
  197. package/dist/src/generators/qwik/convert-method-to-function.d.ts +1 -0
  198. package/dist/src/generators/qwik/convert-method-to-function.js +162 -0
  199. package/dist/src/generators/qwik/directives.js +43 -23
  200. package/dist/src/generators/qwik/handlers.js +6 -22
  201. package/dist/src/generators/qwik/index.d.ts +3 -1
  202. package/dist/src/generators/qwik/index.js +3 -1
  203. package/dist/src/generators/qwik/jsx.d.ts +12 -0
  204. package/dist/src/generators/qwik/jsx.js +81 -24
  205. package/dist/src/generators/qwik/src-generator.d.ts +21 -8
  206. package/dist/src/generators/qwik/src-generator.js +177 -43
  207. package/dist/src/generators/qwik/styles.js +3 -3
  208. package/dist/src/generators/react/generator.d.ts +6 -0
  209. package/dist/src/generators/react/generator.js +447 -0
  210. package/dist/src/generators/react/helpers.d.ts +2 -0
  211. package/dist/src/generators/react/helpers.js +14 -0
  212. package/dist/src/generators/react/index.d.ts +2 -0
  213. package/dist/src/generators/react/index.js +18 -0
  214. package/dist/src/generators/react/state.d.ts +9 -0
  215. package/dist/src/generators/react/state.js +109 -0
  216. package/dist/src/generators/react/types.d.ts +10 -0
  217. package/dist/src/generators/react/types.js +2 -0
  218. package/dist/src/generators/react-native.d.ts +2 -2
  219. package/dist/src/generators/react-native.js +8 -10
  220. package/dist/src/generators/react.d.ts +7 -3
  221. package/dist/src/generators/react.js +190 -92
  222. package/dist/src/generators/solid/index.d.ts +3 -0
  223. package/dist/src/generators/solid/index.js +345 -0
  224. package/dist/src/generators/solid/state.d.ts +19 -0
  225. package/dist/src/generators/solid/state.js +144 -0
  226. package/dist/src/generators/solid/types.d.ts +6 -0
  227. package/dist/src/generators/solid/types.js +2 -0
  228. package/dist/src/generators/solid.d.ts +3 -2
  229. package/dist/src/generators/solid.js +86 -50
  230. package/dist/src/generators/stencil/collect-class-string.d.ts +1 -1
  231. package/dist/src/generators/stencil/collect-class-string.js +10 -11
  232. package/dist/src/generators/stencil/generate.d.ts +1 -1
  233. package/dist/src/generators/stencil/generate.js +16 -31
  234. package/dist/src/generators/svelte.d.ts +2 -2
  235. package/dist/src/generators/svelte.js +160 -88
  236. package/dist/src/generators/swift-ui.d.ts +1 -1
  237. package/dist/src/generators/swift-ui.js +19 -20
  238. package/dist/src/generators/template.d.ts +1 -1
  239. package/dist/src/generators/template.js +11 -18
  240. package/dist/src/generators/vue.d.ts +17 -9
  241. package/dist/src/generators/vue.js +227 -106
  242. package/dist/src/helpers/babel-transform.js +8 -14
  243. package/dist/src/helpers/create-mitosis-component.d.ts +1 -1
  244. package/dist/src/helpers/create-mitosis-component.js +1 -1
  245. package/dist/src/helpers/create-mitosis-node.js +1 -1
  246. package/dist/src/helpers/fast-clone.js +1 -3
  247. package/dist/src/helpers/filter-empty-text-nodes.js +1 -2
  248. package/dist/src/helpers/get-bindings.d.ts +2 -0
  249. package/dist/src/helpers/get-bindings.js +18 -0
  250. package/dist/src/helpers/get-custom-imports.d.ts +15 -0
  251. package/dist/src/helpers/get-custom-imports.js +40 -0
  252. package/dist/src/helpers/get-prop-functions.d.ts +5 -0
  253. package/dist/src/helpers/get-prop-functions.js +29 -0
  254. package/dist/src/helpers/get-props-ref.d.ts +2 -0
  255. package/dist/src/helpers/get-props-ref.js +32 -0
  256. package/dist/src/helpers/get-refs.js +3 -2
  257. package/dist/src/helpers/get-state-object-string.d.ts +6 -4
  258. package/dist/src/helpers/get-state-object-string.js +37 -27
  259. package/dist/src/helpers/get-styles.js +4 -3
  260. package/dist/src/helpers/getters-to-functions.d.ts +1 -1
  261. package/dist/src/helpers/getters-to-functions.js +3 -2
  262. package/dist/src/helpers/handle-missing-state.js +1 -1
  263. package/dist/src/helpers/has-bindings-text.d.ts +2 -0
  264. package/dist/src/helpers/has-bindings-text.js +21 -0
  265. package/dist/src/helpers/has-stateful-dom.d.ts +2 -0
  266. package/dist/src/helpers/has-stateful-dom.js +21 -0
  267. package/dist/src/helpers/has.d.ts +9 -0
  268. package/dist/src/helpers/has.js +27 -0
  269. package/dist/src/helpers/is-children.js +3 -1
  270. package/dist/src/helpers/is-component.js +1 -3
  271. package/dist/src/helpers/is-html-attribute.d.ts +4 -0
  272. package/dist/src/helpers/is-html-attribute.js +380 -0
  273. package/dist/src/helpers/json.d.ts +3 -1
  274. package/dist/src/helpers/map-refs.js +39 -14
  275. package/dist/src/helpers/nullable.d.ts +3 -0
  276. package/dist/src/helpers/nullable.js +7 -0
  277. package/dist/src/helpers/parsers.js +1 -2
  278. package/dist/src/helpers/process-http-requests.js +1 -1
  279. package/dist/src/helpers/render-imports.d.ts +20 -2
  280. package/dist/src/helpers/render-imports.js +115 -54
  281. package/dist/src/helpers/render-imports.test.d.ts +1 -0
  282. package/dist/src/helpers/render-imports.test.js +33 -0
  283. package/dist/src/helpers/replace-idenifiers.js +5 -7
  284. package/dist/src/helpers/slots.d.ts +2 -0
  285. package/dist/src/helpers/slots.js +8 -0
  286. package/dist/src/helpers/state.d.ts +11 -0
  287. package/dist/src/helpers/state.js +43 -0
  288. package/dist/src/helpers/strip-state-and-props-refs.d.ts +6 -1
  289. package/dist/src/helpers/strip-state-and-props-refs.js +70 -15
  290. package/dist/src/helpers/styles/collect-css.d.ts +6 -0
  291. package/dist/src/helpers/styles/collect-css.js +87 -0
  292. package/dist/src/helpers/styles/collect-css.test.d.ts +1 -0
  293. package/dist/src/helpers/styles/collect-css.test.js +18 -0
  294. package/dist/src/helpers/styles/collect-styled-components.d.ts +2 -0
  295. package/dist/src/helpers/styles/collect-styled-components.js +61 -0
  296. package/dist/src/helpers/styles/helpers.d.ts +31 -0
  297. package/dist/src/helpers/styles/helpers.js +80 -0
  298. package/dist/src/helpers/typescript.d.ts +5 -0
  299. package/dist/src/helpers/typescript.js +2 -0
  300. package/dist/src/index.d.ts +12 -4
  301. package/dist/src/index.js +28 -8
  302. package/dist/src/modules/plugins.d.ts +1 -1
  303. package/dist/src/parsers/angular.js +22 -34
  304. package/dist/src/parsers/builder.d.ts +32 -29
  305. package/dist/src/parsers/builder.js +99 -85
  306. package/dist/src/parsers/jsx/ast.d.ts +3 -0
  307. package/dist/src/parsers/jsx/ast.js +74 -0
  308. package/dist/src/parsers/jsx/component-types.d.ts +6 -0
  309. package/dist/src/parsers/jsx/component-types.js +88 -0
  310. package/dist/src/parsers/jsx/context.d.ts +6 -0
  311. package/dist/src/parsers/jsx/context.js +68 -0
  312. package/dist/src/parsers/jsx/helpers.d.ts +3 -0
  313. package/dist/src/parsers/jsx/helpers.js +36 -0
  314. package/dist/src/parsers/jsx/index.d.ts +4 -0
  315. package/dist/src/parsers/jsx/index.js +25 -0
  316. package/dist/src/parsers/jsx/jsx.d.ts +10 -0
  317. package/dist/src/parsers/{jsx.js → jsx/jsx.js} +258 -330
  318. package/dist/src/parsers/jsx/metadata.d.ts +12 -0
  319. package/dist/src/parsers/jsx/metadata.js +70 -0
  320. package/dist/src/parsers/jsx/props.d.ts +2 -0
  321. package/dist/src/parsers/jsx/props.js +72 -0
  322. package/dist/src/parsers/jsx/state.d.ts +13 -0
  323. package/dist/src/parsers/jsx/state.js +161 -0
  324. package/dist/src/parsers/jsx/types.d.ts +11 -0
  325. package/dist/src/parsers/jsx/types.js +2 -0
  326. package/dist/src/parsers/liquid.js +51 -149
  327. package/dist/src/plugins/compile-away-builder-components.js +161 -116
  328. package/dist/src/symbols/symbol-processor.d.ts +2 -0
  329. package/dist/src/symbols/symbol-processor.js +58 -20
  330. package/dist/src/targets.d.ts +11 -6
  331. package/dist/src/targets.js +13 -1
  332. package/dist/src/types/config.d.ts +42 -13
  333. package/dist/src/types/json.d.ts +5 -2
  334. package/dist/src/types/mitosis-component.d.ts +40 -12
  335. package/dist/src/types/mitosis-node.d.ts +15 -9
  336. package/dist/src/types/transpiler.d.ts +14 -0
  337. package/dist/src/types/transpiler.js +2 -0
  338. package/dist/test/qwik/Accordion/low.jsx +45 -12
  339. package/dist/test/qwik/Accordion/med.jsx +2 -8
  340. package/dist/test/qwik/For/low.jsx +46 -27
  341. package/dist/test/qwik/For/med.jsx +2 -8
  342. package/dist/test/qwik/Image/high.js +1 -1
  343. package/dist/test/qwik/Image/med.js +24 -18
  344. package/dist/test/qwik/Image.slow/high.js +1 -1
  345. package/dist/test/qwik/Image.slow/med.js +24 -18
  346. package/dist/test/qwik/bindings/low.cjs +16 -4
  347. package/dist/test/qwik/bindings/med.cjs +1 -10
  348. package/dist/test/qwik/button/high.js +1 -1
  349. package/dist/test/qwik/button/low.js +18 -4
  350. package/dist/test/qwik/button/med.js +4 -10
  351. package/dist/test/qwik/component/bindings/low.jsx +72 -11
  352. package/dist/test/qwik/component/bindings/med.jsx +3 -49
  353. package/dist/test/qwik/component/component/inputs/high.cjsx +1 -1
  354. package/dist/test/qwik/component/component/inputs/med.cjsx +18 -15
  355. package/dist/test/qwik/for-loop.bindings/high.cjs +0 -0
  356. package/dist/test/qwik/for-loop.bindings/low.cjs +56 -0
  357. package/dist/test/qwik/for-loop.bindings/med.cjs +5 -0
  358. package/dist/test/qwik/hello_world/stylesheet/low.jsx +17 -3
  359. package/dist/test/qwik/hello_world/stylesheet/med.jsx +2 -8
  360. package/dist/test/qwik/mount/high.cjs +0 -0
  361. package/dist/test/qwik/mount/low.cjs +47 -0
  362. package/dist/test/qwik/mount/med.cjs +3 -0
  363. package/dist/test/qwik/page-with-symbol/low.js +17 -3
  364. package/dist/test/qwik/page-with-symbol/med.js +2 -8
  365. package/dist/test/qwik/show-hide/high.jsx +1 -1
  366. package/dist/test/qwik/show-hide/med.jsx +28 -21
  367. package/dist/test/qwik/svg/low.js +22 -5
  368. package/dist/test/qwik/svg/med.js +2 -8
  369. package/dist/test/qwik/todo/Todo.cjs/high.cjs +6 -10
  370. package/dist/test/qwik/todo/Todo.cjs/med.cjs +18 -15
  371. package/dist/test/qwik/todo/Todo.js/high.js +7 -10
  372. package/dist/test/qwik/todo/Todo.js/med.js +17 -15
  373. package/dist/test/qwik/todo/Todo.tsx/high.tsx +7 -10
  374. package/dist/test/qwik/todo/Todo.tsx/med.tsx +17 -15
  375. package/dist/test/qwik/todos/Todo.tsx/high.tsx +1 -1
  376. package/dist/test/qwik/todos/Todo.tsx/low.tsx +18 -13
  377. package/dist/test/qwik/todos/Todo.tsx/med.tsx +1 -6
  378. package/dist/tsconfig.build.tsbuildinfo +1 -1
  379. package/dist/tsconfig.tsbuildinfo +1 -1
  380. package/jsx-runtime.d.ts +2133 -0
  381. package/package.json +20 -8
  382. package/README.md +0 -239
  383. package/dist/src/__tests__/data/blocks/onUpdate.raw copy.d.ts +0 -1
  384. package/dist/src/__tests__/data/blocks/onUpdate.raw copy.jsx +0 -10
  385. package/dist/src/__tests__/data/blocks/slot.raw.d.ts +0 -5
  386. package/dist/src/__tests__/data/blocks/slot.raw.jsx +0 -6
  387. package/dist/src/__tests__/data/blocks/styles.raw.d.ts +0 -1
  388. package/dist/src/__tests__/data/blocks/styles.raw.jsx +0 -10
  389. package/dist/src/helpers/babel-transform copy.d.ts +0 -8
  390. package/dist/src/helpers/babel-transform copy.js +0 -138
  391. package/dist/src/helpers/collect-styles.d.ts +0 -35
  392. package/dist/src/helpers/collect-styles.js +0 -178
  393. package/dist/src/jsx-types.d.ts +0 -1171
  394. package/dist/src/parsers/jsx.d.ts +0 -20
@@ -0,0 +1,311 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.componentToQwik = void 0;
13
+ var babel_transform_1 = require("../../helpers/babel-transform");
14
+ var fast_clone_1 = require("../../helpers/fast-clone");
15
+ var collect_css_1 = require("../../helpers/styles/collect-css");
16
+ var state_1 = require("../../helpers/state");
17
+ var add_prevent_default_1 = require("./add-prevent-default");
18
+ var convert_method_to_function_1 = require("./convert-method-to-function");
19
+ var jsx_1 = require("./jsx");
20
+ var src_generator_1 = require("./src-generator");
21
+ var plugins_1 = require("../../modules/plugins");
22
+ Error.stackTraceLimit = 9999;
23
+ // TODO(misko): styles are not processed.
24
+ var DEBUG = false;
25
+ var componentToQwik = function (userOptions) {
26
+ if (userOptions === void 0) { userOptions = {}; }
27
+ return function (_a) {
28
+ var _b, _c, _d;
29
+ var _component = _a.component, path = _a.path;
30
+ // Make a copy we can safely mutate, similar to babel's toolchain
31
+ var component = (0, fast_clone_1.fastClone)(_component);
32
+ if (userOptions.plugins) {
33
+ component = (0, plugins_1.runPreJsonPlugins)(component, userOptions.plugins);
34
+ }
35
+ (0, add_prevent_default_1.addPreventDefault)(component);
36
+ if (userOptions.plugins) {
37
+ component = (0, plugins_1.runPostJsonPlugins)(component, userOptions.plugins);
38
+ }
39
+ var file = new src_generator_1.File(component.name + '.js', {
40
+ isPretty: true,
41
+ isJSX: true,
42
+ isTypeScript: false,
43
+ isModule: true,
44
+ isBuilder: false,
45
+ }, '@builder.io/qwik', '');
46
+ try {
47
+ emitImports(file, component);
48
+ emitTypes(file, component);
49
+ var metadata = component.meta.useMetadata || {};
50
+ var isLightComponent = ((_c = (_b = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _b === void 0 ? void 0 : _b.component) === null || _c === void 0 ? void 0 : _c.isLight) || false;
51
+ var imports_1 = (_d = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _d === void 0 ? void 0 : _d.imports;
52
+ imports_1 && Object.keys(imports_1).forEach(function (key) { return file.import(imports_1[key], key); });
53
+ var state_2 = emitStateMethodsAndRewriteBindings(file, component, metadata);
54
+ var hasState_1 = (0, state_1.checkHasState)(component);
55
+ var css_1 = null;
56
+ var componentBody = (0, src_generator_1.arrowFnBlock)(['props'], [
57
+ function () {
58
+ css_1 = emitUseStyles(file, component);
59
+ emitUseContext(file, component);
60
+ emitUseRef(file, component);
61
+ hasState_1 && emitUseStore(file, state_2);
62
+ emitUseContextProvider(file, component);
63
+ emitUseMount(file, component);
64
+ emitUseWatch(file, component);
65
+ emitUseCleanup(file, component);
66
+ emitTagNameHack(file, component);
67
+ emitJSX(file, component);
68
+ },
69
+ ], [component.propsTypeRef || 'any']);
70
+ file.src.const(component.name, isLightComponent
71
+ ? componentBody
72
+ : (0, src_generator_1.invoke)(file.import(file.qwikModule, 'component$'), [componentBody]), true, true);
73
+ file.exportDefault(component.name);
74
+ emitStyles(file, css_1);
75
+ DEBUG && file.exportConst('COMPONENT', JSON.stringify(component, null, 2));
76
+ return '// GENERATED BY MITOSIS\n\n' + file.toString();
77
+ }
78
+ catch (e) {
79
+ console.error(e);
80
+ return e.stack || String(e);
81
+ }
82
+ };
83
+ };
84
+ exports.componentToQwik = componentToQwik;
85
+ function emitTagNameHack(file, component) {
86
+ var _a;
87
+ var elementTag = (_a = component.meta.useMetadata) === null || _a === void 0 ? void 0 : _a.elementTag;
88
+ if (elementTag) {
89
+ file.src.emit(elementTag, '=', (0, convert_method_to_function_1.convertMethodToFunction)(elementTag, stateToMethodOrGetter(component.state), getLexicalScopeVars(component)), ';');
90
+ }
91
+ }
92
+ function emitUseMount(file, component) {
93
+ if (component.hooks.onMount) {
94
+ // This is called useMount, but in practice it is used as
95
+ // useClientEffect. Not sure if this is correct, but for now.
96
+ var code = component.hooks.onMount.code;
97
+ file.src.emit(file.import(file.qwikModule, 'useClientEffect$').localName, '(()=>{', code, '});');
98
+ }
99
+ }
100
+ function emitUseWatch(file, component) {
101
+ if (component.hooks.onUpdate) {
102
+ component.hooks.onUpdate.forEach(function (onUpdate) {
103
+ file.src.emit(file.import(file.qwikModule, 'useWatch$').localName, '(({track})=>{');
104
+ emitTrackExpressions(file.src, onUpdate.deps);
105
+ file.src.emit(convertTypeScriptToJS(onUpdate.code));
106
+ file.src.emit('});');
107
+ });
108
+ }
109
+ }
110
+ function emitTrackExpressions(src, deps) {
111
+ if (deps && deps.startsWith('[') && deps.endsWith(']')) {
112
+ var dependencies = deps.substring(1, deps.length - 1).split(',');
113
+ dependencies.forEach(function (dep) {
114
+ var lastDotIdx = dep.lastIndexOf('.');
115
+ if (lastDotIdx > 0) {
116
+ var objExp = dep.substring(0, lastDotIdx).replace(/\?$/, '');
117
+ var objProp = dep.substring(lastDotIdx + 1);
118
+ objExp && src.emit(objExp, '&&track(', objExp, ',"', objProp, '");');
119
+ }
120
+ });
121
+ }
122
+ }
123
+ function emitUseCleanup(file, component) {
124
+ if (component.hooks.onUnMount) {
125
+ var code = component.hooks.onUnMount.code;
126
+ file.src.emit(file.import(file.qwikModule, 'useCleanup$').localName, '(()=>{', code, '});');
127
+ }
128
+ }
129
+ function emitJSX(file, component) {
130
+ var directives = new Map();
131
+ var handlers = new Map();
132
+ var styles = new Map();
133
+ var parentSymbolBindings = {};
134
+ file.src.emit('return ', (0, jsx_1.renderJSXNodes)(file, directives, handlers, component.children, styles, parentSymbolBindings));
135
+ }
136
+ function emitUseContextProvider(file, component) {
137
+ Object.keys(component.context.set).forEach(function (ctxKey) {
138
+ var context = component.context.set[ctxKey];
139
+ file.src.emit(file.import(file.qwikModule, 'useContextProvider').localName, '(', context.name, ',', file.import(file.qwikModule, 'useStore').localName, '({');
140
+ context.value &&
141
+ Object.keys(context.value).forEach(function (prop) {
142
+ var propValue = context.value[prop];
143
+ file.src.emit(prop, ':');
144
+ if (isGetter(propValue)) {
145
+ file.src.emit('(()=>{', extractGetterBody(propValue), '})(),');
146
+ }
147
+ else if (typeof propValue == 'function') {
148
+ throw new Error('Qwik: Functions are not supported in context');
149
+ }
150
+ else {
151
+ file.src.emit(JSON.stringify(propValue));
152
+ }
153
+ });
154
+ file.src.emit('})', ');');
155
+ });
156
+ }
157
+ function emitUseContext(file, component) {
158
+ Object.keys(component.context.get).forEach(function (ctxKey) {
159
+ var context = component.context.get[ctxKey];
160
+ file.src.emit('const ', ctxKey, '=', file.import(file.qwikModule, 'useContext').localName, '(', context.name, ');');
161
+ });
162
+ }
163
+ function emitUseRef(file, component) {
164
+ Object.keys(component.refs).forEach(function (refKey) {
165
+ file.src.emit("const ", refKey, '=', file.import(file.qwikModule, 'useRef').localName, '();');
166
+ });
167
+ }
168
+ function emitUseStyles(file, component) {
169
+ var css = (0, collect_css_1.collectCss)(component, { prefix: component.name });
170
+ if (css) {
171
+ file.src.emit(file.import(file.qwikModule, 'useStylesScoped$').localName, '(STYLES);');
172
+ }
173
+ return css;
174
+ }
175
+ function emitStyles(file, css) {
176
+ if (css) {
177
+ file.exportConst('STYLES', '`' + css.replace(/`/g, '\\`') + '`');
178
+ }
179
+ }
180
+ /**
181
+ * @param file
182
+ * @param stateInit
183
+ */
184
+ function emitUseStore(file, stateInit) {
185
+ var state = stateInit[0];
186
+ var hasState = state && Object.keys(state).length > 0;
187
+ if (hasState) {
188
+ file.src.emit('const state=', file.import(file.qwikModule, 'useStore').localName, '(');
189
+ file.src.emit(JSON.stringify(state));
190
+ file.src.emit(');');
191
+ }
192
+ else {
193
+ // TODO hack for now so that `state` variable is defined, even though it is never read.
194
+ file.src.emit('const state={};');
195
+ }
196
+ }
197
+ function emitTypes(file, component) {
198
+ var _a;
199
+ if (file.options.isTypeScript) {
200
+ (_a = component.types) === null || _a === void 0 ? void 0 : _a.forEach(function (t) { return file.src.emit(t, '\n'); });
201
+ }
202
+ }
203
+ function emitStateMethodsAndRewriteBindings(file, component, metadata) {
204
+ var _a;
205
+ var lexicalArgs = getLexicalScopeVars(component);
206
+ var state = emitStateMethods(file, component.state, lexicalArgs);
207
+ var methodMap = stateToMethodOrGetter(component.state);
208
+ rewriteCodeExpr(component, methodMap, lexicalArgs, (_a = metadata.qwik) === null || _a === void 0 ? void 0 : _a.replace);
209
+ return state;
210
+ }
211
+ function rewriteCodeExpr(obj, methodMap, lexicalArgs, replace) {
212
+ if (obj && typeof obj == 'object') {
213
+ if (Array.isArray(obj)) {
214
+ obj.forEach(function (item) { return rewriteCodeExpr(item, methodMap, lexicalArgs, replace); });
215
+ }
216
+ else {
217
+ Object.keys(obj).forEach(function (key) {
218
+ var value = obj[key];
219
+ if (typeof value == 'string') {
220
+ if (value.startsWith(CODE_PREFIX) || key == 'code') {
221
+ var code_1 = (0, convert_method_to_function_1.convertMethodToFunction)(value, methodMap, lexicalArgs);
222
+ replace &&
223
+ Object.keys(replace).forEach(function (key) { return (code_1 = code_1.replace(key, replace[key])); });
224
+ obj[key] = code_1;
225
+ }
226
+ }
227
+ rewriteCodeExpr(value, methodMap, lexicalArgs, replace);
228
+ });
229
+ }
230
+ }
231
+ }
232
+ function getLexicalScopeVars(component) {
233
+ return __spreadArray(__spreadArray(['props', 'state'], Object.keys(component.refs), true), Object.keys(component.context.get), true);
234
+ }
235
+ function emitImports(file, component) {
236
+ var _a;
237
+ // <SELF> is used for self-referencing within the file.
238
+ file.import('<SELF>', component.name);
239
+ (_a = component.imports) === null || _a === void 0 ? void 0 : _a.forEach(function (i) {
240
+ Object.keys(i.imports).forEach(function (key) {
241
+ var keyValue = i.imports[key];
242
+ file.import(i.path.replace('.lite', '').replace('.tsx', ''), keyValue, key);
243
+ });
244
+ });
245
+ }
246
+ var CODE_PREFIX = '@builder.io/mitosis/';
247
+ var FUNCTION = CODE_PREFIX + 'function:';
248
+ var METHOD = CODE_PREFIX + 'method:';
249
+ var GETTER = CODE_PREFIX + 'method:get ';
250
+ function emitStateMethods(file, componentState, lexicalArgs) {
251
+ var stateValues = {};
252
+ var stateInit = [stateValues];
253
+ var methodMap = stateToMethodOrGetter(componentState);
254
+ Object.keys(componentState).forEach(function (key) {
255
+ var _a;
256
+ var code = (_a = componentState[key]) === null || _a === void 0 ? void 0 : _a.code;
257
+ if (isCode(code)) {
258
+ var codeIisGetter = isGetter(code);
259
+ var prefixIdx = code.indexOf(':') + 1;
260
+ if (codeIisGetter) {
261
+ prefixIdx += 'get '.length;
262
+ }
263
+ else if (isFunction(code)) {
264
+ prefixIdx += 'function '.length;
265
+ }
266
+ code = code.substring(prefixIdx);
267
+ code = (0, convert_method_to_function_1.convertMethodToFunction)(code, methodMap, lexicalArgs).replace('(', "(".concat(lexicalArgs.join(','), ","));
268
+ var functionName = code.split(/\(/)[0];
269
+ if (codeIisGetter) {
270
+ stateInit.push("state.".concat(key, "=").concat(functionName, "(").concat(lexicalArgs.join(','), ")"));
271
+ }
272
+ if (!file.options.isTypeScript) {
273
+ // Erase type information
274
+ code = convertTypeScriptToJS(code);
275
+ }
276
+ file.exportConst(functionName, 'function ' + code, true);
277
+ }
278
+ else {
279
+ stateValues[key] = code;
280
+ }
281
+ });
282
+ return stateInit;
283
+ }
284
+ function convertTypeScriptToJS(code) {
285
+ return (0, babel_transform_1.babelTransformExpression)(code, {});
286
+ }
287
+ function isGetter(code) {
288
+ return typeof code === 'string' && code.startsWith(GETTER);
289
+ }
290
+ function isCode(code) {
291
+ return typeof code === 'string' && code.startsWith(CODE_PREFIX);
292
+ }
293
+ function isFunction(code) {
294
+ return typeof code === 'string' && code.startsWith(FUNCTION);
295
+ }
296
+ function extractGetterBody(code) {
297
+ var start = code.indexOf('{');
298
+ var end = code.lastIndexOf('}');
299
+ return code.substring(start + 1, end).trim();
300
+ }
301
+ function stateToMethodOrGetter(state) {
302
+ var methodMap = {};
303
+ Object.keys(state).forEach(function (key) {
304
+ var _a;
305
+ var code = (_a = state[key]) === null || _a === void 0 ? void 0 : _a.code;
306
+ if (typeof code == 'string' && code.startsWith(METHOD)) {
307
+ methodMap[key] = code.startsWith(GETTER) ? 'getter' : 'method';
308
+ }
309
+ });
310
+ return methodMap;
311
+ }
@@ -16,6 +16,7 @@ export declare function createFileSet(options?: QwikOptions): FileSet;
16
16
  export declare function addComponent(fileSet: FileSet, component: MitosisComponent, opts?: {
17
17
  isRoot?: boolean;
18
18
  shareStyles?: boolean;
19
+ hostProps?: Record<string, string>;
19
20
  }): void;
20
21
  export declare function renderUseLexicalScope(file: File): (this: SrcBuilder) => SrcBuilder;
21
22
  export declare function addCommonStyles(fileSet: FileSet): void;
@@ -21,6 +21,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.addCommonStyles = exports.renderUseLexicalScope = exports.addComponent = exports.createFileSet = void 0;
24
+ var create_mitosis_node_1 = require("../../helpers/create-mitosis-node");
24
25
  var compile_away_builder_components_1 = require("../../plugins/compile-away-builder-components");
25
26
  var handlers_1 = require("./handlers");
26
27
  var jsx_1 = require("./jsx");
@@ -35,6 +36,7 @@ function createFileSet(options) {
35
36
  isModule: opts.output != 'cjs',
36
37
  isTypeScript: opts.output == 'ts',
37
38
  isJSX: opts.jsx,
39
+ isBuilder: true,
38
40
  };
39
41
  var fileSet = {
40
42
  high: new src_generator_1.File('high.' + extension, srcOptions, opts.qwikLib, opts.qrlPrefix),
@@ -53,8 +55,11 @@ function getCommonStyles(fileSet) {
53
55
  }
54
56
  function addComponent(fileSet, component, opts) {
55
57
  if (opts === void 0) { opts = {}; }
56
- var _opts = __assign({ isRoot: false, shareStyles: false }, opts);
57
- (0, compile_away_builder_components_1.compileAwayBuilderComponentsFromTree)(component, __assign(__assign({}, compile_away_builder_components_1.components), { Image: undefined, CoreButton: undefined }));
58
+ var _opts = __assign({ isRoot: false, shareStyles: false, hostProps: null }, opts);
59
+ (0, compile_away_builder_components_1.compileAwayBuilderComponentsFromTree)(component, __assign(__assign({}, compile_away_builder_components_1.components), {
60
+ // A set of components that should not be compiled away because they are implemented as runtime components.
61
+ Image: undefined, CoreButton: undefined }));
62
+ addBuilderBlockClass(component.children);
58
63
  var componentName = component.name;
59
64
  var handlers = (0, handlers_1.renderHandlers)(fileSet.high, componentName, component.children);
60
65
  // If the component has no handlers, than it is probably static
@@ -63,48 +68,60 @@ function addComponent(fileSet, component, opts) {
63
68
  var isStatic = Array.from(handlers.keys()).reduce(function (p, v) { return p && v.indexOf('state') == -1; }, true);
64
69
  var onRenderFile = isStatic ? fileSet.low : fileSet.med;
65
70
  var componentFile = fileSet.med;
66
- var styles = _opts.shareStyles
67
- ? getCommonStyles(fileSet).styles
68
- : new Map();
71
+ var styles = _opts.shareStyles ? getCommonStyles(fileSet).styles : new Map();
69
72
  (0, styles_1.collectStyles)(component.children, styles);
70
73
  var useStyles = function () { return null; };
71
- if (_opts.shareStyles) {
72
- if (_opts.isRoot) {
73
- var symbolName = componentName + '_styles';
74
- getCommonStyles(fileSet).symbolName = symbolName;
75
- useStyles = generateStyles(componentFile, fileSet.low, symbolName, false);
74
+ if (styles.size) {
75
+ if (_opts.shareStyles) {
76
+ if (_opts.isRoot) {
77
+ var symbolName = componentName + '_styles';
78
+ getCommonStyles(fileSet).symbolName = symbolName;
79
+ useStyles = generateStyles(onRenderFile, fileSet.low, symbolName, false);
80
+ }
76
81
  }
77
- }
78
- else {
79
- if (styles.size) {
82
+ else {
80
83
  var symbolName = componentName + '_styles';
81
84
  onRenderFile.exportConst(symbolName, (0, styles_1.renderStyles)(styles));
82
- useStyles = generateStyles(componentFile, onRenderFile, symbolName, true);
85
+ useStyles = generateStyles(onRenderFile, onRenderFile, symbolName, true);
83
86
  }
84
87
  }
85
- addComponentOnMount(componentFile, onRenderFile, componentName, component, useStyles);
86
- componentFile.exportConst(componentName, (0, src_generator_1.invoke)(componentFile.import(componentFile.qwikModule, 'componentQrl'), [generateQrl(componentFile, componentName + '_onMount')], ['any', 'any']));
87
88
  var directives = new Map();
88
- onRenderFile.exportConst(componentName + '_onRender', (0, src_generator_1.arrowFnBlock)([], [
89
- renderUseLexicalScope(onRenderFile),
90
- function () {
91
- return this.emit('return ', (0, jsx_1.renderJSXNodes)(onRenderFile, directives, handlers, component.children, styles, {}), ';');
92
- },
93
- ]));
89
+ var rootChildren = component.children;
90
+ if (_opts.hostProps) {
91
+ rootChildren = [
92
+ (0, create_mitosis_node_1.createMitosisNode)({
93
+ name: 'Host',
94
+ properties: _opts.hostProps,
95
+ children: component.children,
96
+ }),
97
+ ];
98
+ }
99
+ addComponentOnMount(onRenderFile, function () {
100
+ return this.emit('return ', (0, jsx_1.renderJSXNodes)(onRenderFile, directives, handlers, rootChildren, styles, {}), ';');
101
+ }, componentName, component, useStyles);
102
+ componentFile.exportConst(componentName, (0, src_generator_1.invoke)(componentFile.import(componentFile.qwikModule, 'componentQrl'), [generateQrl(componentFile, onRenderFile, componentName + '_onMount')], ['any', 'any']));
94
103
  directives.forEach(function (code, name) {
95
104
  fileSet.med.import(fileSet.med.qwikModule, 'h');
96
105
  fileSet.med.exportConst(name, code, true);
97
106
  });
98
107
  }
99
108
  exports.addComponent = addComponent;
100
- function generateStyles(componentFile, styleFile, symbol, scoped) {
109
+ function generateStyles(fromFile, dstFile, symbol, scoped) {
101
110
  return function () {
102
- this.emit((0, src_generator_1.invoke)(componentFile.import(componentFile.qwikModule, scoped ? 'withScopedStylesQrl' : 'useStylesQrl'), [generateQrl(styleFile, symbol)]), ';');
111
+ this.emit((0, src_generator_1.invoke)(fromFile.import(fromFile.qwikModule, scoped ? 'withScopedStylesQrl' : 'useStylesQrl'), [generateQrl(fromFile, dstFile, symbol)]), ';');
103
112
  };
104
113
  }
114
+ function addBuilderBlockClass(children) {
115
+ children.forEach(function (child) {
116
+ var props = child.properties;
117
+ if (props['builder-id']) {
118
+ props.class = (props.class ? props.class + ' ' : '') + 'builder-block';
119
+ }
120
+ });
121
+ }
105
122
  function renderUseLexicalScope(file) {
106
123
  return function () {
107
- return this.emit('const state=', file.import(file.qwikModule, 'useLexicalScope').name, '()[0]');
124
+ return this.emit('const state=', file.import(file.qwikModule, 'useLexicalScope').localName, '()[0]');
108
125
  };
109
126
  }
110
127
  exports.renderUseLexicalScope = renderUseLexicalScope;
@@ -116,32 +133,47 @@ function addCommonStyles(fileSet) {
116
133
  }
117
134
  }
118
135
  exports.addCommonStyles = addCommonStyles;
119
- function addComponentOnMount(componentFile, onRenderFile, componentName, component, useStyles) {
136
+ function addComponentOnMount(componentFile, onRenderEmit, componentName, component, useStyles) {
120
137
  var inputInitializer = [];
121
138
  if (component.inputs) {
122
139
  component.inputs.forEach(function (input) {
123
140
  input.defaultValue !== undefined &&
124
- inputInitializer.push('if(state.', input.name, '===undefined)state.', input.name, '=', JSON.stringify(input.defaultValue), ';');
141
+ inputInitializer.push('if(!state.hasOwnProperty("', input.name, '"))state.', input.name, '=', JSON.stringify(input.defaultValue), ';');
125
142
  });
126
143
  }
127
144
  componentFile.exportConst(componentName + '_onMount', function () {
128
145
  var _this = this;
129
- this.emit((0, src_generator_1.arrowFnValue)(['state'], function () {
146
+ this.emit((0, src_generator_1.arrowFnValue)(['props'], function () {
130
147
  var _a;
131
- return _this.emit.apply(_this, __spreadArray(__spreadArray(['{'], inputInitializer, false), ['typeof __STATE__==="object"&&Object.assign(state,__STATE__[state.serverStateId]);',
132
- (0, src_generator_1.iif)((_a = component.hooks.onMount) === null || _a === void 0 ? void 0 : _a.code),
133
- ';',
148
+ return _this.emit.apply(_this, __spreadArray(__spreadArray(['{',
149
+ 'const state=',
150
+ componentFile.import(componentFile.qwikModule, 'useStore').localName,
151
+ '(()=>{',
152
+ 'const state = Object.assign({},props,typeof __STATE__==="object"?__STATE__[props.serverStateId]:undefined);'], inputInitializer, false), [inlineCode((_a = component.hooks.onMount) === null || _a === void 0 ? void 0 : _a.code),
153
+ 'return state;',
154
+ '});',
134
155
  useStyles,
135
- 'return ',
136
- generateQrl(onRenderFile, componentName + '_onRender', ['state']),
156
+ onRenderEmit,
137
157
  ';}'], false));
138
158
  }));
139
159
  });
140
160
  }
141
- function generateQrl(componentFile, componentName, capture) {
161
+ function inlineCode(code) {
162
+ return function () {
163
+ if (code) {
164
+ // HACK: remove the return value as it is not the state we are creating.
165
+ code = code
166
+ .trim()
167
+ .replace(/return main\(\);?$/, '')
168
+ .trim();
169
+ this.emit(code, ';');
170
+ }
171
+ };
172
+ }
173
+ function generateQrl(fromFile, dstFile, componentName, capture) {
142
174
  if (capture === void 0) { capture = []; }
143
- return (0, src_generator_1.invoke)(componentFile.import(componentFile.qwikModule, 'qrl'), [
144
- componentFile.toQrlChunk(),
175
+ return (0, src_generator_1.invoke)(fromFile.import(fromFile.qwikModule, 'qrl'), [
176
+ dstFile.toQrlChunk(),
145
177
  (0, src_generator_1.quote)(componentName),
146
178
  "[".concat(capture.join(','), "]"),
147
179
  ]);
@@ -0,0 +1 @@
1
+ export declare function convertMethodToFunction(code: string, properties: Record<string, 'method' | 'getter'>, lexicalArgs: string[]): string;
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertMethodToFunction = void 0;
4
+ function convertMethodToFunction(code, properties, lexicalArgs) {
5
+ var out = [];
6
+ var idx = 0;
7
+ var lastIdx = idx;
8
+ var end = code.length;
9
+ var mode = "code" /* Mode.code */;
10
+ var braceDepth = 0;
11
+ var stringEndBraceDepth = -1;
12
+ var stringEndBraceDepthQueue = [];
13
+ var lastCh = null;
14
+ while (idx < end) {
15
+ var ch = code.charCodeAt(idx++);
16
+ // console.log(mode, code[idx - 1]);
17
+ switch (mode) {
18
+ case "code" /* Mode.code */:
19
+ if (ch === QUOTE_DOUBLE) {
20
+ mode = "stringDouble" /* Mode.stringDouble */;
21
+ }
22
+ else if (ch === QUOTE_SINGLE) {
23
+ mode = "stringSingle" /* Mode.stringSingle */;
24
+ }
25
+ else if (ch === QUOTE_BACK_TICK) {
26
+ mode = "stringTemplate" /* Mode.stringTemplate */;
27
+ }
28
+ else if (ch === OPEN_BRACE) {
29
+ braceDepth++;
30
+ }
31
+ else if (lastCh == FORWARD_SLASH && ch == FORWARD_SLASH) {
32
+ mode = "commentSingleline" /* Mode.commentSingleline */;
33
+ }
34
+ else if (lastCh == FORWARD_SLASH && ch == STAR) {
35
+ mode = "commentMultiline" /* Mode.commentMultiline */;
36
+ }
37
+ else if (ch === CLOSE_BRACE) {
38
+ braceDepth--;
39
+ if (braceDepth === stringEndBraceDepth) {
40
+ stringEndBraceDepth = stringEndBraceDepthQueue.pop();
41
+ mode = "stringTemplate" /* Mode.stringTemplate */;
42
+ }
43
+ }
44
+ else if (isWord(ch, code, idx, 'this') || isWord(ch, code, idx, 'state')) {
45
+ idx--;
46
+ flush();
47
+ consumeIdent();
48
+ if (code.charCodeAt(idx) == DOT) {
49
+ idx++;
50
+ var propEndIdx = findIdentEnd();
51
+ var identifier = code.substring(idx, propEndIdx);
52
+ var propType = properties[identifier];
53
+ if (propType) {
54
+ var isGetter = code.charCodeAt(propEndIdx) !== OPEN_PAREN;
55
+ lastIdx = idx = propEndIdx + (isGetter ? 0 : 1);
56
+ if (isGetter) {
57
+ if (propType === 'method') {
58
+ out.push(identifier, ".bind(null,".concat(lexicalArgs.join(','), ")"));
59
+ }
60
+ else {
61
+ out.push(identifier, "(".concat(lexicalArgs.join(','), ")"));
62
+ }
63
+ }
64
+ else {
65
+ out.push(identifier, "(".concat(lexicalArgs.join(','), ","));
66
+ }
67
+ }
68
+ else {
69
+ flush();
70
+ }
71
+ }
72
+ }
73
+ break;
74
+ case "commentSingleline" /* Mode.commentSingleline */:
75
+ if (ch == EOL)
76
+ mode = "code" /* Mode.code */;
77
+ break;
78
+ case "commentMultiline" /* Mode.commentMultiline */:
79
+ if (lastCh == STAR && ch == FORWARD_SLASH)
80
+ mode = "code" /* Mode.code */;
81
+ break;
82
+ case "stringSingle" /* Mode.stringSingle */:
83
+ if (lastCh !== BACKSLASH && ch == QUOTE_SINGLE)
84
+ mode = "code" /* Mode.code */;
85
+ break;
86
+ case "stringDouble" /* Mode.stringDouble */:
87
+ if (lastCh !== BACKSLASH && ch == QUOTE_DOUBLE)
88
+ mode = "code" /* Mode.code */;
89
+ break;
90
+ case "stringTemplate" /* Mode.stringTemplate */:
91
+ if (lastCh !== BACKSLASH && ch == QUOTE_BACK_TICK) {
92
+ mode = "code" /* Mode.code */;
93
+ }
94
+ else if (lastCh === DOLLAR && ch == OPEN_BRACE) {
95
+ mode = "code" /* Mode.code */;
96
+ stringEndBraceDepthQueue.push(stringEndBraceDepth);
97
+ stringEndBraceDepth = braceDepth;
98
+ braceDepth++;
99
+ }
100
+ break;
101
+ }
102
+ lastCh = ch;
103
+ }
104
+ flush();
105
+ return out.join('');
106
+ function flush() {
107
+ out.push(code.substring(lastIdx, idx));
108
+ lastIdx = idx;
109
+ }
110
+ function findIdentEnd() {
111
+ var scanIdx = idx;
112
+ while (isIdentCh(code.charCodeAt(scanIdx)) && scanIdx < end) {
113
+ scanIdx++;
114
+ }
115
+ return scanIdx;
116
+ }
117
+ function consumeIdent() {
118
+ while (isIdentCh(code.charCodeAt(idx))) {
119
+ idx++;
120
+ }
121
+ }
122
+ }
123
+ exports.convertMethodToFunction = convertMethodToFunction;
124
+ function isIdentCh(ch) {
125
+ return ((CHAR_0 <= ch && ch <= CHAR_9) ||
126
+ (CHAR_a <= ch && ch <= CHAR_z) ||
127
+ (CHAR_A <= ch && ch <= CHAR_Z) ||
128
+ ch === UNDERSCORE ||
129
+ ch === DOLLAR);
130
+ }
131
+ function isWord(ch, code, idx, word) {
132
+ if (ch !== word.charCodeAt(0))
133
+ return false;
134
+ for (var i = 1; i < word.length; i++) {
135
+ if (code.charCodeAt(idx + i - 1) !== word.charCodeAt(i)) {
136
+ return false;
137
+ }
138
+ }
139
+ if (isIdentCh(code.charCodeAt(idx + word.length - 1))) {
140
+ return false;
141
+ }
142
+ return true;
143
+ }
144
+ var QUOTE_DOUBLE = '"'.charCodeAt(0);
145
+ var QUOTE_SINGLE = "'".charCodeAt(0);
146
+ var QUOTE_BACK_TICK = '`'.charCodeAt(0);
147
+ var BACKSLASH = "\\".charCodeAt(0);
148
+ var FORWARD_SLASH = "/".charCodeAt(0);
149
+ var EOL = "\n".charCodeAt(0);
150
+ var STAR = "*".charCodeAt(0);
151
+ var CHAR_0 = "0".charCodeAt(0);
152
+ var CHAR_9 = "9".charCodeAt(0);
153
+ var CHAR_a = "a".charCodeAt(0);
154
+ var CHAR_z = "z".charCodeAt(0);
155
+ var CHAR_A = "A".charCodeAt(0);
156
+ var CHAR_Z = "Z".charCodeAt(0);
157
+ var UNDERSCORE = "_".charCodeAt(0);
158
+ var DOLLAR = "$".charCodeAt(0);
159
+ var DOT = ".".charCodeAt(0);
160
+ var OPEN_PAREN = '('.charCodeAt(0);
161
+ var OPEN_BRACE = '{'.charCodeAt(0);
162
+ var CLOSE_BRACE = '}'.charCodeAt(0);