@builder.io/mitosis 0.0.75 → 0.0.77-0

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 (52) hide show
  1. package/dist/src/generators/alpine/generate.d.ts +20 -0
  2. package/dist/src/generators/alpine/generate.js +207 -0
  3. package/dist/src/generators/alpine/index.d.ts +1 -0
  4. package/dist/src/generators/alpine/index.js +17 -0
  5. package/dist/src/generators/alpine/render-mount-hook.d.ts +2 -0
  6. package/dist/src/generators/alpine/render-mount-hook.js +14 -0
  7. package/dist/src/generators/alpine/render-update-hooks.d.ts +5 -0
  8. package/dist/src/generators/alpine/render-update-hooks.js +44 -0
  9. package/dist/src/generators/angular.d.ts +2 -3
  10. package/dist/src/generators/angular.js +89 -97
  11. package/dist/src/generators/helpers/functions.js +2 -1
  12. package/dist/src/generators/html.js +1 -1
  13. package/dist/src/generators/qwik/component-generator.js +8 -1
  14. package/dist/src/generators/svelte/blocks.js +19 -21
  15. package/dist/src/generators/svelte/helpers.d.ts +5 -1
  16. package/dist/src/generators/svelte/helpers.js +8 -5
  17. package/dist/src/generators/svelte/svelte.js +34 -31
  18. package/dist/src/generators/swift-ui.js +1 -1
  19. package/dist/src/generators/vue/blocks.js +4 -2
  20. package/dist/src/generators/vue/compositionApi.js +3 -1
  21. package/dist/src/generators/vue/helpers.d.ts +2 -2
  22. package/dist/src/generators/vue/helpers.js +13 -5
  23. package/dist/src/generators/vue/optionsApi.js +0 -5
  24. package/dist/src/generators/vue/vue.js +4 -26
  25. package/dist/src/helpers/babel-transform.d.ts +2 -1
  26. package/dist/src/helpers/babel-transform.js +16 -19
  27. package/dist/src/helpers/get-state-object-string.d.ts +1 -1
  28. package/dist/src/helpers/get-state-object-string.js +5 -5
  29. package/dist/src/helpers/has-bindings-text.js +1 -1
  30. package/dist/src/helpers/is-children.d.ts +4 -1
  31. package/dist/src/helpers/is-children.js +5 -4
  32. package/dist/src/helpers/patterns.d.ts +1 -0
  33. package/dist/src/helpers/patterns.js +3 -1
  34. package/dist/src/helpers/plugins/process-code.js +1 -1
  35. package/dist/src/helpers/render-imports.d.ts +11 -3
  36. package/dist/src/helpers/render-imports.js +18 -4
  37. package/dist/src/helpers/styles/helpers.d.ts +0 -1
  38. package/dist/src/helpers/traverse-nodes.d.ts +1 -1
  39. package/dist/src/helpers/traverse-nodes.js +3 -3
  40. package/dist/src/index.d.ts +1 -1
  41. package/dist/src/index.js +2 -3
  42. package/dist/src/parsers/builder.d.ts +4 -4
  43. package/dist/src/parsers/jsx/function-parser.js +8 -0
  44. package/dist/src/parsers/jsx/metadata.js +17 -1
  45. package/dist/src/parsers/jsx/state.js +6 -1
  46. package/dist/src/plugins/map-styles.js +1 -1
  47. package/dist/src/targets.d.ts +1 -0
  48. package/dist/src/targets.js +2 -0
  49. package/dist/src/types/mitosis-component.d.ts +4 -8
  50. package/dist/tsconfig.build.tsbuildinfo +1 -1
  51. package/jsx-runtime.d.ts +2 -0
  52. package/package.json +9 -10
@@ -54,85 +54,76 @@ var get_custom_imports_1 = require("../helpers/get-custom-imports");
54
54
  var get_components_used_1 = require("../helpers/get-components-used");
55
55
  var is_upper_case_1 = require("../helpers/is-upper-case");
56
56
  var html_tags_1 = require("../constants/html_tags");
57
+ var function_1 = require("fp-ts/lib/function");
58
+ var merge_options_1 = require("../helpers/merge-options");
59
+ var process_code_1 = require("../helpers/plugins/process-code");
57
60
  var BUILT_IN_COMPONENTS = new Set(['Show', 'For', 'Fragment']);
58
61
  var mappers = {
59
- Fragment: function (json, options, blockOptions) {
60
- return "<div>".concat(json.children
61
- .map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); })
62
- .join('\n'), "</div>");
62
+ Fragment: function (json, options) {
63
+ return "<ng-container>".concat(json.children
64
+ .map(function (item) { return (0, exports.blockToAngular)(item, options); })
65
+ .join('\n'), "</ng-container>");
63
66
  },
