@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,177 +1,165 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.renderPreComponent = exports.renderImport = exports.transformImportPath = exports.checkIsComponentImport = void 0;
4
- var component_file_extensions_1 = require("./component-file-extensions");
5
- var DEFAULT_IMPORT = 'default';
6
- var STAR_IMPORT = '*';
7
- var getStarImport = function (_a) {
8
- var theImport = _a.theImport;
9
- for (var key in theImport.imports) {
10
- var value = theImport.imports[key];
4
+ const component_file_extensions_1 = require("./component-file-extensions");
5
+ const DEFAULT_IMPORT = 'default';
6
+ const STAR_IMPORT = '*';
7
+ const getStarImport = ({ theImport }) => {
8
+ for (const key in theImport.imports) {
9
+ const value = theImport.imports[key];
11
10
  if (value === STAR_IMPORT) {
12
11
  return key;
13
12
  }
14
13
  }
15
14
  return null;
16
15
  };
17
- var getDefaultImport = function (_a) {
18
- var theImport = _a.theImport;
19
- for (var key in theImport.imports) {
20
- var value = theImport.imports[key];
16
+ const getDefaultImport = ({ theImport }) => {
17
+ for (const key in theImport.imports) {
18
+ const value = theImport.imports[key];
21
19
  if (value === DEFAULT_IMPORT) {
22
20
  return key;
23
21
  }
24
22
  }
25
23
  return null;
26
24
  };
27
- var CONTEXT_IMPORTS = ['context.lite', 'context.lite.ts', 'context.lite.js'];
28
- var checkIsContextImport = function (theImport) {
29
- return CONTEXT_IMPORTS.some(function (contextPath) { return theImport.path.endsWith(contextPath); });
30
- };
31
- var checkIsComponentImport = function (theImport) {
32
- return !checkIsContextImport(theImport) &&
33
- component_file_extensions_1.COMPONENT_IMPORT_EXTENSIONS.some(function (contextPath) { return theImport.path.endsWith(contextPath); });
34
- };
25
+ const CONTEXT_IMPORTS = ['context.lite', 'context.lite.ts', 'context.lite.js'];
26
+ const checkIsContextImport = (theImport) => CONTEXT_IMPORTS.some((contextPath) => theImport.path.endsWith(contextPath));
27
+ const checkIsComponentImport = (theImport) => !checkIsContextImport(theImport) &&
28
+ component_file_extensions_1.COMPONENT_IMPORT_EXTENSIONS.some((contextPath) => theImport.path.endsWith(contextPath));
35
29
  exports.checkIsComponentImport = checkIsComponentImport;
36
- var transformImportPath = function (_a) {
37
- var theImport = _a.theImport, target = _a.target, preserveFileExtensions = _a.preserveFileExtensions, explicitImportFileExtension = _a.explicitImportFileExtension;
30
+ const transformImportPath = ({ theImport, target, preserveFileExtensions, explicitImportFileExtension, }) => {
38
31
  // We need to drop the `.lite` from context files, because the context generator does so as well.
39
32
  if (checkIsContextImport(theImport)) {
40
- var path_1 = theImport.path;
41
- CONTEXT_IMPORTS.forEach(function (contextPath) {
42
- if (path_1.endsWith(contextPath)) {
43
- path_1 = path_1.replace(contextPath, 'context.js');
33
+ let path = theImport.path;
34
+ CONTEXT_IMPORTS.forEach((contextPath) => {
35
+ if (path.endsWith(contextPath)) {
36
+ path = path.replace(contextPath, 'context.js');
44
37
  }
45
38
  });
46
- return path_1;
39
+ return path;
47
40
  }
48
41
  if (preserveFileExtensions)
49
42
  return theImport.path;
50
43
  if ((0, exports.checkIsComponentImport)(theImport)) {
51
- return theImport.path.replace(component_file_extensions_1.INPUT_EXTENSION_REGEX, (0, component_file_extensions_1.getComponentFileExtensionForTarget)({ target: target, type: 'import', explicitImportFileExtension: explicitImportFileExtension }));
44
+ return theImport.path.replace(component_file_extensions_1.INPUT_EXTENSION_REGEX, (0, component_file_extensions_1.getComponentFileExtensionForTarget)({ target, type: 'import', explicitImportFileExtension }));
52
45
  }
53
46
  return theImport.path;
54
47
  };
55
48
  exports.transformImportPath = transformImportPath;
56
- var getNamedImports = function (_a) {
57
- var theImport = _a.theImport;
58
- var namedImports = Object.entries(theImport.imports)
59
- .filter(function (_a) {
60
- var value = _a[1];
61
- return ![DEFAULT_IMPORT, STAR_IMPORT].includes(value);
62
- })
63
- .map(function (_a) {
64
- var key = _a[0], value = _a[1];
65
- return key !== value ? "".concat(value, " as ").concat(key) : value;
49
+ const getNamedImports = ({ theImport }) => {
50
+ const namedImports = Object.entries(theImport.imports)
51
+ .filter(([, value]) => ![DEFAULT_IMPORT, STAR_IMPORT].includes(value))
52
+ .map(([key, value]) => {
53
+ return key !== value ? `${value} as ${key}` : value;
66
54
  });
67
55
  if (namedImports.length > 0) {
68
- return "{ ".concat(namedImports.join(', '), " }");
56
+ return `{ ${namedImports.join(', ')} }`;
69
57
  }
70
58
  else {
71
59
  return null;
72
60
  }
73
61
  };
74
- var getImportedValues = function (_a) {
75
- var theImport = _a.theImport;
76
- var starImport = getStarImport({ theImport: theImport });
77
- var defaultImport = getDefaultImport({ theImport: theImport });
78
- var namedImports = getNamedImports({ theImport: theImport });
79
- return { starImport: starImport, defaultImport: defaultImport, namedImports: namedImports };
62
+ const getImportedValues = ({ theImport }) => {
63
+ const starImport = getStarImport({ theImport });
64
+ const defaultImport = getDefaultImport({ theImport });
65
+ const namedImports = getNamedImports({ theImport });
66
+ return { starImport, defaultImport, namedImports };
80
67
  };
81
- var getImportValue = function (_a) {
82
- var defaultImport = _a.defaultImport, namedImports = _a.namedImports, starImport = _a.starImport;
68
+ const getImportValue = ({ defaultImport, namedImports, starImport }) => {
83
69
  if (starImport) {
84
- return " * as ".concat(starImport, " ");
70
+ return ` * as ${starImport} `;
85
71
  }
86
72
  else {
87
73
  return [defaultImport, namedImports].filter(Boolean).join(', ');
88
74
  }
89
75
  };
90
- var renderImport = function (_a) {
91
- var theImport = _a.theImport, target = _a.target, asyncComponentImports = _a.asyncComponentImports, _b = _a.preserveFileExtensions, preserveFileExtensions = _b === void 0 ? false : _b, _c = _a.component, component = _c === void 0 ? undefined : _c, _d = _a.componentsUsed, componentsUsed = _d === void 0 ? [] : _d, importMapper = _a.importMapper, _e = _a.explicitImportFileExtension, explicitImportFileExtension = _e === void 0 ? false : _e;
92
- var importedValues = getImportedValues({ theImport: theImport });
93
- var path = (0, exports.transformImportPath)({
94
- theImport: theImport,
95
- target: target,
96
- preserveFileExtensions: preserveFileExtensions,
97
- explicitImportFileExtension: explicitImportFileExtension,
76
+ const renderImport = ({ theImport, target, asyncComponentImports, preserveFileExtensions = false, component = undefined, componentsUsed = [], importMapper, explicitImportFileExtension = false, }) => {
77
+ const importedValues = getImportedValues({ theImport });
78
+ const path = (0, exports.transformImportPath)({
79
+ theImport,
80
+ target,
81
+ preserveFileExtensions,
82
+ explicitImportFileExtension,
98
83
  });
99
- var importValue = getImportValue(importedValues);
100
- var isComponentImport = (0, exports.checkIsComponentImport)(theImport);
101
- var shouldBeAsyncImport = asyncComponentImports && isComponentImport;
102
- var isTypeImport = theImport.importKind === 'type';
84
+ const importValue = getImportValue(importedValues);
85
+ const isComponentImport = (0, exports.checkIsComponentImport)(theImport);
86
+ const shouldBeAsyncImport = asyncComponentImports && isComponentImport;
87
+ const isTypeImport = theImport.importKind === 'type';
103
88
  // For lit (components) we just want to do a plain import
104
89
  // https://lit.dev/docs/components/rendering/#composing-templates
105
90
  if (isComponentImport && target === 'lit') {
106
- return "import '".concat(path, "';");
91
+ return `import '${path}';`;
107
92
  }
108
93
  if (shouldBeAsyncImport) {
109
- var isVueImport = target === 'vue';
94
+ const isVueImport = target === 'vue';
110
95
  if (isVueImport && importedValues.namedImports) {
111
96
  console.warn('Vue: Async Component imports cannot include named imports. Dropping async import. This might break your code.');
112
97
  }
113
98
  else {
114
- return "const ".concat(importValue, " = () => import('").concat(path, "')\n .then(x => x.default)\n .catch(err => {\n console.error('Error while attempting to dynamically import component ").concat(importValue, " at ").concat(path, "', err);\n throw err;\n });");
99
+ return `const ${importValue} = () => import('${path}')
100
+ .then(x => x.default)
101
+ .catch(err => {
102
+ console.error('Error while attempting to dynamically import component ${importValue} at ${path}', err);
103
+ throw err;
104
+ });`;
115
105
  }
116
106
  }
117
107
  if (importMapper) {
118
108
  return importMapper(component, theImport, importedValues, componentsUsed);
119
109
  }
120
110
  return importValue
121
- ? "import ".concat(isTypeImport ? 'type' : '', " ").concat(importValue, " from '").concat(path, "';")
122
- : "import '".concat(path, "';");
111
+ ? `import ${isTypeImport ? 'type' : ''} ${importValue} from '${path}';`
112
+ : `import '${path}';`;
123
113
  };
124
114
  exports.renderImport = renderImport;
125
- var renderImports = function (_a) {
126
- var imports = _a.imports, target = _a.target, asyncComponentImports = _a.asyncComponentImports, excludeMitosisComponents = _a.excludeMitosisComponents, _b = _a.preserveFileExtensions, preserveFileExtensions = _b === void 0 ? false : _b, component = _a.component, componentsUsed = _a.componentsUsed, importMapper = _a.importMapper, explicitImportFileExtension = _a.explicitImportFileExtension;
127
- return imports
128
- .filter(function (theImport) {
129
- if (
130
- // Remove compile away components
131
- theImport.path === '@builder.io/components' ||
132
- // TODO: Mitosis output needs this
133
- theImport.path.startsWith('@builder.io/mitosis')) {
134
- return false;
135
- }
136
- else if (excludeMitosisComponents && theImport.path.includes('.lite')) {
137
- return false;
138
- }
139
- else {
140
- return true;
141
- }
142
- })
143
- .map(function (theImport) {
144
- return (0, exports.renderImport)({
145
- theImport: theImport,
146
- target: target,
147
- asyncComponentImports: asyncComponentImports,
148
- preserveFileExtensions: preserveFileExtensions,
149
- component: component,
150
- componentsUsed: componentsUsed,
151
- importMapper: importMapper,
152
- explicitImportFileExtension: explicitImportFileExtension,
153
- });
154
- })
155
- .join('\n');
156
- };
157
- var renderPreComponent = function (_a) {
158
- var _b;
159
- var component = _a.component, target = _a.target, excludeMitosisComponents = _a.excludeMitosisComponents, _c = _a.asyncComponentImports, asyncComponentImports = _c === void 0 ? false : _c, _d = _a.preserveFileExtensions, preserveFileExtensions = _d === void 0 ? false : _d, _e = _a.componentsUsed, componentsUsed = _e === void 0 ? [] : _e, importMapper = _a.importMapper, _f = _a.explicitImportFileExtension, explicitImportFileExtension = _f === void 0 ? false : _f;
160
- return "\n ".concat(renderImports({
115
+ const renderImports = ({ imports, target, asyncComponentImports, excludeMitosisComponents, preserveFileExtensions = false, component, componentsUsed, importMapper, explicitImportFileExtension, }) => imports
116
+ .filter((theImport) => {
117
+ if (
118
+ // Remove compile away components
119
+ theImport.path === '@builder.io/components' ||
120
+ // TODO: Mitosis output needs this
121
+ theImport.path.startsWith('@builder.io/mitosis')) {
122
+ return false;
123
+ }
124
+ else if (excludeMitosisComponents && theImport.path.includes('.lite')) {
125
+ return false;
126
+ }
127
+ else {
128
+ return true;
129
+ }
130
+ })
131
+ .map((theImport) => (0, exports.renderImport)({
132
+ theImport,
133
+ target,
134
+ asyncComponentImports,
135
+ preserveFileExtensions,
136
+ component,
137
+ componentsUsed,
138
+ importMapper,
139
+ explicitImportFileExtension,
140
+ }))
141
+ .join('\n');
142
+ const renderPreComponent = ({ component, target, excludeMitosisComponents, asyncComponentImports = false, preserveFileExtensions = false, componentsUsed = [], importMapper, explicitImportFileExtension = false, }) => {
143
+ var _a;
144
+ return `
145
+ ${renderImports({
161
146
  imports: component.imports,
162
- target: target,
163
- asyncComponentImports: asyncComponentImports,
164
- excludeMitosisComponents: excludeMitosisComponents,
165
- preserveFileExtensions: preserveFileExtensions,
166
- component: component,
167
- componentsUsed: componentsUsed,
168
- importMapper: importMapper,
169
- explicitImportFileExtension: explicitImportFileExtension,
170
- }), "\n ").concat(renderExportAndLocal(component), "\n ").concat(((_b = component.hooks.preComponent) === null || _b === void 0 ? void 0 : _b.code) || '', "\n ");
147
+ target,
148
+ asyncComponentImports,
149
+ excludeMitosisComponents,
150
+ preserveFileExtensions,
151
+ component,
152
+ componentsUsed,
153
+ importMapper,
154
+ explicitImportFileExtension,
155
+ })}
156
+ ${renderExportAndLocal(component)}
157
+ ${((_a = component.hooks.preComponent) === null || _a === void 0 ? void 0 : _a.code) || ''}
158
+ `;
171
159
  };
172
160
  exports.renderPreComponent = renderPreComponent;
173
- var renderExportAndLocal = function (component) {
161
+ const renderExportAndLocal = (component) => {
174
162
  return Object.keys(component.exports || {})
175
- .map(function (key) { return component.exports[key].code; })
163
+ .map((key) => component.exports[key].code)
176
164
  .join('\n');
177
165
  };
@@ -4,48 +4,47 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.replaceNodes = exports.replacePropsIdentifier = exports.replaceStateIdentifier = exports.replaceIdentifiers = void 0;
7
- var core_1 = require("@babel/core");
8
- var generator_1 = __importDefault(require("@babel/generator"));
9
- var function_1 = require("fp-ts/lib/function");
10
- var babel_transform_1 = require("./babel-transform");
7
+ const core_1 = require("@babel/core");
8
+ const generator_1 = __importDefault(require("@babel/generator"));
9
+ const function_1 = require("fp-ts/lib/function");
10
+ const babel_transform_1 = require("./babel-transform");
11
11
  /**
12
12
  * Given a `to` function given by the user, figure out the best argument to provide to the `to` function.
13
13
  * This function makes a best guess based on the AST structure it's dealing with.
14
14
  */
15
- var getToParam = function (path) {
15
+ const getToParam = (path) => {
16
16
  if (core_1.types.isMemberExpression(path.node) || core_1.types.isOptionalMemberExpression(path.node)) {
17
17
  if (core_1.types.isIdentifier(path.node.property)) {
18
18
  // if simple member expression e.g. `props.foo`, returns `foo`
19
- var propertyName = path.node.property.name;
19
+ const propertyName = path.node.property.name;
20
20
  return propertyName;
21
21
  }
22
22
  else {
23
23
  // if nested member expression e.g. `props.foo.bar.baz`, returns `foo.bar.baz`
24
- var x = (0, generator_1.default)(path.node.property).code;
24
+ const x = (0, generator_1.default)(path.node.property).code;
25
25
  return x;
26
26
  }
27
27
  }
28
28
  else {
29
29
  // if naked identifier e.g. `foo`, returns `foo`
30
- var nodeName = path.node.name;
30
+ const nodeName = path.node.name;
31
31
  return nodeName;
32
32
  }
33
33
  };
34
- var _replaceIdentifiers = function (path, _a) {
35
- var _b, _c;
36
- var from = _a.from, to = _a.to;
37
- var memberExpressionObject = core_1.types.isIdentifier(path.node) ? path.node : path.node.object;
38
- var normalizedFrom = Array.isArray(from) ? from : [from];
34
+ const _replaceIdentifiers = (path, { from, to }) => {
35
+ var _a, _b;
36
+ const memberExpressionObject = core_1.types.isIdentifier(path.node) ? path.node : path.node.object;
37
+ const normalizedFrom = Array.isArray(from) ? from : [from];
39
38
  if (!core_1.types.isIdentifier(memberExpressionObject) ||
40
- ((_c = (_b = path.node) === null || _b === void 0 ? void 0 : _b._builder_meta) === null || _c === void 0 ? void 0 : _c.newlyGenerated)) {
39
+ ((_b = (_a = path.node) === null || _a === void 0 ? void 0 : _a._builder_meta) === null || _b === void 0 ? void 0 : _b.newlyGenerated)) {
41
40
  return;
42
41
  }
43
- var matchesFrom = normalizedFrom.includes(memberExpressionObject.name);
42
+ const matchesFrom = normalizedFrom.includes(memberExpressionObject.name);
44
43
  if (matchesFrom) {
45
44
  if (to) {
46
45
  // `props.foo` to `state`, e.g. `state.foo`
47
46
  if (typeof to === 'string') {
48
- var cleanedIdentifier = (0, function_1.pipe)(
47
+ const cleanedIdentifier = (0, function_1.pipe)(
49
48
  // Remove trailing `.` if it exists in the user-provided string, as the dot is generated
50
49
  // by babel from the AST
51
50
  to.endsWith('.') ? to.substring(0, to.length - 1) : to, core_1.types.identifier);
@@ -59,12 +58,11 @@ var _replaceIdentifiers = function (path, _a) {
59
58
  }
60
59
  else {
61
60
  try {
62
- var newMemberExpression = (0, function_1.pipe)(getToParam(path), function (x) { return to(x, memberExpressionObject.name); }, function (expression) {
63
- var _a = expression.split('.'), head = _a[0], tail = _a.slice(1);
61
+ const newMemberExpression = (0, function_1.pipe)(getToParam(path), (x) => to(x, memberExpressionObject.name), (expression) => {
62
+ const [head, ...tail] = expression.split('.');
64
63
  return [head, tail.join('.')];
65
- }, function (_a) {
66
- var obj = _a[0], prop = _a[1];
67
- var objIdentifier = core_1.types.identifier(obj);
64
+ }, ([obj, prop]) => {
65
+ const objIdentifier = core_1.types.identifier(obj);
68
66
  if (prop === '') {
69
67
  return objIdentifier;
70
68
  }
@@ -92,7 +90,7 @@ var _replaceIdentifiers = function (path, _a) {
92
90
  }
93
91
  else {
94
92
  if (core_1.types.isIdentifier(path.node)) {
95
- console.debug("Could not replace Identifier with nothing.");
93
+ console.debug(`Could not replace Identifier with nothing.`);
96
94
  }
97
95
  else {
98
96
  // if we're looking at a member expression, e.g. `props.foo` and no `to` was provided, then we want to strip out
@@ -105,17 +103,16 @@ var _replaceIdentifiers = function (path, _a) {
105
103
  /**
106
104
  * @deprecated Use `replaceNodes` instead.
107
105
  */
108
- var replaceIdentifiers = function (_a) {
109
- var code = _a.code, from = _a.from, to = _a.to;
106
+ const replaceIdentifiers = ({ code, from, to }) => {
110
107
  try {
111
108
  return (0, function_1.pipe)((0, babel_transform_1.babelTransformExpression)(code, {
112
- MemberExpression: function (path) {
113
- _replaceIdentifiers(path, { from: from, to: to });
109
+ MemberExpression(path) {
110
+ _replaceIdentifiers(path, { from, to });
114
111
  },
115
- OptionalMemberExpression: function (path) {
116
- _replaceIdentifiers(path, { from: from, to: to });
112
+ OptionalMemberExpression(path) {
113
+ _replaceIdentifiers(path, { from, to });
117
114
  },
118
- Identifier: function (path) {
115
+ Identifier(path) {
119
116
  // we only want to ignore certain identifiers:
120
117
  if (
121
118
  // (optional) member expressions are already handled in other visitors
@@ -127,52 +124,46 @@ var replaceIdentifiers = function (_a) {
127
124
  // !(types.isVariableDeclarator(path.parent) && path.parent.id === path.node)
128
125
  // object -> { detail: { state: 'something' } } shouldn't be transformed to { detail: { this: 'something' } }
129
126
  !core_1.types.isObjectProperty(path.parent)) {
130
- _replaceIdentifiers(path, { from: from, to: to });
127
+ _replaceIdentifiers(path, { from, to });
131
128
  }
132
129
  },
133
130
  }),
134
131
  // merely running `babel.transform` will add spaces around the code, even if we don't end up replacing anything.
135
132
  // we have some other code downstream that cannot have untrimmed spaces, so we need to trim the output.
136
- function (code) { return code.trim(); });
133
+ (code) => code.trim());
137
134
  }
138
135
  catch (err) {
139
136
  throw err;
140
137
  }
141
138
  };
142
139
  exports.replaceIdentifiers = replaceIdentifiers;
143
- var replaceStateIdentifier = function (to) { return function (code) {
144
- return (0, exports.replaceIdentifiers)({ code: code, from: 'state', to: to });
145
- }; };
140
+ const replaceStateIdentifier = (to) => (code) => (0, exports.replaceIdentifiers)({ code, from: 'state', to });
146
141
  exports.replaceStateIdentifier = replaceStateIdentifier;
147
- var replacePropsIdentifier = function (to) { return function (code) {
148
- return (0, exports.replaceIdentifiers)({ code: code, from: 'props', to: to });
149
- }; };
142
+ const replacePropsIdentifier = (to) => (code) => (0, exports.replaceIdentifiers)({ code, from: 'props', to });
150
143
  exports.replacePropsIdentifier = replacePropsIdentifier;
151
- var isNewlyGenerated = function (node) { var _a; return (_a = node === null || node === void 0 ? void 0 : node._builder_meta) === null || _a === void 0 ? void 0 : _a.newlyGenerated; };
144
+ const isNewlyGenerated = (node) => { var _a; return (_a = node === null || node === void 0 ? void 0 : node._builder_meta) === null || _a === void 0 ? void 0 : _a.newlyGenerated; };
152
145
  /**
153
146
  * Replaces all instances of a Babel AST Node with a new Node within a code string.
154
147
  * Uses `generate()` to convert the Node to a string and compare them.
155
148
  */
156
- var replaceNodes = function (_a) {
157
- var code = _a.code, nodeMaps = _a.nodeMaps;
158
- var searchAndReplace = function (path) {
149
+ const replaceNodes = ({ code, nodeMaps, }) => {
150
+ const searchAndReplace = (path) => {
159
151
  if (isNewlyGenerated(path.node) || isNewlyGenerated(path.parent))
160
152
  return;
161
- for (var _i = 0, nodeMaps_1 = nodeMaps; _i < nodeMaps_1.length; _i++) {
162
- var _a = nodeMaps_1[_i], from = _a.from, to = _a.to, condition = _a.condition;
153
+ for (const { from, to, condition } of nodeMaps) {
163
154
  if (isNewlyGenerated(path.node) || isNewlyGenerated(path.parent))
164
155
  return;
165
156
  // if (path.node.type !== from.type) return;
166
- var matchesCondition = condition ? condition(path) : true;
157
+ const matchesCondition = condition ? condition(path) : true;
167
158
  if ((0, generator_1.default)(path.node).code === (0, generator_1.default)(from).code && matchesCondition) {
168
- var x = core_1.types.cloneNode(to);
159
+ const x = core_1.types.cloneNode(to);
169
160
  x._builder_meta = { newlyGenerated: true };
170
161
  try {
171
162
  path.replaceWith(x);
172
163
  }
173
164
  catch (err) {
174
165
  console.log('error replacing', {
175
- code: code,
166
+ code,
176
167
  orig: (0, generator_1.default)(path.node).code,
177
168
  to: (0, generator_1.default)(x).code,
178
169
  });
@@ -182,13 +173,13 @@ var replaceNodes = function (_a) {
182
173
  }
183
174
  };
184
175
  return (0, babel_transform_1.babelTransformExpression)(code, {
185
- MemberExpression: function (path) {
176
+ MemberExpression(path) {
186
177
  searchAndReplace(path);
187
178
  },
188
- Identifier: function (path) {
179
+ Identifier(path) {
189
180
  searchAndReplace(path);
190
181
  },
191
- OptionalMemberExpression: function (path) {
182
+ OptionalMemberExpression(path) {
192
183
  searchAndReplace(path);
193
184
  },
194
185
  });
@@ -2,17 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stripNewlinesInStrings = void 0;
4
4
  function stripNewlinesInStrings(string) {
5
- var inString = null;
5
+ let inString = null;
6
6
  return string
7
7
  .split('')
8
- .map(function (char, index) {
8
+ .map((char, index) => {
9
9
  if (inString) {
10
10
  if (char === '\n') {
11
11
  return ' ';
12
12
  }
13
13
  }
14
14
  // Prior char is escape char and the char before that is not escaping it
15
- var isEscaped = string[index - 1] === '\\' && string[index - 2] !== '\\';
15
+ const isEscaped = string[index - 1] === '\\' && string[index - 2] !== '\\';
16
16
  if (!inString && (char === '"' || char === "'") && !isEscaped) {
17
17
  inString = char;
18
18
  }
@@ -1,39 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mapSignalTypeInTSFile = exports.mapSignalType = exports.getSignalImportName = exports.getSignalMitosisImportForTarget = void 0;
4
- var core_1 = require("@babel/core");
5
- var function_1 = require("fp-ts/lib/function");
6
- var babel_transform_1 = require("../../helpers/babel-transform");
7
- var mitosis_imports_1 = require("../mitosis-imports");
8
- var getSignalMappingForTarget = function (target) {
4
+ const core_1 = require("@babel/core");
5
+ const function_1 = require("fp-ts/lib/function");
6
+ const babel_transform_1 = require("../../helpers/babel-transform");
7
+ const mitosis_imports_1 = require("../mitosis-imports");
8
+ const getSignalMappingForTarget = (target) => {
9
9
  switch (target) {
10
10
  case 'svelte':
11
- var importDeclaration = core_1.types.importDeclaration([core_1.types.importSpecifier(core_1.types.identifier('Writable'), core_1.types.identifier('Writable'))], core_1.types.stringLiteral('svelte/store'));
11
+ const importDeclaration = core_1.types.importDeclaration([core_1.types.importSpecifier(core_1.types.identifier('Writable'), core_1.types.identifier('Writable'))], core_1.types.stringLiteral('svelte/store'));
12
12
  importDeclaration.importKind = 'type';
13
13
  return {
14
- getTypeReference: function (generics) {
15
- if (generics === void 0) { generics = []; }
16
- return core_1.types.tsTypeReference(core_1.types.identifier('Writable'), core_1.types.tsTypeParameterInstantiation(generics));
17
- },
18
- importDeclaration: importDeclaration,
14
+ getTypeReference: (generics = []) => core_1.types.tsTypeReference(core_1.types.identifier('Writable'), core_1.types.tsTypeParameterInstantiation(generics)),
15
+ importDeclaration,
19
16
  };
20
17
  default:
21
18
  return undefined;
22
19
  }
23
20
  };
24
- var getSignalMitosisImportForTarget = function (target) {
25
- var signalType = getSignalMappingForTarget(target);
21
+ const getSignalMitosisImportForTarget = (target) => {
22
+ const signalType = getSignalMappingForTarget(target);
26
23
  if (!signalType) {
27
24
  return undefined;
28
25
  }
29
26
  return (0, mitosis_imports_1.mapImportDeclarationToMitosisImport)(signalType.importDeclaration);
30
27
  };
31
28
  exports.getSignalMitosisImportForTarget = getSignalMitosisImportForTarget;
32
- var getSignalImportName = function (code) {
33
- var foundSignalUsage = false;
34
- var signalImportName = undefined;
29
+ const getSignalImportName = (code) => {
30
+ let foundSignalUsage = false;
31
+ let signalImportName = undefined;
35
32
  (0, babel_transform_1.babelTransformExpression)(code, {
36
- ImportSpecifier: function (path) {
33
+ ImportSpecifier(path) {
37
34
  if (core_1.types.isIdentifier(path.node.imported) && path.node.imported.name === 'Signal') {
38
35
  if (path.parentPath.isImportDeclaration() &&
39
36
  path.parentPath.node.source.value === '@builder.io/mitosis') {
@@ -51,7 +48,7 @@ var getSignalImportName = function (code) {
51
48
  return undefined;
52
49
  }
53
50
  (0, babel_transform_1.babelTransformExpression)(code, {
54
- TSTypeReference: function (path) {
51
+ TSTypeReference(path) {
55
52
  if (core_1.types.isIdentifier(path.node.typeName) && path.node.typeName.name === signalImportName) {
56
53
  foundSignalUsage = true;
57
54
  path.stop();
@@ -61,14 +58,13 @@ var getSignalImportName = function (code) {
61
58
  return foundSignalUsage ? signalImportName : undefined;
62
59
  };
63
60
  exports.getSignalImportName = getSignalImportName;
64
- var addSignalImport = function (_a) {
65
- var code = _a.code, target = _a.target;
66
- var signalType = getSignalMappingForTarget(target);
61
+ const addSignalImport = ({ code, target }) => {
62
+ const signalType = getSignalMappingForTarget(target);
67
63
  if (!signalType) {
68
64
  return code;
69
65
  }
70
66
  return (0, babel_transform_1.babelTransformExpression)(code, {
71
- Program: function (path) {
67
+ Program(path) {
72
68
  path.node.body.unshift(signalType.importDeclaration);
73
69
  },
74
70
  });
@@ -77,14 +73,13 @@ var addSignalImport = function (_a) {
77
73
  * Finds all `Signal` types and replaces them with the correct type for the given target.
78
74
  * e.g. `Signal<string>` becomes `Writable<string>` for Svelte.
79
75
  */
80
- var mapSignalType = function (_a) {
81
- var code = _a.code, target = _a.target, _b = _a.signalImportName, signalImportName = _b === void 0 ? (0, exports.getSignalImportName)(code) : _b;
82
- var signalType = getSignalMappingForTarget(target);
83
- var map = function (path) {
76
+ const mapSignalType = ({ code, target, signalImportName = (0, exports.getSignalImportName)(code), }) => {
77
+ const signalType = getSignalMappingForTarget(target);
78
+ const map = (path) => {
84
79
  var _a;
85
80
  if (core_1.types.isIdentifier(path.node.typeName) && path.node.typeName.name === signalImportName) {
86
- var params = ((_a = path.node.typeParameters) === null || _a === void 0 ? void 0 : _a.params) || [];
87
- var newType = (signalType === null || signalType === void 0 ? void 0 : signalType.getTypeReference)
81
+ const params = ((_a = path.node.typeParameters) === null || _a === void 0 ? void 0 : _a.params) || [];
82
+ const newType = (signalType === null || signalType === void 0 ? void 0 : signalType.getTypeReference)
88
83
  ? signalType.getTypeReference(params)
89
84
  : // if no mapping exists, drop `Signal` and just use the generic type passed to `Signal` as-is.
90
85
  params[0];
@@ -92,7 +87,7 @@ var mapSignalType = function (_a) {
92
87
  }
93
88
  };
94
89
  return (0, babel_transform_1.babelTransformExpression)(code, {
95
- TSTypeReference: function (path) {
90
+ TSTypeReference(path) {
96
91
  map(path);
97
92
  },
98
93
  });
@@ -104,14 +99,11 @@ exports.mapSignalType = mapSignalType;
104
99
  * - Maps the `Signal` type to the target's equivalent
105
100
  * - Adds the equivalent of the `Signal` import to the file
106
101
  */
107
- var mapSignalTypeInTSFile = function (_a) {
108
- var code = _a.code, target = _a.target;
109
- var signalImportName = (0, exports.getSignalImportName)(code);
102
+ const mapSignalTypeInTSFile = ({ code, target }) => {
103
+ const signalImportName = (0, exports.getSignalImportName)(code);
110
104
  if (!signalImportName) {
111
105
  return code;
112
106
  }
113
- return (0, function_1.pipe)((0, exports.mapSignalType)({ target: target, code: code, signalImportName: signalImportName }), function (code) {
114
- return addSignalImport({ code: code, target: target });
115
- });
107
+ return (0, function_1.pipe)((0, exports.mapSignalType)({ target, code, signalImportName }), (code) => addSignalImport({ code, target }));
116
108
  };
117
109
  exports.mapSignalTypeInTSFile = mapSignalTypeInTSFile;