@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,100 +1,117 @@
1
1
  "use strict";
2
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
- return cooked;
5
- };
6
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
7
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
8
4
  };
9
5
  Object.defineProperty(exports, "__esModule", { value: true });
10
6
  exports.generateCompositionApiScript = void 0;
11
- var dedent_1 = require("../../helpers/dedent");
12
- var get_state_object_string_1 = require("../../helpers/get-state-object-string");
13
- var json5_1 = __importDefault(require("json5"));
14
- var lodash_1 = require("lodash");
15
- var helpers_1 = require("./helpers");
16
- var getCompositionPropDefinition = function (_a) {
17
- var options = _a.options, component = _a.component, props = _a.props;
18
- var isTs = options.typescript;
19
- var str = 'const props = ';
7
+ const dedent_1 = require("../../helpers/dedent");
8
+ const get_state_object_string_1 = require("../../helpers/get-state-object-string");
9
+ const json5_1 = __importDefault(require("json5"));
10
+ const lodash_1 = require("lodash");
11
+ const helpers_1 = require("./helpers");
12
+ const getCompositionPropDefinition = ({ options, component, props, }) => {
13
+ const isTs = options.typescript;
14
+ let str = 'const props = ';
20
15
  if (component.defaultProps) {
21
- var generic = isTs ? "<".concat(component.propsTypeRef, ">") : '';
22
- var defalutPropsString = props
23
- .map(function (prop) {
16
+ const generic = isTs ? `<${component.propsTypeRef}>` : '';
17
+ const defalutPropsString = props
18
+ .map((prop) => {
24
19
  var _a;
25
- var value = component.defaultProps.hasOwnProperty(prop)
20
+ const value = component.defaultProps.hasOwnProperty(prop)
26
21
  ? (_a = component.defaultProps[prop]) === null || _a === void 0 ? void 0 : _a.code
27
22
  : 'undefined';
28
- return "".concat(prop, ": ").concat(value);
23
+ return `${prop}: ${value}`;
29
24
  })
30
25
  .join(',');
31
- str += "withDefaults(defineProps".concat(generic, "(), {").concat(defalutPropsString, "})");
26
+ str += `withDefaults(defineProps${generic}(), {${defalutPropsString}})`;
32
27
  }
33
28
  else if (isTs && component.propsTypeRef && component.propsTypeRef !== 'any') {
34
- str += "defineProps<".concat(component.propsTypeRef, ">()");
29
+ str += `defineProps<${component.propsTypeRef}>()`;
35
30
  }
36
31
  else {
37
- str += "defineProps(".concat(json5_1.default.stringify(props), ")");
32
+ str += `defineProps(${json5_1.default.stringify(props)})`;
38
33
  }
39
34
  return str;
40
35
  };
41
36
  function generateCompositionApiScript(component, options, template, props, onUpdateWithDeps, onUpdateWithoutDeps) {
42
37
  var _a, _b, _c, _d, _e, _f;
43
- var isTs = options.typescript;
44
- var refs = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
38
+ const isTs = options.typescript;
39
+ let refs = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
45
40
  data: true,
46
41
  functions: false,
47
42
  getters: false,
48
43
  format: 'variables',
49
- valueMapper: function (code, _, typeParameter) {
50
- return isTs && typeParameter ? "ref<".concat(typeParameter, ">(").concat(code, ")") : "ref(".concat(code, ")");
51
- },
44
+ valueMapper: (code, _, typeParameter) => isTs && typeParameter ? `ref<${typeParameter}>(${code})` : `ref(${code})`,
52
45
  keyPrefix: 'const',
53
46
  });
54
- var methods = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
47
+ let methods = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
55
48
  data: false,
56
49
  getters: false,
57
50
  functions: true,
58
51
  format: 'variables',
59
52
  });
60
53
  if (template.includes('_classStringToObject')) {
61
- methods += " function _classStringToObject(str".concat(isTs ? ': string' : '', ") {\n const obj").concat(isTs ? ': Record<string, boolean>' : '', " = {};\n if (typeof str !== 'string') { return obj }\n const classNames = str.trim().split(/\\s+/);\n for (const name of classNames) {\n obj[name] = true;\n }\n return obj;\n } ");
54
+ methods += ` function _classStringToObject(str${isTs ? ': string' : ''}) {
55
+ const obj${isTs ? ': Record<string, boolean>' : ''} = {};
56
+ if (typeof str !== 'string') { return obj }
57
+ const classNames = str.trim().split(/\\s+/);
58
+ for (const name of classNames) {
59
+ obj[name] = true;
60
+ }
61
+ return obj;
62
+ } `;
62
63
  }
