@builder.io/mitosis 0.0.56-98 → 0.0.57

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 (259) hide show
  1. package/dist/src/__tests__/data/blocks/content-slot-jsx.raw.jsx +4 -1
  2. package/dist/src/__tests__/data/blocks/form.raw.jsx +5 -5
  3. package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.d.ts +5 -1
  4. package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.jsx +3 -3
  5. package/dist/src/__tests__/data/jsx-json.spec.d.ts +2 -0
  6. package/dist/src/__tests__/data/jsx-json.spec.js +10226 -0
  7. package/dist/src/__tests__/shared.d.ts +7 -2
  8. package/dist/src/__tests__/shared.js +66 -9
  9. package/dist/src/constants/method-literal-prefix.d.ts +0 -1
  10. package/dist/src/constants/method-literal-prefix.js +0 -3
  11. package/dist/src/generators/angular.d.ts +2 -2
  12. package/dist/src/generators/angular.js +5 -3
  13. package/dist/src/generators/builder.d.ts +4 -11
  14. package/dist/src/generators/builder.js +3 -2
  15. package/dist/src/generators/context/svelte.d.ts +3 -0
  16. package/dist/src/generators/context/svelte.js +3 -0
  17. package/dist/src/generators/helpers/functions.d.ts +2 -0
  18. package/dist/src/generators/helpers/functions.js +28 -0
  19. package/dist/src/generators/html.d.ts +3 -3
  20. package/dist/src/generators/html.js +9 -7
  21. package/dist/src/generators/liquid.d.ts +2 -2
  22. package/dist/src/generators/liquid.js +4 -4
  23. package/dist/src/generators/lit/generate.d.ts +2 -2
  24. package/dist/src/generators/lit/generate.js +14 -6
  25. package/dist/src/generators/marko/generate.d.ts +2 -2
  26. package/dist/src/generators/marko/generate.js +10 -8
  27. package/dist/src/generators/mitosis.d.ts +3 -4
  28. package/dist/src/generators/mitosis.js +3 -2
  29. package/dist/src/generators/qwik/component-generator.d.ts +2 -2
  30. package/dist/src/generators/qwik/component-generator.js +49 -55
  31. package/dist/src/generators/qwik/component.d.ts +0 -1
  32. package/dist/src/generators/qwik/component.js +22 -19
  33. package/dist/src/generators/qwik/directives.d.ts +1 -0
  34. package/dist/src/generators/qwik/directives.js +11 -14
  35. package/dist/src/generators/qwik/jsx.d.ts +1 -1
  36. package/dist/src/generators/qwik/jsx.js +9 -5
  37. package/dist/src/generators/qwik/src-generator.js +9 -3
  38. package/dist/src/generators/qwik/stable-serialize.d.ts +6 -0
  39. package/dist/src/generators/qwik/stable-serialize.js +51 -0
  40. package/dist/src/generators/react/generator.d.ts +6 -0
  41. package/dist/src/generators/{react.js → react/generator.js} +58 -150
  42. package/dist/src/generators/react/helpers.d.ts +2 -0
  43. package/dist/src/generators/react/helpers.js +14 -0
  44. package/dist/src/generators/react/index.d.ts +2 -0
  45. package/dist/src/generators/react/index.js +18 -0
  46. package/dist/src/generators/react/state.d.ts +9 -0
  47. package/dist/src/generators/react/state.js +107 -0
  48. package/dist/src/generators/react/types.d.ts +10 -0
  49. package/dist/src/{types/string-map.js → generators/react/types.js} +0 -0
  50. package/dist/src/generators/react-native.d.ts +2 -2
  51. package/dist/src/generators/solid/index.d.ts +3 -0
  52. package/dist/src/generators/{solid.js → solid/index.js} +80 -40
  53. package/dist/src/generators/solid/state.d.ts +19 -0
  54. package/dist/src/generators/solid/state.js +144 -0
  55. package/dist/src/generators/solid/types.d.ts +6 -0
  56. package/dist/src/generators/solid/types.js +2 -0
  57. package/dist/src/generators/stencil/generate.d.ts +2 -2
  58. package/dist/src/generators/stencil/generate.js +5 -2
  59. package/dist/src/generators/svelte.d.ts +6 -7
  60. package/dist/src/generators/svelte.js +43 -40
  61. package/dist/src/generators/swift-ui.d.ts +3 -5
  62. package/dist/src/generators/swift-ui.js +3 -2
  63. package/dist/src/generators/template.d.ts +2 -2
  64. package/dist/src/generators/template.js +3 -2
  65. package/dist/src/generators/vue.d.ts +5 -3
  66. package/dist/src/generators/vue.js +256 -113
  67. package/dist/src/helpers/babel-transform.d.ts +3 -1
  68. package/dist/src/helpers/babel-transform.js +52 -56
  69. package/dist/src/helpers/get-bindings.js +3 -5
  70. package/dist/src/helpers/get-props.js +14 -1
  71. package/dist/src/helpers/get-state-object-string.js +24 -21
  72. package/dist/src/helpers/getters-to-functions.js +1 -11
  73. package/dist/src/helpers/map-refs.js +25 -25
  74. package/dist/src/helpers/nodes/for.d.ts +4 -0
  75. package/dist/src/helpers/nodes/for.js +13 -0
  76. package/dist/src/helpers/nullable.d.ts +2 -0
  77. package/dist/src/helpers/nullable.js +7 -0
  78. package/dist/src/helpers/patterns.d.ts +2 -0
  79. package/dist/src/helpers/patterns.js +5 -1
  80. package/dist/src/helpers/render-imports.js +3 -3
  81. package/dist/src/helpers/replace-identifiers.d.ts +5 -0
  82. package/dist/src/helpers/{replace-idenifiers.js → replace-identifiers.js} +2 -1
  83. package/dist/src/helpers/slots.d.ts +2 -0
  84. package/dist/src/helpers/slots.js +15 -1
  85. package/dist/src/helpers/state.d.ts +0 -2
  86. package/dist/src/helpers/state.js +1 -10
  87. package/dist/src/helpers/strip-state-and-props-refs.d.ts +1 -1
  88. package/dist/src/helpers/strip-state-and-props-refs.js +43 -31
  89. package/dist/src/helpers/styles/helpers.d.ts +1 -0
  90. package/dist/src/index.d.ts +0 -2
  91. package/dist/src/index.js +0 -2
  92. package/dist/src/parsers/angular.js +2 -2
  93. package/dist/src/parsers/builder.d.ts +2 -2
  94. package/dist/src/parsers/builder.js +61 -43
  95. package/dist/src/parsers/constants/outdated-prefixes.d.ts +10 -0
  96. package/dist/src/parsers/constants/outdated-prefixes.js +13 -0
  97. package/dist/src/parsers/context.js +2 -2
  98. package/dist/src/parsers/helpers/state.d.ts +3 -0
  99. package/dist/src/parsers/helpers/state.js +30 -0
  100. package/dist/src/parsers/jsx/component-types.d.ts +1 -1
  101. package/dist/src/parsers/jsx/component-types.js +15 -2
  102. package/dist/src/parsers/jsx/context.js +1 -1
  103. package/dist/src/parsers/jsx/element-parser.d.ts +6 -0
  104. package/dist/src/parsers/jsx/element-parser.js +243 -0
  105. package/dist/src/parsers/jsx/exports.d.ts +3 -0
  106. package/dist/src/parsers/jsx/exports.js +78 -0
  107. package/dist/src/parsers/jsx/function-parser.d.ts +7 -0
  108. package/dist/src/parsers/jsx/function-parser.js +291 -0
  109. package/dist/src/parsers/jsx/helpers.d.ts +2 -0
  110. package/dist/src/parsers/jsx/helpers.js +30 -1
  111. package/dist/src/parsers/jsx/imports.d.ts +7 -0
  112. package/dist/src/parsers/jsx/imports.js +65 -0
  113. package/dist/src/parsers/jsx/index.d.ts +1 -1
  114. package/dist/src/parsers/jsx/index.js +1 -2
  115. package/dist/src/parsers/jsx/jsx.js +29 -516
  116. package/dist/src/parsers/jsx/state.d.ts +2 -3
  117. package/dist/src/parsers/jsx/state.js +15 -22
  118. package/dist/src/plugins/compile-away-builder-components.js +6 -0
  119. package/dist/src/symbols/symbol-processor.js +3 -0
  120. package/dist/src/targets.d.ts +21 -28
  121. package/dist/src/targets.js +2 -2
  122. package/dist/src/types/config.d.ts +11 -1
  123. package/dist/src/types/mitosis-component.d.ts +12 -6
  124. package/dist/src/types/mitosis-component.js +11 -0
  125. package/dist/src/types/mitosis-context.d.ts +2 -2
  126. package/dist/src/types/mitosis-node.d.ts +14 -5
  127. package/dist/src/types/mitosis-node.js +3 -0
  128. package/dist/src/types/transpiler.d.ts +6 -1
  129. package/dist/tsconfig.build.tsbuildinfo +1 -1
  130. package/package.json +9 -9
  131. package/dist/src/__tests__/angular.test.d.ts +0 -1
  132. package/dist/src/__tests__/angular.test.js +0 -10
  133. package/dist/src/__tests__/builder.test.d.ts +0 -1
  134. package/dist/src/__tests__/builder.test.js +0 -235
  135. package/dist/src/__tests__/context.test.d.ts +0 -1
  136. package/dist/src/__tests__/context.test.js +0 -35
  137. package/dist/src/__tests__/data/blocks/builder-render-block.raw.d.ts +0 -6
  138. package/dist/src/__tests__/data/blocks/builder-render-block.raw.jsx +0 -90
  139. package/dist/src/__tests__/data/blocks/builder-render-content.raw.d.ts +0 -10
  140. package/dist/src/__tests__/data/blocks/builder-render-content.raw.jsx +0 -69
  141. package/dist/src/__tests__/hash-code.test.d.ts +0 -1
  142. package/dist/src/__tests__/hash-code.test.js +0 -11
  143. package/dist/src/__tests__/html.test.d.ts +0 -1
  144. package/dist/src/__tests__/html.test.js +0 -7
  145. package/dist/src/__tests__/liquid.test.d.ts +0 -1
  146. package/dist/src/__tests__/liquid.test.js +0 -7
  147. package/dist/src/__tests__/lit.test.d.ts +0 -1
  148. package/dist/src/__tests__/lit.test.js +0 -7
  149. package/dist/src/__tests__/marko.test.d.ts +0 -1
  150. package/dist/src/__tests__/marko.test.js +0 -14
  151. package/dist/src/__tests__/parse-jsx.test.d.ts +0 -1
  152. package/dist/src/__tests__/parse-jsx.test.js +0 -37
  153. package/dist/src/__tests__/qwik/convert-method-to-function.test.d.ts +0 -1
  154. package/dist/src/__tests__/qwik/convert-method-to-function.test.js +0 -37
  155. package/dist/src/__tests__/qwik/src-generator.test.d.ts +0 -1
  156. package/dist/src/__tests__/qwik/src-generator.test.js +0 -65
  157. package/dist/src/__tests__/qwik.directive.test.d.ts +0 -1
  158. package/dist/src/__tests__/qwik.directive.test.js +0 -108
  159. package/dist/src/__tests__/qwik.test.d.ts +0 -1
  160. package/dist/src/__tests__/qwik.test.js +0 -465
  161. package/dist/src/__tests__/react-native.test.d.ts +0 -1
  162. package/dist/src/__tests__/react-native.test.js +0 -7
  163. package/dist/src/__tests__/react.test.d.ts +0 -1
  164. package/dist/src/__tests__/react.test.js +0 -20
  165. package/dist/src/__tests__/solid.test.d.ts +0 -1
  166. package/dist/src/__tests__/solid.test.js +0 -10
  167. package/dist/src/__tests__/stencil.test.d.ts +0 -1
  168. package/dist/src/__tests__/stencil.test.js +0 -7
  169. package/dist/src/__tests__/styles.test.d.ts +0 -1
  170. package/dist/src/__tests__/styles.test.js +0 -23
  171. package/dist/src/__tests__/svelte.test.d.ts +0 -1
  172. package/dist/src/__tests__/svelte.test.js +0 -7
  173. package/dist/src/__tests__/vue.test.d.ts +0 -1
  174. package/dist/src/__tests__/vue.test.js +0 -7
  175. package/dist/src/__tests__/webcomponent.test.d.ts +0 -1
  176. package/dist/src/__tests__/webcomponent.test.js +0 -15
  177. package/dist/src/constants/function-literal-prefix.d.ts +0 -1
  178. package/dist/src/constants/function-literal-prefix.js +0 -4
  179. package/dist/src/generators/qwik/convertMethodToFunction.d.ts +0 -1
  180. package/dist/src/generators/qwik/convertMethodToFunction.js +0 -161
  181. package/dist/src/generators/react.d.ts +0 -14
  182. package/dist/src/generators/solid.d.ts +0 -5
  183. package/dist/src/helpers/babel-transform.test.d.ts +0 -1
  184. package/dist/src/helpers/babel-transform.test.js +0 -7
  185. package/dist/src/helpers/generic-format.test.d.ts +0 -1
  186. package/dist/src/helpers/generic-format.test.js +0 -8
  187. package/dist/src/helpers/map-to-attributes.d.ts +0 -2
  188. package/dist/src/helpers/map-to-attributes.js +0 -19
  189. package/dist/src/helpers/map-to-css.d.ts +0 -2
  190. package/dist/src/helpers/map-to-css.js +0 -16
  191. package/dist/src/helpers/parse-reactive-script.d.ts +0 -7
  192. package/dist/src/helpers/parse-reactive-script.js +0 -87
  193. package/dist/src/helpers/remove-surrounding-block.test.d.ts +0 -1
  194. package/dist/src/helpers/remove-surrounding-block.test.js +0 -9
  195. package/dist/src/helpers/render-imports.test.d.ts +0 -1
  196. package/dist/src/helpers/render-imports.test.js +0 -33
  197. package/dist/src/helpers/replace-idenifiers.d.ts +0 -1
  198. package/dist/src/helpers/styles/collect-css.test.d.ts +0 -1
  199. package/dist/src/helpers/styles/collect-css.test.js +0 -18
  200. package/dist/src/parsers/html.d.ts +0 -0
  201. package/dist/src/parsers/html.js +0 -2
  202. package/dist/src/parsers/liquid.d.ts +0 -70
  203. package/dist/src/parsers/liquid.js +0 -2538
  204. package/dist/src/types/string-map.d.ts +0 -3
  205. package/dist/test/qwik/Accordion/high.jsx +0 -0
  206. package/dist/test/qwik/Accordion/low.jsx +0 -240
  207. package/dist/test/qwik/Accordion/med.jsx +0 -4
  208. package/dist/test/qwik/For/high.jsx +0 -0
  209. package/dist/test/qwik/For/low.jsx +0 -52
  210. package/dist/test/qwik/For/med.jsx +0 -4
  211. package/dist/test/qwik/Image/high.js +0 -9
  212. package/dist/test/qwik/Image/low.js +0 -0
  213. package/dist/test/qwik/Image/med.js +0 -155
  214. package/dist/test/qwik/Image.slow/high.js +0 -9
  215. package/dist/test/qwik/Image.slow/low.js +0 -0
  216. package/dist/test/qwik/Image.slow/med.js +0 -155
  217. package/dist/test/qwik/bindings/high.cjs +0 -0
  218. package/dist/test/qwik/bindings/low.cjs +0 -45
  219. package/dist/test/qwik/bindings/med.cjs +0 -3
  220. package/dist/test/qwik/button/high.js +0 -3
  221. package/dist/test/qwik/button/low.js +0 -25
  222. package/dist/test/qwik/button/med.js +0 -31
  223. package/dist/test/qwik/component/bindings/high.jsx +0 -0
  224. package/dist/test/qwik/component/bindings/low.jsx +0 -104
  225. package/dist/test/qwik/component/bindings/med.jsx +0 -7
  226. package/dist/test/qwik/component/component/inputs/high.cjsx +0 -9
  227. package/dist/test/qwik/component/component/inputs/low.cjsx +0 -0
  228. package/dist/test/qwik/component/component/inputs/med.cjsx +0 -68
  229. package/dist/test/qwik/for-loop.bindings/high.cjs +0 -0
  230. package/dist/test/qwik/for-loop.bindings/low.cjs +0 -56
  231. package/dist/test/qwik/for-loop.bindings/med.cjs +0 -5
  232. package/dist/test/qwik/hello_world/stylesheet/high.jsx +0 -0
  233. package/dist/test/qwik/hello_world/stylesheet/low.jsx +0 -26
  234. package/dist/test/qwik/hello_world/stylesheet/med.jsx +0 -4
  235. package/dist/test/qwik/mount/high.cjs +0 -0
  236. package/dist/test/qwik/mount/low.cjs +0 -47
  237. package/dist/test/qwik/mount/med.cjs +0 -3
  238. package/dist/test/qwik/page-with-symbol/high.js +0 -0
  239. package/dist/test/qwik/page-with-symbol/low.js +0 -33
  240. package/dist/test/qwik/page-with-symbol/med.js +0 -4
  241. package/dist/test/qwik/show-hide/high.jsx +0 -9
  242. package/dist/test/qwik/show-hide/low.jsx +0 -0
  243. package/dist/test/qwik/show-hide/med.jsx +0 -181
  244. package/dist/test/qwik/svg/high.js +0 -0
  245. package/dist/test/qwik/svg/low.js +0 -30
  246. package/dist/test/qwik/svg/med.js +0 -4
  247. package/dist/test/qwik/todo/Todo.cjs/high.cjs +0 -19
  248. package/dist/test/qwik/todo/Todo.cjs/low.cjs +0 -0
  249. package/dist/test/qwik/todo/Todo.cjs/med.cjs +0 -51
  250. package/dist/test/qwik/todo/Todo.js/high.js +0 -19
  251. package/dist/test/qwik/todo/Todo.js/low.js +0 -0
  252. package/dist/test/qwik/todo/Todo.js/med.js +0 -47
  253. package/dist/test/qwik/todo/Todo.tsx/high.tsx +0 -19
  254. package/dist/test/qwik/todo/Todo.tsx/low.tsx +0 -0
  255. package/dist/test/qwik/todo/Todo.tsx/med.tsx +0 -43
  256. package/dist/test/qwik/todos/Todo.tsx/high.tsx +0 -7
  257. package/dist/test/qwik/todos/Todo.tsx/low.tsx +0 -32
  258. package/dist/test/qwik/todos/Todo.tsx/med.tsx +0 -4
  259. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -61,12 +61,10 @@ var babel_transform_1 = require("../helpers/babel-transform");
