@builder.io/mitosis 0.0.115-0 → 0.0.115-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/generators/alpine/generate.js +4 -4
- package/dist/src/generators/angular.js +4 -4
- package/dist/src/generators/html.js +8 -8
- package/dist/src/generators/liquid.js +4 -4
- package/dist/src/generators/lit/generate.js +4 -4
- package/dist/src/generators/marko/generate.js +4 -4
- package/dist/src/generators/qwik/component-generator.js +18 -7
- package/dist/src/generators/react/generator.js +53 -10
- package/dist/src/generators/rsc.js +31 -25
- package/dist/src/generators/solid/index.js +4 -4
- package/dist/src/generators/stencil/generate.js +4 -4
- package/dist/src/generators/svelte/svelte.js +4 -4
- package/dist/src/generators/template.js +4 -4
- package/dist/src/generators/vue/vue.js +9 -4
- package/dist/src/helpers/get-state-object-string.d.ts +1 -1
- package/dist/src/helpers/get-state-object-string.js +3 -3
- package/dist/src/helpers/render-imports.js +1 -1
- package/dist/src/helpers/replace-identifiers.d.ts +1 -0
- package/dist/src/helpers/replace-identifiers.js +7 -7
- package/dist/src/modules/plugins.d.ts +22 -4
- package/dist/src/modules/plugins.js +18 -14
- package/dist/src/parsers/jsx/hooks/use-target.js +0 -2
- package/dist/src/types/metadata.d.ts +4 -0
- package/dist/src/types/plugins.d.ts +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -92,11 +92,11 @@ var componentToTemplate = function (options) {
|
|
|
92
92
|
var component = _a.component;
|
|
93
93
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
94
94
|
if (options.plugins) {
|
|
95
|
-
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
95
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json: json, plugins: options.plugins });
|
|
96
96
|
}
|
|
97
97
|
var css = (0, collect_css_1.collectCss)(json);
|
|
98
98
|
if (options.plugins) {
|
|
99
|
-
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
99
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json: json, plugins: options.plugins });
|
|
100
100
|
}
|
|
101
101
|
var str = json.children.map(function (item) { return blockToTemplate(item); }).join('\n');
|
|
102
102
|
if (css.trim().length) {
|
|
@@ -104,7 +104,7 @@ var componentToTemplate = function (options) {
|
|
|
104
104
|
}
|
|
105
105
|
str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n export default function template(props) {\n let state = ", "\n\n return `", "`\n }\n \n "], ["\n export default function template(props) {\n let state = ", "\n\n return \\`", "\\`\n }\n \n "])), (0, get_state_object_string_1.getStateObjectStringFromComponent)(json), str.replace(/\s+/g, ' '));
|
|
106
106
|
if (options.plugins) {
|
|
107
|
-
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
107
|
+
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
108
108
|
}
|
|
109
109
|
if (options.prettier !== false) {
|
|
110
110
|
try {
|
|
@@ -124,7 +124,7 @@ var componentToTemplate = function (options) {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
if (options.plugins) {
|
|
127
|
-
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
127
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
128
128
|
}
|
|
129
129
|
return str;
|
|
130
130
|
};
|
|
@@ -174,7 +174,7 @@ var componentToVue = function (userOptions) {
|
|
|
174
174
|
(0, process_http_requests_1.processHttpRequests)(component);
|
|
175
175
|
processDynamicComponents(component, options);
|
|
176
176
|
processForKeys(component, options);
|
|
177
|
-
component = (0, plugins_1.runPreJsonPlugins)(component, options.plugins);
|
|
177
|
+
component = (0, plugins_1.runPreJsonPlugins)({ json: component, plugins: options.plugins });
|
|
178
178
|
if (options.api === 'options') {
|
|
179
179
|
(0, map_refs_1.mapRefs)(component, function (refName) { return "this.$refs.".concat(refName); });
|
|
180
180
|
}
|
|
@@ -182,7 +182,7 @@ var componentToVue = function (userOptions) {
|
|
|
182
182
|
var props = Array.from((0, get_props_1.getProps)(component));
|
|
183
183
|
var elementProps = props.filter(function (prop) { return !(0, slots_1.isSlotProperty)(prop); });
|
|
184
184
|
var slotsProps = props.filter(function (prop) { return (0, slots_1.isSlotProperty)(prop); });
|
|
185
|
-
component = (0, plugins_1.runPostJsonPlugins)(component, options.plugins);
|
|
185
|
+
component = (0, plugins_1.runPostJsonPlugins)({ json: component, plugins: options.plugins });
|
|
186
186
|
var css = (0, collect_css_1.collectCss)(component, {
|
|
187
187
|
prefix: (_c = (_b = options.cssNamespace) === null || _b === void 0 ? void 0 : _b.call(options)) !== null && _c !== void 0 ? _c : undefined,
|
|
188
188
|
});
|
|
@@ -222,7 +222,12 @@ var componentToVue = function (userOptions) {
|
|
|
222
222
|
: (0, optionsApi_1.generateOptionsApiScript)(component, options, path, template, elementProps, onUpdateWithDeps, onUpdateWithoutDeps), !css.trim().length
|
|
223
223
|
? ''
|
|
224
224
|
: "<style scoped>\n ".concat(css, "\n </style>"));
|
|
225
|
-
str = (0, plugins_1.runPreCodePlugins)(
|
|
225
|
+
str = (0, plugins_1.runPreCodePlugins)({
|
|
226
|
+
json: component,
|
|
227
|
+
code: str,
|
|
228
|
+
plugins: options.plugins,
|
|
229
|
+
options: { json: component },
|
|
230
|
+
});
|
|
226
231
|
if (true || options.prettier !== false) {
|
|
227
232
|
try {
|
|
228
233
|
str = (0, standalone_1.format)(str, {
|
|
@@ -240,7 +245,7 @@ var componentToVue = function (userOptions) {
|
|
|
240
245
|
console.warn('Could not prettify', { string: str }, err);
|
|
241
246
|
}
|
|
242
247
|
}
|
|
243
|
-
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
248
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: component, code: str, plugins: options.plugins });
|
|
244
249
|
for (var _i = 0, removePatterns_1 = removePatterns; _i < removePatterns_1.length; _i++) {
|
|
245
250
|
var pattern = removePatterns_1[_i];
|
|
246
251
|
str = str.replace(pattern, '').trim();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MitosisComponent } from '../types/mitosis-component';
|
|
2
2
|
import { MitosisContext } from '../types/mitosis-context';
|
|
3
|
-
declare type ValueMapper = (code: string, type: 'data' | 'function' | 'getter', typeParameter
|
|
3
|
+
declare type ValueMapper = (code: string, type: 'data' | 'function' | 'getter', typeParameter: string | undefined, key: string | undefined) => string;
|
|
4
4
|
interface GetStateObjectStringOptions {
|
|
5
5
|
data?: boolean;
|
|
6
6
|
functions?: boolean;
|
|
@@ -34,19 +34,19 @@ var convertStateMemberToString = function (_a) {
|
|
|
34
34
|
if (functions === false || typeof code !== 'string') {
|
|
35
35
|
return undefined;
|
|
36
36
|
}
|
|
37
|
-
return "".concat(keyPrefix, " ").concat(key, " ").concat(keyValueDelimiter, " ").concat(valueMapper(code, 'function', typeParameter));
|
|
37
|
+
return "".concat(keyPrefix, " ").concat(key, " ").concat(keyValueDelimiter, " ").concat(valueMapper(code, 'function', typeParameter, key));
|
|
38
38
|
}
|
|
39
39
|
case 'method': {
|
|
40
40
|
if (functions === false || typeof code !== 'string') {
|
|
41
41
|
return undefined;
|
|
42
42
|
}
|
|
43
|
-
return "".concat(keyPrefix, " ").concat(valueMapper(code, 'function', typeParameter));
|
|
43
|
+
return "".concat(keyPrefix, " ").concat(valueMapper(code, 'function', typeParameter, key));
|
|
44
44
|
}
|
|
45
45
|
case 'getter': {
|
|
46
46
|
if (getters === false || typeof code !== 'string') {
|
|
47
47
|
return undefined;
|
|
48
48
|
}
|
|
49
|
-
return "".concat(keyPrefix, " ").concat(valueMapper(code, 'getter', typeParameter));
|
|
49
|
+
return "".concat(keyPrefix, " ").concat(valueMapper(code, 'getter', typeParameter, key));
|
|
50
50
|
}
|
|
51
51
|
case 'property': {
|
|
52
52
|
if (data === false) {
|
|
@@ -54,7 +54,7 @@ exports.checkIsComponentImport = checkIsComponentImport;
|
|
|
54
54
|
var transformImportPath = function (theImport, target, preserveFileExtensions) {
|
|
55
55
|
// We need to drop the `.lite` from context files, because the context generator does so as well.
|
|
56
56
|
if (theImport.path.endsWith('.context.lite')) {
|
|
57
|
-
return theImport.path.replace('.lite', '
|
|
57
|
+
return theImport.path.replace('.lite', '');
|
|
58
58
|
}
|
|
59
59
|
if ((0, exports.checkIsComponentImport)(theImport) && !preserveFileExtensions) {
|
|
60
60
|
return theImport.path.replace('.lite', getFileExtensionForTarget(target));
|
|
@@ -147,6 +147,7 @@ var replacePropsIdentifier = function (to) { return function (code) {
|
|
|
147
147
|
return (0, exports.replaceIdentifiers)({ code: code, from: 'props', to: to });
|
|
148
148
|
}; };
|
|
149
149
|
exports.replacePropsIdentifier = replacePropsIdentifier;
|
|
150
|
+
var isNewlyGenerated = function (node) { var _a; return (_a = node === null || node === void 0 ? void 0 : node._builder_meta) === null || _a === void 0 ? void 0 : _a.newlyGenerated; };
|
|
150
151
|
/**
|
|
151
152
|
* Replaces all instances of a Babel AST Node with a new Node within a code string.
|
|
152
153
|
* Uses `generate()` to convert the Node to a string and compare them.
|
|
@@ -154,17 +155,15 @@ exports.replacePropsIdentifier = replacePropsIdentifier;
|
|
|
154
155
|
var replaceNodes = function (_a) {
|
|
155
156
|
var code = _a.code, nodeMaps = _a.nodeMaps;
|
|
156
157
|
var searchAndReplace = function (path) {
|
|
157
|
-
|
|
158
|
-
if ((_b = (_a = path.node) === null || _a === void 0 ? void 0 : _a._builder_meta) === null || _b === void 0 ? void 0 : _b.newlyGenerated) {
|
|
158
|
+
if (isNewlyGenerated(path.node) || isNewlyGenerated(path.parent))
|
|
159
159
|
return;
|
|
160
|
-
}
|
|
161
160
|
for (var _i = 0, nodeMaps_1 = nodeMaps; _i < nodeMaps_1.length; _i++) {
|
|
162
|
-
var
|
|
163
|
-
if ((
|
|
161
|
+
var _a = nodeMaps_1[_i], from = _a.from, to = _a.to, condition = _a.condition;
|
|
162
|
+
if (isNewlyGenerated(path.node) || isNewlyGenerated(path.parent))
|
|
164
163
|
return;
|
|
165
|
-
}
|
|
166
164
|
// if (path.node.type !== from.type) return;
|
|
167
|
-
|
|
165
|
+
var matchesCondition = condition ? condition(path) : true;
|
|
166
|
+
if ((0, generator_1.default)(path.node).code === (0, generator_1.default)(from).code && matchesCondition) {
|
|
168
167
|
var x = core_1.types.cloneNode(to);
|
|
169
168
|
x._builder_meta = { newlyGenerated: true };
|
|
170
169
|
try {
|
|
@@ -176,6 +175,7 @@ var replaceNodes = function (_a) {
|
|
|
176
175
|
orig: (0, generator_1.default)(path.node).code,
|
|
177
176
|
to: (0, generator_1.default)(x).code,
|
|
178
177
|
});
|
|
178
|
+
console.log({ parent: path.parent });
|
|
179
179
|
// throw err;
|
|
180
180
|
}
|
|
181
181
|
}
|
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
import { MitosisComponent } from '../types/mitosis-component';
|
|
2
2
|
import { Plugin } from '../types/plugins';
|
|
3
3
|
export type { Plugin };
|
|
4
|
-
export declare const runPreJsonPlugins: (json
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
export declare const runPreJsonPlugins: ({ json, plugins, options, }: {
|
|
5
|
+
json: MitosisComponent;
|
|
6
|
+
plugins: Plugin[];
|
|
7
|
+
options?: any;
|
|
8
|
+
}) => MitosisComponent;
|
|
9
|
+
export declare const runPostJsonPlugins: ({ json, plugins, options, }: {
|
|
10
|
+
json: MitosisComponent;
|
|
11
|
+
plugins: Plugin[];
|
|
12
|
+
options?: any;
|
|
13
|
+
}) => MitosisComponent;
|
|
14
|
+
export declare const runPreCodePlugins: ({ code, plugins, options, json, }: {
|
|
15
|
+
json: MitosisComponent;
|
|
16
|
+
code: string;
|
|
17
|
+
plugins: Plugin[];
|
|
18
|
+
options?: any;
|
|
19
|
+
}) => string;
|
|
20
|
+
export declare const runPostCodePlugins: ({ code, plugins, options, json, }: {
|
|
21
|
+
json: MitosisComponent;
|
|
22
|
+
code: string;
|
|
23
|
+
plugins: Plugin[];
|
|
24
|
+
options?: any;
|
|
25
|
+
}) => string;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runPostCodePlugins = exports.runPreCodePlugins = exports.runPostJsonPlugins = exports.runPreJsonPlugins = void 0;
|
|
4
|
-
var runPreJsonPlugins = function (
|
|
5
|
-
var
|
|
4
|
+
var runPreJsonPlugins = function (_a) {
|
|
5
|
+
var _b;
|
|
6
|
+
var json = _a.json, plugins = _a.plugins, options = _a.options;
|
|
6
7
|
var useJson = json;
|
|
7
8
|
for (var _i = 0, plugins_1 = plugins; _i < plugins_1.length; _i++) {
|
|
8
9
|
var plugin = plugins_1[_i];
|
|
9
|
-
var preFunction = (
|
|
10
|
+
var preFunction = (_b = plugin(options).json) === null || _b === void 0 ? void 0 : _b.pre;
|
|
10
11
|
if (preFunction) {
|
|
11
12
|
useJson = preFunction(json) || json;
|
|
12
13
|
}
|
|
@@ -14,12 +15,13 @@ var runPreJsonPlugins = function (json, plugins, options) {
|
|
|
14
15
|
return useJson;
|
|
15
16
|
};
|
|
16
17
|
exports.runPreJsonPlugins = runPreJsonPlugins;
|
|
17
|
-
var runPostJsonPlugins = function (
|
|
18
|
-
var
|
|
18
|
+
var runPostJsonPlugins = function (_a) {
|
|
19
|
+
var _b;
|
|
20
|
+
var json = _a.json, plugins = _a.plugins, options = _a.options;
|
|
19
21
|
var useJson = json;
|
|
20
22
|
for (var _i = 0, plugins_2 = plugins; _i < plugins_2.length; _i++) {
|
|
21
23
|
var plugin = plugins_2[_i];
|
|
22
|
-
var postFunction = (
|
|
24
|
+
var postFunction = (_b = plugin(options).json) === null || _b === void 0 ? void 0 : _b.post;
|
|
23
25
|
if (postFunction) {
|
|
24
26
|
useJson = postFunction(json) || json;
|
|
25
27
|
}
|
|
@@ -27,27 +29,29 @@ var runPostJsonPlugins = function (json, plugins, options) {
|
|
|
27
29
|
return useJson;
|
|
28
30
|
};
|
|
29
31
|
exports.runPostJsonPlugins = runPostJsonPlugins;
|
|
30
|
-
var runPreCodePlugins = function (
|
|
31
|
-
var
|
|
32
|
+
var runPreCodePlugins = function (_a) {
|
|
33
|
+
var _b;
|
|
34
|
+
var code = _a.code, plugins = _a.plugins, options = _a.options, json = _a.json;
|
|
32
35
|
var string = code;
|
|
33
36
|
for (var _i = 0, plugins_3 = plugins; _i < plugins_3.length; _i++) {
|
|
34
37
|
var plugin = plugins_3[_i];
|
|
35
|
-
var preFunction = (
|
|
38
|
+
var preFunction = (_b = plugin(options).code) === null || _b === void 0 ? void 0 : _b.pre;
|
|
36
39
|
if (preFunction) {
|
|
37
|
-
string = preFunction(string);
|
|
40
|
+
string = preFunction(string, json);
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
return string;
|
|
41
44
|
};
|
|
42
45
|
exports.runPreCodePlugins = runPreCodePlugins;
|
|
43
|
-
var runPostCodePlugins = function (
|
|
44
|
-
var
|
|
46
|
+
var runPostCodePlugins = function (_a) {
|
|
47
|
+
var _b;
|
|
48
|
+
var code = _a.code, plugins = _a.plugins, options = _a.options, json = _a.json;
|
|
45
49
|
var string = code;
|
|
46
50
|
for (var _i = 0, plugins_4 = plugins; _i < plugins_4.length; _i++) {
|
|
47
51
|
var plugin = plugins_4[_i];
|
|
48
|
-
var postFunction = (
|
|
52
|
+
var postFunction = (_b = plugin(options).code) === null || _b === void 0 ? void 0 : _b.post;
|
|
49
53
|
if (postFunction) {
|
|
50
|
-
string = postFunction(string);
|
|
54
|
+
string = postFunction(string, json);
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
return string;
|
|
@@ -84,8 +84,6 @@ var getUseTargetStatements = function (useTargetHook) {
|
|
|
84
84
|
targetBlock[prop.key.name] = {
|
|
85
85
|
code: (0, generator_1.default)(targetCode).code,
|
|
86
86
|
};
|
|
87
|
-
// TO-DO: replace the useTarget() call with a magic string
|
|
88
|
-
// this will be replaced with the actual target code later
|
|
89
87
|
});
|
|
90
88
|
return Object.keys(targetBlock).length ? targetBlock : undefined;
|
|
91
89
|
};
|
|
@@ -12,6 +12,7 @@ export declare type ComponentMetadata = {
|
|
|
12
12
|
component?: {
|
|
13
13
|
isLight?: boolean;
|
|
14
14
|
};
|
|
15
|
+
setUseStoreFirst?: boolean;
|
|
15
16
|
hasDeepStore?: boolean;
|
|
16
17
|
mutable?: string[];
|
|
17
18
|
imports?: Dictionary<string>;
|
|
@@ -20,5 +21,8 @@ export declare type ComponentMetadata = {
|
|
|
20
21
|
solid?: {
|
|
21
22
|
state?: Dictionary<SolidState>;
|
|
22
23
|
};
|
|
24
|
+
rsc?: {
|
|
25
|
+
isRSC?: boolean;
|
|
26
|
+
};
|
|
23
27
|
};
|
|
24
28
|
export {};
|
|
@@ -5,7 +5,7 @@ export declare type Plugin = (options?: any) => {
|
|
|
5
5
|
post?: (json: MitosisComponent) => MitosisComponent | void;
|
|
6
6
|
};
|
|
7
7
|
code?: {
|
|
8
|
-
pre?: (code: string) => string;
|
|
9
|
-
post?: (code: string) => string;
|
|
8
|
+
pre?: (code: string, json: MitosisComponent) => string;
|
|
9
|
+
post?: (code: string, json: MitosisComponent) => string;
|
|
10
10
|
};
|
|
11
11
|
};
|