@builder.io/mitosis 0.0.45 → 0.0.46

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 (206) hide show
  1. package/dist/src/__tests__/builder.test.js +71 -68
  2. package/dist/src/__tests__/context.test.js +13 -10
  3. package/dist/src/__tests__/data/basic.raw.jsx +1 -1
  4. package/dist/src/__tests__/data/blocks/button-with-metadata.raw.jsx +1 -1
  5. package/dist/src/__tests__/data/blocks/columns.raw.jsx +2 -2
  6. package/dist/src/__tests__/data/blocks/custom-code.raw.jsx +3 -3
  7. package/dist/src/__tests__/data/blocks/embed.raw.jsx +3 -3
  8. package/dist/src/__tests__/data/blocks/form.raw.jsx +5 -5
  9. package/dist/src/__tests__/data/blocks/image.raw.jsx +4 -4
  10. package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +4 -4
  11. package/dist/src/__tests__/data/context/component-with-context.lite.jsx +2 -2
  12. package/dist/src/__tests__/data/context/simple.context.lite.js +1 -1
  13. package/dist/src/__tests__/html.test.js +2 -2
  14. package/dist/src/__tests__/liquid.test.js +34 -34
  15. package/dist/src/__tests__/parse-jsx.test.js +1 -1
  16. package/dist/src/__tests__/qwik.test.js +36 -36
  17. package/dist/src/__tests__/react-native.test.js +35 -35
  18. package/dist/src/__tests__/react.test.js +35 -35
  19. package/dist/src/__tests__/solid.test.js +32 -32
  20. package/dist/src/__tests__/vue.test.js +35 -34
  21. package/dist/src/generators/angular.d.ts +4 -7
  22. package/dist/src/generators/angular.js +77 -81
  23. package/dist/src/generators/builder.d.ts +4 -4
  24. package/dist/src/generators/builder.js +57 -57
  25. package/dist/src/generators/context/react.d.ts +3 -1
  26. package/dist/src/generators/context/react.js +20 -17
  27. package/dist/src/generators/html.d.ts +5 -9
  28. package/dist/src/generators/html.js +205 -199
  29. package/dist/src/generators/liquid.d.ts +5 -9
  30. package/dist/src/generators/liquid.js +62 -59
  31. package/dist/src/generators/mitosis.d.ts +6 -7
  32. package/dist/src/generators/mitosis.js +61 -63
  33. package/dist/src/generators/qwik/component.js +13 -13
  34. package/dist/src/generators/qwik/handlers.js +12 -8
  35. package/dist/src/generators/qwik/jsx.js +13 -9
  36. package/dist/src/generators/qwik/styles.js +11 -7
  37. package/dist/src/generators/react-native.d.ts +4 -7
  38. package/dist/src/generators/react-native.js +25 -22
  39. package/dist/src/generators/react.d.ts +4 -8
  40. package/dist/src/generators/react.js +103 -112
  41. package/dist/src/generators/solid.d.ts +4 -8
  42. package/dist/src/generators/solid.js +55 -54
  43. package/dist/src/generators/svelte.d.ts +4 -7
  44. package/dist/src/generators/svelte.js +120 -123
  45. package/dist/src/generators/swift-ui.d.ts +2 -2
  46. package/dist/src/generators/swift-ui.js +62 -62
  47. package/dist/src/generators/template.d.ts +4 -8
  48. package/dist/src/generators/template.js +48 -45
  49. package/dist/src/generators/vue.d.ts +9 -9
  50. package/dist/src/generators/vue.js +169 -169
  51. package/dist/src/helpers/babel-transform.js +9 -9
  52. package/dist/src/helpers/collect-styles.js +39 -39
  53. package/dist/src/helpers/dash-case.js +1 -1
  54. package/dist/src/helpers/generic-format.test.js +2 -2
  55. package/dist/src/helpers/get-components-used.js +2 -2
  56. package/dist/src/helpers/get-components.js +3 -3
  57. package/dist/src/helpers/get-props.js +1 -1
  58. package/dist/src/helpers/get-refs.js +2 -2
  59. package/dist/src/helpers/get-state-object-string.js +5 -5
  60. package/dist/src/helpers/get-state-used.js +1 -1
  61. package/dist/src/helpers/get-styles.js +1 -1
  62. package/dist/src/helpers/getters-to-functions.js +4 -4
  63. package/dist/src/helpers/handle-missing-state.js +1 -1
  64. package/dist/src/helpers/has-component.js +2 -2
  65. package/dist/src/helpers/has-props.js +1 -1
  66. package/dist/src/helpers/is-children.js +1 -1
  67. package/dist/src/helpers/json.d.ts +1 -0
  68. package/dist/src/helpers/json.js +17 -0
  69. package/dist/src/helpers/map-refs.js +4 -4
  70. package/dist/src/helpers/map-to-attributes.js +4 -4
  71. package/dist/src/helpers/map-to-css.js +2 -2
  72. package/dist/src/helpers/parse-node.js +2 -2
  73. package/dist/src/helpers/parse-reactive-script.js +4 -4
  74. package/dist/src/helpers/process-http-requests.js +1 -1
  75. package/dist/src/helpers/process-tag-references.js +4 -4
  76. package/dist/src/helpers/remove-surrounding-block.test.js +1 -1
  77. package/dist/src/helpers/render-imports.js +7 -7
  78. package/dist/src/helpers/replace-idenifiers.js +1 -1
  79. package/dist/src/helpers/strip-meta-properties.js +2 -2
  80. package/dist/src/helpers/trace-reference-to-module-path.js +1 -1
  81. package/dist/src/helpers/traverse-nodes.js +2 -2
  82. package/dist/src/helpers/try-prettier-format.js +1 -1
  83. package/dist/src/index.d.ts +2 -0
  84. package/dist/src/index.js +2 -0
  85. package/dist/src/modules/plugins.d.ts +2 -10
  86. package/dist/src/parsers/angular.js +13 -13
  87. package/dist/src/parsers/builder.js +54 -58
  88. package/dist/src/parsers/context.js +2 -2
  89. package/dist/src/parsers/jsx.js +59 -87
  90. package/dist/src/parsers/liquid.js +191 -194
  91. package/dist/src/plugins/compile-away-builder-components.js +49 -45
  92. package/dist/src/plugins/compile-away-components.js +3 -3
  93. package/dist/src/plugins/map-styles.js +3 -3
  94. package/dist/src/targets.d.ts +24 -0
  95. package/dist/src/targets.js +30 -0
  96. package/dist/src/types/config.d.ts +31 -0
  97. package/dist/src/types/{jsx-lite-component.js → config.js} +0 -0
  98. package/dist/{test/qwik/Todo/Todo.js/low.js → src/types/generators.d.ts} +0 -0
  99. package/dist/src/types/generators.js +1 -0
  100. package/dist/src/types/plugins.d.ts +11 -0
  101. package/dist/src/types/{jsx-lite-context.js → plugins.js} +0 -0
  102. package/dist/test/qwik/{Todo → todo}/Todo.cjs/high.cjs +0 -0
  103. package/dist/test/qwik/{Todo → todo}/Todo.cjs/low.cjs +0 -0
  104. package/dist/test/qwik/{Todo → todo}/Todo.cjs/med.cjs +0 -0
  105. package/dist/test/qwik/{Todo → todo}/Todo.js/high.js +0 -0
  106. package/dist/test/qwik/{qwik/todo → todo}/Todo.js/low.js +0 -0
  107. package/dist/test/qwik/{Todo → todo}/Todo.js/med.js +0 -0
  108. package/dist/test/qwik/{Todo → todo}/Todo.tsx/high.tsx +0 -0
  109. package/dist/test/qwik/{Todo → todo}/Todo.tsx/low.tsx +0 -0
  110. package/dist/test/qwik/{Todo → todo}/Todo.tsx/med.tsx +0 -0
  111. package/dist/test/qwik/{Todos → todos}/Todo.tsx/high.tsx +0 -0
  112. package/dist/test/qwik/{Todos → todos}/Todo.tsx/low.tsx +0 -0
  113. package/dist/test/qwik/{Todos → todos}/Todo.tsx/med.tsx +0 -0
  114. package/dist/tsconfig.tsbuildinfo +1 -1
  115. package/package.json +2 -2
  116. package/dist/src/__tests__/data/blocks/tabs.raw.d.ts +0 -11
  117. package/dist/src/__tests__/data/blocks/tabs.raw.jsx +0 -24
  118. package/dist/src/__tests__/qoot.test.d.ts +0 -1
  119. package/dist/src/__tests__/qoot.test.js +0 -115
  120. package/dist/src/generators/jsx-lite.d.ts +0 -10
  121. package/dist/src/generators/jsx-lite.js +0 -176
  122. package/dist/src/generators/qoot.d.ts +0 -21
  123. package/dist/src/generators/qoot.js +0 -442
  124. package/dist/src/generators/qwik.d.ts +0 -21
  125. package/dist/src/generators/qwik.js +0 -458
  126. package/dist/src/helpers/create-jsx-lite-component.d.ts +0 -2
  127. package/dist/src/helpers/create-jsx-lite-component.js +0 -16
  128. package/dist/src/helpers/create-jsx-lite-context.d.ts +0 -4
  129. package/dist/src/helpers/create-jsx-lite-context.js +0 -18
  130. package/dist/src/helpers/create-jsx-lite-node.d.ts +0 -2
  131. package/dist/src/helpers/create-jsx-lite-node.js +0 -16
  132. package/dist/src/helpers/is-jsx-lite-node.d.ts +0 -2
  133. package/dist/src/helpers/is-jsx-lite-node.js +0 -7
  134. package/dist/src/types/jsx-lite-component.d.ts +0 -63
  135. package/dist/src/types/jsx-lite-context.d.ts +0 -6
  136. package/dist/src/types/jsx-lite-node.d.ts +0 -13
  137. package/dist/src/types/jsx-lite-node.js +0 -2
  138. package/dist/src/types/jsx-lite-styles.d.ts +0 -1
  139. package/dist/src/types/jsx-lite-styles.js +0 -2
  140. package/dist/test/qoot/Todo/bundle.js +0 -88
  141. package/dist/test/qoot/Todo/component.ts +0 -17
  142. package/dist/test/qoot/Todo/onButtonClick.ts +0 -13
  143. package/dist/test/qoot/Todo/onInput2Blur.ts +0 -11
  144. package/dist/test/qoot/Todo/onInput2KeyUp.ts +0 -10
  145. package/dist/test/qoot/Todo/onInputClick.ts +0 -10
  146. package/dist/test/qoot/Todo/onLabelDblClick.ts +0 -11
  147. package/dist/test/qoot/Todo/public.ts +0 -4
  148. package/dist/test/qoot/Todo/template.tsx +0 -46
  149. package/dist/test/qoot/Todos/component.ts +0 -9
  150. package/dist/test/qoot/Todos/onInputClick.ts +0 -14
  151. package/dist/test/qoot/Todos/public.ts +0 -3
  152. package/dist/test/qoot/Todos/template.tsx +0 -30
  153. package/dist/test/qwik/Todo/bundle.js +0 -46
  154. package/dist/test/qwik/Todo/component.ts +0 -17
  155. package/dist/test/qwik/Todo/onButtonClick.ts +0 -10
  156. package/dist/test/qwik/Todo/onInput2Blur.ts +0 -14
  157. package/dist/test/qwik/Todo/onInput2KeyUp.ts +0 -10
  158. package/dist/test/qwik/Todo/onInputClick.ts +0 -13
  159. package/dist/test/qwik/Todo/onLabelDblClick.ts +0 -11
  160. package/dist/test/qwik/Todo/public.ts +0 -3
  161. package/dist/test/qwik/Todo/template.tsx +0 -46
  162. package/dist/test/qwik/Todo.ts +0 -4
  163. package/dist/test/qwik/Todo_component.ts +0 -17
  164. package/dist/test/qwik/Todo_onButtonClick.ts +0 -13
  165. package/dist/test/qwik/Todo_onInput2Blur.ts +0 -14
  166. package/dist/test/qwik/Todo_onInput2KeyUp.ts +0 -10
  167. package/dist/test/qwik/Todo_onInputClick.ts +0 -13
  168. package/dist/test/qwik/Todo_onLabelDblClick.ts +0 -14
  169. package/dist/test/qwik/Todo_template.tsx +0 -46
  170. package/dist/test/qwik/Todos/component.ts +0 -9
  171. package/dist/test/qwik/Todos/onInputClick.ts +0 -14
  172. package/dist/test/qwik/Todos/public.ts +0 -3
  173. package/dist/test/qwik/Todos/template.tsx +0 -30
  174. package/dist/test/qwik/Todos.ts +0 -3
  175. package/dist/test/qwik/Todos_component.ts +0 -9
  176. package/dist/test/qwik/Todos_onInputClick.ts +0 -14
  177. package/dist/test/qwik/Todos_template.tsx +0 -30
  178. package/dist/test/qwik/qwik/Image/high.js +0 -1
  179. package/dist/test/qwik/qwik/Image/low.js +0 -75
  180. package/dist/test/qwik/qwik/Image/med.js +0 -9
  181. package/dist/test/qwik/qwik/Image.slow/high.js +0 -1
  182. package/dist/test/qwik/qwik/Image.slow/low.js +0 -75
  183. package/dist/test/qwik/qwik/Image.slow/med.js +0 -9
  184. package/dist/test/qwik/qwik/button/high.js +0 -8
  185. package/dist/test/qwik/qwik/button/low.js +0 -34
  186. package/dist/test/qwik/qwik/button/med.js +0 -9
  187. package/dist/test/qwik/qwik/hello_world/stylesheet/high.jsx +0 -1
  188. package/dist/test/qwik/qwik/hello_world/stylesheet/low.jsx +0 -24
  189. package/dist/test/qwik/qwik/hello_world/stylesheet/med.jsx +0 -9
  190. package/dist/test/qwik/qwik/page-with-symbol/high.js +0 -1
  191. package/dist/test/qwik/qwik/page-with-symbol/low.js +0 -49
  192. package/dist/test/qwik/qwik/page-with-symbol/med.js +0 -9
  193. package/dist/test/qwik/qwik/svg/high.js +0 -1
  194. package/dist/test/qwik/qwik/svg/low.js +0 -30
  195. package/dist/test/qwik/qwik/svg/med.js +0 -9
  196. package/dist/test/qwik/qwik/todo/Todo.cjs/high.cjs +0 -31
  197. package/dist/test/qwik/qwik/todo/Todo.cjs/low.cjs +0 -1
  198. package/dist/test/qwik/qwik/todo/Todo.cjs/med.cjs +0 -59
  199. package/dist/test/qwik/qwik/todo/Todo.js/high.js +0 -5
  200. package/dist/test/qwik/qwik/todo/Todo.js/med.js +0 -1
  201. package/dist/test/qwik/qwik/todo/Todo.tsx/high.tsx +0 -30
  202. package/dist/test/qwik/qwik/todo/Todo.tsx/low.tsx +0 -1
  203. package/dist/test/qwik/qwik/todo/Todo.tsx/med.tsx +0 -34
  204. package/dist/test/qwik/qwik/todos/Todo.tsx/high.tsx +0 -12
  205. package/dist/test/qwik/qwik/todos/Todo.tsx/low.tsx +0 -24
  206. package/dist/test/qwik/qwik/todos/Todo.tsx/med.tsx +0 -8