61
61
  var function_1 = require("fp-ts/lib/function");
62
62
  var context_1 = require("./helpers/context");
63
63
  var html_tags_1 = require("../constants/html_tags");
64
- var lodash_1 = require("lodash");
65
- var function_literal_prefix_1 = require("../constants/function-literal-prefix");
66
- var method_literal_prefix_1 = require("../constants/method-literal-prefix");
67
- var patterns_1 = require("../helpers/patterns");
68
64
  var is_upper_case_1 = require("../helpers/is-upper-case");
69
65
  var json5_1 = __importDefault(require("json5"));
66
+ var functions_1 = require("./helpers/functions");
67
+ var for_1 = require("../helpers/nodes/for");
70
68
  var mappers = {
71
69
  Fragment: function (_a) {
72
70
  var _b;
@@ -93,7 +91,8 @@ var mappers = {
93
91
  delete firstChild.properties.key;
94
92
  delete firstChild.bindings.key;
95
93
  }
96
- return "\n{#each ".concat(stripStateAndProps((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code, options), " as ").concat(json.scope.For[0]).concat(json.scope.For[1] ? ", ".concat(json.scope.For[1]) : '', " ").concat(keyValue ? "(".concat(keyValue, ")") : '', "}\n").concat(json.children.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "\n{/each}\n");
94
+ var args = (0, for_1.getForArguments)(json, { excludeCollectionName: true }).join(', ');
95
+ return "\n{#each ".concat(stripStateAndProps((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code, options), " as ").concat(args, " ").concat(keyValue ? "(".concat(keyValue, ")") : '', "}\n").concat(json.children.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "\n{/each}\n");
97
96
  },
98
97
  Show: function (_a) {
99
98
  var _b;
@@ -159,7 +158,11 @@ var blockToSvelte = function (_a) {
159
158
  var _b, _c, _d, _e, _f;
160
159
  var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
161
160
  if (mappers[json.name]) {
162
- return mappers[json.name]({ json: json, options: options, parentComponent: parentComponent });
161
+ return mappers[json.name]({
162
+ json: json,
163
+ options: options,
164
+ parentComponent: parentComponent,
165
+ });
163
166
  }
164
167
  var tagName = getTagName({ json: json, parentComponent: parentComponent });
165
168
  if ((0, is_children_1.default)(json)) {
@@ -200,7 +203,13 @@ var blockToSvelte = function (_a) {
200
203
  if (key.startsWith('on')) {
201
204
  var event_1 = key.replace('on', '').toLowerCase();
202
205
  // TODO: handle quotes in event handler values
203
- str += " on:".concat(event_1, "=\"{").concat(cusArgs.join(','), " => {").concat((0, remove_surrounding_block_1.removeSurroundingBlock)(useValue), "}}\" ");
206
+ var valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(useValue);
207
+ if (valueWithoutBlock === key) {
208
+ str += " on:".concat(event_1, "={").concat(valueWithoutBlock, "} ");
209
+ }
210
+ else {
211
+ str += " on:".concat(event_1, "=\"{").concat(cusArgs.join(','), " => {").concat(valueWithoutBlock, "}}\" ");
212
+ }
204
213
  }
205
214
  else if (key === 'ref') {
206
215
  str += " bind:this={".concat(useValue, "} ");
@@ -224,7 +233,7 @@ var blockToSvelte = function (_a) {
224
233
  if (json.children) {
225
234
  str += json.children
226
235
  .map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); })
227
- .join('\n');
236
+ .join('');
228
237
  }
229
238
  str += "</".concat(tagName, ">");
230
239
  return str;
@@ -267,33 +276,13 @@ var useBindValue = function (json, options) {
267
276
  var stripThisRefs = function (str) {
268
277
  return str.replace(/this\.([a-zA-Z_\$0-9]+)/g, '$1');
269
278
  };
270
- var FUNCTION_HACK_PLUGIN = function () { return ({
271
- json: {
272
- pre: function (json) {
273
- var _a;
274
- for (var key in json.state) {
275
- var value = (_a = json.state[key]) === null || _a === void 0 ? void 0 : _a.code;
276
- if (typeof value === 'string' && value.startsWith(method_literal_prefix_1.methodLiteralPrefix)) {
277
- var strippedValue = value.replace(method_literal_prefix_1.methodLiteralPrefix, '');
278
- if (!Boolean(strippedValue.match(patterns_1.GETTER))) {
279
- var newValue = "".concat(function_literal_prefix_1.functionLiteralPrefix, " function ").concat(strippedValue);
280
- json.state[key] = {
281
- code: newValue,
282
- type: 'function',
283
- };
284
- }
285
- }
286
- }
287
- },
288
- },
289
- }); };
290
279
  var componentToSvelte = function (_a) {
291
280
  if (_a === void 0) { _a = {}; }
292
281
  var _b = _a.plugins, plugins = _b === void 0 ? [] : _b, userProvidedOptions = __rest(_a, ["plugins"]);
293
282
  return function (_a) {
294
- var _b, _c, _d, _e, _f, _g, _h;
283
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k;
295
284
  var component = _a.component;
296
- var options = __assign({ stateType: 'variables', prettier: true, plugins: __spreadArray([FUNCTION_HACK_PLUGIN], plugins, true) }, userProvidedOptions);
285
+ var options = __assign({ stateType: 'variables', prettier: true, plugins: __spreadArray([functions_1.FUNCTION_HACK_PLUGIN], plugins, true) }, userProvidedOptions);
297
286
  // Make a copy we can safely mutate, similar to babel's toolchain
298
287
  var json = (0, fast_clone_1.fastClone)(component);
299
288
  if (options.plugins) {
@@ -322,7 +311,7 @@ var componentToSvelte = function (_a) {
322
311
  format: 'variables',
323
312
  keyPrefix: '$: ',
324
313
  valueMapper: function (code) {
325
- return (0, function_1.pipe)(stripStateAndProps(code.replace(/^get ([a-zA-Z_\$0-9]+)/, '$1 = ').replace(/\)/, ') => '), options), stripThisRefs);
314
+ return (0, function_1.pipe)(code.replace(/^get ([a-zA-Z_\$0-9]+)/, '$1 = ').replace(/\)/, ') => '), function (str) { return stripStateAndProps(str, options); }, stripThisRefs);
326
315
  },
327
316
  }), babel_transform_1.babelTransformCode);
328
317
  var functionsString = (0, function_1.pipe)((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
@@ -330,7 +319,6 @@ var componentToSvelte = function (_a) {
330
319
  getters: false,
331
320
  functions: true,
332
321
  format: 'variables',
333
- keyPrefix: 'const ',
334
322
  valueMapper: function (code) { return (0, function_1.pipe)(stripStateAndProps(code, options), stripThisRefs); },
335
323
  }), babel_transform_1.babelTransformCode);
336
324
  var hasData = dataString.length > 4;
@@ -339,16 +327,31 @@ var componentToSvelte = function (_a) {
339
327
  return (0, function_1.pipe)(stripStateAndProps(hookCode, options), babel_transform_1.babelTransformCode);
340
328
  };
341
329
  var str = '';
342
- if ((_b = json.types) === null || _b === void 0 ? void 0 : _b.length) {
343
- str += (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <script context='module' lang='ts'>\n ", "\n </script>\n \n\n \n\n "], ["\n <script context='module' lang='ts'>\n ", "\n </script>\n \\n\n \\n\n "])), json.types ? json.types.join('\n\n') + '\n' : '');
330
+ var tsLangAttribute = options.typescript ? "lang='ts'" : '';
331
+ if (options.typescript && ((_b = json.types) === null || _b === void 0 ? void 0 : _b.length)) {
332
+ str += (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <script context='module' ", ">\n ", "\n </script>\n \n\n \n\n "], ["\n <script context='module' ", ">\n ", "\n </script>\n \\n\n \\n\n "])), tsLangAttribute, json.types ? json.types.join('\n\n') + '\n' : '');
333
+ }
334
+ // prepare svelte imports
335
+ var svelteImports = [];
336
+ if ((_d = (_c = json.hooks.onMount) === null || _c === void 0 ? void 0 : _c.code) === null || _d === void 0 ? void 0 : _d.length) {
337
+ svelteImports.push('onMount');
338
+ }
339
+ if ((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.length) {
340
+ svelteImports.push('afterUpdate');
341
+ }
342
+ if ((_g = (_f = json.hooks.onUnMount) === null || _f === void 0 ? void 0 : _f.code) === null || _g === void 0 ? void 0 : _g.length) {
343
+ svelteImports.push('onDestroy');
344
+ }
345
+ if ((0, context_1.hasContext)(component)) {
346
+ svelteImports.push('getContext', 'setContext');
344
347
  }
345
- str += (0, dedent_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n <script lang='ts'>\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "], ["\n <script lang='ts'>\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "])), !((_c = json.hooks.onMount) === null || _c === void 0 ? void 0 : _c.code) ? '' : "import { onMount } from 'svelte'", !((_d = json.hooks.onUpdate) === null || _d === void 0 ? void 0 : _d.length) ? '' : "import { afterUpdate } from 'svelte'", !((_e = json.hooks.onUnMount) === null || _e === void 0 ? void 0 : _e.code) ? '' : "import { onDestroy } from 'svelte'", (0, render_imports_1.renderPreComponent)({ component: json, target: 'svelte' }), (0, context_1.hasContext)(component) ? 'import { getContext, setContext } from "svelte";' : '', !hasData || options.stateType === 'variables' ? '' : "import onChange from 'on-change'", (0, lodash_1.uniq)(refs.map(function (ref) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(ref); }).concat(props))
348
+ str += (0, dedent_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n <script ", ">\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "], ["\n <script ", ">\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "])), tsLangAttribute, !svelteImports.length ? '' : "import { ".concat(svelteImports.sort().join(', '), " } from 'svelte'"), (0, render_imports_1.renderPreComponent)({ component: json, target: 'svelte' }), !hasData || options.stateType === 'variables' ? '' : "import onChange from 'on-change'", props
346
349
  .map(function (name) {
347
350
  if (name === 'children') {
348
351
  return '';
349
352
  }
350
353
  var propDeclaration = "export let ".concat(name);
351
- if (json.propsTypeRef && json.propsTypeRef !== 'any') {
354
+ if (options.typescript && json.propsTypeRef && json.propsTypeRef !== 'any') {
352
355
  propDeclaration += ": ".concat(json.propsTypeRef.split(' |')[0], "['").concat(name, "']");
353
356
  }
354
357
  if (json.defaultProps && json.defaultProps.hasOwnProperty(name)) {
@@ -359,13 +362,13 @@ var componentToSvelte = function (_a) {
359
362
  })
360
363
  .join('\n'), (0, helpers_1.hasStyle)(json)
361
364
  ? "\n function mitosis_styling (node, vars) {\n Object.entries(vars).forEach(([ p, v ]) => { node.style[p] = v })\n }\n "
362
- : '', getContextCode(json), setContextCode(json), functionsString.length < 4 ? '' : functionsString, getterString.length < 4 ? '' : getterString, options.stateType === 'proxies'
365
+ : '', getContextCode(json), setContextCode(json), functionsString.length < 4 ? '' : functionsString, getterString.length < 4 ? '' : getterString, refs.map(function (ref) { return "let ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(ref)); }).join('\n'), options.stateType === 'proxies'
363
366
  ? dataString.length < 4
364
367
  ? ''
365
368
  : "let state = onChange(".concat(dataString, ", () => state = state)")
366
- : dataString, !((_f = json.hooks.onMount) === null || _f === void 0 ? void 0 : _f.code)
369
+ : dataString, !((_h = json.hooks.onMount) === null || _h === void 0 ? void 0 : _h.code)
367
370
  ? ''
368
- : "onMount(() => { ".concat(transformHookCode(json.hooks.onMount.code), " });"), !((_g = json.hooks.onUpdate) === null || _g === void 0 ? void 0 : _g.length)
371
+ : "onMount(() => { ".concat(transformHookCode(json.hooks.onMount.code), " });"), !((_j = json.hooks.onUpdate) === null || _j === void 0 ? void 0 : _j.length)
369
372
  ? ''
370
373
  : json.hooks.onUpdate
371
374
  .map(function (_a, index) {
@@ -379,7 +382,7 @@ var componentToSvelte = function (_a) {
379
382
  return "afterUpdate(() => { ".concat(hookCode, " })");
380
383
  }
381
384
  })
382
- .join(';'), !((_h = json.hooks.onUnMount) === null || _h === void 0 ? void 0 : _h.code)
385
+ .join(';'), !((_k = json.hooks.onUnMount) === null || _k === void 0 ? void 0 : _k.code)
383
386
  ? ''
384
387
  : "onDestroy(() => { ".concat(transformHookCode(json.hooks.onUnMount.code), " });"), json.children
385
388
  .map(function (item) {
@@ -1,5 +1,3 @@
1
- import { Transpiler } from '../types/transpiler';
2
- export declare type ToSwiftOptions = {
3
- prettier?: boolean;
4
- };
5
- export declare const componentToSwift: (options?: ToSwiftOptions) => Transpiler;
1
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
2
+ export declare type ToSwiftOptions = BaseTranspilerOptions;
3
+ export declare const componentToSwift: TranspilerGenerator<ToSwiftOptions>;
@@ -18,6 +18,7 @@ var get_state_object_string_1 = require("../helpers/get-state-object-string");
18
18
  var get_styles_1 = require("../helpers/get-styles");
19
19
  var is_children_1 = __importDefault(require("../helpers/is-children"));
20
20
  var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
21
+ var mitosis_node_1 = require("../types/mitosis-node");
21
22
  var state_1 = require("../helpers/state");
22
23
  var scrolls = function (json) {
23
24
  var _a;
@@ -91,8 +92,8 @@ var blockToSwift = function (json, options) {
91
92
  delete json.properties.placeholder;
92
93
  json.properties._ = placeholder || '';
93
94
  }
94
- if (json.name === 'For') {
95
- str += "ForEach(".concat(processBinding((_a = json.bindings.each) === null || _a === void 0 ? void 0 : _a.code, options), ", id: \\.self) { ").concat(json.properties._forName, " in ").concat(children
95
+ if ((0, mitosis_node_1.checkIsForNode)(json)) {
96
+ str += "ForEach(".concat(processBinding((_a = json.bindings.each) === null || _a === void 0 ? void 0 : _a.code, options), ", id: \\.self) { ").concat(json.scope.forName, " in ").concat(children
96
97
  .map(function (item) { return blockToSwift(item, options); })
97
98
  .join('\n'), " }");
98
99
  }
@@ -1,4 +1,4 @@
1
- import { BaseTranspilerOptions, Transpiler } from '../types/transpiler';
1
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
2
2
  export interface ToTemplateOptions extends BaseTranspilerOptions {
3
3
  }
4
- export declare const componentToTemplate: (options?: ToTemplateOptions) => Transpiler;
4
+ export declare const componentToTemplate: TranspilerGenerator<ToTemplateOptions>;
@@ -12,6 +12,7 @@ var standalone_1 = require("prettier/standalone");
12
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
+ var mitosis_node_1 = require("../types/mitosis-node");
15
16
  var plugins_1 = require("../modules/plugins");
16
17
  var dedent_1 = __importDefault(require("dedent"));
17
18
  var get_state_object_string_1 = require("../helpers/get-state-object-string");
@@ -34,8 +35,8 @@ var blockToTemplate = function (json, options) {
34
35
  return "${".concat((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code, "}");
35
36
  }
36
37
  var str = '';
37
- if (json.name === 'For') {
38
- str += "${".concat((_b = json.bindings.each) === null || _b === void 0 ? void 0 : _b.code, "?.map(").concat(json.properties._forName, " => `");
38
+ if ((0, mitosis_node_1.checkIsForNode)(json)) {
39
+ str += "${".concat((_b = json.bindings.each) === null || _b === void 0 ? void 0 : _b.code, "?.map(").concat(json.scope.forName, " => `");
39
40
  if (json.children) {
40
41
  str += json.children.map(function (item) { return blockToTemplate(item, options); }).join('\n');
41
42
  }
@@ -1,7 +1,8 @@
1
1
  import { MitosisNode } from '../types/mitosis-node';
2
- import { BaseTranspilerOptions, Transpiler } from '../types/transpiler';
2
+ import { BaseTranspilerOptions } from '../types/transpiler';
3
3
  import { OmitObj } from '../helpers/typescript';
4
4
  export declare type VueVersion = 2 | 3;
5
+ export declare type Api = 'options' | 'composition';
5
6
  interface VueVersionOpt {
6
7
  vueVersion: VueVersion;
7
8
  }
@@ -9,6 +10,7 @@ export interface ToVueOptions extends BaseTranspilerOptions, VueVersionOpt {
9
10
  cssNamespace?: () => string;
10
11
  namePrefix?: (path: string) => string;
11
12
  asyncComponentImports?: boolean;
13
+ api?: Api;
12
14
  }
13
15
  declare type BlockRenderer = (json: MitosisNode, options: ToVueOptions, scope?: Scope) => string;
14
16
  interface Scope {
@@ -16,6 +18,6 @@ interface Scope {
16
18
  }
17
19
  export declare const blockToVue: BlockRenderer;
18
20
  declare type VueOptsWithoutVersion = OmitObj<ToVueOptions, VueVersionOpt>;
19
- export declare const componentToVue2: (vueOptions?: VueOptsWithoutVersion) => Transpiler;
20
- export declare const componentToVue3: (vueOptions?: VueOptsWithoutVersion) => Transpiler;
21
+ export declare const componentToVue2: (vueOptions?: VueOptsWithoutVersion) => import("../types/transpiler").Transpiler<string>;
22
+ export declare const componentToVue3: (vueOptions?: VueOptsWithoutVersion) => import("../types/transpiler").Transpiler<string>;
21
23
  export {};