@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,51 +1,38 @@
|
|
|
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
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
7
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
8
|
-
if (ar || !(i in from)) {
|
|
9
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
10
|
-
ar[i] = from[i];
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
14
|
-
};
|
|
15
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
4
|
};
|
|
18
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
6
|
exports.componentToVue = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
7
|
+
const babel_transform_1 = require("../../helpers/babel-transform");
|
|
8
|
+
const bindings_1 = require("../../helpers/bindings");
|
|
9
|
+
const dedent_1 = require("../../helpers/dedent");
|
|
10
|
+
const fast_clone_1 = require("../../helpers/fast-clone");
|
|
11
|
+
const get_props_1 = require("../../helpers/get-props");
|
|
12
|
+
const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
13
|
+
const map_refs_1 = require("../../helpers/map-refs");
|
|
14
|
+
const merge_options_1 = require("../../helpers/merge-options");
|
|
15
|
+
const on_event_1 = require("../../helpers/on-event");
|
|
16
|
+
const process_code_1 = require("../../helpers/plugins/process-code");
|
|
17
|
+
const process_http_requests_1 = require("../../helpers/process-http-requests");
|
|
18
|
+
const render_imports_1 = require("../../helpers/render-imports");
|
|
19
|
+
const replace_identifiers_1 = require("../../helpers/replace-identifiers");
|
|
20
|
+
const slots_1 = require("../../helpers/slots");
|
|
21
|
+
const strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
|
|
22
|
+
const collect_css_1 = require("../../helpers/styles/collect-css");
|
|
23
|
+
const function_1 = require("fp-ts/lib/function");
|
|
24
|
+
const lodash_1 = require("lodash");
|
|
25
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
26
|
+
const standalone_1 = require("prettier/standalone");
|
|
27
|
+
const plugins_1 = require("../../modules/plugins");
|
|
28
|
+
const functions_1 = require("../helpers/functions");
|
|
29
|
+
const blocks_1 = require("./blocks");
|
|
30
|
+
const compositionApi_1 = require("./compositionApi");
|
|
31
|
+
const helpers_1 = require("./helpers");
|
|
32
|
+
const optionsApi_1 = require("./optionsApi");
|
|
46
33
|
// Transform <foo.bar key="value" /> to <component :is="foo.bar" key="value" />
|
|
47
34
|
function processDynamicComponents(json, _options) {
|
|
48
|
-
(0, legacy_1.default)(json).forEach(
|
|
35
|
+
(0, legacy_1.default)(json).forEach((node) => {
|
|
49
36
|
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
50
37
|
if (node.name.includes('.')) {
|
|
51
38
|
node.bindings.is = (0, bindings_1.createSingleBinding)({ code: node.name });
|
|
@@ -55,10 +42,10 @@ function processDynamicComponents(json, _options) {
|
|
|
55
42
|
});
|
|
56
43
|
}
|
|
57
44
|
function processForKeys(json, _options) {
|
|
58
|
-
(0, legacy_1.default)(json).forEach(
|
|
45
|
+
(0, legacy_1.default)(json).forEach((node) => {
|
|
59
46
|
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
60
47
|
if (node.name === 'For') {
|
|
61
|
-
|
|
48
|
+
const firstChild = node.children[0];
|
|
62
49
|
if (firstChild && firstChild.bindings.key) {
|
|
63
50
|
node.bindings.key = firstChild.bindings.key;
|
|
64
51
|
delete firstChild.bindings.key;
|
|
@@ -73,192 +60,208 @@ function processForKeys(json, _options) {
|
|
|
73
60
|
*
|
|
74
61
|
* We add a `computed` property for the dependencies, and a matching `watch` function for the `onUpdate` code
|
|
75
62
|
*/
|
|
76
|
-
|
|
63
|
+
const onUpdatePlugin = (options) => ({
|
|
77
64
|
json: {
|
|
78
|
-
post:
|
|
65
|
+
post: (component) => {
|
|
79
66
|
if (component.hooks.onUpdate) {
|
|
80
67
|
component.hooks.onUpdate
|
|
81
|
-
.filter(
|
|
82
|
-
.forEach(
|
|
68
|
+
.filter((hook) => { var _a; return (_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length; })
|
|
69
|
+
.forEach((hook, index) => {
|
|
83
70
|
var _a;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
71
|
+
const code = `get ${(0, helpers_1.getOnUpdateHookName)(index)} () {
|
|
72
|
+
return {
|
|
73
|
+
${(_a = hook.deps) === null || _a === void 0 ? void 0 : _a.slice(1, -1).split(',').map((dep, k) => {
|
|
74
|
+
const val = dep.trim();
|
|
75
|
+
return `${k}: ${val}`;
|
|
76
|
+
}).join(',')}
|
|
77
|
+
}
|
|
78
|
+
}`;
|
|
88
79
|
component.state[(0, helpers_1.getOnUpdateHookName)(index)] = {
|
|
89
|
-
code
|
|
80
|
+
code,
|
|
90
81
|
type: 'getter',
|
|
91
82
|
};
|
|
92
83
|
});
|
|
93
84
|
}
|
|
94
85
|
},
|
|
95
86
|
},
|
|
96
|
-
});
|
|
97
|
-
|
|
87
|
+
});
|
|
88
|
+
const BASE_OPTIONS = {
|
|
98
89
|
api: 'options',
|
|
99
90
|
defineComponent: true,
|
|
100
91
|
casing: 'pascal',
|
|
101
92
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
options.asyncComponentImports = false;
|
|
117
|
-
}
|
|
118
|
-
(_b = options.plugins).unshift.apply(_b, __spreadArray(__spreadArray(__spreadArray([(0, on_event_1.processOnEventHooksPlugin)()], (options.api === 'options' ? [onUpdatePlugin] : []), false), (options.api === 'composition' ? [functions_1.FUNCTION_HACK_PLUGIN] : []), false), [(0, process_code_1.CODE_PROCESSOR_PLUGIN)(function (codeType) {
|
|
119
|
-
if (options.api === 'composition') {
|
|
120
|
-
switch (codeType) {
|
|
121
|
-
case 'hooks':
|
|
122
|
-
return function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component }); };
|
|
123
|
-
case 'state':
|
|
124
|
-
return function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component }); };
|
|
125
|
-
case 'bindings':
|
|
126
|
-
return (0, function_1.flow)(
|
|
127
|
-
// Strip types from any JS code that ends up in the template, because Vue does not support TS code in templates.
|
|
128
|
-
babel_transform_1.convertTypeScriptToJS, function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component, codeType: codeType }); });
|
|
129
|
-
case 'context-set':
|
|
130
|
-
return function (code) {
|
|
131
|
-
return (0, helpers_1.processBinding)({ code: code, options: options, json: component, preserveGetter: true });
|
|
132
|
-
};
|
|
133
|
-
case 'hooks-deps':
|
|
134
|
-
return (0, replace_identifiers_1.replaceStateIdentifier)(null);
|
|
135
|
-
case 'properties':
|
|
136
|
-
case 'dynamic-jsx-elements':
|
|
137
|
-
case 'types':
|
|
138
|
-
return function (c) { return c; };
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
switch (codeType) {
|
|
143
|
-
case 'hooks':
|
|
144
|
-
return function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component }); };
|
|
145
|
-
case 'bindings':
|
|
146
|
-
return (0, function_1.flow)(
|
|
147
|
-
// Strip types from any JS code that ends up in the template, because Vue does not support TS code in templates.
|
|
148
|
-
babel_transform_1.convertTypeScriptToJS, function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component, codeType: codeType }); });
|
|
149
|
-
case 'properties':
|
|
150
|
-
case 'dynamic-jsx-elements':
|
|
151
|
-
case 'hooks-deps':
|
|
152
|
-
case 'types':
|
|
153
|
-
return function (c) { return c; };
|
|
154
|
-
case 'state':
|
|
155
|
-
return function (c) { return (0, helpers_1.processBinding)({ code: c, options: options, json: component }); };
|
|
156
|
-
case 'context-set':
|
|
157
|
-
return function (code) {
|
|
158
|
-
return (0, helpers_1.processBinding)({
|
|
159
|
-
code: code,
|
|
160
|
-
options: options,
|
|
161
|
-
json: component,
|
|
162
|
-
thisPrefix: '_this',
|
|
163
|
-
preserveGetter: true,
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
})], false));
|
|
169
|
-
(0, process_http_requests_1.processHttpRequests)(component);
|
|
170
|
-
processDynamicComponents(component, options);
|
|
171
|
-
processForKeys(component, options);
|
|
172
|
-
component = (0, plugins_1.runPreJsonPlugins)({ json: component, plugins: options.plugins });
|
|
173
|
-
if (options.api === 'options') {
|
|
174
|
-
(0, map_refs_1.mapRefs)(component, function (refName) { return "this.$refs.".concat(refName); });
|
|
175
|
-
}
|
|
176
|
-
// need to run this before we process the component's code
|
|
177
|
-
var props = Array.from((0, get_props_1.getProps)(component));
|
|
178
|
-
var elementProps = props.filter(function (prop) { return !(0, slots_1.isSlotProperty)(prop); });
|
|
179
|
-
var slotsProps = props.filter(function (prop) { return (0, slots_1.isSlotProperty)(prop); });
|
|
180
|
-
component = (0, plugins_1.runPostJsonPlugins)({ json: component, plugins: options.plugins });
|
|
181
|
-
var css = (0, collect_css_1.collectCss)(component, {
|
|
182
|
-
prefix: (_d = (_c = options.cssNamespace) === null || _c === void 0 ? void 0 : _c.call(options)) !== null && _d !== void 0 ? _d : undefined,
|
|
183
|
-
});
|
|
184
|
-
(0, strip_meta_properties_1.stripMetaProperties)(component);
|
|
185
|
-
var templateStrBody = component.children
|
|
186
|
-
.map(function (item) { return (0, blocks_1.blockToVue)(item, options, { isRootNode: true }); })
|
|
187
|
-
.join('\n');
|
|
188
|
-
var template = options.casing === 'kebab'
|
|
189
|
-
? (0, helpers_1.renameMitosisComponentsToKebabCase)(templateStrBody)
|
|
190
|
-
: templateStrBody;
|
|
191
|
-
var onUpdateWithDeps = ((_e = component.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.filter(function (hook) { var _a; return (_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length; })) || [];
|
|
192
|
-
var onUpdateWithoutDeps = ((_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); })) || [];
|
|
193
|
-
var getterKeys = Object.keys((0, lodash_1.pickBy)(component.state, function (i) { return (i === null || i === void 0 ? void 0 : i.type) === 'getter'; }));
|
|
194
|
-
// import from vue
|
|
195
|
-
var vueImports = [];
|
|
196
|
-
if (options.asyncComponentImports) {
|
|
197
|
-
vueImports.push('defineAsyncComponent');
|
|
198
|
-
}
|
|
199
|
-
if (options.api === 'options' && options.defineComponent) {
|
|
200
|
-
vueImports.push('defineComponent');
|
|
201
|
-
}
|
|
93
|
+
const componentToVue = (userOptions) => ({ component: _component, path }) => {
|
|
94
|
+
var _a, _b, _c, _d, _e, _f;
|
|
95
|
+
// Make a copy we can safely mutate, similar to babel's toolchain can be used
|
|
96
|
+
let component = (0, fast_clone_1.fastClone)(_component);
|
|
97
|
+
const options = (0, merge_options_1.initializeOptions)({
|
|
98
|
+
target: 'vue',
|
|
99
|
+
component,
|
|
100
|
+
defaults: BASE_OPTIONS,
|
|
101
|
+
userOptions: userOptions,
|
|
102
|
+
});
|
|
103
|
+
if (options.api === 'composition') {
|
|
104
|
+
options.asyncComponentImports = false;
|
|
105
|
+
}
|
|
106
|
+
options.plugins.unshift((0, on_event_1.processOnEventHooksPlugin)(), ...(options.api === 'options' ? [onUpdatePlugin] : []), ...(options.api === 'composition' ? [functions_1.FUNCTION_HACK_PLUGIN] : []), (0, process_code_1.CODE_PROCESSOR_PLUGIN)((codeType) => {
|
|
202
107
|
if (options.api === 'composition') {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
asyncComponentImports: options.asyncComponentImports,
|
|
221
|
-
}), (options.typescript && ((_h = component.types) === null || _h === void 0 ? void 0 : _h.join('\n'))) || '', options.api === 'composition'
|
|
222
|
-
? (0, compositionApi_1.generateCompositionApiScript)(component, options, template, elementProps, onUpdateWithDeps, onUpdateWithoutDeps)
|
|
223
|
-
: (0, optionsApi_1.generateOptionsApiScript)(component, options, path, template, elementProps, onUpdateWithDeps, onUpdateWithoutDeps), !css.trim().length
|
|
224
|
-
? ''
|
|
225
|
-
: "<style scoped>\n ".concat(css, "\n </style>"));
|
|
226
|
-
str = (0, plugins_1.runPreCodePlugins)({
|
|
227
|
-
json: component,
|
|
228
|
-
code: str,
|
|
229
|
-
plugins: options.plugins,
|
|
230
|
-
options: { json: component },
|
|
231
|
-
});
|
|
232
|
-
if (true || options.prettier !== false) {
|
|
233
|
-
try {
|
|
234
|
-
str = (0, standalone_1.format)(str, {
|
|
235
|
-
parser: 'vue',
|
|
236
|
-
plugins: [
|
|
237
|
-
// To support running in browsers
|
|
238
|
-
require('prettier/parser-typescript'),
|
|
239
|
-
require('prettier/parser-html'),
|
|
240
|
-
require('prettier/parser-postcss'),
|
|
241
|
-
require('prettier/parser-babel'),
|
|
242
|
-
],
|
|
243
|
-
});
|
|
108
|
+
switch (codeType) {
|
|
109
|
+
case 'hooks':
|
|
110
|
+
return (code) => (0, helpers_1.processBinding)({ code, options, json: component });
|
|
111
|
+
case 'state':
|
|
112
|
+
return (code) => (0, helpers_1.processBinding)({ code, options, json: component });
|
|
113
|
+
case 'bindings':
|
|
114
|
+
return (0, function_1.flow)(
|
|
115
|
+
// Strip types from any JS code that ends up in the template, because Vue does not support TS code in templates.
|
|
116
|
+
babel_transform_1.convertTypeScriptToJS, (code) => (0, helpers_1.processBinding)({ code, options, json: component, codeType }));
|
|
117
|
+
case 'context-set':
|
|
118
|
+
return (code) => (0, helpers_1.processBinding)({ code, options, json: component, preserveGetter: true });
|
|
119
|
+
case 'hooks-deps':
|
|
120
|
+
return (0, replace_identifiers_1.replaceStateIdentifier)(null);
|
|
121
|
+
case 'properties':
|
|
122
|
+
case 'dynamic-jsx-elements':
|
|
123
|
+
case 'types':
|
|
124
|
+
return (c) => c;
|
|
244
125
|
}
|
|
245
|
-
|
|
246
|
-
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
switch (codeType) {
|
|
129
|
+
case 'hooks':
|
|
130
|
+
return (code) => (0, helpers_1.processBinding)({ code, options, json: component });
|
|
131
|
+
case 'bindings':
|
|
132
|
+
return (0, function_1.flow)(
|
|
133
|
+
// Strip types from any JS code that ends up in the template, because Vue does not support TS code in templates.
|
|
134
|
+
babel_transform_1.convertTypeScriptToJS, (code) => (0, helpers_1.processBinding)({ code, options, json: component, codeType }));
|
|
135
|
+
case 'properties':
|
|
136
|
+
case 'dynamic-jsx-elements':
|
|
137
|
+
case 'hooks-deps':
|
|
138
|
+
case 'types':
|
|
139
|
+
return (c) => c;
|
|
140
|
+
case 'state':
|
|
141
|
+
return (c) => (0, helpers_1.processBinding)({ code: c, options, json: component });
|
|
142
|
+
case 'context-set':
|
|
143
|
+
return (code) => (0, helpers_1.processBinding)({
|
|
144
|
+
code,
|
|
145
|
+
options,
|
|
146
|
+
json: component,
|
|
147
|
+
thisPrefix: '_this',
|
|
148
|
+
preserveGetter: true,
|
|
149
|
+
});
|
|
247
150
|
}
|
|
248
151
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
152
|
+
}));
|
|
153
|
+
(0, process_http_requests_1.processHttpRequests)(component);
|
|
154
|
+
processDynamicComponents(component, options);
|
|
155
|
+
processForKeys(component, options);
|
|
156
|
+
component = (0, plugins_1.runPreJsonPlugins)({ json: component, plugins: options.plugins });
|
|
157
|
+
if (options.api === 'options') {
|
|
158
|
+
(0, map_refs_1.mapRefs)(component, (refName) => `this.$refs.${refName}`);
|
|
159
|
+
}
|
|
160
|
+
// need to run this before we process the component's code
|
|
161
|
+
const props = Array.from((0, get_props_1.getProps)(component));
|
|
162
|
+
const elementProps = props.filter((prop) => !(0, slots_1.isSlotProperty)(prop));
|
|
163
|
+
const slotsProps = props.filter((prop) => (0, slots_1.isSlotProperty)(prop));
|
|
164
|
+
component = (0, plugins_1.runPostJsonPlugins)({ json: component, plugins: options.plugins });
|
|
165
|
+
const css = (0, collect_css_1.collectCss)(component, {
|
|
166
|
+
prefix: (_b = (_a = options.cssNamespace) === null || _a === void 0 ? void 0 : _a.call(options)) !== null && _b !== void 0 ? _b : undefined,
|
|
167
|
+
});
|
|
168
|
+
(0, strip_meta_properties_1.stripMetaProperties)(component);
|
|
169
|
+
const templateStrBody = component.children
|
|
170
|
+
.map((item) => (0, blocks_1.blockToVue)(item, options, { isRootNode: true }))
|
|
171
|
+
.join('\n');
|
|
172
|
+
const template = options.casing === 'kebab'
|
|
173
|
+
? (0, helpers_1.renameMitosisComponentsToKebabCase)(templateStrBody)
|
|
174
|
+
: templateStrBody;
|
|
175
|
+
const onUpdateWithDeps = ((_c = component.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.filter((hook) => { var _a; return (_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length; })) || [];
|
|
176
|
+
const onUpdateWithoutDeps = ((_d = component.hooks.onUpdate) === null || _d === void 0 ? void 0 : _d.filter((hook) => { var _a; return !((_a = hook.deps) === null || _a === void 0 ? void 0 : _a.length); })) || [];
|
|
177
|
+
const getterKeys = Object.keys((0, lodash_1.pickBy)(component.state, (i) => (i === null || i === void 0 ? void 0 : i.type) === 'getter'));
|
|
178
|
+
// import from vue
|
|
179
|
+
let vueImports = [];
|
|
180
|
+
if (options.asyncComponentImports) {
|
|
181
|
+
vueImports.push('defineAsyncComponent');
|
|
182
|
+
}
|
|
183
|
+
if (options.api === 'options' && options.defineComponent) {
|
|
184
|
+
vueImports.push('defineComponent');
|
|
185
|
+
}
|
|
186
|
+
if (options.api === 'composition') {
|
|
187
|
+
onUpdateWithDeps.length && vueImports.push('watch');
|
|
188
|
+
component.hooks.onMount.length && vueImports.push('onMounted');
|
|
189
|
+
((_e = component.hooks.onUnMount) === null || _e === void 0 ? void 0 : _e.code) && vueImports.push('onUnmounted');
|
|
190
|
+
onUpdateWithoutDeps.length && vueImports.push('onUpdated');
|
|
191
|
+
(0, lodash_1.size)(getterKeys) && vueImports.push('computed');
|
|
192
|
+
(0, lodash_1.size)(component.context.set) && vueImports.push('provide');
|
|
193
|
+
(0, lodash_1.size)(component.context.get) && vueImports.push('inject');
|
|
194
|
+
(0, lodash_1.size)(Object.keys(component.state).filter((key) => { var _a; return ((_a = component.state[key]) === null || _a === void 0 ? void 0 : _a.type) === 'property'; })) && vueImports.push('ref');
|
|
195
|
+
(0, lodash_1.size)(slotsProps) && vueImports.push('useSlots');
|
|
196
|
+
}
|
|
197
|
+
const tsLangAttribute = options.typescript ? `lang='ts'` : '';
|
|
198
|
+
let str = (0, dedent_1.dedent) `
|
|
199
|
+
${template.trim().length > 0
|
|
200
|
+
? `<template>
|
|
201
|
+
${template}
|
|
202
|
+
</template>`
|
|
203
|
+
: ''}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
<script ${options.api === 'composition' ? 'setup' : ''} ${tsLangAttribute}>
|
|
207
|
+
${vueImports.length ? `import { ${(0, lodash_1.uniq)(vueImports).sort().join(', ')} } from "vue"` : ''}
|
|
208
|
+
|
|
209
|
+
${(0, render_imports_1.renderPreComponent)({
|
|
210
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
211
|
+
component,
|
|
212
|
+
target: 'vue',
|
|
213
|
+
asyncComponentImports: options.asyncComponentImports,
|
|
214
|
+
})}
|
|
215
|
+
|
|
216
|
+
${(options.typescript && ((_f = component.types) === null || _f === void 0 ? void 0 : _f.join('\n'))) || ''}
|
|
217
|
+
|
|
218
|
+
${options.api === 'composition'
|
|
219
|
+
? (0, compositionApi_1.generateCompositionApiScript)(component, options, template, elementProps, onUpdateWithDeps, onUpdateWithoutDeps)
|
|
220
|
+
: (0, optionsApi_1.generateOptionsApiScript)(component, options, path, template, elementProps, onUpdateWithDeps, onUpdateWithoutDeps)}
|
|
221
|
+
</script>
|
|
222
|
+
|
|
223
|
+
${!css.trim().length
|
|
224
|
+
? ''
|
|
225
|
+
: `<style scoped>
|
|
226
|
+
${css}
|
|
227
|
+
</style>`}
|
|
228
|
+
`;
|
|
229
|
+
str = (0, plugins_1.runPreCodePlugins)({
|
|
230
|
+
json: component,
|
|
231
|
+
code: str,
|
|
232
|
+
plugins: options.plugins,
|
|
233
|
+
options: { json: component },
|
|
234
|
+
});
|
|
235
|
+
if (true || options.prettier !== false) {
|
|
236
|
+
try {
|
|
237
|
+
str = (0, standalone_1.format)(str, {
|
|
238
|
+
parser: 'vue',
|
|
239
|
+
plugins: [
|
|
240
|
+
// To support running in browsers
|
|
241
|
+
require('prettier/parser-typescript'),
|
|
242
|
+
require('prettier/parser-html'),
|
|
243
|
+
require('prettier/parser-postcss'),
|
|
244
|
+
require('prettier/parser-babel'),
|
|
245
|
+
],
|
|
246
|
+
});
|
|
253
247
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
248
|
+
catch (err) {
|
|
249
|
+
console.warn('Could not prettify', { string: str }, err);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
str = (0, plugins_1.runPostCodePlugins)({ json: component, code: str, plugins: options.plugins });
|
|
253
|
+
for (const pattern of removePatterns) {
|
|
254
|
+
str = str.replace(pattern, '').trim();
|
|
255
|
+
}
|
|
256
|
+
str = str.replace(/<script(.*)>\n?<\/script>/g, '').trim();
|
|
257
|
+
return str;
|
|
257
258
|
};
|
|
258
259
|
exports.componentToVue = componentToVue;
|
|
259
260
|
// Remove unused artifacts like empty script or style tags
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
261
|
+
const removePatterns = [
|
|
262
|
+
`<script>
|
|
263
|
+
export default {};
|
|
264
|
+
</script>`,
|
|
265
|
+
`<style>
|
|
266
|
+
</style>`,
|
|
263
267
|
];
|
|
264
|
-
var templateObject_1;
|
|
@@ -1,15 +1,4 @@
|
|
|
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
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -33,45 +22,35 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
33
22
|
__setModuleDefault(result, mod);
|
|
34
23
|
return result;
|
|
35
24
|
};
|
|
36
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
37
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
38
|
-
if (ar || !(i in from)) {
|
|
39
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
40
|
-
ar[i] = from[i];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
44
|
-
};
|
|
45
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
27
|
};
|
|
48
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
29
|
exports.convertTypeScriptToJS = exports.babelTransformExpression = exports.babelTransformCode = void 0;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var code = _a.code, useCode = _a.useCode, result = _a.result, visitor = _a.visitor, stripTypes = _a.stripTypes;
|
|
30
|
+
const babel = __importStar(require("@babel/core"));
|
|
31
|
+
const plugin_syntax_decorators_1 = __importDefault(require("@babel/plugin-syntax-decorators"));
|
|
32
|
+
const plugin_syntax_typescript_1 = __importDefault(require("@babel/plugin-syntax-typescript"));
|
|
33
|
+
const preset_typescript_1 = __importDefault(require("@babel/preset-typescript"));
|
|
34
|
+
const function_1 = require("fp-ts/lib/function");
|
|
35
|
+
const patterns_1 = require("./patterns");
|
|
36
|
+
const handleErrorOrExpression = ({ code, useCode, result, visitor, stripTypes, }) => {
|
|
58
37
|
try {
|
|
59
38
|
// If it can't, e.g. this is an expression or code fragment, modify the code below and try again
|
|
60
39
|
// Detect method fragments. These get passed sometimes and otherwise
|
|
61
40
|
// generate compile errors. They are of the form `foo() { ... }`
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
41
|
+
const isMethod = Boolean(!code.trim().startsWith('function') && code.trim().match(/^[a-z0-9_]+\s*\([^\)]*\)\s*[\{:]/i));
|
|
42
|
+
const isGetter = (0, patterns_1.checkIsGetter)(code);
|
|
43
|
+
const isMethodOrGetter = isMethod || isGetter;
|
|
65
44
|
if (isMethodOrGetter) {
|
|
66
|
-
useCode =
|
|
45
|
+
useCode = `function ${useCode}`;
|
|
67
46
|
}
|
|
68
47
|
result = (0, function_1.pipe)(
|
|
69
48
|
// Parse the code as an expression (instead of the default, a block) by giving it a fake variable assignment
|
|
70
49
|
// e.g. if the code parsed is { ... } babel will treat that as a block by deafult, unless processed as an expression
|
|
71
50
|
// that is an object
|
|
72
|
-
|
|
51
|
+
`let _ = ${useCode}`, (code) => (0, exports.babelTransformCode)(code, visitor, stripTypes), trimSemicolons,
|
|
73
52
|
// Remove our fake variable assignment
|
|
74
|
-
|
|
53
|
+
(str) => str.replace(/let _ =\s/, ''));
|
|
75
54
|
if (isMethodOrGetter) {
|
|
76
55
|
return result.replace('function', '');
|
|
77
56
|
}
|
|
@@ -82,32 +61,35 @@ var handleErrorOrExpression = function (_a) {
|
|
|
82
61
|
throw err;
|
|
83
62
|
}
|
|
84
63
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
64
|
+
const babelTransform = ({ code, visitor, stripTypes, }) => {
|
|
65
|
+
return babel.transform(code, {
|
|
66
|
+
sourceFileName: 'file.tsx',
|
|
67
|
+
configFile: false,
|
|
68
|
+
babelrc: false,
|
|
69
|
+
parserOpts: { allowReturnOutsideFunction: true },
|
|
70
|
+
...(stripTypes ? { presets: [[preset_typescript_1.default, { isTSX: true, allExtensions: true }]] } : {}),
|
|
71
|
+
plugins: [
|
|
88
72
|
[plugin_syntax_typescript_1.default, { isTSX: true }],
|
|
89
|
-
[plugin_syntax_decorators_1.default, { legacy: true }]
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
var _a;
|
|
94
|
-
if (stripTypes === void 0) { stripTypes = false; }
|
|
95
|
-
return ((_a = babelTransform({ code: code, visitor: visitor, stripTypes: stripTypes })) === null || _a === void 0 ? void 0 : _a.code) || '';
|
|
73
|
+
[plugin_syntax_decorators_1.default, { legacy: true }],
|
|
74
|
+
...(visitor ? [() => ({ visitor })] : []),
|
|
75
|
+
],
|
|
76
|
+
});
|
|
96
77
|
};
|
|
78
|
+
const babelTransformCode = (code, visitor, stripTypes = false) => { var _a; return ((_a = babelTransform({ code, visitor, stripTypes })) === null || _a === void 0 ? void 0 : _a.code) || ''; };
|
|
97
79
|
exports.babelTransformCode = babelTransformCode;
|
|
98
80
|
// Babel adds trailing semicolons, but for expressions we need those gone
|
|
99
81
|
// TODO: maybe detect if the original code ended with one, and keep it if so, for the case
|
|
100
82
|
// of appending several fragements
|
|
101
|
-
|
|
102
|
-
|
|
83
|
+
const trimSemicolons = (code) => code.replace(/;$/, '');
|
|
84
|
+
const trimExpression = (type) => (code) => {
|
|
103
85
|
switch (type) {
|
|
104
86
|
case 'functionBody':
|
|
105
87
|
return code.replace(/^function\s*\(\)\s*\{/, '').replace(/\};?$/, '');
|
|
106
88
|
default:
|
|
107
89
|
return trimSemicolons(code);
|
|
108
90
|
}
|
|
109
|
-
};
|
|
110
|
-
|
|
91
|
+
};
|
|
92
|
+
const getType = (code, initialType) => {
|
|
111
93
|
// match for object literal like { foo: ... }
|
|
112
94
|
if (initialType === 'unknown' && code.trim().match(/^\s*{\s*[a-z0-9]+:/i)) {
|
|
113
95
|
return 'expression';
|
|
@@ -120,34 +102,29 @@ var getType = function (code, initialType) {
|
|
|
120
102
|
}
|
|
121
103
|
return initialType;
|
|
122
104
|
};
|
|
123
|
-
|
|
124
|
-
if (initialType === void 0) { initialType = 'unknown'; }
|
|
125
|
-
if (stripTypes === void 0) { stripTypes = false; }
|
|
105
|
+
const babelTransformExpression = (code, visitor, initialType = 'unknown', stripTypes = false) => {
|
|
126
106
|
if (!code) {
|
|
127
107
|
return '';
|
|
128
108
|
}
|
|
129
|
-
|
|
130
|
-
return (0, function_1.pipe)(code, isGetter ? patterns_1.replaceGetterWithFunction : function_1.identity,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return { type
|
|
134
|
-
},
|
|
135
|
-
var type = _a.type, useCode = _a.useCode;
|
|
109
|
+
const isGetter = code.trim().startsWith('get ');
|
|
110
|
+
return (0, function_1.pipe)(code, isGetter ? patterns_1.replaceGetterWithFunction : function_1.identity, (code) => {
|
|
111
|
+
const type = getType(code, initialType);
|
|
112
|
+
const useCode = type === 'functionBody' ? `function(){${code}}` : code;
|
|
113
|
+
return { type, useCode };
|
|
114
|
+
}, ({ type, useCode }) => {
|
|
136
115
|
if (type !== 'expression') {
|
|
137
116
|
try {
|
|
138
117
|
return (0, function_1.pipe)((0, exports.babelTransformCode)(useCode, visitor, stripTypes), trimExpression(type));
|
|
139
118
|
}
|
|
140
119
|
catch (error) {
|
|
141
|
-
return handleErrorOrExpression({ code
|
|
120
|
+
return handleErrorOrExpression({ code, useCode, result: null, visitor, stripTypes });
|
|
142
121
|
}
|
|
143
122
|
}
|
|
144
123
|
else {
|
|
145
|
-
return handleErrorOrExpression({ code
|
|
124
|
+
return handleErrorOrExpression({ code, useCode, result: null, visitor, stripTypes });
|
|
146
125
|
}
|
|
147
126
|
}, isGetter ? patterns_1.replaceFunctionWithGetter : function_1.identity);
|
|
148
127
|
};
|
|
149
128
|
exports.babelTransformExpression = babelTransformExpression;
|
|
150
|
-
|
|
151
|
-
return (0, exports.babelTransformExpression)(code, {}, 'unknown', true);
|
|
152
|
-
};
|
|
129
|
+
const convertTypeScriptToJS = (code) => (0, exports.babelTransformExpression)(code, {}, 'unknown', true);
|
|
153
130
|
exports.convertTypeScriptToJS = convertTypeScriptToJS;
|