@builder.io/mitosis 0.0.74 → 0.0.76
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/angular.d.ts +2 -0
- package/dist/src/generators/angular.js +16 -5
- package/dist/src/generators/lit/generate.js +0 -3
- package/dist/src/generators/marko/generate.js +0 -3
- package/dist/src/generators/qwik/component-generator.js +9 -8
- package/dist/src/generators/qwik/directives.js +4 -0
- package/dist/src/generators/qwik/jsx.d.ts +1 -1
- package/dist/src/generators/qwik/jsx.js +5 -9
- package/dist/src/generators/react/generator.js +15 -11
- package/dist/src/generators/solid/index.js +24 -26
- package/dist/src/generators/stencil/generate.js +0 -3
- package/dist/src/generators/svelte/blocks.d.ts +10 -0
- package/dist/src/generators/svelte/blocks.js +188 -0
- package/dist/src/generators/svelte/helpers.d.ts +2 -0
- package/dist/src/generators/svelte/helpers.js +11 -0
- package/dist/src/generators/svelte/index.d.ts +1 -0
- package/dist/src/generators/svelte/index.js +5 -0
- package/dist/src/generators/svelte/svelte.d.ts +3 -0
- package/dist/src/generators/svelte/svelte.js +250 -0
- package/dist/src/generators/svelte/types.d.ts +4 -0
- package/dist/src/generators/svelte/types.js +2 -0
- package/dist/src/generators/vue/blocks.js +13 -23
- package/dist/src/generators/vue/compositionApi.js +23 -83
- package/dist/src/generators/vue/helpers.d.ts +10 -4
- package/dist/src/generators/vue/helpers.js +100 -18
- package/dist/src/generators/vue/optionsApi.js +6 -28
- package/dist/src/generators/vue/types.d.ts +5 -2
- package/dist/src/generators/vue/vue.d.ts +1 -4
- package/dist/src/generators/vue/vue.js +70 -49
- package/dist/src/helpers/is-children.js +3 -2
- package/dist/src/helpers/merge-options.d.ts +7 -0
- package/dist/src/helpers/merge-options.js +31 -0
- package/dist/src/helpers/plugins/process-code.d.ts +8 -0
- package/dist/src/helpers/plugins/process-code.js +69 -0
- package/dist/src/helpers/render-imports.d.ts +11 -3
- package/dist/src/helpers/render-imports.js +18 -4
- package/dist/src/helpers/replace-identifiers.js +18 -8
- package/dist/src/helpers/typescript.d.ts +1 -1
- package/dist/src/parsers/angular.js +4 -3
- package/dist/src/parsers/builder.d.ts +2 -2
- package/dist/src/parsers/jsx/ast.d.ts +2 -0
- package/dist/src/parsers/jsx/component-types.d.ts +2 -0
- package/dist/src/parsers/jsx/element-parser.d.ts +3 -1
- package/dist/src/parsers/jsx/exports.d.ts +4 -2
- package/dist/src/parsers/jsx/function-parser.d.ts +2 -0
- package/dist/src/parsers/jsx/helpers.d.ts +2 -0
- package/dist/src/parsers/jsx/imports.d.ts +2 -0
- package/dist/src/parsers/jsx/metadata.d.ts +2 -0
- package/dist/src/parsers/jsx/state.d.ts +2 -0
- package/dist/src/targets.d.ts +1 -1
- package/dist/src/types/mitosis-component.d.ts +8 -7
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/src/generators/svelte.d.ts +0 -14
- package/dist/src/generators/svelte.js +0 -455
|
@@ -10,10 +10,23 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
13
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.processBinding = exports.getContextNames = exports.renameMitosisComponentsToKebabCase = exports.encodeQuotes = exports.invertBooleanExpression = exports.getOnUpdateHookName = exports.addBindingsToJson = exports.addPropertiesToJson = void 0;
|
|
15
|
-
var
|
|
23
|
+
exports.getContextProvideString = exports.getContextValue = exports.processBinding = exports.getContextNames = exports.renameMitosisComponentsToKebabCase = exports.encodeQuotes = exports.invertBooleanExpression = exports.getOnUpdateHookName = exports.addBindingsToJson = exports.addPropertiesToJson = void 0;
|
|
24
|
+
var get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
16
25
|
var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
26
|
+
var function_1 = require("fp-ts/lib/function");
|
|
27
|
+
var babel_transform_1 = require("../../helpers/babel-transform");
|
|
28
|
+
var core_1 = require("@babel/core");
|
|
29
|
+
var lodash_1 = require("lodash");
|
|
17
30
|
var addPropertiesToJson = function (properties) {
|
|
18
31
|
return function (json) { return (__assign(__assign({}, json), { properties: __assign(__assign({}, json.properties), properties) })); };
|
|
19
32
|
};
|
|
@@ -40,23 +53,92 @@ function getContextNames(json) {
|
|
|
40
53
|
return Object.keys(json.context.get);
|
|
41
54
|
}
|
|
42
55
|
exports.getContextNames = getContextNames;
|
|
56
|
+
function shouldAppendValueToRef(path) {
|
|
57
|
+
var parent = path.parent, node = path.node;
|
|
58
|
+
if (core_1.types.isFunctionDeclaration(parent) && parent.id === node) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (core_1.types.isCallExpression(parent)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
var isMemberExpression = core_1.types.isMemberExpression(parent);
|
|
65
|
+
if (isMemberExpression &&
|
|
66
|
+
core_1.types.isThisExpression(parent.object) &&
|
|
67
|
+
core_1.types.isProgram(path.scope.block) &&
|
|
68
|
+
path.scope.hasReference(node.name)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (isMemberExpression &&
|
|
72
|
+
core_1.types.isIdentifier(parent.object) &&
|
|
73
|
+
core_1.types.isIdentifier(parent.property) &&
|
|
74
|
+
parent.property.name === node.name) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (Object.keys(path.scope.bindings).includes(path.node.name)) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (path.parentPath.listKey === 'arguments' || path.parentPath.listKey === 'params') {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
var getAllRefs = function (component) {
|
|
86
|
+
var refKeys = Object.keys(component.refs);
|
|
87
|
+
var stateKeys = Object.keys((0, lodash_1.pickBy)(component.state, function (i) { return (i === null || i === void 0 ? void 0 : i.type) === 'property'; }));
|
|
88
|
+
var allKeys = __spreadArray(__spreadArray([], refKeys, true), stateKeys, true);
|
|
89
|
+
return allKeys;
|
|
90
|
+
};
|
|
91
|
+
function processRefs(input, component, options) {
|
|
92
|
+
var refs = options.api === 'options' ? getContextNames(component) : getAllRefs(component);
|
|
93
|
+
return (0, babel_transform_1.babelTransformExpression)(input, {
|
|
94
|
+
Identifier: function (path) {
|
|
95
|
+
var name = path.node.name;
|
|
96
|
+
if (refs.includes(name) && shouldAppendValueToRef(path)) {
|
|
97
|
+
var newValue = options.api === 'options' ? "this.".concat(name) : "".concat(name, ".value");
|
|
98
|
+
path.replaceWith(core_1.types.identifier(newValue));
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
43
103
|
// TODO: migrate all stripStateAndPropsRefs to use this here
|
|
44
104
|
// to properly replace context refs
|
|
45
|
-
function
|
|
105
|
+
var processBinding = function (_a) {
|
|
46
106
|
var code = _a.code, options = _a.options, json = _a.json, _b = _a.includeProps, includeProps = _b === void 0 ? true : _b;
|
|
47
|
-
return (0,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
107
|
+
return (0, function_1.pipe)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
108
|
+
includeState: true,
|
|
109
|
+
includeProps: includeProps,
|
|
110
|
+
replaceWith: function (name) {
|
|
111
|
+
switch (options.api) {
|
|
112
|
+
case 'composition':
|
|
113
|
+
return name;
|
|
114
|
+
case 'options':
|
|
115
|
+
if (name === 'children' || name.startsWith('children.')) {
|
|
116
|
+
return 'this.$slots.default';
|
|
117
|
+
}
|
|
118
|
+
return "this.".concat(name);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
}), function (c) { return processRefs(c, json, options); });
|
|
122
|
+
};
|
|
62
123
|
exports.processBinding = processBinding;
|
|
124
|
+
var getContextValue = function (_a) {
|
|
125
|
+
var options = _a.options, json = _a.json;
|
|
126
|
+
return function (_a) {
|
|
127
|
+
var name = _a.name, ref = _a.ref, value = _a.value;
|
|
128
|
+
var valueStr = value
|
|
129
|
+
? (0, get_state_object_string_1.stringifyContextValue)(value, {
|
|
130
|
+
valueMapper: function (code) { return (0, exports.processBinding)({ code: code, options: options, json: json }); },
|
|
131
|
+
})
|
|
132
|
+
: ref
|
|
133
|
+
? (0, exports.processBinding)({ code: ref, options: options, json: json })
|
|
134
|
+
: null;
|
|
135
|
+
return valueStr;
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
exports.getContextValue = getContextValue;
|
|
139
|
+
var getContextProvideString = function (json, options) {
|
|
140
|
+
return "{\n ".concat(Object.values(json.context.set)
|
|
141
|
+
.map(function (setVal) { return "".concat(setVal.name, ": ").concat((0, exports.getContextValue)({ options: options, json: json })(setVal)); })
|
|
142
|
+
.join(','), "\n }");
|
|
143
|
+
};
|
|
144
|
+
exports.getContextProvideString = getContextProvideString;
|
|
@@ -22,7 +22,6 @@ var nullable_1 = require("../../helpers/nullable");
|
|
|
22
22
|
var patterns_1 = require("../../helpers/patterns");
|
|
23
23
|
var render_imports_1 = require("../../helpers/render-imports");
|
|
24
24
|
var helpers_1 = require("./helpers");
|
|
25
|
-
var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
26
25
|
function getContextInjectString(component, options) {
|
|
27
26
|
var str = '{';
|
|
28
27
|
for (var key in component.context.get) {
|
|
@@ -31,21 +30,6 @@ function getContextInjectString(component, options) {
|
|
|
31
30
|
str += '}';
|
|
32
31
|
return str;
|
|
33
32
|
}
|
|
34
|
-
function getContextProvideString(component, options) {
|
|
35
|
-
var str = '{';
|
|
36
|
-
for (var key in component.context.set) {
|
|
37
|
-
var _a = component.context.set[key], ref = _a.ref, value = _a.value, name_1 = _a.name;
|
|
38
|
-
str += "\n ".concat(name_1, ": ").concat(value
|
|
39
|
-
? (0, get_state_object_string_1.stringifyContextValue)(value, {
|
|
40
|
-
valueMapper: function (code) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, { replaceWith: '_this.' }); },
|
|
41
|
-
})
|
|
42
|
-
: ref
|
|
43
|
-
? (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(ref, { replaceWith: '_this.' })
|
|
44
|
-
: null, ",\n ");
|
|
45
|
-
}
|
|
46
|
-
str += '}';
|
|
47
|
-
return str;
|
|
48
|
-
}
|
|
49
33
|
var generateComponentImport = function (options) {
|
|
50
34
|
return function (componentName) {
|
|
51
35
|
if (options.vueVersion >= 3 && options.asyncComponentImports) {
|
|
@@ -149,29 +133,23 @@ function generateOptionsApiScript(component, options, path, template, props, onU
|
|
|
149
133
|
: "name: '".concat(path && ((_a = options.namePrefix) === null || _a === void 0 ? void 0 : _a.call(options, path)) ? ((_b = options.namePrefix) === null || _b === void 0 ? void 0 : _b.call(options, path)) + '-' : '').concat((0, lodash_1.kebabCase)(component.name), "',"), "\n ").concat(generateComponents(componentsUsed, options), "\n ").concat(props.length ? "props: ".concat(json5_1.default.stringify(propsDefinition), ",") : '', "\n ").concat(dataString.length < 4
|
|
150
134
|
? ''
|
|
151
135
|
: "\n data: () => (".concat(dataString, "),\n "), "\n\n ").concat((0, lodash_1.size)(component.context.set)
|
|
152
|
-
? "provide() {\n
|
|
136
|
+
? "provide() {\n return ".concat((0, helpers_1.getContextProvideString)(component, options), "\n },")
|
|
153
137
|
: '', "\n ").concat((0, lodash_1.size)(component.context.get)
|
|
154
138
|
? "inject: ".concat(getContextInjectString(component, options), ",")
|
|
155
139
|
: '', "\n ").concat(((_c = component.hooks.onInit) === null || _c === void 0 ? void 0 : _c.code)
|
|
156
|
-
? "created() {\n ".concat(
|
|
140
|
+
? "created() {\n ".concat(component.hooks.onInit.code, "\n },")
|
|
157
141
|
: '', "\n ").concat(((_d = component.hooks.onMount) === null || _d === void 0 ? void 0 : _d.code)
|
|
158
|
-
? "mounted() {\n ".concat(
|
|
142
|
+
? "mounted() {\n ".concat(component.hooks.onMount.code, "\n },")
|
|
159
143
|
: '', "\n ").concat(onUpdateWithoutDeps.length
|
|
160
|
-
? "updated() {\n ".concat(onUpdateWithoutDeps
|
|
161
|
-
.map(function (hook) { return (0, helpers_1.processBinding)({ code: hook.code, options: options, json: component }); })
|
|
162
|
-
.join('\n'), "\n },")
|
|
144
|
+
? "updated() {\n ".concat(onUpdateWithoutDeps.map(function (hook) { return hook.code; }).join('\n'), "\n },")
|
|
163
145
|
: '', "\n ").concat(onUpdateWithDeps.length
|
|
164
146
|
? "watch: {\n ".concat(onUpdateWithDeps
|
|
165
147
|
.map(function (hook, index) {
|
|
166
|
-
return "".concat((0, helpers_1.getOnUpdateHookName)(index), "() {\n ").concat(
|
|
148
|
+
return "".concat((0, helpers_1.getOnUpdateHookName)(index), "() {\n ").concat(hook.code, "\n }\n ");
|
|
167
149
|
})
|
|
168
150
|
.join(','), "\n },")
|
|
169
151
|
: '', "\n ").concat(component.hooks.onUnMount
|
|
170
|
-
? "unmounted() {\n ".concat(
|
|
171
|
-
code: component.hooks.onUnMount.code,
|
|
172
|
-
options: options,
|
|
173
|
-
json: component,
|
|
174
|
-
}), "\n },")
|
|
152
|
+
? "unmounted() {\n ".concat(component.hooks.onUnMount.code, "\n },")
|
|
175
153
|
: '', "\n\n ").concat(getterString.length < 4
|
|
176
154
|
? ''
|
|
177
155
|
: " \n computed: ".concat(getterString, ",\n "), "\n ").concat(functionsString.length < 4
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { OmitObj } from '../../helpers/typescript';
|
|
1
2
|
import { BaseTranspilerOptions } from '../../types/transpiler';
|
|
2
3
|
export declare type VueVersion = 2 | 3;
|
|
3
4
|
export declare type Api = 'options' | 'composition';
|
|
4
|
-
|
|
5
|
+
interface VueVersionOpt {
|
|
5
6
|
vueVersion: VueVersion;
|
|
6
7
|
}
|
|
7
8
|
export interface ToVueOptions extends BaseTranspilerOptions, VueVersionOpt {
|
|
8
9
|
cssNamespace?: () => string;
|
|
9
10
|
namePrefix?: (path: string) => string;
|
|
10
11
|
asyncComponentImports?: boolean;
|
|
11
|
-
api
|
|
12
|
+
api: Api;
|
|
12
13
|
}
|
|
14
|
+
export declare type VueOptsWithoutVersion = OmitObj<ToVueOptions, VueVersionOpt>;
|
|
15
|
+
export {};
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ToVueOptions, VueVersionOpt } from './types';
|
|
3
|
-
declare type VueOptsWithoutVersion = OmitObj<ToVueOptions, VueVersionOpt>;
|
|
1
|
+
import { VueOptsWithoutVersion } from './types';
|
|
4
2
|
export declare const componentToVue2: (vueOptions?: VueOptsWithoutVersion) => import("../../types/transpiler").Transpiler<string>;
|
|
5
3
|
export declare const componentToVue3: (vueOptions?: VueOptsWithoutVersion) => import("../../types/transpiler").Transpiler<string>;
|
|
6
|
-
export {};
|
|
@@ -14,26 +14,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
14
14
|
};
|
|
15
15
|
return __assign.apply(this, arguments);
|
|
16
16
|
};
|
|
17
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
18
|
-
var t = {};
|
|
19
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
20
|
-
t[p] = s[p];
|
|
21
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
22
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
23
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
24
|
-
t[p[i]] = s[p[i]];
|
|
25
|
-
}
|
|
26
|
-
return t;
|
|
27
|
-
};
|
|
28
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
-
if (ar || !(i in from)) {
|
|
31
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
-
ar[i] = from[i];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
|
-
};
|
|
37
17
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
38
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
19
|
};
|
|
@@ -59,6 +39,10 @@ var helpers_1 = require("./helpers");
|
|
|
59
39
|
var optionsApi_1 = require("./optionsApi");
|
|
60
40
|
var compositionApi_1 = require("./compositionApi");
|
|
61
41
|
var blocks_1 = require("./blocks");
|
|
42
|
+
var merge_options_1 = require("../../helpers/merge-options");
|
|
43
|
+
var process_code_1 = require("../../helpers/plugins/process-code");
|
|
44
|
+
var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
45
|
+
var patterns_1 = require("../../helpers/patterns");
|
|
62
46
|
// Transform <foo.bar key="value" /> to <component :is="foo.bar" key="value" />
|
|
63
47
|
function processDynamicComponents(json, _options) {
|
|
64
48
|
(0, traverse_1.default)(json).forEach(function (node) {
|
|
@@ -115,22 +99,66 @@ var BASE_OPTIONS = {
|
|
|
115
99
|
vueVersion: 2,
|
|
116
100
|
api: 'options',
|
|
117
101
|
};
|
|
118
|
-
var mergeOptions = function (_a, _b) {
|
|
119
|
-
var _c = _a.plugins, pluginsA = _c === void 0 ? [] : _c, a = __rest(_a, ["plugins"]);
|
|
120
|
-
var _d = _b.plugins, pluginsB = _d === void 0 ? [] : _d, b = __rest(_b, ["plugins"]);
|
|
121
|
-
return (__assign(__assign(__assign({}, a), b), { plugins: __spreadArray(__spreadArray([], pluginsA, true), pluginsB, true) }));
|
|
122
|
-
};
|
|
123
102
|
var componentToVue = function (userOptions) {
|
|
124
|
-
if (userOptions === void 0) { userOptions = BASE_OPTIONS; }
|
|
125
103
|
return function (_a) {
|
|
126
|
-
var _b, _c, _d, _e, _f, _g, _h
|
|
104
|
+
var _b, _c, _d, _e, _f, _g, _h;
|
|
127
105
|
var component = _a.component, path = _a.path;
|
|
128
|
-
var options = mergeOptions(BASE_OPTIONS, userOptions);
|
|
106
|
+
var options = (0, merge_options_1.mergeOptions)(BASE_OPTIONS, userOptions);
|
|
107
|
+
options.plugins.unshift((0, process_code_1.CODE_PROCESSOR_PLUGIN)(function (codeType) {
|
|
108
|
+
if (options.api === 'composition') {
|
|
109
|
+
switch (codeType) {
|
|
110
|
+
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
|
+
};
|
|
121
|
+
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
|
+
};
|
|
136
|
+
case 'bindings':
|
|
137
|
+
return function (c) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(c); };
|
|
138
|
+
case 'hooks-deps':
|
|
139
|
+
return function (c) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(c, { includeProps: false }); };
|
|
140
|
+
case 'properties':
|
|
141
|
+
return function (c) { return c; };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
switch (codeType) {
|
|
146
|
+
case 'hooks':
|
|
147
|
+
return function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component }); };
|
|
148
|
+
case 'bindings':
|
|
149
|
+
return function (c) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(c); };
|
|
150
|
+
case 'properties':
|
|
151
|
+
case 'hooks-deps':
|
|
152
|
+
case 'state':
|
|
153
|
+
return function (c) { return c; };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}));
|
|
129
157
|
if (options.api === 'options') {
|
|
130
|
-
|
|
158
|
+
options.plugins.unshift(onUpdatePlugin);
|
|
131
159
|
}
|
|
132
160
|
else if (options.api === 'composition') {
|
|
133
|
-
|
|
161
|
+
options.plugins.unshift(functions_1.FUNCTION_HACK_PLUGIN);
|
|
134
162
|
options.asyncComponentImports = false;
|
|
135
163
|
}
|
|
136
164
|
// Make a copy we can safely mutate, similar to babel's toolchain can be used
|
|
@@ -138,24 +166,21 @@ var componentToVue = function (userOptions) {
|
|
|
138
166
|
(0, process_http_requests_1.processHttpRequests)(component);
|
|
139
167
|
processDynamicComponents(component, options);
|
|
140
168
|
processForKeys(component, options);
|
|
141
|
-
|
|
142
|
-
component = (0, plugins_1.runPreJsonPlugins)(component, options.plugins);
|
|
143
|
-
}
|
|
169
|
+
component = (0, plugins_1.runPreJsonPlugins)(component, options.plugins);
|
|
144
170
|
if (options.api === 'options') {
|
|
145
171
|
(0, map_refs_1.mapRefs)(component, function (refName) { return "this.$refs.".concat(refName); });
|
|
146
172
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
173
|
+
// need to run this before we process the component's code
|
|
174
|
+
var elementProps = Array.from((0, get_props_1.getProps)(component)).filter(function (prop) { return !(0, slots_1.isSlotProperty)(prop); });
|
|
175
|
+
component = (0, plugins_1.runPostJsonPlugins)(component, options.plugins);
|
|
150
176
|
var css = (0, collect_css_1.collectCss)(component, {
|
|
151
|
-
prefix: (
|
|
177
|
+
prefix: (_c = (_b = options.cssNamespace) === null || _b === void 0 ? void 0 : _b.call(options)) !== null && _c !== void 0 ? _c : undefined,
|
|
152
178
|
});
|
|
153
179
|
(0, strip_meta_properties_1.stripMetaProperties)(component);
|
|
154
180
|
var template = (0, function_1.pipe)(component.children.map(function (item) { return (0, blocks_1.blockToVue)(item, options, { isRootNode: true }); }).join('\n'), helpers_1.renameMitosisComponentsToKebabCase);
|
|
155
|
-
var onUpdateWithDeps = ((
|
|
156
|
-
var onUpdateWithoutDeps = ((
|
|
181
|
+
var onUpdateWithDeps = ((_d = component.hooks.onUpdate) === null || _d === void 0 ? void 0 : _d.filter(function (hook) { var _a; return (_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length; })) || [];
|
|
182
|
+
var onUpdateWithoutDeps = ((_e = component.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.filter(function (hook) { var _a; return !((_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length); })) || [];
|
|
157
183
|
var getterKeys = Object.keys((0, lodash_1.pickBy)(component.state, function (i) { return (i === null || i === void 0 ? void 0 : i.type) === 'getter'; }));
|
|
158
|
-
var elementProps = Array.from((0, get_props_1.getProps)(component)).filter(function (prop) { return !(0, slots_1.isSlotProperty)(prop); });
|
|
159
184
|
// import from vue
|
|
160
185
|
var vueImports = [];
|
|
161
186
|
if (options.vueVersion >= 3 && options.asyncComponentImports) {
|
|
@@ -163,8 +188,8 @@ var componentToVue = function (userOptions) {
|
|
|
163
188
|
}
|
|
164
189
|
if (options.api === 'composition') {
|
|
165
190
|
onUpdateWithDeps.length && vueImports.push('watch');
|
|
166
|
-
((
|
|
167
|
-
((
|
|
191
|
+
((_f = component.hooks.onMount) === null || _f === void 0 ? void 0 : _f.code) && vueImports.push('onMounted');
|
|
192
|
+
((_g = component.hooks.onUnMount) === null || _g === void 0 ? void 0 : _g.code) && vueImports.push('onUnmounted');
|
|
168
193
|
onUpdateWithoutDeps.length && vueImports.push('onUpdated');
|
|
169
194
|
(0, lodash_1.size)(getterKeys) && vueImports.push('computed');
|
|
170
195
|
(0, lodash_1.size)(component.context.set) && vueImports.push('provide');
|
|
@@ -172,7 +197,7 @@ var componentToVue = function (userOptions) {
|
|
|
172
197
|
(0, lodash_1.size)(Object.keys(component.state).filter(function (key) { var _a; return ((_a = component.state[key]) === null || _a === void 0 ? void 0 : _a.type) === 'property'; })) && vueImports.push('ref');
|
|
173
198
|
}
|
|
174
199
|
var tsLangAttribute = options.typescript ? "lang='ts'" : '';
|
|
175
|
-
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <template>\n ", "\n </template>\n\n\n <script ", " ", ">\n ", "\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n "], ["\n <template>\n ", "\n </template>\n\n\n <script ", " ", ">\n ", "\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n "])), template, options.api === 'composition' ? 'setup' : '', tsLangAttribute, vueImports.length ? "import { ".concat((0, lodash_1.uniq)(vueImports).sort().join(', '), " } from \"vue\"") : '', (options.typescript && ((
|
|
200
|
+
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <template>\n ", "\n </template>\n\n\n <script ", " ", ">\n ", "\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n "], ["\n <template>\n ", "\n </template>\n\n\n <script ", " ", ">\n ", "\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n "])), template, options.api === 'composition' ? 'setup' : '', tsLangAttribute, vueImports.length ? "import { ".concat((0, lodash_1.uniq)(vueImports).sort().join(', '), " } from \"vue\"") : '', (options.typescript && ((_h = component.types) === null || _h === void 0 ? void 0 : _h.join('\n'))) || '', (0, render_imports_1.renderPreComponent)({
|
|
176
201
|
component: component,
|
|
177
202
|
target: 'vue',
|
|
178
203
|
asyncComponentImports: options.asyncComponentImports,
|
|
@@ -181,9 +206,7 @@ var componentToVue = function (userOptions) {
|
|
|
181
206
|
: (0, optionsApi_1.generateOptionsApiScript)(component, options, path, template, elementProps, onUpdateWithDeps, onUpdateWithoutDeps), !css.trim().length
|
|
182
207
|
? ''
|
|
183
208
|
: "<style scoped>\n ".concat(css, "\n </style>"));
|
|
184
|
-
|
|
185
|
-
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
186
|
-
}
|
|
209
|
+
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
187
210
|
if (true || options.prettier !== false) {
|
|
188
211
|
try {
|
|
189
212
|
str = (0, standalone_1.format)(str, {
|
|
@@ -201,9 +224,7 @@ var componentToVue = function (userOptions) {
|
|
|
201
224
|
console.warn('Could not prettify', { string: str }, err);
|
|
202
225
|
}
|
|
203
226
|
}
|
|
204
|
-
|
|
205
|
-
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
206
|
-
}
|
|
227
|
+
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
207
228
|
for (var _i = 0, removePatterns_1 = removePatterns; _i < removePatterns_1.length; _i++) {
|
|
208
229
|
var pattern = removePatterns_1[_i];
|
|
209
230
|
str = str.replace(pattern, '');
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
function isChildren(node) {
|
|
4
4
|
var _a;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
var textValue = ((_a = node.bindings._text) === null || _a === void 0 ? void 0 : _a.code) || node.properties.__text || '';
|
|
6
|
+
var trimmedTextValue = textValue.replace(/\s+/g, '');
|
|
7
|
+
return ['props.children', 'children'].includes(trimmedTextValue);
|
|
7
8
|
}
|
|
8
9
|
exports.default = isChildren;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.mergeOptions = void 0;
|
|
24
|
+
/**
|
|
25
|
+
* Merges options while combining the `plugins` array.
|
|
26
|
+
*/
|
|
27
|
+
var mergeOptions = function (a, b) {
|
|
28
|
+
if (b === void 0) { b = {}; }
|
|
29
|
+
return __assign(__assign(__assign({}, a), b), { plugins: __spreadArray(__spreadArray([], (a.plugins || []), true), (b.plugins || []), true) });
|
|
30
|
+
};
|
|
31
|
+
exports.mergeOptions = mergeOptions;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Plugin } from '../../types/plugins';
|
|
2
|
+
declare type CodeType = 'hooks' | 'hooks-deps' | 'bindings' | 'properties' | 'state';
|
|
3
|
+
declare type CodeProcessor = (codeType: CodeType) => (code: string) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Given a `codeProcessor` function, processes all code expressions within a Mitosis component.
|
|
6
|
+
*/
|
|
7
|
+
export declare const CODE_PROCESSOR_PLUGIN: (codeProcessor: CodeProcessor) => Plugin;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CODE_PROCESSOR_PLUGIN = void 0;
|
|
4
|
+
var nullable_1 = require("../nullable");
|
|
5
|
+
var traverse_nodes_1 = require("../traverse-nodes");
|
|
6
|
+
/**
|
|
7
|
+
* Process code in bindings and properties of a node
|
|
8
|
+
*/
|
|
9
|
+
var preProcessBlockCode = function (_a) {
|
|
10
|
+
var json = _a.json, codeProcessor = _a.codeProcessor;
|
|
11
|
+
var propertiesProcessor = codeProcessor('properties');
|
|
12
|
+
for (var key in json.properties) {
|
|
13
|
+
var value = json.properties[key];
|
|
14
|
+
if (value) {
|
|
15
|
+
json.properties[key] = propertiesProcessor(value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
var bindingsProcessor = codeProcessor('bindings');
|
|
19
|
+
for (var key in json.bindings) {
|
|
20
|
+
var value = json.bindings[key];
|
|
21
|
+
if (value === null || value === void 0 ? void 0 : value.code) {
|
|
22
|
+
value.code = bindingsProcessor(value.code);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Given a `codeProcessor` function, processes all code expressions within a Mitosis component.
|
|
28
|
+
*/
|
|
29
|
+
var CODE_PROCESSOR_PLUGIN = function (codeProcessor) {
|
|
30
|
+
return function () { return ({
|
|
31
|
+
json: {
|
|
32
|
+
post: function (json) {
|
|
33
|
+
var processHookCode = codeProcessor('hooks');
|
|
34
|
+
/**
|
|
35
|
+
* process code in hooks
|
|
36
|
+
*/
|
|
37
|
+
for (var key in json.hooks) {
|
|
38
|
+
var typedKey = key;
|
|
39
|
+
var hooks = json.hooks[typedKey];
|
|
40
|
+
if ((0, nullable_1.checkIsDefined)(hooks) && Array.isArray(hooks)) {
|
|
41
|
+
for (var _i = 0, hooks_1 = hooks; _i < hooks_1.length; _i++) {
|
|
42
|
+
var hook = hooks_1[_i];
|
|
43
|
+
hook.code = processHookCode(hook.code);
|
|
44
|
+
if (hook.deps) {
|
|
45
|
+
hook.deps = codeProcessor('hooks-deps')(hook.deps);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if ((0, nullable_1.checkIsDefined)(hooks)) {
|
|
50
|
+
hooks.code = processHookCode(hooks.code);
|
|
51
|
+
if (hooks.deps) {
|
|
52
|
+
hooks.deps = codeProcessor('hooks-deps')(hooks.deps);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (var key in json.state) {
|
|
57
|
+
var state = json.state[key];
|
|
58
|
+
if (state && state.type !== 'property') {
|
|
59
|
+
state.code = codeProcessor('state')(state.code);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
(0, traverse_nodes_1.tarverseNodes)(json, function (node) {
|
|
63
|
+
preProcessBlockCode({ json: node, codeProcessor: codeProcessor });
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
}); };
|
|
68
|
+
};
|
|
69
|
+
exports.CODE_PROCESSOR_PLUGIN = CODE_PROCESSOR_PLUGIN;
|
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
import { Target } from '../types/config';
|
|
2
2
|
import { MitosisComponent, MitosisImport } from '../types/mitosis-component';
|
|
3
3
|
export declare const checkIsComponentImport: (theImport: MitosisImport) => boolean;
|
|
4
|
-
export declare const renderImport: ({ theImport, target, asyncComponentImports, preserveFileExtensions, }: {
|
|
4
|
+
export declare const renderImport: ({ theImport, target, asyncComponentImports, preserveFileExtensions, component, componentsUsed, importMapper, }: {
|
|
5
5
|
theImport: MitosisImport;
|
|
6
6
|
target: Target;
|
|
7
7
|
asyncComponentImports: boolean;
|
|
8
8
|
preserveFileExtensions?: boolean | undefined;
|
|
9
|
+
component?: MitosisComponent | null | undefined;
|
|
10
|
+
componentsUsed?: string[] | undefined;
|
|
11
|
+
importMapper?: Function | null | undefined;
|
|
9
12
|
}) => string;
|
|
10
|
-
export declare const renderImports: ({ imports, target, asyncComponentImports, excludeMitosisComponents, preserveFileExtensions, }: {
|
|
13
|
+
export declare const renderImports: ({ imports, target, asyncComponentImports, excludeMitosisComponents, preserveFileExtensions, component, componentsUsed, importMapper, }: {
|
|
11
14
|
imports: MitosisImport[];
|
|
12
15
|
target: Target;
|
|
13
16
|
asyncComponentImports: boolean;
|
|
14
17
|
excludeMitosisComponents?: boolean | undefined;
|
|
15
18
|
preserveFileExtensions?: boolean | undefined;
|
|
19
|
+
component: MitosisComponent;
|
|
20
|
+
componentsUsed?: string[] | undefined;
|
|
21
|
+
importMapper?: Function | null | undefined;
|
|
16
22
|
}) => string;
|
|
17
|
-
export declare const renderPreComponent: ({ component, target, excludeMitosisComponents, asyncComponentImports, preserveFileExtensions, }: {
|
|
23
|
+
export declare const renderPreComponent: ({ component, target, excludeMitosisComponents, asyncComponentImports, preserveFileExtensions, componentsUsed, importMapper, }: {
|
|
18
24
|
component: MitosisComponent;
|
|
19
25
|
target: Target;
|
|
20
26
|
asyncComponentImports?: boolean | undefined;
|
|
21
27
|
excludeMitosisComponents?: boolean | undefined;
|
|
22
28
|
preserveFileExtensions?: boolean | undefined;
|
|
29
|
+
componentsUsed?: string[] | undefined;
|
|
30
|
+
importMapper?: Function | null | undefined;
|
|
23
31
|
}) => string;
|
|
24
32
|
export declare const renderExportAndLocal: (component: MitosisComponent) => string;
|