@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
@@ -9,7 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.componentToTemplate = void 0;
11
11
  var standalone_1 = require("prettier/standalone");
12
- var collect_styles_1 = require("../helpers/collect-styles");
12
+ var collect_css_1 = require("../helpers/styles/collect-css");
13
13
  var fast_clone_1 = require("../helpers/fast-clone");
14
14
  var jsx_1 = require("../parsers/jsx");
15
15
  var plugins_1 = require("../modules/plugins");
@@ -17,13 +17,12 @@ var dedent_1 = __importDefault(require("dedent"));
17
17
  var get_state_object_string_1 = require("../helpers/get-state-object-string");
18
18
  var mappers = {
19
19
  Fragment: function (json, options) {
20
- return "<div>".concat(json.children
21
- .map(function (item) { return blockToTemplate(item, options); })
22
- .join('\n'), "</div>");
20
+ return "<div>".concat(json.children.map(function (item) { return blockToTemplate(item, options); }).join('\n'), "</div>");
23
21
  },
24
22
  };
25
23
  // TODO: spread support
26
24
  var blockToTemplate = function (json, options) {
25
+ var _a, _b, _c, _d;
27
26
  if (options === void 0) { options = {}; }
28
27
  if (mappers[json.name]) {
29
28
  return mappers[json.name](json, options);
@@ -32,24 +31,20 @@ var blockToTemplate = function (json, options) {
32
31
  return json.properties._text;
33
32
  }
34
33
  if (json.bindings._text) {
35
- return "${".concat(json.bindings._text, "}");
34
+ return "${".concat((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code, "}");
36
35
  }
37
36
  var str = '';
38
37
  if (json.name === 'For') {
39
- str += "${".concat(json.bindings.each, "?.map(").concat(json.properties._forName, " => `");
38
+ str += "${".concat((_b = json.bindings.each) === null || _b === void 0 ? void 0 : _b.code, "?.map(").concat(json.properties._forName, " => `");
40
39
  if (json.children) {
41
- str += json.children
42
- .map(function (item) { return blockToTemplate(item, options); })
43
- .join('\n');
40
+ str += json.children.map(function (item) { return blockToTemplate(item, options); }).join('\n');
44
41
  }
45
42
  str += '`).join("")}';
46
43
  }
47
44
  else if (json.name === 'Show') {
48
- str += "${!(".concat(json.bindings.when, ") ? '' : `");
45
+ str += "${!(".concat((_c = json.bindings.when) === null || _c === void 0 ? void 0 : _c.code, ") ? '' : `");
49
46
  if (json.children) {
50
- str += json.children
51
- .map(function (item) { return blockToTemplate(item, options); })
52
- .join('\n');
47
+ str += json.children.map(function (item) { return blockToTemplate(item, options); }).join('\n');
53
48
  }
54
49
  str += '`}';
55
50
  }
@@ -71,7 +66,7 @@ var blockToTemplate = function (json, options) {
71
66
  if (key === '_spread' || key === 'ref' || key === 'css') {
72
67
  continue;
73
68
  }
74
- var value = json.bindings[key];
69
+ var value = (_d = json.bindings[key]) === null || _d === void 0 ? void 0 : _d.code;
75
70
  // TODO: proper babel transform to replace. Util for this
76
71
  var useValue = value;
77
72
  if (key.startsWith('on')) {
@@ -86,9 +81,7 @@ var blockToTemplate = function (json, options) {
86
81
  }
87
82
  str += '>';
88
83
  if (json.children) {
89
- str += json.children
90
- .map(function (item) { return blockToTemplate(item, options); })
91
- .join('\n');
84
+ str += json.children.map(function (item) { return blockToTemplate(item, options); }).join('\n');
92
85
  }
93
86
  str += "</".concat(json.name, ">");
94
87
  }
@@ -103,7 +96,7 @@ var componentToTemplate = function (options) {
103
96
  if (options.plugins) {
104
97
  json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
105
98
  }
106
- var css = (0, collect_styles_1.collectCss)(json);
99
+ var css = (0, collect_css_1.collectCss)(json);
107
100
  if (options.plugins) {
108
101
  json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
109
102
  }
@@ -1,13 +1,21 @@
1
1
  import { MitosisNode } from '../types/mitosis-node';
2
- import { BaseTranspilerOptions, TranspilerArgs } from '../types/config';
3
- export interface ToVueOptions extends BaseTranspilerOptions {
4
- vueVersion?: 2 | 3;
2
+ import { BaseTranspilerOptions, Transpiler } from '../types/transpiler';
3
+ import { OmitObj } from '../helpers/typescript';
4
+ export declare type VueVersion = 2 | 3;
5
+ interface VueVersionOpt {
6
+ vueVersion: VueVersion;
7
+ }
8
+ export interface ToVueOptions extends BaseTranspilerOptions, VueVersionOpt {
5
9
  cssNamespace?: () => string;
6
10
  namePrefix?: (path: string) => string;
7
- builderRegister?: boolean;
8
- registerComponentPrepend?: string;
11
+ asyncComponentImports?: boolean;
12
+ }
13
+ declare type BlockRenderer = (json: MitosisNode, options: ToVueOptions, scope?: Scope) => string;
14
+ interface Scope {
15
+ isRootNode?: boolean;
9
16
  }
10
- export declare const blockToVue: (node: MitosisNode, options: ToVueOptions) => string;
11
- export declare const componentToVue: (userOptions?: ToVueOptions) => ({ component, path }: TranspilerArgs & {
12
- path: string;
13
- }) => string;
17
+ export declare const blockToVue: BlockRenderer;
18
+ declare type VueOptsWithoutVersion = OmitObj<ToVueOptions, VueVersionOpt>;
19
+ export declare const componentToVue2: (vueOptions?: VueOptsWithoutVersion) => Transpiler;
20
+ export declare const componentToVue3: (vueOptions?: VueOptsWithoutVersion) => Transpiler;
21
+ export {};
@@ -38,10 +38,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  return (mod && mod.__esModule) ? mod : { "default": mod };
39
39
  };
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.componentToVue = exports.blockToVue = void 0;
41
+ exports.componentToVue3 = exports.componentToVue2 = exports.blockToVue = void 0;
42
42
  var dedent_1 = __importDefault(require("dedent"));
43
43
  var standalone_1 = require("prettier/standalone");
44
- var collect_styles_1 = require("../helpers/collect-styles");
44
+ var collect_css_1 = require("../helpers/styles/collect-css");
45
45
  var fast_clone_1 = require("../helpers/fast-clone");
46
46
  var get_state_object_string_1 = require("../helpers/get-state-object-string");
47
47
  var map_refs_1 = require("../helpers/map-refs");
@@ -59,15 +59,33 @@ var get_components_used_1 = require("../helpers/get-components-used");
59
59
  var lodash_1 = require("lodash");
60
60
  var replace_idenifiers_1 = require("../helpers/replace-idenifiers");
61
61
  var filter_empty_text_nodes_1 = require("../helpers/filter-empty-text-nodes");
62
- var json5_1 = __importDefault(require("json5"));
63
62
  var process_http_requests_1 = require("../helpers/process-http-requests");
64
63
  var patterns_1 = require("../helpers/patterns");
65
64
  var method_literal_prefix_1 = require("../constants/method-literal-prefix");
65
+ var function_1 = require("fp-ts/lib/function");
66
+ var get_custom_imports_1 = require("../helpers/get-custom-imports");
67
+ var slots_1 = require("../helpers/slots");
68
+ function encodeQuotes(string) {
69
+ return string.replace(/"/g, '&quot;');
70
+ }
71
+ var SPECIAL_PROPERTIES = {
72
+ V_IF: 'v-if',
73
+ V_FOR: 'v-for',
74
+ V_ELSE: 'v-else',
75
+ V_ELSE_IF: 'v-else-if',
76
+ };
66
77
  function getContextNames(json) {
67
78
  return Object.keys(json.context.get);
68
79
  }
69
80
  var ON_UPDATE_HOOK_NAME = 'onUpdateHook';
70
81
  var getOnUpdateHookName = function (index) { return ON_UPDATE_HOOK_NAME + "".concat(index); };
82
+ var invertBooleanExpression = function (expression) { return "!Boolean(".concat(expression, ")"); };
83
+ var addPropertiesToJson = function (properties) {
84
+ return function (json) { return (__assign(__assign({}, json), { properties: __assign(__assign({}, json.properties), properties) })); };
85
+ };
86
+ var addBindingsToJson = function (bindings) {
87
+ return function (json) { return (__assign(__assign({}, json), { bindings: __assign(__assign({}, json.bindings), bindings) })); };
88
+ };
71
89
  // TODO: migrate all stripStateAndPropsRefs to use this here
72
90
  // to properly replace context refs
73
91
  function processBinding(code, _options, json) {
@@ -82,42 +100,86 @@ var NODE_MAPPERS = {
82
100
  return json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n');
83
101
  },
84
102
  For: function (json, options) {
85
- var keyValue = json.bindings.key || 'index';
86
- var forValue = "(".concat(json.properties._forName, ", index) in ").concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.each));
103
+ var _a, _b;
104
+ var _c;
105
+ var keyValue = json.bindings.key || { code: 'index' };
106
+ var forValue = "(".concat(json.properties._forName, ", index) in ").concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code));
87
107
  if (options.vueVersion >= 3) {
88
108
  // TODO: tmk key goes on different element (parent vs child) based on Vue 2 vs Vue 3
89
- return "<template :key=\"".concat(keyValue, "\" v-for=\"").concat(forValue, "\">\n ").concat(json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n'), "\n </template>");
109
+ return "<template :key=\"".concat(encodeQuotes((keyValue === null || keyValue === void 0 ? void 0 : keyValue.code) || 'index'), "\" v-for=\"").concat(encodeQuotes(forValue), "\">\n ").concat(json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n'), "\n </template>");
90
110
  }
91
111
  // Vue 2 can only handle one root element
92
112
  var firstChild = json.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)[0];
93
- if (!firstChild) {
94
- return '';
95
- }
96
- firstChild.bindings.key = keyValue;
97
- firstChild.properties['v-for'] = forValue;
98
- return (0, exports.blockToVue)(firstChild, options);
113
+ // Edge-case for when the parent is a `Show`, we need to pass down the `v-if` prop.
114
+ var jsonIf = json.properties[SPECIAL_PROPERTIES.V_IF];
115
+ return firstChild
116
+ ? (0, function_1.pipe)(firstChild, addBindingsToJson({ key: keyValue }), addPropertiesToJson(__assign((_a = {}, _a[SPECIAL_PROPERTIES.V_FOR] = forValue, _a), (jsonIf ? (_b = {}, _b[SPECIAL_PROPERTIES.V_IF] = jsonIf, _b) : {}))), function (block) { return (0, exports.blockToVue)(block, options); })
117
+ : '';
99
118
  },
100
- Show: function (json, options) {
101
- var ifValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.when);
102
- if (options.vueVersion >= 3) {
103
- return "\n <template v-if=\"".concat(ifValue, "\">\n ").concat(json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n'), "\n </template>\n ").concat(!json.meta.else
104
- ? ''
105
- : "\n <template v-else>\n ".concat((0, exports.blockToVue)(json.meta.else, options), "\n </template>\n "), "\n ");
106
- }
107
- var ifString = '';
108
- // Vue 2 can only handle one root element
109
- var firstChild = json.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)[0];
110
- if (firstChild) {
111
- firstChild.properties['v-if'] = ifValue;
112
- ifString = (0, exports.blockToVue)(firstChild, options);
113
- }
114
- var elseString = '';
115
- var elseBlock = json.meta.else;
116
- if ((0, is_mitosis_node_1.isMitosisNode)(elseBlock)) {
117
- elseBlock.properties['v-else'] = '';
118
- elseString = (0, exports.blockToVue)(elseBlock, options);
119
+ Show: function (json, options, scope) {
120
+ var _a, _b, _c, _d, _e;
121
+ var _f, _g;
122
+ var ifValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_f = json.bindings.when) === null || _f === void 0 ? void 0 : _f.code);
123
+ switch (options.vueVersion) {
124
+ case 3:
125
+ return "\n <template ".concat(SPECIAL_PROPERTIES.V_IF, "=\"").concat(encodeQuotes(ifValue), "\">\n ").concat(json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n'), "\n </template>\n ").concat((0, is_mitosis_node_1.isMitosisNode)(json.meta.else)
126
+ ? "\n <template ".concat(SPECIAL_PROPERTIES.V_ELSE, ">\n ").concat((0, exports.blockToVue)(json.meta.else, options), "\n </template>")
127
+ : '', "\n ");
128
+ case 2:
129
+ // Vue 2 can only handle one root element, so we just take the first one.
130
+ // TO-DO: warn user of multi-children Show.
131
+ var firstChild = json.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)[0];
132
+ var elseBlock = json.meta.else;
133
+ var hasShowChild = (firstChild === null || firstChild === void 0 ? void 0 : firstChild.name) === 'Show';
134
+ var childElseBlock = firstChild === null || firstChild === void 0 ? void 0 : firstChild.meta.else;
135
+ /**
136
+ * This is special edge logic to handle 2 nested Show elements in Vue 2.
137
+ * We need to invert the logic to make it work, due to no-template-root-element limitations in Vue 2.
138
+ *
139
+ * <show when={foo} else={else-1}>
140
+ * <show when={bar} else={else-2}>
141
+ * <if-code>
142
+ * </show>
143
+ * </show>
144
+ *
145
+ *
146
+ * foo: true && bar: true => if-code
147
+ * foo: true && bar: false => else-2
148
+ * foo: false && bar: true?? => else-1
149
+ *
150
+ *
151
+ * map to:
152
+ *
153
+ * <else-1 if={!foo} />
154
+ * <else-2 else-if={!bar} />
155
+ * <if-code v-else />
156
+ *
157
+ */
158
+ if (firstChild &&
159
+ (0, is_mitosis_node_1.isMitosisNode)(elseBlock) &&
160
+ hasShowChild &&
161
+ (0, is_mitosis_node_1.isMitosisNode)(childElseBlock)) {
162
+ var ifString = (0, function_1.pipe)(elseBlock, addPropertiesToJson((_a = {}, _a[SPECIAL_PROPERTIES.V_IF] = invertBooleanExpression(ifValue), _a)), function (block) { return (0, exports.blockToVue)(block, options); });
163
+ var childIfValue = (0, function_1.pipe)((_g = firstChild.bindings.when) === null || _g === void 0 ? void 0 : _g.code, strip_state_and_props_refs_1.stripStateAndPropsRefs, invertBooleanExpression);
164
+ var elseIfString = (0, function_1.pipe)(childElseBlock, addPropertiesToJson((_b = {}, _b[SPECIAL_PROPERTIES.V_ELSE_IF] = childIfValue, _b)), function (block) { return (0, exports.blockToVue)(block, options); });
165
+ var firstChildOfFirstChild = firstChild.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)[0];
166
+ var elseString = firstChildOfFirstChild
167
+ ? (0, function_1.pipe)(firstChildOfFirstChild, addPropertiesToJson((_c = {}, _c[SPECIAL_PROPERTIES.V_ELSE] = '', _c)), function (block) { return (0, exports.blockToVue)(block, options); })
168
+ : '';
169
+ return "\n\n ".concat(ifString, "\n\n ").concat(elseIfString, "\n\n ").concat(elseString, "\n\n ");
170
+ }
171
+ else {
172
+ var ifString = firstChild
173
+ ? (0, function_1.pipe)(firstChild, addPropertiesToJson((_d = {}, _d[SPECIAL_PROPERTIES.V_IF] = ifValue, _d)), function (block) { return (0, exports.blockToVue)(block, options); })
174
+ : '';
175
+ var elseString = (0, is_mitosis_node_1.isMitosisNode)(elseBlock)
176
+ ? (0, function_1.pipe)(elseBlock, addPropertiesToJson((_e = {}, _e[SPECIAL_PROPERTIES.V_ELSE] = '', _e)), function (block) {
177
+ return (0, exports.blockToVue)(block, options);
178
+ })
179
+ : '';
180
+ return "\n ".concat(ifString, "\n ").concat(elseString, "\n ");
181
+ }
119
182
  }
120
- return "\n ".concat(ifString, "\n ").concat(elseString, "\n ");
121
183
  },