64
- Slot: function (json, options, blockOptions) {
65
- return "<ng-content ".concat(Object.keys(json.bindings)
66
- .map(function (binding) {
67
- var _a, _b;
68
- if (binding === 'name') {
69
- var selector = (0, lodash_1.kebabCase)((_b = (_a = json.bindings.name) === null || _a === void 0 ? void 0 : _a.code) === null || _b === void 0 ? void 0 : _b.replace('props.slot', ''));
67
+ Slot: function (json, options) {
68
+ return "<ng-content ".concat(Object.entries(json.bindings)
69
+ .map(function (_a) {
70
+ var binding = _a[0], value = _a[1];
71
+ if (value && binding === 'name') {
72
+ var selector = (0, function_1.pipe)(value.code, slots_1.stripSlotPrefix, lodash_1.kebabCase);
70
73
  return "select=\"[".concat(selector, "]\"");
71
74
  }
72
75
  })
73
- .join('\n'), ">").concat(Object.keys(json.bindings)
74
- .map(function (binding) {
75
- var _a;
76
- if (binding !== 'name') {
77
- return "".concat((_a = json.bindings[binding]) === null || _a === void 0 ? void 0 : _a.code);
76
+ .join('\n'), ">").concat(Object.entries(json.bindings)
77
+ .map(function (_a) {
78
+ var binding = _a[0], value = _a[1];
79
+ if (value && binding !== 'name') {
80
+ return value.code;
78
81
  }
79
82
  })
80
83
  .join('\n'), "</ng-content>");
81
84
  },
82
85
  };
86
+ var generateNgModule = function (content, name, componentsUsed, component, bootstrapMapper) {
87
+ return "import { NgModule } from \"@angular/core\";\nimport { BrowserModule } from \"@angular/platform-browser\";\n\n".concat(content, "\n\n@NgModule({\n declarations: [").concat(name, "],\n imports: [BrowserModule").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 {}");
88
+ };
83
89
  // TODO: Maybe in the future allow defining `string | function` as values
84
90
  var BINDINGS_MAPPER = {
85
91
  innerHTML: 'innerHTML',
86
92
  style: 'ngStyle',
87
93
  };
88
94
  var blockToAngular = function (json, options, blockOptions) {
89
- var _a, _b, _c, _d, _e, _f, _g;
95
+ var _a, _b, _c, _d;
90
96
  if (options === void 0) { options = {}; }
91
97
  if (blockOptions === void 0) { blockOptions = {}; }
92
- var contextVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.contextVars) || [];
93
- var outputVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.outputVars) || [];
94
98
  var childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
95
- var domRefs = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.domRefs) || [];
96
99
  var isValidHtmlTag = html_tags_1.VALID_HTML_TAGS.includes(json.name.trim());
97
100
  if (mappers[json.name]) {
98
- return mappers[json.name](json, options, blockOptions);
101
+ return mappers[json.name](json, options);
99
102
  }
100
- if ((0, is_children_1.default)(json)) {
103
+ if ((0, is_children_1.default)({ node: json })) {
101
104
  return "<ng-content></ng-content>";
102
105
  }
103
106
  if (json.properties._text) {
104
107
  return json.properties._text;
105
108
  }
106
- if (/props\.slot/.test((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code)) {
107
- var selector = (0, lodash_1.kebabCase)((_c = (_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code) === null || _c === void 0 ? void 0 : _c.replace('props.slot', ''));
108
- return "<ng-content select=\"[".concat(selector, "]\"></ng-content>");
109
- }
110
- if ((_d = json.bindings._text) === null || _d === void 0 ? void 0 : _d.code) {
111
- return "{{".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings._text.code, {
112
- // the context is the class
113
- contextVars: [],
114
- outputVars: outputVars,
115
- domRefs: domRefs,
116
- }), "}}");
109
+ var textCode = (_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code;
110
+ if (textCode) {
111
+ if ((0, slots_1.isSlotProperty)(textCode)) {
112
+ var selector = (0, function_1.pipe)(textCode, slots_1.stripSlotPrefix, lodash_1.kebabCase);
113
+ return "<ng-content select=\"[".concat(selector, "]\"></ng-content>");
114
+ }
115
+ return "{{".concat(textCode, "}}");
117
116
  }
118
117
  var str = '';
119
118
  var needsToRenderSlots = [];
120
119
  if ((0, mitosis_node_1.checkIsForNode)(json)) {
121
120
  var indexName = json.scope.indexName;
122
- str += "<ng-container *ngFor=\"let ".concat(json.scope.forName, " of ").concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_e = json.bindings.each) === null || _e === void 0 ? void 0 : _e.code, {
123
- contextVars: contextVars,
124
- outputVars: outputVars,
125
- domRefs: domRefs,
126
- })).concat(indexName ? "; let ".concat(indexName, " = index") : '', "\">");
121
+ str += "<ng-container *ngFor=\"let ".concat(json.scope.forName, " of ").concat((_b = json.bindings.each) === null || _b === void 0 ? void 0 : _b.code).concat(indexName ? "; let ".concat(indexName, " = index") : '', "\">");
127
122
  str += json.children.map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); }).join('\n');
128
123
  str += "</ng-container>";
129
124
  }
130
125
  else if (json.name === 'Show') {
131
- str += "<ng-container *ngIf=\"".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_f = json.bindings.when) === null || _f === void 0 ? void 0 : _f.code, {
132
- contextVars: contextVars,
133
- outputVars: outputVars,
134
- domRefs: domRefs,
135
- }), "\">");
126
+ str += "<ng-container *ngIf=\"".concat((_c = json.bindings.when) === null || _c === void 0 ? void 0 : _c.code, "\">");
136
127
  str += json.children.map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); }).join('\n');