@@ -24,8 +24,8 @@ var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
24
24
  // Transform <foo.bar key="value" /> to <component :is="foo.bar" key="value" />
25
25
  function processDynamicComponents(json, options) {
26
26
  var found = false;
27
- traverse_1.default(json).forEach(function (node) {
28
- if (is_mitosis_node_1.isMitosisNode(node)) {
27
+ (0, traverse_1.default)(json).forEach(function (node) {
28
+ if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
29
29
  if (node.name.includes('.')) {
30
30
  node.bindings.component = node.name;
31
31
  node.name = 'Dynamic';
@@ -63,20 +63,20 @@ var collectClassString = function (json) {
63
63
  }
64
64
  if (typeof json.bindings.css === 'string' &&
65
65
  json.bindings.css.trim().length > 4) {
66
- dynamicClasses.push("css(" + json.bindings.css + ")");
66
+ dynamicClasses.push("css(".concat(json.bindings.css, ")"));
67
67
  }
68
68
  delete json.bindings.css;
69
69
  var staticClassesString = staticClasses.join(' ');
70
70
  var dynamicClassesString = dynamicClasses.join(" + ' ' + ");
71
71
  var hasDynamicClasses = Boolean(dynamicClasses.length);
72
72
  if (hasStaticClasses && !hasDynamicClasses) {
73
- return "\"" + staticClassesString + "\"";
73
+ return "\"".concat(staticClassesString, "\"");
74
74
  }
75
75
  if (hasDynamicClasses && !hasStaticClasses) {
76
- return "{" + dynamicClassesString + "}";
76
+ return "{".concat(dynamicClassesString, "}");
77
77
  }
78
78
  if (hasDynamicClasses && hasStaticClasses) {
79
- return "{\"" + staticClassesString + " \" + " + dynamicClassesString + "}";
79
+ return "{\"".concat(staticClassesString, " \" + ").concat(dynamicClassesString, "}");
80
80
  }
81
81
  return null;
82
82
  };
@@ -86,29 +86,29 @@ var blockToSolid = function (json, options) {
86
86
  return json.properties._text;
87
87
  }
88
88
  if (json.bindings._text) {
89
- return "{" + json.bindings._text + "}";
89
+ return "{".concat(json.bindings._text, "}");
90
90
  }
91
91
  if (json.name === 'For') {
92
92
  var needsWrapper = json.children.length !== 1;
93
- return "<For each={" + json.bindings.each + "}>\n {(" + json.properties._forName + ", index) =>\n " + (needsWrapper ? '<>' : '') + "\n " + json.children.map(function (child) { return blockToSolid(child, options); }) + "}\n " + (needsWrapper ? '</>' : '') + "\n </For>";
93
+ return "<For each={".concat(json.bindings.each, "}>\n {(").concat(json.properties._forName, ", index) =>\n ").concat(needsWrapper ? '<>' : '', "\n ").concat(json.children.map(function (child) { return blockToSolid(child, options); }), "}\n ").concat(needsWrapper ? '</>' : '', "\n </For>");
94
94
  }
95
95
  var str = '';
96
96
  if (json.name === 'Fragment') {
97
97
  str += '<';
98
98
  }
99
99
  else {
100
- str += "<" + json.name + " ";
100
+ str += "<".concat(json.name, " ");
101
101
  }
102
102
  var classString = collectClassString(json);
103
103
  if (classString) {
104
- str += " class=" + classString + " ";
104
+ str += " class=".concat(classString, " ");
105
105
  }
106
106
  if (json.bindings._spread) {
107
- str += " {...(" + json.bindings._spread + ")} ";
107
+ str += " {...(".concat(json.bindings._spread, ")} ");
108
108
  }
109
109
  for (var key in json.properties) {
110
110
  var value = json.properties[key];
111
- str += " " + key + "=\"" + value + "\" ";
111
+ str += " ".concat(key, "=\"").concat(value, "\" ");
112
112
  }
113
113
  for (var key in json.bindings) {
114
114
  var value = json.bindings[key];
@@ -117,10 +117,10 @@ var blockToSolid = function (json, options) {
117
117
  }
118
118
  if (key.startsWith('on')) {
119
119
  var useKey = key === 'onChange' && json.name === 'input' ? 'onInput' : key;
120
- str += " " + useKey + "={event => " + value + "} ";
120
+ str += " ".concat(useKey, "={event => ").concat(value, "} ");
121
121
  }
122
122
  else {
123
- str += " " + key + "={" + value + "} ";
123
+ str += " ".concat(key, "={").concat(value, "} ");
124
124
  }
125
125
  }
126
126
  if (jsx_1.selfClosingTags.has(json.name)) {
@@ -134,57 +134,58 @@ var blockToSolid = function (json, options) {
134
134
  str += '</>';
135
135
  }
136
136
  else {
137
- str += "</" + json.name + ">";
137
+ str += "</".concat(json.name, ">");
138
138
  }
139
139
  return str;
140
140
  };
141
141
  var getRefsString = function (json, refs) {
142
- if (refs === void 0) { refs = get_refs_1.getRefs(json); }
142
+ if (refs === void 0) { refs = (0, get_refs_1.getRefs)(json); }
143
143
  var str = '';
144
144
  for (var _i = 0, _a = Array.from(refs); _i < _a.length; _i++) {
145
145
  var ref = _a[_i];
146
- str += "\nconst " + ref + " = useRef();";
146
+ str += "\nconst ".concat(ref, " = useRef();");
147
147
  }
148
148
  return str;
149
149
  };
150
- var componentToSolid = function (componentJson, options) {
150
+ var componentToSolid = function (options) {
151
151
  if (options === void 0) { options = {}; }
152
- var json = fast_clone_1.fastClone(componentJson);
153
- if (options.plugins) {
154
- json = plugins_1.runPreJsonPlugins(json, options.plugins);
155
- }
156
- var componentHasStyles = collect_styles_1.hasStyles(json);
157
- var addWrapper = json.children.length > 1;
158
- if (options.plugins) {
159
- json = plugins_1.runPostJsonPlugins(json, options.plugins);
160
- }
161
- strip_meta_properties_1.stripMetaProperties(json);
162
- var foundDynamicComponents = processDynamicComponents(json, options);
163
- var stateString = get_state_object_string_1.getStateObjectStringFromComponent(json);
164
- var hasState = Boolean(Object.keys(componentJson.state).length);
165
- var componentsUsed = get_components_used_1.getComponentsUsed(json);
166
- var hasShowComponent = componentsUsed.has('Show');
167
- var hasForComponent = componentsUsed.has('For');
168
- var str = dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n\n export default function ", "(props) {\n ", "\n \n ", "\n\n ", "\n\n return (", "\n ", "\n ", ")\n }\n\n "], ["\n ",
169
- "\n ", "\n ", "\n ",
170
- "\n ", "\n\n export default function ", "(props) {\n ", "\n \n ", "\n\n ", "\n\n return (", "\n ", "\n ", ")\n }\n\n "])), !(hasShowComponent || hasForComponent)
171
- ? ''
172
- : "import { \n " + (!hasShowComponent ? '' : 'Show, ') + "\n " + (!hasForComponent ? '' : 'For, ') + "\n " + (!json.hooks.onMount ? '' : 'onMount, ') + "\n } from 'solid-js';", !foundDynamicComponents ? '' : "import { Dynamic } from 'solid-js/web';", !hasState ? '' : "import { createMutable } from 'solid-js/store';", !componentHasStyles
173
- ? ''
174
- : "import { css } from \"solid-styled-components\";", render_imports_1.renderPreComponent(json), json.name, !hasState ? '' : "const state = createMutable(" + stateString + ");", getRefsString(json), !json.hooks.onMount ? '' : "onMount(() => { " + json.hooks.onMount + " })", addWrapper ? '<>' : '', json.children.map(function (item) { return blockToSolid(item, options); }).join('\n'), addWrapper ? '</>' : '');
175
- if (options.plugins) {
176
- str = plugins_1.runPreCodePlugins(str, options.plugins);
177
- }
178
- if (options.prettier !== false) {
179
- str = standalone_1.format(str, {
180
- parser: 'typescript',
181
- plugins: [require('prettier/parser-typescript')],
182
- });
183
- }
184
- if (options.plugins) {
185
- str = plugins_1.runPostCodePlugins(str, options.plugins);
186
- }
187
- return str;
152
+ return function (_a) {
153
+ var component = _a.component;
154
+ var json = (0, fast_clone_1.fastClone)(component);
155
+ if (options.plugins) {
156
+ json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
157
+ }
158
+ var componentHasStyles = (0, collect_styles_1.hasStyles)(json);
159
+ var addWrapper = json.children.length > 1;
160
+ if (options.plugins) {
161
+ json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
162
+ }
163
+ (0, strip_meta_properties_1.stripMetaProperties)(json);
164
+ var foundDynamicComponents = processDynamicComponents(json, options);
165
+ var stateString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json);
166
+ var hasState = Boolean(Object.keys(component.state).length);
167
+ var componentsUsed = (0, get_components_used_1.getComponentsUsed)(json);
168
+ var hasShowComponent = componentsUsed.has('Show');
169
+ var hasForComponent = componentsUsed.has('For');
170
+ var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n\n export default function ", "(props) {\n ", "\n \n ", "\n\n ", "\n\n return (", "\n ", "\n ", ")\n }\n\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n\n export default function ", "(props) {\n ", "\n \n ", "\n\n ", "\n\n return (", "\n ", "\n ", ")\n }\n\n "])), !(hasShowComponent || hasForComponent)
171
+ ? ''
172
+ : "import { \n ".concat(!hasShowComponent ? '' : 'Show, ', "\n ").concat(!hasForComponent ? '' : 'For, ', "\n ").concat(!json.hooks.onMount ? '' : 'onMount, ', "\n } from 'solid-js';"), !foundDynamicComponents ? '' : "import { Dynamic } from 'solid-js/web';", !hasState ? '' : "import { createMutable } from 'solid-js/store';", !componentHasStyles
173
+ ? ''
174
+ : "import { css } from \"solid-styled-components\";", (0, render_imports_1.renderPreComponent)(json), json.name, !hasState ? '' : "const state = createMutable(".concat(stateString, ");"), getRefsString(json), !json.hooks.onMount ? '' : "onMount(() => { ".concat(json.hooks.onMount, " })"), addWrapper ? '<>' : '', json.children.map(function (item) { return blockToSolid(item, options); }).join('\n'), addWrapper ? '</>' : '');
175
+ if (options.plugins) {
176
+ str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
177
+ }
178
+ if (options.prettier !== false) {
179
+ str = (0, standalone_1.format)(str, {
180
+ parser: 'typescript',
181
+ plugins: [require('prettier/parser-typescript')],
182
+ });
183
+ }
184
+ if (options.plugins) {
185
+ str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
186
+ }
187
+ return str;
188
+ };
188
189
  };
189
190
  exports.componentToSolid = componentToSolid;
190
191
  var templateObject_1;
@@ -1,10 +1,7 @@
1
- import { MitosisComponent } from '../types/mitosis-component';
2
1
  import { MitosisNode } from '../types/mitosis-node';
3
- import { Plugin } from '../modules/plugins';
4
- export declare type ToSvelteOptions = {
5
- prettier?: boolean;
2
+ import { BaseTranspilerOptions, Transpiler } from '../types/config';
3
+ export interface ToSvelteOptions extends BaseTranspilerOptions {
6
4
  stateType?: 'proxies' | 'variables';
7
- plugins?: Plugin[];
8
- };
5
+ }
9
6
  export declare const blockToSvelte: (json: MitosisNode, options: ToSvelteOptions) => string;
10
- export declare const componentToSvelte: (componentJson: MitosisComponent, options?: ToSvelteOptions) => string;
7
+ export declare const componentToSvelte: (options?: ToSvelteOptions) => Transpiler;
@@ -37,51 +37,51 @@ var strip_meta_properties_1 = require("../helpers/strip-meta-properties");
37
37
  var remove_surrounding_block_1 = require("../helpers/remove-surrounding-block");
38
38
  var mappers = {
39
39
  Fragment: function (json, options) {
40
- return "" + json.children
41
- .map(function (item) { return exports.blockToSvelte(item, options); })
42
- .join('\n');
40
+ return "".concat(json.children
41
+ .map(function (item) { return (0, exports.blockToSvelte)(item, options); })
42
+ .join('\n'));
43
43
  },
44
44
  };
45
45
  var blockToSvelte = function (json, options) {
46
46
  if (mappers[json.name]) {
47
47
  return mappers[json.name](json, options);
48
48
  }
49
- if (is_children_1.default(json)) {
49
+ if ((0, is_children_1.default)(json)) {
50
50
  return "<slot></slot>";
51
51
  }
52
52
  if (json.properties._text) {
53
53
  return json.properties._text;
54
54
  }
55
55
  if (json.bindings._text) {
56
- return "{" + strip_state_and_props_refs_1.stripStateAndPropsRefs(json.bindings._text, {
56
+ return "{".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings._text, {
57
57
  includeState: options.stateType === 'variables',
58
- }) + "}";
58
+ }), "}");
59
59
  }
60
60
  var str = '';
61
61
  if (json.name === 'For') {
62
- str += "{#each " + strip_state_and_props_refs_1.stripStateAndPropsRefs(json.bindings.each, {
62
+ str += "{#each ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.each, {
63
63
  includeState: options.stateType === 'variables',
64
- }) + " as " + json.properties._forName + " }";
65
- str += json.children.map(function (item) { return exports.blockToSvelte(item, options); }).join('\n');
64
+ }), " as ").concat(json.properties._forName, " }");
65
+ str += json.children.map(function (item) { return (0, exports.blockToSvelte)(item, options); }).join('\n');
66
66
  str += "{/each}";
