@builder.io/mitosis 0.0.82 → 0.0.84

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.
@@ -57,7 +57,7 @@ var html_tags_1 = require("../constants/html_tags");
57
57
  var function_1 = require("fp-ts/lib/function");
58
58
  var merge_options_1 = require("../helpers/merge-options");
59
59
  var process_code_1 = require("../helpers/plugins/process-code");
60
- var BUILT_IN_COMPONENTS = new Set(['Show', 'For', 'Fragment']);
60
+ var BUILT_IN_COMPONENTS = new Set(['Show', 'For', 'Fragment', 'Slot']);
61
61
  var mappers = {
62
62
  Fragment: function (json, options) {
63
63
  return "<ng-container>".concat(json.children
@@ -85,7 +85,7 @@ var mappers = {
85
85
  },
86
86
  };
87
87
  var generateNgModule = function (content, name, componentsUsed, component, bootstrapMapper) {
88
- 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
+ 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 {}");
89
89
  };
90
90
  // TODO: Maybe in the future allow defining `string | function` as values
91
91
  var BINDINGS_MAPPER = {
@@ -0,0 +1,5 @@
1
+ import { MitosisContext } from '../../../types/mitosis-context';
2
+ import { BaseTranspilerOptions } from '../../../types/transpiler';
3
+ export declare const getContextWithSymbolKey: (options: Pick<BaseTranspilerOptions, 'prettier'>) => ({ context }: {
4
+ context: MitosisContext;
5
+ }) => string;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getContextWithSymbolKey = void 0;
4
+ var standalone_1 = require("prettier/standalone");
5
+ var get_state_object_string_1 = require("../../../helpers/get-state-object-string");
6
+ var getContextWithSymbolKey = function (options) {
7
+ return function (_a) {
8
+ var context = _a.context;
9
+ var str = "\n const key = Symbol(); \n\n export default {\n ".concat(context.name, ": ").concat((0, get_state_object_string_1.stringifyContextValue)(context.value), ", \n key \n }\n ");
10
+ if (options.prettier !== false) {
11
+ try {
12
+ str = (0, standalone_1.format)(str, {
13
+ parser: 'typescript',
14
+ plugins: [
15
+ require('prettier/parser-typescript'), // To support running in browsers
16
+ ],
17
+ });
18
+ }
19
+ catch (err) {
20
+ console.error('Format error for file:', str);
21
+ throw err;
22
+ }
23
+ }
24
+ return str;
25
+ };
26
+ };
27
+ exports.getContextWithSymbolKey = getContextWithSymbolKey;
@@ -1,11 +1,7 @@
1
- import { MitosisContext } from '../../types/mitosis-context';
2
1
  import { BaseTranspilerOptions } from '../../types/transpiler';
3
- interface ContextToSvelteOptions extends Pick<BaseTranspilerOptions, 'prettier'> {
4
- }
5
2
  /**
6
3
  * TO-DO: support types
7
4
  */
8
- export declare const contextToSvelte: (options?: ContextToSvelteOptions) => ({ context }: {
9
- context: MitosisContext;
5
+ export declare const contextToSvelte: (options: Pick<BaseTranspilerOptions, "prettier">) => ({ context }: {
6
+ context: import("../../types/mitosis-context").MitosisContext;
10
7
  }) => string;
11
- export {};
@@ -1,31 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.contextToSvelte = void 0;
4
- var standalone_1 = require("prettier/standalone");
5
- var get_state_object_string_1 = require("../../helpers/get-state-object-string");
4
+ var context_with_symbol_key_1 = require("./helpers/context-with-symbol-key");
6
5
  /**
7
6
  * TO-DO: support types
8
7
  */
9
- var contextToSvelte = function (options) {
10
- if (options === void 0) { options = {}; }
11
- return function (_a) {
12
- var context = _a.context;
13
- var str = "\n const key = Symbol(); \n\n export default {\n ".concat(context.name, ": ").concat((0, get_state_object_string_1.stringifyContextValue)(context.value), ", \n key \n }\n ");
14
- if (options.prettier !== false) {
15
- try {
16
- str = (0, standalone_1.format)(str, {
17
- parser: 'typescript',
18
- plugins: [
19
- require('prettier/parser-typescript'), // To support running in browsers
20
- ],
21
- });
22
- }
23
- catch (err) {
24
- console.error('Format error for file:', str);
25
- throw err;
26
- }
27
- }
28
- return str;
29
- };
30
- };
31
- exports.contextToSvelte = contextToSvelte;
8
+ exports.contextToSvelte = context_with_symbol_key_1.getContextWithSymbolKey;
@@ -1,6 +1,3 @@
1
- import { MitosisContext } from '../../types/mitosis-context';
2
- declare type ContextToVueOptions = {
3
- format?: boolean;
4
- };
5
- export declare function contextToVue(context: MitosisContext, options?: ContextToVueOptions): string;
6
- export {};
1
+ export declare const contextToVue: (options: Pick<import("../..").BaseTranspilerOptions, "prettier">) => ({ context }: {
2
+ context: import("../../types/mitosis-context").MitosisContext;
3
+ }) => string;
@@ -1,9 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.contextToVue = void 0;
4
- function contextToVue(context, options) {
5
- if (options === void 0) { options = {}; }
6
- var str = "\n // Noop file\n export default {};\n ";
7
- return str;
8
- }
9
- exports.contextToVue = contextToVue;
4
+ var context_with_symbol_key_1 = require("./helpers/context-with-symbol-key");
5
+ exports.contextToVue = context_with_symbol_key_1.getContextWithSymbolKey;
@@ -0,0 +1,8 @@
1
+ import { MitosisComponent } from '../../types/mitosis-component';
2
+ import { MitosisNode } from '../../types/mitosis-node';
3
+ import { ToSolidOptions } from './types';
4
+ export declare const blockToSolid: ({ json, options, component, }: {
5
+ json: MitosisNode;
6
+ options: ToSolidOptions;
7
+ component: MitosisComponent;
8
+ }) => string;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.blockToSolid = void 0;
4
+ var core_1 = require("@babel/core");
5
+ var lodash_1 = require("lodash");
6
+ var babel_transform_1 = require("../../helpers/babel-transform");
7
+ var filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
8
+ var typescript_1 = require("../../helpers/typescript");
9
+ var jsx_1 = require("../../parsers/jsx");
10
+ var mitosis_node_1 = require("../../types/mitosis-node");
11
+ var styles_1 = require("./helpers/styles");
12
+ var ATTTRIBUTE_MAPPERS = {
13
+ for: 'htmlFor',
14
+ };
15
+ var transformAttributeName = function (name) {
16
+ if ((0, typescript_1.objectHasKey)(ATTTRIBUTE_MAPPERS, name))
17
+ return ATTTRIBUTE_MAPPERS[name];
18
+ return name;
19
+ };
20
+ var blockToSolid = function (_a) {
21
+ var _b, _c;
22
+ var json = _a.json, options = _a.options, component = _a.component;
23
+ if (json.properties._text) {
24
+ return json.properties._text;
25
+ }
26
+ if ((_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code) {
27
+ return "{".concat(json.bindings._text.code, "}");
28
+ }
29
+ if ((0, mitosis_node_1.checkIsForNode)(json)) {
30
+ var needsWrapper = json.children.length !== 1;
31
+ // The SolidJS `<For>` component has a special index() signal function.
32
+ // https://www.solidjs.com/docs/latest#%3Cfor%3E
33
+ return "<For each={".concat((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code, "}>\n {(").concat(json.scope.forName, ", _index) => {\n const ").concat(json.scope.indexName || 'index', " = _index();\n return ").concat(needsWrapper ? '<>' : '').concat(json.children
34
+ .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
35
+ .map(function (child) { return (0, exports.blockToSolid)({ component: component, json: child, options: options }); }), "}}\n ").concat(needsWrapper ? '</>' : '', "\n </For>");
36
+ }
37
+ var str = '';
38
+ if (json.name === 'Fragment') {
39
+ str += '<';
40
+ }
41
+ else {
42
+ str += "<".concat(json.name, " ");
43
+ }
44
+ if (json.name === 'Show' && json.meta.else) {
45
+ str += "fallback={".concat((0, exports.blockToSolid)({ component: component, json: json.meta.else, options: options }), "}");
46
+ }
47
+ var classString = (0, styles_1.collectClassString)(json, options);
48
+ if (classString) {
49
+ str += " class=".concat(classString, " ");
50
+ }
51
+ for (var key in json.properties) {
52
+ var value = json.properties[key];
53
+ var newKey = transformAttributeName(key);
54
+ str += " ".concat(newKey, "=\"").concat(value, "\" ");
55
+ }
56
+ for (var key in json.bindings) {
57
+ var _d = json.bindings[key], code = _d.code, _e = _d.arguments, cusArg = _e === void 0 ? ['event'] : _e, type = _d.type;
58
+ if (!code)
59
+ continue;
60
+ if (type === 'spread') {
61
+ str += " {...(".concat(code, ")} ");
62
+ }
63
+ else if (key.startsWith('on')) {
64
+ var useKey = key === 'onChange' && json.name === 'input' ? 'onInput' : key;
65
+ str += " ".concat(useKey, "={(").concat(cusArg.join(','), ") => ").concat(code, "} ");
66
+ }
67
+ else {
68
+ var useValue = code;
69
+ if (key === 'style') {
70
+ // Convert camelCase keys to kebab-case
71
+ // TODO: support more than top level objects, may need
72
+ // a runtime helper for expressions that are not a direct
73
+ // object literal, such as ternaries and other expression
74
+ // types
75
+ useValue = (0, babel_transform_1.babelTransformExpression)(code, {
76
+ ObjectExpression: function (path) {
77
+ // TODO: limit to top level objects only
78
+ for (var _i = 0, _a = path.node.properties; _i < _a.length; _i++) {
79
+ var property = _a[_i];
80
+ if (core_1.types.isObjectProperty(property)) {
81
+ if (core_1.types.isIdentifier(property.key) || core_1.types.isStringLiteral(property.key)) {
82
+ var key_1 = core_1.types.isIdentifier(property.key)
83
+ ? property.key.name
84
+ : property.key.value;
85
+ property.key = core_1.types.stringLiteral((0, lodash_1.kebabCase)(key_1));
86
+ }
87
+ }
88
+ }
89
+ },
90
+ });
91
+ }
92
+ var newKey = transformAttributeName(key);
93
+ str += " ".concat(newKey, "={").concat(useValue, "} ");
94
+ }
95
+ }
96
+ if (jsx_1.selfClosingTags.has(json.name)) {
97
+ return str + ' />';
98
+ }
99
+ str += '>';
100
+ if (json.children) {
101
+ str += json.children
102
+ .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
103
+ .map(function (item) { return (0, exports.blockToSolid)({ component: component, json: item, options: options }); })
104
+ .join('\n');
105
+ }
106
+ if (json.name === 'Fragment') {
107
+ str += '</>';
108
+ }
109
+ else {
110
+ str += "</".concat(json.name, ">");
111
+ }
112
+ return str;
113
+ };
114
+ exports.blockToSolid = blockToSolid;
@@ -0,0 +1,3 @@
1
+ import { MitosisNode } from '../../../types/mitosis-node';
2
+ import { ToSolidOptions } from '../types';
3
+ export declare const collectClassString: (json: MitosisNode, options: ToSolidOptions) => string | null;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectClassString = void 0;
4
+ // This should really be a preprocessor mapping the `class` attribute binding based on what other values have
5
+ // to make this more pluggable
6
+ var collectClassString = function (json, options) {
7
+ var _a, _b, _c;
8
+ var staticClasses = [];
9
+ if (json.properties.class) {
10
+ staticClasses.push(json.properties.class);
11
+ delete json.properties.class;
12
+ }
13
+ if (json.properties.className) {
14
+ staticClasses.push(json.properties.className);
15
+ delete json.properties.className;
16
+ }
17
+ var dynamicClasses = [];
18
+ if (typeof ((_a = json.bindings.class) === null || _a === void 0 ? void 0 : _a.code) === 'string') {
19
+ dynamicClasses.push(json.bindings.class.code);
20
+ delete json.bindings.class;
21
+ }
22
+ if (typeof ((_b = json.bindings.className) === null || _b === void 0 ? void 0 : _b.code) === 'string') {
23
+ dynamicClasses.push(json.bindings.className.code);
24
+ delete json.bindings.className;
25
+ }
26
+ if (typeof ((_c = json.bindings.css) === null || _c === void 0 ? void 0 : _c.code) === 'string' &&
27
+ json.bindings.css.code.trim().length > 4 &&
28
+ options.stylesType === 'styled-components') {
29
+ dynamicClasses.push("css(".concat(json.bindings.css.code, ")"));
30
+ }
31
+ delete json.bindings.css;
32
+ var staticClassesString = staticClasses.join(' ');
33
+ var dynamicClassesString = dynamicClasses.join(" + ' ' + ");
34
+ var hasStaticClasses = Boolean(staticClasses.length);
35
+ var hasDynamicClasses = Boolean(dynamicClasses.length);
36
+ if (hasStaticClasses && !hasDynamicClasses) {
37
+ return "\"".concat(staticClassesString, "\"");
38
+ }
39
+ if (hasDynamicClasses && !hasStaticClasses) {
40
+ return "{".concat(dynamicClassesString, "}");
41
+ }
42
+ if (hasDynamicClasses && hasStaticClasses) {
43
+ return "{\"".concat(staticClassesString, " \" + ").concat(dynamicClassesString, "}");
44
+ }
45
+ return null;
46
+ };
47
+ exports.collectClassString = collectClassString;
@@ -56,8 +56,6 @@ var standalone_1 = require("prettier/standalone");
56
56
  var helpers_1 = require("../../helpers/styles/helpers");
57
57
  var get_refs_1 = require("../../helpers/get-refs");
58
58
  var render_imports_1 = require("../../helpers/render-imports");
59
- var jsx_1 = require("../../parsers/jsx");
60
- var mitosis_node_1 = require("../../types/mitosis-node");
61
59
  var plugins_1 = require("../../modules/plugins");
62
60
  var fast_clone_1 = require("../../helpers/fast-clone");
63
61
  var strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
@@ -66,9 +64,6 @@ var traverse_1 = __importDefault(require("traverse"));
66
64
  var is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
67
65
  var filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
68
66
  var create_mitosis_node_1 = require("../../helpers/create-mitosis-node");
69
- var babel_transform_1 = require("../../helpers/babel-transform");
70
- var core_1 = require("@babel/core");
71
- var lodash_1 = require("lodash");
72
67
  var state_1 = require("./state");
73
68
  var nullable_1 = require("../../helpers/nullable");
74
69
  var get_state_object_string_1 = require("../../helpers/get-state-object-string");
@@ -80,8 +75,8 @@ var helpers_2 = require("./state/helpers");
80
75
  var merge_options_1 = require("../../helpers/merge-options");
81
76
  var process_code_1 = require("../../helpers/plugins/process-code");
82
77
  var context_1 = require("../helpers/context");
83
- var typescript_1 = require("../../helpers/typescript");
84
- // Transform <foo.bar key="value" /> to <component :is="foo.bar" key="value" />
78
+ var blocks_1 = require("./blocks");
79
+ // Transform <foo.bar key={value} /> to <Dynamic compnent={foo.bar} key={value} />
85
80
  function processDynamicComponents(json, options) {
86
81
  var found = false;
87
82
  (0, traverse_1.default)(json).forEach(function (node) {
@@ -102,170 +97,6 @@ function getContextString(component, options) {
102
97
  }
103
98
  return str;
104
99
  }
105
- // This should really be a preprocessor mapping the `class` attribute binding based on what other values have
106
- // to make this more pluggable
107
- var collectClassString = function (json, options) {
108
- var _a, _b, _c;
109
- var staticClasses = [];
110
- if (json.properties.class) {
111
- staticClasses.push(json.properties.class);
112
- delete json.properties.class;
113
- }
114
- if (json.properties.className) {
115
- staticClasses.push(json.properties.className);
116
- delete json.properties.className;
117
- }
118
- var dynamicClasses = [];
119
- if (typeof ((_a = json.bindings.class) === null || _a === void 0 ? void 0 : _a.code) === 'string') {
120
- dynamicClasses.push(json.bindings.class.code);
121
- delete json.bindings.class;
122
- }
123
- if (typeof ((_b = json.bindings.className) === null || _b === void 0 ? void 0 : _b.code) === 'string') {
124
- dynamicClasses.push(json.bindings.className.code);
125
- delete json.bindings.className;
126
- }
127
- if (typeof ((_c = json.bindings.css) === null || _c === void 0 ? void 0 : _c.code) === 'string' &&
128
- json.bindings.css.code.trim().length > 4 &&
129
- options.stylesType === 'styled-components') {
130
- dynamicClasses.push("css(".concat(json.bindings.css.code, ")"));
131
- }
132
- delete json.bindings.css;
133
- var staticClassesString = staticClasses.join(' ');
134
- var dynamicClassesString = dynamicClasses.join(" + ' ' + ");
135
- var hasStaticClasses = Boolean(staticClasses.length);
136
- var hasDynamicClasses = Boolean(dynamicClasses.length);
137
- if (hasStaticClasses && !hasDynamicClasses) {
138
- return "\"".concat(staticClassesString, "\"");
139
- }
140
- if (hasDynamicClasses && !hasStaticClasses) {
141
- return "{".concat(dynamicClassesString, "}");
142
- }
143
- if (hasDynamicClasses && hasStaticClasses) {
144
- return "{\"".concat(staticClassesString, " \" + ").concat(dynamicClassesString, "}");
145
- }
146
- return null;
147
- };
148
- var preProcessBlockCode = function (_a) {
149
- var json = _a.json, options = _a.options, component = _a.component;
150
- for (var key in json.properties) {
151
- var value = json.properties[key];
152
- if (value) {
153
- json.properties[key] = (0, helpers_2.updateStateCode)({ options: options, component: component, updateSetters: false })(value);
154
- }
155
- }
156
- for (var key in json.bindings) {
157
- var value = json.bindings[key];
158
- if (value === null || value === void 0 ? void 0 : value.code) {
159
- json.bindings[key] = {
160
- arguments: value.arguments,
161
- code: (0, helpers_2.updateStateCode)({ options: options, component: component, updateSetters: true })(value.code),
162
- type: value === null || value === void 0 ? void 0 : value.type,
163
- };
164
- }
165
- }
166
- };
167
- var ATTTRIBUTE_MAPPERS = {
168
- for: 'htmlFor',
169
- };
170
- var transformAttributeName = function (name) {
171
- if ((0, typescript_1.objectHasKey)(ATTTRIBUTE_MAPPERS, name))
172
- return ATTTRIBUTE_MAPPERS[name];
173
- return name;
174
- };
175
- var blockToSolid = function (_a) {
176
- var _b, _c;
177
- var json = _a.json, options = _a.options, component = _a.component;
178
- if (json.properties._text) {
179
- return json.properties._text;
180
- }
181
- if ((_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code) {
182
- return "{".concat(json.bindings._text.code, "}");
183
- }
184
- if ((0, mitosis_node_1.checkIsForNode)(json)) {
185
- var needsWrapper = json.children.length !== 1;
186
- // The SolidJS `<For>` component has a special index() signal function.
187
- // https://www.solidjs.com/docs/latest#%3Cfor%3E
188
- return "<For each={".concat((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code, "}>\n {(").concat(json.scope.forName, ", _index) => {\n const ").concat(json.scope.indexName || 'index', " = _index();\n return ").concat(needsWrapper ? '<>' : '').concat(json.children
189
- .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
190
- .map(function (child) { return blockToSolid({ component: component, json: child, options: options }); }), "}}\n ").concat(needsWrapper ? '</>' : '', "\n </For>");
191
- }
192
- var str = '';
193
- if (json.name === 'Fragment') {
194
- str += '<';
195
- }
196
- else {
197
- str += "<".concat(json.name, " ");
198
- }
199
- if (json.name === 'Show' && json.meta.else) {
200
- str += "fallback={".concat(blockToSolid({ component: component, json: json.meta.else, options: options }), "}");
201
- }
202
- var classString = collectClassString(json, options);
203
- if (classString) {
204
- str += " class=".concat(classString, " ");
205
- }
206
- for (var key in json.properties) {
207
- var value = json.properties[key];
208
- var newKey = transformAttributeName(key);
209
- str += " ".concat(newKey, "=\"").concat(value, "\" ");
210
- }
211
- for (var key in json.bindings) {
212
- var _d = json.bindings[key], code = _d.code, _e = _d.arguments, cusArg = _e === void 0 ? ['event'] : _e, type = _d.type;
213
- if (!code)
214
- continue;
215
- if (type === 'spread') {
216
- str += " {...(".concat(code, ")} ");
217
- }
218
- else if (key.startsWith('on')) {
219
- var useKey = key === 'onChange' && json.name === 'input' ? 'onInput' : key;
220
- str += " ".concat(useKey, "={(").concat(cusArg.join(','), ") => ").concat(code, "} ");
221
- }
222
- else {
223
- var useValue = code;
224
- if (key === 'style') {
225
- // Convert camelCase keys to kebab-case
226
- // TODO: support more than top level objects, may need
227
- // a runtime helper for expressions that are not a direct
228
- // object literal, such as ternaries and other expression
229
- // types
230
- useValue = (0, babel_transform_1.babelTransformExpression)(code, {
231
- ObjectExpression: function (path) {
232
- // TODO: limit to top level objects only
233
- for (var _i = 0, _a = path.node.properties; _i < _a.length; _i++) {
234
- var property = _a[_i];
235
- if (core_1.types.isObjectProperty(property)) {
236
- if (core_1.types.isIdentifier(property.key) || core_1.types.isStringLiteral(property.key)) {
237
- var key_1 = core_1.types.isIdentifier(property.key)
238
- ? property.key.name
239
- : property.key.value;
240
- property.key = core_1.types.stringLiteral((0, lodash_1.kebabCase)(key_1));
241
- }
242
- }
243
- }
244
- },
245
- });
246
- }
247
- var newKey = transformAttributeName(key);
248
- str += " ".concat(newKey, "={").concat(useValue, "} ");
249
- }
250
- }
251
- if (jsx_1.selfClosingTags.has(json.name)) {
252
- return str + ' />';
253
- }
254
- str += '>';
255
- if (json.children) {
256
- str += json.children
257
- .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
258
- .map(function (item) { return blockToSolid({ component: component, json: item, options: options }); })
259
- .join('\n');
260
- }
261
- if (json.name === 'Fragment') {
262
- str += '</>';
263
- }
264
- else {
265
- str += "</".concat(json.name, ">");
266
- }
267
- return str;
268
- };
269
100
  var getRefsString = function (json) {
270
101
  return Array.from((0, get_refs_1.getRefs)(json))
271
102
  .map(function (ref) { return "let ".concat(ref, ";"); })
@@ -317,15 +148,13 @@ var componentToSolid = function (passedOptions) {
317
148
  addProviderComponents(json, options);
318
149
  var componentHasStyles = (0, helpers_1.hasCss)(json);
319
150
  var addWrapper = json.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes).length !== 1 || options.stylesType === 'style-tag';
151
+ // we need to run this before we run the code processor plugin, so the dynamic component variables are transformed
152
+ var foundDynamicComponents = processDynamicComponents(json, options);
320
153
  if (options.plugins) {
321
154
  json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
322
155
  }
323
156
  (0, strip_meta_properties_1.stripMetaProperties)(json);
324
- var foundDynamicComponents = processDynamicComponents(json, options);
325
- var css = options.stylesType === 'style-tag' &&
326
- (0, collect_css_1.collectCss)(json, {
327
- prefix: (0, hash_sum_1.default)(json),
328
- });
157
+ var css = options.stylesType === 'style-tag' && (0, collect_css_1.collectCss)(json, { prefix: (0, hash_sum_1.default)(json) });
329
158
  var state = (0, state_1.getState)({ json: json, options: options });
330
159
  var componentsUsed = (0, get_components_used_1.getComponentsUsed)(json);
331
160
  var hasShowComponent = componentsUsed.has('Show');
@@ -354,7 +183,7 @@ var componentToSolid = function (passedOptions) {
354
183
  .join('\n')
355
184
  : '', addWrapper ? '<>' : '', json.children
356
185
  .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
357
- .map(function (item) { return blockToSolid({ component: component, json: item, options: options }); })
186
+ .map(function (item) { return (0, blocks_1.blockToSolid)({ component: component, json: item, options: options }); })
358
187
  .join('\n'), options.stylesType === 'style-tag' && css && css.trim().length > 4
359
188
  ? // We add the jsx attribute so prettier formats this nicely
360
189
  "<style jsx>{`".concat(css, "`}</style>")
@@ -125,10 +125,12 @@ var componentToSvelte = function (userProvidedOptions) {
125
125
  // Make a copy we can safely mutate, similar to babel's toolchain
126
126
  var json = (0, fast_clone_1.fastClone)(component);
127
127
  json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
128
- var refs = Array.from((0, get_refs_1.getRefs)(json));
129
128
  useBindValue(json, options);
130
129
  (0, getters_to_functions_1.gettersToFunctions)(json);
131
130
  var props = Array.from((0, get_props_1.getProps)(json)).filter(function (prop) { return !(0, slots_1.isSlotProperty)(prop); });
131
+ var refs = Array.from((0, get_refs_1.getRefs)(json))
132
+ .map((0, helpers_2.stripStateAndProps)({ json: json, options: options }))
133
+ .filter(function (x) { return !props.includes(x); });
132
134
  json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
133
135
  var css = (0, collect_css_1.collectCss)(json);
134
136
  (0, strip_meta_properties_1.stripMetaProperties)(json);
@@ -206,7 +208,7 @@ var componentToSvelte = function (userProvidedOptions) {
206
208
  // https://svelte.dev/repl/bd9b56891f04414982517bbd10c52c82?version=3.31.0
207
209
  (0, helpers_1.hasStyle)(json)
208
210
  ? "\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 "
209
- : '', 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'
211
+ : '', getContextCode(json), setContextCode({ json: json, options: options }), functionsString.length < 4 ? '' : functionsString, getterString.length < 4 ? '' : getterString, refs.map(function (ref) { return "let ".concat(ref); }).join('\n'), options.stateType === 'proxies'
210
212
  ? dataString.length < 4
211
213
  ? ''
212
214
  : "let state = onChange(".concat(dataString, ", () => state = state)")
@@ -61,11 +61,13 @@ function generateCompositionApiScript(component, options, template, props, onUpd
61
61
  methods += " function _classStringToObject(str) {\n const obj = {};\n if (typeof str !== 'string') { return obj }\n const classNames = str.trim().split(/\\s+/);\n for (const name of classNames) {\n obj[name] = true;\n }\n return obj;\n } ";
62
62
  }
63
63
  var getterKeys = Object.keys((0, lodash_1.pickBy)(component.state, function (i) { return (i === null || i === void 0 ? void 0 : i.type) === 'getter'; }));
64
- var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\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 ", "\n ", "\n\n ", "\n\n ", "\n ", "\n "])), props.length ? getCompositionPropDefinition({ component: component, props: props, options: options }) : '', refs, (_a = Object.keys(component.context.get)) === null || _a === void 0 ? void 0 : _a.map(function (key) { return "const ".concat(key, " = inject(").concat(component.context.get[key].name, ")"); }).join('\n'), (_b = Object.values(component.context.set)) === null || _b === void 0 ? void 0 : _b.map(function (contextSet) {
65
- return "provide(".concat(contextSet.name, ", ").concat((0, helpers_1.getContextValue)({
66
- json: component,
67
- options: options,
68
- })(contextSet), ")");
64
+ var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\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 ", "\n ", "\n\n ", "\n\n ", "\n ", "\n "])), props.length ? getCompositionPropDefinition({ component: component, props: props, options: options }) : '', refs, (_a = Object.entries(component.context.get)) === null || _a === void 0 ? void 0 : _a.map(function (_a) {
65
+ var key = _a[0], context = _a[1];
66
+ return "const ".concat(key, " = inject(").concat((0, helpers_1.getContextKey)(context), ")");
67
+ }).join('\n'), (_b = Object.values(component.context.set)) === null || _b === void 0 ? void 0 : _b.map(function (contextSet) {
68
+ var contextValue = (0, helpers_1.getContextValue)({ json: component, options: options })(contextSet);
69
+ var key = (0, helpers_1.getContextKey)(contextSet);
70
+ return "provide(".concat(key, ", ").concat(contextValue, ")");
69
71
  }).join('\n'), (_c = Object.keys(component.refs)) === null || _c === void 0 ? void 0 : _c.map(function (key) {
70
72
  if (options.typescript) {
71
73
  return "const ".concat(key, " = ref<").concat(component.refs[key].typeParameter, ">()");
@@ -1,5 +1,5 @@
1
1
  import { Nullable } from '../../helpers/nullable';
2
- import { ContextSetInfo, MitosisComponent } from '../../types/mitosis-component';
2
+ import { ContextGetInfo, ContextSetInfo, MitosisComponent } from '../../types/mitosis-component';
3
3
  import { MitosisNode } from '../../types/mitosis-node';
4
4
  import { ToVueOptions } from './types';
5
5
  export declare const addPropertiesToJson: (properties: MitosisNode['properties']) => (json: MitosisNode) => MitosisNode;
@@ -9,14 +9,15 @@ 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, preserveGetter, }: {
12
+ declare type ProcessBinding = {
13
13
  code: string;
14
14
  options: ToVueOptions;
15
15
  json: MitosisComponent;
16
- preserveGetter?: boolean | undefined;
17
- }) => string;
18
- export declare const getContextValue: ({ options, json }: {
19
- options: ToVueOptions;
20
- json: MitosisComponent;
21
- }) => ({ name, ref, value }: ContextSetInfo) => Nullable<string>;
22
- export declare const getContextProvideString: (json: MitosisComponent, options: ToVueOptions) => string;
16
+ preserveGetter?: boolean;
17
+ thisPrefix?: 'this' | '_this';
18
+ };
19
+ export declare const processBinding: ({ code, options, json, preserveGetter, thisPrefix, }: ProcessBinding) => string;
20
+ export declare const getContextValue: (args: Pick<ProcessBinding, 'options' | 'json' | 'thisPrefix'>) => ({ name, ref, value }: ContextSetInfo) => Nullable<string>;
21
+ export declare const checkIfContextHasStrName: (context: ContextGetInfo | ContextSetInfo) => boolean;
22
+ export declare const getContextKey: (context: ContextGetInfo | ContextSetInfo) => string;
23
+ export {};