@builder.io/mitosis 0.0.76 → 0.0.77

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 (50) 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 +0 -3
  10. package/dist/src/generators/angular.js +79 -95
  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/styles/helpers.d.ts +0 -1
  36. package/dist/src/helpers/traverse-nodes.d.ts +1 -1
  37. package/dist/src/helpers/traverse-nodes.js +3 -3
  38. package/dist/src/index.d.ts +1 -1
  39. package/dist/src/index.js +2 -3
  40. package/dist/src/parsers/builder.d.ts +4 -4
  41. package/dist/src/parsers/jsx/function-parser.js +8 -0
  42. package/dist/src/parsers/jsx/metadata.js +17 -1
  43. package/dist/src/parsers/jsx/state.js +6 -1
  44. package/dist/src/plugins/map-styles.js +1 -1
  45. package/dist/src/targets.d.ts +1 -0
  46. package/dist/src/targets.js +2 -0
  47. package/dist/src/types/mitosis-component.d.ts +4 -8
  48. package/dist/tsconfig.build.tsbuildinfo +1 -1
  49. package/jsx-runtime.d.ts +2 -0
  50. package/package.json +7 -9
@@ -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;
@@ -28,7 +28,6 @@ var get_refs_1 = require("../../helpers/get-refs");
28
28
  var get_state_object_string_1 = require("../../helpers/get-state-object-string");
29
29
  var is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
30
30
  var render_imports_1 = require("../../helpers/render-imports");
31
- var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
32
31
  var plugins_1 = require("../../modules/plugins");
33
32
  var strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
34
33
  var getters_to_functions_1 = require("../../helpers/getters-to-functions");
@@ -42,22 +41,30 @@ var merge_options_1 = require("../../helpers/merge-options");
42
41
  var process_code_1 = require("../../helpers/plugins/process-code");
43
42
  var helpers_2 = require("./helpers");
44
43
  var blocks_1 = require("./blocks");
44
+ var patterns_1 = require("../../helpers/patterns");
45
45
  var getContextCode = function (json) {
46
46
  var contextGetters = json.context.get;
47
- return Object.keys(contextGetters)
48
- .map(function (key) { return "let ".concat(key, " = getContext(").concat(contextGetters[key].name, ".key);"); })
47
+ return Object.entries(contextGetters)
48
+ .map(function (_a) {
49
+ var key = _a[0], context = _a[1];
50
+ var name = context.name;
51
+ return "let ".concat(key, " = getContext(").concat(name, ".key);");
52
+ })
49
53
  .join('\n');
50
54
  };
51
- var setContextCode = function (json) {
52
- var contextSetters = json.context.set;
53
- return Object.keys(contextSetters)
54
- .map(function (key) {
55
- var _a = contextSetters[key], ref = _a.ref, value = _a.value, name = _a.name;
56
- return "setContext(".concat(value ? "".concat(name, ".key") : name, ", ").concat(value
57
- ? (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, get_state_object_string_1.stringifyContextValue)(value))
55
+ var setContextCode = function (_a) {
56
+ var json = _a.json, options = _a.options;
57
+ var processCode = (0, helpers_2.stripStateAndProps)({ json: json, options: options });
58
+ return Object.values(json.context.set)
59
+ .map(function (context) {
60
+ var value = context.value, name = context.name, ref = context.ref;
61
+ var key = value ? "".concat(name, ".key") : name;
62
+ var valueStr = value
63
+ ? processCode((0, get_state_object_string_1.stringifyContextValue)(value))
58
64
  : ref
59
- ? (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(ref)
60
- : 'undefined', ");");
65
+ ? processCode(ref)
66
+ : 'undefined';
67
+ return "setContext(".concat(key, ", ").concat(valueStr, ");");
61
68
  })
62
69
  .join('\n');
63
70
  };
@@ -92,20 +99,11 @@ var useBindValue = function (json, options) {
92
99
  }
93
100
  });
94
101
  };