137
128
  str += "</ng-container>";
138
129
  }
@@ -155,19 +146,14 @@ var blockToAngular = function (json, options, blockOptions) {
155
146
  str += " ".concat(key, "=\"").concat(value, "\" ");
156
147
  }
157
148
  for (var key in json.bindings) {
158
- if (((_g = json.bindings[key]) === null || _g === void 0 ? void 0 : _g.type) === 'spread') {
149
+ if (((_d = json.bindings[key]) === null || _d === void 0 ? void 0 : _d.type) === 'spread') {
159
150
  continue;
160
151
  }
161
152
  if (key.startsWith('$')) {
162
153
  continue;
163
154
  }
164
- var _h = json.bindings[key], code = _h.code, _j = _h.arguments, cusArgs = _j === void 0 ? ['event'] : _j;
155
+ var _e = json.bindings[key], code = _e.code, _f = _e.arguments, cusArgs = _f === void 0 ? ['event'] : _f;
165
156
  // TODO: proper babel transform to replace. Util for this
166
- var useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
167
- contextVars: contextVars,
168
- outputVars: outputVars,
169
- domRefs: domRefs,
170
- }).replace(/"/g, '&quot;');
171
157
  if (key.startsWith('on')) {
172
158
  var event_1 = key.replace('on', '').toLowerCase();
173
159
  if (event_1 === 'change' && json.name === 'input' /* todo: other tags */) {
@@ -177,28 +163,28 @@ var blockToAngular = function (json, options, blockOptions) {
177
163
  var eventName = cusArgs[0];
178
164
  var regexp = new RegExp('(^|\\n|\\r| |;|\\(|\\[|!)' + eventName + '(\\?\\.|\\.|\\(| |;|\\)|$)', 'g');
179
165
  var replacer = '$1$event$2';
180
- var finalValue = (0, remove_surrounding_block_1.removeSurroundingBlock)(useValue.replace(regexp, replacer));
166
+ var finalValue = (0, remove_surrounding_block_1.removeSurroundingBlock)(code.replace(regexp, replacer));
181
167
  str += " (".concat(event_1, ")=\"").concat(finalValue, "\" ");
182
168
  }
183
169
  else if (key === 'class') {
184
- str += " [class]=\"".concat(useValue, "\" ");
170
+ str += " [class]=\"".concat(code, "\" ");
185
171
  }
186
172
  else if (key === 'ref') {
187
- str += " #".concat(useValue, " ");
173
+ str += " #".concat(code, " ");
188
174
  }
189
175
  else if ((0, slots_1.isSlotProperty)(key)) {
190
- var lowercaseKey = key.replace('slot', '')[0].toLowerCase() + key.replace('slot', '').substring(1);
191
- needsToRenderSlots.push("".concat(useValue.replace(/(\/\>)|\>/, " ".concat(lowercaseKey, ">"))));
176
+ var lowercaseKey = (0, function_1.pipe)(key, slots_1.stripSlotPrefix, function (x) { return x.toLowerCase(); });
177
+ needsToRenderSlots.push("".concat(code.replace(/(\/\>)|\>/, " ".concat(lowercaseKey, ">"))));
192
178
  }
193
179
  else if (BINDINGS_MAPPER[key]) {
194
- str += " [".concat(BINDINGS_MAPPER[key], "]=\"").concat(useValue, "\" ");
180
+ str += " [".concat(BINDINGS_MAPPER[key], "]=\"").concat(code, "\" ");
195
181
  }
196
182
  else if (isValidHtmlTag || key.includes('-')) {
197
183
  // standard html elements need the attr to satisfy the compiler in many cases: eg: svg elements and [fill]
198
- str += " [attr.".concat(key, "]=\"").concat(useValue, "\" ");
184
+ str += " [attr.".concat(key, "]=\"").concat(code, "\" ");
199
185
  }
200
186
  else {
201
- str += "[".concat(key, "]=\"").concat(useValue, "\" ");
187
+ str += "[".concat(key, "]=\"").concat(code, "\" ");
202
188
  }
203
189
  }
204
190
  if (jsx_1.selfClosingTags.has(json.name)) {
@@ -225,9 +211,42 @@ var componentToAngular = function (userOptions) {
225
211
  preserveImports: false,
226
212
  preserveFileExtensions: false,
227
213
  };
228
- var options = __assign(__assign({}, DEFAULT_OPTIONS), userOptions);
229
214
  // Make a copy we can safely mutate, similar to babel's toolchain
230
215
  var json = (0, fast_clone_1.fastClone)(_component);
216
+ var contextVars = Object.keys(((_b = json === null || json === void 0 ? void 0 : json.context) === null || _b === void 0 ? void 0 : _b.get) || {});
217
+ var metaOutputVars = ((_d = (_c = json.meta) === null || _c === void 0 ? void 0 : _c.useMetadata) === null || _d === void 0 ? void 0 : _d.outputs) || [];
218
+ var outputVars = (0, lodash_1.uniq)(__spreadArray(__spreadArray([], metaOutputVars, true), (0, get_prop_functions_1.getPropFunctions)(json), true));
219
+ var stateVars = Object.keys((json === null || json === void 0 ? void 0 : json.state) || {});
220
+ var options = (0, merge_options_1.mergeOptions)(__assign(__assign({}, DEFAULT_OPTIONS), userOptions));
221
+ options.plugins = __spreadArray(__spreadArray([], (options.plugins || []), true), [
222
+ (0, process_code_1.CODE_PROCESSOR_PLUGIN)(function (codeType) {
223
+ var domRefs = (0, get_refs_1.getRefs)(json);
224
+ switch (codeType) {
225
+ case 'hooks':
226
+ return function (code) {
227
+ return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
228
+ replaceWith: 'this.',
229
+ contextVars: contextVars,
230
+ outputVars: outputVars,
231
+ domRefs: Array.from(domRefs),
232
+ stateVars: stateVars,
233
+ });
234
+ };
235
+ case 'bindings':
236
+ return function (code) {
237
+ return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
238
+ contextVars: [],
239
+ outputVars: outputVars,
240
+ domRefs: [], // the template doesn't need the this keyword.
241
+ }).replace(/"/g, '&quot;');
242
+ };
243
+ case 'hooks-deps':
244
+ case 'state':
245
+ case 'properties':
246
+ return function (x) { return x; };
247
+ }
248
+ }),
249
+ ], false);
231
250
  if (options.plugins) {
232
251
  json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
233
252
  }