63
- var getterKeys = Object.keys((0, lodash_1.pickBy)(component.state, function (i) { return (i === null || i === void 0 ? void 0 : i.type) === 'getter'; }));
64
- var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n ", "\n "], ["\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n ", "\n "])), props.length ? getCompositionPropDefinition({ component: component, props: props, options: options }) : '', refs, (_a = Object.entries(component.context.get)) === null || _a === void 0 ? void 0 : _a.map(function (_a) {
65
- var key = _a[0], context = _a[1];
66
- return "const ".concat(key, " = inject(").concat((0, helpers_1.getContextKey)(context), ")");
67
- }).join('\n'), (_b = Object.values(component.context.set)) === null || _b === void 0 ? void 0 : _b.map(function (contextSet) {
68
- var contextValue = (0, helpers_1.getContextValue)(contextSet);
69
- var key = (0, helpers_1.getContextKey)(contextSet);
70
- return "provide(".concat(key, ", ").concat(contextValue, ")");
71
- }).join('\n'), (_c = Object.keys(component.refs)) === null || _c === void 0 ? void 0 : _c.map(function (key) {
64
+ const getterKeys = Object.keys((0, lodash_1.pickBy)(component.state, (i) => (i === null || i === void 0 ? void 0 : i.type) === 'getter'));
65
+ let str = (0, dedent_1.dedent) `
66
+ ${props.length ? getCompositionPropDefinition({ component, props, options }) : ''}
67
+ ${refs}
68
+
69
+ ${(_a = Object.entries(component.context.get)) === null || _a === void 0 ? void 0 : _a.map(([key, context]) => {
70
+ return `const ${key} = inject(${(0, helpers_1.getContextKey)(context)})`;
71
+ }).join('\n')}
72
+
73
+ ${(_b = Object.values(component.context.set)) === null || _b === void 0 ? void 0 : _b.map((contextSet) => {
74
+ const contextValue = (0, helpers_1.getContextValue)(contextSet);
75
+ const key = (0, helpers_1.getContextKey)(contextSet);
76
+ return `provide(${key}, ${contextValue})`;
77
+ }).join('\n')}
78
+
79
+ ${(_c = Object.keys(component.refs)) === null || _c === void 0 ? void 0 : _c.map((key) => {
72
80
  if (isTs) {
73
- return "const ".concat(key, " = ref<").concat(component.refs[key].typeParameter, ">()");
81
+ return `const ${key} = ref<${component.refs[key].typeParameter}>()`;
74
82
  }
75
83
  else {
76
- return "const ".concat(key, " = ref(null)");
84
+ return `const ${key} = ref(null)`;
77
85
  }
78
- }).join('\n'), (_e = (_d = component.hooks.onInit) === null || _d === void 0 ? void 0 : _d.code) !== null && _e !== void 0 ? _e : '', component.hooks.onMount.map(function (hook) { return "onMounted(() => { ".concat(hook.code, " })"); }).join('\n'), !((_f = component.hooks.onUnMount) === null || _f === void 0 ? void 0 : _f.code)
86
+ }).join('\n')}
87
+ ${(_e = (_d = component.hooks.onInit) === null || _d === void 0 ? void 0 : _d.code) !== null && _e !== void 0 ? _e : ''}
88
+ ${component.hooks.onMount.map((hook) => `onMounted(() => { ${hook.code} })`).join('\n')}
89
+ ${!((_f = component.hooks.onUnMount) === null || _f === void 0 ? void 0 : _f.code)
79
90
  ? ''
80
- : "onUnmounted(() => { ".concat(component.hooks.onUnMount.code, "})"), (getterKeys === null || getterKeys === void 0 ? void 0 : getterKeys.map(function (key) {
91
+ : `onUnmounted(() => { ${component.hooks.onUnMount.code}})`}
92
+ ${(getterKeys === null || getterKeys === void 0 ? void 0 : getterKeys.map((key) => {
81
93
  var _a, _b;
82
- var code = (_b = (_a = component.state[key]) === null || _a === void 0 ? void 0 : _a.code) === null || _b === void 0 ? void 0 : _b.toString();
94
+ const code = (_b = (_a = component.state[key]) === null || _a === void 0 ? void 0 : _a.code) === null || _b === void 0 ? void 0 : _b.toString();
83
95
  if (!code) {
84
96
  return '';
85
97
  }
86
98
  // transform `foo() { return this.bar }` to `() => { return bar.value }`
87
- var getterAsFunction = code.replace(key, '').trim().replace(/^\(\)/, '() =>');
88
- var computedCode = "const ".concat(key, " = computed(").concat(getterAsFunction, ")");
99
+ const getterAsFunction = code.replace(key, '').trim().replace(/^\(\)/, '() =>');
100
+ const computedCode = `const ${key} = computed(${getterAsFunction})`;
89
101
  return computedCode;
90
- }).join('\n')) || '', (onUpdateWithoutDeps === null || onUpdateWithoutDeps === void 0 ? void 0 : onUpdateWithoutDeps.map(function (hook) { return "onUpdated(() => {".concat(hook.code, "})"); }).join('\n')) || '', (onUpdateWithDeps === null || onUpdateWithDeps === void 0 ? void 0 : onUpdateWithDeps.map(function (hook) {
91
- return "watch(() => ".concat((0, helpers_1.processBinding)({
102
+ }).join('\n')) || ''}
103
+
104
+ ${(onUpdateWithoutDeps === null || onUpdateWithoutDeps === void 0 ? void 0 : onUpdateWithoutDeps.map((hook) => `onUpdated(() => {${hook.code}})`).join('\n')) || ''}
105
+
106
+ ${(onUpdateWithDeps === null || onUpdateWithDeps === void 0 ? void 0 : onUpdateWithDeps.map((hook) => {
107
+ return `watch(() => ${(0, helpers_1.processBinding)({
92
108
  code: hook.deps || '',
93
- options: options,
109
+ options,
94
110
  json: component,
95
- }), ", () => { ").concat(hook.code, " }, {immediate: true})");
96
- }).join('\n')) || '', methods !== null && methods !== void 0 ? methods : '');
111
+ })}, () => { ${hook.code} }, {immediate: true})`;
112
+ }).join('\n')) || ''}
113
+ ${methods !== null && methods !== void 0 ? methods : ''}
114
+ `;
97
115
  return str;
