@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,97 +1,71 @@
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
- var __assign = (this && this.__assign) || function () {
7
- __assign = Object.assign || function(t) {
8
- for (var s, i = 1, n = arguments.length; i < n; i++) {
9
- s = arguments[i];
10
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11
- t[p] = s[p];
12
- }
13
- return t;
14
- };
15
- return __assign.apply(this, arguments);
16
- };
17
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
- if (ar || !(i in from)) {
20
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
- ar[i] = from[i];
22
- }
23
- }
24
- return to.concat(ar || Array.prototype.slice.call(from));
25
- };
26
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
27
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
28
4
  };
29
5
  Object.defineProperty(exports, "__esModule", { value: true });
30
6
  exports.componentToAngular = exports.blockToAngular = void 0;
31
- var html_tags_1 = require("../../constants/html_tags");
32
- var dedent_1 = require("../../helpers/dedent");
33
- var fast_clone_1 = require("../../helpers/fast-clone");
34
- var get_components_used_1 = require("../../helpers/get-components-used");
35
- var get_custom_imports_1 = require("../../helpers/get-custom-imports");
36
- var get_prop_functions_1 = require("../../helpers/get-prop-functions");
37
- var get_props_1 = require("../../helpers/get-props");
38
- var get_props_ref_1 = require("../../helpers/get-props-ref");
39
- var get_refs_1 = require("../../helpers/get-refs");
40
- var get_state_object_string_1 = require("../../helpers/get-state-object-string");
41
- var indent_1 = require("../../helpers/indent");
42
- var is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
43
- var is_upper_case_1 = require("../../helpers/is-upper-case");
44
- var map_refs_1 = require("../../helpers/map-refs");
45
- var merge_options_1 = require("../../helpers/merge-options");
46
- var process_code_1 = require("../../helpers/plugins/process-code");
47
- var remove_surrounding_block_1 = require("../../helpers/remove-surrounding-block");
48
- var render_imports_1 = require("../../helpers/render-imports");
49
- var replace_identifiers_1 = require("../../helpers/replace-identifiers");
50
- var slots_1 = require("../../helpers/slots");
51
- var strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
52
- var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
53
- var collect_css_1 = require("../../helpers/styles/collect-css");
54
- var helpers_1 = require("../../helpers/styles/helpers");
55
- var traverse_nodes_1 = require("../../helpers/traverse-nodes");
56
- var plugins_1 = require("../../modules/plugins");
57
- var symbol_processor_1 = require("../../symbols/symbol-processor");
58
- var mitosis_node_1 = require("../../types/mitosis-node");
59
- var function_1 = require("fp-ts/lib/function");
60
- var lodash_1 = require("lodash");
61
- var legacy_1 = __importDefault(require("neotraverse/legacy"));
62
- var standalone_1 = require("prettier/standalone");
63
- var is_children_1 = __importDefault(require("../../helpers/is-children"));
64
- var on_mount_1 = require("../helpers/on-mount");
65
- var helpers_2 = require("./helpers");
66
- var types_1 = require("./types");
67
- var mappers = {
68
- Fragment: function (root, json, options) {
69
- return "<ng-container>".concat(json.children
70
- .map(function (item) { return (0, exports.blockToAngular)({ root: root, json: item, options: options }); })
71
- .join('\n'), "</ng-container>");
7
+ const html_tags_1 = require("../../constants/html_tags");
8
+ const dedent_1 = require("../../helpers/dedent");
9
+ const fast_clone_1 = require("../../helpers/fast-clone");
10
+ const get_components_used_1 = require("../../helpers/get-components-used");
11
+ const get_custom_imports_1 = require("../../helpers/get-custom-imports");
12
+ const get_prop_functions_1 = require("../../helpers/get-prop-functions");
13
+ const get_props_1 = require("../../helpers/get-props");
14
+ const get_props_ref_1 = require("../../helpers/get-props-ref");
15
+ const get_refs_1 = require("../../helpers/get-refs");
16
+ const get_state_object_string_1 = require("../../helpers/get-state-object-string");
17
+ const indent_1 = require("../../helpers/indent");
18
+ const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
19
+ const is_upper_case_1 = require("../../helpers/is-upper-case");
20
+ const map_refs_1 = require("../../helpers/map-refs");
21
+ const merge_options_1 = require("../../helpers/merge-options");
22
+ const process_code_1 = require("../../helpers/plugins/process-code");
23
+ const remove_surrounding_block_1 = require("../../helpers/remove-surrounding-block");
24
+ const render_imports_1 = require("../../helpers/render-imports");
25
+ const replace_identifiers_1 = require("../../helpers/replace-identifiers");
26
+ const slots_1 = require("../../helpers/slots");
27
+ const strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
28
+ const strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
29
+ const collect_css_1 = require("../../helpers/styles/collect-css");
30
+ const helpers_1 = require("../../helpers/styles/helpers");
31
+ const traverse_nodes_1 = require("../../helpers/traverse-nodes");
32
+ const plugins_1 = require("../../modules/plugins");
33
+ const symbol_processor_1 = require("../../symbols/symbol-processor");
34
+ const mitosis_node_1 = require("../../types/mitosis-node");
35
+ const function_1 = require("fp-ts/lib/function");
36
+ const lodash_1 = require("lodash");
37
+ const legacy_1 = __importDefault(require("neotraverse/legacy"));
38
+ const standalone_1 = require("prettier/standalone");
39
+ const is_children_1 = __importDefault(require("../../helpers/is-children"));
40
+ const on_mount_1 = require("../helpers/on-mount");
41
+ const helpers_2 = require("./helpers");
42
+ const types_1 = require("./types");
43
+ const mappers = {
44
+ Fragment: (root, json, options) => {
45
+ return `<ng-container>${json.children
46
+ .map((item) => (0, exports.blockToAngular)({ root, json: item, options }))
47
+ .join('\n')}</ng-container>`;
72
48
  },
73
- Slot: function (root, json, options) {
74
- var renderChildren = function () { var _a; return (_a = json.children) === null || _a === void 0 ? void 0 : _a.map(function (item) { return (0, exports.blockToAngular)({ root: root, json: item, options: options }); }).join('\n'); };
75
- return "<ng-content ".concat(Object.entries(__assign(__assign({}, json.bindings), json.properties))
76
- .map(function (_a) {
77
- var binding = _a[0], value = _a[1];
49
+ Slot: (root, json, options) => {
50
+ const renderChildren = () => { var _a; return (_a = json.children) === null || _a === void 0 ? void 0 : _a.map((item) => (0, exports.blockToAngular)({ root, json: item, options })).join('\n'); };
51
+ return `<ng-content ${Object.entries({ ...json.bindings, ...json.properties })
52
+ .map(([binding, value]) => {
78
53
  if (value && binding === 'name') {
79
- var selector = (0, function_1.pipe)((0, lodash_1.isString)(value) ? value : value.code, slots_1.stripSlotPrefix, lodash_1.kebabCase);
80
- return "select=\"[".concat(selector, "]\"");
54
+ const selector = (0, function_1.pipe)((0, lodash_1.isString)(value) ? value : value.code, slots_1.stripSlotPrefix, lodash_1.kebabCase);
55
+ return `select="[${selector}]"`;
81
56
  }
82
57
  })
83
- .join('\n'), ">").concat(Object.entries(json.bindings)
84
- .map(function (_a) {
85
- var binding = _a[0], value = _a[1];
58
+ .join('\n')}>${Object.entries(json.bindings)
59
+ .map(([binding, value]) => {
86
60
  if (value && binding !== 'name') {
87
61
  return value.code;
88
62
  }
89
63
  })
90
- .join('\n')).concat(renderChildren(), "</ng-content>");
64
+ .join('\n')}${renderChildren()}</ng-content>`;
91
65
  },
92
66
  };
93
- var preprocessCssAsJson = function (json) {
94
- (0, legacy_1.default)(json).forEach(function (item) {
67
+ const preprocessCssAsJson = (json) => {
68
+ (0, legacy_1.default)(json).forEach((item) => {
95
69
  var _a, _b;
96
70
  if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
97
71
  if ((0, helpers_1.nodeHasCss)(item)) {
@@ -102,157 +76,155 @@ var preprocessCssAsJson = function (json) {
102
76
  }
103
77
  });
104
78
  };
105
- var generateNgModule = function (content, name, componentsUsed, component, bootstrapMapper) {
106
- return "import { NgModule } from \"@angular/core\";\nimport { CommonModule } from \"@angular/common\";\n\n".concat(content, "\n\n@NgModule({\n declarations: [").concat(name, "],\n imports: [CommonModule").concat(componentsUsed.length ? ', ' + componentsUsed.map(function (comp) { return "".concat(comp, "Module"); }).join(', ') : '', "],\n exports: [").concat(name, "],\n ").concat(bootstrapMapper ? bootstrapMapper(name, componentsUsed, component) : '', "\n})\nexport class ").concat(name, "Module {}");
79
+ const generateNgModule = (content, name, componentsUsed, component, bootstrapMapper) => {
80
+ return `import { NgModule } from "@angular/core";
81
+ import { CommonModule } from "@angular/common";
82
+
83
+ ${content}
84
+
85
+ @NgModule({
86
+ declarations: [${name}],
87
+ imports: [CommonModule${componentsUsed.length ? ', ' + componentsUsed.map((comp) => `${comp}Module`).join(', ') : ''}],
88
+ exports: [${name}],
89
+ ${bootstrapMapper ? bootstrapMapper(name, componentsUsed, component) : ''}
90
+ })
91
+ export class ${name}Module {}`;
107
92
  };
108
93
  // TODO: Maybe in the future allow defining `string | function` as values
109
- var BINDINGS_MAPPER = {
94
+ const BINDINGS_MAPPER = {
110
95
  innerHTML: 'innerHTML',
111
96
  style: 'ngStyle',
112
97
  };
113
- var handleObjectBindings = function (code) {
114
- var objectCode = code.replace(/^{/, '').replace(/}$/, '');
98
+ const handleObjectBindings = (code) => {
99
+ let objectCode = code.replace(/^{/, '').replace(/}$/, '');
115
100
  objectCode = objectCode.replace(/\/\/.*\n/g, '');
116
- var spreadOutObjects = objectCode
117
- .split(',')
118
- .filter(function (item) { return item.includes('...'); })
119
- .map(function (item) { return item.replace('...', '').trim(); });
120
- var objectKeys = objectCode
121
- .split(',')
122
- .filter(function (item) { return !item.includes('...'); })
123
- .map(function (item) { return item.trim(); });
124
- var otherObjs = objectKeys.map(function (item) {
125
- return "{ ".concat(item, " }");
126
- });
127
- var temp = "".concat(spreadOutObjects.join(', '), ", ").concat(otherObjs.join(', '));
128
- if (temp.endsWith(', ')) {
129
- temp = temp.slice(0, -2);
130
- }
131
- if (temp.startsWith(', ')) {
132
- temp = temp.slice(2);
133
- }
101
+ let temp = objectCode;
102
+ //STEP 1. remove spread operator for expressions like '{ ...objectName }' and replace them with object name, example {...obj} => obj
103
+ temp = temp.replace(/\{\s*\.\.\.(\w+)\s*}/g, '$1');
104
+ //STEP 2. remove all remaining spread operators that could be nested somewhere deeper, example { ...obj, field1: value1 } => { obj, field1: value1 }
105
+ temp = temp.replace(/\.\.\./g, '');
106
+ //STEP 3. deal with consequences of STEP 2 - for all left field assignments we create new objects provided to useObjectWrapper,
107
+ //and we get rid of surrounding brackets of the initial input value, example {...obj1,test:true,...obj2} => obj1, {test: true}, obj2
108
+ temp = temp.replace(/(\s*\w+\s*:\s*((["'].+["'])|(\[.+])|([\w.]+)))(,|[\n\s]*)/g, `{ $1 },`);
134
109
  // handle template strings
135
110
  if (temp.includes('`')) {
136
111
  // template str
137
- var str = temp.match(/`[^`]*`/g);
138
- var values = str && str[0].match(/\${[^}]*}/g);
139
- var forValues = values === null || values === void 0 ? void 0 : values.map(function (val) { return val.slice(2, -1); }).join(' + ');
112
+ let str = temp.match(/`[^`]*`/g);
113
+ let values = str && str[0].match(/\${[^}]*}/g);
114
+ let forValues = values === null || values === void 0 ? void 0 : values.map((val) => val.slice(2, -1)).join(' + ');
140
115
  if (str && forValues) {
141
116
  temp = temp.replace(str[0], forValues);
142
117
  }
143
118
  }
144
119
  return temp;
145
120
  };
146
- var processCodeBlockInTemplate = function (code) {
121
+ const processCodeBlockInTemplate = (code) => {
147
122
  // contains helper calls as Angular doesn't support JS expressions in templates
148
- if (code.startsWith('{')) {
123
+ if (code.startsWith('{') && code.includes('...')) {
149
124
  // Objects cannot be spread out directly in Angular so we need to use `useObjectWrapper`
150
- return "useObjectWrapper(".concat(handleObjectBindings(code), ")");
125
+ return `useObjectWrapper(${handleObjectBindings(code)})`;
151
126
  }
152
127
  else if (code.startsWith('Object.values')) {
153
- var stripped = code.replace('Object.values', '');
154
- return "useObjectDotValues".concat(stripped);
128
+ let stripped = code.replace('Object.values', '');
129
+ return `useObjectDotValues${stripped}`;
155
130
  }
156
131
  else if (code.includes('JSON.stringify')) {
157
- var obj = code.match(/JSON.stringify\((.*)\)/);
158
- return "useJsonStringify(".concat(obj, ")");
132
+ let obj = code.match(/JSON.stringify\((.*)\)/);
133
+ return `useJsonStringify(${obj})`;
159
134
  }
160
135
  else if (code.includes(' as ')) {
161
- var asIndex = code.indexOf('as');
162
- var asCode = code.slice(0, asIndex - 1);
163
- return "$any".concat(asCode, ")");
136
+ const asIndex = code.indexOf('as');
137
+ const asCode = code.slice(0, asIndex - 1);
138
+ return `$any${asCode})`;
164
139
  }
165
140
  else {
166
- return "".concat(code);
141
+ return `${code}`;
167
142
  }
168
143
  };
169
- var processEventBinding = function (key, code, nodeName, customArg) {
170
- var event = key.replace('on', '');
144
+ const processEventBinding = (key, code, nodeName, customArg) => {
145
+ let event = key.replace('on', '');
171
146
  event = event.charAt(0).toLowerCase() + event.slice(1);
172
147
  if (event === 'change' && nodeName === 'input' /* todo: other tags */) {
173
148
  event = 'input';
174
149
  }
175
150
  // TODO: proper babel transform to replace. Util for this
176
- var eventName = customArg;
177
- var regexp = new RegExp('(^|\\n|\\r| |;|\\(|\\[|!)' + eventName + '(\\?\\.|\\.|\\(| |;|\\)|$)', 'g');
178
- var replacer = '$1$event$2';
179
- var finalValue = (0, remove_surrounding_block_1.removeSurroundingBlock)(code.replace(regexp, replacer));
151
+ const eventName = customArg;
152
+ const regexp = new RegExp('(^|\\n|\\r| |;|\\(|\\[|!)' + eventName + '(\\?\\.|\\.|\\(| |;|\\)|$)', 'g');
153
+ const replacer = '$1$event$2';
154
+ const finalValue = (0, remove_surrounding_block_1.removeSurroundingBlock)(code.replace(regexp, replacer));
180
155
  return {
181
- event: event,
156
+ event,
182
157
  value: finalValue,
183
158
  };
184
159
  };
185
- var stringifyBinding = function (node, options, blockOptions) {
186
- return function (_a) {
187
- var key = _a[0], binding = _a[1];
188
- if (options.state === 'inline-with-wrappers' && (binding === null || binding === void 0 ? void 0 : binding.type) === 'spread') {
189
- return;
190
- }
191
- if (key.startsWith('$') || key.startsWith('"') || key === 'key') {
192
- return;
193
- }
194
- var keyToUse = BINDINGS_MAPPER[key] || key;
195
- var _b = binding, code = _b.code, _c = _b.arguments, cusArgs = _c === void 0 ? ['event'] : _c;
196
- // TODO: proper babel transform to replace. Util for this
197
- if (keyToUse.startsWith('on')) {
198
- var _d = processEventBinding(keyToUse, code, node.name, cusArgs[0]), event_1 = _d.event, value = _d.value;
199
- return " (".concat(event_1, ")=\"").concat(value, "\"");
200
- }
201
- else if (keyToUse === 'class') {
202
- return " [class]=\"".concat(code, "\" ");
203
- }
204
- else if (keyToUse === 'ref') {
205
- return " #".concat(code, " ");
206
- }
207
- else if ((html_tags_1.VALID_HTML_TAGS.includes(node.name.trim()) || keyToUse.includes('-')) &&
208
- !blockOptions.nativeAttributes.includes(keyToUse) &&
209
- !Object.values(BINDINGS_MAPPER).includes(keyToUse)) {
210
- // standard html elements need the attr to satisfy the compiler in many cases: eg: svg elements and [fill]
211
- return " [attr.".concat(keyToUse, "]=\"").concat(code, "\" ");
212
- }
213
- else {
214
- var codeToUse = options.state === 'inline-with-wrappers' ? processCodeBlockInTemplate(code) : code;
215
- return "[".concat(keyToUse, "]=\"").concat(codeToUse, "\"");
216
- }
217
- };
160
+ const stringifyBinding = (node, options, blockOptions) => ([key, binding]) => {
161
+ if (options.state === 'inline-with-wrappers' && (binding === null || binding === void 0 ? void 0 : binding.type) === 'spread') {
162
+ return;
163
+ }
164
+ if (key.startsWith('$') || key.startsWith('"') || key === 'key') {
165
+ return;
166
+ }
167
+ const keyToUse = BINDINGS_MAPPER[key] || key;
168
+ const { code, arguments: cusArgs = ['event'] } = binding;
169
+ // TODO: proper babel transform to replace. Util for this
170
+ if (keyToUse.startsWith('on')) {
171
+ const { event, value } = processEventBinding(keyToUse, code, node.name, cusArgs[0]);
172
+ return ` (${event})="${value}"`;
173
+ }
174
+ else if (keyToUse === 'class') {
175
+ return ` [class]="${code}" `;
176
+ }
177
+ else if (keyToUse === 'ref') {
178
+ return ` #${code} `;
179
+ }
180
+ else if ((html_tags_1.VALID_HTML_TAGS.includes(node.name.trim()) || keyToUse.includes('-')) &&
181
+ !blockOptions.nativeAttributes.includes(keyToUse) &&
182
+ !Object.values(BINDINGS_MAPPER).includes(keyToUse)) {
183
+ // standard html elements need the attr to satisfy the compiler in many cases: eg: svg elements and [fill]
184
+ return ` [attr.${keyToUse}]="${code}" `;
185
+ }
186
+ else {
187
+ const codeToUse = options.state === 'inline-with-wrappers' ? processCodeBlockInTemplate(code) : code;
188
+ return `[${keyToUse}]="${codeToUse}"`;
189
+ }
218
190
  };
219
- var handleNgOutletBindings = function (node, options) {
191
+ const handleNgOutletBindings = (node, options) => {
220
192
  var _a;
221
- var allProps = '';
222
- for (var key in node.properties) {
193
+ let allProps = '';
194
+ for (const key in node.properties) {
223
195
  if (key.startsWith('$')) {
224
196
  continue;
225
197
  }
226
198
  if (key === 'key') {
227
199
  continue;
228
200
  }
229
- var value = node.properties[key];
230
- allProps += "".concat(key, ": '").concat(value, "', ");
201
+ const value = node.properties[key];
202
+ allProps += `${key}: '${value}', `;
231
203
  }
232
- for (var key in node.bindings) {
204
+ for (const key in node.bindings) {
233
205
  if (key.startsWith('"')) {
234
206
  continue;
235
207
  }
236
208
  if (key.startsWith('$')) {
237
209
  continue;
238
210
  }
239
- var _b = node.bindings[key], code = _b.code, _c = _b.arguments, cusArgs = _c === void 0 ? ['event'] : _c;
211
+ let { code, arguments: cusArgs = ['event'] } = node.bindings[key];
240
212
  if (options.state === 'class-properties') {
241
- code = "this.".concat(code);
213
+ code = `this.${code}`;
242
214
  if (((_a = node.bindings[key]) === null || _a === void 0 ? void 0 : _a.type) === 'spread') {
243
- allProps += "...".concat(code, ", ");
215
+ allProps += `...${code}, `;
244
216
  continue;
245
217
  }
246
218
  }
247
- var keyToUse = key.includes('-') ? "'".concat(key, "'") : key;
219
+ let keyToUse = key.includes('-') ? `'${key}'` : key;
248
220
  keyToUse = keyToUse.replace('state.', '').replace('props.', '');
249
221
  if (key.startsWith('on')) {
250
- var _d = processEventBinding(key, code, node.name, cusArgs[0]), event_2 = _d.event, value = _d.value;
251
- allProps += "on".concat(event_2.charAt(0).toUpperCase() + event_2.slice(1), ": ").concat(value.replace(/\(.*?\)/g, ''), ".bind(this), ");
222
+ const { event, value } = processEventBinding(key, code, node.name, cusArgs[0]);
223
+ allProps += `on${event.charAt(0).toUpperCase() + event.slice(1)}: ${value.replace(/\(.*?\)/g, '')}.bind(this), `;
252
224
  }
253
225
  else {
254
- var codeToUse = options.state === 'inline-with-wrappers' ? processCodeBlockInTemplate(code) : code;
255
- allProps += "".concat(keyToUse, ": ").concat(codeToUse, ", ");
226
+ const codeToUse = options.state === 'inline-with-wrappers' ? processCodeBlockInTemplate(code) : code;
227
+ allProps += `${keyToUse}: ${codeToUse}, `;
256
228
  }
257
229
  }
258
230
  if (allProps.endsWith(', ')) {
@@ -263,126 +235,129 @@ var handleNgOutletBindings = function (node, options) {
263
235
  }
264
236
  return allProps;
265
237
  };
266
- var blockToAngular = function (_a) {
267
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
268
- var root = _a.root, json = _a.json, _m = _a.options, options = _m === void 0 ? {} : _m, _o = _a.blockOptions, blockOptions = _o === void 0 ? {
269
- nativeAttributes: [],
270
- } : _o;
271
- var childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
238
+ const blockToAngular = ({ root, json, options = {}, blockOptions = {
239
+ nativeAttributes: [],
240
+ }, }) => {
241
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
242
+ const childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
272
243
  if (mappers[json.name]) {
273
244
  return mappers[json.name](root, json, options);
274
245
  }
275
246
  if ((0, is_children_1.default)({ node: json })) {
276
- return "<ng-content></ng-content>";
247
+ return `<ng-content></ng-content>`;
277
248
  }
278
249
  if (json.properties._text) {
279
250
  return json.properties._text;
280
251
  }
281
- var textCode = (_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code;
252
+ const textCode = (_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code;
282
253
  if (textCode) {
283
254
  if ((0, slots_1.isSlotProperty)(textCode)) {
284
- return "<ng-content select=\"[".concat((0, slots_1.toKebabSlot)(textCode), "]\"></ng-content>");
255
+ return `<ng-content select="[${(0, slots_1.toKebabSlot)(textCode)}]"></ng-content>`;
285
256
  }
286
257
  if (textCode.includes('JSON.stringify')) {
287
- var obj = textCode.replace(/JSON.stringify\(\s*(\w+)\s*,?.*\)/, '$1');
288
- return "{{".concat(obj, " | json}}");
258
+ const obj = textCode.replace(/JSON.stringify\(\s*(\w+)\s*,?.*\)/, '$1');
259
+ return `{{${obj} | json}}`;
289
260
  }
290
- return "{{".concat(textCode, "}}");
261
+ return `{{${textCode}}}`;
291
262
  }
292
- var str = '';
263
+ let str = '';
293
264
  if ((0, mitosis_node_1.checkIsForNode)(json)) {
294
- var indexName = json.scope.indexName;
295
- var forName = json.scope.forName;
265
+ const indexName = json.scope.indexName;
266
+ const forName = json.scope.forName;
296
267
  // Check if "key" is present for the first child of the for loop
297
- if (json.children[0].bindings && ((_c = json.children[0].bindings.key) === null || _c === void 0 ? void 0 : _c.code)) {
298
- var fnIndex = ((_d = root.meta) === null || _d === void 0 ? void 0 : _d._trackByForIndex) || 0;
299
- var trackByFnName = "trackBy".concat(forName ? forName.charAt(0).toUpperCase() + forName.slice(1) : '').concat(fnIndex);
268
+ if (json.children[0].bindings && ((_b = json.children[0].bindings.key) === null || _b === void 0 ? void 0 : _b.code)) {
269
+ const fnIndex = ((_c = root.meta) === null || _c === void 0 ? void 0 : _c._trackByForIndex) || 0;
270
+ const trackByFnName = `trackBy${forName ? forName.charAt(0).toUpperCase() + forName.slice(1) : ''}${fnIndex}`;
300
271
  root.meta._trackByForIndex = fnIndex + 1;
301
- var code = (_e = json.children[0].bindings.key) === null || _e === void 0 ? void 0 : _e.code;
272
+ let code = (_d = json.children[0].bindings.key) === null || _d === void 0 ? void 0 : _d.code;
302
273
  root.state[trackByFnName] = {
303
- code: "".concat(trackByFnName, "(").concat(indexName !== null && indexName !== void 0 ? indexName : '_', ", ").concat(forName, ") { return ").concat(code, "; }"),
274
+ code: `${trackByFnName}(${indexName !== null && indexName !== void 0 ? indexName : '_'}, ${forName}) { return ${code}; }`,
304
275
  type: 'method',
305
276
  };
306
- str += "<ng-container *ngFor=\"let ".concat(forName, " of ").concat((_f = json.bindings.each) === null || _f === void 0 ? void 0 : _f.code).concat(indexName ? "; let ".concat(indexName, " = index") : '', "; trackBy: ").concat(trackByFnName, "\">");
277
+ str += `<ng-container *ngFor="let ${forName} of ${(_e = json.bindings.each) === null || _e === void 0 ? void 0 : _e.code}${indexName ? `; let ${indexName} = index` : ''}; trackBy: ${trackByFnName}">`;
307
278
  }
308
279
  else {
309
- str += "<ng-container *ngFor=\"let ".concat(forName, " of ").concat((_g = json.bindings.each) === null || _g === void 0 ? void 0 : _g.code).concat(indexName ? "; let ".concat(indexName, " = index") : '', "\">");
280
+ str += `<ng-container *ngFor="let ${forName} of ${(_f = json.bindings.each) === null || _f === void 0 ? void 0 : _f.code}${indexName ? `; let ${indexName} = index` : ''}">`;
310
281
  }
311
282
  str += json.children
312
- .map(function (item) { return (0, exports.blockToAngular)({ root: root, json: item, options: options, blockOptions: blockOptions }); })
283
+ .map((item) => (0, exports.blockToAngular)({ root, json: item, options, blockOptions }))
313
284
  .join('\n');
314
- str += "</ng-container>";
285
+ str += `</ng-container>`;
315
286
  }
316
287
  else if (json.name === 'Show') {
317
- var condition = (_h = json.bindings.when) === null || _h === void 0 ? void 0 : _h.code;
288
+ let condition = (_g = json.bindings.when) === null || _g === void 0 ? void 0 : _g.code;
318
289
  if (options.state === 'inline-with-wrappers' && (condition === null || condition === void 0 ? void 0 : condition.includes('typeof'))) {
319
- var wordAfterTypeof = condition.split('typeof')[1].trim().split(' ')[0];
320
- condition = condition.replace("typeof ".concat(wordAfterTypeof), "useTypeOf(".concat(wordAfterTypeof, ")"));
290
+ let wordAfterTypeof = condition.split('typeof')[1].trim().split(' ')[0];
291
+ condition = condition.replace(`typeof ${wordAfterTypeof}`, `useTypeOf(${wordAfterTypeof})`);
321
292
  }
322
- str += "<ng-container *ngIf=\"".concat(condition, "\">");
293
+ str += `<ng-container *ngIf="${condition}">`;
323
294
  str += json.children
324
- .map(function (item) { return (0, exports.blockToAngular)({ root: root, json: item, options: options, blockOptions: blockOptions }); })
295
+ .map((item) => (0, exports.blockToAngular)({ root, json: item, options, blockOptions }))
325
296
  .join('\n');
326
- str += "</ng-container>";
297
+ str += `</ng-container>`;
327
298
  // else condition
328
- if ((0, is_mitosis_node_1.isMitosisNode)((_j = json.meta) === null || _j === void 0 ? void 0 : _j.else)) {
329
- str += "<ng-container *ngIf=\"!(".concat(condition, ")\">");
330
- str += (0, exports.blockToAngular)({ root: root, json: json.meta.else, options: options, blockOptions: blockOptions });
331
- str += "</ng-container>";
299
+ if ((0, is_mitosis_node_1.isMitosisNode)((_h = json.meta) === null || _h === void 0 ? void 0 : _h.else)) {
300
+ str += `<ng-container *ngIf="!(${condition})">`;
301
+ str += (0, exports.blockToAngular)({ root, json: json.meta.else, options, blockOptions });
302
+ str += `</ng-container>`;
332
303
  }
333
304
  }
334
305
  else if (json.name.includes('.')) {
335
- var elSelector = childComponents.find(function (impName) { return impName === json.name; })
306
+ const elSelector = childComponents.find((impName) => impName === json.name)
336
307
  ? (0, lodash_1.kebabCase)(json.name)
337
308
  : json.name;
338
- var allProps = handleNgOutletBindings(json, options);
309
+ let allProps = handleNgOutletBindings(json, options);
339
310
  if (options.state === 'class-properties') {
340
- var inputsPropsStateName = "mergedInputs_".concat((0, symbol_processor_1.hashCodeAsString)(allProps));
311
+ const inputsPropsStateName = `mergedInputs_${(0, symbol_processor_1.hashCodeAsString)(allProps)}`;
341
312
  root.state[inputsPropsStateName] = {
342
313
  code: '{}' + (options.typescript ? ' as any' : ''),
343
314
  type: 'property',
344
315
  };
345
- if (!((_k = root.hooks.onInit) === null || _k === void 0 ? void 0 : _k.code.includes(inputsPropsStateName))) {
316
+ if (!((_j = root.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code.includes(inputsPropsStateName))) {
346
317
  if (!root.hooks.onInit) {
347
318
  root.hooks.onInit = { code: '' };
348
319
  }
349
- root.hooks.onInit.code += "\nthis.".concat(inputsPropsStateName, " = {").concat(allProps, "};\n");
320
+ root.hooks.onInit.code += `\nthis.${inputsPropsStateName} = {${allProps}};\n`;
350
321
  }
351
- if (!((_l = root.hooks.onUpdate) === null || _l === void 0 ? void 0 : _l.map(function (hook) { return hook.code; }).join('').includes(inputsPropsStateName))) {
322
+ if (!((_k = root.hooks.onUpdate) === null || _k === void 0 ? void 0 : _k.map((hook) => hook.code).join('').includes(inputsPropsStateName))) {
352
323
  if (!root.hooks.onUpdate) {
353
324
  root.hooks.onUpdate = [];
354
325
  }
355
326
  root.hooks.onUpdate.push({
356
- code: "this.".concat(inputsPropsStateName, " = {").concat(allProps, "}"),
327
+ code: `this.${inputsPropsStateName} = {${allProps}}`,
357
328
  });
358
329
  }
359
- allProps = "".concat(inputsPropsStateName);
330
+ allProps = `${inputsPropsStateName}`;
360
331
  }
361
332
  else {
362
- allProps = "{ ".concat(allProps, " }");
363
- }
364
- str += "<ng-container *ngComponentOutlet=\"\n ".concat(elSelector.replace('state.', '').replace('props.', ''), ";\n inputs: ").concat(allProps, ";\n content: myContent;\n \"> ");
365
- str += "</ng-container>";
333
+ allProps = `{ ${allProps} }`;
334
+ }
335
+ str += `<ng-container *ngComponentOutlet="
336
+ ${elSelector.replace('state.', '').replace('props.', '')};
337
+ inputs: ${allProps};
338
+ content: myContent;
339
+ "> `;
340
+ str += `</ng-container>`;
366
341
  }
367
342
  else {
368
- var elSelector = childComponents.find(function (impName) { return impName === json.name; })
343
+ const elSelector = childComponents.find((impName) => impName === json.name)
369
344
  ? (0, lodash_1.kebabCase)(json.name)
370
345
  : json.name;
371
- str += "<".concat(elSelector, " ");
346
+ str += `<${elSelector} `;
372
347
  // TODO: spread support for angular
373
348
  // if (json.bindings._spread) {
374
349
  // str += `v-bind="${stripStateAndPropsRefs(
375
350
  // json.bindings._spread as string,
376
351
  // )}"`;
377
352
  // }
378
- for (var key in json.properties) {
353
+ for (const key in json.properties) {
379
354
  if (key.startsWith('$')) {
380
355
  continue;
381
356
  }
382
- var value = json.properties[key];
383
- str += " ".concat(key, "=\"").concat(value, "\" ");
357
+ const value = json.properties[key];
358
+ str += ` ${key}="${value}" `;
384
359
  }
385
- var stringifiedBindings = Object.entries(json.bindings)
360
+ const stringifiedBindings = Object.entries(json.bindings)
386
361
  .map(stringifyBinding(json, options, blockOptions))
387
362
  .join('');
388
363
  str += stringifiedBindings;
@@ -392,53 +367,46 @@ var blockToAngular = function (_a) {
392
367
  str += '>';
393
368
  if (json.children) {
394
369
  str += json.children
395
- .map(function (item) { return (0, exports.blockToAngular)({ root: root, json: item, options: options, blockOptions: blockOptions }); })
370
+ .map((item) => (0, exports.blockToAngular)({ root, json: item, options, blockOptions }))
396
371
  .join('\n');
397
372
  }
398
- str += "</".concat(elSelector, ">");
373
+ str += `</${elSelector}>`;
399
374
  }
400
375
  return str;
401
376
  };
402
377
  exports.blockToAngular = blockToAngular;
403
- var traverseToGetAllDynamicComponents = function (json, options, blockOptions) {
404
- var components = new Set();
405
- var dynamicTemplate = '';
406
- (0, legacy_1.default)(json).forEach(function (item) {
378
+ const traverseToGetAllDynamicComponents = (json, options, blockOptions) => {
379
+ const components = new Set();
380
+ let dynamicTemplate = '';
381
+ (0, legacy_1.default)(json).forEach((item) => {
407
382
  if ((0, is_mitosis_node_1.isMitosisNode)(item) && item.name.includes('.') && item.name.split('.').length === 2) {
408
- var children = item.children
409
- .map(function (child) { return (0, exports.blockToAngular)({ root: json, json: child, options: options, blockOptions: blockOptions }); })
383
+ const children = item.children
384
+ .map((child) => (0, exports.blockToAngular)({ root: json, json: child, options, blockOptions }))
410
385
  .join('\n');
411
- dynamicTemplate = "<ng-template #".concat(item.name.split('.')[1].toLowerCase() + 'Template', ">").concat(children, "</ng-template>");
386
+ dynamicTemplate = `<ng-template #${item.name.split('.')[1].toLowerCase() + 'Template'}>${children}</ng-template>`;
412
387
  components.add(item.name);
413
388
  }
414
389
  });
415
390
  return {
416
- components: components,
417
- dynamicTemplate: dynamicTemplate,
391
+ components,
392
+ dynamicTemplate,
418
393
  };
419
394
  };
420
- var processAngularCode = function (_a) {
421
- var contextVars = _a.contextVars, outputVars = _a.outputVars, domRefs = _a.domRefs, stateVars = _a.stateVars, replaceWith = _a.replaceWith;
422
- return function (code) {
423
- return (0, function_1.pipe)((0, strip_state_and_props_refs_1.DO_NOT_USE_VARS_TRANSFORMS)(code, {
424
- contextVars: contextVars,
425
- domRefs: domRefs,
426
- outputVars: outputVars,
427
- stateVars: stateVars,
428
- }), function (newCode) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(newCode, { replaceWith: replaceWith }); });
429
- };
395
+ const processAngularCode = ({ contextVars, outputVars, domRefs, stateVars, replaceWith, }) => (code) => (0, function_1.pipe)((0, strip_state_and_props_refs_1.DO_NOT_USE_VARS_TRANSFORMS)(code, {
396
+ contextVars,
397
+ domRefs,
398
+ outputVars,
399
+ stateVars,
400
+ }), (newCode) => (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(newCode, { replaceWith }));
401
+ const isASimpleProperty = (code) => {
402
+ const expressions = ['==', '===', '!=', '!==', '<', '>', '<=', '>='];
403
+ const invalidChars = ['{', '}', '(', ')', 'typeof'];
404
+ return !invalidChars.some((char) => code.includes(char)) && !expressions.includes(code);
430
405
  };
431
- var isASimpleProperty = function (code) {
432
- var expressions = ['==', '===', '!=', '!==', '<', '>', '<=', '>='];
433
- var invalidChars = ['{', '}', '(', ')', 'typeof'];
434
- return !invalidChars.some(function (char) { return code.includes(char); }) && !expressions.includes(code);
435
- };
436
- var generateNewBindingName = function (index, name) {
437
- return "node_".concat(index, "_").concat(name.replaceAll('.', '_').replaceAll('-', '_'));
438
- };
439
- var handleBindings = function (json, item, index, forName, indexName) {
406
+ const generateNewBindingName = (index, name) => `node_${index}_${name.replaceAll('.', '_').replaceAll('-', '_')}`;
407
+ const handleBindings = (json, item, index, forName, indexName) => {
440
408
  var _a, _b, _c, _d, _e, _f, _g, _h;
441
- for (var key in item.bindings) {
409
+ for (const key in item.bindings) {
442
410
  if (key.startsWith('"') ||
443
411
  key.startsWith('$') ||
444
412
  key === 'css' ||
@@ -446,37 +414,37 @@ var handleBindings = function (json, item, index, forName, indexName) {
446
414
  isASimpleProperty(item.bindings[key].code)) {
447
415
  continue;
448
416
  }
449
- var newBindingName = generateNewBindingName(index, item.name);
417
+ const newBindingName = generateNewBindingName(index, item.name);
450
418
  if (forName) {
451
419
  if (item.name === 'For')
452
420
  continue;
453
421
  if (key === 'key')
454
422
  continue;
455
423
  if (key.startsWith('on')) {
456
- var _j = item.bindings[key].arguments, cusArgs = _j === void 0 ? ['event'] : _j;
457
- var eventBindingName = "".concat(generateNewBindingName(index, item.name), "_event");
424
+ const { arguments: cusArgs = ['event'] } = item.bindings[key];
425
+ const eventBindingName = `${generateNewBindingName(index, item.name)}_event`;
458
426
  if (((_a = item.bindings[key]) === null || _a === void 0 ? void 0 : _a.code.trim().startsWith('{')) &&
459
427
  ((_b = item.bindings[key]) === null || _b === void 0 ? void 0 : _b.code.trim().endsWith('}'))) {
460
- var forAndIndex = "".concat(forName ? ", ".concat(forName) : '').concat(indexName ? ", ".concat(indexName) : '');
461
- var eventArgs = "".concat(cusArgs.join(', ')).concat(forAndIndex);
428
+ const forAndIndex = `${forName ? `, ${forName}` : ''}${indexName ? `, ${indexName}` : ''}`;
429
+ const eventArgs = `${cusArgs.join(', ')}${forAndIndex}`;
462
430
  json.state[eventBindingName] = {
463
- code: "(".concat(eventArgs, ") => ").concat(item.bindings[key].code),
431
+ code: `(${eventArgs}) => ${item.bindings[key].code}`,
464
432
  type: 'function',
465
433
  };
466
- item.bindings[key].code = "state.".concat(eventBindingName, "(").concat(eventArgs, ")");
434
+ item.bindings[key].code = `state.${eventBindingName}(${eventArgs})`;
467
435
  json.state[newBindingName] = {
468
- code: "(".concat(eventArgs, ") => (").concat(item.bindings[key].code, ")"),
436
+ code: `(${eventArgs}) => (${item.bindings[key].code})`,
469
437
  type: 'function',
470
438
  };
471
- item.bindings[key].code = "state.".concat(newBindingName, "($").concat(eventArgs, ")");
439
+ item.bindings[key].code = `state.${newBindingName}($${eventArgs})`;
472
440
  }
473
441
  }
474
442
  else {
475
443
  json.state[newBindingName] = {
476
- code: "(".concat(forName).concat(indexName ? ", ".concat(indexName) : '', ") => (").concat(item.bindings[key].code, ")"),
444
+ code: `(${forName}${indexName ? `, ${indexName}` : ''}) => (${item.bindings[key].code})`,
477
445
  type: 'function',
478
446
  };
479
- item.bindings[key].code = "state.".concat(newBindingName, "(").concat(forName).concat(indexName ? ", ".concat(indexName) : '', ")");
447
+ item.bindings[key].code = `state.${newBindingName}(${forName}${indexName ? `, ${indexName}` : ''})`;
480
448
  }
481
449
  }
482
450
  else if ((_c = item.bindings[key]) === null || _c === void 0 ? void 0 : _c.code) {
@@ -485,36 +453,36 @@ var handleBindings = function (json, item, index, forName, indexName) {
485
453
  if (!((_e = json.hooks['onInit']) === null || _e === void 0 ? void 0 : _e.code)) {
486
454
  json.hooks['onInit'] = { code: '' };
487
455
  }
488
- json.hooks['onInit'].code += "\nstate.".concat(newBindingName, " = ").concat(item.bindings[key].code, ";\n");
456
+ json.hooks['onInit'].code += `\nstate.${newBindingName} = ${item.bindings[key].code};\n`;
489
457
  json.hooks['onUpdate'] = json.hooks['onUpdate'] || [];
490
458
  json.hooks['onUpdate'].push({
491
- code: "state.".concat(newBindingName, " = ").concat(item.bindings[key].code),
459
+ code: `state.${newBindingName} = ${item.bindings[key].code}`,
492
460
  });
493
- item.bindings[key].code = "state.".concat(newBindingName);
461
+ item.bindings[key].code = `state.${newBindingName}`;
494
462
  }
495
463
  else if (key.startsWith('on')) {
496
- var _k = item.bindings[key].arguments, cusArgs = _k === void 0 ? ['event'] : _k;
464
+ const { arguments: cusArgs = ['event'] } = item.bindings[key];
497
465
  if (((_f = item.bindings[key]) === null || _f === void 0 ? void 0 : _f.code.trim().startsWith('{')) &&
498
466
  ((_g = item.bindings[key]) === null || _g === void 0 ? void 0 : _g.code.trim().endsWith('}'))) {
499
467
  json.state[newBindingName] = {
500
- code: "(".concat(cusArgs.join(', '), ") => ").concat(item.bindings[key].code),
468
+ code: `(${cusArgs.join(', ')}) => ${item.bindings[key].code}`,
501
469
  type: 'function',
502
470
  };
503
- item.bindings[key].code = "state.".concat(newBindingName, "(").concat(cusArgs.join(', '), ")");
471
+ item.bindings[key].code = `state.${newBindingName}(${cusArgs.join(', ')})`;
504
472
  }
505
473
  }
506
474
  else {
507
- json.state[newBindingName] = { code: "null", type: 'property' };
475
+ json.state[newBindingName] = { code: `null`, type: 'property' };
508
476
  if (!((_h = json.hooks['onInit']) === null || _h === void 0 ? void 0 : _h.code)) {
509
477
  json.hooks['onInit'] = { code: '' };
510
478
  }
511
- json.hooks['onInit'].code += "\nstate.".concat(newBindingName, " = {...(").concat(item.bindings[key].code, ")};\n");
479
+ json.hooks['onInit'].code += `\nstate.${newBindingName} = {...(${item.bindings[key].code})};\n`;
512
480
  json.hooks['onUpdate'] = json.hooks['onUpdate'] || [];
513
481
  json.hooks['onUpdate'].push({
514
- code: "state.".concat(newBindingName, " = {...(").concat(item.bindings[key].code, ")}"),
482
+ code: `state.${newBindingName} = {...(${item.bindings[key].code})}`,
515
483
  });
516
484
  item.bindings[newBindingName] = item.bindings[key];
517
- item.bindings[key].code = "state.".concat(newBindingName);
485
+ item.bindings[key].code = `state.${newBindingName}`;
518
486
  delete item.bindings[key];
519
487
  }
520
488
  }
@@ -522,42 +490,41 @@ var handleBindings = function (json, item, index, forName, indexName) {
522
490
  }
523
491
  return index;
524
492
  };
525
- var handleProperties = function (json, item, index) {
526
- for (var key in item.properties) {
493
+ const handleProperties = (json, item, index) => {
494
+ for (const key in item.properties) {
527
495
  if (key.startsWith('$') || isASimpleProperty(item.properties[key])) {
528
496
  continue;
529
497
  }
530
- var newBindingName = generateNewBindingName(index, item.name);
531
- json.state[newBindingName] = { code: '`' + "".concat(item.properties[key]) + '`', type: 'property' };
532
- item.bindings[key] = { code: "state.".concat(newBindingName), type: 'single' };
498
+ const newBindingName = generateNewBindingName(index, item.name);
499
+ json.state[newBindingName] = { code: '`' + `${item.properties[key]}` + '`', type: 'property' };
500
+ item.bindings[key] = { code: `state.${newBindingName}`, type: 'single' };
533
501
  delete item.properties[key];
534
502
  index++;
535
503
  }
536
504
  return index;
537
505
  };
538
- var handleAngularBindings = function (json, item, index, _a) {
539
- var _b = _a === void 0 ? {} : _a, forName = _b.forName, indexName = _b.indexName;
506
+ const handleAngularBindings = (json, item, index, { forName, indexName } = {}) => {
540
507
  if ((0, is_children_1.default)({ node: item }))
541
508
  return index;
542
509
  index = handleBindings(json, item, index, forName, indexName);
543
510
  index = handleProperties(json, item, index);
544
511
  return index;
545
512
  };
546
- var classPropertiesPlugin = function () { return ({
513
+ const classPropertiesPlugin = () => ({
547
514
  json: {
548
- pre: function (json) {
549
- var lastId = 0;
550
- (0, traverse_nodes_1.traverseNodes)(json, function (item) {
515
+ pre: (json) => {
516
+ let lastId = 0;
517
+ (0, traverse_nodes_1.traverseNodes)(json, (item) => {
551
518
  if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
552
519
  if (item.name === 'For') {
553
- var forName_1 = item.scope.forName;
554
- var indexName_1 = item.scope.indexName;
555
- (0, traverse_nodes_1.traverseNodes)(item, function (child) {
520
+ const forName = item.scope.forName;
521
+ const indexName = item.scope.indexName;
522
+ (0, traverse_nodes_1.traverseNodes)(item, (child) => {
556
523
  if ((0, is_mitosis_node_1.isMitosisNode)(child)) {
557
524
  child._traversed = true;
558
525
  lastId = handleAngularBindings(json, child, lastId, {
559
- forName: forName_1,
560
- indexName: indexName_1,
526
+ forName,
527
+ indexName,
561
528
  });
562
529
  }
563
530
  });
@@ -570,331 +537,380 @@ var classPropertiesPlugin = function () { return ({
570
537
  return json;
571
538
  },
572
539
  },
573
- }); };
540
+ });
574
541
  // if any state "property" is trying to access state.* or props.*
575
542
  // then we need to move them to onInit where they can be accessed
576
- var transformState = function (json) {
543
+ const transformState = (json) => {
577
544
  Object.entries(json.state)
578
545
  .reverse()
579
- .forEach(function (_a) {
580
- var _b;
581
- var key = _a[0], value = _a[1];
546
+ .forEach(([key, value]) => {
547
+ var _a;
582
548
  if ((value === null || value === void 0 ? void 0 : value.type) === 'property') {
583
549
  if (value.code && (value.code.includes('state.') || value.code.includes('props.'))) {
584
- var code = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value.code, { replaceWith: 'this' });
550
+ const code = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value.code, { replaceWith: 'this' });
585
551
  json.state[key].code = 'null';
586
- if (!((_b = json.hooks.onInit) === null || _b === void 0 ? void 0 : _b.code)) {
552
+ if (!((_a = json.hooks.onInit) === null || _a === void 0 ? void 0 : _a.code)) {
587
553
  json.hooks.onInit = { code: '' };
588
554
  }
589
- json.hooks.onInit.code = "\nthis.".concat(key, " = ").concat(code, ";\n").concat(json.hooks.onInit.code);
555
+ json.hooks.onInit.code = `\nthis.${key} = ${code};\n${json.hooks.onInit.code}`;
590
556
  }
591
557
  }
592
558
  });
593
559
  };
594
- var componentToAngular = function (userOptions) {
595
- if (userOptions === void 0) { userOptions = {}; }
596
- return function (_a) {
597
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
598
- var _component = _a.component;
599
- // Make a copy we can safely mutate, similar to babel's toolchain
600
- var json = (0, fast_clone_1.fastClone)(_component);
601
- var useMetadata = (_b = json.meta) === null || _b === void 0 ? void 0 : _b.useMetadata;
602
- var contextVars = Object.keys(((_c = json === null || json === void 0 ? void 0 : json.context) === null || _c === void 0 ? void 0 : _c.get) || {});
603
- // TODO: Why is 'outputs' used here and shouldn't it be typed in packages/core/src/types/metadata.ts
604
- var metaOutputVars = (useMetadata === null || useMetadata === void 0 ? void 0 : useMetadata.outputs) || [];
605
- var outputVars = (0, lodash_1.uniq)(__spreadArray(__spreadArray([], metaOutputVars, true), (0, get_prop_functions_1.getPropFunctions)(json), true));
606
- var stateVars = Object.keys((json === null || json === void 0 ? void 0 : json.state) || {});
607
- var options = (0, merge_options_1.initializeOptions)({
608
- target: 'angular',
609
- component: _component,
610
- defaults: types_1.DEFAULT_ANGULAR_OPTIONS,
611
- userOptions: userOptions,
612
- });
613
- options.plugins = __spreadArray(__spreadArray([], (options.plugins || []), true), [
614
- (0, process_code_1.CODE_PROCESSOR_PLUGIN)(function (codeType) {
615
- switch (codeType) {
616
- case 'hooks':
617
- return (0, function_1.flow)(processAngularCode({
618
- replaceWith: 'this',
619
- contextVars: contextVars,
620
- outputVars: outputVars,
621
- domRefs: Array.from((0, get_refs_1.getRefs)(json)),
622
- stateVars: stateVars,
623
- }), function (code) {
624
- var allMethodNames = Object.entries(json.state)
625
- .filter(function (_a) {
626
- var _ = _a[0], value = _a[1];
627
- return (value === null || value === void 0 ? void 0 : value.type) === 'function' || (value === null || value === void 0 ? void 0 : value.type) === 'method';
628
- })
629
- .map(function (_a) {
630
- var key = _a[0];
631
- return key;
632
- });
633
- return (0, replace_identifiers_1.replaceIdentifiers)({
634
- code: code,
635
- from: allMethodNames,
636
- to: function (name) { return "this.".concat(name); },
637
- });
560
+ const componentToAngular = (userOptions = {}) => ({ component: _component }) => {
561
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
562
+ // Make a copy we can safely mutate, similar to babel's toolchain
563
+ let json = (0, fast_clone_1.fastClone)(_component);
564
+ const useMetadata = (_a = json.meta) === null || _a === void 0 ? void 0 : _a.useMetadata;
565
+ const contextVars = Object.keys(((_b = json === null || json === void 0 ? void 0 : json.context) === null || _b === void 0 ? void 0 : _b.get) || {});
566
+ // TODO: Why is 'outputs' used here and shouldn't it be typed in packages/core/src/types/metadata.ts
567
+ const metaOutputVars = (useMetadata === null || useMetadata === void 0 ? void 0 : useMetadata.outputs) || [];
568
+ const outputVars = (0, lodash_1.uniq)([...metaOutputVars, ...(0, get_prop_functions_1.getPropFunctions)(json)]);
569
+ const stateVars = Object.keys((json === null || json === void 0 ? void 0 : json.state) || {});
570
+ const options = (0, merge_options_1.initializeOptions)({
571
+ target: 'angular',
572
+ component: _component,
573
+ defaults: types_1.DEFAULT_ANGULAR_OPTIONS,
574
+ userOptions: userOptions,
575
+ });
576
+ options.plugins = [
577
+ ...(options.plugins || []),
578
+ (0, process_code_1.CODE_PROCESSOR_PLUGIN)((codeType) => {
579
+ switch (codeType) {
580
+ case 'hooks':
581
+ return (0, function_1.flow)(processAngularCode({
582
+ replaceWith: 'this',
583
+ contextVars,
584
+ outputVars,
585
+ domRefs: Array.from((0, get_refs_1.getRefs)(json)),
586
+ stateVars,
587
+ }), (code) => {
588
+ const allMethodNames = Object.entries(json.state)
589
+ .filter(([_, value]) => (value === null || value === void 0 ? void 0 : value.type) === 'function' || (value === null || value === void 0 ? void 0 : value.type) === 'method')
590
+ .map(([key]) => key);
591
+ return (0, replace_identifiers_1.replaceIdentifiers)({
592
+ code,
593
+ from: allMethodNames,
594
+ to: (name) => `this.${name}`,
638
595
  });
639
- case 'bindings':
640
- return function (code) {
641
- var newLocal = processAngularCode({
642
- contextVars: [],
643
- outputVars: outputVars,
644
- domRefs: [], // the template doesn't need the this keyword.
645
- })(code);
646
- return newLocal.replace(/"/g, '&quot;');
647
- };
648
- case 'hooks-deps':
649
- case 'state':
650
- case 'context-set':
651
- case 'properties':
652
- case 'dynamic-jsx-elements':
653
- case 'types':
654
- return function (x) { return x; };
655
- }
656
- }),
657
- ], false);
658
- if (options.state === 'class-properties') {
659
- options.plugins.push(classPropertiesPlugin);
660
- }
661
- if (options.plugins) {
662
- json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
663
- }
664
- var _o = (0, get_props_ref_1.getPropsRef)(json, true), forwardProp = _o[0], hasPropRef = _o[1];
665
- var childComponents = [];
666
- var propsTypeRef = json.propsTypeRef !== 'any' ? json.propsTypeRef : undefined;
667
- json.imports.forEach(function (_a) {
668
- var imports = _a.imports;
669
- Object.keys(imports).forEach(function (key) {
670
- if (imports[key] === 'default') {
671
- childComponents.push(key);
672
- }
673
- });
674
- });
675
- var customImports = (0, get_custom_imports_1.getCustomImports)(json);
676
- var _p = json.exports, localExports = _p === void 0 ? {} : _p;
677
- var localExportVars = Object.keys(localExports)
678
- .filter(function (key) { return localExports[key].usedInLocal; })
679
- .map(function (key) { return "".concat(key, " = ").concat(key, ";"); });
680
- var injectables = contextVars.map(function (variableName) {
681
- var _a, _b, _c, _d;
682
- var variableType = (_a = json === null || json === void 0 ? void 0 : json.context) === null || _a === void 0 ? void 0 : _a.get[variableName].name;
683
- if ((_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.injectables) {
684
- return (_c = options === null || options === void 0 ? void 0 : options.experimental) === null || _c === void 0 ? void 0 : _c.injectables(variableName, variableType);
685
- }
686
- if ((_d = options === null || options === void 0 ? void 0 : options.experimental) === null || _d === void 0 ? void 0 : _d.inject) {
687
- return "@Inject(forwardRef(() => ".concat(variableType, ")) public ").concat(variableName, ": ").concat(variableType);
596
+ });
597
+ case 'bindings':
598
+ return (code) => {
599
+ const newLocal = processAngularCode({
600
+ contextVars: [],
601
+ outputVars,
602
+ domRefs: [], // the template doesn't need the this keyword.
603
+ })(code);
604
+ return newLocal.replace(/"/g, '&quot;');
605
+ };
606
+ case 'hooks-deps':
607
+ case 'state':
608
+ case 'context-set':
609
+ case 'properties':
610
+ case 'dynamic-jsx-elements':
611
+ case 'types':
612
+ return (x) => x;
688
613
  }
689
- return "public ".concat(variableName, " : ").concat(variableType);
690
- });
691
- var hasConstructor = Boolean(injectables.length);
692
- var props = (0, get_props_1.getProps)(json);
693
- // prevent jsx props from showing up as @Input
694
- if (hasPropRef) {
695
- props.delete(forwardProp);
696
- }
697
- props.delete('children');
698
- // remove props for outputs
699
- outputVars.forEach(function (variableName) {
700
- props.delete(variableName);
701
- });
702
- var outputs = outputVars.map(function (variableName) {
703
- var _a, _b;
704
- if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.outputs) {
705
- return (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.outputs(json, variableName);
614
+ }),
615
+ ];
616
+ if (options.state === 'class-properties') {
617
+ options.plugins.push(classPropertiesPlugin);
618
+ }
619
+ if (options.plugins) {
620
+ json = (0, plugins_1.runPreJsonPlugins)({ json, plugins: options.plugins });
621
+ }
622
+ const [forwardProp, hasPropRef] = (0, get_props_ref_1.getPropsRef)(json, true);
623
+ const childComponents = [];
624
+ const propsTypeRef = json.propsTypeRef !== 'any' ? json.propsTypeRef : undefined;
625
+ json.imports.forEach(({ imports }) => {
626
+ Object.keys(imports).forEach((key) => {
627
+ if (imports[key] === 'default') {
628
+ childComponents.push(key);
706
629
  }
707
- return "@Output() ".concat(variableName, " = new EventEmitter()");
708
630
  });
709
- var domRefs = (0, get_refs_1.getRefs)(json);
710
- var jsRefs = Object.keys(json.refs).filter(function (ref) { return !domRefs.has(ref); });
711
- var componentsUsed = Array.from((0, get_components_used_1.getComponentsUsed)(json)).filter(function (item) {
712
- return item.length && (0, is_upper_case_1.isUpperCase)(item[0]) && !types_1.BUILT_IN_COMPONENTS.has(item);
713
- });
714
- (0, map_refs_1.mapRefs)(json, function (refName) {
715
- var isDomRef = domRefs.has(refName);
716
- return "this.".concat(isDomRef ? '' : '_').concat(refName).concat(isDomRef ? '.nativeElement' : '');
717
- });
718
- if (options.plugins) {
719
- json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
720
- }
721
- preprocessCssAsJson(json);
722
- var css = (0, collect_css_1.collectCss)(json);
723
- if (options.prettier !== false) {
724
- css = tryFormat(css, 'css');
725
- }
726
- var helperFunctions = new Set();
727
- var template = json.children
728
- .map(function (item) {
729
- var _a, _b;
730
- var tmpl = (0, exports.blockToAngular)({
731
- root: json,
732
- json: item,
733
- options: options,
734
- blockOptions: {
735
- childComponents: childComponents,
736
- nativeAttributes: (_b = (_a = useMetadata === null || useMetadata === void 0 ? void 0 : useMetadata.angular) === null || _a === void 0 ? void 0 : _a.nativeAttributes) !== null && _b !== void 0 ? _b : [],
737
- },
738
- });
739
- if (options.state === 'inline-with-wrappers') {
740
- (0, helpers_2.getAppropriateTemplateFunctionKeys)(tmpl).forEach(function (key) {
741
- return helperFunctions.add((0, helpers_2.HELPER_FUNCTIONS)(options.typescript)[key]);
742
- });
743
- }
744
- return tmpl;
745
- })
746
- .join('\n');
747
- if (options.prettier !== false) {
748
- template = tryFormat(template, 'html');
631
+ });
632
+ const customImports = (0, get_custom_imports_1.getCustomImports)(json);
633
+ const { exports: localExports = {} } = json;
634
+ const localExportVars = Object.keys(localExports)
635
+ .filter((key) => localExports[key].usedInLocal)
636
+ .map((key) => `${key} = ${key};`);
637
+ const injectables = contextVars.map((variableName) => {
638
+ var _a, _b, _c, _d;
639
+ const variableType = (_a = json === null || json === void 0 ? void 0 : json.context) === null || _a === void 0 ? void 0 : _a.get[variableName].name;
640
+ if ((_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.injectables) {
641
+ return (_c = options === null || options === void 0 ? void 0 : options.experimental) === null || _c === void 0 ? void 0 : _c.injectables(variableName, variableType);
642
+ }
643
+ if ((_d = options === null || options === void 0 ? void 0 : options.experimental) === null || _d === void 0 ? void 0 : _d.inject) {
644
+ return `@Inject(forwardRef(() => ${variableType})) public ${variableName}: ${variableType}`;
645
+ }
646
+ return `public ${variableName} : ${variableType}`;
647
+ });
648
+ const hasConstructor = Boolean(injectables.length);
649
+ const props = (0, get_props_1.getProps)(json);
650
+ // prevent jsx props from showing up as @Input
651
+ if (hasPropRef) {
652
+ props.delete(forwardProp);
653
+ }
654
+ props.delete('children');
655
+ // remove props for outputs
656
+ outputVars.forEach((variableName) => {
657
+ props.delete(variableName);
658
+ });
659
+ const outputs = outputVars.map((variableName) => {
660
+ var _a, _b;
661
+ if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.outputs) {
662
+ return (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.outputs(json, variableName);
749
663
  }
750
- (0, strip_meta_properties_1.stripMetaProperties)(json);
751
- var _q = traverseToGetAllDynamicComponents(json, options, {
752
- childComponents: childComponents,
753
- nativeAttributes: (_e = (_d = useMetadata === null || useMetadata === void 0 ? void 0 : useMetadata.angular) === null || _d === void 0 ? void 0 : _d.nativeAttributes) !== null && _e !== void 0 ? _e : [],
754
- }), dynamicComponents = _q.components, dynamicTemplate = _q.dynamicTemplate;
755
- transformState(json);
756
- var dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
757
- format: 'class',
758
- valueMapper: processAngularCode({
759
- replaceWith: 'this',
760
- contextVars: contextVars,
761
- outputVars: outputVars,
762
- domRefs: Array.from(domRefs),
763
- stateVars: stateVars,
764
- }),
664
+ return `@Output() ${variableName} = new EventEmitter()`;
665
+ });
666
+ const domRefs = (0, get_refs_1.getRefs)(json);
667
+ const jsRefs = Object.keys(json.refs).filter((ref) => !domRefs.has(ref));
668
+ const componentsUsed = Array.from((0, get_components_used_1.getComponentsUsed)(json)).filter((item) => {
669
+ return item.length && (0, is_upper_case_1.isUpperCase)(item[0]) && !types_1.BUILT_IN_COMPONENTS.has(item);
670
+ });
671
+ (0, map_refs_1.mapRefs)(json, (refName) => {
672
+ const isDomRef = domRefs.has(refName);
673
+ return `this.${isDomRef ? '' : '_'}${refName}${isDomRef ? '.nativeElement' : ''}`;
674
+ });
675
+ if (options.plugins) {
676
+ json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
677
+ }
678
+ preprocessCssAsJson(json);
679
+ let css = (0, collect_css_1.collectCss)(json);
680
+ if (options.prettier !== false) {
681
+ css = tryFormat(css, 'css');
682
+ }
683
+ const helperFunctions = new Set();
684
+ let template = json.children
685
+ .map((item) => {
686
+ var _a, _b;
687
+ const tmpl = (0, exports.blockToAngular)({
688
+ root: json,
689
+ json: item,
690
+ options,
691
+ blockOptions: {
692
+ childComponents,
693
+ nativeAttributes: (_b = (_a = useMetadata === null || useMetadata === void 0 ? void 0 : useMetadata.angular) === null || _a === void 0 ? void 0 : _a.nativeAttributes) !== null && _b !== void 0 ? _b : [],
694
+ },
765
695
  });
766
- var hostDisplayCss = options.visuallyIgnoreHostElement ? ':host { display: contents; }' : '';
767
- var styles = css.length ? [hostDisplayCss, css].join('\n') : hostDisplayCss;
768
- // Preparing built in component metadata parameters
769
- var componentMetadata = __assign(__assign({ selector: "'".concat((0, lodash_1.kebabCase)(json.name || 'my-component'), ", ").concat(json.name, "'"), template: "`\n ".concat((0, indent_1.indent)(dynamicTemplate, 8).replace(/`/g, '\\`').replace(/\$\{/g, '\\${'), "\n ").concat((0, indent_1.indent)(template, 8).replace(/`/g, '\\`').replace(/\$\{/g, '\\${'), "\n `") }, (styles
696
+ if (options.state === 'inline-with-wrappers') {
697
+ (0, helpers_2.getAppropriateTemplateFunctionKeys)(tmpl).forEach((key) => helperFunctions.add((0, helpers_2.HELPER_FUNCTIONS)(options.typescript)[key]));
698
+ }
699
+ return tmpl;
700
+ })
701
+ .join('\n');
702
+ if (options.prettier !== false) {
703
+ template = tryFormat(template, 'html');
704
+ }
705
+ (0, strip_meta_properties_1.stripMetaProperties)(json);
706
+ const { components: dynamicComponents, dynamicTemplate } = traverseToGetAllDynamicComponents(json, options, {
707
+ childComponents,
708
+ nativeAttributes: (_d = (_c = useMetadata === null || useMetadata === void 0 ? void 0 : useMetadata.angular) === null || _c === void 0 ? void 0 : _c.nativeAttributes) !== null && _d !== void 0 ? _d : [],
709
+ });
710
+ transformState(json);
711
+ const dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
712
+ format: 'class',
713
+ valueMapper: processAngularCode({
714
+ replaceWith: 'this',
715
+ contextVars,
716
+ outputVars,
717
+ domRefs: Array.from(domRefs),
718
+ stateVars,
719
+ }),
720
+ });
721
+ const hostDisplayCss = options.visuallyIgnoreHostElement ? ':host { display: contents; }' : '';
722
+ const styles = css.length ? [hostDisplayCss, css].join('\n') : hostDisplayCss;
723
+ // Preparing built in component metadata parameters
724
+ const componentMetadata = {
725
+ selector: `'${(0, lodash_1.kebabCase)(json.name || 'my-component')}, ${json.name}'`,
726
+ template: `\`
727
+ ${(0, indent_1.indent)(dynamicTemplate, 8).replace(/`/g, '\\`').replace(/\$\{/g, '\\${')}
728
+ ${(0, indent_1.indent)(template, 8).replace(/`/g, '\\`').replace(/\$\{/g, '\\${')}
729
+ \``,
730
+ ...(styles
770
731
  ? {
771
- styles: "[`".concat((0, indent_1.indent)(styles, 8), "`]"),
732
+ styles: `[\`${(0, indent_1.indent)(styles, 8)}\`]`,
772
733
  }
773
- : {})), (options.standalone
734
+ : {}),
735
+ ...(options.standalone
774
736
  ? // TODO: also add child component imports here as well
775
737
  {
776
738
  standalone: 'true',
777
- imports: "[".concat(__spreadArray(['CommonModule'], componentsUsed, true).join(', '), "]"),
739
+ imports: `[${['CommonModule', ...componentsUsed].join(', ')}]`,
778
740
  }
779
- : {}));
780
- // Taking into consideration what user has passed in options and allowing them to override the default generated metadata
781
- Object.entries(json.meta.angularConfig || {}).forEach(function (_a) {
782
- var key = _a[0], value = _a[1];
783
- componentMetadata[key] = value;
784
- });
785
- var getPropsDefinition = function (_a) {
786
- var json = _a.json;
787
- if (!json.defaultProps)
788
- return '';
789
- var defalutPropsString = Object.keys(json.defaultProps)
790
- .map(function (prop) {
791
- var _a;
792
- var value = json.defaultProps.hasOwnProperty(prop)
793
- ? (_a = json.defaultProps[prop]) === null || _a === void 0 ? void 0 : _a.code
794
- : 'undefined';
795
- return "".concat(prop, ": ").concat(value);
796
- })
797
- .join(',');
798
- return "const defaultProps = {".concat(defalutPropsString, "};\n");
799
- };
800
- var angularCoreImports = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], (outputs.length ? ['Output', 'EventEmitter'] : []), true), (((_f = options === null || options === void 0 ? void 0 : options.experimental) === null || _f === void 0 ? void 0 : _f.inject) ? ['Inject', 'forwardRef'] : []), true), [
801
- 'Component'
802
- ], false), (domRefs.size || dynamicComponents.size ? ['ViewChild', 'ElementRef'] : []), true), (props.size ? ['Input'] : []), true), (dynamicComponents.size ? ['ViewContainerRef', 'TemplateRef'] : []), true), (((_g = json.hooks.onUpdate) === null || _g === void 0 ? void 0 : _g.length) && options.typescript ? ['SimpleChanges'] : []), true).join(', ');
803
- var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { ", " } from '@angular/core';\n ", "\n\n ", "\n ", "\n ", "\n\n @Component({\n ", "\n })\n export default class ", " {\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 import { ", " } from '@angular/core';\n ", "\n\n ", "\n ", "\n ", "\n\n @Component({\n ", "\n })\n export default class ", " {\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 "])), angularCoreImports, options.standalone ? "import { CommonModule } from '@angular/common';" : '', json.types ? json.types.join('\n') : '', getPropsDefinition({ json: json }), (0, render_imports_1.renderPreComponent)({
804
- explicitImportFileExtension: options.explicitImportFileExtension,
805
- component: json,
806
- target: 'angular',
807
- excludeMitosisComponents: !options.standalone && !options.preserveImports,
808
- preserveFileExtensions: options.preserveFileExtensions,
809
- componentsUsed: componentsUsed,
810
- importMapper: options === null || options === void 0 ? void 0 : options.importMapper,
811
- }), Object.entries(componentMetadata)
812
- .map(function (_a) {
813
- var k = _a[0], v = _a[1];
814
- return "".concat(k, ": ").concat(v);
815
- })
816
- .join(','), json.name, localExportVars.join('\n'), customImports.map(function (name) { return "".concat(name, " = ").concat(name); }).join('\n'), Array.from(props)
817
- .filter(function (item) { return !(0, slots_1.isSlotProperty)(item) && item !== 'children'; })
818
- .map(function (item) {
819
- var propType = propsTypeRef ? "".concat(propsTypeRef, "[\"").concat(item, "\"]") : 'any';
820
- var propDeclaration = "@Input() ".concat(item).concat(options.typescript ? "!: ".concat(propType) : '');
821
- if (json.defaultProps && json.defaultProps.hasOwnProperty(item)) {
822
- propDeclaration += " = defaultProps[\"".concat(item, "\"]");
823
- }
824
- return propDeclaration;
825
- })
826
- .join('\n'), outputs.join('\n'), Array.from(domRefs)
827
- .map(function (refName) {
828
- return "@ViewChild('".concat(refName, "') ").concat(refName).concat(options.typescript ? '!: ElementRef' : '');
829
- })
830
- .join('\n'), Array.from(dynamicComponents)
831
- .map(function (component) {
832
- return "@ViewChild('".concat(component
833
- .split('.')[1]
834
- .toLowerCase(), "Template', { static: true }) ").concat(component
835
- .split('.')[1]
836
- .toLowerCase(), "TemplateRef").concat(options.typescript ? '!: TemplateRef<any>' : '');
837
- })
838
- .join('\n'), dynamicComponents.size ? "myContent".concat(options.typescript ? '?: any[][];' : '') : '', dataString, helperFunctions.size ? Array.from(helperFunctions).join('\n') : '', jsRefs
839
- .map(function (ref) {
840
- var argument = json.refs[ref].argument;
841
- var typeParameter = json.refs[ref].typeParameter;
842
- return "private _".concat(ref).concat(typeParameter ? ": ".concat(typeParameter) : '').concat(argument
843
- ? " = ".concat(processAngularCode({
844
- replaceWith: 'this.',
845
- contextVars: contextVars,
846
- outputVars: outputVars,
847
- domRefs: Array.from(domRefs),
848
- stateVars: stateVars,
849
- })(argument))
850
- : '', ";");
741
+ : {}),
742
+ };
743
+ // Taking into consideration what user has passed in options and allowing them to override the default generated metadata
744
+ Object.entries(json.meta.angularConfig || {}).forEach(([key, value]) => {
745
+ componentMetadata[key] = value;
746
+ });
747
+ const getPropsDefinition = ({ json }) => {
748
+ if (!json.defaultProps)
749
+ return '';
750
+ const defalutPropsString = Object.keys(json.defaultProps)
751
+ .map((prop) => {
752
+ var _a;
753
+ const value = json.defaultProps.hasOwnProperty(prop)
754
+ ? (_a = json.defaultProps[prop]) === null || _a === void 0 ? void 0 : _a.code
755
+ : 'undefined';
756
+ return `${prop}: ${value}`;
851
757
  })
852
- .join('\n'), !hasConstructor && !dynamicComponents.size
853
- ? ''
854
- : "constructor(\n".concat(injectables.join(',\n')).concat(dynamicComponents.size
855
- ? "\nprivate vcRef".concat(options.typescript ? ': ViewContainerRef' : '', ",\n")
856
- : '', ") {}\n "), !json.hooks.onMount.length && !dynamicComponents.size && !((_h = json.hooks.onInit) === null || _h === void 0 ? void 0 : _h.code)
857
- ? ''
858
- : "ngOnInit() {\n ".concat(!((_j = json.hooks) === null || _j === void 0 ? void 0 : _j.onInit)
859
- ? ''
860
- : "\n ".concat((_k = json.hooks.onInit) === null || _k === void 0 ? void 0 : _k.code, "\n "), "\n ").concat(json.hooks.onMount.length > 0
861
- ? "\n if (typeof window !== 'undefined') {\n ".concat((0, on_mount_1.stringifySingleScopeOnMount)(json), "\n }\n ")
862
- : '', "\n ").concat(dynamicComponents.size
863
- ? "\n this.myContent = [".concat(Array.from(dynamicComponents)
864
- .map(function (component) {
865
- return "this.vcRef.createEmbeddedView(this.".concat(component
866
- .split('.')[1]
867
- .toLowerCase(), "TemplateRef).rootNodes");
868
- })
869
- .join(', '), "];\n ")
870
- : '', "\n }"), !((_l = json.hooks.onUpdate) === null || _l === void 0 ? void 0 : _l.length)
871
- ? ''
872
- : "ngOnChanges(changes".concat(options.typescript ? ': SimpleChanges' : '', ") {\n if (typeof window !== 'undefined') {\n ").concat((_m = json.hooks.onUpdate) === null || _m === void 0 ? void 0 : _m.reduce(function (code, hook) {
873
- code += hook.code;
874
- return code + '\n';
875
- }, ''), "\n }\n }\n "), !json.hooks.onUnMount
876
- ? ''
877
- : "ngOnDestroy() {\n ".concat(json.hooks.onUnMount.code, "\n }"));
878
- if (options.standalone !== true) {
879
- str = generateNgModule(str, json.name, componentsUsed, json, options.bootstrapMapper);
880
- }
881
- if (options.plugins) {
882
- str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
883
- }
884
- if (options.prettier !== false) {
885
- str = tryFormat(str, 'typescript');
886
- }
887
- if (options.plugins) {
888
- str = (0, plugins_1.runPostCodePlugins)({ json: json, code: str, plugins: options.plugins });
889
- }
890
- return str;
758
+ .join(',');
759
+ return `const defaultProps = {${defalutPropsString}};\n`;
891
760
  };
761
+ const angularCoreImports = [
762
+ ...(outputs.length ? ['Output', 'EventEmitter'] : []),
763
+ ...(((_e = options === null || options === void 0 ? void 0 : options.experimental) === null || _e === void 0 ? void 0 : _e.inject) ? ['Inject', 'forwardRef'] : []),
764
+ 'Component',
765
+ ...(domRefs.size || dynamicComponents.size ? ['ViewChild', 'ElementRef'] : []),
766
+ ...(props.size ? ['Input'] : []),
767
+ ...(dynamicComponents.size ? ['ViewContainerRef', 'TemplateRef'] : []),
768
+ ...(((_f = json.hooks.onUpdate) === null || _f === void 0 ? void 0 : _f.length) && options.typescript ? ['SimpleChanges'] : []),
769
+ ].join(', ');
770
+ let str = (0, dedent_1.dedent) `
771
+ import { ${angularCoreImports} } from '@angular/core';
772
+ ${options.standalone ? `import { CommonModule } from '@angular/common';` : ''}
773
+
774
+ ${json.types ? json.types.join('\n') : ''}
775
+ ${getPropsDefinition({ json })}
776
+ ${(0, render_imports_1.renderPreComponent)({
777
+ explicitImportFileExtension: options.explicitImportFileExtension,
778
+ component: json,
779
+ target: 'angular',
780
+ excludeMitosisComponents: !options.standalone && !options.preserveImports,
781
+ preserveFileExtensions: options.preserveFileExtensions,
782
+ componentsUsed,
783
+ importMapper: options === null || options === void 0 ? void 0 : options.importMapper,
784
+ })}
785
+
786
+ @Component({
787
+ ${Object.entries(componentMetadata)
788
+ .map(([k, v]) => `${k}: ${v}`)
789
+ .join(',')}
790
+ })
791
+ export default class ${json.name} {
792
+ ${localExportVars.join('\n')}
793
+ ${customImports.map((name) => `${name} = ${name}`).join('\n')}
794
+
795
+ ${Array.from(props)
796
+ .filter((item) => !(0, slots_1.isSlotProperty)(item) && item !== 'children')
797
+ .map((item) => {
798
+ const propType = propsTypeRef ? `${propsTypeRef}["${item}"]` : 'any';
799
+ let propDeclaration = `@Input() ${item}${options.typescript ? `!: ${propType}` : ''}`;
800
+ if (json.defaultProps && json.defaultProps.hasOwnProperty(item)) {
801
+ propDeclaration += ` = defaultProps["${item}"]`;
802
+ }
803
+ return propDeclaration;
804
+ })
805
+ .join('\n')}
806
+
807
+ ${outputs.join('\n')}
808
+
809
+ ${Array.from(domRefs)
810
+ .map((refName) => `@ViewChild('${refName}') ${refName}${options.typescript ? '!: ElementRef' : ''}`)
811
+ .join('\n')}
812
+
813
+ ${Array.from(dynamicComponents)
814
+ .map((component) => `@ViewChild('${component
815
+ .split('.')[1]
816
+ .toLowerCase()}Template', { static: true }) ${component
817
+ .split('.')[1]
818
+ .toLowerCase()}TemplateRef${options.typescript ? '!: TemplateRef<any>' : ''}`)
819
+ .join('\n')}
820
+
821
+ ${dynamicComponents.size ? `myContent${options.typescript ? '?: any[][];' : ''}` : ''}
822
+
823
+ ${dataString}
824
+
825
+ ${helperFunctions.size ? Array.from(helperFunctions).join('\n') : ''}
826
+
827
+ ${jsRefs
828
+ .map((ref) => {
829
+ const argument = json.refs[ref].argument;
830
+ const typeParameter = json.refs[ref].typeParameter;
831
+ return `private _${ref}${typeParameter ? `: ${typeParameter}` : ''}${argument
832
+ ? ` = ${processAngularCode({
833
+ replaceWith: 'this.',
834
+ contextVars,
835
+ outputVars,
836
+ domRefs: Array.from(domRefs),
837
+ stateVars,
838
+ })(argument)}`
839
+ : ''};`;
840
+ })
841
+ .join('\n')}
842
+
843
+ ${!hasConstructor && !dynamicComponents.size
844
+ ? ''
845
+ : `constructor(\n${injectables.join(',\n')}${dynamicComponents.size
846
+ ? `\nprivate vcRef${options.typescript ? ': ViewContainerRef' : ''},\n`
847
+ : ''}) {}
848
+ `}
849
+ ${!json.hooks.onMount.length && !dynamicComponents.size && !((_g = json.hooks.onInit) === null || _g === void 0 ? void 0 : _g.code)
850
+ ? ''
851
+ : `ngOnInit() {
852
+ ${!((_h = json.hooks) === null || _h === void 0 ? void 0 : _h.onInit)
853
+ ? ''
854
+ : `
855
+ ${(_j = json.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code}
856
+ `}
857
+ ${json.hooks.onMount.length > 0
858
+ ? `
859
+ if (typeof window !== 'undefined') {
860
+ ${(0, on_mount_1.stringifySingleScopeOnMount)(json)}
861
+ }
862
+ `
863
+ : ''}
864
+ ${dynamicComponents.size
865
+ ? `
866
+ this.myContent = [${Array.from(dynamicComponents)
867
+ .map((component) => `this.vcRef.createEmbeddedView(this.${component
868
+ .split('.')[1]
869
+ .toLowerCase()}TemplateRef).rootNodes`)
870
+ .join(', ')}];
871
+ `
872
+ : ''}
873
+ }`}
874
+
875
+ ${!((_k = json.hooks.onUpdate) === null || _k === void 0 ? void 0 : _k.length)
876
+ ? ''
877
+ : `ngOnChanges(changes${options.typescript ? ': SimpleChanges' : ''}) {
878
+ if (typeof window !== 'undefined') {
879
+ ${(_l = json.hooks.onUpdate) === null || _l === void 0 ? void 0 : _l.reduce((code, hook) => {
880
+ code += hook.code;
881
+ return code + '\n';
882
+ }, '')}
883
+ }
884
+ }
885
+ `}
886
+
887
+ ${!json.hooks.onUnMount
888
+ ? ''
889
+ : `ngOnDestroy() {
890
+ ${json.hooks.onUnMount.code}
891
+ }`}
892
+
893
+ }
894
+ `;
895
+ if (options.standalone !== true) {
896
+ str = generateNgModule(str, json.name, componentsUsed, json, options.bootstrapMapper);
897
+ }
898
+ if (options.plugins) {
899
+ str = (0, plugins_1.runPreCodePlugins)({ json, code: str, plugins: options.plugins });
900
+ }
901
+ if (options.prettier !== false) {
902
+ str = tryFormat(str, 'typescript');
903
+ }
904
+ if (options.plugins) {
905
+ str = (0, plugins_1.runPostCodePlugins)({ json, code: str, plugins: options.plugins });
906
+ }
907
+ return str;
892
908
  };
893
909
  exports.componentToAngular = componentToAngular;
894
- var tryFormat = function (str, parser) {
910
+ const tryFormat = (str, parser) => {
895
911
  try {
896
912
  return (0, standalone_1.format)(str, {
897
- parser: parser,
913
+ parser,
898
914
  plugins: [
899
915
  // To support running in browsers
900
916
  require('prettier/parser-typescript'),
@@ -910,4 +926,3 @@ var tryFormat = function (str, parser) {
910
926
  }
911
927
  return str;
912
928
  };
913
- var templateObject_1;