@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,21 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTypescriptProject = exports.getContextSymbols = exports.getPropsSymbol = exports.removeMitosisImport = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
});
|
|
14
|
-
};
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const babel_transform_1 = require("./babel-transform");
|
|
6
|
+
const removeMitosisImport = (code) => (0, babel_transform_1.babelTransformExpression)(code, {
|
|
7
|
+
ImportDeclaration(path) {
|
|
8
|
+
if (path.node.source.value === '@builder.io/mitosis') {
|
|
9
|
+
path.remove();
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
});
|
|
15
13
|
exports.removeMitosisImport = removeMitosisImport;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return ast.forEachChild(
|
|
14
|
+
const getPropsSymbol = (ast) => {
|
|
15
|
+
let propsSymbol = undefined;
|
|
16
|
+
return ast.forEachChild((node) => {
|
|
19
17
|
var _a;
|
|
20
18
|
if (propsSymbol !== undefined)
|
|
21
19
|
return undefined;
|
|
@@ -30,17 +28,17 @@ var getPropsSymbol = function (ast) {
|
|
|
30
28
|
});
|
|
31
29
|
};
|
|
32
30
|
exports.getPropsSymbol = getPropsSymbol;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
ast.forEachDescendant(
|
|
31
|
+
const getContextSymbols = (ast) => {
|
|
32
|
+
const contextSymbols = new Set();
|
|
33
|
+
ast.forEachDescendant((node) => {
|
|
36
34
|
if (!ts_morph_1.Node.isVariableDeclaration(node))
|
|
37
35
|
return;
|
|
38
|
-
|
|
36
|
+
const initializer = node.getInitializer();
|
|
39
37
|
if (!ts_morph_1.Node.isCallExpression(initializer))
|
|
40
38
|
return;
|
|
41
39
|
if (initializer.getExpression().getText() !== 'useContext')
|
|
42
40
|
return;
|
|
43
|
-
|
|
41
|
+
const contextSymbol = node.getNameNode().getSymbol();
|
|
44
42
|
if (contextSymbol === undefined)
|
|
45
43
|
return;
|
|
46
44
|
contextSymbols.add(contextSymbol);
|
|
@@ -48,16 +46,18 @@ var getContextSymbols = function (ast) {
|
|
|
48
46
|
return contextSymbols;
|
|
49
47
|
};
|
|
50
48
|
exports.getContextSymbols = getContextSymbols;
|
|
51
|
-
|
|
49
|
+
const getProject = (tsConfigFilePath) => {
|
|
52
50
|
try {
|
|
53
|
-
return new ts_morph_1.Project({ tsConfigFilePath
|
|
51
|
+
return new ts_morph_1.Project({ tsConfigFilePath });
|
|
54
52
|
}
|
|
55
53
|
catch (err) {
|
|
56
|
-
throw new Error(
|
|
54
|
+
throw new Error(`Error creating Typescript Project. Make sure \`tsConfigFilePath\` points to a valid tsconfig.json file.
|
|
55
|
+
Path received: "${tsConfigFilePath}"
|
|
56
|
+
`);
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return { project
|
|
59
|
+
const createTypescriptProject = (tsConfigFilePath) => {
|
|
60
|
+
const project = getProject(tsConfigFilePath);
|
|
61
|
+
return { project };
|
|
62
62
|
};
|
|
63
63
|
exports.createTypescriptProject = createTypescriptProject;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.objectHasKey = void 0;
|
|
4
|
-
|
|
5
|
-
return key in object;
|
|
6
|
-
};
|
|
4
|
+
const objectHasKey = (object, key) => key in object;
|
|
7
5
|
exports.objectHasKey = objectHasKey;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runPostCodePlugins = exports.runPreCodePlugins = exports.runPostJsonPlugins = exports.runPreJsonPlugins = void 0;
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var plugin = plugins_1[_i];
|
|
10
|
-
var preFunction = (_b = plugin(options).json) === null || _b === void 0 ? void 0 : _b.pre;
|
|
4
|
+
const runPreJsonPlugins = ({ json, plugins, options, }) => {
|
|
5
|
+
var _a;
|
|
6
|
+
let useJson = json;
|
|
7
|
+
for (const plugin of plugins) {
|
|
8
|
+
const preFunction = (_a = plugin(options).json) === null || _a === void 0 ? void 0 : _a.pre;
|
|
11
9
|
if (preFunction) {
|
|
12
10
|
useJson = preFunction(json) || json;
|
|
13
11
|
}
|
|
@@ -15,13 +13,11 @@ var runPreJsonPlugins = function (_a) {
|
|
|
15
13
|
return useJson;
|
|
16
14
|
};
|
|
17
15
|
exports.runPreJsonPlugins = runPreJsonPlugins;
|
|
18
|
-
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var plugin = plugins_2[_i];
|
|
24
|
-
var postFunction = (_b = plugin(options).json) === null || _b === void 0 ? void 0 : _b.post;
|
|
16
|
+
const runPostJsonPlugins = ({ json, plugins, options, }) => {
|
|
17
|
+
var _a;
|
|
18
|
+
let useJson = json;
|
|
19
|
+
for (const plugin of plugins) {
|
|
20
|
+
const postFunction = (_a = plugin(options).json) === null || _a === void 0 ? void 0 : _a.post;
|
|
25
21
|
if (postFunction) {
|
|
26
22
|
useJson = postFunction(json) || json;
|
|
27
23
|
}
|
|
@@ -29,13 +25,11 @@ var runPostJsonPlugins = function (_a) {
|
|
|
29
25
|
return useJson;
|
|
30
26
|
};
|
|
31
27
|
exports.runPostJsonPlugins = runPostJsonPlugins;
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var plugin = plugins_3[_i];
|
|
38
|
-
var preFunction = (_b = plugin(options).code) === null || _b === void 0 ? void 0 : _b.pre;
|
|
28
|
+
const runPreCodePlugins = ({ code, plugins, options, json, }) => {
|
|
29
|
+
var _a;
|
|
30
|
+
let string = code;
|
|
31
|
+
for (const plugin of plugins) {
|
|
32
|
+
const preFunction = (_a = plugin(options).code) === null || _a === void 0 ? void 0 : _a.pre;
|
|
39
33
|
if (preFunction) {
|
|
40
34
|
string = preFunction(string, json);
|
|
41
35
|
}
|
|
@@ -43,13 +37,11 @@ var runPreCodePlugins = function (_a) {
|
|
|
43
37
|
return string;
|
|
44
38
|
};
|
|
45
39
|
exports.runPreCodePlugins = runPreCodePlugins;
|
|
46
|
-
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var plugin = plugins_4[_i];
|
|
52
|
-
var postFunction = (_b = plugin(options).code) === null || _b === void 0 ? void 0 : _b.post;
|
|
40
|
+
const runPostCodePlugins = ({ code, plugins, options, json, }) => {
|
|
41
|
+
var _a;
|
|
42
|
+
let string = code;
|
|
43
|
+
for (const plugin of plugins) {
|
|
44
|
+
const postFunction = (_a = plugin(options).code) === null || _a === void 0 ? void 0 : _a.post;
|
|
53
45
|
if (postFunction) {
|
|
54
46
|
string = postFunction(string, json);
|
|
55
47
|
}
|
|
@@ -4,45 +4,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.angularToMitosisComponent = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
const compiler_1 = require("@angular/compiler");
|
|
8
|
+
const core_1 = require("@babel/core");
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
11
|
+
const babel_transform_1 = require("../helpers/babel-transform");
|
|
12
|
+
const bindings_1 = require("../helpers/bindings");
|
|
13
|
+
const capitalize_1 = require("../helpers/capitalize");
|
|
14
|
+
const create_mitosis_component_1 = require("../helpers/create-mitosis-component");
|
|
15
|
+
const create_mitosis_node_1 = require("../helpers/create-mitosis-node");
|
|
16
|
+
const getTsAST = (code) => {
|
|
17
17
|
return typescript_1.default.createSourceFile('code.ts', code, typescript_1.default.ScriptTarget.Latest, true);
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
const transformBinding = (binding, _options) => {
|
|
20
20
|
return (0, babel_transform_1.babelTransformCode)(binding, {
|
|
21
|
-
Identifier
|
|
22
|
-
|
|
21
|
+
Identifier(path) {
|
|
22
|
+
const name = path.node.name;
|
|
23
23
|
if ((core_1.types.isObjectProperty(path.parent) && path.parent.key === path.node) ||
|
|
24
24
|
(core_1.types.isMemberExpression(path.parent) && path.parent.property === path.node)) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
if (!(name.startsWith('state.') || name === 'event' || name === '$event')) {
|
|
28
|
-
path.replaceWith(core_1.types.identifier(
|
|
28
|
+
path.replaceWith(core_1.types.identifier(`state.${name}`));
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
});
|
|
32
32
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var isBoundText = function (node) { return typeof node.value === 'object'; };
|
|
43
|
-
var angularTemplateNodeToMitosisNode = function (node, options) {
|
|
33
|
+
const isElement = (node) =>
|
|
34
|
+
// TODO: theres got to be a better way than this
|
|
35
|
+
Array.isArray(node.attributes);
|
|
36
|
+
const isTemplate = (node) =>
|
|
37
|
+
// TODO: theres got to be a better way than this
|
|
38
|
+
Array.isArray(node.templateAttrs);
|
|
39
|
+
const isText = (node) => typeof node.value === 'string';
|
|
40
|
+
const isBoundText = (node) => typeof node.value === 'object';
|
|
41
|
+
const angularTemplateNodeToMitosisNode = (node, options) => {
|
|
44
42
|
if (isTemplate(node)) {
|
|
45
|
-
|
|
43
|
+
const ngIf = node.templateAttrs.find((item) => item.name === 'ngIf');
|
|
46
44
|
if (ngIf) {
|
|
47
45
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
48
46
|
name: 'Show',
|
|
@@ -54,11 +52,11 @@ var angularTemplateNodeToMitosisNode = function (node, options) {
|
|
|
54
52
|
children: [angularTemplateNodeToMitosisNode((0, lodash_1.omit)(node, 'templateAttrs'), options)],
|
|
55
53
|
});
|
|
56
54
|
}
|
|
57
|
-
|
|
55
|
+
const ngFor = node.templateAttrs.find((item) => item.name === 'ngFor');
|
|
58
56
|
if (ngFor) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
const value = ngFor.value.source;
|
|
58
|
+
const split = value.split(/let\s|\sof\s/);
|
|
59
|
+
const [_let, itemName, _of, expression] = split;
|
|
62
60
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
63
61
|
name: 'For',
|
|
64
62
|
bindings: {
|
|
@@ -72,31 +70,28 @@ var angularTemplateNodeToMitosisNode = function (node, options) {
|
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
72
|
if (isElement(node)) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
for (
|
|
78
|
-
var input = _a[_i];
|
|
73
|
+
const properties = {};
|
|
74
|
+
const bindings = {};
|
|
75
|
+
for (const input of node.inputs) {
|
|
79
76
|
bindings[input.name] = (0, bindings_1.createSingleBinding)({
|
|
80
77
|
code: transformBinding(input.value.source, options),
|
|
81
78
|
});
|
|
82
79
|
}
|
|
83
|
-
for (
|
|
84
|
-
var output = _c[_b];
|
|
80
|
+
for (const output of node.outputs) {
|
|
85
81
|
bindings['on' + (0, capitalize_1.capitalize)(output.name)] = (0, bindings_1.createSingleBinding)({
|
|
86
82
|
code: transformBinding(output.handler
|
|
87
83
|
.source // TODO: proper reference replace
|
|
88
84
|
.replace(/\$event/g, 'event'), options),
|
|
89
85
|
});
|
|
90
86
|
}
|
|
91
|
-
for (
|
|
92
|
-
var attribute = _e[_d];
|
|
87
|
+
for (const attribute of node.attributes) {
|
|
93
88
|
properties[attribute.name] = attribute.value;
|
|
94
89
|
}
|
|
95
90
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
96
91
|
name: node.name,
|
|
97
|
-
properties
|
|
92
|
+
properties,
|
|
98
93
|
bindings: bindings,
|
|
99
|
-
children: node.children.map(
|
|
94
|
+
children: node.children.map((node) => angularTemplateNodeToMitosisNode(node, options)),
|
|
100
95
|
});
|
|
101
96
|
}
|
|
102
97
|
if (isText(node)) {
|
|
@@ -114,34 +109,32 @@ var angularTemplateNodeToMitosisNode = function (node, options) {
|
|
|
114
109
|
},
|
|
115
110
|
});
|
|
116
111
|
}
|
|
117
|
-
throw new Error(
|
|
112
|
+
throw new Error(`Element node type {${node}} is not supported`);
|
|
118
113
|
};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
114
|
+
const angularTemplateToMitosisNodes = (template, options) => {
|
|
115
|
+
const ast = (0, compiler_1.parseTemplate)(template, '.');
|
|
116
|
+
const blocks = ast.nodes.map((node) => angularTemplateNodeToMitosisNode(node, options));
|
|
122
117
|
return blocks;
|
|
123
118
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
for (
|
|
128
|
-
var statement = _a[_i];
|
|
119
|
+
const parseTypescript = (code, options) => {
|
|
120
|
+
const component = (0, create_mitosis_component_1.createMitosisComponent)();
|
|
121
|
+
const ast = getTsAST(code);
|
|
122
|
+
for (const statement of ast.statements) {
|
|
129
123
|
if (typescript_1.default.isClassDeclaration(statement)) {
|
|
130
|
-
|
|
124
|
+
const decorators = typescript_1.default.canHaveDecorators(statement) ? typescript_1.default.getDecorators(statement) : undefined;
|
|
131
125
|
if (decorators) {
|
|
132
|
-
for (
|
|
133
|
-
var decorator = decorators_1[_b];
|
|
126
|
+
for (const decorator of decorators) {
|
|
134
127
|
// TODO: proper reference tracing
|
|
135
128
|
if (typescript_1.default.isCallExpression(decorator.expression))
|
|
136
129
|
if (typescript_1.default.isIdentifier(decorator.expression.expression) &&
|
|
137
130
|
decorator.expression.expression.text === 'Component') {
|
|
138
|
-
|
|
131
|
+
const firstArg = decorator.expression.arguments[0];
|
|
139
132
|
if (typescript_1.default.isObjectLiteralExpression(firstArg)) {
|
|
140
|
-
firstArg.properties.find(
|
|
133
|
+
firstArg.properties.find((item) => {
|
|
141
134
|
if (typescript_1.default.isPropertyAssignment(item)) {
|
|
142
135
|
if (typescript_1.default.isIdentifier(item.name) && item.name.text === 'template') {
|
|
143
136
|
if (typescript_1.default.isTemplateLiteral(item.initializer)) {
|
|
144
|
-
|
|
137
|
+
const template = item.initializer.getText().trim().slice(1, -1);
|
|
145
138
|
component.children = angularTemplateToMitosisNodes(template, options);
|
|
146
139
|
}
|
|
147
140
|
}
|
|
@@ -155,8 +148,7 @@ var parseTypescript = function (code, options) {
|
|
|
155
148
|
}
|
|
156
149
|
return component;
|
|
157
150
|
};
|
|
158
|
-
function angularToMitosisComponent(code, options) {
|
|
159
|
-
if (options === void 0) { options = {}; }
|
|
151
|
+
function angularToMitosisComponent(code, options = {}) {
|
|
160
152
|
return parseTypescript(code, options);
|
|
161
153
|
}
|
|
162
154
|
exports.angularToMitosisComponent = angularToMitosisComponent;
|