@builder.io/mitosis 0.4.0 → 0.4.2

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 (196) hide show
  1. package/dist/src/constants/media-sizes.js +4 -5
  2. package/dist/src/generators/alpine/generate.js +114 -132
  3. package/dist/src/generators/alpine/render-mount-hook.js +8 -5
  4. package/dist/src/generators/alpine/render-update-hooks.js +13 -13
  5. package/dist/src/generators/angular/helpers.js +19 -9
  6. package/dist/src/generators/angular/index.js +599 -584
  7. package/dist/src/generators/builder.js +200 -165
  8. package/dist/src/generators/context/angular.js +32 -26
  9. package/dist/src/generators/context/helpers/context-with-symbol-key.js +25 -21
  10. package/dist/src/generators/context/qwik.js +21 -21
  11. package/dist/src/generators/context/react.js +22 -22
  12. package/dist/src/generators/context/rsc.js +20 -22
  13. package/dist/src/generators/context/solid.js +22 -22
  14. package/dist/src/generators/context/svelte.js +33 -28
  15. package/dist/src/generators/context/vue.js +1 -1
  16. package/dist/src/generators/helpers/context.js +6 -13
  17. package/dist/src/generators/helpers/functions.js +8 -8
  18. package/dist/src/generators/helpers/on-mount.js +9 -5
  19. package/dist/src/generators/helpers/rsc.js +7 -9
  20. package/dist/src/generators/html.js +995 -534
  21. package/dist/src/generators/liquid.js +81 -79
  22. package/dist/src/generators/lit/collect-class-string.js +10 -12
  23. package/dist/src/generators/lit/generate.js +204 -159
  24. package/dist/src/generators/marko/generate.js +193 -183
  25. package/dist/src/generators/minify.js +5 -9
  26. package/dist/src/generators/mitosis.js +135 -134
  27. package/dist/src/generators/qwik/component-generator.js +159 -154
  28. package/dist/src/generators/qwik/component.js +51 -81
  29. package/dist/src/generators/qwik/directives.js +68 -84
  30. package/dist/src/generators/qwik/helpers/add-prevent-default.js +6 -7
  31. package/dist/src/generators/qwik/helpers/convert-method-to-function.js +38 -38
  32. package/dist/src/generators/qwik/helpers/handlers.js +16 -25
  33. package/dist/src/generators/qwik/helpers/stable-inject.js +7 -8
  34. package/dist/src/generators/qwik/helpers/stable-serialize.js +7 -8
  35. package/dist/src/generators/qwik/helpers/state.js +36 -43
  36. package/dist/src/generators/qwik/helpers/styles.js +19 -40
  37. package/dist/src/generators/qwik/jsx.js +63 -75
  38. package/dist/src/generators/qwik/src-generator.js +134 -167
  39. package/dist/src/generators/react/blocks.js +122 -127
  40. package/dist/src/generators/react/generator.js +314 -259
  41. package/dist/src/generators/react/helpers.js +23 -28
  42. package/dist/src/generators/react/state.js +34 -51
  43. package/dist/src/generators/react-native/index.js +72 -84
  44. package/dist/src/generators/react-native/sanitize-react-native-block-styles.js +14 -26
  45. package/dist/src/generators/rsc.js +30 -36
  46. package/dist/src/generators/solid/blocks.js +46 -43
  47. package/dist/src/generators/solid/helpers/styles.js +11 -11
  48. package/dist/src/generators/solid/index.js +199 -190
  49. package/dist/src/generators/solid/state/helpers.js +76 -90
  50. package/dist/src/generators/solid/state/signals.js +30 -37
  51. package/dist/src/generators/solid/state/state.js +35 -48
  52. package/dist/src/generators/solid/state/store.js +40 -46
  53. package/dist/src/generators/stencil/collect-class-string.js +10 -12
  54. package/dist/src/generators/stencil/generate.js +158 -145
  55. package/dist/src/generators/svelte/blocks.js +146 -144
  56. package/dist/src/generators/svelte/helpers.js +10 -17
  57. package/dist/src/generators/svelte/svelte.js +321 -287
  58. package/dist/src/generators/swift-ui.js +162 -101
  59. package/dist/src/generators/taro.js +32 -36
  60. package/dist/src/generators/template.js +71 -74
  61. package/dist/src/generators/vue/blocks.js +116 -107
  62. package/dist/src/generators/vue/compositionApi.js +67 -50
  63. package/dist/src/generators/vue/helpers.js +71 -96
  64. package/dist/src/generators/vue/optionsApi.js +134 -105
  65. package/dist/src/generators/vue/vue.js +210 -207
  66. package/dist/src/helpers/babel-transform.js +40 -63
  67. package/dist/src/helpers/bindings.js +4 -12
  68. package/dist/src/helpers/camel-case.js +4 -5
  69. package/dist/src/helpers/capitalize.js +1 -1
  70. package/dist/src/helpers/component-file-extensions.js +23 -35
  71. package/dist/src/helpers/create-mitosis-component.js +22 -26
  72. package/dist/src/helpers/create-mitosis-context.js +5 -12
  73. package/dist/src/helpers/create-mitosis-node.js +10 -12
  74. package/dist/src/helpers/dash-case.js +2 -2
  75. package/dist/src/helpers/dedent.js +18 -22
  76. package/dist/src/helpers/event-handlers.js +1 -1
  77. package/dist/src/helpers/fast-clone.js +1 -1
  78. package/dist/src/helpers/filter-empty-text-nodes.js +2 -2
  79. package/dist/src/helpers/generic-format.js +7 -8
  80. package/dist/src/helpers/get-bindings.js +4 -4
  81. package/dist/src/helpers/get-components-used.js +3 -3
  82. package/dist/src/helpers/get-components.js +4 -4
  83. package/dist/src/helpers/get-custom-imports.js +10 -12
  84. package/dist/src/helpers/get-prop-functions.js +7 -8
  85. package/dist/src/helpers/get-props-ref.js +8 -8
  86. package/dist/src/helpers/get-props.js +12 -13
  87. package/dist/src/helpers/get-refs.js +4 -4
  88. package/dist/src/helpers/get-state-object-string.js +42 -61
  89. package/dist/src/helpers/get-state-used.js +7 -8
  90. package/dist/src/helpers/get-styles.js +6 -6
  91. package/dist/src/helpers/getters-to-functions.js +8 -12
  92. package/dist/src/helpers/handle-missing-state.js +3 -3
  93. package/dist/src/helpers/has-bindings-text.js +6 -6
  94. package/dist/src/helpers/has-component.js +4 -4
  95. package/dist/src/helpers/has-props.js +3 -3
  96. package/dist/src/helpers/has-stateful-dom.js +4 -4
  97. package/dist/src/helpers/has.js +3 -3
  98. package/dist/src/helpers/indent.js +2 -3
  99. package/dist/src/helpers/is-children.js +4 -5
  100. package/dist/src/helpers/is-component.js +1 -1
  101. package/dist/src/helpers/is-html-attribute.js +2 -11
  102. package/dist/src/helpers/is-mitosis-node.js +1 -1
  103. package/dist/src/helpers/is-root-text-node.js +1 -1
  104. package/dist/src/helpers/is-upper-case.js +1 -1
  105. package/dist/src/helpers/is-valid-attribute-name.js +1 -1
  106. package/dist/src/helpers/json.js +2 -2
  107. package/dist/src/helpers/map-refs.js +29 -40
  108. package/dist/src/helpers/merge-options.js +20 -31
  109. package/dist/src/helpers/mitosis-imports.js +5 -6
  110. package/dist/src/helpers/nodes/for.js +2 -3
  111. package/dist/src/helpers/nullable.js +1 -3
  112. package/dist/src/helpers/on-event.js +32 -36
  113. package/dist/src/helpers/output.js +4 -5
  114. package/dist/src/helpers/parse-node.js +13 -5
  115. package/dist/src/helpers/parsers.js +10 -14
  116. package/dist/src/helpers/patterns.js +6 -8
  117. package/dist/src/helpers/plugins/process-code/index.js +114 -120
  118. package/dist/src/helpers/plugins/process-signals.js +114 -125
  119. package/dist/src/helpers/plugins/process-target-blocks.js +18 -20
  120. package/dist/src/helpers/process-http-requests.js +8 -4
  121. package/dist/src/helpers/remove-surrounding-block.js +2 -2
  122. package/dist/src/helpers/render-imports.js +99 -111
  123. package/dist/src/helpers/replace-identifiers.js +40 -49
  124. package/dist/src/helpers/replace-new-lines-in-strings.js +3 -3
  125. package/dist/src/helpers/signals/signals.js +27 -35
  126. package/dist/src/helpers/slots.js +11 -20
  127. package/dist/src/helpers/state.js +1 -3
  128. package/dist/src/helpers/strip-meta-properties.js +6 -6
  129. package/dist/src/helpers/strip-state-and-props-refs.js +21 -32
  130. package/dist/src/helpers/styles/collect-css.js +39 -44
  131. package/dist/src/helpers/styles/collect-styled-components.js +30 -28
  132. package/dist/src/helpers/styles/helpers.js +23 -29
  133. package/dist/src/helpers/trace-reference-to-module-path.js +3 -4
  134. package/dist/src/helpers/transform-state-setters.js +16 -19
  135. package/dist/src/helpers/traverse-nodes.js +2 -2
  136. package/dist/src/helpers/try-prettier-format.js +3 -3
  137. package/dist/src/helpers/typescript-project.js +25 -25
  138. package/dist/src/helpers/typescript.js +1 -3
  139. package/dist/src/modules/plugins.js +20 -28
  140. package/dist/src/parsers/angular.js +49 -57
  141. package/dist/src/parsers/builder/builder.js +448 -343
  142. package/dist/src/parsers/builder/helpers.js +10 -10
  143. package/dist/src/parsers/context.js +15 -17
  144. package/dist/src/parsers/jsx/ast.js +11 -11
  145. package/dist/src/parsers/jsx/component-types.js +22 -32
  146. package/dist/src/parsers/jsx/context.js +12 -12
  147. package/dist/src/parsers/jsx/element-parser.js +43 -54
  148. package/dist/src/parsers/jsx/exports.js +12 -14
  149. package/dist/src/parsers/jsx/function-parser.js +108 -119
  150. package/dist/src/parsers/jsx/helpers.js +11 -13
  151. package/dist/src/parsers/jsx/hooks/helpers.js +14 -16
  152. package/dist/src/parsers/jsx/hooks/index.js +34 -44
  153. package/dist/src/parsers/jsx/hooks/use-target.js +27 -27
  154. package/dist/src/parsers/jsx/imports.js +7 -17
  155. package/dist/src/parsers/jsx/jsx.js +92 -91
  156. package/dist/src/parsers/jsx/props-types.js +8 -10
  157. package/dist/src/parsers/jsx/props.js +15 -23
  158. package/dist/src/parsers/jsx/signals.js +28 -29
  159. package/dist/src/parsers/jsx/state.d.ts +2 -4
  160. package/dist/src/parsers/jsx/state.js +59 -93
  161. package/dist/src/parsers/svelte/css/index.js +1 -1
  162. package/dist/src/parsers/svelte/helpers/bindings.js +18 -19
  163. package/dist/src/parsers/svelte/helpers/children.js +5 -6
  164. package/dist/src/parsers/svelte/helpers/expressions.js +7 -9
  165. package/dist/src/parsers/svelte/helpers/hooks.js +2 -2
  166. package/dist/src/parsers/svelte/helpers/post-process.js +49 -70
  167. package/dist/src/parsers/svelte/helpers/string.js +5 -5
  168. package/dist/src/parsers/svelte/html/actions.js +17 -10
  169. package/dist/src/parsers/svelte/html/each.js +11 -16
  170. package/dist/src/parsers/svelte/html/element.js +68 -78
  171. package/dist/src/parsers/svelte/html/fragment.js +3 -3
  172. package/dist/src/parsers/svelte/html/if-else.js +11 -18
  173. package/dist/src/parsers/svelte/html/index.js +14 -14
  174. package/dist/src/parsers/svelte/html/mustache-tag.js +5 -5
  175. package/dist/src/parsers/svelte/html/slot.js +5 -5
  176. package/dist/src/parsers/svelte/html/text.js +7 -14
  177. package/dist/src/parsers/svelte/index.js +23 -72
  178. package/dist/src/parsers/svelte/instance/context.js +17 -17
  179. package/dist/src/parsers/svelte/instance/expressions.js +2 -2
  180. package/dist/src/parsers/svelte/instance/functions.js +35 -30
  181. package/dist/src/parsers/svelte/instance/hooks.js +4 -5
  182. package/dist/src/parsers/svelte/instance/imports.js +11 -21
  183. package/dist/src/parsers/svelte/instance/index.js +22 -22
  184. package/dist/src/parsers/svelte/instance/properties.js +11 -23
  185. package/dist/src/parsers/svelte/instance/reactive.js +11 -11
  186. package/dist/src/parsers/svelte/instance/references.js +13 -13
  187. package/dist/src/parsers/svelte/instance/statements.js +3 -3
  188. package/dist/src/parsers/svelte/module/index.js +14 -26
  189. package/dist/src/parsers/svelte/typescript/index.js +27 -36
  190. package/dist/src/plugins/compile-away-builder-components.js +223 -156
  191. package/dist/src/plugins/compile-away-components.js +13 -21
  192. package/dist/src/plugins/map-styles.js +7 -7
  193. package/dist/src/symbols/symbol-processor.js +44 -62
  194. package/dist/src/targets.js +19 -19
  195. package/dist/src/types/mitosis-node.js +1 -1
  196. package/package.json +1 -1