95
- /**
96
- * Removes all `this.` references.
97
- */
98
- var stripThisRefs = function (str) {
99
- return str.replace(/this\.([a-zA-Z_\$0-9]+)/g, '$1');
100
- };
101
102
  var DEFAULT_OPTIONS = {
102
103
  stateType: 'variables',
103
104
  prettier: true,
104
105
  plugins: [functions_1.FUNCTION_HACK_PLUGIN],
105
106
  };
106
- var transformHookCode = function (options) { return function (hookCode) {
107
- return (0, function_1.pipe)((0, helpers_2.stripStateAndProps)(hookCode, options), babel_transform_1.babelTransformCode);
108
- }; };
109
107
  var componentToSvelte = function (userProvidedOptions) {
110
108
  return function (_a) {
111
109
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
@@ -115,12 +113,13 @@ var componentToSvelte = function (userProvidedOptions) {
115
113
  (0, process_code_1.CODE_PROCESSOR_PLUGIN)(function (codeType) {
116
114
  switch (codeType) {
117
115
  case 'hooks':
118
- return transformHookCode(options);
116
+ return (0, function_1.flow)((0, helpers_2.stripStateAndProps)({ json: json, options: options }), babel_transform_1.babelTransformCode);
119
117
  case 'bindings':
120
118
  case 'hooks-deps':
121
119
  case 'state':
120
+ return (0, function_1.flow)((0, helpers_2.stripStateAndProps)({ json: json, options: options }), patterns_1.stripGetter);
122
121
  case 'properties':
123
- return function (c) { return c; };
122
+ return (0, helpers_2.stripStateAndProps)({ json: json, options: options });
124
123
  }
125
124
  }),
126
125
  ], false);
@@ -140,7 +139,6 @@ var componentToSvelte = function (userProvidedOptions) {
140
139
  getters: false,
141
140
  format: options.stateType === 'proxies' ? 'object' : 'variables',
142
141
  keyPrefix: options.stateType === 'variables' ? 'let ' : '',
143
- valueMapper: function (code) { return (0, helpers_2.stripStateAndProps)(code, options); },
144
142
  }), babel_transform_1.babelTransformCode);
145
143
  var getterString = (0, function_1.pipe)((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
146
144
  data: false,
@@ -149,7 +147,10 @@ var componentToSvelte = function (userProvidedOptions) {
149
147
  format: 'variables',
150
148
  keyPrefix: '$: ',
151
149
  valueMapper: function (code) {
152
- return (0, function_1.pipe)(code.replace(/^get ([a-zA-Z_\$0-9]+)/, '$1 = ').replace(/\)/, ') => '), function (str) { return (0, helpers_2.stripStateAndProps)(str, options); }, stripThisRefs);
150
+ return code
151
+ .trim()
152
+ .replace(/^([a-zA-Z_\$0-9]+)/, '$1 = ')
153
+ .replace(/\)/, ') => ');
153
154
  },
154
155
  }), babel_transform_1.babelTransformCode);
155
156
  var functionsString = (0, function_1.pipe)((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
@@ -157,7 +158,6 @@ var componentToSvelte = function (userProvidedOptions) {
157
158
  getters: false,
158
159
  functions: true,
159
160
  format: 'variables',
160
- valueMapper: function (code) { return (0, function_1.pipe)((0, helpers_2.stripStateAndProps)(code, options), stripThisRefs); },
161
161
  }), babel_transform_1.babelTransformCode);
162
162
  var hasData = dataString.length > 4;
163
163
  var str = '';
@@ -167,6 +167,7 @@ var componentToSvelte = function (userProvidedOptions) {
167
167
  }
168
168
  // prepare svelte imports
169
169
  var svelteImports = [];
170
+ var svelteStoreImports = [];
170
171
  if ((_d = (_c = json.hooks.onMount) === null || _c === void 0 ? void 0 : _c.code) === null || _d === void 0 ? void 0 : _d.length) {
171
172
  svelteImports.push('onMount');
172
173
  }