98
116
  }
99
117
  exports.generateCompositionApiScript = generateCompositionApiScript;
100
- var templateObject_1;
@@ -1,82 +1,66 @@
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
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
- if (ar || !(i in from)) {
16
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
- ar[i] = from[i];
18
- }
19
- }
20
- return to.concat(ar || Array.prototype.slice.call(from));
21
- };
22
2
  Object.defineProperty(exports, "__esModule", { value: true });
23
3
  exports.getContextKey = exports.checkIfContextHasStrName = exports.getContextValue = exports.processBinding = exports.getContextNames = exports.renameMitosisComponentsToKebabCase = exports.mapMitosisComponentToKebabCase = exports.encodeQuotes = exports.invertBooleanExpression = exports.getOnUpdateHookName = exports.addBindingsToJson = exports.addPropertiesToJson = void 0;
24
- var babel_transform_1 = require("../../helpers/babel-transform");
25
- var get_state_object_string_1 = require("../../helpers/get-state-object-string");
26
- var patterns_1 = require("../../helpers/patterns");
27
- var replace_identifiers_1 = require("../../helpers/replace-identifiers");
28
- var slots_1 = require("../../helpers/slots");
29
- var core_1 = require("@babel/core");
30
- var function_1 = require("fp-ts/lib/function");
31
- var lodash_1 = require("lodash");
32
- var html_tags_1 = require("../../constants/html_tags");
33
- var addPropertiesToJson = function (properties) {
34
- return function (json) { return (__assign(__assign({}, json), { properties: __assign(__assign({}, json.properties), properties) })); };
35
- };
4
+ const babel_transform_1 = require("../../helpers/babel-transform");
5
+ const get_state_object_string_1 = require("../../helpers/get-state-object-string");
6
+ const patterns_1 = require("../../helpers/patterns");
7
+ const replace_identifiers_1 = require("../../helpers/replace-identifiers");
8
+ const slots_1 = require("../../helpers/slots");
9
+ const core_1 = require("@babel/core");
10
+ const function_1 = require("fp-ts/lib/function");
11
+ const lodash_1 = require("lodash");
12
+ const html_tags_1 = require("../../constants/html_tags");
13
+ const addPropertiesToJson = (properties) => (json) => ({
14
+ ...json,
15
+ properties: {
16
+ ...json.properties,
17
+ ...properties,
18
+ },
19
+ });
36
20
  exports.addPropertiesToJson = addPropertiesToJson;