@@ -1,25 +1,14 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
5
  Object.defineProperty(exports, "__esModule", { value: true });
17
6
  exports.processTagReferences = exports.wrapInFragment = exports.getFragment = exports.closeFrag = exports.openFrag = exports.processBinding = void 0;
18
- var is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
19
- var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
20
- var lodash_1 = require("lodash");
21
- var legacy_1 = __importDefault(require("neotraverse/legacy"));
22
- var processBinding = function (str, options) {
7
+ const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
8
+ const strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
9
+ const lodash_1 = require("lodash");
10
+ const legacy_1 = __importDefault(require("neotraverse/legacy"));
11
+ const processBinding = (str, options) => {
23
12
  // fix web-component tag transform issue with dashes by not transforming it
24
13
  if (options.stateType !== 'useState') {
25
14
  return str;
@@ -30,35 +19,41 @@ var processBinding = function (str, options) {
30
19
  });
31
20
  };
32
21
  exports.processBinding = processBinding;
33
- var openFrag = function (options) { return getFragment('open', options); };
22
+ const openFrag = (options) => getFragment('open', options);
34
23
  exports.openFrag = openFrag;
35
- var closeFrag = function (options) { return getFragment('close', options); };
24
+ const closeFrag = (options) => getFragment('close', options);
36
25
  exports.closeFrag = closeFrag;
37
26
  function getFragment(type, options) {
38
- var tagName = options.preact ? 'Fragment' : '';
39
- return type === 'open' ? "<".concat(tagName, ">") : "</".concat(tagName, ">");
27
+ const tagName = options.preact ? 'Fragment' : '';
28
+ return type === 'open' ? `<${tagName}>` : `</${tagName}>`;
40
29
  }
41
30
  exports.getFragment = getFragment;
42
- var wrapInFragment = function (json) { return json.children.length !== 1; };
31
+ const wrapInFragment = (json) => json.children.length !== 1;
43
32
  exports.wrapInFragment = wrapInFragment;
44
33
  function getRefName(path) {
45
34
  return (0, lodash_1.upperFirst)(path) + 'Ref';
46
35
  }
47
36
  function processTagReferences(json, options) {
48
- var namesFound = new Set();
49
- (0, legacy_1.default)(json).forEach(function (el) {
37
+ const namesFound = new Set();
38
+ (0, legacy_1.default)(json).forEach((el) => {
50
39
  var _a, _b;
51
40
  if (!(0, is_mitosis_node_1.isMitosisNode)(el)) {
52
41
  return;
53
42
  }
54
- var processedRefName = el.name.includes('-') ? el.name : (0, exports.processBinding)(el.name, options);
43
+ const processedRefName = el.name.includes('-') ? el.name : (0, exports.processBinding)(el.name, options);
55
44
  if (el.name.includes('state.')) {
56
45
  switch ((_a = json.state[processedRefName]) === null || _a === void 0 ? void 0 : _a.type) {
57
46
  case 'getter':
58
- var refName = getRefName(processedRefName);
47
+ const refName = getRefName(processedRefName);
59
48
  if (!namesFound.has(el.name)) {
60
49
  namesFound.add(el.name);
61
- json.hooks.init = __assign(__assign({}, json.hooks.init), { code: "\n ".concat(((_b = json.hooks.init) === null || _b === void 0 ? void 0 : _b.code) || '', "\n const ").concat(refName, " = ").concat(el.name, ";\n ") });
50
+ json.hooks.init = {
51
+ ...json.hooks.init,
52
+ code: `
53
+ ${((_b = json.hooks.init) === null || _b === void 0 ? void 0 : _b.code) || ''}
54
+ const ${refName} = ${el.name};
55
+ `,
56
+ };
62
57
  }
63
58
  el.name = refName;
64
59
  break;
@@ -67,10 +62,10 @@ function processTagReferences(json, options) {
67
62
  case 'method':
68
63
  case 'function':
69
64
  case 'property':
70
- var capitalizedName = (0, lodash_1.upperFirst)(processedRefName);
65
+ const capitalizedName = (0, lodash_1.upperFirst)(processedRefName);
71
66
  if (capitalizedName !== processedRefName) {
72
67
  el.name = capitalizedName;
73
- json.state[capitalizedName] = __assign({}, json.state[processedRefName]);
68
+ json.state[capitalizedName] = { ...json.state[processedRefName] };
74
69
  delete json.state[processedRefName];
75
70
  }
76
71
  else {
@@ -1,59 +1,42 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
5
  Object.defineProperty(exports, "__esModule", { value: true });
17
6
  exports.updateStateSettersInCode = exports.updateStateSetters = exports.getUseStateCode = exports.processHookCode = void 0;
18
- var capitalize_1 = require("../../helpers/capitalize");
19
- var is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
20
- var patterns_1 = require("../../helpers/patterns");
21
- var transform_state_setters_1 = require("../../helpers/transform-state-setters");
22
- var core_1 = require("@babel/core");
23
- var function_1 = require("fp-ts/lib/function");
24
- var legacy_1 = __importDefault(require("neotraverse/legacy"));
25
- var helpers_1 = require("./helpers");
7
+ const capitalize_1 = require("../../helpers/capitalize");
8
+ const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
9
+ const patterns_1 = require("../../helpers/patterns");
10
+ const transform_state_setters_1 = require("../../helpers/transform-state-setters");
11
+ const core_1 = require("@babel/core");
12
+ const function_1 = require("fp-ts/lib/function");
13
+ const legacy_1 = __importDefault(require("neotraverse/legacy"));
14
+ const helpers_1 = require("./helpers");
26
15
  /**
27
16
  * Removes all `this.` references.
28
17
  */
29
- var stripThisRefs = function (str, options) {
18
+ const stripThisRefs = (str, options) => {
30
19
  if (options.stateType !== 'useState') {
31
20
  return str;
32
21
  }
33
22
  return str.replace(/this\.([a-zA-Z_\$0-9]+)/g, '$1');
34
23
  };
35
- var processHookCode = function (_a) {
36
- var str = _a.str, options = _a.options;
37
- return (0, helpers_1.processBinding)((0, exports.updateStateSettersInCode)(str, options), options);
38
- };
24
+ const processHookCode = ({ str, options }) => (0, helpers_1.processBinding)((0, exports.updateStateSettersInCode)(str, options), options);
39
25
  exports.processHookCode = processHookCode;
40
- var valueMapper = function (options) { return function (val) {
41
- var x = (0, exports.processHookCode)({ str: val, options: options });
26
+ const valueMapper = (options) => (val) => {
27
+ const x = (0, exports.processHookCode)({ str: val, options });
42
28
  return stripThisRefs(x, options);
43
- }; };
44
- var getSetStateFnName = function (stateName) { return "set".concat((0, capitalize_1.capitalize)(stateName)); };
45
- var processStateValue = function (options) {
46
- var mapValue = valueMapper(options);
47
- return function (_a) {
48
- var key = _a[0], stateVal = _a[1];
29
+ };
30
+ const getSetStateFnName = (stateName) => `set${(0, capitalize_1.capitalize)(stateName)}`;
31
+ const processStateValue = (options) => {
32
+ const mapValue = valueMapper(options);
33
+ return ([key, stateVal]) => {
49
34
  if (!stateVal) {
50
35
  return '';
51
36
  }
52
- var getDefaultCase = function () {
53
- return "const [".concat(key, ", ").concat(getSetStateFnName(key), "] = useState(() => (").concat(mapValue(value), "))");
54
- };
55
- var value = stateVal.code || '';
56
- var type = stateVal.type;
37
+ const getDefaultCase = () => `const [${key}, ${getSetStateFnName(key)}] = useState(() => (${mapValue(value)}))`;
38
+ const value = stateVal.code || '';
39
+ const type = stateVal.type;
57
40
  if (typeof value === 'string') {
58
41
  switch (type) {
59
42
  case 'getter':
@@ -71,39 +54,39 @@ var processStateValue = function (options) {
71
54
  }
72
55
  };
73
56
  };
74
- var getUseStateCode = function (json, options) {
75
- var lineItemDelimiter = '\n\n\n';
76
- var stringifiedState = Object.entries(json.state).map(processStateValue(options));
57
+ const getUseStateCode = (json, options) => {
58
+ const lineItemDelimiter = '\n\n\n';
59
+ const stringifiedState = Object.entries(json.state).map(processStateValue(options));
77
60
  return stringifiedState.join(lineItemDelimiter);
78
61
  };
79
62
  exports.getUseStateCode = getUseStateCode;
80
- var updateStateSetters = function (json, options) {
63
+ const updateStateSetters = (json, options) => {
81
64
  if (options.stateType !== 'useState') {
82
65
  return;
83
66
  }
84
67
  (0, legacy_1.default)(json).forEach(function (item) {
85
68
  if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
86
- for (var key in item.bindings) {
87
- var values = item.bindings[key];
88
- var newValue = (0, exports.updateStateSettersInCode)(values === null || values === void 0 ? void 0 : values.code, options);
69
+ for (const key in item.bindings) {
70
+ let values = item.bindings[key];
71
+ const newValue = (0, exports.updateStateSettersInCode)(values === null || values === void 0 ? void 0 : values.code, options);
89
72
  if (newValue !== (values === null || values === void 0 ? void 0 : values.code)) {
90
- item.bindings[key] = __assign(__assign({}, values), { code: newValue });
73
+ item.bindings[key] = {
74
+ ...values,
75
+ code: newValue,
76
+ };
91
77
  }
92
78
  }
93
79
  }
94
80
  });
95
81
  };
96
82
  exports.updateStateSetters = updateStateSetters;
97
- var updateStateSettersInCode = function (value, options) {
83
+ const updateStateSettersInCode = (value, options) => {
98
84
  if (options.stateType !== 'useState') {
99
85
  return value;
100
86
  }
101
87
  return (0, transform_state_setters_1.transformStateSetters)({
102
- value: value,
103
- transformer: function (_a) {
104
- var path = _a.path, propertyName = _a.propertyName;
105
- return core_1.types.callExpression(core_1.types.identifier(getSetStateFnName(propertyName)), [path.node.right]);
106
- },
88
+ value,
89
+ transformer: ({ path, propertyName }) => core_1.types.callExpression(core_1.types.identifier(getSetStateFnName(propertyName)), [path.node.right]),
107
90
  });
108
91
  };
109
92
  exports.updateStateSettersInCode = updateStateSettersInCode;
@@ -1,69 +1,58 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
5
  Object.defineProperty(exports, "__esModule", { value: true });
17
6
  exports.componentToReactNative = exports.collectReactNativeStyles = void 0;
18
- var bindings_1 = require("../../helpers/bindings");
19
- var fast_clone_1 = require("../../helpers/fast-clone");
20
- var is_children_1 = __importDefault(require("../../helpers/is-children"));
21
- var is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
22
- var merge_options_1 = require("../../helpers/merge-options");
23
- var json5_1 = __importDefault(require("json5"));
24
- var lodash_1 = require("lodash");
25
- var legacy_1 = __importDefault(require("neotraverse/legacy"));
26
- var html_tags_1 = require("../../constants/html_tags");
27
- var react_1 = require("../react");
28
- var sanitize_react_native_block_styles_1 = require("./sanitize-react-native-block-styles");
29
- var stylePropertiesThatMustBeNumber = new Set(['lineHeight']);
30
- var MEDIA_QUERY_KEY_REGEX = /^@media.*/;
31
- var sanitizeStyle = function (obj) { return function (key, value) {
32
- var propertyValue = obj[key];
7
+ const bindings_1 = require("../../helpers/bindings");
8
+ const fast_clone_1 = require("../../helpers/fast-clone");
9
+ const is_children_1 = __importDefault(require("../../helpers/is-children"));
10
+ const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
11
+ const merge_options_1 = require("../../helpers/merge-options");
12
+ const json5_1 = __importDefault(require("json5"));
13
+ const lodash_1 = require("lodash");
14
+ const legacy_1 = __importDefault(require("neotraverse/legacy"));
15
+ const html_tags_1 = require("../../constants/html_tags");
16
+ const react_1 = require("../react");
17
+ const sanitize_react_native_block_styles_1 = require("./sanitize-react-native-block-styles");
18
+ const stylePropertiesThatMustBeNumber = new Set(['lineHeight']);
19
+ const MEDIA_QUERY_KEY_REGEX = /^@media.*/;
20
+ const sanitizeStyle = (obj) => (key, value) => {
21
+ const propertyValue = obj[key];
33
22
  if (key.match(MEDIA_QUERY_KEY_REGEX)) {
34
23
  console.warn('Unsupported: skipping media queries for react-native: ', key, propertyValue);
35
24
  delete obj[key];
36
25
  return;
37
26
  }
38
- }; };
39
- var collectReactNativeStyles = function (json) {
40
- var styleMap = {};
41
- var componentIndexes = {};
42
- var getStyleSheetName = function (item) {
43
- var componentName = (0, lodash_1.camelCase)(item.name || 'view');
27
+ };
28
+ const collectReactNativeStyles = (json) => {
29
+ const styleMap = {};
30
+ const componentIndexes = {};
31
+ const getStyleSheetName = (item) => {
32
+ const componentName = (0, lodash_1.camelCase)(item.name || 'view');
44
33
  // If we have already seen this component name, we will increment the index. Otherwise, we will set the index to 1.
45
- var index = (componentIndexes[componentName] = (componentIndexes[componentName] || 0) + 1);
46
- return "".concat(componentName).concat(index);
34
+ const index = (componentIndexes[componentName] = (componentIndexes[componentName] || 0) + 1);
35
+ return `${componentName}${index}`;
47
36
  };
48
37
  (0, legacy_1.default)(json).forEach(function (item) {
49
38
  var _a, _b, _c;
50
39
  if (!(0, is_mitosis_node_1.isMitosisNode)(item)) {
51
40
  return;
52
41
  }
53
- var cssValue = json5_1.default.parse(((_a = item.bindings.css) === null || _a === void 0 ? void 0 : _a.code) || '{}');
42
+ let cssValue = json5_1.default.parse(((_a = item.bindings.css) === null || _a === void 0 ? void 0 : _a.code) || '{}');
54
43
  delete item.bindings.css;
55
44
  if ((0, lodash_1.size)(cssValue)) {
56
45
  // Style properties like `"20px"` need to be numbers like `20` for react native
57
- for (var key in cssValue) {
46
+ for (const key in cssValue) {
58
47
  sanitizeStyle(cssValue)(key, cssValue[key]);
59
48
  cssValue = (0, sanitize_react_native_block_styles_1.sanitizeReactNativeBlockStyles)(cssValue);
60
49
  }
61
50
  }
62
51
  try {
63
- var styleValue = json5_1.default.parse(((_b = item.bindings.style) === null || _b === void 0 ? void 0 : _b.code) || '{}');
52
+ let styleValue = json5_1.default.parse(((_b = item.bindings.style) === null || _b === void 0 ? void 0 : _b.code) || '{}');
64
53
  if ((0, lodash_1.size)(styleValue)) {
65
54
  // Style properties like `"20px"` need to be numbers like `20` for react native
66
- for (var key in styleValue) {
55
+ for (const key in styleValue) {
67
56
  sanitizeStyle(styleValue)(key, styleValue[key]);
68
57
  styleValue = (0, sanitize_react_native_block_styles_1.sanitizeReactNativeBlockStyles)(styleValue);
69
58
  }
@@ -74,8 +63,8 @@ var collectReactNativeStyles = function (json) {
74
63
  if (!(0, lodash_1.size)(cssValue)) {
75
64
  return;
76
65
  }
77
- var styleSheetName = getStyleSheetName(item);
78
- var styleSheetAccess = "styles.".concat(styleSheetName);
66
+ const styleSheetName = getStyleSheetName(item);
67
+ const styleSheetAccess = `styles.${styleSheetName}`;
79
68
  styleMap[styleSheetName] = cssValue;
80
69
  if (!item.bindings.style) {
81
70
  item.bindings.style = (0, bindings_1.createSingleBinding)({
@@ -87,13 +76,16 @@ var collectReactNativeStyles = function (json) {
87
76
  // run the code below only if the style binding is a JSON object
88
77
  json5_1.default.parse(item.bindings.style.code || '{}');
89
78
  item.bindings.style = (0, bindings_1.createSingleBinding)({
90
- code: ((_c = item.bindings.style) === null || _c === void 0 ? void 0 : _c.code.replace(/}$/, ", ...".concat(styleSheetAccess, " }"))) || styleSheetAccess,
79
+ code: ((_c = item.bindings.style) === null || _c === void 0 ? void 0 : _c.code.replace(/}$/, `, ...${styleSheetAccess} }`)) || styleSheetAccess,
91
80
  });
92
81
  }
93
82
  catch (e) {
94
83
  // if not a JSON, then it's a property, so we should spread it.
95
84
  item.bindings.style = (0, bindings_1.createSingleBinding)({
96
- code: "{\n ...".concat(styleSheetAccess, ",\n ...").concat(item.bindings.style.code, "\n }"),
85
+ code: `{
86
+ ...${styleSheetAccess},
87
+ ...${item.bindings.style.code}
88
+ }`,
97
89
  });
98
90
  }
99
91
  });
@@ -104,14 +96,14 @@ exports.collectReactNativeStyles = collectReactNativeStyles;
104
96
  * Plugin that handles necessary transformations from React to React Native:
105
97
  * - Converts DOM tags to <View /> and <Text />
106
98
  */
107
- var PROCESS_REACT_NATIVE_PLUGIN = function () { return ({
99
+ const PROCESS_REACT_NATIVE_PLUGIN = () => ({
108
100
  json: {
109
- pre: function (json) {
110
- (0, legacy_1.default)(json).forEach(function (node) {
101
+ pre: (json) => {
102
+ (0, legacy_1.default)(json).forEach((node) => {
111
103
  var _a, _b, _c, _d;
112
104
  if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
113
105
  // TODO: handle TextInput, Image, etc
114
- if ((0, is_children_1.default)({ node: node })) {
106
+ if ((0, is_children_1.default)({ node })) {
115
107
  node.name = '';
116
108
  }
117
109
  else if (node.name.toLowerCase() === node.name && html_tags_1.VALID_HTML_TAGS.includes(node.name)) {
@@ -143,13 +135,13 @@ var PROCESS_REACT_NATIVE_PLUGIN = function () { return ({
143
135
  });
144
136
  },
145
137
  },
146
- }); };
138
+ });
147
139
  /**
148
140
  * Removes React Native className and class properties from the JSON
149
141
  */
150
- var REMOVE_REACT_NATIVE_CLASSES_PLUGIN = function () { return ({
142
+ const REMOVE_REACT_NATIVE_CLASSES_PLUGIN = () => ({
151
143
  json: {
152
- pre: function (json) {
144
+ pre: (json) => {
153
145
  (0, legacy_1.default)(json).forEach(function (node) {
154
146
  if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
155
147
  if (node.properties.class) {
@@ -168,41 +160,41 @@ var REMOVE_REACT_NATIVE_CLASSES_PLUGIN = function () { return ({
168
160
  });
169
161
  },
170
162
  },
171
- }); };
163
+ });
172
164
  /**
173
165
  * Converts class and className properties to twrnc style syntax
174
166
  */
175
- var TWRNC_STYLES_PLUGIN = function () { return ({
167
+ const TWRNC_STYLES_PLUGIN = () => ({
176
168
  json: {
177
- post: function (json) {
169
+ post: (json) => {
178
170
  (0, legacy_1.default)(json).forEach(function (node) {
179
171
  if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
180
- var staticClasses = [node.properties.class, node.properties.className]
172
+ let staticClasses = [node.properties.class, node.properties.className]
181
173
  .filter(Boolean)
182
174
  .join(' ');
183
- var dynamicClasses = [node.bindings.class, node.bindings.className].filter(Boolean);
175
+ let dynamicClasses = [node.bindings.class, node.bindings.className].filter(Boolean);
184
176
  if (staticClasses || dynamicClasses.length) {
185
- var styleCode = '';
177
+ let styleCode = '';
186
178
  if (staticClasses) {
187
- styleCode = "tw`".concat(staticClasses, "`");
179
+ styleCode = `tw\`${staticClasses}\``;
188
180
  }
189
181
  if (dynamicClasses.length) {
190
- var dynamicCode = dynamicClasses
191
- .map(function (dc) { return (dc && dc.code ? dc.code : null); })
182
+ let dynamicCode = dynamicClasses
183
+ .map((dc) => (dc && dc.code ? dc.code : null))
192
184
  .filter(Boolean)
193
185
  .join(', ');
194
186
  if (dynamicCode) {
195
187
  if (styleCode) {
196
188
  // If we have both static and dynamic classes
197
- styleCode = "tw.style(".concat(styleCode, ", ").concat(dynamicCode, ")");
189
+ styleCode = `tw.style(${styleCode}, ${dynamicCode})`;
198
190
  }
199
191
  else if (dynamicClasses.length > 1) {
200
192
  // If we have multiple dynamic classes
201
- styleCode = "tw.style([".concat(dynamicCode, "])");
193
+ styleCode = `tw.style([${dynamicCode}])`;
202
194
  }
203
195
  else {
204
196
  // If we have a single dynamic class
205
- styleCode = "tw.style(".concat(dynamicCode, ")");
197
+ styleCode = `tw.style(${dynamicCode})`;
206
198
  }
207
199
  }
208
200
  }
@@ -219,17 +211,17 @@ var TWRNC_STYLES_PLUGIN = function () { return ({
219
211
  });
220
212
  },
221
213
  },
222
- }); };
214
+ });
223
215
  /**
224
216
  * Converts class and className properties to native-wind style syntax
225
217
  * Note: We only support the "with babel" setup: https://www.nativewind.dev/guides/babel
226
218
  */
227
- var NATIVE_WIND_STYLES_PLUGIN = function () { return ({
219
+ const NATIVE_WIND_STYLES_PLUGIN = () => ({
228
220
  json: {
229
- post: function (json) {
221
+ post: (json) => {
230
222
  (0, legacy_1.default)(json).forEach(function (node) {
231
223
  if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
232
- var combinedClasses = [
224
+ let combinedClasses = [
233
225
  node.properties.class,
234
226
  node.properties.className,
235
227
  node.bindings.class,
@@ -256,28 +248,24 @@ var NATIVE_WIND_STYLES_PLUGIN = function () { return ({
256
248
  });
257
249
  },
258
250
  },
259
- }); };
260
- var DEFAULT_OPTIONS = {
251
+ });
252
+ const DEFAULT_OPTIONS = {
261
253
  stateType: 'useState',
262
254
  stylesType: 'react-native',
263
255
  plugins: [PROCESS_REACT_NATIVE_PLUGIN],
264
256
  };
265
- var componentToReactNative = function (_options) {
266
- if (_options === void 0) { _options = {}; }
267
- return function (_a) {
268
- var component = _a.component, path = _a.path;
269
- var json = (0, fast_clone_1.fastClone)(component);
270
- var options = (0, merge_options_1.mergeOptions)(DEFAULT_OPTIONS, _options);
271
- if (options.stylesType === 'twrnc') {
272
- options.plugins.push(TWRNC_STYLES_PLUGIN);
273
- }
274
- else if (options.stylesType === 'native-wind') {
275
- options.plugins.push(NATIVE_WIND_STYLES_PLUGIN);
276
- }
277
- else {
278
- options.plugins.push(REMOVE_REACT_NATIVE_CLASSES_PLUGIN);
279
- }
280
- return (0, react_1.componentToReact)(__assign(__assign({}, options), { type: 'native' }))({ component: json, path: path });
281
- };
257
+ const componentToReactNative = (_options = {}) => ({ component, path }) => {
258
+ const json = (0, fast_clone_1.fastClone)(component);
259
+ const options = (0, merge_options_1.mergeOptions)(DEFAULT_OPTIONS, _options);
260
+ if (options.stylesType === 'twrnc') {
261
+ options.plugins.push(TWRNC_STYLES_PLUGIN);
262
+ }
263
+ else if (options.stylesType === 'native-wind') {
264
+ options.plugins.push(NATIVE_WIND_STYLES_PLUGIN);
265
+ }
266
+ else {
267
+ options.plugins.push(REMOVE_REACT_NATIVE_CLASSES_PLUGIN);
268
+ }
269
+ return (0, react_1.componentToReact)({ ...options, type: 'native' })({ component: json, path });
282
270
  };
283
271
  exports.componentToReactNative = componentToReactNative;
@@ -1,20 +1,9 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.sanitizeReactNativeBlockStyles = void 0;
15
- var propertiesThatMustBeNumber = new Set(['lineHeight']);
16
- var displayValues = new Set(['flex', 'none']);
17
- var normalizeNumber = function (value) {
4
+ const propertiesThatMustBeNumber = new Set(['lineHeight']);
5
+ const displayValues = new Set(['flex', 'none']);
6
+ const normalizeNumber = (value) => {
18
7
  if (Number.isNaN(value)) {
19
8
  return undefined;
20
9
  }
@@ -26,27 +15,26 @@ var normalizeNumber = function (value) {
26
15
  return value;
27
16
  }
28
17
  };
29
- var sanitizeReactNativeBlockStyles = function (styles) {
30
- return Object.keys(styles).reduce(function (acc, key) {
31
- var _a, _b, _c;
32
- var propertyValue = styles[key];
18
+ const sanitizeReactNativeBlockStyles = (styles) => {
19
+ return Object.keys(styles).reduce((acc, key) => {
20
+ const propertyValue = styles[key];
33
21
  if (key === 'display' && !displayValues.has(propertyValue)) {
34
- console.warn("Style value for key \"display\" must be \"flex\" or \"none\" but had ".concat(propertyValue));
22
+ console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
35
23
  return acc;
36
24
  }
37
25
  if (propertiesThatMustBeNumber.has(key) && typeof propertyValue !== 'number') {
38
- console.warn("Style key ".concat(key, " must be a number, but had value `").concat(styles[key], "`"));
26
+ console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
39
27
  return acc;
40
28
  }
41
29
  if (typeof propertyValue === 'string') {
42
30
  // `px` units need to be stripped and replaced with numbers
43
31
  // https://regexr.com/6ualn
44
- var isPixelUnit = propertyValue.match(/^-?(\d*)(\.?)(\d*)*px$/);
32
+ const isPixelUnit = propertyValue.match(/^-?(\d*)(\.?)(\d*)*px$/);
45
33
  if (isPixelUnit) {
46
- var newValue = parseFloat(propertyValue);
47
- var normalizedValue = normalizeNumber(newValue);
34
+ const newValue = parseFloat(propertyValue);
35
+ const normalizedValue = normalizeNumber(newValue);
48
36
  if (normalizedValue) {
49
- return __assign(__assign({}, acc), (_a = {}, _a[key] = normalizedValue, _a));
37
+ return { ...acc, [key]: normalizedValue };
50
38
  }
51
39
  else {
52
40
  return acc;
@@ -54,10 +42,10 @@ var sanitizeReactNativeBlockStyles = function (styles) {
54
42
  }
55
43
  else if (propertyValue === '0') {
56
44
  // 0 edge case needs to be handled
57
- return __assign(__assign({}, acc), (_b = {}, _b[key] = 0, _b));
45
+ return { ...acc, [key]: 0 };
58
46
  }
59
47
  }
60
- return __assign(__assign({}, acc), (_c = {}, _c[key] = propertyValue, _c));
48
+ return { ...acc, [key]: propertyValue };
61
49
  }, {});
62
50
  };
63
51
  exports.sanitizeReactNativeBlockStyles = sanitizeReactNativeBlockStyles;