67
67
  }
68
68
  else if (json.name === 'Show') {
69
- str += "{#if " + strip_state_and_props_refs_1.stripStateAndPropsRefs(json.bindings.when, {
69
+ str += "{#if ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.when, {
70
70
  includeState: options.stateType === 'variables',
71
- }) + " }";
72
- str += json.children.map(function (item) { return exports.blockToSvelte(item, options); }).join('\n');
71
+ }), " }");
72
+ str += json.children.map(function (item) { return (0, exports.blockToSvelte)(item, options); }).join('\n');
73
73
  str += "{/if}";
74
74
  }
75
75
  else {
76
- str += "<" + json.name + " ";
76
+ str += "<".concat(json.name, " ");
77
77
  if (json.bindings._spread) {
78
- str += "{..." + strip_state_and_props_refs_1.stripStateAndPropsRefs(json.bindings._spread, {
78
+ str += "{...".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings._spread, {
79
79
  includeState: options.stateType === 'variables',
80
- }) + "}";
80
+ }), "}");
81
81
  }
82
82
  for (var key in json.properties) {
83
83
  var value = json.properties[key];
84
- str += " " + key + "=\"" + value + "\" ";
84
+ str += " ".concat(key, "=\"").concat(value, "\" ");
85
85
  }
86
86
  for (var key in json.bindings) {
87
87
  if (key === '_spread') {
@@ -89,19 +89,19 @@ var blockToSvelte = function (json, options) {
89
89
  }
90
90
  var value = json.bindings[key];
91
91
  // TODO: proper babel transform to replace. Util for this
92
- var useValue = strip_state_and_props_refs_1.stripStateAndPropsRefs(value, {
92
+ var useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value, {
93
93
  includeState: options.stateType === 'variables',
94
94
  });
95
95
  if (key.startsWith('on')) {
96
96
  var event_1 = key.replace('on', '').toLowerCase();
97
97
  // TODO: handle quotes in event handler values
98
- str += " on:" + event_1 + "=\"{event => " + remove_surrounding_block_1.removeSurroundingBlock(useValue) + "}\" ";
98
+ str += " on:".concat(event_1, "=\"{event => ").concat((0, remove_surrounding_block_1.removeSurroundingBlock)(useValue), "}\" ");
99
99
  }
100
100
  else if (key === 'ref') {
101
- str += " bind:this={" + useValue + "} ";
101
+ str += " bind:this={".concat(useValue, "} ");
102
102
  }
103
103
  else {
104
- str += " " + key + "={" + useValue + "} ";
104
+ str += " ".concat(key, "={").concat(useValue, "} ");
105
105
  }
106
106
  }
107
107
  if (jsx_1.selfClosingTags.has(json.name)) {
@@ -110,10 +110,10 @@ var blockToSvelte = function (json, options) {
110
110
  str += '>';
111
111
  if (json.children) {
112
112
  str += json.children
113
- .map(function (item) { return exports.blockToSvelte(item, options); })
113
+ .map(function (item) { return (0, exports.blockToSvelte)(item, options); })
114
114
  .join('\n');
115
115
  }
116
- str += "</" + json.name + ">";
116
+ str += "</".concat(json.name, ">");
117
117
  }
118
118
  return str;
119
119
  };
@@ -126,12 +126,12 @@ exports.blockToSvelte = blockToSvelte;
126
126
  * when easily identified, for more idiomatic svelte code
127
127
  */
128
128
  var useBindValue = function (json, options) {
129
- traverse_1.default(json).forEach(function (item) {
130
- if (is_mitosis_node_1.isMitosisNode(item)) {
129
+ (0, traverse_1.default)(json).forEach(function (item) {
130
+ if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
131
131
  var _a = item.bindings, value = _a.value, onChange = _a.onChange;
132
132
  if (value && onChange) {
133
133
  if (onChange.replace(/\s+/g, '') ===
134
- value + "=event.target.value") {
134
+ "".concat(value, "=event.target.value")) {
135
135
  delete item.bindings.value;
136
136
  delete item.bindings.onChange;
137
137
  item.bindings['bind:value'] = value;
@@ -140,110 +140,107 @@ var useBindValue = function (json, options) {
140
140
  }
141
141
  });
142
142
  };
143
- var componentToSvelte = function (componentJson, options) {
143
+ var componentToSvelte = function (options) {
144
144
  if (options === void 0) { options = {}; }
145
- var useOptions = __assign(__assign({}, options), { stateType: 'variables' });
146
- // Make a copy we can safely mutate, similar to babel's toolchain
147
- var json = fast_clone_1.fastClone(componentJson);
148
- if (useOptions.plugins) {
149
- json = plugins_1.runPreJsonPlugins(json, useOptions.plugins);
150
- }
151
- var refs = Array.from(get_refs_1.getRefs(json));
152
- useBindValue(json, useOptions);
153
- if (useOptions.plugins) {
154
- json = plugins_1.runPostJsonPlugins(json, useOptions.plugins);
155
- }
156
- var css = collect_styles_1.collectCss(json);
157
- strip_meta_properties_1.stripMetaProperties(json);
158
- var dataString = get_state_object_string_1.getStateObjectStringFromComponent(json, {
159
- data: true,
160
- functions: false,
161
- getters: false,
162
- format: useOptions.stateType === 'proxies' ? 'object' : 'variables',
163
- keyPrefix: useOptions.stateType === 'variables' ? 'let ' : '',
164
- valueMapper: function (code) {
165
- return strip_state_and_props_refs_1.stripStateAndPropsRefs(code, {
166
- includeState: useOptions.stateType === 'variables',
167
- });
168
- },
169
- });
170
- var getterString = get_state_object_string_1.getStateObjectStringFromComponent(json, {
171
- data: false,
172
- getters: true,
173
- functions: false,
174
- format: 'variables',
175
- keyPrefix: '$: ',
176
- valueMapper: function (code) {
177
- return strip_state_and_props_refs_1.stripStateAndPropsRefs(code.replace(/^get ([a-zA-Z_\$0-9]+)/, '$1 = ').replace(/\)/, ') => '), {
145
+ return function (_a) {
146
+ var component = _a.component;
147
+ var useOptions = __assign(__assign({}, options), { stateType: 'variables' });
148
+ // Make a copy we can safely mutate, similar to babel's toolchain
149
+ var json = (0, fast_clone_1.fastClone)(component);
150
+ if (useOptions.plugins) {
151
+ json = (0, plugins_1.runPreJsonPlugins)(json, useOptions.plugins);
152
+ }
153
+ var refs = Array.from((0, get_refs_1.getRefs)(json));
154
+ useBindValue(json, useOptions);
155
+ if (useOptions.plugins) {
156
+ json = (0, plugins_1.runPostJsonPlugins)(json, useOptions.plugins);
157
+ }
158
+ var css = (0, collect_styles_1.collectCss)(json);
159
+ (0, strip_meta_properties_1.stripMetaProperties)(json);
160
+ var dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
161
+ data: true,
162
+ functions: false,
163
+ getters: false,
164
+ format: useOptions.stateType === 'proxies' ? 'object' : 'variables',
165
+ keyPrefix: useOptions.stateType === 'variables' ? 'let ' : '',
166
+ valueMapper: function (code) {
167
+ return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
168
+ includeState: useOptions.stateType === 'variables',
169
+ });
170
+ },
171
+ });
172
+ var getterString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
173
+ data: false,
174
+ getters: true,
175
+ functions: false,
176
+ format: 'variables',
177
+ keyPrefix: '$: ',
178
+ valueMapper: function (code) {
179
+ return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code.replace(/^get ([a-zA-Z_\$0-9]+)/, '$1 = ').replace(/\)/, ') => '), {
180
+ includeState: useOptions.stateType === 'variables',
181
+ });
182
+ },
183
+ });
184
+ var functionsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
185
+ data: false,
186
+ getters: false,
187
+ functions: true,
188
+ format: 'variables',
189
+ keyPrefix: 'function ',
190
+ valueMapper: function (code) {
191
+ return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
192
+ includeState: useOptions.stateType === 'variables',
193
+ });
194
+ },
195
+ });
196
+ var hasData = dataString.length > 4;
197
+ var props = Array.from((0, get_props_1.getProps)(json));
198
+ var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <script>\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 </script>\n\n ", "\n\n ", "\n "])), !json.hooks.onMount ? '' : "import { onMount } from 'svelte'", !json.hooks.onUnMount ? '' : "import { onDestroy } from 'svelte'", (0, render_imports_1.renderPreComponent)(json), !hasData || useOptions.stateType === 'variables'
199
+ ? ''
200
+ : "import onChange from 'on-change'", refs
201
+ .concat(props)
202
+ .map(function (name) { return "export let ".concat(name, ";"); })
203
+ .join('\n'), functionsString.length < 4 ? '' : functionsString, getterString.length < 4 ? '' : getterString, useOptions.stateType === 'proxies'
204
+ ? dataString.length < 4
205
+ ? ''
206
+ : "let state = onChange(".concat(dataString, ", () => state = state)")
207
+ : dataString, !json.hooks.onMount
208
+ ? ''
209
+ : "onMount(() => { ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.hooks.onMount, {
178
210
  includeState: useOptions.stateType === 'variables',
179
- });
180
- },
181
- });
182
- var functionsString = get_state_object_string_1.getStateObjectStringFromComponent(json, {
183
- data: false,
184
- getters: false,
185
- functions: true,
186
- format: 'variables',
187
- keyPrefix: 'function ',
188
- valueMapper: function (code) {
189
- return strip_state_and_props_refs_1.stripStateAndPropsRefs(code, {
211
+ }), " });"), !json.hooks.onUnMount
212
+ ? ''
213
+ : "onDestroy(() => { ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.hooks.onUnMount, {
190
214
  includeState: useOptions.stateType === 'variables',
191
- });
192
- },
193
- });
194
- var hasData = dataString.length > 4;
195
- var props = Array.from(get_props_1.getProps(json));
196
- var str = dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <script>\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 ",
197
- "\n ",
198
- "\n\n ", "\n ", "\n\n ",
199
- "\n\n ",
200
- "\n\n ",
201
- "\n </script>\n\n ", "\n\n ",
202
- "\n "])), !json.hooks.onMount ? '' : "import { onMount } from 'svelte'", !json.hooks.onUnMount ? '' : "import { onDestroy } from 'svelte'", render_imports_1.renderPreComponent(json), !hasData || useOptions.stateType === 'variables'
203
- ? ''
204
- : "import onChange from 'on-change'", refs
205
- .concat(props)
206
- .map(function (name) { return "export let " + name + ";"; })
207
- .join('\n'), functionsString.length < 4 ? '' : functionsString, getterString.length < 4 ? '' : getterString, useOptions.stateType === 'proxies'
208
- ? dataString.length < 4
215
+ }), " });"), json.children.map(function (item) { return (0, exports.blockToSvelte)(item, useOptions); }).join('\n'), !css.trim().length
209
216
  ? ''
