@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,48 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findSignals = void 0;
4
- var ts_morph_1 = require("ts-morph");
5
- var typescript_project_1 = require("../../helpers/typescript-project");
6
- var MITOSIS_IMPORT_PATHS = [
4
+ const ts_morph_1 = require("ts-morph");
5
+ const typescript_project_1 = require("../../helpers/typescript-project");
6
+ const MITOSIS_IMPORT_PATHS = [
7
7
  // actual production path
8
8
  '/node_modules/@builder.io/mitosis/',
9
9
  // possible path if symlinking mitosis locally
10
10
  '/mitosis/packages/core/',
11
11
  ];
12
- var findSignals = function (_a) {
13
- var filePath = _a.filePath, project = _a.project;
14
- var ast = project.getSourceFileOrThrow(filePath);
12
+ const findSignals = ({ filePath, project }) => {
13
+ const ast = project.getSourceFileOrThrow(filePath);
15
14
  if (ast === undefined) {
16
15
  throw new Error('Could not find AST. Please provide a correct `filePath`.');
17
16
  }
18
- var reactiveValues = {
17
+ const reactiveValues = {
19
18
  props: new Set(),
20
19
  state: new Set(),
21
20
  context: new Set(),
22
21
  };
23
- var propsSymbol = (0, typescript_project_1.getPropsSymbol)(ast);
24
- var contextSymbols = (0, typescript_project_1.getContextSymbols)(ast);
25
- var checkIsSignalSymbol = function (type) {
22
+ const propsSymbol = (0, typescript_project_1.getPropsSymbol)(ast);
23
+ const contextSymbols = (0, typescript_project_1.getContextSymbols)(ast);
24
+ const checkIsSignalSymbol = (type) => {
26
25
  var _a;
27
- var symbol = (_a = type.getTargetType()) === null || _a === void 0 ? void 0 : _a.getAliasSymbol();
26
+ const symbol = (_a = type.getTargetType()) === null || _a === void 0 ? void 0 : _a.getAliasSymbol();
28
27
  if (!symbol || symbol.getName() !== 'Signal')
29
28
  return false;
30
- var compilerSymbol = symbol === null || symbol === void 0 ? void 0 : symbol.compilerSymbol;
31
- var parent = compilerSymbol.parent;
29
+ const compilerSymbol = symbol === null || symbol === void 0 ? void 0 : symbol.compilerSymbol;
30
+ const parent = compilerSymbol.parent;
32
31
  if (!parent)
33
32
  return false;
34
- if (MITOSIS_IMPORT_PATHS.some(function (path) { return parent.getName().includes(path); })) {
33
+ if (MITOSIS_IMPORT_PATHS.some((path) => parent.getName().includes(path))) {
35
34
  return true;
36
35
  }
37
36
  return false;
38
37
  };
39
- var checkIsOptionalSignal = function (node) {
40
- var hasUndefined = false;
41
- var hasSignal = false;
42
- var perfectMatch = node
38
+ const checkIsOptionalSignal = (node) => {
39
+ let hasUndefined = false;
40
+ let hasSignal = false;
41
+ const perfectMatch = node
43
42
  .getType()
44
43
  .getUnionTypes()
45
- .every(function (type) {
44
+ .every((type) => {
46
45
  if (type.isUndefined()) {
47
46
  hasUndefined = true;
48
47
  return true;
@@ -55,34 +54,34 @@ var findSignals = function (_a) {
55
54
  });
56
55
  return perfectMatch && hasUndefined && hasSignal;
57
56
  };
58
- ast.forEachDescendant(function (parentNode) {
57
+ ast.forEachDescendant((parentNode) => {
59
58
  if (ts_morph_1.Node.isPropertyAccessExpression(parentNode)) {
60
- var node = parentNode.getExpression();
61
- var isOptionalAccess = parentNode.hasQuestionDotToken();
62
- var isSignal = isOptionalAccess
59
+ const node = parentNode.getExpression();
60
+ const isOptionalAccess = parentNode.hasQuestionDotToken();
61
+ const isSignal = isOptionalAccess
63
62
  ? checkIsOptionalSignal(node)
64
63
  : checkIsSignalSymbol(node.getType());
65
64
  if (!isSignal)
66
65
  return;
67
- var isInsideType_1 = false;
68
- var isInsideDeclaration = false;
69
- node.getParentWhile(function (parent, child) {
66
+ let isInsideType = false;
67
+ let isInsideDeclaration = false;
68
+ node.getParentWhile((parent, child) => {
70
69
  // stop once we hit the function block
71
70
  if (ts_morph_1.Node.isBlock(child) || ts_morph_1.Node.isBlock(parent)) {
72
71
  return false;
73
72
  }
74
73
  // crawl up parents to make sure we're not inside a type
75
74
  if (ts_morph_1.Node.isTypeNode(parent) || ts_morph_1.Node.isTypeAliasDeclaration(parent)) {
76
- isInsideType_1 = true;
75
+ isInsideType = true;
77
76
  return false;
78
77
  }
79
78
  return true;
80
79
  });
81
- if (isInsideType_1)
80
+ if (isInsideType)
82
81
  return;
83
82
  if (isInsideDeclaration)
84
83
  return;
85
- var nodeSymbol = node.getSymbol();
84
+ const nodeSymbol = node.getSymbol();
86
85
  if (ts_morph_1.Node.isPropertyAccessExpression(node) &&
87
86
  node.getExpression().getSymbol() === propsSymbol) {
88
87
  reactiveValues.props.add(node.getNameNode().getText());
@@ -1,6 +1,5 @@
1
- import * as babel from '@babel/core';
2
1
  import { MitosisComponent, MitosisState } from '../../types/mitosis-component';
3
- declare const types: typeof babel.types;
2
+ import { ObjectExpression } from '@babel/types';
4
3
  /**
5
4
  * Convert state identifiers from React hooks format to the state.* format Mitosis needs
6
5
  * e.g.
@@ -8,5 +7,4 @@ declare const types: typeof babel.types;
8
7
  * setText(...) -> state.text = ...
9
8
  */
10
9
  export declare function mapStateIdentifiers(json: MitosisComponent): void;
11
- export declare const parseStateObjectToMitosisState: (object: babel.types.ObjectExpression, isState?: boolean) => MitosisState;
12
- export {};
10
+ export declare const parseStateObjectToMitosisState: (object: ObjectExpression, isState?: boolean) => MitosisState;
@@ -1,79 +1,44 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || function (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
36
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
4
  };
39
5
  Object.defineProperty(exports, "__esModule", { value: true });
40
6
  exports.parseStateObjectToMitosisState = exports.mapStateIdentifiers = void 0;
41
- var babel = __importStar(require("@babel/core"));
42
- var function_1 = require("fp-ts/lib/function");
43
- var legacy_1 = __importDefault(require("neotraverse/legacy"));
44
- var babel_transform_1 = require("../../helpers/babel-transform");
45
- var capitalize_1 = require("../../helpers/capitalize");
46
- var is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
47
- var process_code_1 = require("../../helpers/plugins/process-code");
48
- var helpers_1 = require("./helpers");
49
- var types = babel.types;
7
+ const babel_transform_1 = require("../../helpers/babel-transform");
8
+ const capitalize_1 = require("../../helpers/capitalize");
9
+ const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
10
+ const process_code_1 = require("../../helpers/plugins/process-code");
11
+ const types_1 = require("@babel/types");
12
+ const function_1 = require("fp-ts/lib/function");
13
+ const legacy_1 = __importDefault(require("neotraverse/legacy"));
14
+ const helpers_1 = require("./helpers");
50
15
  function mapStateIdentifiersInExpression(expression, stateProperties) {
51
- var setExpressions = stateProperties.map(function (propertyName) { return "set".concat((0, capitalize_1.capitalize)(propertyName)); });
16
+ const setExpressions = stateProperties.map((propertyName) => `set${(0, capitalize_1.capitalize)(propertyName)}`);
52
17
  return (0, function_1.pipe)((0, babel_transform_1.babelTransformExpression)(expression, {
53
- Identifier: function (path) {
18
+ Identifier(path) {
54
19
  if (stateProperties.includes(path.node.name)) {
55
20
  if (
56
21
  // ignore member expressions, as the `stateProperty` is going to be at the module scope.
57
- !(types.isMemberExpression(path.parent) && path.parent.property === path.node) &&
58
- !(types.isOptionalMemberExpression(path.parent) && path.parent.property === path.node) &&
22
+ !((0, types_1.isMemberExpression)(path.parent) && path.parent.property === path.node) &&
23
+ !((0, types_1.isOptionalMemberExpression)(path.parent) && path.parent.property === path.node) &&
59
24
  // ignore declarations of that state property, e.g. `function foo() {}`
60
- !types.isDeclaration(path.parent) &&
61
- !types.isFunctionDeclaration(path.parent) &&
62
- !(types.isFunctionExpression(path.parent) && path.parent.id === path.node) &&
25
+ !(0, types_1.isDeclaration)(path.parent) &&
26
+ !(0, types_1.isFunctionDeclaration)(path.parent) &&
27
+ !((0, types_1.isFunctionExpression)(path.parent) && path.parent.id === path.node) &&
63
28
  // ignore object keys
64
- !(types.isObjectProperty(path.parent) && path.parent.key === path.node)) {
65
- var hasTypeParent_1 = false;
66
- path.findParent(function (parent) {
67
- if (types.isTSType(parent) || types.isTSInterfaceBody(parent)) {
68
- hasTypeParent_1 = true;
29
+ !((0, types_1.isObjectProperty)(path.parent) && path.parent.key === path.node)) {
30
+ let hasTypeParent = false;
31
+ path.findParent((parent) => {
32
+ if ((0, types_1.isTSType)(parent) || (0, types_1.isTSInterfaceBody)(parent)) {
33
+ hasTypeParent = true;
69
34
  return true;
70
35
  }
71
36
  return false;
72
37
  });
73
- if (hasTypeParent_1) {
38
+ if (hasTypeParent) {
74
39
  return;
75
40
  }
76
- var newExpression = types.memberExpression(types.identifier('state'), types.identifier(path.node.name));
41
+ const newExpression = (0, types_1.memberExpression)((0, types_1.identifier)('state'), (0, types_1.identifier)(path.node.name));
77
42
  try {
78
43
  path.replaceWith(newExpression);
79
44
  }
@@ -89,19 +54,19 @@ function mapStateIdentifiersInExpression(expression, stateProperties) {
89
54
  }
90
55
  }
91
56
  },
92
- CallExpression: function (path) {
93
- if (types.isIdentifier(path.node.callee)) {
57
+ CallExpression(path) {
58
+ if ((0, types_1.isIdentifier)(path.node.callee)) {
94
59
  if (setExpressions.includes(path.node.callee.name)) {
95
60
  // setFoo -> foo
96
- var statePropertyName = (0, helpers_1.uncapitalize)(path.node.callee.name.slice(3));
61
+ const statePropertyName = (0, helpers_1.uncapitalize)(path.node.callee.name.slice(3));
97
62
  // setFoo(...) -> state.foo = ...
98
- path.replaceWith(types.assignmentExpression('=', types.identifier("state.".concat(statePropertyName)), path.node.arguments[0]));
63
+ path.replaceWith((0, types_1.assignmentExpression)('=', (0, types_1.identifier)(`state.${statePropertyName}`), path.node.arguments[0]));
99
64
  }
100
65
  }
101
66
  },
102
- }), function (code) { return code.trim(); });
67
+ }), (code) => code.trim());
103
68
  }
104
- var consolidateClassBindings = function (item) {
69
+ const consolidateClassBindings = (item) => {
105
70
  if (item.bindings.className) {
106
71
  if (item.bindings.class) {
107
72
  // TO-DO: it's too much work to merge 2 bindings, so just remove the old one for now.
@@ -114,7 +79,7 @@ var consolidateClassBindings = function (item) {
114
79
  }
115
80
  if (item.properties.className) {
116
81
  if (item.properties.class) {
117
- item.properties.class = "".concat(item.properties.class, " ").concat(item.properties.className);
82
+ item.properties.class = `${item.properties.class} ${item.properties.className}`;
118
83
  }
119
84
  else {
120
85
  item.properties.class = item.properties.className;
@@ -122,7 +87,7 @@ var consolidateClassBindings = function (item) {
122
87
  delete item.properties.className;
123
88
  }
124
89
  if (item.properties.class && item.bindings.class) {
125
- console.warn("[".concat(item.name, "]: Ended up with both a property and binding for 'class'."));
90
+ console.warn(`[${item.name}]: Ended up with both a property and binding for 'class'.`);
126
91
  }
127
92
  };
128
93
  /**
@@ -132,8 +97,8 @@ var consolidateClassBindings = function (item) {
132
97
  * setText(...) -> state.text = ...
133
98
  */
134
99
  function mapStateIdentifiers(json) {
135
- var stateProperties = Object.keys(json.state);
136
- var plugin = (0, process_code_1.createCodeProcessorPlugin)(function () { return function (code) { return mapStateIdentifiersInExpression(code, stateProperties); }; });
100
+ const stateProperties = Object.keys(json.state);
101
+ const plugin = (0, process_code_1.createCodeProcessorPlugin)(() => (code) => mapStateIdentifiersInExpression(code, stateProperties));
137
102
  plugin(json);
138
103
  (0, legacy_1.default)(json).forEach(function (item) {
139
104
  if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
@@ -142,17 +107,17 @@ function mapStateIdentifiers(json) {
142
107
  });
143
108
  }
144
109
  exports.mapStateIdentifiers = mapStateIdentifiers;
145
- var processStateObjectSlice = function (item) {
146
- if (types.isObjectProperty(item)) {
147
- if (types.isFunctionExpression(item.value)) {
110
+ const processStateObjectSlice = (item) => {
111
+ if ((0, types_1.isObjectProperty)(item)) {
112
+ if ((0, types_1.isFunctionExpression)(item.value)) {
148
113
  return {
149
114
  code: (0, helpers_1.parseCode)(item.value).trim(),
150
115
  type: 'function',
151
116
  };
152
117
  }
153
- else if (types.isArrowFunctionExpression(item.value)) {
154
- var n = babel.types.objectMethod('method', item.key, item.value.params, item.value.body);
155
- var code = (0, helpers_1.parseCode)(n).trim();
118
+ else if ((0, types_1.isArrowFunctionExpression)(item.value)) {
119
+ const n = (0, types_1.objectMethod)('method', item.key, item.value.params, item.value.body);
120
+ const code = (0, helpers_1.parseCode)(n).trim();
156
121
  return {
157
122
  code: code,
158
123
  type: 'method',
@@ -161,7 +126,7 @@ var processStateObjectSlice = function (item) {
161
126
  else {
162
127
  // Remove typescript types, e.g. from
163
128
  // { foo: ('string' as SomeType) }
164
- if (types.isTSAsExpression(item.value)) {
129
+ if ((0, types_1.isTSAsExpression)(item.value)) {
165
130
  return {
166
131
  code: (0, helpers_1.parseCode)(item.value.expression).trim(),
167
132
  type: 'property',
@@ -175,9 +140,9 @@ var processStateObjectSlice = function (item) {
175
140
  };
176
141
  }
177
142
  }
178
- else if (types.isObjectMethod(item)) {
179
- var n = (0, helpers_1.parseCode)(__assign(__assign({}, item), { returnType: null })).trim();
180
- var isGetter = item.kind === 'get';
143
+ else if ((0, types_1.isObjectMethod)(item)) {
144
+ const n = (0, helpers_1.parseCode)({ ...item, returnType: null }).trim();
145
+ const isGetter = item.kind === 'get';
181
146
  return {
182
147
  code: n,
183
148
  type: isGetter ? 'getter' : 'method',
@@ -187,9 +152,9 @@ var processStateObjectSlice = function (item) {
187
152
  throw new Error('Unexpected state value type', item);
188
153
  }
189
154
  };
190
- var processDefaultPropsSlice = function (item) {
191
- if (types.isObjectProperty(item)) {
192
- if (types.isFunctionExpression(item.value) || types.isArrowFunctionExpression(item.value)) {
155
+ const processDefaultPropsSlice = (item) => {
156
+ if ((0, types_1.isObjectProperty)(item)) {
157
+ if ((0, types_1.isFunctionExpression)(item.value) || (0, types_1.isArrowFunctionExpression)(item.value)) {
193
158
  return {
194
159
  code: (0, helpers_1.parseCode)(item.value),
195
160
  type: 'method',
@@ -198,7 +163,7 @@ var processDefaultPropsSlice = function (item) {
198
163
  else {
199
164
  // Remove typescript types, e.g. from
200
165
  // { foo: ('string' as SomeType) }
201
- if (types.isTSAsExpression(item.value)) {
166
+ if ((0, types_1.isTSAsExpression)(item.value)) {
202
167
  return {
203
168
  code: (0, helpers_1.parseCode)(item.value.expression),
204
169
  type: 'property',
@@ -212,9 +177,9 @@ var processDefaultPropsSlice = function (item) {
212
177
  };
213
178
  }
214
179
  }
215
- else if (types.isObjectMethod(item)) {
216
- var n = (0, helpers_1.parseCode)(__assign(__assign({}, item), { returnType: null }));
217
- var isGetter = item.kind === 'get';
180
+ else if ((0, types_1.isObjectMethod)(item)) {
181
+ const n = (0, helpers_1.parseCode)({ ...item, returnType: null });
182
+ const isGetter = item.kind === 'get';
218
183
  return {
219
184
  code: n,
220
185
  type: isGetter ? 'getter' : 'method',
@@ -224,20 +189,21 @@ var processDefaultPropsSlice = function (item) {
224
189
  throw new Error('Unexpected state value type', item);
225
190
  }
226
191
  };
227
- var parseStateObjectToMitosisState = function (object, isState) {
228
- if (isState === void 0) { isState = true; }
229
- var state = {};
230
- object.properties.forEach(function (x) {
231
- if (types.isSpreadElement(x)) {
192
+ const parseStateObjectToMitosisState = (object, isState = true) => {
193
+ const state = {};
194
+ object.properties.forEach((x) => {
195
+ if ((0, types_1.isSpreadElement)(x)) {
232
196
  throw new Error('Parse Error: Mitosis cannot consume spread element in state object: ' + x);
233
197
  }
234
- if (types.isPrivateName(x.key)) {
198
+ if ((0, types_1.isPrivateName)(x.key)) {
235
199
  throw new Error('Parse Error: Mitosis cannot consume private name in state object: ' + x.key);
236
200
  }
237
- if (!types.isIdentifier(x.key)) {
238
- throw new Error('Parse Error: Mitosis cannot consume non-identifier key in state object: ' + x.key);
201
+ if (!(0, types_1.isIdentifier)(x.key) && !(0, types_1.isStringLiteral)(x.key)) {
202
+ throw new Error('Parse Error: Mitosis cannot consume non-identifier and non-string key in state object: ' +
203
+ x.key);
239
204
  }
240
- state[x.key.name] = isState ? processStateObjectSlice(x) : processDefaultPropsSlice(x);
205
+ const keyName = (0, types_1.isStringLiteral)(x.key) ? x.key.value : x.key.name;
206
+ state[keyName] = isState ? processStateObjectSlice(x) : processDefaultPropsSlice(x);
241
207
  });
242
208
  return state;
243
209
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseCss = void 0;
4
- var parseCss = function (ast, json) {
4
+ const parseCss = (ast, json) => {
5
5
  var _a;
6
6
  json.style = (_a = ast.css) === null || _a === void 0 ? void 0 : _a.content.styles;
7
7
  };
@@ -1,27 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processBindings = void 0;
4
- var bindings_1 = require("../../../helpers/bindings");
5
- function replaceGroupWithChecked(node, isArray) {
4
+ const bindings_1 = require("../../../helpers/bindings");
5
+ function replaceGroupWithChecked(node, isArray = false) {
6
6
  var _a, _b, _c;
7
- if (isArray === void 0) { isArray = false; }
8
7
  if ((_b = (_a = node.bindings.group) === null || _a === void 0 ? void 0 : _a.code) === null || _b === void 0 ? void 0 : _b.length) {
9
- var bindingValue = (_c = node.bindings.value) === null || _c === void 0 ? void 0 : _c.code;
10
- var propertyValue = node.properties.value;
11
- var groupBinding = node.bindings.group.code;
12
- var code = '';
8
+ const bindingValue = (_c = node.bindings.value) === null || _c === void 0 ? void 0 : _c.code;
9
+ const propertyValue = node.properties.value;
10
+ const groupBinding = node.bindings.group.code;
11
+ let code = '';
13
12
  if (isArray) {
14
13
  code = bindingValue
15
- ? "".concat(groupBinding, ".includes(").concat(bindingValue, ")")
16
- : "".concat(groupBinding, ".includes('").concat(propertyValue, "')");
14
+ ? `${groupBinding}.includes(${bindingValue})`
15
+ : `${groupBinding}.includes('${propertyValue}')`;
17
16
  }
18
17
  else {
19
18
  code = bindingValue
20
- ? "".concat(groupBinding, " === ").concat(bindingValue)
21
- : "".concat(groupBinding, " === '").concat(propertyValue, "'");
19
+ ? `${groupBinding} === ${bindingValue}`
20
+ : `${groupBinding} === '${propertyValue}'`;
22
21
  }
23
22
  node.bindings['checked'] = (0, bindings_1.createSingleBinding)({
24
- code: code,
23
+ code,
25
24
  });
26
25
  delete node.bindings.group;
27
26
  }
@@ -36,15 +35,15 @@ function replaceGroupWithChecked(node, isArray) {
36
35
  */
37
36
  function processBindings(json, node) {
38
37
  var _a, _b, _c, _d, _e, _f, _g;
39
- var name;
40
- var target = 'event.target.value';
41
- var binding = '';
42
- var isArray = false;
38
+ let name;
39
+ let target = 'event.target.value';
40
+ let binding = '';
41
+ let isArray = false;
43
42
  if (Object.prototype.hasOwnProperty.call(node.bindings, 'group')) {
44
43
  name = 'group';
45
44
  binding = (_b = (_a = node.bindings.group) === null || _a === void 0 ? void 0 : _a.code) !== null && _b !== void 0 ? _b : '';
46
45
  if (binding.startsWith('state.')) {
47
- var stateObject = json.state[binding.replace(/^state\./, '')];
46
+ const stateObject = json.state[binding.replace(/^state\./, '')];
48
47
  isArray = Array.isArray(stateObject === null || stateObject === void 0 ? void 0 : stateObject.code);
49
48
  }
50
49
  replaceGroupWithChecked(node, isArray);
@@ -61,10 +60,10 @@ function processBindings(json, node) {
61
60
  target = 'event.target.checked';
62
61
  binding = (_f = (_e = node.bindings.onChange) === null || _e === void 0 ? void 0 : _e.code.split('=')[0]) !== null && _f !== void 0 ? _f : '';
63
62
  }
64
- var onChangeCode = "".concat(binding, " = ").concat(target);
63
+ let onChangeCode = `${binding} = ${target}`;
65
64
  // If the binding is an array, we should push / splice rather than assigning
66
65
  if (isArray) {
67
- onChangeCode = "event.target.checked ? ".concat(binding, ".push(").concat(target, ") : ").concat(binding, ".splice(").concat(binding, ".indexOf(").concat(node.properties.value ? "'".concat(node.properties.value, "'") : (_g = node.bindings.value) === null || _g === void 0 ? void 0 : _g.code, "), 1)");
66
+ onChangeCode = `event.target.checked ? ${binding}.push(${target}) : ${binding}.splice(${binding}.indexOf(${node.properties.value ? `'${node.properties.value}'` : (_g = node.bindings.value) === null || _g === void 0 ? void 0 : _g.code}), 1)`;
68
67
  }
69
68
  if (name !== 'ref' && binding) {
70
69
  node.bindings['onChange'] = (0, bindings_1.createSingleBinding)({
@@ -1,18 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseChildren = exports.filterChildren = void 0;
4
- var html_1 = require("../html");
4
+ const html_1 = require("../html");
5
5
  function filterChildren(children) {
6
6
  var _a;
7
- return ((_a = children === null || children === void 0 ? void 0 : children.filter(function (n) { var _a; return n.type !== 'Comment' && (n.type !== 'Text' || ((_a = n.data) === null || _a === void 0 ? void 0 : _a.trim().length)); })) !== null && _a !== void 0 ? _a : []);
7
+ return ((_a = children === null || children === void 0 ? void 0 : children.filter((n) => { var _a; return n.type !== 'Comment' && (n.type !== 'Text' || ((_a = n.data) === null || _a === void 0 ? void 0 : _a.trim().length)); })) !== null && _a !== void 0 ? _a : []);
8
8
  }
9
9
  exports.filterChildren = filterChildren;
10
10
  function parseChildren(json, node) {
11
- var children = [];
11
+ const children = [];
12
12
  if (node.children) {
13
- for (var _i = 0, _a = filterChildren(node.children); _i < _a.length; _i++) {
14
- var child = _a[_i];
15
- var mitosisNode = (0, html_1.parseHtmlNode)(json, child);
13
+ for (const child of filterChildren(node.children)) {
14
+ const mitosisNode = (0, html_1.parseHtmlNode)(json, child);
16
15
  if (mitosisNode) {
17
16
  children.push(mitosisNode);
18
17
  }
@@ -1,21 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseObjectExpression = void 0;
4
- var astring_1 = require("astring");
5
- var references_1 = require("../instance/references");
4
+ const astring_1 = require("astring");
5
+ const references_1 = require("../instance/references");
6
6
  function parseObjectExpression(json, node) {
7
- var _a;
8
- var properties = node.properties.map(function (n) {
9
- var node_ = n;
7
+ const properties = node.properties.map((n) => {
8
+ const node_ = n;
10
9
  return {
11
10
  key: (0, astring_1.generate)(node_.key),
12
11
  value: (0, references_1.getParsedValue)(json, node_.value),
13
12
  };
14
13
  });
15
- var c = {};
16
- for (var _i = 0, properties_1 = properties; _i < properties_1.length; _i++) {
17
- var item = properties_1[_i];
18
- Object.assign(c, (_a = {}, _a[item.key] = item.value, _a));
14
+ const c = {};
15
+ for (const item of properties) {
16
+ Object.assign(c, { [item.key]: item.value });
19
17
  }
20
18
  return c;
21
19
  }
@@ -4,11 +4,11 @@ exports.addToOnInitHook = void 0;
4
4
  function addToOnInitHook(json, code) {
5
5
  var _a;
6
6
  if ((_a = json.hooks.onInit) === null || _a === void 0 ? void 0 : _a.code.length) {
7
- json.hooks.onInit.code += "\n ".concat(code);
7
+ json.hooks.onInit.code += `\n ${code}`;
8
8
  }
9
9
  else {
10
10
  json.hooks.onInit = {
11
- code: code,
11
+ code,
12
12
  };
13
13
  }
14
14
  }