37
- var addBindingsToJson = function (bindings) {
38
- return function (json) { return (__assign(__assign({}, json), { bindings: __assign(__assign({}, json.bindings), bindings) })); };
39
- };
21
+ const addBindingsToJson = (bindings) => (json) => ({
22
+ ...json,
23
+ bindings: {
24
+ ...json.bindings,
25
+ ...bindings,
26
+ },
27
+ });
40
28
  exports.addBindingsToJson = addBindingsToJson;
41
- var ON_UPDATE_HOOK_NAME = 'onUpdateHook';
42
- var getOnUpdateHookName = function (index) { return ON_UPDATE_HOOK_NAME + "".concat(index); };
29
+ const ON_UPDATE_HOOK_NAME = 'onUpdateHook';
30
+ const getOnUpdateHookName = (index) => ON_UPDATE_HOOK_NAME + `${index}`;
43
31
  exports.getOnUpdateHookName = getOnUpdateHookName;
44
- var invertBooleanExpression = function (expression) { return "!Boolean(".concat(expression, ")"); };
32
+ const invertBooleanExpression = (expression) => `!Boolean(${expression})`;
45
33
  exports.invertBooleanExpression = invertBooleanExpression;
46
34
  function encodeQuotes(string) {
47
35
  return string.replace(/"/g, '&quot;');
48
36
  }
49
37
  exports.encodeQuotes = encodeQuotes;
50
- var mapMitosisComponentToKebabCase = function (componentName) {
51
- return componentName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
52
- };
38
+ const mapMitosisComponentToKebabCase = (componentName) => componentName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
53
39
  exports.mapMitosisComponentToKebabCase = mapMitosisComponentToKebabCase;
54
40
  // Transform <FooBar> to <foo-bar> as Vue2 needs
55
- var renameMitosisComponentsToKebabCase = function (str) {
56
- return str.replace(/<\/?\w+/g, function (match) {
57
- var tagName = match.replaceAll('<', '').replaceAll('/', '');
58
- if (html_tags_1.VALID_HTML_TAGS.includes(tagName)) {
59
- return match;
60
- }
61
- else {
62
- return (0, exports.mapMitosisComponentToKebabCase)(match);
63
- }
64
- });
65
- };
41
+ const renameMitosisComponentsToKebabCase = (str) => str.replace(/<\/?\w+/g, (match) => {
42
+ const tagName = match.replaceAll('<', '').replaceAll('/', '');
43
+ if (html_tags_1.VALID_HTML_TAGS.includes(tagName)) {
44
+ return match;
45
+ }
46
+ else {
47
+ return (0, exports.mapMitosisComponentToKebabCase)(match);
48
+ }
49
+ });
66
50
  exports.renameMitosisComponentsToKebabCase = renameMitosisComponentsToKebabCase;
67
51
  function getContextNames(json) {
68
52
  return Object.keys(json.context.get);
69
53
  }
70
54
  exports.getContextNames = getContextNames;
71
55
  function shouldAppendValueToRef(path) {
72
- var parent = path.parent, node = path.node;
56
+ const { parent, node } = path;
73
57
  if (core_1.types.isFunctionDeclaration(parent) && parent.id === node) {
74
58
  return false;
75
59
  }
76
60
  if (core_1.types.isCallExpression(parent)) {
77
61
  return false;
78
62
  }
79
- var isMemberExpression = core_1.types.isMemberExpression(parent);
63
+ const isMemberExpression = core_1.types.isMemberExpression(parent);
80
64
  if (isMemberExpression &&
81
65
  core_1.types.isThisExpression(parent.object) &&
82
66
  core_1.types.isProgram(path.scope.block) &&
@@ -97,20 +81,19 @@ function shouldAppendValueToRef(path) {
97
81
  }
98
82
  return true;
99
83
  }
100
- var getAllRefs = function (component) {
101
- var refKeys = Object.keys(component.refs);
102
- var stateKeys = Object.keys((0, lodash_1.pickBy)(component.state, function (i) { return (i === null || i === void 0 ? void 0 : i.type) === 'property'; }));
103
- var allKeys = __spreadArray(__spreadArray([], refKeys, true), stateKeys, true);
84
+ const getAllRefs = (component) => {
85
+ const refKeys = Object.keys(component.refs);
86
+ const stateKeys = Object.keys((0, lodash_1.pickBy)(component.state, (i) => (i === null || i === void 0 ? void 0 : i.type) === 'property'));
87
+ const allKeys = [...refKeys, ...stateKeys];
104
88
  return allKeys;
105
89
  };
106
- function processRefs(_a) {
107
- var input = _a.input, component = _a.component, options = _a.options, thisPrefix = _a.thisPrefix;
108
- var refs = options.api === 'options' ? getContextNames(component) : getAllRefs(component);
90
+ function processRefs({ input, component, options, thisPrefix, }) {
91
+ const refs = options.api === 'options' ? getContextNames(component) : getAllRefs(component);
109
92
  return (0, babel_transform_1.babelTransformExpression)(input, {
110
- Identifier: function (path) {
111
- var name = path.node.name;
93
+ Identifier(path) {
94
+ const name = path.node.name;
112
95
  if (refs.includes(name) && shouldAppendValueToRef(path)) {
113
- var newValue = options.api === 'options' ? "".concat(thisPrefix, ".").concat(name) : "".concat(name, ".value");
96
+ const newValue = options.api === 'options' ? `${thisPrefix}.${name}` : `${name}.value`;
114
97
  path.replaceWith(core_1.types.identifier(newValue));
115
98
  }
116
99
  },
@@ -118,54 +101,47 @@ function processRefs(_a) {
118
101
  }
119
102
  function prefixMethodsWithThis(input, component, options) {
120
103
  if (options.api === 'options') {
121
- var allMethodNames = Object.entries(component.state)
122
- .filter(function (_a) {
123
- var _key = _a[0], value = _a[1];
124
- return (value === null || value === void 0 ? void 0 : value.type) === 'function';
125
- })
126
- .map(function (_a) {
127
- var key = _a[0];
128
- return key;
129
- });
104
+ const allMethodNames = Object.entries(component.state)
105
+ .filter(([_key, value]) => (value === null || value === void 0 ? void 0 : value.type) === 'function')
106
+ .map(([key]) => key);
130
107
  if (!allMethodNames.length)
131
108
  return input;
132
- return (0, replace_identifiers_1.replaceIdentifiers)({ code: input, from: allMethodNames, to: function (name) { return "this.".concat(name); } });
109
+ return (0, replace_identifiers_1.replaceIdentifiers)({ code: input, from: allMethodNames, to: (name) => `this.${name}` });
133
110
  }
134
111
  else {
135
112
  return input;
136
113
  }
137
114
  }
138
115
  function optionsApiStateAndPropsReplace(name, thisPrefix, codeType) {
139
- var prefixToUse = codeType === 'bindings' ? '' : thisPrefix + '.';
116
+ const prefixToUse = codeType === 'bindings' ? '' : thisPrefix + '.';
140
117
  if (name === 'children' || name.startsWith('children.')) {
141
- return "".concat(prefixToUse, "$slots.default");
118
+ return `${prefixToUse}$slots.default`;
142
119
  }
143
120
  return (0, slots_1.isSlotProperty)(name)
144
- ? (0, slots_1.replaceSlotsInString)(name, function (x) { return "".concat(prefixToUse, "$slots.").concat(x); })
145
- : "".concat(prefixToUse).concat(name);
121
+ ? (0, slots_1.replaceSlotsInString)(name, (x) => `${prefixToUse}$slots.${x}`)
122
+ : `${prefixToUse}${name}`;
146
123
  }
147
124
  // TODO: migrate all stripStateAndPropsRefs to use this here
148
125
  // to properly replace context refs
149
- var processBinding = function (_a) {
150
- var code = _a.code, options = _a.options, json = _a.json, _b = _a.preserveGetter, preserveGetter = _b === void 0 ? false : _b, _c = _a.thisPrefix, thisPrefix = _c === void 0 ? 'this' : _c, codeType = _a.codeType;
126
+ const processBinding = ({ code, options, json, preserveGetter = false, thisPrefix = 'this', codeType, }) => {
151
127
  try {
152
- return (0, function_1.pipe)(code, (0, replace_identifiers_1.replacePropsIdentifier)(function (name) {
128
+ return (0, function_1.pipe)(code, (0, replace_identifiers_1.replacePropsIdentifier)((name) => {
153
129
  switch (options.api) {
154
130
  // keep pointing to `props.${value}`
155
131
  case 'composition':
156
- var slotPrefix_1 = codeType === 'bindings' ? '$slots' : 'useSlots()';
132
+ const slotPrefix = codeType === 'bindings' ? '$slots' : 'useSlots()';
157
133
  if (name === 'children' || name.startsWith('children.')) {
158
- return "".concat(slotPrefix_1, ".default");
134
+ return `${slotPrefix}.default`;
159
135
  }
160
136
  return (0, slots_1.isSlotProperty)(name)
161
- ? (0, slots_1.replaceSlotsInString)(name, function (x) { return "".concat(slotPrefix_1, ".").concat(x); })
137
+ ? (0, slots_1.replaceSlotsInString)(name, (x) => `${slotPrefix}.${x}`)
162
138
  : codeType === 'bindings'
163
139
  ? name
164
- : "props.".concat(name);
140
+ : `props.${name}`;
165
141
  case 'options':
166
142
  return optionsApiStateAndPropsReplace(name, thisPrefix, codeType);
167
143
  }
168
- }), (0, replace_identifiers_1.replaceStateIdentifier)(function (name) {
144
+ }), (0, replace_identifiers_1.replaceStateIdentifier)((name) => {
169
145
  switch (options.api) {
170
146
  case 'composition':
171
147
  return name;
@@ -174,29 +150,28 @@ var processBinding = function (_a) {
174
150
  }
175
151
  }), codeType === 'bindings'
176
152
  ? function_1.identity
177
- : (0, function_1.flow)(function (x) { return processRefs({ input: x, component: json, options: options, thisPrefix: thisPrefix }); }, function (x) { return prefixMethodsWithThis(x, json, options); }), preserveGetter === false ? patterns_1.stripGetter : function_1.identity);
153
+ : (0, function_1.flow)((x) => processRefs({ input: x, component: json, options, thisPrefix }), (x) => prefixMethodsWithThis(x, json, options)), preserveGetter === false ? patterns_1.stripGetter : function_1.identity);
178
154
  }
179
155
  catch (e) {
180
- console.error('could not process bindings in ', { code: code });
156
+ console.error('could not process bindings in ', { code });
181
157
  throw e;
182
158
  }
183
159
  };
184
160
  exports.processBinding = processBinding;
185
- var getContextValue = function (_a) {
186
- var name = _a.name, ref = _a.ref, value = _a.value;
187
- var valueStr = value ? (0, get_state_object_string_1.stringifyContextValue)(value) : ref;
161
+ const getContextValue = ({ name, ref, value }) => {
162
+ const valueStr = value ? (0, get_state_object_string_1.stringifyContextValue)(value) : ref;
188
163
  return valueStr;
189
164
  };
190
165
  exports.getContextValue = getContextValue;
191
- var checkIfContextHasStrName = function (context) {
166
+ const checkIfContextHasStrName = (context) => {
192
167
  // check if the name is wrapped in single or double quotes
193
- var isStrName = context.name.startsWith("'") || context.name.startsWith('"');
168
+ const isStrName = context.name.startsWith("'") || context.name.startsWith('"');
194
169
  return isStrName;
195
170
  };
196
171
  exports.checkIfContextHasStrName = checkIfContextHasStrName;
197
- var getContextKey = function (context) {
198
- var isStrName = (0, exports.checkIfContextHasStrName)(context);
199
- var key = isStrName ? context.name : "".concat(context.name, ".key");
172
+ const getContextKey = (context) => {
173
+ const isStrName = (0, exports.checkIfContextHasStrName)(context);
174
+ const key = isStrName ? context.name : `${context.name}.key`;
200
175
  return key;
201
176
  };
202
177
  exports.getContextKey = getContextKey;