@@ -179,9 +180,11 @@ var componentToSvelte = function (userProvidedOptions) {
179
180
  if ((0, context_1.hasContext)(component)) {
180
181
  svelteImports.push('getContext', 'setContext');
181
182
  }
182
- str += (0, dedent_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n <script ", ">\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n ", "\n \n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "], ["\n <script ", ">\n ", "\n ", "\n\n ", "\n ", "\n "
183
+ str += (0, dedent_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n <script ", ">\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 </script>\n\n ", "\n\n ", "\n "], ["\n <script ", ">\n ", "\n ", "\n\n ", "\n\n ", "\n ", "\n "
183
184
  // https://svelte.dev/repl/bd9b56891f04414982517bbd10c52c82?version=3.31.0
184
- , "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n ", "\n \n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "])), tsLangAttribute, !svelteImports.length ? '' : "import { ".concat(svelteImports.sort().join(', '), " } from 'svelte'"), (0, render_imports_1.renderPreComponent)({ component: json, target: 'svelte' }), !hasData || options.stateType === 'variables' ? '' : "import onChange from 'on-change'", props
185
+ , "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n ", "\n \n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "])), tsLangAttribute, !svelteImports.length ? '' : "import { ".concat(svelteImports.sort().join(', '), " } from 'svelte'"), !svelteStoreImports.length
186
+ ? ''
187
+ : "import { ".concat(svelteStoreImports.sort().join(', '), " } from 'svelte/store'"), (0, render_imports_1.renderPreComponent)({ component: json, target: 'svelte' }), !hasData || options.stateType === 'variables' ? '' : "import onChange from 'on-change'", props
185
188
  .map(function (name) {
186
189
  if (name === 'children') {
187
190
  return '';
@@ -200,17 +203,17 @@ var componentToSvelte = function (userProvidedOptions) {
200
203
  // https://svelte.dev/repl/bd9b56891f04414982517bbd10c52c82?version=3.31.0
201
204
  (0, helpers_1.hasStyle)(json)
202
205
  ? "\n function mitosis_styling (node, vars) {\n Object.entries(vars || {}).forEach(([ p, v ]) => {\n if (p.startsWith('--')) {\n node.style.setProperty(p, v);\n } else {\n node.style[p] = v;\n }\n })\n }\n "
203
- : '', getContextCode(json), setContextCode(json), functionsString.length < 4 ? '' : functionsString, getterString.length < 4 ? '' : getterString, refs.map(function (ref) { return "let ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(ref)); }).join('\n'), options.stateType === 'proxies'
206
+ : '', getContextCode(json), setContextCode({ json: json, options: options }), functionsString.length < 4 ? '' : functionsString, getterString.length < 4 ? '' : getterString, refs.map(function (ref) { return "let ".concat((0, helpers_2.stripStateAndProps)({ json: json, options: options })(ref)); }).join('\n'), options.stateType === 'proxies'
204
207
  ? dataString.length < 4
205
208
  ? ''
206
209
  : "let state = onChange(".concat(dataString, ", () => state = state)")
207
- : dataString, (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_j = (_h = json.hooks.onInit) === null || _h === void 0 ? void 0 : _h.code) !== null && _j !== void 0 ? _j : ''), !((_k = json.hooks.onMount) === null || _k === void 0 ? void 0 : _k.code) ? '' : "onMount(() => { ".concat(json.hooks.onMount.code, " });"), ((_l = json.hooks.onUpdate) === null || _l === void 0 ? void 0 : _l.map(function (_a, index) {
210
+ : dataString, (_j = (_h = json.hooks.onInit) === null || _h === void 0 ? void 0 : _h.code) !== null && _j !== void 0 ? _j : '', !((_k = json.hooks.onMount) === null || _k === void 0 ? void 0 : _k.code) ? '' : "onMount(() => { ".concat(json.hooks.onMount.code, " });"), ((_l = json.hooks.onUpdate) === null || _l === void 0 ? void 0 : _l.map(function (_a, index) {
208
211
  var code = _a.code, deps = _a.deps;
209
212
  if (!deps) {
210
213
  return "afterUpdate(() => { ".concat(code, " });");
211
214
  }
212
215
  var fnName = "onUpdateFn_".concat(index);
213
- return "\n function ".concat(fnName, "() {\n ").concat(code, "\n }\n $: ").concat(fnName, "(...").concat((0, helpers_2.stripStateAndProps)(deps, options), ")\n ");
216
+ return "\n function ".concat(fnName, "() {\n ").concat(code, "\n }\n $: ").concat(fnName, "(...").concat(deps, ")\n ");
214
217
  }).join(';')) || '', !((_m = json.hooks.onUnMount) === null || _m === void 0 ? void 0 : _m.code) ? '' : "onDestroy(() => { ".concat(json.hooks.onUnMount.code, " });"), json.children
215
218
  .map(function (item) {
216
219
  return (0, blocks_1.blockToSvelte)({
@@ -59,7 +59,7 @@ var blockToSwift = function (json, options) {
59
59
  // TODO: Add support for `{props.children}` bindings
60
60
  // Right now we return an empty string because the generated code
61
61
  // is very likely wrong.
62
- if ((0, is_children_1.default)(json)) {
62
+ if ((0, is_children_1.default)({ node: json })) {
63
63
  return '/* `props.children` is not supported yet for SwiftUI */';
64
64
  }
65
65
  if (json.properties._text) {
@@ -236,7 +236,7 @@ var blockToVue = function (node, options, scope) {
236
236
  if (nodeMapper) {
237
237
  return nodeMapper(node, options, scope);
238
238
  }
239
- if ((0, is_children_1.default)(node)) {
239
+ if ((0, is_children_1.default)({ node: node })) {
240
240
  return "<slot/>";
241
241
  }
242
242
  if (node.name === 'style') {
@@ -272,7 +272,9 @@ var blockToVue = function (node, options, scope) {
272
272
  var stringifiedBindings = Object.entries(node.bindings).map(stringifyBinding(node)).join('');
273
273
  str += stringifiedBindings;
274
274
  // spreads
275
- var spreads = (0, lodash_1.filter)(node.bindings, function (binding) { return (binding === null || binding === void 0 ? void 0 : binding.type) === 'spread'; }).map(function (value) { return value === null || value === void 0 ? void 0 : value.code; });
275
+ var spreads = (0, lodash_1.filter)(node.bindings, function (binding) { return (binding === null || binding === void 0 ? void 0 : binding.type) === 'spread'; }).map(function (value) {
276
+ return (value === null || value === void 0 ? void 0 : value.code) === 'props' ? '$props' : value === null || value === void 0 ? void 0 : value.code;
277
+ });
276
278
  if (spreads === null || spreads === void 0 ? void 0 : spreads.length) {
277
279
  if (spreads.length > 1) {
278
280
  var spreadsString = "{...".concat(spreads.join(', ...'), "}");
@@ -36,7 +36,9 @@ function generateCompositionApiScript(component, options, template, props, onUpd
36
36
  functions: false,
37
37
  getters: false,
38
38
  format: 'variables',
39
- valueMapper: function (code) { return "ref(".concat(code, ")"); },
39
+ valueMapper: function (code, _, typeParameter) {
40
+ return options.typescript && typeParameter ? "ref<".concat(typeParameter, ">(").concat(code, ")") : "ref(".concat(code, ")");
41
+ },
40
42
  keyPrefix: 'const',
41
43
  });
42
44
  var methods = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
@@ -9,11 +9,11 @@ export declare const invertBooleanExpression: (expression: string) => string;
9
9
  export declare function encodeQuotes(string: string): string;
10
10
  export declare const renameMitosisComponentsToKebabCase: (str: string) => string;
11
11
  export declare function getContextNames(json: MitosisComponent): string[];
12
- export declare const processBinding: ({ code, options, json, includeProps, }: {
12
+ export declare const processBinding: ({ code, options, json, preserveGetter, }: {
13
13
  code: string;
14
14
  options: ToVueOptions;
15
15
  json: MitosisComponent;
16
- includeProps?: boolean | undefined;
16
+ preserveGetter?: boolean | undefined;
17
17
  }) => string;
18
18
  export declare const getContextValue: ({ options, json }: {
19
19
  options: ToVueOptions;
@@ -27,6 +27,7 @@ var function_1 = require("fp-ts/lib/function");
27
27
  var babel_transform_1 = require("../../helpers/babel-transform");
28
28
  var core_1 = require("@babel/core");
29
29
  var lodash_1 = require("lodash");
30
+ var patterns_1 = require("../../helpers/patterns");
30
31
  var addPropertiesToJson = function (properties) {
31
32
  return function (json) { return (__assign(__assign({}, json), { properties: __assign(__assign({}, json.properties), properties) })); };
32
33
  };
@@ -103,10 +104,12 @@ function processRefs(input, component, options) {
103
104
  // TODO: migrate all stripStateAndPropsRefs to use this here
104
105
  // to properly replace context refs
105
106
  var processBinding = function (_a) {
106
- var code = _a.code, options = _a.options, json = _a.json, _b = _a.includeProps, includeProps = _b === void 0 ? true : _b;
107
+ var code = _a.code, options = _a.options, json = _a.json, _b = _a.preserveGetter, preserveGetter = _b === void 0 ? false : _b;
107
108
  return (0, function_1.pipe)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
108
109
  includeState: true,
109
- includeProps: includeProps,
110
+ // we don't want to process `props` in the Composition API because it has a `props` ref,
111
+ // therefore we can keep pointing to `props.${value}`
112
+ includeProps: options.api === 'options',
110
113
  replaceWith: function (name) {
111
114
  switch (options.api) {
112
115
  case 'composition':
@@ -118,7 +121,12 @@ var processBinding = function (_a) {
118
121
  return "this.".concat(name);
119
122
  }
120
123
  },
121
- }), function (c) { return processRefs(c, json, options); });
124
+ }), function (x) {
125
+ var wasGetter = x.match(patterns_1.GETTER);
126
+ return (0, function_1.pipe)(x,
127
+ // workaround so that getter code is valid and parseable by babel.
128
+ patterns_1.stripGetter, function (code) { return processRefs(code, json, options); }, function (code) { return (preserveGetter && wasGetter ? "get ".concat(code) : code); });
129
+ });
122
130
  };
123
131
  exports.processBinding = processBinding;
124
132
  var getContextValue = function (_a) {
@@ -127,10 +135,10 @@ var getContextValue = function (_a) {
127
135
  var name = _a.name, ref = _a.ref, value = _a.value;
128
136
  var valueStr = value
129
137
  ? (0, get_state_object_string_1.stringifyContextValue)(value, {
130
- valueMapper: function (code) { return (0, exports.processBinding)({ code: code, options: options, json: json }); },
138
+ valueMapper: function (code) { return (0, exports.processBinding)({ code: code, options: options, json: json, preserveGetter: true }); },
131
139
  })
132
140
  : ref
133
- ? (0, exports.processBinding)({ code: ref, options: options, json: json })
141
+ ? (0, exports.processBinding)({ code: ref, options: options, json: json, preserveGetter: true })
134
142
  : null;
135
143
  return valueStr;
136
144
  };
@@ -19,7 +19,6 @@ var get_components_used_1 = require("../../helpers/get-components-used");
19
19
  var get_custom_imports_1 = require("../../helpers/get-custom-imports");
20
20
  var get_state_object_string_1 = require("../../helpers/get-state-object-string");
21
21
  var nullable_1 = require("../../helpers/nullable");
22
- var patterns_1 = require("../../helpers/patterns");
23
22
  var render_imports_1 = require("../../helpers/render-imports");
24
23
  var helpers_1 = require("./helpers");
25
24
  function getContextInjectString(component, options) {
@@ -86,15 +85,11 @@ function generateOptionsApiScript(component, options, path, template, props, onU
86
85
  data: false,
87
86
  getters: true,
88
87
  functions: false,
89
- valueMapper: function (code) {
90
- return (0, helpers_1.processBinding)({ code: code.replace(patterns_1.GETTER, ''), options: options, json: component });
91
- },
92
88
  });
93
89
  var functionsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
94
90
  data: false,
95
91
  getters: false,
96
92
  functions: true,
97
- valueMapper: function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component }); },
98
93
  });
99
94
  var includeClassMapHelper = template.includes('_classStringToObject');
100
95
  if (includeClassMapHelper) {
@@ -42,7 +42,6 @@ var blocks_1 = require("./blocks");
42
42
  var merge_options_1 = require("../../helpers/merge-options");
43
43
  var process_code_1 = require("../../helpers/plugins/process-code");
44
44
  var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
45
- var patterns_1 = require("../../helpers/patterns");
46
45
  // Transform <foo.bar key="value" /> to <component :is="foo.bar" key="value" />
47
46
  function processDynamicComponents(json, _options) {
48
47
  (0, traverse_1.default)(json).forEach(function (node) {
@@ -108,31 +107,9 @@ var componentToVue = function (userOptions) {
108
107
  if (options.api === 'composition') {
109
108
  switch (codeType) {
110
109
  case 'hooks':
111
- return function (code) {
112
- return (0, helpers_1.processBinding)({
113
- code: code,
114
- options: options,
115
- json: component,
116
- // we don't want to process `props`, because Vue 3 code has a `props` ref, and
117
- // therefore we can keep pointing to `props.${value}`
118
- includeProps: false,
119
- });
120
- };
110
+ return function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component }); };
121
111
  case 'state':
122
- return function (code) {
123
- return (0, function_1.pipe)(
124
- // workaround so that getter code is valid and parseable by babel.
125
- code.replace(patterns_1.GETTER, ''), function (c) {
126
- return (0, helpers_1.processBinding)({
127
- code: c,
128
- options: options,
129
- json: component,
130
- // we don't want to process `props`, because Vue 3 code has a `props` ref, and
131
- // therefore we can keep pointing to `props.${value}`
132
- includeProps: false,
133
- });
134
- });
135
- };
112
+ return function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component }); };
136
113
  case 'bindings':
137
114
  return function (c) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(c); };
138
115
  case 'hooks-deps':
@@ -149,8 +126,9 @@ var componentToVue = function (userOptions) {
149
126
  return function (c) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(c); };
150
127
  case 'properties':
151
128
  case 'hooks-deps':
152
- case 'state':
153
129
  return function (c) { return c; };
130
+ case 'state':
131
+ return function (c) { return (0, helpers_1.processBinding)({ code: c, options: options, json: component }); };
154
132
  }
155
133
  }
156
134
  }));
@@ -3,5 +3,6 @@ import type { Visitor } from '@babel/traverse';
3
3
  export declare const babelTransform: <VisitorContextType = any>(code: string, visitor?: babel.Visitor<VisitorContextType> | undefined) => babel.BabelFileResult | null;
4
4
  export declare const babelTransformCode: <VisitorContextType = any>(code: string, visitor?: babel.Visitor<VisitorContextType> | undefined) => string;
5
5
  declare type ExpressionType = 'expression' | 'unknown' | 'block' | 'functionBody';
6
- export declare const babelTransformExpression: <VisitorContextType = any>(code: string, visitor: babel.Visitor<VisitorContextType>, type?: ExpressionType) => string;
6
+ export declare const getType: (code: string, initialType: ExpressionType) => ExpressionType;
7
+ export declare const babelTransformExpression: <VisitorContextType = any>(code: string, visitor: babel.Visitor<VisitorContextType>, initialType?: ExpressionType) => string;
7
8
  export {};