210
- : "let state = onChange(" + dataString + ", () => state = state)"
211
- : dataString, !json.hooks.onMount
212
- ? ''
213
- : "onMount(() => { " + strip_state_and_props_refs_1.stripStateAndPropsRefs(json.hooks.onMount, {
214
- includeState: useOptions.stateType === 'variables',
215
- }) + " });", !json.hooks.onUnMount
216
- ? ''
217
- : "onDestroy(() => { " + strip_state_and_props_refs_1.stripStateAndPropsRefs(json.hooks.onUnMount, {
218
- includeState: useOptions.stateType === 'variables',
219
- }) + " });", json.children.map(function (item) { return exports.blockToSvelte(item, useOptions); }).join('\n'), !css.trim().length
220
- ? ''
221
- : "<style>\n " + css + "\n </style>");
222
- if (useOptions.plugins) {
223
- str = plugins_1.runPreCodePlugins(str, useOptions.plugins);
224
- }
225
- if (useOptions.prettier !== false) {
226
- try {
227
- str = standalone_1.format(str, {
228
- parser: 'svelte',
229
- plugins: [
230
- // To support running in browsers
231
- require('prettier/parser-html'),
232
- require('prettier/parser-postcss'),
233
- require('prettier/parser-babel'),
234
- require('prettier/parser-typescript'),
235
- require('prettier-plugin-svelte'),
236
- ],
237
- });
217
+ : "<style>\n ".concat(css, "\n </style>"));
218
+ if (useOptions.plugins) {
219
+ str = (0, plugins_1.runPreCodePlugins)(str, useOptions.plugins);
238
220
  }
239
- catch (err) {
240
- console.warn('Could not prettify', { string: str }, err);
221
+ if (useOptions.prettier !== false) {
222
+ try {
223
+ str = (0, standalone_1.format)(str, {
224
+ parser: 'svelte',
225
+ plugins: [
226
+ // To support running in browsers
227
+ require('prettier/parser-html'),
228
+ require('prettier/parser-postcss'),
229
+ require('prettier/parser-babel'),
230
+ require('prettier/parser-typescript'),
231
+ require('prettier-plugin-svelte'),
232
+ ],
233
+ });
234
+ }
235
+ catch (err) {
236
+ console.warn('Could not prettify', { string: str }, err);
237
+ }
241
238
  }
242
- }
243
- if (useOptions.plugins) {
244
- str = plugins_1.runPostCodePlugins(str, useOptions.plugins);
245
- }
246
- return str;
239
+ if (useOptions.plugins) {
240
+ str = (0, plugins_1.runPostCodePlugins)(str, useOptions.plugins);
241
+ }
242
+ return str;
243
+ };
247
244
  };
248
245
  exports.componentToSvelte = componentToSvelte;
249
246
  var templateObject_1;
@@ -1,5 +1,5 @@
1
- import { MitosisComponent } from '../types/mitosis-component';
1
+ import { Transpiler } from '..';
2
2
  export declare type ToSwiftOptions = {
3
3
  prettier?: boolean;
4
4
  };
5
- export declare const componentToSwift: (componentJson: MitosisComponent, options?: ToSwiftOptions) => string;
5
+ export declare const componentToSwift: (options?: ToSwiftOptions) => Transpiler;