@builder.io/mitosis 0.0.56-98 → 0.0.57
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/__tests__/data/blocks/content-slot-jsx.raw.jsx +4 -1
- package/dist/src/__tests__/data/blocks/form.raw.jsx +5 -5
- package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.d.ts +5 -1
- package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.jsx +3 -3
- package/dist/src/__tests__/data/jsx-json.spec.d.ts +2 -0
- package/dist/src/__tests__/data/jsx-json.spec.js +10226 -0
- package/dist/src/__tests__/shared.d.ts +7 -2
- package/dist/src/__tests__/shared.js +66 -9
- package/dist/src/constants/method-literal-prefix.d.ts +0 -1
- package/dist/src/constants/method-literal-prefix.js +0 -3
- package/dist/src/generators/angular.d.ts +2 -2
- package/dist/src/generators/angular.js +5 -3
- package/dist/src/generators/builder.d.ts +4 -11
- package/dist/src/generators/builder.js +3 -2
- package/dist/src/generators/context/svelte.d.ts +3 -0
- package/dist/src/generators/context/svelte.js +3 -0
- package/dist/src/generators/helpers/functions.d.ts +2 -0
- package/dist/src/generators/helpers/functions.js +28 -0
- package/dist/src/generators/html.d.ts +3 -3
- package/dist/src/generators/html.js +9 -7
- package/dist/src/generators/liquid.d.ts +2 -2
- package/dist/src/generators/liquid.js +4 -4
- package/dist/src/generators/lit/generate.d.ts +2 -2
- package/dist/src/generators/lit/generate.js +14 -6
- package/dist/src/generators/marko/generate.d.ts +2 -2
- package/dist/src/generators/marko/generate.js +10 -8
- package/dist/src/generators/mitosis.d.ts +3 -4
- package/dist/src/generators/mitosis.js +3 -2
- package/dist/src/generators/qwik/component-generator.d.ts +2 -2
- package/dist/src/generators/qwik/component-generator.js +49 -55
- package/dist/src/generators/qwik/component.d.ts +0 -1
- package/dist/src/generators/qwik/component.js +22 -19
- package/dist/src/generators/qwik/directives.d.ts +1 -0
- package/dist/src/generators/qwik/directives.js +11 -14
- package/dist/src/generators/qwik/jsx.d.ts +1 -1
- package/dist/src/generators/qwik/jsx.js +9 -5
- package/dist/src/generators/qwik/src-generator.js +9 -3
- package/dist/src/generators/qwik/stable-serialize.d.ts +6 -0
- package/dist/src/generators/qwik/stable-serialize.js +51 -0
- package/dist/src/generators/react/generator.d.ts +6 -0
- package/dist/src/generators/{react.js → react/generator.js} +58 -150
- package/dist/src/generators/react/helpers.d.ts +2 -0
- package/dist/src/generators/react/helpers.js +14 -0
- package/dist/src/generators/react/index.d.ts +2 -0
- package/dist/src/generators/react/index.js +18 -0
- package/dist/src/generators/react/state.d.ts +9 -0
- package/dist/src/generators/react/state.js +107 -0
- package/dist/src/generators/react/types.d.ts +10 -0
- package/dist/src/{types/string-map.js → generators/react/types.js} +0 -0
- package/dist/src/generators/react-native.d.ts +2 -2
- package/dist/src/generators/solid/index.d.ts +3 -0
- package/dist/src/generators/{solid.js → solid/index.js} +80 -40
- package/dist/src/generators/solid/state.d.ts +19 -0
- package/dist/src/generators/solid/state.js +144 -0
- package/dist/src/generators/solid/types.d.ts +6 -0
- package/dist/src/generators/solid/types.js +2 -0
- package/dist/src/generators/stencil/generate.d.ts +2 -2
- package/dist/src/generators/stencil/generate.js +5 -2
- package/dist/src/generators/svelte.d.ts +6 -7
- package/dist/src/generators/svelte.js +43 -40
- package/dist/src/generators/swift-ui.d.ts +3 -5
- package/dist/src/generators/swift-ui.js +3 -2
- package/dist/src/generators/template.d.ts +2 -2
- package/dist/src/generators/template.js +3 -2
- package/dist/src/generators/vue.d.ts +5 -3
- package/dist/src/generators/vue.js +256 -113
- package/dist/src/helpers/babel-transform.d.ts +3 -1
- package/dist/src/helpers/babel-transform.js +52 -56
- package/dist/src/helpers/get-bindings.js +3 -5
- package/dist/src/helpers/get-props.js +14 -1
- package/dist/src/helpers/get-state-object-string.js +24 -21
- package/dist/src/helpers/getters-to-functions.js +1 -11
- package/dist/src/helpers/map-refs.js +25 -25
- package/dist/src/helpers/nodes/for.d.ts +4 -0
- package/dist/src/helpers/nodes/for.js +13 -0
- package/dist/src/helpers/nullable.d.ts +2 -0
- package/dist/src/helpers/nullable.js +7 -0
- package/dist/src/helpers/patterns.d.ts +2 -0
- package/dist/src/helpers/patterns.js +5 -1
- package/dist/src/helpers/render-imports.js +3 -3
- package/dist/src/helpers/replace-identifiers.d.ts +5 -0
- package/dist/src/helpers/{replace-idenifiers.js → replace-identifiers.js} +2 -1
- package/dist/src/helpers/slots.d.ts +2 -0
- package/dist/src/helpers/slots.js +15 -1
- package/dist/src/helpers/state.d.ts +0 -2
- package/dist/src/helpers/state.js +1 -10
- package/dist/src/helpers/strip-state-and-props-refs.d.ts +1 -1
- package/dist/src/helpers/strip-state-and-props-refs.js +43 -31
- package/dist/src/helpers/styles/helpers.d.ts +1 -0
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -2
- package/dist/src/parsers/angular.js +2 -2
- package/dist/src/parsers/builder.d.ts +2 -2
- package/dist/src/parsers/builder.js +61 -43
- package/dist/src/parsers/constants/outdated-prefixes.d.ts +10 -0
- package/dist/src/parsers/constants/outdated-prefixes.js +13 -0
- package/dist/src/parsers/context.js +2 -2
- package/dist/src/parsers/helpers/state.d.ts +3 -0
- package/dist/src/parsers/helpers/state.js +30 -0
- package/dist/src/parsers/jsx/component-types.d.ts +1 -1
- package/dist/src/parsers/jsx/component-types.js +15 -2
- package/dist/src/parsers/jsx/context.js +1 -1
- package/dist/src/parsers/jsx/element-parser.d.ts +6 -0
- package/dist/src/parsers/jsx/element-parser.js +243 -0
- package/dist/src/parsers/jsx/exports.d.ts +3 -0
- package/dist/src/parsers/jsx/exports.js +78 -0
- package/dist/src/parsers/jsx/function-parser.d.ts +7 -0
- package/dist/src/parsers/jsx/function-parser.js +291 -0
- package/dist/src/parsers/jsx/helpers.d.ts +2 -0
- package/dist/src/parsers/jsx/helpers.js +30 -1
- package/dist/src/parsers/jsx/imports.d.ts +7 -0
- package/dist/src/parsers/jsx/imports.js +65 -0
- package/dist/src/parsers/jsx/index.d.ts +1 -1
- package/dist/src/parsers/jsx/index.js +1 -2
- package/dist/src/parsers/jsx/jsx.js +29 -516
- package/dist/src/parsers/jsx/state.d.ts +2 -3
- package/dist/src/parsers/jsx/state.js +15 -22
- package/dist/src/plugins/compile-away-builder-components.js +6 -0
- package/dist/src/symbols/symbol-processor.js +3 -0
- package/dist/src/targets.d.ts +21 -28
- package/dist/src/targets.js +2 -2
- package/dist/src/types/config.d.ts +11 -1
- package/dist/src/types/mitosis-component.d.ts +12 -6
- package/dist/src/types/mitosis-component.js +11 -0
- package/dist/src/types/mitosis-context.d.ts +2 -2
- package/dist/src/types/mitosis-node.d.ts +14 -5
- package/dist/src/types/mitosis-node.js +3 -0
- package/dist/src/types/transpiler.d.ts +6 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/dist/src/__tests__/angular.test.d.ts +0 -1
- package/dist/src/__tests__/angular.test.js +0 -10
- package/dist/src/__tests__/builder.test.d.ts +0 -1
- package/dist/src/__tests__/builder.test.js +0 -235
- package/dist/src/__tests__/context.test.d.ts +0 -1
- package/dist/src/__tests__/context.test.js +0 -35
- package/dist/src/__tests__/data/blocks/builder-render-block.raw.d.ts +0 -6
- package/dist/src/__tests__/data/blocks/builder-render-block.raw.jsx +0 -90
- package/dist/src/__tests__/data/blocks/builder-render-content.raw.d.ts +0 -10
- package/dist/src/__tests__/data/blocks/builder-render-content.raw.jsx +0 -69
- package/dist/src/__tests__/hash-code.test.d.ts +0 -1
- package/dist/src/__tests__/hash-code.test.js +0 -11
- package/dist/src/__tests__/html.test.d.ts +0 -1
- package/dist/src/__tests__/html.test.js +0 -7
- package/dist/src/__tests__/liquid.test.d.ts +0 -1
- package/dist/src/__tests__/liquid.test.js +0 -7
- package/dist/src/__tests__/lit.test.d.ts +0 -1
- package/dist/src/__tests__/lit.test.js +0 -7
- package/dist/src/__tests__/marko.test.d.ts +0 -1
- package/dist/src/__tests__/marko.test.js +0 -14
- package/dist/src/__tests__/parse-jsx.test.d.ts +0 -1
- package/dist/src/__tests__/parse-jsx.test.js +0 -37
- package/dist/src/__tests__/qwik/convert-method-to-function.test.d.ts +0 -1
- package/dist/src/__tests__/qwik/convert-method-to-function.test.js +0 -37
- package/dist/src/__tests__/qwik/src-generator.test.d.ts +0 -1
- package/dist/src/__tests__/qwik/src-generator.test.js +0 -65
- package/dist/src/__tests__/qwik.directive.test.d.ts +0 -1
- package/dist/src/__tests__/qwik.directive.test.js +0 -108
- package/dist/src/__tests__/qwik.test.d.ts +0 -1
- package/dist/src/__tests__/qwik.test.js +0 -465
- package/dist/src/__tests__/react-native.test.d.ts +0 -1
- package/dist/src/__tests__/react-native.test.js +0 -7
- package/dist/src/__tests__/react.test.d.ts +0 -1
- package/dist/src/__tests__/react.test.js +0 -20
- package/dist/src/__tests__/solid.test.d.ts +0 -1
- package/dist/src/__tests__/solid.test.js +0 -10
- package/dist/src/__tests__/stencil.test.d.ts +0 -1
- package/dist/src/__tests__/stencil.test.js +0 -7
- package/dist/src/__tests__/styles.test.d.ts +0 -1
- package/dist/src/__tests__/styles.test.js +0 -23
- package/dist/src/__tests__/svelte.test.d.ts +0 -1
- package/dist/src/__tests__/svelte.test.js +0 -7
- package/dist/src/__tests__/vue.test.d.ts +0 -1
- package/dist/src/__tests__/vue.test.js +0 -7
- package/dist/src/__tests__/webcomponent.test.d.ts +0 -1
- package/dist/src/__tests__/webcomponent.test.js +0 -15
- package/dist/src/constants/function-literal-prefix.d.ts +0 -1
- package/dist/src/constants/function-literal-prefix.js +0 -4
- package/dist/src/generators/qwik/convertMethodToFunction.d.ts +0 -1
- package/dist/src/generators/qwik/convertMethodToFunction.js +0 -161
- package/dist/src/generators/react.d.ts +0 -14
- package/dist/src/generators/solid.d.ts +0 -5
- package/dist/src/helpers/babel-transform.test.d.ts +0 -1
- package/dist/src/helpers/babel-transform.test.js +0 -7
- package/dist/src/helpers/generic-format.test.d.ts +0 -1
- package/dist/src/helpers/generic-format.test.js +0 -8
- package/dist/src/helpers/map-to-attributes.d.ts +0 -2
- package/dist/src/helpers/map-to-attributes.js +0 -19
- package/dist/src/helpers/map-to-css.d.ts +0 -2
- package/dist/src/helpers/map-to-css.js +0 -16
- package/dist/src/helpers/parse-reactive-script.d.ts +0 -7
- package/dist/src/helpers/parse-reactive-script.js +0 -87
- package/dist/src/helpers/remove-surrounding-block.test.d.ts +0 -1
- package/dist/src/helpers/remove-surrounding-block.test.js +0 -9
- package/dist/src/helpers/render-imports.test.d.ts +0 -1
- package/dist/src/helpers/render-imports.test.js +0 -33
- package/dist/src/helpers/replace-idenifiers.d.ts +0 -1
- package/dist/src/helpers/styles/collect-css.test.d.ts +0 -1
- package/dist/src/helpers/styles/collect-css.test.js +0 -18
- package/dist/src/parsers/html.d.ts +0 -0
- package/dist/src/parsers/html.js +0 -2
- package/dist/src/parsers/liquid.d.ts +0 -70
- package/dist/src/parsers/liquid.js +0 -2538
- package/dist/src/types/string-map.d.ts +0 -3
- package/dist/test/qwik/Accordion/high.jsx +0 -0
- package/dist/test/qwik/Accordion/low.jsx +0 -240
- package/dist/test/qwik/Accordion/med.jsx +0 -4
- package/dist/test/qwik/For/high.jsx +0 -0
- package/dist/test/qwik/For/low.jsx +0 -52
- package/dist/test/qwik/For/med.jsx +0 -4
- package/dist/test/qwik/Image/high.js +0 -9
- package/dist/test/qwik/Image/low.js +0 -0
- package/dist/test/qwik/Image/med.js +0 -155
- package/dist/test/qwik/Image.slow/high.js +0 -9
- package/dist/test/qwik/Image.slow/low.js +0 -0
- package/dist/test/qwik/Image.slow/med.js +0 -155
- package/dist/test/qwik/bindings/high.cjs +0 -0
- package/dist/test/qwik/bindings/low.cjs +0 -45
- package/dist/test/qwik/bindings/med.cjs +0 -3
- package/dist/test/qwik/button/high.js +0 -3
- package/dist/test/qwik/button/low.js +0 -25
- package/dist/test/qwik/button/med.js +0 -31
- package/dist/test/qwik/component/bindings/high.jsx +0 -0
- package/dist/test/qwik/component/bindings/low.jsx +0 -104
- package/dist/test/qwik/component/bindings/med.jsx +0 -7
- package/dist/test/qwik/component/component/inputs/high.cjsx +0 -9
- package/dist/test/qwik/component/component/inputs/low.cjsx +0 -0
- package/dist/test/qwik/component/component/inputs/med.cjsx +0 -68
- package/dist/test/qwik/for-loop.bindings/high.cjs +0 -0
- package/dist/test/qwik/for-loop.bindings/low.cjs +0 -56
- package/dist/test/qwik/for-loop.bindings/med.cjs +0 -5
- package/dist/test/qwik/hello_world/stylesheet/high.jsx +0 -0
- package/dist/test/qwik/hello_world/stylesheet/low.jsx +0 -26
- package/dist/test/qwik/hello_world/stylesheet/med.jsx +0 -4
- package/dist/test/qwik/mount/high.cjs +0 -0
- package/dist/test/qwik/mount/low.cjs +0 -47
- package/dist/test/qwik/mount/med.cjs +0 -3
- package/dist/test/qwik/page-with-symbol/high.js +0 -0
- package/dist/test/qwik/page-with-symbol/low.js +0 -33
- package/dist/test/qwik/page-with-symbol/med.js +0 -4
- package/dist/test/qwik/show-hide/high.jsx +0 -9
- package/dist/test/qwik/show-hide/low.jsx +0 -0
- package/dist/test/qwik/show-hide/med.jsx +0 -181
- package/dist/test/qwik/svg/high.js +0 -0
- package/dist/test/qwik/svg/low.js +0 -30
- package/dist/test/qwik/svg/med.js +0 -4
- package/dist/test/qwik/todo/Todo.cjs/high.cjs +0 -19
- package/dist/test/qwik/todo/Todo.cjs/low.cjs +0 -0
- package/dist/test/qwik/todo/Todo.cjs/med.cjs +0 -51
- package/dist/test/qwik/todo/Todo.js/high.js +0 -19
- package/dist/test/qwik/todo/Todo.js/low.js +0 -0
- package/dist/test/qwik/todo/Todo.js/med.js +0 -47
- package/dist/test/qwik/todo/Todo.tsx/high.tsx +0 -19
- package/dist/test/qwik/todo/Todo.tsx/low.tsx +0 -0
- package/dist/test/qwik/todo/Todo.tsx/med.tsx +0 -43
- package/dist/test/qwik/todos/Todo.tsx/high.tsx +0 -7
- package/dist/test/qwik/todos/Todo.tsx/low.tsx +0 -32
- package/dist/test/qwik/todos/Todo.tsx/med.tsx +0 -4
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -40,6 +40,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
41
|
exports.componentToVue3 = exports.componentToVue2 = exports.blockToVue = void 0;
|
|
42
42
|
var dedent_1 = __importDefault(require("dedent"));
|
|
43
|
+
var json5_1 = __importDefault(require("json5"));
|
|
44
|
+
var core_1 = require("@babel/core");
|
|
43
45
|
var standalone_1 = require("prettier/standalone");
|
|
44
46
|
var collect_css_1 = require("../helpers/styles/collect-css");
|
|
45
47
|
var fast_clone_1 = require("../helpers/fast-clone");
|
|
@@ -57,14 +59,15 @@ var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
|
|
|
57
59
|
var traverse_1 = __importDefault(require("traverse"));
|
|
58
60
|
var get_components_used_1 = require("../helpers/get-components-used");
|
|
59
61
|
var lodash_1 = require("lodash");
|
|
60
|
-
var
|
|
62
|
+
var replace_identifiers_1 = require("../helpers/replace-identifiers");
|
|
61
63
|
var filter_empty_text_nodes_1 = require("../helpers/filter-empty-text-nodes");
|
|
62
64
|
var process_http_requests_1 = require("../helpers/process-http-requests");
|
|
63
65
|
var patterns_1 = require("../helpers/patterns");
|
|
64
|
-
var method_literal_prefix_1 = require("../constants/method-literal-prefix");
|
|
65
66
|
var function_1 = require("fp-ts/lib/function");
|
|
66
67
|
var get_custom_imports_1 = require("../helpers/get-custom-imports");
|
|
67
68
|
var slots_1 = require("../helpers/slots");
|
|
69
|
+
var functions_1 = require("./helpers/functions");
|
|
70
|
+
var babel_transform_1 = require("../helpers/babel-transform");
|
|
68
71
|
function encodeQuotes(string) {
|
|
69
72
|
return string.replace(/"/g, '"');
|
|
70
73
|
}
|
|
@@ -74,6 +77,10 @@ var SPECIAL_PROPERTIES = {
|
|
|
74
77
|
V_ELSE: 'v-else',
|
|
75
78
|
V_ELSE_IF: 'v-else-if',
|
|
76
79
|
};
|
|
80
|
+
// Transform <FooBar> to <foo-bar> as Vue2 needs
|
|
81
|
+
var renameMitosisComponentsToKebabCase = function (str) {
|
|
82
|
+
return str.replace(/<\/?\w+/g, function (match) { return match.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); });
|
|
83
|
+
};
|
|
77
84
|
function getContextNames(json) {
|
|
78
85
|
return Object.keys(json.context.get);
|
|
79
86
|
}
|
|
@@ -88,22 +95,28 @@ var addBindingsToJson = function (bindings) {
|
|
|
88
95
|
};
|
|
89
96
|
// TODO: migrate all stripStateAndPropsRefs to use this here
|
|
90
97
|
// to properly replace context refs
|
|
91
|
-
function processBinding(code, _options, json) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
98
|
+
function processBinding(code, _options, json, includeProps) {
|
|
99
|
+
if (includeProps === void 0) { includeProps = true; }
|
|
100
|
+
return (0, replace_identifiers_1.replaceIdentifiers)({
|
|
101
|
+
code: (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
102
|
+
includeState: true,
|
|
103
|
+
includeProps: includeProps,
|
|
104
|
+
replaceWith: 'this.',
|
|
105
|
+
}),
|
|
106
|
+
from: getContextNames(json),
|
|
107
|
+
to: function (name) { return (_options.api === 'options' ? "this.".concat(name) : "".concat(name, ".value")); },
|
|
108
|
+
});
|
|
97
109
|
}
|
|
98
110
|
var NODE_MAPPERS = {
|
|
99
111
|
Fragment: function (json, options) {
|
|
100
112
|
return json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n');
|
|
101
113
|
},
|
|
102
|
-
For: function (
|
|
114
|
+
For: function (_json, options) {
|
|
103
115
|
var _a, _b;
|
|
104
116
|
var _c;
|
|
117
|
+
var json = _json;
|
|
105
118
|
var keyValue = json.bindings.key || { code: 'index' };
|
|
106
|
-
var forValue = "(".concat(json.
|
|
119
|
+
var forValue = "(".concat(json.scope.forName, ", index) in ").concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code));
|
|
107
120
|
if (options.vueVersion >= 3) {
|
|
108
121
|
// TODO: tmk key goes on different element (parent vs child) based on Vue 2 vs Vue 3
|
|
109
122
|
return "<template :key=\"".concat(encodeQuotes((keyValue === null || keyValue === void 0 ? void 0 : keyValue.code) || 'index'), "\" v-for=\"").concat(encodeQuotes(forValue), "\">\n ").concat(json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n'), "\n </template>");
|
|
@@ -119,7 +132,7 @@ var NODE_MAPPERS = {
|
|
|
119
132
|
Show: function (json, options, scope) {
|
|
120
133
|
var _a, _b, _c, _d, _e;
|
|
121
134
|
var _f, _g;
|
|
122
|
-
var ifValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_f = json.bindings.when) === null || _f === void 0 ? void 0 : _f.code);
|
|
135
|
+
var ifValue = (0, slots_1.replaceSlotsInString)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_f = json.bindings.when) === null || _f === void 0 ? void 0 : _f.code), function (slotName) { return "$slots.".concat(slotName); });
|
|
123
136
|
switch (options.vueVersion) {
|
|
124
137
|
case 3:
|
|
125
138
|
return "\n <template ".concat(SPECIAL_PROPERTIES.V_IF, "=\"").concat(encodeQuotes(ifValue), "\">\n ").concat(json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n'), "\n </template>\n ").concat((0, is_mitosis_node_1.isMitosisNode)(json.meta.else)
|
|
@@ -181,6 +194,17 @@ var NODE_MAPPERS = {
|
|
|
181
194
|
}
|
|
182
195
|
}
|
|
183
196
|
},
|
|
197
|
+
Slot: function (json, options) {
|
|
198
|
+
var _a, _b;
|
|
199
|
+
if (!json.bindings.name) {
|
|
200
|
+
var key = Object.keys(json.bindings).find(Boolean);
|
|
201
|
+
if (!key)
|
|
202
|
+
return '<slot />';
|
|
203
|
+
return "\n <template #".concat(key, ">\n ").concat((_a = json.bindings[key]) === null || _a === void 0 ? void 0 : _a.code, "\n </template>\n ");
|
|
204
|
+
}
|
|
205
|
+
var strippedTextCode = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.name.code);
|
|
206
|
+
return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(strippedTextCode).toLowerCase(), "\">").concat((_b = json.children) === null || _b === void 0 ? void 0 : _b.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n'), "</slot>");
|
|
207
|
+
},
|
|
184
208
|
};
|
|
185
209
|
// TODO: Maybe in the future allow defining `string | function` as values
|
|
186
210
|
var BINDING_MAPPERS = {
|
|
@@ -233,12 +257,17 @@ var stringifyBinding = function (node) {
|
|
|
233
257
|
event_1 = 'input';
|
|
234
258
|
}
|
|
235
259
|
var isAssignmentExpression = useValue.includes('=');
|
|
260
|
+
var valueWRenamedEvent = (0, replace_identifiers_1.replaceIdentifiers)({
|
|
261
|
+
code: useValue,
|
|
262
|
+
from: cusArgs[0],
|
|
263
|
+
to: '$event',
|
|
264
|
+
});
|
|
236
265
|
// TODO: proper babel transform to replace. Util for this
|
|
237
266
|
if (isAssignmentExpression) {
|
|
238
|
-
return " @".concat(event_1, "=\"").concat(encodeQuotes((0, remove_surrounding_block_1.removeSurroundingBlock)(
|
|
267
|
+
return " @".concat(event_1, "=\"").concat(encodeQuotes((0, remove_surrounding_block_1.removeSurroundingBlock)(valueWRenamedEvent)), "\" ");
|
|
239
268
|
}
|
|
240
269
|
else {
|
|
241
|
-
return " @".concat(event_1, "=\"").concat(encodeQuotes((0, remove_surrounding_block_1.removeSurroundingBlock)((0, remove_surrounding_block_1.removeSurroundingBlock)(
|
|
270
|
+
return " @".concat(event_1, "=\"").concat(encodeQuotes((0, remove_surrounding_block_1.removeSurroundingBlock)((0, remove_surrounding_block_1.removeSurroundingBlock)(valueWRenamedEvent))), "\" ");
|
|
242
271
|
}
|
|
243
272
|
}
|
|
244
273
|
else if (key === 'ref') {
|
|
@@ -335,7 +364,7 @@ function getContextProvideString(component, options) {
|
|
|
335
364
|
return str;
|
|
336
365
|
}
|
|
337
366
|
/**
|
|
338
|
-
* This plugin handle `onUpdate` code that watches
|
|
367
|
+
* This plugin handle `onUpdate` code that watches dependencies.
|
|
339
368
|
* We need to apply this workaround to be able to watch specific dependencies in Vue 2: https://stackoverflow.com/a/45853349
|
|
340
369
|
*
|
|
341
370
|
* We add a `computed` property for the dependencies, and a matching `watch` function for the `onUpdate` code
|
|
@@ -348,7 +377,7 @@ var onUpdatePlugin = function (options) { return ({
|
|
|
348
377
|
.filter(function (hook) { var _a; return (_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length; })
|
|
349
378
|
.forEach(function (hook, index) {
|
|
350
379
|
var _a;
|
|
351
|
-
var code = "
|
|
380
|
+
var code = "get ".concat(getOnUpdateHookName(index), " () {\n return {\n ").concat((_a = hook.deps) === null || _a === void 0 ? void 0 : _a.slice(1, -1).split(',').map(function (dep, k) {
|
|
352
381
|
var val = dep.trim();
|
|
353
382
|
return "".concat(k, ": ").concat(val);
|
|
354
383
|
}).join(','), "\n }\n }");
|
|
@@ -362,8 +391,9 @@ var onUpdatePlugin = function (options) { return ({
|
|
|
362
391
|
},
|
|
363
392
|
}); };
|
|
364
393
|
var BASE_OPTIONS = {
|
|
365
|
-
plugins: [
|
|
394
|
+
plugins: [],
|
|
366
395
|
vueVersion: 2,
|
|
396
|
+
api: 'options',
|
|
367
397
|
};
|
|
368
398
|
var mergeOptions = function (_a, _b) {
|
|
369
399
|
var _c = _a.plugins, pluginsA = _c === void 0 ? [] : _c, a = __rest(_a, ["plugins"]);
|
|
@@ -393,11 +423,192 @@ var appendToDataString = function (_a) {
|
|
|
393
423
|
var dataString = _a.dataString, newContent = _a.newContent;
|
|
394
424
|
return dataString.replace(/}$/, "".concat(newContent, "}"));
|
|
395
425
|
};
|
|
426
|
+
function generateOptionsApiScript(component, options, path, template, props, onUpdateWithDeps, onUpdateWithoutDeps) {
|
|
427
|
+
var _a, _b, _c;
|
|
428
|
+
var localExports = component.exports;
|
|
429
|
+
var localVarAsData = [];
|
|
430
|
+
var localVarAsFunc = [];
|
|
431
|
+
if (localExports) {
|
|
432
|
+
Object.keys(localExports).forEach(function (key) {
|
|
433
|
+
if (localExports[key].usedInLocal) {
|
|
434
|
+
if (localExports[key].isFunction) {
|
|
435
|
+
localVarAsFunc.push(key);
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
localVarAsData.push(key);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
var dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
|
|
444
|
+
data: true,
|
|
445
|
+
functions: false,
|
|
446
|
+
getters: false,
|
|
447
|
+
});
|
|
448
|
+
// Append refs to data as { foo, bar, etc }
|
|
449
|
+
dataString = appendToDataString({
|
|
450
|
+
dataString: dataString,
|
|
451
|
+
newContent: (0, get_custom_imports_1.getCustomImports)(component).join(','),
|
|
452
|
+
});
|
|
453
|
+
if (localVarAsData.length) {
|
|
454
|
+
dataString = appendToDataString({ dataString: dataString, newContent: localVarAsData.join(',') });
|
|
455
|
+
}
|
|
456
|
+
var getterString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
|
|
457
|
+
data: false,
|
|
458
|
+
getters: true,
|
|
459
|
+
functions: false,
|
|
460
|
+
valueMapper: function (code) { return processBinding(code.replace(patterns_1.GETTER, ''), options, component); },
|
|
461
|
+
});
|
|
462
|
+
var functionsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
|
|
463
|
+
data: false,
|
|
464
|
+
getters: false,
|
|
465
|
+
functions: true,
|
|
466
|
+
valueMapper: function (code) { return processBinding(code, options, component); },
|
|
467
|
+
});
|
|
468
|
+
var includeClassMapHelper = template.includes('_classStringToObject');
|
|
469
|
+
if (includeClassMapHelper) {
|
|
470
|
+
functionsString = functionsString.replace(/}\s*$/, "_classStringToObject(str) {\n const obj = {};\n if (typeof str !== 'string') { return obj }\n const classNames = str.trim().split(/\\s+/);\n for (const name of classNames) {\n obj[name] = true;\n }\n return obj;\n } }");
|
|
471
|
+
}
|
|
472
|
+
if (localVarAsFunc.length) {
|
|
473
|
+
functionsString = functionsString.replace(/}\s*$/, "".concat(localVarAsFunc.join(','), "}"));
|
|
474
|
+
}
|
|
475
|
+
// Component references to include in `component: { YourComponent, ... }
|
|
476
|
+
var componentsUsed = Array.from((0, get_components_used_1.getComponentsUsed)(component))
|
|
477
|
+
.filter(function (name) { return name.length && !name.includes('.') && name[0].toUpperCase() === name[0]; })
|
|
478
|
+
// Strip out components that compile away
|
|
479
|
+
.filter(function (name) { return !['For', 'Show', 'Fragment', 'Slot', component.name].includes(name); });
|
|
480
|
+
var propsDefinition = Array.from(props).filter(function (prop) { return prop !== 'children' && prop !== 'class'; });
|
|
481
|
+
// add default props (if set)
|
|
482
|
+
if (component.defaultProps) {
|
|
483
|
+
propsDefinition = propsDefinition.reduce(function (propsDefinition, curr) {
|
|
484
|
+
var _a;
|
|
485
|
+
return ((propsDefinition[curr] = ((_a = component.defaultProps) === null || _a === void 0 ? void 0 : _a.hasOwnProperty(curr))
|
|
486
|
+
? { default: component.defaultProps[curr] }
|
|
487
|
+
: {}),
|
|
488
|
+
propsDefinition);
|
|
489
|
+
}, {});
|
|
490
|
+
}
|
|
491
|
+
return "\n export default {\n ".concat(!component.name
|
|
492
|
+
? ''
|
|
493
|
+
: "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.size ? "props: ".concat(json5_1.default.stringify(propsDefinition), ",") : '', "\n ").concat(dataString.length < 4
|
|
494
|
+
? ''
|
|
495
|
+
: "\n data: () => (".concat(dataString, "),\n "), "\n\n ").concat((0, lodash_1.size)(component.context.set)
|
|
496
|
+
? "provide() {\n const _this = this;\n return ".concat(getContextProvideString(component, options), "\n },")
|
|
497
|
+
: '', "\n ").concat((0, lodash_1.size)(component.context.get)
|
|
498
|
+
? "inject: ".concat(getContextInjectString(component, options), ",")
|
|
499
|
+
: '', "\n\n ").concat(((_c = component.hooks.onMount) === null || _c === void 0 ? void 0 : _c.code)
|
|
500
|
+
? "mounted() {\n ".concat(processBinding(component.hooks.onMount.code, options, component), "\n },")
|
|
501
|
+
: '', "\n ").concat(onUpdateWithoutDeps.length
|
|
502
|
+
? "updated() {\n ".concat(onUpdateWithoutDeps
|
|
503
|
+
.map(function (hook) { return processBinding(hook.code, options, component); })
|
|
504
|
+
.join('\n'), "\n },")
|
|
505
|
+
: '', "\n ").concat(onUpdateWithDeps.length
|
|
506
|
+
? "watch: {\n ".concat(onUpdateWithDeps
|
|
507
|
+
.map(function (hook, index) {
|
|
508
|
+
return "".concat(getOnUpdateHookName(index), "() {\n ").concat(processBinding(hook.code, options, component), "\n }\n ");
|
|
509
|
+
})
|
|
510
|
+
.join(','), "\n },")
|
|
511
|
+
: '', "\n ").concat(component.hooks.onUnMount
|
|
512
|
+
? "unmounted() {\n ".concat(processBinding(component.hooks.onUnMount.code, options, component), "\n },")
|
|
513
|
+
: '', "\n\n ").concat(getterString.length < 4
|
|
514
|
+
? ''
|
|
515
|
+
: " \n computed: ".concat(getterString, ",\n "), "\n ").concat(functionsString.length < 4
|
|
516
|
+
? ''
|
|
517
|
+
: "\n methods: ".concat(functionsString, ",\n "), "\n }");
|
|
518
|
+
}
|
|
519
|
+
var getCompositionPropDefinition = function (_a) {
|
|
520
|
+
var options = _a.options, component = _a.component, props = _a.props;
|
|
521
|
+
var str = 'const props = ';
|
|
522
|
+
if (component.defaultProps) {
|
|
523
|
+
var generic = options.typescript ? "<".concat(component.propsTypeRef, ">") : '';
|
|
524
|
+
str += "withDefaults(defineProps".concat(generic, "(), ").concat(json5_1.default.stringify(component.defaultProps), ")");
|
|
525
|
+
}
|
|
526
|
+
else if (options.typescript && component.propsTypeRef && component.propsTypeRef !== 'any') {
|
|
527
|
+
str += "defineProps<".concat(component.propsTypeRef, ">()");
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
str += "defineProps(".concat(json5_1.default.stringify(Array.from(props)), ")");
|
|
531
|
+
}
|
|
532
|
+
return str;
|
|
533
|
+
};
|
|
534
|
+
function appendValueToRefs(input, component, options) {
|
|
535
|
+
var refKeys = Object.keys((0, lodash_1.pickBy)(component.state, function (i) { return (i === null || i === void 0 ? void 0 : i.type) === 'property'; }));
|
|
536
|
+
var output = processBinding(input, options, component, false);
|
|
537
|
+
return (0, babel_transform_1.babelTransformExpression)(output, {
|
|
538
|
+
Identifier: function (path) {
|
|
539
|
+
if (!(core_1.types.isFunctionDeclaration(path.parent) && path.parent.id === path.node) &&
|
|
540
|
+
!core_1.types.isCallExpression(path.parent) &&
|
|
541
|
+
(!core_1.types.isMemberExpression(path.parent) || core_1.types.isThisExpression(path.parent.object)) &&
|
|
542
|
+
path.parentPath.listKey !== 'arguments' &&
|
|
543
|
+
path.parentPath.listKey !== 'params' &&
|
|
544
|
+
refKeys.includes(path.node.name)) {
|
|
545
|
+
path.replaceWith(core_1.types.identifier("".concat(path.node.name, ".value")));
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
function generateCompositionApiScript(component, options, template, props, onUpdateWithDeps, onUpdateWithoutDeps) {
|
|
551
|
+
var _a, _b, _c, _d, _e;
|
|
552
|
+
var refs = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
|
|
553
|
+
data: true,
|
|
554
|
+
functions: false,
|
|
555
|
+
getters: false,
|
|
556
|
+
format: 'variables',
|
|
557
|
+
valueMapper: function (code) {
|
|
558
|
+
return processBinding("ref(".concat(code, ")"), options, component);
|
|
559
|
+
},
|
|
560
|
+
keyPrefix: 'const',
|
|
561
|
+
});
|
|
562
|
+
var methods = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
|
|
563
|
+
data: false,
|
|
564
|
+
getters: false,
|
|
565
|
+
functions: true,
|
|
566
|
+
valueMapper: function (code) { return processBinding(code, options, component, false); },
|
|
567
|
+
format: 'variables',
|
|
568
|
+
});
|
|
569
|
+
if (template.includes('_classStringToObject')) {
|
|
570
|
+
methods += " function _classStringToObject(str) {\n const obj = {};\n if (typeof str !== 'string') { return obj }\n const classNames = str.trim().split(/\\s+/);\n for (const name of classNames) {\n obj[name] = true;\n }\n return obj;\n } ";
|
|
571
|
+
}
|
|
572
|
+
var getterKeys = Object.keys((0, lodash_1.pickBy)(component.state, function (i) { return (i === null || i === void 0 ? void 0 : i.type) === 'getter'; }));
|
|
573
|
+
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n "], ["\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n "])), props.size ? getCompositionPropDefinition({ component: component, props: props, options: options }) : '', refs, (_a = Object.keys(component.context.get)) === null || _a === void 0 ? void 0 : _a.map(function (key) { return "const ".concat(key, " = inject(").concat(component.context.get[key].name, ")"); }).join('\n'), (_b = Object.keys(component.context.set)) === null || _b === void 0 ? void 0 : _b.map(function (key) { return "provide(".concat(component.context.set[key].name, ", ").concat(component.context.set[key].ref, ")"); }).join('\n'), (_c = Object.keys(component.refs)) === null || _c === void 0 ? void 0 : _c.map(function (key) { return "const ".concat(key, " = ref<").concat(component.refs[key].typeParameter, ">()"); }).join('\n'), !((_d = component.hooks.onMount) === null || _d === void 0 ? void 0 : _d.code)
|
|
574
|
+
? ''
|
|
575
|
+
: "onMounted(() => { ".concat(appendValueToRefs(component.hooks.onMount.code, component, options), "})"), !((_e = component.hooks.onUnMount) === null || _e === void 0 ? void 0 : _e.code)
|
|
576
|
+
? ''
|
|
577
|
+
: "onMounted(() => { ".concat(appendValueToRefs(component.hooks.onUnMount.code, component, options), "})"), !getterKeys
|
|
578
|
+
? ''
|
|
579
|
+
: getterKeys
|
|
580
|
+
.map(function (key) {
|
|
581
|
+
var _a, _b;
|
|
582
|
+
var code = (_b = (_a = component.state[key]) === null || _a === void 0 ? void 0 : _a.code) === null || _b === void 0 ? void 0 : _b.toString();
|
|
583
|
+
return !code
|
|
584
|
+
? ''
|
|
585
|
+
: "const ".concat(key, " = computed(").concat(appendValueToRefs(code.replace(key, '').replace('get ()', '() =>'), component, options), ")");
|
|
586
|
+
})
|
|
587
|
+
.join('\n'), !(onUpdateWithoutDeps === null || onUpdateWithoutDeps === void 0 ? void 0 : onUpdateWithoutDeps.length)
|
|
588
|
+
? ''
|
|
589
|
+
: onUpdateWithoutDeps.map(function (hook) {
|
|
590
|
+
return "onUpdated(() => ".concat(appendValueToRefs(hook.code, component, options), ")");
|
|
591
|
+
}), !(onUpdateWithDeps === null || onUpdateWithDeps === void 0 ? void 0 : onUpdateWithDeps.length)
|
|
592
|
+
? ''
|
|
593
|
+
: onUpdateWithDeps.map(function (hook) {
|
|
594
|
+
return appendValueToRefs("watch(".concat(hook.deps, ", (").concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(hook.deps), ") => { ").concat(hook.code, "})\n"), component, options);
|
|
595
|
+
}), (methods === null || methods === void 0 ? void 0 : methods.length) ? appendValueToRefs(methods, component, options) : '');
|
|
596
|
+
str = str.replace(/this\./g, ''); // strip this elsewhere (e.g. functions)
|
|
597
|
+
return str;
|
|
598
|
+
}
|
|
396
599
|
var componentToVue = function (userOptions) {
|
|
600
|
+
if (userOptions === void 0) { userOptions = BASE_OPTIONS; }
|
|
397
601
|
return function (_a) {
|
|
398
|
-
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
602
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
399
603
|
var component = _a.component, path = _a.path;
|
|
400
604
|
var options = mergeOptions(BASE_OPTIONS, userOptions);
|
|
605
|
+
if (options.api === 'options') {
|
|
606
|
+
(_b = options.plugins) === null || _b === void 0 ? void 0 : _b.unshift(onUpdatePlugin);
|
|
607
|
+
}
|
|
608
|
+
else if (options.api === 'composition') {
|
|
609
|
+
(_c = options.plugins) === null || _c === void 0 ? void 0 : _c.unshift(functions_1.FUNCTION_HACK_PLUGIN);
|
|
610
|
+
options.asyncComponentImports = false;
|
|
611
|
+
}
|
|
401
612
|
// Make a copy we can safely mutate, similar to babel's toolchain can be used
|
|
402
613
|
component = (0, fast_clone_1.fastClone)(component);
|
|
403
614
|
(0, process_http_requests_1.processHttpRequests)(component);
|
|
@@ -406,109 +617,44 @@ var componentToVue = function (userOptions) {
|
|
|
406
617
|
if (options.plugins) {
|
|
407
618
|
component = (0, plugins_1.runPreJsonPlugins)(component, options.plugins);
|
|
408
619
|
}
|
|
409
|
-
(
|
|
620
|
+
if (options.api === 'options') {
|
|
621
|
+
(0, map_refs_1.mapRefs)(component, function (refName) { return "this.$refs.".concat(refName); });
|
|
622
|
+
}
|
|
410
623
|
if (options.plugins) {
|
|
411
624
|
component = (0, plugins_1.runPostJsonPlugins)(component, options.plugins);
|
|
412
625
|
}
|
|
413
626
|
var css = (0, collect_css_1.collectCss)(component, {
|
|
414
|
-
prefix: (
|
|
415
|
-
});
|
|
416
|
-
var localExports = component.exports;
|
|
417
|
-
var localVarAsData = [];
|
|
418
|
-
var localVarAsFunc = [];
|
|
419
|
-
if (localExports) {
|
|
420
|
-
Object.keys(localExports).forEach(function (key) {
|
|
421
|
-
if (localExports[key].usedInLocal) {
|
|
422
|
-
if (localExports[key].isFunction) {
|
|
423
|
-
localVarAsFunc.push(key);
|
|
424
|
-
}
|
|
425
|
-
else {
|
|
426
|
-
localVarAsData.push(key);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
var dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
|
|
432
|
-
data: true,
|
|
433
|
-
functions: false,
|
|
434
|
-
getters: false,
|
|
435
|
-
});
|
|
436
|
-
var getterString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
|
|
437
|
-
data: false,
|
|
438
|
-
getters: true,
|
|
439
|
-
functions: false,
|
|
440
|
-
valueMapper: function (code) { return processBinding(code.replace(patterns_1.GETTER, ''), options, component); },
|
|
441
|
-
});
|
|
442
|
-
var functionsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
|
|
443
|
-
data: false,
|
|
444
|
-
getters: false,
|
|
445
|
-
functions: true,
|
|
446
|
-
valueMapper: function (code) { return processBinding(code, options, component); },
|
|
627
|
+
prefix: (_e = (_d = options.cssNamespace) === null || _d === void 0 ? void 0 : _d.call(options)) !== null && _e !== void 0 ? _e : undefined,
|
|
447
628
|
});
|
|
448
|
-
// Component references to include in `component: { YourComponent, ... }
|
|
449
|
-
var componentsUsed = Array.from((0, get_components_used_1.getComponentsUsed)(component))
|
|
450
|
-
.filter(function (name) { return name.length && !name.includes('.') && name[0].toUpperCase() === name[0]; })
|
|
451
|
-
// Strip out components that compile away
|
|
452
|
-
.filter(function (name) { return !['For', 'Show', 'Fragment', component.name].includes(name); });
|
|
453
|
-
// Append refs to data as { foo, bar, etc }
|
|
454
|
-
dataString = appendToDataString({
|
|
455
|
-
dataString: dataString,
|
|
456
|
-
newContent: (0, get_custom_imports_1.getCustomImports)(component).join(','),
|
|
457
|
-
});
|
|
458
|
-
if (localVarAsData.length) {
|
|
459
|
-
dataString = appendToDataString({ dataString: dataString, newContent: localVarAsData.join(',') });
|
|
460
|
-
}
|
|
461
|
-
var elementProps = (0, get_props_1.getProps)(component);
|
|
462
629
|
(0, strip_meta_properties_1.stripMetaProperties)(component);
|
|
463
630
|
var template = (0, function_1.pipe)(component.children.map(function (item) { return (0, exports.blockToVue)(item, options, { isRootNode: true }); }).join('\n'), renameMitosisComponentsToKebabCase);
|
|
464
|
-
var
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
631
|
+
var onUpdateWithDeps = ((_f = component.hooks.onUpdate) === null || _f === void 0 ? void 0 : _f.filter(function (hook) { var _a; return (_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length; })) || [];
|
|
632
|
+
var onUpdateWithoutDeps = ((_g = component.hooks.onUpdate) === null || _g === void 0 ? void 0 : _g.filter(function (hook) { var _a; return !((_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length); })) || [];
|
|
633
|
+
var getterKeys = Object.keys((0, lodash_1.pickBy)(component.state, function (i) { return (i === null || i === void 0 ? void 0 : i.type) === 'getter'; }));
|
|
634
|
+
var elementProps = (0, get_props_1.getProps)(component);
|
|
635
|
+
// import from vue
|
|
636
|
+
var vueImports = [];
|
|
637
|
+
if (options.vueVersion >= 3 && options.asyncComponentImports) {
|
|
638
|
+
vueImports.push('defineAsyncComponent');
|
|
470
639
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
640
|
+
if (options.api === 'composition') {
|
|
641
|
+
onUpdateWithDeps.length && vueImports.push('watch');
|
|
642
|
+
((_h = component.hooks.onMount) === null || _h === void 0 ? void 0 : _h.code) && vueImports.push('onMounted');
|
|
643
|
+
((_j = component.hooks.onUnMount) === null || _j === void 0 ? void 0 : _j.code) && vueImports.push('onUnMounted');
|
|
644
|
+
onUpdateWithoutDeps.length && vueImports.push('onUpdated');
|
|
645
|
+
(0, lodash_1.size)(getterKeys) && vueImports.push('computed');
|
|
646
|
+
(0, lodash_1.size)(component.context.set) && vueImports.push('provide');
|
|
647
|
+
(0, lodash_1.size)(component.context.get) && vueImports.push('inject');
|
|
648
|
+
(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');
|
|
480
649
|
}
|
|
481
|
-
var
|
|
650
|
+
var tsLangAttribute = options.typescript ? "lang='ts'" : '';
|
|
651
|
+
var str = (0, dedent_1.default)(templateObject_2 || (templateObject_2 = __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 && ((_k = component.types) === null || _k === void 0 ? void 0 : _k.join('\n'))) || '', (0, render_imports_1.renderPreComponent)({
|
|
482
652
|
component: component,
|
|
483
653
|
target: 'vue',
|
|
484
654
|
asyncComponentImports: options.asyncComponentImports,
|
|
485
|
-
}),
|
|
486
|
-
?
|
|
487
|
-
:
|
|
488
|
-
? ''
|
|
489
|
-
: "\n data: () => (".concat(dataString, "),\n "), (0, lodash_1.size)(component.context.set)
|
|
490
|
-
? "provide() {\n const _this = this;\n return ".concat(getContextProvideString(component, options), "\n },")
|
|
491
|
-
: '', (0, lodash_1.size)(component.context.get)
|
|
492
|
-
? "inject: ".concat(getContextInjectString(component, options), ",")
|
|
493
|
-
: '', ((_j = component.hooks.onMount) === null || _j === void 0 ? void 0 : _j.code)
|
|
494
|
-
? "mounted() {\n ".concat(processBinding(component.hooks.onMount.code, options, component), "\n },")
|
|
495
|
-
: '', onUpdateWithoutDeps.length
|
|
496
|
-
? "updated() {\n ".concat(onUpdateWithoutDeps
|
|
497
|
-
.map(function (hook) { return processBinding(hook.code, options, component); })
|
|
498
|
-
.join('\n'), "\n },")
|
|
499
|
-
: '', onUpdateWithDeps.length
|
|
500
|
-
? "watch: {\n ".concat(onUpdateWithDeps
|
|
501
|
-
.map(function (hook, index) {
|
|
502
|
-
return "".concat(getOnUpdateHookName(index), "() {\n ").concat(processBinding(hook.code, options, component), "\n }\n ");
|
|
503
|
-
})
|
|
504
|
-
.join(','), "\n },")
|
|
505
|
-
: '', component.hooks.onUnMount
|
|
506
|
-
? "unmounted() {\n ".concat(processBinding(component.hooks.onUnMount.code, options, component), "\n },")
|
|
507
|
-
: '', getterString.length < 4
|
|
508
|
-
? ''
|
|
509
|
-
: "\n computed: ".concat(getterString, ",\n "), functionsString.length < 4
|
|
510
|
-
? ''
|
|
511
|
-
: "\n methods: ".concat(functionsString, ",\n "), !css.trim().length
|
|
655
|
+
}), options.api === 'composition'
|
|
656
|
+
? generateCompositionApiScript(component, options, template, elementProps, onUpdateWithDeps, onUpdateWithoutDeps)
|
|
657
|
+
: generateOptionsApiScript(component, options, path, template, elementProps, onUpdateWithDeps, onUpdateWithoutDeps), !css.trim().length
|
|
512
658
|
? ''
|
|
513
659
|
: "<style scoped>\n ".concat(css, "\n </style>"));
|
|
514
660
|
if (options.plugins) {
|
|
@@ -520,6 +666,7 @@ var componentToVue = function (userOptions) {
|
|
|
520
666
|
parser: 'vue',
|
|
521
667
|
plugins: [
|
|
522
668
|
// To support running in browsers
|
|
669
|
+
require('prettier/parser-typescript'),
|
|
523
670
|
require('prettier/parser-html'),
|
|
524
671
|
require('prettier/parser-postcss'),
|
|
525
672
|
require('prettier/parser-babel'),
|
|
@@ -548,13 +695,9 @@ var componentToVue3 = function (vueOptions) {
|
|
|
548
695
|
return componentToVue(__assign(__assign({}, vueOptions), { vueVersion: 3 }));
|
|
549
696
|
};
|
|
550
697
|
exports.componentToVue3 = componentToVue3;
|
|
551
|
-
// Transform <FooBar> to <foo-bar> as Vue2 needs
|
|
552
|
-
var renameMitosisComponentsToKebabCase = function (str) {
|
|
553
|
-
return str.replace(/<\/?\w+/g, function (match) { return match.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); });
|
|
554
|
-
};
|
|
555
698
|
// Remove unused artifacts like empty script or style tags
|
|
556
699
|
var removePatterns = [
|
|
557
700
|
"<script>\nexport default {};\n</script>",
|
|
558
701
|
"<style>\n</style>",
|
|
559
702
|
];
|
|
560
|
-
var templateObject_1;
|
|
703
|
+
var templateObject_1, templateObject_2;
|
|
@@ -2,4 +2,6 @@ import * as babel from '@babel/core';
|
|
|
2
2
|
import type { Visitor } from '@babel/traverse';
|
|
3
3
|
export declare const babelTransform: <VisitorContextType = any>(code: string, visitor?: babel.Visitor<VisitorContextType> | undefined) => babel.BabelFileResult | null;
|
|
4
4
|
export declare const babelTransformCode: <VisitorContextType = any>(code: string, visitor?: babel.Visitor<VisitorContextType> | undefined) => string;
|
|
5
|
-
|
|
5
|
+
declare type ExpressionType = 'expression' | 'unknown' | 'block' | 'functionBody';
|
|
6
|
+
export declare const babelTransformExpression: <VisitorContextType = any>(code: string, visitor: babel.Visitor<VisitorContextType>, type?: ExpressionType) => string;
|
|
7
|
+
export {};
|