@builder.io/mitosis 0.0.95 → 0.0.97-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/generators/angular.js +1 -0
- package/dist/src/generators/qwik/component-generator.js +33 -16
- package/dist/src/generators/qwik/directives.d.ts +0 -8
- package/dist/src/generators/qwik/directives.js +1 -3
- package/dist/src/generators/qwik/helpers/state.d.ts +5 -1
- package/dist/src/generators/qwik/helpers/state.js +5 -10
- package/dist/src/generators/qwik/jsx.js +2 -2
- package/dist/src/generators/qwik/src-generator.d.ts +1 -1
- package/dist/src/generators/qwik/src-generator.js +2 -2
- package/dist/src/generators/solid/index.js +1 -0
- package/dist/src/generators/solid/state/helpers.js +20 -25
- package/dist/src/generators/svelte/svelte.js +3 -0
- package/dist/src/generators/vue/helpers.js +30 -47
- package/dist/src/generators/vue/vue.js +11 -4
- package/dist/src/helpers/plugins/process-code.d.ts +1 -1
- package/dist/src/helpers/plugins/process-code.js +1 -0
- package/dist/src/helpers/replace-identifiers.d.ts +2 -0
- package/dist/src/helpers/replace-identifiers.js +9 -1
- package/dist/src/helpers/strip-state-and-props-refs.js +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -2
|
@@ -6,7 +6,6 @@ var fast_clone_1 = require("../../helpers/fast-clone");
|
|
|
6
6
|
var collect_css_1 = require("../../helpers/styles/collect-css");
|
|
7
7
|
var state_1 = require("../../helpers/state");
|
|
8
8
|
var add_prevent_default_1 = require("./helpers/add-prevent-default");
|
|
9
|
-
var convert_method_to_function_1 = require("./helpers/convert-method-to-function");
|
|
10
9
|
var jsx_1 = require("./jsx");
|
|
11
10
|
var src_generator_1 = require("./src-generator");
|
|
12
11
|
var plugins_1 = require("../../modules/plugins");
|
|
@@ -34,6 +33,7 @@ var PLUGINS = [
|
|
|
34
33
|
case 'hooks':
|
|
35
34
|
case 'hooks-deps':
|
|
36
35
|
case 'properties':
|
|
36
|
+
case 'dynamic-jsx-elements':
|
|
37
37
|
// update signal getters to have `.value`
|
|
38
38
|
return function (code, k) {
|
|
39
39
|
// `ref` should not update the signal value access
|
|
@@ -47,7 +47,19 @@ var PLUGINS = [
|
|
|
47
47
|
to: function (x) { return (x === ref ? "".concat(x, ".value") : "".concat(ref, ".value.").concat(x)); },
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
|
-
|
|
50
|
+
// update signal getters to have `.value`
|
|
51
|
+
return (0, replace_identifiers_1.replaceStateIdentifier)(function (name) {
|
|
52
|
+
var state = json.state[name];
|
|
53
|
+
switch (state === null || state === void 0 ? void 0 : state.type) {
|
|
54
|
+
case 'getter':
|
|
55
|
+
return "".concat(name, ".value");
|
|
56
|
+
case 'function':
|
|
57
|
+
case 'method':
|
|
58
|
+
case 'property':
|
|
59
|
+
case undefined:
|
|
60
|
+
return "state.".concat(name);
|
|
61
|
+
}
|
|
62
|
+
})(code);
|
|
51
63
|
};
|
|
52
64
|
}
|
|
53
65
|
}),
|
|
@@ -77,27 +89,27 @@ var componentToQwik = function (userOptions) {
|
|
|
77
89
|
emitImports(file, component);
|
|
78
90
|
emitTypes(file, component);
|
|
79
91
|
emitExports(file, component);
|
|
80
|
-
var
|
|
81
|
-
var isLightComponent = ((_c = (_b =
|
|
82
|
-
var mutable_1 = ((_d =
|
|
83
|
-
var imports_1 = ((_e =
|
|
92
|
+
var metadata_1 = component.meta.useMetadata || {};
|
|
93
|
+
var isLightComponent = ((_c = (_b = metadata_1 === null || metadata_1 === void 0 ? void 0 : metadata_1.qwik) === null || _b === void 0 ? void 0 : _b.component) === null || _c === void 0 ? void 0 : _c.isLight) || false;
|
|
94
|
+
var mutable_1 = ((_d = metadata_1 === null || metadata_1 === void 0 ? void 0 : metadata_1.qwik) === null || _d === void 0 ? void 0 : _d.mutable) || [];
|
|
95
|
+
var imports_1 = ((_e = metadata_1 === null || metadata_1 === void 0 ? void 0 : metadata_1.qwik) === null || _e === void 0 ? void 0 : _e.imports) || {};
|
|
84
96
|
Object.keys(imports_1).forEach(function (key) { return file.import(imports_1[key], key); });
|
|
85
|
-
var state_3 = (0, state_2.emitStateMethodsAndRewriteBindings)(file, component,
|
|
97
|
+
var state_3 = (0, state_2.emitStateMethodsAndRewriteBindings)(file, component, metadata_1);
|
|
86
98
|
var hasState_1 = (0, state_1.checkHasState)(component);
|
|
87
99
|
var css_1 = null;
|
|
88
100
|
var componentFn = (0, src_generator_1.arrowFnBlock)(['props'], [
|
|
89
101
|
function () {
|
|
90
|
-
var _a
|
|
102
|
+
var _a;
|
|
91
103
|
css_1 = emitUseStyles(file, component);
|
|
92
104
|
emitUseContext(file, component);
|
|
93
105
|
emitUseRef(file, component);
|
|
94
|
-
hasState_1 &&
|
|
106
|
+
hasState_1 &&
|
|
107
|
+
(0, state_2.emitUseStore)({ file: file, stateInit: state_3, isDeep: (_a = metadata_1 === null || metadata_1 === void 0 ? void 0 : metadata_1.qwik) === null || _a === void 0 ? void 0 : _a.hasDeepStore });
|
|
108
|
+
emitUseComputed(file, component);
|
|
95
109
|
emitUseContextProvider(file, component);
|
|
96
110
|
emitUseClientEffect(file, component);
|
|
97
111
|
emitUseMount(file, component);
|
|
98
112
|
emitUseTask(file, component);
|
|
99
|
-
emitTagNameHack(file, component, (_a = component.meta.useMetadata) === null || _a === void 0 ? void 0 : _a.elementTag);
|
|
100
|
-
emitTagNameHack(file, component, (_b = component.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.componentElementTag);
|
|
101
113
|
emitJSX(file, component, mutable_1);
|
|
102
114
|
},
|
|
103
115
|
], [(component.propsTypeRef || 'any') + (isLightComponent ? '&{key?:any}' : '')]);
|
|
@@ -126,11 +138,6 @@ function emitExports(file, component) {
|
|
|
126
138
|
file.src.emit(code);
|
|
127
139
|
});
|
|
128
140
|
}
|
|
129
|
-
function emitTagNameHack(file, component, metadataValue) {
|
|
130
|
-
if (typeof metadataValue === 'string' && metadataValue) {
|
|
131
|
-
file.src.emit(metadataValue, '=', (0, convert_method_to_function_1.convertMethodToFunction)(metadataValue, (0, state_2.getStateMethodsAndGetters)(component.state), (0, state_2.getLexicalScopeVars)(component)), ';');
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
141
|
function emitUseClientEffect(file, component) {
|
|
135
142
|
if (component.hooks.onMount) {
|
|
136
143
|
// This is called useMount, but in practice it is used as
|
|
@@ -265,3 +272,13 @@ function extractGetterBody(code) {
|
|
|
265
272
|
var end = code.lastIndexOf('}');
|
|
266
273
|
return code.substring(start + 1, end).trim();
|
|
267
274
|
}
|
|
275
|
+
function emitUseComputed(file, component) {
|
|
276
|
+
for (var _i = 0, _a = Object.entries(component.state); _i < _a.length; _i++) {
|
|
277
|
+
var _b = _a[_i], key = _b[0], stateValue = _b[1];
|
|
278
|
+
switch (stateValue === null || stateValue === void 0 ? void 0 : stateValue.type) {
|
|
279
|
+
case 'getter':
|
|
280
|
+
file.src.const("\n ".concat(key, " = ").concat(file.import(file.qwikModule, 'useComputed$').localName, "(() => {\n ").concat(extractGetterBody(stateValue.code), "\n })\n "));
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
@@ -21,12 +21,4 @@ interface ImageProps {
|
|
|
21
21
|
noWebp?: boolean;
|
|
22
22
|
}
|
|
23
23
|
export declare function Image(props: ImageProps): any;
|
|
24
|
-
export declare function __passThroughProps__(dstProps: Record<string, any>, srcProps: Record<string, any>): Record<string, any>;
|
|
25
|
-
export declare function CoreButton(props: {
|
|
26
|
-
text?: string;
|
|
27
|
-
link?: string;
|
|
28
|
-
class?: string;
|
|
29
|
-
openInNewTab?: string;
|
|
30
|
-
tagName$: string;
|
|
31
|
-
}): any;
|
|
32
24
|
export {};
|
|
@@ -4,7 +4,7 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
4
4
|
return cooked;
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.Image = exports.DIRECTIVES = void 0;
|
|
8
8
|
var for_1 = require("../../helpers/nodes/for");
|
|
9
9
|
var minify_1 = require("../minify");
|
|
10
10
|
var src_generator_1 = require("./src-generator");
|
|
@@ -124,7 +124,6 @@ function __passThroughProps__(dstProps, srcProps) {
|
|
|
124
124
|
}
|
|
125
125
|
return dstProps;
|
|
126
126
|
}
|
|
127
|
-
exports.__passThroughProps__ = __passThroughProps__;
|
|
128
127
|
function CoreButton(props) {
|
|
129
128
|
var hasLink = !!props.link;
|
|
130
129
|
var hProps = {
|
|
@@ -135,5 +134,4 @@ function CoreButton(props) {
|
|
|
135
134
|
};
|
|
136
135
|
return h(hasLink ? 'a' : props.tagName$ || 'span', __passThroughProps__(hProps, props));
|
|
137
136
|
}
|
|
138
|
-
exports.CoreButton = CoreButton;
|
|
139
137
|
var templateObject_1, templateObject_2, templateObject_3;
|
|
@@ -20,7 +20,11 @@ export declare type StateValues = Record<PropertyName, StateValue>;
|
|
|
20
20
|
* @param file
|
|
21
21
|
* @param stateInit
|
|
22
22
|
*/
|
|
23
|
-
export declare function emitUseStore(file
|
|
23
|
+
export declare function emitUseStore({ file, stateInit, isDeep, }: {
|
|
24
|
+
file: File;
|
|
25
|
+
stateInit: StateInit;
|
|
26
|
+
isDeep: boolean;
|
|
27
|
+
}): void;
|
|
24
28
|
export declare function emitStateMethodsAndRewriteBindings(file: File, component: MitosisComponent, metadata: Record<string, any>): StateInit;
|
|
25
29
|
export declare function getLexicalScopeVars(component: MitosisComponent): string[];
|
|
26
30
|
export declare type MethodMap = Record<string, 'method' | 'getter'>;
|
|
@@ -21,7 +21,8 @@ var babel_transform_1 = require("../../../helpers/babel-transform");
|
|
|
21
21
|
* @param file
|
|
22
22
|
* @param stateInit
|
|
23
23
|
*/
|
|
24
|
-
function emitUseStore(
|
|
24
|
+
function emitUseStore(_a) {
|
|
25
|
+
var file = _a.file, stateInit = _a.stateInit, isDeep = _a.isDeep;
|
|
25
26
|
var state = stateInit[0];
|
|
26
27
|
var hasState = state && Object.keys(state).length > 0;
|
|
27
28
|
if (hasState) {
|
|
@@ -29,7 +30,8 @@ function emitUseStore(file, stateInit) {
|
|
|
29
30
|
if (file.options.isTypeScript) {
|
|
30
31
|
file.src.emit('<any>');
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
+
var fnArgs = [(0, stable_inject_1.stableInject)(state), isDeep ? '{deep: true}' : undefined].filter(Boolean);
|
|
34
|
+
file.src.emit("(".concat(fnArgs, ");"));
|
|
33
35
|
}
|
|
34
36
|
else {
|
|
35
37
|
// TODO hack for now so that `state` variable is defined, even though it is never read.
|
|
@@ -45,22 +47,15 @@ function emitStateMethods(file, componentState, lexicalArgs) {
|
|
|
45
47
|
var stateValue = componentState[key];
|
|
46
48
|
switch (stateValue === null || stateValue === void 0 ? void 0 : stateValue.type) {
|
|
47
49
|
case 'method':
|
|
48
|
-
case 'getter':
|
|
49
50
|
case 'function':
|
|
50
51
|
var code = stateValue.code;
|
|
51
52
|
var prefixIdx = 0;
|
|
52
|
-
if (stateValue.type === '
|
|
53
|
-
prefixIdx += 'get '.length;
|
|
54
|
-
}
|
|
55
|
-
else if (stateValue.type === 'function') {
|
|
53
|
+
if (stateValue.type === 'function') {
|
|
56
54
|
prefixIdx += 'function '.length;
|
|
57
55
|
}
|
|
58
56
|
code = code.substring(prefixIdx);
|
|
59
57
|
code = (0, convert_method_to_function_1.convertMethodToFunction)(code, methodMap, lexicalArgs).replace('(', "(".concat(lexicalArgs.join(','), ","));
|
|
60
58
|
var functionName = code.split(/\(/)[0];
|
|
61
|
-
if (stateValue.type === 'getter') {
|
|
62
|
-
stateInit.push("state.".concat(key, "=").concat(functionName, "(").concat(lexicalArgs.join(','), ")"));
|
|
63
|
-
}
|
|
64
59
|
if (!file.options.isTypeScript) {
|
|
65
60
|
// Erase type information
|
|
66
61
|
code = (0, babel_transform_1.convertTypeScriptToJS)(code);
|
|
@@ -190,11 +190,11 @@ function rewriteHandlers(file, handlers, bindings, symbolBindings) {
|
|
|
190
190
|
if (Object.prototype.hasOwnProperty.call(bindings, key)) {
|
|
191
191
|
var bindingValue = bindings[key];
|
|
192
192
|
var bindingExpr = bindingValue.code;
|
|
193
|
-
var handlerBlock =
|
|
193
|
+
var handlerBlock = handlers.get(bindingExpr);
|
|
194
194
|
if (key == 'css') {
|
|
195
195
|
continue;
|
|
196
196
|
}
|
|
197
|
-
else if (
|
|
197
|
+
else if (handlerBlock) {
|
|
198
198
|
key = "".concat(key, "$");
|
|
199
199
|
bindingExpr = (0, src_generator_1.invoke)(file.import(file.qwikModule, 'qrl'), [
|
|
200
200
|
(0, src_generator_1.quote)(file.qrlPrefix + 'high.js'),
|
|
@@ -61,7 +61,7 @@ export declare class Symbol {
|
|
|
61
61
|
}
|
|
62
62
|
export declare class Imports {
|
|
63
63
|
imports: Map<string, Map<string, Symbol>>;
|
|
64
|
-
get(moduleName: string, symbolName: string,
|
|
64
|
+
get(moduleName: string, symbolName: string, asVar?: string): Symbol;
|
|
65
65
|
hasImport(localName: string): boolean;
|
|
66
66
|
}
|
|
67
67
|
export declare function quote(text: string): string;
|
|
@@ -456,7 +456,7 @@ var Imports = /** @class */ (function () {
|
|
|
456
456
|
function Imports() {
|
|
457
457
|
this.imports = new Map();
|
|
458
458
|
}
|
|
459
|
-
Imports.prototype.get = function (moduleName, symbolName,
|
|
459
|
+
Imports.prototype.get = function (moduleName, symbolName, asVar) {
|
|
460
460
|
var importSymbols = this.imports.get(moduleName);
|
|
461
461
|
if (!importSymbols) {
|
|
462
462
|
importSymbols = new Map();
|
|
@@ -464,7 +464,7 @@ var Imports = /** @class */ (function () {
|
|
|
464
464
|
}
|
|
465
465
|
var symbol = importSymbols.get(symbolName);
|
|
466
466
|
if (!symbol) {
|
|
467
|
-
symbol = new Symbol(symbolName,
|
|
467
|
+
symbol = new Symbol(symbolName, asVar || symbolName);
|
|
468
468
|
importSymbols.set(symbolName, symbol);
|
|
469
469
|
}
|
|
470
470
|
return symbol;
|
|
@@ -135,6 +135,7 @@ var componentToSolid = function (passedOptions) {
|
|
|
135
135
|
(0, process_code_1.CODE_PROCESSOR_PLUGIN)(function (codeType) {
|
|
136
136
|
switch (codeType) {
|
|
137
137
|
case 'state':
|
|
138
|
+
case 'dynamic-jsx-elements':
|
|
138
139
|
return function (c) { return c; };
|
|
139
140
|
case 'bindings':
|
|
140
141
|
case 'hooks':
|
|
@@ -6,6 +6,7 @@ var strip_state_and_props_refs_1 = require("../../../helpers/strip-state-and-pro
|
|
|
6
6
|
var function_1 = require("fp-ts/lib/function");
|
|
7
7
|
var transform_state_setters_1 = require("../../../helpers/transform-state-setters");
|
|
8
8
|
var capitalize_1 = require("../../../helpers/capitalize");
|
|
9
|
+
var replace_identifiers_1 = require("../../../helpers/replace-identifiers");
|
|
9
10
|
var getStateSetterName = function (stateName) { return "set".concat((0, capitalize_1.capitalize)(stateName)); };
|
|
10
11
|
exports.getStateSetterName = getStateSetterName;
|
|
11
12
|
var getStateTypeForValue = function (_a) {
|
|
@@ -73,32 +74,26 @@ var updateStateSettersInCode = function (_a) {
|
|
|
73
74
|
};
|
|
74
75
|
};
|
|
75
76
|
var updateStateGettersInCode = function (options, component) {
|
|
76
|
-
return function (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
(state === null || state === void 0 ? void 0 : state.type) === 'property' ||
|
|
88
|
-
// getters become plain functions, requiring a function call to access their value
|
|
89
|
-
(state === null || state === void 0 ? void 0 : state.type) === 'getter') {
|
|
90
|
-
return "".concat(name, "()");
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
return name;
|
|
94
|
-
}
|
|
95
|
-
case 'store':
|
|
96
|
-
case 'mutable':
|
|
97
|
-
return name;
|
|
77
|
+
return (0, replace_identifiers_1.replaceStateIdentifier)(function (name) {
|
|
78
|
+
var stateType = (0, exports.getStateTypeForValue)({ value: name, component: component, options: options });
|
|
79
|
+
var state = component.state[name];
|
|
80
|
+
switch (stateType) {
|
|
81
|
+
case 'signals':
|
|
82
|
+
if (
|
|
83
|
+
// signal accessors are lazy, so we need to add a function call to property calls
|
|
84
|
+
(state === null || state === void 0 ? void 0 : state.type) === 'property' ||
|
|
85
|
+
// getters become plain functions, requiring a function call to access their value
|
|
86
|
+
(state === null || state === void 0 ? void 0 : state.type) === 'getter') {
|
|
87
|
+
return "".concat(name, "()");
|
|
98
88
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
89
|
+
else {
|
|
90
|
+
return name;
|
|
91
|
+
}
|
|
92
|
+
case 'store':
|
|
93
|
+
case 'mutable':
|
|
94
|
+
return name;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
102
97
|
};
|
|
103
98
|
var updateStateCode = function (_a) {
|
|
104
99
|
var options = _a.options, component = _a.component, _b = _a.updateSetters, updateSetters = _b === void 0 ? true : _b;
|
|
@@ -118,6 +118,7 @@ var componentToSvelte = function (userProvidedOptions) {
|
|
|
118
118
|
case 'hooks':
|
|
119
119
|
case 'hooks-deps':
|
|
120
120
|
case 'state':
|
|
121
|
+
case 'dynamic-jsx-elements':
|
|
121
122
|
return function (x) { return x; };
|
|
122
123
|
}
|
|
123
124
|
}),
|
|
@@ -131,6 +132,8 @@ var componentToSvelte = function (userProvidedOptions) {
|
|
|
131
132
|
return (0, function_1.flow)((0, helpers_2.stripStateAndProps)({ json: json, options: options }), patterns_1.stripGetter);
|
|
132
133
|
case 'properties':
|
|
133
134
|
return (0, helpers_2.stripStateAndProps)({ json: json, options: options });
|
|
135
|
+
case 'dynamic-jsx-elements':
|
|
136
|
+
return function (x) { return x; };
|
|
134
137
|
}
|
|
135
138
|
}),
|
|
136
139
|
], false);
|
|
@@ -22,8 +22,6 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.getContextKey = exports.checkIfContextHasStrName = exports.getContextValue = exports.processBinding = exports.getContextNames = exports.renameMitosisComponentsToKebabCase = exports.encodeQuotes = exports.invertBooleanExpression = exports.getOnUpdateHookName = exports.addBindingsToJson = exports.addPropertiesToJson = void 0;
|
|
24
24
|
var get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
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
25
|
var babel_transform_1 = require("../../helpers/babel-transform");
|
|
28
26
|
var core_1 = require("@babel/core");
|
|
29
27
|
var lodash_1 = require("lodash");
|
|
@@ -31,6 +29,7 @@ var patterns_1 = require("../../helpers/patterns");
|
|
|
31
29
|
var replace_identifiers_1 = require("../../helpers/replace-identifiers");
|
|
32
30
|
var slots_1 = require("../../helpers/slots");
|
|
33
31
|
var html_tags_1 = require("../../constants/html_tags");
|
|
32
|
+
var function_1 = require("fp-ts/lib/function");
|
|
34
33
|
var addPropertiesToJson = function (properties) {
|
|
35
34
|
return function (json) { return (__assign(__assign({}, json), { properties: __assign(__assign({}, json.properties), properties) })); };
|
|
36
35
|
};
|
|
@@ -148,52 +147,36 @@ function optionsApiStateAndPropsReplace(name, thisPrefix, codeType) {
|
|
|
148
147
|
var processBinding = function (_a) {
|
|
149
148
|
var code = _a.code, options = _a.options, json = _a.json, _b = _a.preserveGetter, preserveGetter = _b === void 0 ? false : _b, _c = _a.thisPrefix, thisPrefix = _c === void 0 ? 'this' : _c, codeType = _a.codeType;
|
|
150
149
|
try {
|
|
151
|
-
return (0, function_1.pipe)(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
switch (options.api) {
|
|
158
|
-
// keep pointing to `props.${value}`
|
|
159
|
-
case 'composition':
|
|
160
|
-
if (codeType === 'bindings') {
|
|
161
|
-
return (0, slots_1.isSlotProperty)(name)
|
|
162
|
-
? (0, slots_1.replaceSlotsInString)(name, function (x) { return "$slots.".concat(x); })
|
|
163
|
-
: name;
|
|
164
|
-
}
|
|
165
|
-
if (name === 'children' || name.startsWith('children.')) {
|
|
166
|
-
return "useSlots().default";
|
|
167
|
-
}
|
|
168
|
-
return (0, slots_1.isSlotProperty)(name)
|
|
169
|
-
? (0, slots_1.replaceSlotsInString)(name, function (x) { return "useSlots().".concat(x); })
|
|
170
|
-
: "props.".concat(name);
|
|
171
|
-
case 'options':
|
|
172
|
-
return optionsApiStateAndPropsReplace(name, thisPrefix, codeType);
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
}), function (code) {
|
|
176
|
-
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
177
|
-
includeState: true,
|
|
178
|
-
includeProps: false,
|
|
179
|
-
replaceWith: function (name) {
|
|
180
|
-
switch (options.api) {
|
|
181
|
-
case 'composition':
|
|
182
|
-
return name;
|
|
183
|
-
case 'options':
|
|
184
|
-
return optionsApiStateAndPropsReplace(name, thisPrefix, codeType);
|
|
150
|
+
return (0, function_1.pipe)(code, (0, replace_identifiers_1.replacePropsIdentifier)(function (name) {
|
|
151
|
+
switch (options.api) {
|
|
152
|
+
// keep pointing to `props.${value}`
|
|
153
|
+
case 'composition':
|
|
154
|
+
if (codeType === 'bindings') {
|
|
155
|
+
return (0, slots_1.isSlotProperty)(name) ? (0, slots_1.replaceSlotsInString)(name, function (x) { return "$slots.".concat(x); }) : name;
|
|
185
156
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
157
|
+
if (name === 'children' || name.startsWith('children.')) {
|
|
158
|
+
return "useSlots().default";
|
|
159
|
+
}
|
|
160
|
+
return (0, slots_1.isSlotProperty)(name)
|
|
161
|
+
? (0, slots_1.replaceSlotsInString)(name, function (x) { return "useSlots().".concat(x); })
|
|
162
|
+
: "props.".concat(name);
|
|
163
|
+
case 'options':
|
|
164
|
+
return optionsApiStateAndPropsReplace(name, thisPrefix, codeType);
|
|
165
|
+
}
|
|
166
|
+
}), (0, replace_identifiers_1.replaceStateIdentifier)(function (name) {
|
|
167
|
+
switch (options.api) {
|
|
168
|
+
case 'composition':
|
|
169
|
+
return name;
|
|
170
|
+
case 'options':
|
|
171
|
+
return optionsApiStateAndPropsReplace(name, thisPrefix, codeType);
|
|
172
|
+
}
|
|
173
|
+
}),
|
|
174
|
+
// bindings does not need process refs and prefix this
|
|
175
|
+
function (x) {
|
|
176
|
+
return codeType === 'bindings'
|
|
177
|
+
? x
|
|
178
|
+
: processRefs({ input: x, component: json, options: options, thisPrefix: thisPrefix });
|
|
179
|
+
}, function (x) { return (codeType === 'bindings' ? x : prefixMethodsWithThis(x, json, options)); }, function (x) { return (preserveGetter === false ? (0, patterns_1.stripGetter)(x) : x); });
|
|
197
180
|
}
|
|
198
181
|
catch (e) {
|
|
199
182
|
console.error('could not process bindings in ', { code: code });
|
|
@@ -41,8 +41,9 @@ var compositionApi_1 = require("./compositionApi");
|
|
|
41
41
|
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
|
-
var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
45
44
|
var bindings_1 = require("../../helpers/bindings");
|
|
45
|
+
var replace_identifiers_1 = require("../../helpers/replace-identifiers");
|
|
46
|
+
var babel_transform_1 = require("../../helpers/babel-transform");
|
|
46
47
|
// Transform <foo.bar key="value" /> to <component :is="foo.bar" key="value" />
|
|
47
48
|
function processDynamicComponents(json, _options) {
|
|
48
49
|
(0, traverse_1.default)(json).forEach(function (node) {
|
|
@@ -112,10 +113,13 @@ var componentToVue = function (userOptions) {
|
|
|
112
113
|
case 'state':
|
|
113
114
|
return function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component }); };
|
|
114
115
|
case 'bindings':
|
|
115
|
-
return
|
|
116
|
+
return (0, function_1.flow)(
|
|
117
|
+
// Strip types from any JS code that ends up in the template, because Vue does not support TS code in templates.
|
|
118
|
+
babel_transform_1.convertTypeScriptToJS, function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component, codeType: codeType }); });
|
|
116
119
|
case 'hooks-deps':
|
|
117
|
-
return
|
|
120
|
+
return (0, replace_identifiers_1.replaceStateIdentifier)(null);
|
|
118
121
|
case 'properties':
|
|
122
|
+
case 'dynamic-jsx-elements':
|
|
119
123
|
return function (c) { return c; };
|
|
120
124
|
}
|
|
121
125
|
}
|
|
@@ -124,8 +128,11 @@ var componentToVue = function (userOptions) {
|
|
|
124
128
|
case 'hooks':
|
|
125
129
|
return function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component }); };
|
|
126
130
|
case 'bindings':
|
|
127
|
-
return
|
|
131
|
+
return (0, function_1.flow)(
|
|
132
|
+
// Strip types from any JS code that ends up in the template, because Vue does not support TS code in templates.
|
|
133
|
+
babel_transform_1.convertTypeScriptToJS, function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component, codeType: codeType }); });
|
|
128
134
|
case 'properties':
|
|
135
|
+
case 'dynamic-jsx-elements':
|
|
129
136
|
case 'hooks-deps':
|
|
130
137
|
return function (c) { return c; };
|
|
131
138
|
case 'state':
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plugin } from '../../types/plugins';
|
|
2
2
|
import { MitosisComponent } from '../../types/mitosis-component';
|
|
3
|
-
declare type CodeType = 'hooks' | 'hooks-deps' | 'bindings' | 'properties' | 'state';
|
|
3
|
+
declare type CodeType = 'hooks' | 'hooks-deps' | 'bindings' | 'properties' | 'state' | 'dynamic-jsx-elements';
|
|
4
4
|
declare function codeProcessor(codeType: CodeType, json: MitosisComponent): (code: string, hookType: string) => string;
|
|
5
5
|
declare type CodeProcessor = typeof codeProcessor;
|
|
6
6
|
/**
|
|
@@ -22,6 +22,7 @@ var preProcessNodeCode = function (_a) {
|
|
|
22
22
|
value.code = bindingsProcessor(value.code, key);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
json.name = codeProcessor('dynamic-jsx-elements', parentComponent)(json.name, '');
|
|
25
26
|
};
|
|
26
27
|
/**
|
|
27
28
|
* Given a `codeProcessor` function, processes all code expressions within a Mitosis component.
|
|
@@ -4,4 +4,6 @@ declare type ReplaceArgs = {
|
|
|
4
4
|
to: string | ((identifier: string) => string) | null;
|
|
5
5
|
};
|
|
6
6
|
export declare const replaceIdentifiers: ({ code, from, to }: ReplaceArgs) => string;
|
|
7
|
+
export declare const replaceStateIdentifier: (to: ReplaceArgs['to']) => (code: string) => string;
|
|
8
|
+
export declare const replacePropsIdentifier: (to: ReplaceArgs['to']) => (code: string) => string;
|
|
7
9
|
export {};
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.replaceIdentifiers = void 0;
|
|
6
|
+
exports.replacePropsIdentifier = exports.replaceStateIdentifier = exports.replaceIdentifiers = void 0;
|
|
7
7
|
var core_1 = require("@babel/core");
|
|
8
8
|
var generator_1 = __importDefault(require("@babel/generator"));
|
|
9
9
|
var function_1 = require("fp-ts/lib/function");
|
|
@@ -141,3 +141,11 @@ var replaceIdentifiers = function (_a) {
|
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
143
|
exports.replaceIdentifiers = replaceIdentifiers;
|
|
144
|
+
var replaceStateIdentifier = function (to) { return function (code) {
|
|
145
|
+
return (0, exports.replaceIdentifiers)({ code: code, from: 'state', to: to });
|
|
146
|
+
}; };
|
|
147
|
+
exports.replaceStateIdentifier = replaceStateIdentifier;
|
|
148
|
+
var replacePropsIdentifier = function (to) { return function (code) {
|
|
149
|
+
return (0, exports.replaceIdentifiers)({ code: code, from: 'props', to: to });
|
|
150
|
+
}; };
|
|
151
|
+
exports.replacePropsIdentifier = replacePropsIdentifier;
|
|
@@ -83,14 +83,14 @@ var stripStateAndPropsRefs = function (code, _options) {
|
|
|
83
83
|
var newCode = code || '';
|
|
84
84
|
var _a = __assign(__assign({}, DEFAULT_OPTIONS), _options), replaceWith = _a.replaceWith, includeProps = _a.includeProps, includeState = _a.includeState;
|
|
85
85
|
if (includeProps !== false) {
|
|
86
|
-
newCode = (0, replace_identifiers_1.
|
|
86
|
+
newCode = (0, replace_identifiers_1.replacePropsIdentifier)(replaceWith)(newCode);
|
|
87
87
|
// TODO: webcomponent edge-case
|
|
88
88
|
if (/el\.this\.props/.test(newCode)) {
|
|
89
89
|
newCode = newCode.replace(/el\.this\.props/g, 'el.props');
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
if (includeState !== false) {
|
|
93
|
-
newCode = (0, replace_identifiers_1.
|
|
93
|
+
newCode = (0, replace_identifiers_1.replaceStateIdentifier)(replaceWith)(newCode);
|
|
94
94
|
}
|
|
95
95
|
return newCode;
|
|
96
96
|
};
|