@@ -247,8 +266,6 @@ var componentToAngular = function (userOptions) {
247
266
  var localExportVars = Object.keys(localExports)
248
267
  .filter(function (key) { return localExports[key].usedInLocal; })
249
268
  .map(function (key) { return "".concat(key, " = ").concat(key, ";"); });
250
- var metaOutputVars = ((_c = (_b = json.meta) === null || _b === void 0 ? void 0 : _b.useMetadata) === null || _c === void 0 ? void 0 : _c.outputs) || [];
251
- var contextVars = Object.keys(((_d = json === null || json === void 0 ? void 0 : json.context) === null || _d === void 0 ? void 0 : _d.get) || {});
252
269
  var injectables = contextVars.map(function (variableName) {
253
270
  var _a, _b, _c, _d;
254
271
  var variableType = (_a = json === null || json === void 0 ? void 0 : json.context) === null || _a === void 0 ? void 0 : _a.get[variableName].name;
@@ -267,7 +284,6 @@ var componentToAngular = function (userOptions) {
267
284
  props.delete(forwardProp);
268
285
  }
269
286
  props.delete('children');
270
- var outputVars = (0, lodash_1.uniq)(__spreadArray(__spreadArray([], metaOutputVars, true), (0, get_prop_functions_1.getPropFunctions)(json), true));
271
287
  // remove props for outputs
272
288
  outputVars.forEach(function (variableName) {
273
289
  props.delete(variableName);
@@ -282,8 +298,9 @@ var componentToAngular = function (userOptions) {
282
298
  var hasOnMount = Boolean((_f = json.hooks) === null || _f === void 0 ? void 0 : _f.onMount);
283
299
  var domRefs = (0, get_refs_1.getRefs)(json);
284
300
  var jsRefs = Object.keys(json.refs).filter(function (ref) { return !domRefs.has(ref); });
285
- var stateVars = Object.keys((json === null || json === void 0 ? void 0 : json.state) || {});
286
- var componentsUsed = Array.from((0, get_components_used_1.getComponentsUsed)(json)).filter(function (item) { return item.length && (0, is_upper_case_1.isUpperCase)(item[0]) && !BUILT_IN_COMPONENTS.has(item); });
301
+ var componentsUsed = Array.from((0, get_components_used_1.getComponentsUsed)(json)).filter(function (item) {
302
+ return item.length && (0, is_upper_case_1.isUpperCase)(item[0]) && !BUILT_IN_COMPONENTS.has(item);
303
+ });
287
304
  (0, map_refs_1.mapRefs)(json, function (refName) {
288
305
  var isDomRef = domRefs.has(refName);
289
306
  return "this.".concat(isDomRef ? '' : '_').concat(refName).concat(isDomRef ? '.nativeElement' : '');
@@ -295,14 +312,8 @@ var componentToAngular = function (userOptions) {
295
312
  if (options.prettier !== false) {
296
313
  css = tryFormat(css, 'css');
297
314
  }
298
- var blockOptions = {
299
- contextVars: contextVars,
300
- outputVars: outputVars,
301
- domRefs: [],
302
- childComponents: childComponents,
303
- };
304
315
  var template = json.children
305
- .map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); })
316
+ .map(function (item) { return (0, exports.blockToAngular)(item, options, { childComponents: childComponents }); })
306
317
  .join('\n');
307
318
  if (options.prettier !== false) {
308
319
  template = tryFormat(template, 'html');
@@ -337,11 +348,13 @@ var componentToAngular = function (userOptions) {
337
348
  var key = _a[0], value = _a[1];
338
349
  componentMetadata[key] = value;
339
350
  });
340
- var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { ", " ", " Component ", "", " } 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 import { ", " ", " Component ", "", " } 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 "])), outputs.length ? 'Output, EventEmitter, \n' : '', ((_g = options === null || options === void 0 ? void 0 : options.experimental) === null || _g === void 0 ? void 0 : _g.inject) ? 'Inject, forwardRef,' : '', domRefs.size ? ', ViewChild, ElementRef' : '', props.size ? ', Input' : '', options.standalone ? "import { CommonModule } from '@angular/common';" : '', json.types ? json.types.join('\n') : '', !json.defaultProps ? '' : "const defaultProps = ".concat(json5_1.default.stringify(json.defaultProps), "\n"), (0, render_imports_1.renderPreComponent)({
351
+ var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { ", " ", " Component ", "", " } from '@angular/core';\n ", "\n\n ", "\n ", "\n ", "\n\n @Component({\n ", "\n })\n export class ", " {\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n }\n "], ["\n import { ", " ", " Component ", "", " } from '@angular/core';\n ", "\n\n ", "\n ", "\n ", "\n\n @Component({\n ", "\n })\n export class ", " {\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n }\n "])), outputs.length ? 'Output, EventEmitter, \n' : '', ((_g = options === null || options === void 0 ? void 0 : options.experimental) === null || _g === void 0 ? void 0 : _g.inject) ? 'Inject, forwardRef,' : '', domRefs.size ? ', ViewChild, ElementRef' : '', props.size ? ', Input' : '', options.standalone ? "import { CommonModule } from '@angular/common';" : '', json.types ? json.types.join('\n') : '', !json.defaultProps ? '' : "const defaultProps = ".concat(json5_1.default.stringify(json.defaultProps), "\n"), (0, render_imports_1.renderPreComponent)({
341
352
  component: json,
342
353
  target: 'angular',
343
354
  excludeMitosisComponents: !options.standalone && !options.preserveImports,
344
355
  preserveFileExtensions: options.preserveFileExtensions,
356
+ componentsUsed: componentsUsed,
357
+ importMapper: options === null || options === void 0 ? void 0 : options.importMapper,
345
358
  }), Object.entries(componentMetadata)
346
359
  .map(function (_a) {
347
360
  var k = _a[0], v = _a[1];
@@ -377,40 +390,19 @@ var componentToAngular = function (userOptions) {
377
390
  ? ''
378
391
  : "constructor(\n".concat(injectables.join(',\n'), ") {\n ").concat(!((_h = json.hooks) === null || _h === void 0 ? void 0 : _h.onInit)
379
392
  ? ''
380
- : "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_j = json.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code, {
381
- replaceWith: 'this.',
382
- contextVars: contextVars,
383
- outputVars: outputVars,
384
- }), "\n "), "\n }\n "), !hasOnMount
393
+ : "\n ".concat((_j = json.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code, "\n "), "\n }\n "), !hasOnMount
385
394
  ? ''
386
395
  : "ngOnInit() {\n\n ".concat(!((_k = json.hooks) === null || _k === void 0 ? void 0 : _k.onMount)
387
396
  ? ''
388
- : "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_l = json.hooks.onMount) === null || _l === void 0 ? void 0 : _l.code, {
389
- replaceWith: 'this.',
390
- contextVars: contextVars,
391
- outputVars: outputVars,
392
- domRefs: Array.from(domRefs),
393
- stateVars: stateVars,
394
- }), "\n "), "\n }"), !((_m = json.hooks.onUpdate) === null || _m === void 0 ? void 0 : _m.length)
397
+ : "\n ".concat((_l = json.hooks.onMount) === null || _l === void 0 ? void 0 : _l.code, "\n "), "\n }"), !((_m = json.hooks.onUpdate) === null || _m === void 0 ? void 0 : _m.length)
395
398
  ? ''