122
184
  };
123
185
  // TODO: Maybe in the future allow defining `string | function` as values
@@ -129,7 +191,7 @@ function processDynamicComponents(json, _options) {
129
191
  (0, traverse_1.default)(json).forEach(function (node) {
130
192
  if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
131
193
  if (node.name.includes('.')) {
132
- node.bindings.is = node.name;
194
+ node.bindings.is = { code: node.name };
133
195
  node.name = 'component';
134
196
  }
135
197
  }
@@ -155,68 +217,90 @@ var stringifyBinding = function (node) {
155
217
  return '';
156
218
  }
157
219
  else if (key === 'class') {
158
- return " :class=\"_classStringToObject(".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value, {
159
- replaceWith: 'this.',
220
+ return " :class=\"_classStringToObject(".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value === null || value === void 0 ? void 0 : value.code, {
221
+ replaceWith: '',
160
222
  }), ")\" ");
161
223
  // TODO: support dynamic classes as objects somehow like Vue requires
162
224
  // https://vuejs.org/v2/guide/class-and-style.html
163
225
  }
164
226
  else {
165
227
  // TODO: proper babel transform to replace. Util for this
166
- var useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value);
228
+ var useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value === null || value === void 0 ? void 0 : value.code);
167
229
  if (key.startsWith('on')) {
230
+ var _b = value.arguments, cusArgs = _b === void 0 ? ['event'] : _b;
168
231
  var event_1 = key.replace('on', '').toLowerCase();
169
232
  if (event_1 === 'change' && node.name === 'input') {
170
233
  event_1 = 'input';
171
234
  }
235
+ var isAssignmentExpression = useValue.includes('=');
172
236
  // TODO: proper babel transform to replace. Util for this
173
- return " @".concat(event_1, "=\"").concat((0, remove_surrounding_block_1.removeSurroundingBlock)(useValue
174
- // TODO: proper reference parse and replacing
175
- .replace(/event\./g, '$event.')), "\" ");
237
+ if (isAssignmentExpression) {
238
+ return " @".concat(event_1, "=\"").concat(encodeQuotes((0, remove_surrounding_block_1.removeSurroundingBlock)((0, replace_idenifiers_1.replaceIdentifiers)(useValue, cusArgs[0], '$event'))), "\" ");
239
+ }
240
+ else {
241
+ return " @".concat(event_1, "=\"").concat(encodeQuotes((0, remove_surrounding_block_1.removeSurroundingBlock)((0, remove_surrounding_block_1.removeSurroundingBlock)((0, replace_idenifiers_1.replaceIdentifiers)(useValue, cusArgs[0], '$event')))), "\" ");
242
+ }
176
243
  }
