@builder.io/mitosis 0.4.0 → 0.4.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/constants/media-sizes.js +4 -5
- package/dist/src/generators/alpine/generate.js +114 -132
- package/dist/src/generators/alpine/render-mount-hook.js +8 -5
- package/dist/src/generators/alpine/render-update-hooks.js +13 -13
- package/dist/src/generators/angular/helpers.js +19 -9
- package/dist/src/generators/angular/index.js +599 -584
- package/dist/src/generators/builder.js +200 -165
- package/dist/src/generators/context/angular.js +32 -26
- package/dist/src/generators/context/helpers/context-with-symbol-key.js +25 -21
- package/dist/src/generators/context/qwik.js +21 -21
- package/dist/src/generators/context/react.js +22 -22
- package/dist/src/generators/context/rsc.js +20 -22
- package/dist/src/generators/context/solid.js +22 -22
- package/dist/src/generators/context/svelte.js +33 -28
- package/dist/src/generators/context/vue.js +1 -1
- package/dist/src/generators/helpers/context.js +6 -13
- package/dist/src/generators/helpers/functions.js +8 -8
- package/dist/src/generators/helpers/on-mount.js +9 -5
- package/dist/src/generators/helpers/rsc.js +7 -9
- package/dist/src/generators/html.js +995 -534
- package/dist/src/generators/liquid.js +81 -79
- package/dist/src/generators/lit/collect-class-string.js +10 -12
- package/dist/src/generators/lit/generate.js +204 -159
- package/dist/src/generators/marko/generate.js +193 -183
- package/dist/src/generators/minify.js +5 -9
- package/dist/src/generators/mitosis.js +135 -134
- package/dist/src/generators/qwik/component-generator.js +159 -154
- package/dist/src/generators/qwik/component.js +51 -81
- package/dist/src/generators/qwik/directives.js +68 -84
- package/dist/src/generators/qwik/helpers/add-prevent-default.js +6 -7
- package/dist/src/generators/qwik/helpers/convert-method-to-function.js +38 -38
- package/dist/src/generators/qwik/helpers/handlers.js +16 -25
- package/dist/src/generators/qwik/helpers/stable-inject.js +7 -8
- package/dist/src/generators/qwik/helpers/stable-serialize.js +7 -8
- package/dist/src/generators/qwik/helpers/state.js +36 -43
- package/dist/src/generators/qwik/helpers/styles.js +19 -40
- package/dist/src/generators/qwik/jsx.js +63 -75
- package/dist/src/generators/qwik/src-generator.js +134 -167
- package/dist/src/generators/react/blocks.js +122 -127
- package/dist/src/generators/react/generator.js +314 -259
- package/dist/src/generators/react/helpers.js +23 -28
- package/dist/src/generators/react/state.js +34 -51
- package/dist/src/generators/react-native/index.js +72 -84
- package/dist/src/generators/react-native/sanitize-react-native-block-styles.js +14 -26
- package/dist/src/generators/rsc.js +30 -36
- package/dist/src/generators/solid/blocks.js +46 -43
- package/dist/src/generators/solid/helpers/styles.js +11 -11
- package/dist/src/generators/solid/index.js +199 -190
- package/dist/src/generators/solid/state/helpers.js +76 -90
- package/dist/src/generators/solid/state/signals.js +30 -37
- package/dist/src/generators/solid/state/state.js +35 -48
- package/dist/src/generators/solid/state/store.js +40 -46
- package/dist/src/generators/stencil/collect-class-string.js +10 -12
- package/dist/src/generators/stencil/generate.js +158 -145
- package/dist/src/generators/svelte/blocks.js +146 -144
- package/dist/src/generators/svelte/helpers.js +10 -17
- package/dist/src/generators/svelte/svelte.js +321 -287
- package/dist/src/generators/swift-ui.js +162 -101
- package/dist/src/generators/taro.js +32 -36
- package/dist/src/generators/template.js +71 -74
- package/dist/src/generators/vue/blocks.js +116 -107
- package/dist/src/generators/vue/compositionApi.js +67 -50
- package/dist/src/generators/vue/helpers.js +71 -96
- package/dist/src/generators/vue/optionsApi.js +134 -105
- package/dist/src/generators/vue/vue.js +210 -207
- package/dist/src/helpers/babel-transform.js +40 -63
- package/dist/src/helpers/bindings.js +4 -12
- package/dist/src/helpers/camel-case.js +4 -5
- package/dist/src/helpers/capitalize.js +1 -1
- package/dist/src/helpers/component-file-extensions.js +23 -35
- package/dist/src/helpers/create-mitosis-component.js +22 -26
- package/dist/src/helpers/create-mitosis-context.js +5 -12
- package/dist/src/helpers/create-mitosis-node.js +10 -12
- package/dist/src/helpers/dash-case.js +2 -2
- package/dist/src/helpers/dedent.js +18 -22
- package/dist/src/helpers/event-handlers.js +1 -1
- package/dist/src/helpers/fast-clone.js +1 -1
- package/dist/src/helpers/filter-empty-text-nodes.js +2 -2
- package/dist/src/helpers/generic-format.js +7 -8
- package/dist/src/helpers/get-bindings.js +4 -4
- package/dist/src/helpers/get-components-used.js +3 -3
- package/dist/src/helpers/get-components.js +4 -4
- package/dist/src/helpers/get-custom-imports.js +10 -12
- package/dist/src/helpers/get-prop-functions.js +7 -8
- package/dist/src/helpers/get-props-ref.js +8 -8
- package/dist/src/helpers/get-props.js +12 -13
- package/dist/src/helpers/get-refs.js +4 -4
- package/dist/src/helpers/get-state-object-string.js +42 -61
- package/dist/src/helpers/get-state-used.js +7 -8
- package/dist/src/helpers/get-styles.js +6 -6
- package/dist/src/helpers/getters-to-functions.js +8 -12
- package/dist/src/helpers/handle-missing-state.js +3 -3
- package/dist/src/helpers/has-bindings-text.js +6 -6
- package/dist/src/helpers/has-component.js +4 -4
- package/dist/src/helpers/has-props.js +3 -3
- package/dist/src/helpers/has-stateful-dom.js +4 -4
- package/dist/src/helpers/has.js +3 -3
- package/dist/src/helpers/indent.js +2 -3
- package/dist/src/helpers/is-children.js +4 -5
- package/dist/src/helpers/is-component.js +1 -1
- package/dist/src/helpers/is-html-attribute.js +2 -11
- package/dist/src/helpers/is-mitosis-node.js +1 -1
- package/dist/src/helpers/is-root-text-node.js +1 -1
- package/dist/src/helpers/is-upper-case.js +1 -1
- package/dist/src/helpers/is-valid-attribute-name.js +1 -1
- package/dist/src/helpers/json.js +2 -2
- package/dist/src/helpers/map-refs.js +29 -40
- package/dist/src/helpers/merge-options.js +20 -31
- package/dist/src/helpers/mitosis-imports.js +5 -6
- package/dist/src/helpers/nodes/for.js +2 -3
- package/dist/src/helpers/nullable.js +1 -3
- package/dist/src/helpers/on-event.js +32 -36
- package/dist/src/helpers/output.js +4 -5
- package/dist/src/helpers/parse-node.js +13 -5
- package/dist/src/helpers/parsers.js +10 -14
- package/dist/src/helpers/patterns.js +6 -8
- package/dist/src/helpers/plugins/process-code/index.js +114 -120
- package/dist/src/helpers/plugins/process-signals.js +114 -125
- package/dist/src/helpers/plugins/process-target-blocks.js +18 -20
- package/dist/src/helpers/process-http-requests.js +8 -4
- package/dist/src/helpers/remove-surrounding-block.js +2 -2
- package/dist/src/helpers/render-imports.js +99 -111
- package/dist/src/helpers/replace-identifiers.js +40 -49
- package/dist/src/helpers/replace-new-lines-in-strings.js +3 -3
- package/dist/src/helpers/signals/signals.js +27 -35
- package/dist/src/helpers/slots.js +11 -20
- package/dist/src/helpers/state.js +1 -3
- package/dist/src/helpers/strip-meta-properties.js +6 -6
- package/dist/src/helpers/strip-state-and-props-refs.js +21 -32
- package/dist/src/helpers/styles/collect-css.js +39 -44
- package/dist/src/helpers/styles/collect-styled-components.js +30 -28
- package/dist/src/helpers/styles/helpers.js +23 -29
- package/dist/src/helpers/trace-reference-to-module-path.js +3 -4
- package/dist/src/helpers/transform-state-setters.js +16 -19
- package/dist/src/helpers/traverse-nodes.js +2 -2
- package/dist/src/helpers/try-prettier-format.js +3 -3
- package/dist/src/helpers/typescript-project.js +25 -25
- package/dist/src/helpers/typescript.js +1 -3
- package/dist/src/modules/plugins.js +20 -28
- package/dist/src/parsers/angular.js +49 -57
- package/dist/src/parsers/builder/builder.js +448 -343
- package/dist/src/parsers/builder/helpers.js +10 -10
- package/dist/src/parsers/context.js +15 -17
- package/dist/src/parsers/jsx/ast.js +11 -11
- package/dist/src/parsers/jsx/component-types.js +22 -32
- package/dist/src/parsers/jsx/context.js +12 -12
- package/dist/src/parsers/jsx/element-parser.js +43 -54
- package/dist/src/parsers/jsx/exports.js +12 -14
- package/dist/src/parsers/jsx/function-parser.js +108 -119
- package/dist/src/parsers/jsx/helpers.js +11 -13
- package/dist/src/parsers/jsx/hooks/helpers.js +14 -16
- package/dist/src/parsers/jsx/hooks/index.js +34 -44
- package/dist/src/parsers/jsx/hooks/use-target.js +27 -27
- package/dist/src/parsers/jsx/imports.js +7 -17
- package/dist/src/parsers/jsx/jsx.js +92 -91
- package/dist/src/parsers/jsx/props-types.js +8 -10
- package/dist/src/parsers/jsx/props.js +15 -23
- package/dist/src/parsers/jsx/signals.js +28 -29
- package/dist/src/parsers/jsx/state.d.ts +2 -4
- package/dist/src/parsers/jsx/state.js +59 -93
- package/dist/src/parsers/svelte/css/index.js +1 -1
- package/dist/src/parsers/svelte/helpers/bindings.js +18 -19
- package/dist/src/parsers/svelte/helpers/children.js +5 -6
- package/dist/src/parsers/svelte/helpers/expressions.js +7 -9
- package/dist/src/parsers/svelte/helpers/hooks.js +2 -2
- package/dist/src/parsers/svelte/helpers/post-process.js +49 -70
- package/dist/src/parsers/svelte/helpers/string.js +5 -5
- package/dist/src/parsers/svelte/html/actions.js +17 -10
- package/dist/src/parsers/svelte/html/each.js +11 -16
- package/dist/src/parsers/svelte/html/element.js +68 -78
- package/dist/src/parsers/svelte/html/fragment.js +3 -3
- package/dist/src/parsers/svelte/html/if-else.js +11 -18
- package/dist/src/parsers/svelte/html/index.js +14 -14
- package/dist/src/parsers/svelte/html/mustache-tag.js +5 -5
- package/dist/src/parsers/svelte/html/slot.js +5 -5
- package/dist/src/parsers/svelte/html/text.js +7 -14
- package/dist/src/parsers/svelte/index.js +23 -72
- package/dist/src/parsers/svelte/instance/context.js +17 -17
- package/dist/src/parsers/svelte/instance/expressions.js +2 -2
- package/dist/src/parsers/svelte/instance/functions.js +35 -30
- package/dist/src/parsers/svelte/instance/hooks.js +4 -5
- package/dist/src/parsers/svelte/instance/imports.js +11 -21
- package/dist/src/parsers/svelte/instance/index.js +22 -22
- package/dist/src/parsers/svelte/instance/properties.js +11 -23
- package/dist/src/parsers/svelte/instance/reactive.js +11 -11
- package/dist/src/parsers/svelte/instance/references.js +13 -13
- package/dist/src/parsers/svelte/instance/statements.js +3 -3
- package/dist/src/parsers/svelte/module/index.js +14 -26
- package/dist/src/parsers/svelte/typescript/index.js +27 -36
- package/dist/src/plugins/compile-away-builder-components.js +223 -156
- package/dist/src/plugins/compile-away-components.js +13 -21
- package/dist/src/plugins/map-styles.js +7 -7
- package/dist/src/symbols/symbol-processor.js +44 -62
- package/dist/src/targets.js +19 -19
- package/dist/src/types/mitosis-node.js +1 -1
- package/package.json +1 -1
|
@@ -1,100 +1,117 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
4
|
};
|
|
9
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
6
|
exports.generateCompositionApiScript = void 0;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var str = 'const props = ';
|
|
7
|
+
const dedent_1 = require("../../helpers/dedent");
|
|
8
|
+
const get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
9
|
+
const json5_1 = __importDefault(require("json5"));
|
|
10
|
+
const lodash_1 = require("lodash");
|
|
11
|
+
const helpers_1 = require("./helpers");
|
|
12
|
+
const getCompositionPropDefinition = ({ options, component, props, }) => {
|
|
13
|
+
const isTs = options.typescript;
|
|
14
|
+
let str = 'const props = ';
|
|
20
15
|
if (component.defaultProps) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.map(
|
|
16
|
+
const generic = isTs ? `<${component.propsTypeRef}>` : '';
|
|
17
|
+
const defalutPropsString = props
|
|
18
|
+
.map((prop) => {
|
|
24
19
|
var _a;
|
|
25
|
-
|
|
20
|
+
const value = component.defaultProps.hasOwnProperty(prop)
|
|
26
21
|
? (_a = component.defaultProps[prop]) === null || _a === void 0 ? void 0 : _a.code
|
|
27
22
|
: 'undefined';
|
|
28
|
-
return
|
|
23
|
+
return `${prop}: ${value}`;
|
|
29
24
|
})
|
|
30
25
|
.join(',');
|
|
31
|
-
str +=
|
|
26
|
+
str += `withDefaults(defineProps${generic}(), {${defalutPropsString}})`;
|
|
32
27
|
}
|
|
33
28
|
else if (isTs && component.propsTypeRef && component.propsTypeRef !== 'any') {
|
|
34
|
-
str +=
|
|
29
|
+
str += `defineProps<${component.propsTypeRef}>()`;
|
|
35
30
|
}
|
|
36
31
|
else {
|
|
37
|
-
str +=
|
|
32
|
+
str += `defineProps(${json5_1.default.stringify(props)})`;
|
|
38
33
|
}
|
|
39
34
|
return str;
|
|
40
35
|
};
|
|
41
36
|
function generateCompositionApiScript(component, options, template, props, onUpdateWithDeps, onUpdateWithoutDeps) {
|
|
42
37
|
var _a, _b, _c, _d, _e, _f;
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
const isTs = options.typescript;
|
|
39
|
+
let refs = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
|
|
45
40
|
data: true,
|
|
46
41
|
functions: false,
|
|
47
42
|
getters: false,
|
|
48
43
|
format: 'variables',
|
|
49
|
-
valueMapper:
|
|
50
|
-
return isTs && typeParameter ? "ref<".concat(typeParameter, ">(").concat(code, ")") : "ref(".concat(code, ")");
|
|
51
|
-
},
|
|
44
|
+
valueMapper: (code, _, typeParameter) => isTs && typeParameter ? `ref<${typeParameter}>(${code})` : `ref(${code})`,
|
|
52
45
|
keyPrefix: 'const',
|
|
53
46
|
});
|
|
54
|
-
|
|
47
|
+
let methods = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
|
|
55
48
|
data: false,
|
|
56
49
|
getters: false,
|
|
57
50
|
functions: true,
|
|
58
51
|
format: 'variables',
|
|
59
52
|
});
|
|
60
53
|
if (template.includes('_classStringToObject')) {
|
|
61
|
-
methods +=
|
|
54
|
+
methods += ` function _classStringToObject(str${isTs ? ': string' : ''}) {
|
|
55
|
+
const obj${isTs ? ': Record<string, boolean>' : ''} = {};
|
|
56
|
+
if (typeof str !== 'string') { return obj }
|
|
57
|
+
const classNames = str.trim().split(/\\s+/);
|
|
58
|
+
for (const name of classNames) {
|
|
59
|
+
obj[name] = true;
|
|
60
|
+
}
|
|
61
|
+
return obj;
|
|
62
|
+
} `;
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
const getterKeys = Object.keys((0, lodash_1.pickBy)(component.state, (i) => (i === null || i === void 0 ? void 0 : i.type) === 'getter'));
|
|
65
|
+
let str = (0, dedent_1.dedent) `
|
|
66
|
+
${props.length ? getCompositionPropDefinition({ component, props, options }) : ''}
|
|
67
|
+
${refs}
|
|
68
|
+
|
|
69
|
+
${(_a = Object.entries(component.context.get)) === null || _a === void 0 ? void 0 : _a.map(([key, context]) => {
|
|
70
|
+
return `const ${key} = inject(${(0, helpers_1.getContextKey)(context)})`;
|
|
71
|
+
}).join('\n')}
|
|
72
|
+
|
|
73
|
+
${(_b = Object.values(component.context.set)) === null || _b === void 0 ? void 0 : _b.map((contextSet) => {
|
|
74
|
+
const contextValue = (0, helpers_1.getContextValue)(contextSet);
|
|
75
|
+
const key = (0, helpers_1.getContextKey)(contextSet);
|
|
76
|
+
return `provide(${key}, ${contextValue})`;
|
|
77
|
+
}).join('\n')}
|
|
78
|
+
|
|
79
|
+
${(_c = Object.keys(component.refs)) === null || _c === void 0 ? void 0 : _c.map((key) => {
|
|
72
80
|
if (isTs) {
|
|
73
|
-
return
|
|
81
|
+
return `const ${key} = ref<${component.refs[key].typeParameter}>()`;
|
|
74
82
|
}
|
|
75
83
|
else {
|
|
76
|
-
return
|
|
84
|
+
return `const ${key} = ref(null)`;
|
|
77
85
|
}
|
|
78
|
-
}).join('\n')
|
|
86
|
+
}).join('\n')}
|
|
87
|
+
${(_e = (_d = component.hooks.onInit) === null || _d === void 0 ? void 0 : _d.code) !== null && _e !== void 0 ? _e : ''}
|
|
88
|
+
${component.hooks.onMount.map((hook) => `onMounted(() => { ${hook.code} })`).join('\n')}
|
|
89
|
+
${!((_f = component.hooks.onUnMount) === null || _f === void 0 ? void 0 : _f.code)
|
|
79
90
|
? ''
|
|
80
|
-
:
|
|
91
|
+
: `onUnmounted(() => { ${component.hooks.onUnMount.code}})`}
|
|
92
|
+
${(getterKeys === null || getterKeys === void 0 ? void 0 : getterKeys.map((key) => {
|
|
81
93
|
var _a, _b;
|
|
82
|
-
|
|
94
|
+
const code = (_b = (_a = component.state[key]) === null || _a === void 0 ? void 0 : _a.code) === null || _b === void 0 ? void 0 : _b.toString();
|
|
83
95
|
if (!code) {
|
|
84
96
|
return '';
|
|
85
97
|
}
|
|
86
98
|
// transform `foo() { return this.bar }` to `() => { return bar.value }`
|
|
87
|
-
|
|
88
|
-
|
|
99
|
+
const getterAsFunction = code.replace(key, '').trim().replace(/^\(\)/, '() =>');
|
|
100
|
+
const computedCode = `const ${key} = computed(${getterAsFunction})`;
|
|
89
101
|
return computedCode;
|
|
90
|
-
}).join('\n')) || ''
|
|
91
|
-
|
|
102
|
+
}).join('\n')) || ''}
|
|
103
|
+
|
|
104
|
+
${(onUpdateWithoutDeps === null || onUpdateWithoutDeps === void 0 ? void 0 : onUpdateWithoutDeps.map((hook) => `onUpdated(() => {${hook.code}})`).join('\n')) || ''}
|
|
105
|
+
|
|
106
|
+
${(onUpdateWithDeps === null || onUpdateWithDeps === void 0 ? void 0 : onUpdateWithDeps.map((hook) => {
|
|
107
|
+
return `watch(() => ${(0, helpers_1.processBinding)({
|
|
92
108
|
code: hook.deps || '',
|
|
93
|
-
options
|
|
109
|
+
options,
|
|
94
110
|
json: component,
|
|
95
|
-
}),
|
|
96
|
-
}).join('\n')) || ''
|
|
111
|
+
})}, () => { ${hook.code} }, {immediate: true})`;
|
|
112
|
+
}).join('\n')) || ''}
|
|
113
|
+
${methods !== null && methods !== void 0 ? methods : ''}
|
|
114
|
+
`;
|
|
97
115
|
return str;
|
|
98
116
|
}
|
|
99
117
|
exports.generateCompositionApiScript = generateCompositionApiScript;
|
|
100
|
-
var templateObject_1;
|
|
@@ -1,82 +1,66 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
3
|
exports.getContextKey = exports.checkIfContextHasStrName = exports.getContextValue = exports.processBinding = exports.getContextNames = exports.renameMitosisComponentsToKebabCase = exports.mapMitosisComponentToKebabCase = exports.encodeQuotes = exports.invertBooleanExpression = exports.getOnUpdateHookName = exports.addBindingsToJson = exports.addPropertiesToJson = void 0;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
4
|
+
const babel_transform_1 = require("../../helpers/babel-transform");
|
|
5
|
+
const get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
6
|
+
const patterns_1 = require("../../helpers/patterns");
|
|
7
|
+
const replace_identifiers_1 = require("../../helpers/replace-identifiers");
|
|
8
|
+
const slots_1 = require("../../helpers/slots");
|
|
9
|
+
const core_1 = require("@babel/core");
|
|
10
|
+
const function_1 = require("fp-ts/lib/function");
|
|
11
|
+
const lodash_1 = require("lodash");
|
|
12
|
+
const html_tags_1 = require("../../constants/html_tags");
|
|
13
|
+
const addPropertiesToJson = (properties) => (json) => ({
|
|
14
|
+
...json,
|
|
15
|
+
properties: {
|
|
16
|
+
...json.properties,
|
|
17
|
+
...properties,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
36
20
|
exports.addPropertiesToJson = addPropertiesToJson;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
const addBindingsToJson = (bindings) => (json) => ({
|
|
22
|
+
...json,
|
|
23
|
+
bindings: {
|
|
24
|
+
...json.bindings,
|
|
25
|
+
...bindings,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
40
28
|
exports.addBindingsToJson = addBindingsToJson;
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
const ON_UPDATE_HOOK_NAME = 'onUpdateHook';
|
|
30
|
+
const getOnUpdateHookName = (index) => ON_UPDATE_HOOK_NAME + `${index}`;
|
|
43
31
|
exports.getOnUpdateHookName = getOnUpdateHookName;
|
|
44
|
-
|
|
32
|
+
const invertBooleanExpression = (expression) => `!Boolean(${expression})`;
|
|
45
33
|
exports.invertBooleanExpression = invertBooleanExpression;
|
|
46
34
|
function encodeQuotes(string) {
|
|
47
35
|
return string.replace(/"/g, '"');
|
|
48
36
|
}
|
|
49
37
|
exports.encodeQuotes = encodeQuotes;
|
|
50
|
-
|
|
51
|
-
return componentName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
52
|
-
};
|
|
38
|
+
const mapMitosisComponentToKebabCase = (componentName) => componentName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
53
39
|
exports.mapMitosisComponentToKebabCase = mapMitosisComponentToKebabCase;
|
|
54
40
|
// Transform <FooBar> to <foo-bar> as Vue2 needs
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
};
|
|
41
|
+
const renameMitosisComponentsToKebabCase = (str) => str.replace(/<\/?\w+/g, (match) => {
|
|
42
|
+
const tagName = match.replaceAll('<', '').replaceAll('/', '');
|
|
43
|
+
if (html_tags_1.VALID_HTML_TAGS.includes(tagName)) {
|
|
44
|
+
return match;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return (0, exports.mapMitosisComponentToKebabCase)(match);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
66
50
|
exports.renameMitosisComponentsToKebabCase = renameMitosisComponentsToKebabCase;
|
|
67
51
|
function getContextNames(json) {
|
|
68
52
|
return Object.keys(json.context.get);
|
|
69
53
|
}
|
|
70
54
|
exports.getContextNames = getContextNames;
|
|
71
55
|
function shouldAppendValueToRef(path) {
|
|
72
|
-
|
|
56
|
+
const { parent, node } = path;
|
|
73
57
|
if (core_1.types.isFunctionDeclaration(parent) && parent.id === node) {
|
|
74
58
|
return false;
|
|
75
59
|
}
|
|
76
60
|
if (core_1.types.isCallExpression(parent)) {
|
|
77
61
|
return false;
|
|
78
62
|
}
|
|
79
|
-
|
|
63
|
+
const isMemberExpression = core_1.types.isMemberExpression(parent);
|
|
80
64
|
if (isMemberExpression &&
|
|
81
65
|
core_1.types.isThisExpression(parent.object) &&
|
|
82
66
|
core_1.types.isProgram(path.scope.block) &&
|
|
@@ -97,20 +81,19 @@ function shouldAppendValueToRef(path) {
|
|
|
97
81
|
}
|
|
98
82
|
return true;
|
|
99
83
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
84
|
+
const getAllRefs = (component) => {
|
|
85
|
+
const refKeys = Object.keys(component.refs);
|
|
86
|
+
const stateKeys = Object.keys((0, lodash_1.pickBy)(component.state, (i) => (i === null || i === void 0 ? void 0 : i.type) === 'property'));
|
|
87
|
+
const allKeys = [...refKeys, ...stateKeys];
|
|
104
88
|
return allKeys;
|
|
105
89
|
};
|
|
106
|
-
function processRefs(
|
|
107
|
-
|
|
108
|
-
var refs = options.api === 'options' ? getContextNames(component) : getAllRefs(component);
|
|
90
|
+
function processRefs({ input, component, options, thisPrefix, }) {
|
|
91
|
+
const refs = options.api === 'options' ? getContextNames(component) : getAllRefs(component);
|
|
109
92
|
return (0, babel_transform_1.babelTransformExpression)(input, {
|
|
110
|
-
Identifier
|
|
111
|
-
|
|
93
|
+
Identifier(path) {
|
|
94
|
+
const name = path.node.name;
|
|
112
95
|
if (refs.includes(name) && shouldAppendValueToRef(path)) {
|
|
113
|
-
|
|
96
|
+
const newValue = options.api === 'options' ? `${thisPrefix}.${name}` : `${name}.value`;
|
|
114
97
|
path.replaceWith(core_1.types.identifier(newValue));
|
|
115
98
|
}
|
|
116
99
|
},
|
|
@@ -118,54 +101,47 @@ function processRefs(_a) {
|
|
|
118
101
|
}
|
|
119
102
|
function prefixMethodsWithThis(input, component, options) {
|
|
120
103
|
if (options.api === 'options') {
|
|
121
|
-
|
|
122
|
-
.filter(
|
|
123
|
-
|
|
124
|
-
return (value === null || value === void 0 ? void 0 : value.type) === 'function';
|
|
125
|
-
})
|
|
126
|
-
.map(function (_a) {
|
|
127
|
-
var key = _a[0];
|
|
128
|
-
return key;
|
|
129
|
-
});
|
|
104
|
+
const allMethodNames = Object.entries(component.state)
|
|
105
|
+
.filter(([_key, value]) => (value === null || value === void 0 ? void 0 : value.type) === 'function')
|
|
106
|
+
.map(([key]) => key);
|
|
130
107
|
if (!allMethodNames.length)
|
|
131
108
|
return input;
|
|
132
|
-
return (0, replace_identifiers_1.replaceIdentifiers)({ code: input, from: allMethodNames, to:
|
|
109
|
+
return (0, replace_identifiers_1.replaceIdentifiers)({ code: input, from: allMethodNames, to: (name) => `this.${name}` });
|
|
133
110
|
}
|
|
134
111
|
else {
|
|
135
112
|
return input;
|
|
136
113
|
}
|
|
137
114
|
}
|
|
138
115
|
function optionsApiStateAndPropsReplace(name, thisPrefix, codeType) {
|
|
139
|
-
|
|
116
|
+
const prefixToUse = codeType === 'bindings' ? '' : thisPrefix + '.';
|
|
140
117
|
if (name === 'children' || name.startsWith('children.')) {
|
|
141
|
-
return
|
|
118
|
+
return `${prefixToUse}$slots.default`;
|
|
142
119
|
}
|
|
143
120
|
return (0, slots_1.isSlotProperty)(name)
|
|
144
|
-
? (0, slots_1.replaceSlotsInString)(name,
|
|
145
|
-
:
|
|
121
|
+
? (0, slots_1.replaceSlotsInString)(name, (x) => `${prefixToUse}$slots.${x}`)
|
|
122
|
+
: `${prefixToUse}${name}`;
|
|
146
123
|
}
|
|
147
124
|
// TODO: migrate all stripStateAndPropsRefs to use this here
|
|
148
125
|
// to properly replace context refs
|
|
149
|
-
|
|
150
|
-
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;
|
|
126
|
+
const processBinding = ({ code, options, json, preserveGetter = false, thisPrefix = 'this', codeType, }) => {
|
|
151
127
|
try {
|
|
152
|
-
return (0, function_1.pipe)(code, (0, replace_identifiers_1.replacePropsIdentifier)(
|
|
128
|
+
return (0, function_1.pipe)(code, (0, replace_identifiers_1.replacePropsIdentifier)((name) => {
|
|
153
129
|
switch (options.api) {
|
|
154
130
|
// keep pointing to `props.${value}`
|
|
155
131
|
case 'composition':
|
|
156
|
-
|
|
132
|
+
const slotPrefix = codeType === 'bindings' ? '$slots' : 'useSlots()';
|
|
157
133
|
if (name === 'children' || name.startsWith('children.')) {
|
|
158
|
-
return
|
|
134
|
+
return `${slotPrefix}.default`;
|
|
159
135
|
}
|
|
160
136
|
return (0, slots_1.isSlotProperty)(name)
|
|
161
|
-
? (0, slots_1.replaceSlotsInString)(name,
|
|
137
|
+
? (0, slots_1.replaceSlotsInString)(name, (x) => `${slotPrefix}.${x}`)
|
|
162
138
|
: codeType === 'bindings'
|
|
163
139
|
? name
|
|
164
|
-
:
|
|
140
|
+
: `props.${name}`;
|
|
165
141
|
case 'options':
|
|
166
142
|
return optionsApiStateAndPropsReplace(name, thisPrefix, codeType);
|
|
167
143
|
}
|
|
168
|
-
}), (0, replace_identifiers_1.replaceStateIdentifier)(
|
|
144
|
+
}), (0, replace_identifiers_1.replaceStateIdentifier)((name) => {
|
|
169
145
|
switch (options.api) {
|
|
170
146
|
case 'composition':
|
|
171
147
|
return name;
|
|
@@ -174,29 +150,28 @@ var processBinding = function (_a) {
|
|
|
174
150
|
}
|
|
175
151
|
}), codeType === 'bindings'
|
|
176
152
|
? function_1.identity
|
|
177
|
-
: (0, function_1.flow)(
|
|
153
|
+
: (0, function_1.flow)((x) => processRefs({ input: x, component: json, options, thisPrefix }), (x) => prefixMethodsWithThis(x, json, options)), preserveGetter === false ? patterns_1.stripGetter : function_1.identity);
|
|
178
154
|
}
|
|
179
155
|
catch (e) {
|
|
180
|
-
console.error('could not process bindings in ', { code
|
|
156
|
+
console.error('could not process bindings in ', { code });
|
|
181
157
|
throw e;
|
|
182
158
|
}
|
|
183
159
|
};
|
|
184
160
|
exports.processBinding = processBinding;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
var valueStr = value ? (0, get_state_object_string_1.stringifyContextValue)(value) : ref;
|
|
161
|
+
const getContextValue = ({ name, ref, value }) => {
|
|
162
|
+
const valueStr = value ? (0, get_state_object_string_1.stringifyContextValue)(value) : ref;
|
|
188
163
|
return valueStr;
|
|
189
164
|
};
|
|
190
165
|
exports.getContextValue = getContextValue;
|
|
191
|
-
|
|
166
|
+
const checkIfContextHasStrName = (context) => {
|
|
192
167
|
// check if the name is wrapped in single or double quotes
|
|
193
|
-
|
|
168
|
+
const isStrName = context.name.startsWith("'") || context.name.startsWith('"');
|
|
194
169
|
return isStrName;
|
|
195
170
|
};
|
|
196
171
|
exports.checkIfContextHasStrName = checkIfContextHasStrName;
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
172
|
+
const getContextKey = (context) => {
|
|
173
|
+
const isStrName = (0, exports.checkIfContextHasStrName)(context);
|
|
174
|
+
const key = isStrName ? context.name : `${context.name}.key`;
|
|
200
175
|
return key;
|
|
201
176
|
};
|
|
202
177
|
exports.getContextKey = getContextKey;
|