396
399
  : "ngAfterContentChecked() {\n ".concat(json.hooks.onUpdate.reduce(function (code, hook) {
397
- code += (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(hook.code, {
398
- replaceWith: 'this.',
399
- contextVars: contextVars,
400
- outputVars: outputVars,
401
- domRefs: Array.from(domRefs),
402
- stateVars: stateVars,
403
- });
400
+ code += hook.code;
404
401
  return code + '\n';
405
402
  }, ''), "\n }"), !json.hooks.onUnMount
406
403
  ? ''
407
- : "ngOnDestroy() {\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.hooks.onUnMount.code, {
408
- replaceWith: 'this.',
409
- contextVars: contextVars,
410
- outputVars: outputVars,
411
- domRefs: Array.from(domRefs),
412
- stateVars: stateVars,
413
- }), "\n }"));
404
+ : "ngOnDestroy() {\n ".concat(json.hooks.onUnMount.code, "\n }"));
405
+ str = generateNgModule(str, json.name, componentsUsed, json, options.bootstrapMapper);
414
406
  if (options.plugins) {
415
407
  str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
416
408
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FUNCTION_HACK_PLUGIN = void 0;
4
+ var patterns_1 = require("../../helpers/patterns");
4
5
  var FUNCTION_HACK_PLUGIN = function () { return ({
5
6
  json: {
6
7
  pre: function (json) {
@@ -9,7 +10,7 @@ var FUNCTION_HACK_PLUGIN = function () { return ({
9
10
  var value = (_a = json.state[key]) === null || _a === void 0 ? void 0 : _a.code;
10
11
  var type = (_b = json.state[key]) === null || _b === void 0 ? void 0 : _b.type;
11
12
  if (typeof value === 'string' && type === 'method') {
12
- var newValue = "function ".concat(value);
13
+ var newValue = (0, patterns_1.prefixWithFunction)(value);
13
14
  json.state[key] = {
14
15
  code: newValue,
15
16
  type: 'method',
@@ -209,7 +209,7 @@ var blockToHtml = function (json, options, blockOptions) {
209
209
  if (mappers[json.name]) {
210
210
  return mappers[json.name](json, options, blockOptions);
211
211
  }
212
- if ((0, is_children_1.default)(json)) {
212
+ if ((0, is_children_1.default)({ node: json })) {
213
213
  return "<slot></slot>";
214
214
  }
215
215
  if (json.properties._text) {
@@ -70,6 +70,7 @@ var componentToQwik = function (userOptions) {
70
70
  emitUseRef(file, component);
71
71
  hasState_1 && emitUseStore(file, state_2);
72
72
  emitUseContextProvider(file, component);
73
+ emitUseClientEffect(file, component);
73
74
  emitUseMount(file, component);
74
75
  emitUseWatch(file, component);
75
76
  emitUseCleanup(file, component);
@@ -110,7 +111,7 @@ function emitTagNameHack(file, component, metadataValue) {
110
111
  file.src.emit(metadataValue, '=', (0, convert_method_to_function_1.convertMethodToFunction)(metadataValue, stateToMethodOrGetter(component.state), getLexicalScopeVars(component)), ';');
111
112
  }
112
113
  }
113
- function emitUseMount(file, component) {
114
+ function emitUseClientEffect(file, component) {
114
115
  if (component.hooks.onMount) {
115
116
  // This is called useMount, but in practice it is used as
116
117
  // useClientEffect. Not sure if this is correct, but for now.
@@ -118,6 +119,12 @@ function emitUseMount(file, component) {
118
119
  file.src.emit(file.import(file.qwikModule, 'useClientEffect$').localName, '(()=>{', code, '});');
119
120
  }
120
121
  }
122
+ function emitUseMount(file, component) {
123
+ if (component.hooks.onInit) {
124
+ var code = component.hooks.onInit.code;
125
+ file.src.emit(file.import(file.qwikModule, 'useMount$').localName, '(()=>{', code, '});');
126
+ }
127
+ }
121
128
  function emitUseWatch(file, component) {
122
129
  if (component.hooks.onUpdate) {
123
130
  component.hooks.onUpdate.forEach(function (onUpdate) {
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.blockToSvelte = void 0;
7
- var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
8
7
  var jsx_1 = require("../../parsers/jsx");
9
8
  var is_children_1 = __importDefault(require("../../helpers/is-children"));
10
9
  var remove_surrounding_block_1 = require("../../helpers/remove-surrounding-block");
@@ -40,12 +39,12 @@ var mappers = {
40
39
  delete firstChild.bindings.key;
41
40
  }
42
41
  var args = (0, for_1.getForArguments)(json, { excludeCollectionName: true }).join(', ');
43
- return "\n{#each ".concat((0, helpers_1.stripStateAndProps)((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code, options), " as ").concat(args, " ").concat(keyValue ? "(".concat(keyValue, ")") : '', "}\n").concat(json.children.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "\n{/each}\n");
42
+ return "\n{#each ".concat((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code, " as ").concat(args, " ").concat(keyValue ? "(".concat(keyValue, ")") : '', "}\n").concat(json.children.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "\n{/each}\n");
44
43
  },
45
44
  Show: function (_a) {
46
45
  var _b;
47
46
  var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
48
- return "\n{#if ".concat((0, helpers_1.stripStateAndProps)((_b = json.bindings.when) === null || _b === void 0 ? void 0 : _b.code, options), " }\n").concat(json.children.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "\n\n ").concat(json.meta.else
47
+ return "\n{#if ".concat((_b = json.bindings.when) === null || _b === void 0 ? void 0 : _b.code, " }\n").concat(json.children.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "\n\n ").concat(json.meta.else
49
48
  ? "\n {:else}\n ".concat((0, exports.blockToSvelte)({
50
49
  json: json.meta.else,
51
50
  options: options,
@@ -60,14 +59,13 @@ var mappers = {
60
59
  var key = Object.keys(json.bindings).find(Boolean);
61
60
  if (!key)
62
61
  return '<slot />';
63
- return "\n <span #".concat(key, ">\n ").concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_b = json.bindings[key]) === null || _b === void 0 ? void 0 : _b.code), "\n </span>\n ");
62
+ return "\n <span #".concat(key, ">\n ").concat((_b = json.bindings[key]) === null || _b === void 0 ? void 0 : _b.code, "\n </span>\n ");
64
63
  }
65
- var strippedTextCode = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.name.code);
66
- return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(strippedTextCode).toLowerCase(), "\">").concat((_c = json.children) === null || _c === void 0 ? void 0 : _c.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "</slot>");
64
+ return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(json.bindings.name.code).toLowerCase(), "\">").concat((_c = json.children) === null || _c === void 0 ? void 0 : _c.map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); }).join('\n'), "</slot>");
67
65
  },
68
66
  };
69
67
  var BINDINGS_MAPPER = {
70
- innerHTML: function (json, options) { var _a; return "{@html ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_a = json.bindings.innerHTML) === null || _a === void 0 ? void 0 : _a.code), "}"); },
68
+ innerHTML: function (json, options) { var _a; return "{@html ".concat((_a = json.bindings.innerHTML) === null || _a === void 0 ? void 0 : _a.code, "}"); },
71
69
  };
72
70
  var SVELTE_SPECIAL_TAGS = {
73
71
  COMPONENT: 'svelte:component',
@@ -75,7 +73,7 @@ var SVELTE_SPECIAL_TAGS = {
75
73
  SELF: 'svelte:self',
76
74
  };
77
75
  var getTagName = function (_a) {
78
- var json = _a.json, parentComponent = _a.parentComponent;
76
+ var json = _a.json, parentComponent = _a.parentComponent, options = _a.options;
79
77
  if (parentComponent && json.name === parentComponent.name) {
80
78
  return SVELTE_SPECIAL_TAGS.SELF;
81
79
  }
@@ -89,7 +87,9 @@ var getTagName = function (_a) {
89
87
  // TO-DO: no way to decide between <svelte:component> and <svelte:element>...need to do that through metadata
90
88
  // overrides for now
91
89
  if (!isValidHtmlTag && !isSpecialSvelteTag && !hasMatchingImport) {
92
- json.bindings.this = { code: json.name };
90
+ json.bindings.this = {
91
+ code: (0, helpers_1.stripStateAndProps)({ json: parentComponent, options: options })(json.name),
92
+ };
93
93
  return SVELTE_SPECIAL_TAGS.COMPONENT;
94
94
  }
95
95
  return json.name;
@@ -101,15 +101,14 @@ var stringifyBinding = function (options) {
101
101
  return '';
102
102
  }
103
103
  var code = binding.code, _b = binding.arguments, cusArgs = _b === void 0 ? ['event'] : _b, type = binding.type;
104
- var useValue = (0, helpers_1.stripStateAndProps)(code, options);
105
104
  if (type === 'spread') {
106
- var spreadValue = key === 'props' ? '$$props' : useValue;
105
+ var spreadValue = key === 'props' ? '$$props' : code;
107
106
  return " {...".concat(spreadValue, "} ");
108
107
  }
109
108
  else if (key.startsWith('on')) {
110
109
  var event_1 = key.replace('on', '').toLowerCase();
111
110
  // TODO: handle quotes in event handler values
112
- var valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(useValue);
111
+ var valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(code);
113
112
  if (valueWithoutBlock === key) {
114
113
  return " on:".concat(event_1, "={").concat(valueWithoutBlock, "} ");
115
114
  }
@@ -118,10 +117,10 @@ var stringifyBinding = function (options) {
118
117
  }
119
118
  }
120
119
  else if (key === 'ref') {
121
- return " bind:this={".concat(useValue, "} ");
120
+ return " bind:this={".concat(code, "} ");
122
121
  }
123
122
  else {
124
- return " ".concat(key, "={").concat(useValue, "} ");
123
+ return " ".concat(key, "={").concat(code, "} ");
125
124
  }
126
125
  };
127
126
  };
@@ -135,8 +134,8 @@ var blockToSvelte = function (_a) {
135
134
  parentComponent: parentComponent,
136
135
  });
137
136
  }
138
- var tagName = getTagName({ json: json, parentComponent: parentComponent });
139
- if ((0, is_children_1.default)(json)) {
137
+ var tagName = getTagName({ json: json, parentComponent: parentComponent, options: options });
138
+ if ((0, is_children_1.default)({ node: json, extraMatches: ['$$slots.default'] })) {
140
139
  return "<slot></slot>";
141
140
  }
142
141
  if (json.properties._text) {
@@ -144,17 +143,16 @@ var blockToSvelte = function (_a) {
144
143
  }
145
144
  var textCode = (_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code;
146
145
  if (textCode) {
147
- var strippedTextCode = (0, helpers_1.stripStateAndProps)(textCode, options);
148
- if ((0, slots_1.isSlotProperty)(strippedTextCode)) {
149
- return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(strippedTextCode).toLowerCase(), "\"/>");
146
+ if ((0, slots_1.isSlotProperty)(textCode)) {
147
+ return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(textCode).toLowerCase(), "\"/>");
150
148
  }
151
- return "{".concat(strippedTextCode, "}");
149
+ return "{".concat(textCode, "}");
152
150
  }
153
151
  var str = '';
154
152
  str += "<".concat(tagName, " ");
155
153
  var isComponent = Boolean(tagName[0] && (0, is_upper_case_1.isUpperCase)(tagName[0]));
156
154
  if ((((_c = json.bindings.style) === null || _c === void 0 ? void 0 : _c.code) || json.properties.style) && !isComponent) {
157
- var useValue = (0, helpers_1.stripStateAndProps)(((_d = json.bindings.style) === null || _d === void 0 ? void 0 : _d.code) || json.properties.style, options);
155
+ var useValue = ((_d = json.bindings.style) === null || _d === void 0 ? void 0 : _d.code) || json.properties.style;
158
156
  str += "use:mitosis_styling={".concat(useValue, "}");
159
157
  delete json.bindings.style;
160
158
  delete json.properties.style;
@@ -1,2 +1,6 @@
1
+ import { MitosisComponent } from '../../types/mitosis-component';
1
2
  import { ToSvelteOptions } from './types';
2
- export declare const stripStateAndProps: (code: string | undefined, options: ToSvelteOptions) => string;
3
+ export declare const stripStateAndProps: ({ options, json }: {
4
+ options: ToSvelteOptions;
5
+ json: MitosisComponent;
6
+ }) => (code: string) => string;
@@ -2,10 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stripStateAndProps = void 0;
4
4
  var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
5
- var stripStateAndProps = function (code, options) {
6
- return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
7
- includeState: options.stateType === 'variables',
8
- replaceWith: function (name) { return (name === 'children' ? '$$slots.default' : name); },
9
- });
5
+ var stripStateAndProps = function (_a) {
6
+ var options = _a.options, json = _a.json;
7
+ return function (code) {
8
+ return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
9
+ includeState: options.stateType === 'variables',
10
+ replaceWith: function (name) { return (name === 'children' ? '$$slots.default' : name); },
11
+ });
12
+ };
10
13
  };
11
14
  exports.stripStateAndProps = stripStateAndProps;