177
244
  else if (key === 'ref') {
178
- return " ref=\"".concat(useValue, "\" ");
245
+ return " ref=\"".concat(encodeQuotes(useValue), "\" ");
179
246
  }
180
247
  else if (BINDING_MAPPERS[key]) {
181
- return " ".concat(BINDING_MAPPERS[key], "=\"").concat(useValue, "\" ");
248
+ return " ".concat(BINDING_MAPPERS[key], "=\"").concat(encodeQuotes(useValue.replace(/"/g, "\\'")), "\" ");
182
249
  }
183
250
  else {
184
- return " :".concat(key, "=\"").concat(useValue, "\" ");
251
+ return " :".concat(key, "=\"").concat(encodeQuotes(useValue), "\" ");
185
252
  }
186
253
  }
187
254
  };
188
255
  };
189
- var blockToVue = function (node, options) {
256
+ var blockToVue = function (node, options, scope) {
257
+ var _a, _b;
190
258
  var nodeMapper = NODE_MAPPERS[node.name];
191
259
  if (nodeMapper) {
192
- return nodeMapper(node, options);
260
+ return nodeMapper(node, options, scope);
193
261
  }
194
262
  if ((0, is_children_1.default)(node)) {
195
- return "<slot></slot>";
263
+ return "<slot/>";
196
264
  }
197
265
  if (node.name === 'style') {
198
266
  // Vue doesn't allow <style>...</style> in templates, but does support the synonymous
199
- // <component is="style">...</component>
267
+ // <component is="'style'">...</component>
200
268
  node.name = 'component';
201
- node.bindings.is = 'style';
269
+ node.bindings.is = { code: "'style'" };
202
270
  }
203
271
  if (node.properties._text) {
204
272
  return "".concat(node.properties._text);
205
273
  }
206
- if (node.bindings._text) {
207
- return "{{".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(node.bindings._text), "}}");
274
+ var textCode = (_a = node.bindings._text) === null || _a === void 0 ? void 0 : _a.code;
275
+ if (textCode) {
276
+ var strippedTextCode = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(textCode);
277
+ if ((0, slots_1.isSlotProperty)(strippedTextCode)) {
278
+ return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(strippedTextCode).toLowerCase(), "\"/>");
279
+ }
280
+ return "{{".concat(strippedTextCode, "}}");
208
281
  }
209
282
  var str = '';
210
283
  str += "<".concat(node.name, " ");
211
- if (node.bindings._spread) {
212
- str += "v-bind=\"".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(node.bindings._spread), "\"");
284
+ if ((_b = node.bindings._spread) === null || _b === void 0 ? void 0 : _b.code) {
285
+ str += "v-bind=\"".concat(encodeQuotes((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(node.bindings._spread.code)), "\"");
213
286
  }
214
287
  for (var key in node.properties) {
215
288
  var value = node.properties[key];
216
- str += " ".concat(key, "=\"").concat(value, "\" ");
289
+ if (key === 'className') {
290
+ continue;
291
+ }
292
+ else if (key === SPECIAL_PROPERTIES.V_ELSE) {
293
+ str += " ".concat(key, " ");
294
+ }
295
+ else if (typeof value === 'string') {
296
+ str += " ".concat(key, "=\"").concat(encodeQuotes(value), "\" ");
297
+ }
217
298
  }
218
299
  var stringifiedBindings = Object.entries(node.bindings)
219
- .map(stringifyBinding(node))
300
+ .map(function (_a) {
301
+ var k = _a[0], v = _a[1];
302
+ return stringifyBinding(node)([k, v]);
303
+ })
220
304
  .join('');
221
305
  str += stringifiedBindings;
222
306
  if (jsx_1.selfClosingTags.has(node.name)) {
@@ -232,7 +316,7 @@ exports.blockToVue = blockToVue;
232
316
  function getContextInjectString(component, options) {
233
317
  var str = '{';
234
318
  for (var key in component.context.get) {
235
- str += "\n ".concat(key, ": \"").concat(component.context.get[key].name, "\",\n ");
319
+ str += "\n ".concat(key, ": \"").concat(encodeQuotes(component.context.get[key].name), "\",\n ");
236
320
  }
237
321
  str += '}';
238
322
  return str;
@@ -242,10 +326,8 @@ function getContextProvideString(component, options) {
242
326
  for (var key in component.context.set) {
243
327
  var _a = component.context.set[key], value = _a.value, name_1 = _a.name;
244
328
  str += "\n ".concat(name_1, ": ").concat(value
245
- ? (0, get_state_object_string_1.getMemberObjectString)(value, {
246
- valueMapper: function (code) {
247
- return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, { replaceWith: '_this.' });
248
- },
329
+ ? (0, get_state_object_string_1.stringifyContextValue)(value, {
330
+ valueMapper: function (code) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, { replaceWith: '_this.' }); },
249
331
  })
250
332
  : null, ",\n ");
251
333
  }
@@ -266,10 +348,14 @@ var onUpdatePlugin = function (options) { return ({
266
348
  .filter(function (hook) { var _a; return (_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length; })
267
349
  .forEach(function (hook, index) {
268
350
  var _a;
269
- component.state[getOnUpdateHookName(index)] = "".concat(method_literal_prefix_1.methodLiteralPrefix, "get ").concat(getOnUpdateHookName(index), " () {\n return {\n ").concat((_a = hook.deps) === null || _a === void 0 ? void 0 : _a.slice(1, -1).split(',').map(function (dep, k) {
351
+ var code = "".concat(method_literal_prefix_1.methodLiteralPrefix, "get ").concat(getOnUpdateHookName(index), " () {\n return {\n ").concat((_a = hook.deps) === null || _a === void 0 ? void 0 : _a.slice(1, -1).split(',').map(function (dep, k) {
270
352
  var val = dep.trim();
271
353
  return "".concat(k, ": ").concat(val);
272
354
  }).join(','), "\n }\n }");
355
+ component.state[getOnUpdateHookName(index)] = {
356
+ code: code,
357
+ type: 'getter',
358
+ };
273
359
  });
274
360
  }
275
361
  },
@@ -277,16 +363,37 @@ var onUpdatePlugin = function (options) { return ({
277
363
  }); };
278
364
  var BASE_OPTIONS = {
279
365
  plugins: [onUpdatePlugin],
366
+ vueVersion: 2,
280
367
  };
281
368
  var mergeOptions = function (_a, _b) {
282
369
  var _c = _a.plugins, pluginsA = _c === void 0 ? [] : _c, a = __rest(_a, ["plugins"]);
283
370
  var _d = _b.plugins, pluginsB = _d === void 0 ? [] : _d, b = __rest(_b, ["plugins"]);
284
371
  return (__assign(__assign(__assign({}, a), b), { plugins: __spreadArray(__spreadArray([], pluginsA, true), pluginsB, true) }));
285
372
  };
373
+ var generateComponentImport = function (options) {
374
+ return function (componentName) {
375
+ var key = (0, lodash_1.kebabCase)(componentName);
376
+ if (options.vueVersion >= 3 && options.asyncComponentImports) {
377
+ return "'".concat(key, "': defineAsyncComponent(").concat(componentName, ")");
378
+ }
379
+ else {
380
+ return "'".concat(key, "': ").concat(componentName);
381
+ }
382
+ };
383
+ };
384
+ var generateComponents = function (componentsUsed, options) {
385
+ if (componentsUsed.length === 0) {
386
+ return '';
387
+ }
388
+ else {
389
+ return "components: { ".concat(componentsUsed.map(generateComponentImport(options)).join(','), " },");
390
+ }
391
+ };
392
+ var appendToDataString = function (_a) {
393
+ var dataString = _a.dataString, newContent = _a.newContent;
394
+ return dataString.replace(/}$/, "".concat(newContent, "}"));
395
+ };
286
396
  var componentToVue = function (userOptions) {
287
- if (userOptions === void 0) { userOptions = {}; }
288
- // hack while we migrate all other transpilers to receive/handle path
289
- // TO-DO: use `Transpiler` once possible
290
397
  return function (_a) {
291
398
  var _b, _c, _d, _e, _f, _g, _h, _j;
292
399
  var component = _a.component, path = _a.path;
@@ -303,9 +410,24 @@ var componentToVue = function (userOptions) {
303
410
  if (options.plugins) {
304
411
  component = (0, plugins_1.runPostJsonPlugins)(component, options.plugins);
305
412
  }
306
- var css = (0, collect_styles_1.collectCss)(component, {
413
+ var css = (0, collect_css_1.collectCss)(component, {
307
414
  prefix: (_c = (_b = options.cssNamespace) === null || _b === void 0 ? void 0 : _b.call(options)) !== null && _c !== void 0 ? _c : undefined,
308
415
  });
416
+ var localExports = component.exports;
417
+ var localVarAsData = [];
418
+ var localVarAsFunc = [];
419
+ if (localExports) {
420
+ Object.keys(localExports).forEach(function (key) {
421
+ if (localExports[key].usedInLocal) {
422
+ if (localExports[key].isFunction) {
423
+ localVarAsFunc.push(key);
424
+ }
425
+ else {
426
+ localVarAsData.push(key);
427
+ }
428
+ }
429
+ });
430
+ }
309
431
  var dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
310
432
  data: true,
311
433
  functions: false,
@@ -315,9 +437,7 @@ var componentToVue = function (userOptions) {
315
437
  data: false,
316
438
  getters: true,
317
439
  functions: false,
318
- valueMapper: function (code) {
319
- return processBinding(code.replace(patterns_1.GETTER, ''), options, component);
320
- },
440
+ valueMapper: function (code) { return processBinding(code.replace(patterns_1.GETTER, ''), options, component); },
321
441
  });
322
442
  var functionsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
323
443
  data: false,
@@ -325,51 +445,46 @@ var componentToVue = function (userOptions) {
325
445
  functions: true,
326
446
  valueMapper: function (code) { return processBinding(code, options, component); },
327
447
  });
328
- var blocksString = JSON.stringify(component.children);
329
448
  // Component references to include in `component: { YourComponent, ... }
330
449
  var componentsUsed = Array.from((0, get_components_used_1.getComponentsUsed)(component))
331
- .filter(function (name) {
332
- return name.length &&
333
- !name.includes('.') &&
334
- name[0].toUpperCase() === name[0];
335
- })
450
+ .filter(function (name) { return name.length && !name.includes('.') && name[0].toUpperCase() === name[0]; })
336
451
  // Strip out components that compile away
337
452
  .filter(function (name) { return !['For', 'Show', 'Fragment', component.name].includes(name); });
338
453
  // Append refs to data as { foo, bar, etc }
339
- dataString = dataString.replace(/}$/, "".concat(component.imports
340
- .map(function (thisImport) { return Object.keys(thisImport.imports).join(','); })
341
- // Make sure actually used in template
342
- .filter(function (key) { return Boolean(key && blocksString.includes(key)); })
343
- // Don't include component imports
344
- .filter(function (key) { return !componentsUsed.includes(key); })
345
- .join(','), "}"));
454
+ dataString = appendToDataString({
455
+ dataString: dataString,
456
+ newContent: (0, get_custom_imports_1.getCustomImports)(component).join(','),
457
+ });
458
+ if (localVarAsData.length) {
459
+ dataString = appendToDataString({ dataString: dataString, newContent: localVarAsData.join(',') });
460
+ }
346
461
  var elementProps = (0, get_props_1.getProps)(component);
347
462
  (0, strip_meta_properties_1.stripMetaProperties)(component);
348
- var template = component.children
349
- .map(function (item) { return (0, exports.blockToVue)(item, options); })
350
- .join('\n');
463
+ var template = (0, function_1.pipe)(component.children.map(function (item) { return (0, exports.blockToVue)(item, options, { isRootNode: true }); }).join('\n'), renameMitosisComponentsToKebabCase);
351
464
  var includeClassMapHelper = template.includes('_classStringToObject');
352
465
  if (includeClassMapHelper) {
353
- functionsString = functionsString.replace(/}\s*$/, "_classStringToObject(str) {\n const obj = {};\n if (typeof str !== 'string') { return obj }\n const classNames = str.trim().split(/\\s+/); \n for (const name of classNames) {\n obj[name] = true;\n } \n return obj;\n } }");
466
+ functionsString = functionsString.replace(/}\s*$/, "_classStringToObject(str) {\n const obj = {};\n if (typeof str !== 'string') { return obj }\n const classNames = str.trim().split(/\\s+/);\n for (const name of classNames) {\n obj[name] = true;\n }\n return obj;\n } }");
467
+ }
468
+ if (localVarAsFunc.length) {
469
+ functionsString = functionsString.replace(/}\s*$/, "".concat(localVarAsFunc.join(','), "}"));
354
470
  }
355
- var builderRegister = Boolean(options.builderRegister && component.meta.registerComponent);
356
471
  var onUpdateWithDeps = ((_d = component.hooks.onUpdate) === null || _d === void 0 ? void 0 : _d.filter(function (hook) { var _a; return (_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length; })) || [];
357
472
  var onUpdateWithoutDeps = ((_e = component.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.filter(function (hook) { var _a; return !((_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length); })) || [];
358
- var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <template>\n ", "\n </template>\n <script>\n ", "\n ", "\n\n export default ", "{\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n }", "\n </script>\n ", "\n "], ["\n <template>\n ", "\n </template>\n <script>\n ", "\n ", "\n\n export default ", "{\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n }", "\n </script>\n ", "\n "])), template, (0, render_imports_1.renderPreComponent)(component), component.meta.registerComponent
359
- ? (_f = options.registerComponentPrepend) !== null && _f !== void 0 ? _f : ''
360
- : '', !builderRegister ? '' : 'registerComponent(', !component.name
361
- ? ''
362
- : "name: '".concat(((_g = options.namePrefix) === null || _g === void 0 ? void 0 : _g.call(options, path))
363
- ? ((_h = options.namePrefix) === null || _h === void 0 ? void 0 : _h.call(options, path)) + '-'
364
- : '').concat((0, lodash_1.kebabCase)(component.name), "',"), !componentsUsed.length
473
+ var propsDefinition = Array.from(elementProps).filter(function (prop) { return prop !== 'children' && prop !== 'class'; });
474
+ if (component.defaultProps) {
475
+ propsDefinition = propsDefinition.reduce(function (propsDefinition, curr) { return ((propsDefinition[curr] =
476
+ component.defaultProps && component.defaultProps.hasOwnProperty(curr)
477
+ ? { default: component.defaultProps[curr] }
478
+ : {}),
479
+ propsDefinition); }, {});
480
+ }
481
+ var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <template>\n ", "\n </template>\n <script lang=\"ts\">\n ", "\n ", "\n\n ", "\n\n export default {\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n }\n </script>\n ", "\n "], ["\n <template>\n ", "\n </template>\n <script lang=\"ts\">\n ", "\n ", "\n\n ", "\n\n export default {\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n }\n </script>\n ", "\n "])), template, options.vueVersion >= 3 ? 'import { defineAsyncComponent } from "vue"' : '', (0, render_imports_1.renderPreComponent)({
482
+ component: component,
483
+ target: 'vue',
484
+ asyncComponentImports: options.asyncComponentImports,
485
+ }), ((_f = component.types) === null || _f === void 0 ? void 0 : _f.join('\n')) || '', !component.name
365
486
  ? ''
366
- : "components: { ".concat(componentsUsed
367
- .map(function (componentName) {
368
- return "'".concat((0, lodash_1.kebabCase)(componentName), "': async () => ").concat(componentName);
369
- })
370
- .join(','), " },"), elementProps.size
371
- ? "props: ".concat(JSON.stringify(Array.from(elementProps).filter(function (prop) { return prop !== 'children' && prop !== 'class'; })), ",")
372
- : '', dataString.length < 4
487
+ : "name: '".concat(path && ((_g = options.namePrefix) === null || _g === void 0 ? void 0 : _g.call(options, path)) ? ((_h = options.namePrefix) === null || _h === void 0 ? void 0 : _h.call(options, path)) + '-' : '').concat((0, lodash_1.kebabCase)(component.name), "',"), generateComponents(componentsUsed, options), elementProps.size ? "props: ".concat(JSON.stringify(propsDefinition), ",") : '', dataString.length < 4
373
488
  ? ''
374
489
  : "\n data: () => (".concat(dataString, "),\n "), (0, lodash_1.size)(component.context.set)
375
490
  ? "provide() {\n const _this = this;\n return ".concat(getContextProvideString(component, options), "\n },")
@@ -393,9 +508,7 @@ var componentToVue = function (userOptions) {
393
508
  ? ''
394
509
  : "\n computed: ".concat(getterString, ",\n "), functionsString.length < 4
395
510
  ? ''
396
- : "\n methods: ".concat(functionsString, ",\n "), !builderRegister
397
- ? ''
398
- : ", ".concat(json5_1.default.stringify(component.meta.registerComponent || {}), ")"), !css.trim().length
511
+ : "\n methods: ".concat(functionsString, ",\n "), !css.trim().length
399
512
  ? ''
400
513
  : "<style scoped>\n ".concat(css, "\n </style>"));
401
514
  if (options.plugins) {
@@ -424,13 +537,21 @@ var componentToVue = function (userOptions) {
424
537
  var pattern = removePatterns_1[_i];
425
538
  str = str.replace(pattern, '');
426
539
  }
427
- // Transform <FooBar> to <foo-bar> as Vue2 needs
428
- return str.replace(/<\/?\w+/g, function (match) {
429
- return match.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
430
- });
540
+ return str;
431
541
  };
432
542
  };
433
- exports.componentToVue = componentToVue;
543
+ var componentToVue2 = function (vueOptions) {
544
+ return componentToVue(__assign(__assign({}, vueOptions), { vueVersion: 2 }));
545
+ };
546
+ exports.componentToVue2 = componentToVue2;
547
+ var componentToVue3 = function (vueOptions) {
548
+ return componentToVue(__assign(__assign({}, vueOptions), { vueVersion: 3 }));
549
+ };
550
+ exports.componentToVue3 = componentToVue3;
551
+ // Transform <FooBar> to <foo-bar> as Vue2 needs
552
+ var renameMitosisComponentsToKebabCase = function (str) {
553
+ return str.replace(/<\/?\w+/g, function (match) { return match.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); });
554
+ };
434
555
  // Remove unused artifacts like empty script or style tags
435
556
  var removePatterns = [
436
557
  "<script>\nexport default {};\n</script>",