@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
@@ -25,12 +25,12 @@ var stylePropertiesThatMustBeNumber = new Set(['lineHeight']);
25
25
  var collectReactNativeStyles = function (json) {
26
26
  var styleMap = {};
27
27
  var componentIndexes = {};
28
- traverse_1.default(json).forEach(function (item) {
29
- if (is_mitosis_node_1.isMitosisNode(item)) {
28
+ (0, traverse_1.default)(json).forEach(function (item) {
29
+ if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
30
30
  if (typeof item.bindings.css === 'string') {
31
31
  var value = json5_1.default.parse(item.bindings.css);
32
32
  delete item.bindings.css;
33
- if (!lodash_1.size(value)) {
33
+ if (!(0, lodash_1.size)(value)) {
34
34
  return;
35
35
  }
36
36
  // Style properties like `"20px"` need to be numbers like `20` for react native
@@ -44,15 +44,15 @@ var collectReactNativeStyles = function (json) {
44
44
  }
45
45
  if (stylePropertiesThatMustBeNumber.has(key) &&
46
46
  typeof value[key] !== 'number') {
47
- console.warn("Style key " + key + " must be a number, but had value `" + value[key] + "`");
47
+ console.warn("Style key ".concat(key, " must be a number, but had value `").concat(value[key], "`"));
48
48
  delete value[key];
49
49
  }
50
50
  }
51
- var componentName = lodash_1.camelCase(item.name || 'view');
51
+ var componentName = (0, lodash_1.camelCase)(item.name || 'view');
52
52
  var index = (componentIndexes[componentName] =
53
53
  (componentIndexes[componentName] || 0) + 1);
54
- var className = "" + componentName + index;
55
- item.bindings.style = "styles." + className;
54
+ var className = "".concat(componentName).concat(index);
55
+ item.bindings.style = "styles.".concat(className);
56
56
  styleMap[className] = value;
57
57
  }
58
58
  }
@@ -60,22 +60,25 @@ var collectReactNativeStyles = function (json) {
60
60
  return styleMap;
61
61
  };
62
62
  exports.collectReactNativeStyles = collectReactNativeStyles;
63
- var componentToReactNative = function (componentJson, options) {
63
+ var componentToReactNative = function (options) {
64
64
  if (options === void 0) { options = {}; }
65
- var json = fast_clone_1.fastClone(componentJson);
66
- traverse_1.default(json).forEach(function (node) {
67
- var _a, _b, _c;
68
- if (is_mitosis_node_1.isMitosisNode(node)) {
69
- // TODO: handle TextInput, Image, etc
70
- if (node.name.toLowerCase() === node.name) {
71
- node.name = 'View';
72
- }
73
- if (((_a = node.properties._text) === null || _a === void 0 ? void 0 : _a.trim().length) ||
74
- ((_c = (_b = node.bindings._text) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.length)) {
75
- node.name = 'Text';
65
+ return function (_a) {
66
+ var component = _a.component, path = _a.path;
67
+ var json = (0, fast_clone_1.fastClone)(component);
68
+ (0, traverse_1.default)(json).forEach(function (node) {
69
+ var _a, _b, _c;
70
+ if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
71
+ // TODO: handle TextInput, Image, etc
72
+ if (node.name.toLowerCase() === node.name) {
73
+ node.name = 'View';
74
+ }
75
+ if (((_a = node.properties._text) === null || _a === void 0 ? void 0 : _a.trim().length) ||
76
+ ((_c = (_b = node.bindings._text) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.length)) {
77
+ node.name = 'Text';
78
+ }
76
79
  }
77
- }
78
- });
79
- return react_1.componentToReact(json, __assign(__assign({}, options), { stylesType: options.stylesType || 'react-native', type: 'native' }));
80
+ });
81
+ return (0, react_1.componentToReact)(__assign(__assign({}, options), { stylesType: options.stylesType || 'react-native', type: 'native' }))({ component: json, path: path });
82
+ };
80
83
  };
81
84
  exports.componentToReactNative = componentToReactNative;
@@ -1,14 +1,10 @@
1
- import { Plugin } from '../modules/plugins';
2
- import { MitosisComponent } from '../types/mitosis-component';
1
+ import { BaseTranspilerOptions, Transpiler } from '../types/config';
3
2
  import { MitosisNode } from '../types/mitosis-node';
4
- declare type ToReactOptions = {
5
- prettier?: boolean;
3
+ export interface ToReactOptions extends BaseTranspilerOptions {
6
4
  stylesType?: 'emotion' | 'styled-components' | 'styled-jsx' | 'react-native';
7
5
  stateType?: 'useState' | 'mobx' | 'valtio' | 'solid' | 'builder';
8
6
  format?: 'lite' | 'safe';
9
7
  type?: 'dom' | 'native';
10
- plugins?: Plugin[];
11
- };
8
+ }
12
9
  export declare const blockToReact: (json: MitosisNode, options: ToReactOptions) => string;
13
- export declare const componentToReact: (componentJson: MitosisComponent, reactOptions?: ToReactOptions) => string;
14
- export {};
10
+ export declare const componentToReact: (reactOptions?: ToReactOptions) => Transpiler;
@@ -54,23 +54,23 @@ var wrapInFragment = function (json) {
54
54
  var NODE_MAPPERS = {
55
55
  Fragment: function (json, options) {
56
56
  var wrap = wrapInFragment(json);
57
- return "" + (wrap ? '<>' : '') + json.children
58
- .map(function (item) { return exports.blockToReact(item, options); })
59
- .join('\n') + (wrap ? '</>' : '');
57
+ return "".concat(wrap ? '<>' : '').concat(json.children
58
+ .map(function (item) { return (0, exports.blockToReact)(item, options); })
59
+ .join('\n')).concat(wrap ? '</>' : '');
60
60
  },
61
61
  For: function (json, options) {
62
62
  var wrap = wrapInFragment(json);
63
- return "{" + processBinding(json.bindings.each, options) + "?.map(" + json.properties._forName + " => (\n " + (wrap ? '<>' : '') + json.children
63
+ return "{".concat(processBinding(json.bindings.each, options), "?.map(").concat(json.properties._forName, " => (\n ").concat(wrap ? '<>' : '').concat(json.children
64
64
  .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
65
- .map(function (item) { return exports.blockToReact(item, options); })
66
- .join('\n') + (wrap ? '</>' : '') + "\n ))}";
65
+ .map(function (item) { return (0, exports.blockToReact)(item, options); })
66
+ .join('\n')).concat(wrap ? '</>' : '', "\n ))}");
67
67
  },
68
68
  Show: function (json, options) {
69
69
  var wrap = wrapInFragment(json);
70
- return "{" + processBinding(json.bindings.when, options) + " ? (\n " + (wrap ? '<>' : '') + json.children
70
+ return "{".concat(processBinding(json.bindings.when, options), " ? (\n ").concat(wrap ? '<>' : '').concat(json.children
71
71
  .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
72
- .map(function (item) { return exports.blockToReact(item, options); })
73
- .join('\n') + (wrap ? '</>' : '') + "\n ) : " + (!json.meta.else ? 'null' : exports.blockToReact(json.meta.else, options)) + "}";
72
+ .map(function (item) { return (0, exports.blockToReact)(item, options); })
73
+ .join('\n')).concat(wrap ? '</>' : '', "\n ) : ").concat(!json.meta.else ? 'null' : (0, exports.blockToReact)(json.meta.else, options), "}");
74
74
  },
75
75
  };
76
76
  // TODO: Maybe in the future allow defining `string | function` as values
@@ -89,42 +89,42 @@ var blockToReact = function (json, options) {
89
89
  if (json.properties._text) {
90
90
  var text = json.properties._text;
91
91
  if (options.type === 'native' && text.trim().length) {
92
- return "<Text>" + text + "</Text>";
92
+ return "<Text>".concat(text, "</Text>");
93
93
  }
94
94
  return text;
95
95
  }
96
96
  if (json.bindings._text) {
97
97
  var processed = processBinding(json.bindings._text, options);
98
98
  if (options.type === 'native') {
99
- return "<Text>{" + processed + "}</Text>";
99
+ return "<Text>{".concat(processed, "}</Text>");
100
100
  }
101
- return "{" + processed + "}";
101
+ return "{".concat(processed, "}");
102
102
  }
103
103
  var str = '';
104
- str += "<" + json.name + " ";
104
+ str += "<".concat(json.name, " ");
105
105
  if (json.bindings._spread) {
106
- str += " {...(" + processBinding(json.bindings._spread, options) + ")} ";
106
+ str += " {...(".concat(processBinding(json.bindings._spread, options), ")} ");
107
107
  }
108
108
  for (var key in json.properties) {
109
109
  var value = (json.properties[key] || '')
110
110
  .replace(/"/g, '&quot;')
111
111
  .replace(/\n/g, '\\n');
112
112
  if (key === 'class') {
113
- str += " className=\"" + value + "\" ";
113
+ str += " className=\"".concat(value, "\" ");
114
114
  }
115
115
  else if (BINDING_MAPPERS[key]) {
116
116
  var mapper = BINDING_MAPPERS[key];
117
117
  if (typeof mapper === 'function') {
118
118
  var _a = mapper(key, value), newKey = _a[0], newValue = _a[1];
119
- str += " " + newKey + "={" + newValue + "} ";
119
+ str += " ".concat(newKey, "={").concat(newValue, "} ");
120
120
  }
121
121
  else {
122
- str += " " + BINDING_MAPPERS[key] + "=\"" + value + "\" ";
122
+ str += " ".concat(BINDING_MAPPERS[key], "=\"").concat(value, "\" ");
123
123
  }
124
124
  }
125
125
  else {
126
- if (is_valid_attribute_name_1.isValidAttributeName(key)) {
127
- str += " " + key + "=\"" + value.replace(/"/g, '&quot;') + "\" ";
126
+ if ((0, is_valid_attribute_name_1.isValidAttributeName)(key)) {
127
+ str += " ".concat(key, "=\"").concat(value.replace(/"/g, '&quot;'), "\" ");
128
128
  }
129
129
  }
130
130
  }
@@ -138,24 +138,24 @@ var blockToReact = function (json, options) {
138
138
  }
139
139
  var useBindingValue = processBinding(value, options);
140
140
  if (key.startsWith('on')) {
141
- str += " " + key + "={event => " + updateStateSettersInCode(useBindingValue, options) + " } ";
141
+ str += " ".concat(key, "={event => ").concat(updateStateSettersInCode(useBindingValue, options), " } ");
142
142
  }
143
143
  else if (key === 'class') {
144
- str += " className={" + useBindingValue + "} ";
144
+ str += " className={".concat(useBindingValue, "} ");
145
145
  }
146
146
  else if (BINDING_MAPPERS[key]) {
147
147
  var mapper = BINDING_MAPPERS[key];
148
148
  if (typeof mapper === 'function') {
149
149
  var _b = mapper(key, useBindingValue), newKey = _b[0], newValue = _b[1];
150
- str += " " + newKey + "={" + newValue + "} ";
150
+ str += " ".concat(newKey, "={").concat(newValue, "} ");
151
151
  }
152
152
  else {
153
- str += " " + BINDING_MAPPERS[key] + "={" + useBindingValue + "} ";
153
+ str += " ".concat(BINDING_MAPPERS[key], "={").concat(useBindingValue, "} ");
154
154
  }
155
155
  }
156
156
  else {
157
- if (is_valid_attribute_name_1.isValidAttributeName(key)) {
158
- str += " " + key + "={" + useBindingValue + "} ";
157
+ if ((0, is_valid_attribute_name_1.isValidAttributeName)(key)) {
158
+ str += " ".concat(key, "={").concat(useBindingValue, "} ");
159
159
  }
160
160
  }
161
161
  }
@@ -169,17 +169,17 @@ var blockToReact = function (json, options) {
169
169
  }
170
170
  str += '>';
171
171
  if (json.children) {
172
- str += json.children.map(function (item) { return exports.blockToReact(item, options); }).join('\n');
172
+ str += json.children.map(function (item) { return (0, exports.blockToReact)(item, options); }).join('\n');
173
173
  }
174
- return str + ("</" + json.name + ">");
174
+ return str + "</".concat(json.name, ">");
175
175
  };
176
176
  exports.blockToReact = blockToReact;
177
177
  var getRefsString = function (json, refs) {
178
- if (refs === void 0) { refs = get_refs_1.getRefs(json); }
178
+ if (refs === void 0) { refs = (0, get_refs_1.getRefs)(json); }
179
179
  var str = '';
180
180
  for (var _i = 0, _a = Array.from(refs); _i < _a.length; _i++) {
181
181
  var ref = _a[_i];
182
- str += "\nconst " + ref + " = useRef();";
182
+ str += "\nconst ".concat(ref, " = useRef();");
183
183
  }
184
184
  return str;
185
185
  };
@@ -187,7 +187,7 @@ var processBinding = function (str, options) {
187
187
  if (options.stateType !== 'useState') {
188
188
  return str;
189
189
  }
190
- return strip_state_and_props_refs_1.stripStateAndPropsRefs(str, {
190
+ return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(str, {
191
191
  includeState: true,
192
192
  includeProps: false,
193
193
  });
@@ -205,19 +205,19 @@ var getUseStateCode = function (json, options) {
205
205
  if (typeof value === 'string') {
206
206
  if (value.startsWith(function_literal_prefix_1.functionLiteralPrefix)) {
207
207
  var useValue = value.replace(function_literal_prefix_1.functionLiteralPrefix, '');
208
- str += valueMapper(useValue) + " " + lineItemDelimiter;
208
+ str += "".concat(valueMapper(useValue), " ").concat(lineItemDelimiter);
209
209
  }
210
210
  else if (value.startsWith(method_literal_prefix_1.methodLiteralPrefix)) {
211
211
  var methodValue = value.replace(method_literal_prefix_1.methodLiteralPrefix, '');
212
212
  var useValue = methodValue.replace(/^(get )?/, 'function ');
213
- str += valueMapper(useValue) + " " + lineItemDelimiter;
213
+ str += "".concat(valueMapper(useValue), " ").concat(lineItemDelimiter);
214
214
  }
215
215
  else {
216
- str += "const [" + key + ", set" + capitalize_1.capitalize(key) + "] " + keyValueDelimiter + " useState(() => (" + valueMapper(json5_1.default.stringify(value)) + "))" + lineItemDelimiter + " ";
216
+ str += "const [".concat(key, ", set").concat((0, capitalize_1.capitalize)(key), "] ").concat(keyValueDelimiter, " useState(() => (").concat(valueMapper(json5_1.default.stringify(value)), "))").concat(lineItemDelimiter, " ");
217
217
  }
218
218
  }
219
219
  else {
220
- str += "const [" + key + ", set" + capitalize_1.capitalize(key) + "] " + keyValueDelimiter + " useState(() => (" + valueMapper(json5_1.default.stringify(value)) + "))" + lineItemDelimiter + " ";
220
+ str += "const [".concat(key, ", set").concat((0, capitalize_1.capitalize)(key), "] ").concat(keyValueDelimiter, " useState(() => (").concat(valueMapper(json5_1.default.stringify(value)), "))").concat(lineItemDelimiter, " ");
221
221
  }
222
222
  }
223
223
  return str;
@@ -226,8 +226,8 @@ var updateStateSetters = function (json, options) {
226
226
  if (options.stateType !== 'useState') {
227
227
  return;
228
228
  }
229
- traverse_1.default(json).forEach(function (item) {
230
- if (is_mitosis_node_1.isMitosisNode(item)) {
229
+ (0, traverse_1.default)(json).forEach(function (item) {
230
+ if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
231
231
  for (var key in item.bindings) {
232
232
  var value = item.bindings[key];
233
233
  var newValue = updateStateSettersInCode(value, options);
@@ -242,9 +242,9 @@ function addProviderComponents(json, options) {
242
242
  for (var key in json.context.set) {
243
243
  var _a = json.context.set[key], name_1 = _a.name, value = _a.value;
244
244
  json.children = [
245
- create_mitosis_node_1.createMitosisNode(__assign({ name: name_1 + ".Provider", children: json.children }, (value && {
245
+ (0, create_mitosis_node_1.createMitosisNode)(__assign({ name: "".concat(name_1, ".Provider"), children: json.children }, (value && {
246
246
  bindings: {
247
- value: get_state_object_string_1.getMemberObjectString(value),
247
+ value: (0, get_state_object_string_1.getMemberObjectString)(value),
248
248
  },
249
249
  }))),
250
250
  ];
@@ -254,7 +254,7 @@ var updateStateSettersInCode = function (value, options) {
254
254
  if (options.stateType !== 'useState') {
255
255
  return value;
256
256
  }
257
- return babel_transform_1.babelTransformExpression(value, {
257
+ return (0, babel_transform_1.babelTransformExpression)(value, {
258
258
  AssignmentExpression: function (path) {
259
259
  var node = path.node;
260
260
  if (core_1.types.isMemberExpression(node.left)) {
@@ -263,7 +263,7 @@ var updateStateSettersInCode = function (value, options) {
263
263
  if (node.left.object.name === 'state') {
264
264
  // TODO: ultimately support other property access like strings
265
265
  var propertyName = node.left.property.name;
266
- path.replaceWith(core_1.types.callExpression(core_1.types.identifier("set" + capitalize_1.capitalize(propertyName)), [node.right]));
266
+ path.replaceWith(core_1.types.callExpression(core_1.types.identifier("set".concat((0, capitalize_1.capitalize)(propertyName))), [node.right]));
267
267
  }
268
268
  }
269
269
  }
@@ -273,7 +273,7 @@ var updateStateSettersInCode = function (value, options) {
273
273
  function getContextString(component, options) {
274
274
  var str = '';
275
275
  for (var key in component.context.get) {
276
- str += "\n const " + key + " = useContext(" + component.context.get[key].name + ");\n ";
276
+ str += "\n const ".concat(key, " = useContext(").concat(component.context.get[key].name, ");\n ");
277
277
  }
278
278
  return str;
279
279
  }
@@ -284,59 +284,62 @@ function hasContext(component) {
284
284
  var getInitCode = function (json, options) {
285
285
  return processBinding(json.hooks.init || '', options);
286
286
  };
287
- var componentToReact = function (componentJson, reactOptions) {
287
+ var componentToReact = function (reactOptions) {
288
288
  if (reactOptions === void 0) { reactOptions = {}; }
289
- var json = fast_clone_1.fastClone(componentJson);
290
- var options = __assign({ stateType: 'useState', stylesType: 'styled-jsx' }, reactOptions);
291
- if (options.plugins) {
292
- json = plugins_1.runPreJsonPlugins(json, options.plugins);
293
- }
294
- var str = _componentToReact(json, options);
295
- str +=
296
- '\n\n\n' +
297
- json.subComponents
298
- .map(function (item) { return _componentToReact(item, options, true); })
299
- .join('\n\n\n');
300
- if (options.plugins) {
301
- str = plugins_1.runPreCodePlugins(str, options.plugins);
302
- }
303
- if (options.prettier !== false) {
304
- try {
305
- str = standalone_1.format(str, {
306
- parser: 'typescript',
307
- plugins: [
308
- require('prettier/parser-typescript'),
309
- require('prettier/parser-postcss'),
310
- ],
311
- })
312
- // Remove spaces between imports
313
- .replace(/;\n\nimport\s/g, ';\nimport ');
289
+ return function (_a) {
290
+ var component = _a.component;
291
+ var json = (0, fast_clone_1.fastClone)(component);
292
+ var options = __assign({ stateType: 'useState', stylesType: 'styled-jsx' }, reactOptions);
293
+ if (options.plugins) {
294
+ json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
314
295
  }
315
- catch (err) {
316
- console.error('Format error for file:', str, JSON.stringify(json, null, 2));
317
- throw err;
296
+ var str = _componentToReact(json, options);
297
+ str +=
298
+ '\n\n\n' +
299
+ json.subComponents
300
+ .map(function (item) { return _componentToReact(item, options, true); })
301
+ .join('\n\n\n');
302
+ if (options.plugins) {
303
+ str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
318
304
  }
319
- }
320
- if (options.plugins) {
321
- str = plugins_1.runPostCodePlugins(str, options.plugins);
322
- }
323
- return str;
305
+ if (options.prettier !== false) {
306
+ try {
307
+ str = (0, standalone_1.format)(str, {
308
+ parser: 'typescript',
309
+ plugins: [
310
+ require('prettier/parser-typescript'),
311
+ require('prettier/parser-postcss'),
312
+ ],
313
+ })
314
+ // Remove spaces between imports
315
+ .replace(/;\n\nimport\s/g, ';\nimport ');
316
+ }
317
+ catch (err) {
318
+ console.error('Format error for file:', str, JSON.stringify(json, null, 2));
319
+ throw err;
320
+ }
321
+ }
322
+ if (options.plugins) {
323
+ str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
324
+ }
325
+ return str;
326
+ };
324
327
  };
325
328
  exports.componentToReact = componentToReact;
326
329
  var _componentToReact = function (json, options, isSubComponent) {
327
330
  if (isSubComponent === void 0) { isSubComponent = false; }
328
- process_http_requests_1.processHttpRequests(json);
329
- handle_missing_state_1.handleMissingState(json);
330
- process_tag_references_1.processTagReferences(json);
331
+ (0, process_http_requests_1.processHttpRequests)(json);
332
+ (0, handle_missing_state_1.handleMissingState)(json);
333
+ (0, process_tag_references_1.processTagReferences)(json);
331
334
  addProviderComponents(json, options);
332
- var componentHasStyles = collect_styles_1.hasStyles(json);
335
+ var componentHasStyles = (0, collect_styles_1.hasStyles)(json);
333
336
  if (options.stateType === 'useState') {
334
- getters_to_functions_1.gettersToFunctions(json);
337
+ (0, getters_to_functions_1.gettersToFunctions)(json);
335
338
  updateStateSetters(json, options);
336
339
  }
337
- var refs = get_refs_1.getRefs(json);
340
+ var refs = (0, get_refs_1.getRefs)(json);
338
341
  var hasState = Boolean(Object.keys(json.state).length);
339
- map_refs_1.mapRefs(json, function (refName) { return refName + ".current"; });
342
+ (0, map_refs_1.mapRefs)(json, function (refName) { return "".concat(refName, ".current"); });
340
343
  var stylesType = options.stylesType || 'emotion';
341
344
  var stateType = options.stateType || 'mobx';
342
345
  if (stateType === 'builder') {
@@ -345,14 +348,14 @@ var _componentToReact = function (json, options, isSubComponent) {
345
348
  }
346
349
  var useStateCode = stateType === 'useState' && getUseStateCode(json, options);
347
350
  if (options.plugins) {
348
- json = plugins_1.runPostJsonPlugins(json, options.plugins);
351
+ json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
349
352
  }
350
- var css = stylesType === 'styled-jsx' && collect_styles_1.collectCss(json, { classProperty: 'class' });
353
+ var css = stylesType === 'styled-jsx' && (0, collect_styles_1.collectCss)(json, { classProperty: 'class' });
351
354
  var styledComponentsCode = stylesType === 'styled-components' &&
352
355
  componentHasStyles &&
353
- collect_styles_1.collectStyledComponents(json);
356
+ (0, collect_styles_1.collectStyledComponents)(json);
354
357
  if (options.format !== 'lite') {
355
- strip_meta_properties_1.stripMetaProperties(json);
358
+ (0, strip_meta_properties_1.stripMetaProperties)(json);
356
359
  }
357
360
  var reactLibImports = new Set();
358
361
  if (useStateCode && useStateCode.includes('useState')) {
@@ -370,23 +373,11 @@ var _componentToReact = function (json, options, isSubComponent) {
370
373
  var wrap = wrapInFragment(json) || (componentHasStyles && stylesType === 'styled-jsx');
371
374
  var nativeStyles = stylesType === 'react-native' &&
372
375
  componentHasStyles &&
373
- react_native_1.collectReactNativeStyles(json);
374
- var str = dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "function ", "(props) {\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }\n\n ", "\n\n ", "\n "], ["\n ",
375
- "\n ", "\n ",
376
- "\n ",
377
- "\n ",
378
- "\n ",
379
- "\n ",
380
- "\n ", "\n\n ", "function ",
381
- "(props) {\n ",
382
- "\n ", "\n ", "\n ", "\n\n ",
383
- "\n\n ",
384
- "\n\n return (\n ", "\n ", "\n ",
385
- "\n ", "\n );\n }\n\n ",
386
- "\n\n ", "\n "])), options.type !== 'native'
376
+ (0, react_native_1.collectReactNativeStyles)(json);
377
+ var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "function ", "(props) {\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }\n\n ", "\n\n ", "\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "function ", "(props) {\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }\n\n ", "\n\n ", "\n "])), options.type !== 'native'
387
378
  ? ''
388
379
  : "\n import * as React from 'react';\n import { View, StyleSheet, Image, Text } from 'react-native';\n ", styledComponentsCode ? "import styled from 'styled-components';\n" : '', reactLibImports.size
389
- ? "import { " + Array.from(reactLibImports).join(', ') + " } from 'react'"
380
+ ? "import { ".concat(Array.from(reactLibImports).join(', '), " } from 'react'")
390
381
  : '', componentHasStyles && stylesType === 'emotion' && options.format !== 'lite'
391
382
  ? "/** @jsx jsx */\n import { jsx } from '@emotion/react'".trim()
392
383
  : '', hasState && stateType === 'valtio'
@@ -395,27 +386,27 @@ var _componentToReact = function (json, options, isSubComponent) {
395
386
  ? "import { useMutable } from 'react-solid-state';"
396
387
  : '', stateType === 'mobx' && hasState
397
388
  ? "import { useLocalObservable } from 'mobx-react-lite';"
398
- : '', render_imports_1.renderPreComponent(json), isSubComponent ? '' : 'export default ', json.name ||
389
+ : '', (0, render_imports_1.renderPreComponent)(json), isSubComponent ? '' : 'export default ', json.name ||
399
390
  'MyComponent', hasState
400
391
  ? stateType === 'mobx'
401
- ? "const state = useLocalObservable(() => (" + get_state_object_string_1.getStateObjectStringFromComponent(json) + "));"
392
+ ? "const state = useLocalObservable(() => (".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), "));")
402
393
  : stateType === 'useState'
403
394
  ? useStateCode
404
395
  : stateType === 'solid'
405
- ? "const state = useMutable(" + get_state_object_string_1.getStateObjectStringFromComponent(json) + ");"
396
+ ? "const state = useMutable(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
406
397
  : stateType === 'builder'
407
- ? "var state = useBuilderState(" + get_state_object_string_1.getStateObjectStringFromComponent(json) + ");"
408
- : "const state = useLocalProxy(" + get_state_object_string_1.getStateObjectStringFromComponent(json) + ");"
398
+ ? "var state = useBuilderState(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
399
+ : "const state = useLocalProxy(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
409
400
  : '', getContextString(json, options), getRefsString(json), getInitCode(json, options), json.hooks.onMount
410
- ? "useEffect(() => {\n " + processBinding(updateStateSettersInCode(json.hooks.onMount, options), options) + "\n }, [])"
401
+ ? "useEffect(() => {\n ".concat(processBinding(updateStateSettersInCode(json.hooks.onMount, options), options), "\n }, [])")
411
402
  : '', json.hooks.onUnMount
412
- ? "useEffect(() => {\n " + processBinding(updateStateSettersInCode(json.hooks.onUnMount, options), options) + "\n }, [])"
413
- : '', wrap ? '<>' : '', json.children.map(function (item) { return exports.blockToReact(item, options); }).join('\n'), componentHasStyles && stylesType === 'styled-jsx'
414
- ? "<style jsx>{`" + css + "`}</style>"
403
+ ? "useEffect(() => {\n ".concat(processBinding(updateStateSettersInCode(json.hooks.onUnMount, options), options), "\n }, [])")
404
+ : '', wrap ? '<>' : '', json.children.map(function (item) { return (0, exports.blockToReact)(item, options); }).join('\n'), componentHasStyles && stylesType === 'styled-jsx'
405
+ ? "<style jsx>{`".concat(css, "`}</style>")
415
406
  : '', wrap ? '</>' : '', !nativeStyles
416
407
  ? ''
417
- : "\n const styles = StyleSheet.create(" + json5_1.default.stringify(nativeStyles) + ");\n ", styledComponentsCode ? styledComponentsCode : '');
418
- str = replace_new_lines_in_strings_1.stripNewlinesInStrings(str);
408
+ : "\n const styles = StyleSheet.create(".concat(json5_1.default.stringify(nativeStyles), ");\n "), styledComponentsCode ? styledComponentsCode : '');
409
+ str = (0, replace_new_lines_in_strings_1.stripNewlinesInStrings)(str);
419
410
  return str;
420
411
  };
421
412
  var templateObject_1;
@@ -1,8 +1,4 @@
1
- import { MitosisComponent } from '../types/mitosis-component';
2
- import { Plugin } from '../modules/plugins';
3
- declare type ToSolidOptions = {
4
- prettier?: boolean;
5
- plugins?: Plugin[];
6
- };
7
- export declare const componentToSolid: (componentJson: MitosisComponent, options?: ToSolidOptions) => string;
8
- export {};
1
+ import { BaseTranspilerOptions, Transpiler } from '../types/config';
2
+ export interface ToSolidOptions extends BaseTranspilerOptions {
3
+ }
4
+ export declare const componentToSolid: (options?: ToSolidOptions) => Transpiler;