@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
|
@@ -27,9 +27,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.getUseTargetStatements = exports.getIdFromMatch = exports.USE_TARGET_MAGIC_REGEX = exports.USE_TARGET_MAGIC_STRING = exports.getMagicString = exports.getTargetId = void 0;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const babel = __importStar(require("@babel/core"));
|
|
31
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
32
|
+
const TARGETS = {
|
|
33
33
|
alpine: null,
|
|
34
34
|
angular: null,
|
|
35
35
|
customElement: null,
|
|
@@ -52,26 +52,26 @@ var TARGETS = {
|
|
|
52
52
|
rsc: null,
|
|
53
53
|
taro: null,
|
|
54
54
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
const { types } = babel;
|
|
56
|
+
const getTargetId = (component) => {
|
|
57
|
+
const latestId = Object.keys(component.targetBlocks || {}).length;
|
|
58
|
+
const blockId = (latestId + 1).toString();
|
|
59
59
|
return blockId;
|
|
60
60
|
};
|
|
61
61
|
exports.getTargetId = getTargetId;
|
|
62
|
-
|
|
62
|
+
const getMagicString = (targetId) => [exports.USE_TARGET_MAGIC_STRING, targetId].join('');
|
|
63
63
|
exports.getMagicString = getMagicString;
|
|
64
64
|
exports.USE_TARGET_MAGIC_STRING = 'USE_TARGET_BLOCK_';
|
|
65
65
|
// check for uuid.v4() format
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const idRegex = /\d*/;
|
|
67
|
+
const REGEX_BLOCK_NAME = 'blockId';
|
|
68
68
|
exports.USE_TARGET_MAGIC_REGEX = new RegExp(
|
|
69
69
|
// make sure to capture the id of the target block
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
`["']${exports.USE_TARGET_MAGIC_STRING}\(?<${REGEX_BLOCK_NAME}>${idRegex.source}\)["']`, 'g');
|
|
71
|
+
const getIdFromMatch = (match) => {
|
|
72
72
|
var _a;
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
const USE_TARGET_MAGIC_REGEX_WITHOUT_G = new RegExp(`["']${exports.USE_TARGET_MAGIC_STRING}\(?<${REGEX_BLOCK_NAME}>${idRegex.source}\)["']`);
|
|
74
|
+
const result = match.match(USE_TARGET_MAGIC_REGEX_WITHOUT_G);
|
|
75
75
|
if (!result)
|
|
76
76
|
return undefined;
|
|
77
77
|
return (_a = result.groups) === null || _a === void 0 ? void 0 : _a[REGEX_BLOCK_NAME];
|
|
@@ -80,18 +80,18 @@ exports.getIdFromMatch = getIdFromMatch;
|
|
|
80
80
|
/**
|
|
81
81
|
* This function finds `useTarget()` and converts it our JSON representation
|
|
82
82
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
const getUseTargetStatements = (path) => {
|
|
84
|
+
const useTargetHook = path.node;
|
|
85
|
+
const obj = useTargetHook.arguments[0];
|
|
86
86
|
if (!types.isObjectExpression(obj))
|
|
87
87
|
return undefined;
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
const isInlinedCodeInsideFunctionBody = types.isExpressionStatement(path.parent) && types.isBlockStatement(path.parentPath.parent);
|
|
89
|
+
const targetBlock = {
|
|
90
90
|
settings: {
|
|
91
91
|
requiresDefault: !isInlinedCodeInsideFunctionBody,
|
|
92
92
|
},
|
|
93
93
|
};
|
|
94
|
-
obj.properties.forEach(
|
|
94
|
+
obj.properties.forEach((prop) => {
|
|
95
95
|
if (!types.isObjectProperty(prop)) {
|
|
96
96
|
throw new Error('ERROR Parsing `useTarget()`: properties cannot be spread or references');
|
|
97
97
|
}
|
|
@@ -101,19 +101,19 @@ var getUseTargetStatements = function (path) {
|
|
|
101
101
|
if (!Object.keys(TARGETS).concat('default').includes(prop.key.name)) {
|
|
102
102
|
throw new Error('ERROR Parsing `useTarget()`: Invalid target: ' + prop.key.name);
|
|
103
103
|
}
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
const keyName = prop.key.name;
|
|
105
|
+
const targetCode = prop.value;
|
|
106
106
|
if (isInlinedCodeInsideFunctionBody) {
|
|
107
107
|
if (!(types.isArrowFunctionExpression(targetCode) || types.isFunctionExpression(targetCode)))
|
|
108
108
|
return undefined;
|
|
109
|
-
|
|
109
|
+
const body = targetCode.body;
|
|
110
110
|
if (types.isBlockStatement(body)) {
|
|
111
|
-
|
|
112
|
-
body.body.forEach(
|
|
113
|
-
|
|
111
|
+
let code = '';
|
|
112
|
+
body.body.forEach((statement) => {
|
|
113
|
+
code += (0, generator_1.default)(statement).code + '\n';
|
|
114
114
|
});
|
|
115
115
|
targetBlock[keyName] = {
|
|
116
|
-
code
|
|
116
|
+
code,
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
else {
|
|
@@ -22,29 +22,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
26
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
27
|
-
if (ar || !(i in from)) {
|
|
28
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
29
|
-
ar[i] = from[i];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
exports.handleImportDeclaration = void 0;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var options = _a.options, path = _a.path, context = _a.context;
|
|
27
|
+
const babel = __importStar(require("@babel/core"));
|
|
28
|
+
const mitosis_imports_1 = require("../../helpers/mitosis-imports");
|
|
29
|
+
const { types } = babel;
|
|
30
|
+
const handleImportDeclaration = ({ options, path, context, }) => {
|
|
41
31
|
// @builder.io/mitosis or React imports compile away
|
|
42
|
-
|
|
43
|
-
if (
|
|
32
|
+
const customPackages = (options === null || options === void 0 ? void 0 : options.compileAwayPackages) || [];
|
|
33
|
+
if (['react', '@builder.io/mitosis', '@emotion/react', ...customPackages].includes(path.node.source.value)) {
|
|
44
34
|
path.remove();
|
|
45
35
|
return;
|
|
46
36
|
}
|
|
47
|
-
|
|
37
|
+
const importObject = (0, mitosis_imports_1.mapImportDeclarationToMitosisImport)(path.node);
|
|
48
38
|
context.builder.component.imports.push(importObject);
|
|
49
39
|
path.remove();
|
|
50
40
|
};
|
|
@@ -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);
|
|
@@ -38,37 +27,37 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
27
|
};
|
|
39
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
29
|
exports.parseJsx = void 0;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
30
|
+
const filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
|
|
31
|
+
const traverse_nodes_1 = require("../../helpers/traverse-nodes");
|
|
32
|
+
const babel = __importStar(require("@babel/core"));
|
|
33
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
34
|
+
const plugin_syntax_typescript_1 = __importDefault(require("@babel/plugin-syntax-typescript"));
|
|
35
|
+
const preset_typescript_1 = __importDefault(require("@babel/preset-typescript"));
|
|
36
|
+
const function_1 = require("fp-ts/lib/function");
|
|
37
|
+
const hooks_1 = require("../../constants/hooks");
|
|
38
|
+
const create_mitosis_component_1 = require("../../helpers/create-mitosis-component");
|
|
39
|
+
const json_1 = require("../../helpers/json");
|
|
40
|
+
const replace_new_lines_in_strings_1 = require("../../helpers/replace-new-lines-in-strings");
|
|
41
|
+
const signals_1 = require("../../helpers/signals");
|
|
42
|
+
const ast_1 = require("./ast");
|
|
43
|
+
const component_types_1 = require("./component-types");
|
|
44
|
+
const context_1 = require("./context");
|
|
45
|
+
const element_parser_1 = require("./element-parser");
|
|
46
|
+
const exports_1 = require("./exports");
|
|
47
|
+
const function_parser_1 = require("./function-parser");
|
|
48
|
+
const helpers_1 = require("./helpers");
|
|
49
|
+
const hooks_2 = require("./hooks");
|
|
50
|
+
const use_target_1 = require("./hooks/use-target");
|
|
51
|
+
const imports_1 = require("./imports");
|
|
52
|
+
const props_1 = require("./props");
|
|
53
|
+
const props_types_1 = require("./props-types");
|
|
54
|
+
const signals_2 = require("./signals");
|
|
55
|
+
const state_1 = require("./state");
|
|
56
|
+
const { types } = babel;
|
|
57
|
+
const typescriptBabelPreset = [preset_typescript_1.default, { isTSX: true, allExtensions: true }];
|
|
58
|
+
const beforeParse = (path) => {
|
|
70
59
|
path.traverse({
|
|
71
|
-
FunctionDeclaration
|
|
60
|
+
FunctionDeclaration(path) {
|
|
72
61
|
(0, props_1.undoPropsDestructure)(path);
|
|
73
62
|
},
|
|
74
63
|
});
|
|
@@ -80,12 +69,14 @@ var beforeParse = function (path) {
|
|
|
80
69
|
* @param jsx string representation of the Mitosis component
|
|
81
70
|
* @returns A JSON representation of the Mitosis component
|
|
82
71
|
*/
|
|
83
|
-
function parseJsx(jsx, _options) {
|
|
72
|
+
function parseJsx(jsx, _options = {}) {
|
|
84
73
|
var _a;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
74
|
+
let subComponentFunctions = [];
|
|
75
|
+
const options = {
|
|
76
|
+
typescript: false,
|
|
77
|
+
..._options,
|
|
78
|
+
};
|
|
79
|
+
const jsxToUse = options.typescript
|
|
89
80
|
? jsx
|
|
90
81
|
: // strip typescript types by running through babel's TS preset.
|
|
91
82
|
(_a = babel.transform(jsx, {
|
|
@@ -93,20 +84,20 @@ function parseJsx(jsx, _options) {
|
|
|
93
84
|
babelrc: false,
|
|
94
85
|
presets: [typescriptBabelPreset],
|
|
95
86
|
})) === null || _a === void 0 ? void 0 : _a.code;
|
|
96
|
-
|
|
87
|
+
const output = babel.transform(jsxToUse, {
|
|
97
88
|
configFile: false,
|
|
98
89
|
babelrc: false,
|
|
99
90
|
comments: false,
|
|
100
91
|
plugins: [
|
|
101
92
|
[plugin_syntax_typescript_1.default, { isTSX: true }],
|
|
102
|
-
|
|
93
|
+
() => ({
|
|
103
94
|
visitor: {
|
|
104
|
-
JSXExpressionContainer
|
|
95
|
+
JSXExpressionContainer(path, context) {
|
|
105
96
|
if (types.isJSXEmptyExpression(path.node.expression)) {
|
|
106
97
|
path.remove();
|
|
107
98
|
}
|
|
108
99
|
},
|
|
109
|
-
Program
|
|
100
|
+
Program(path, context) {
|
|
110
101
|
if (context.builder) {
|
|
111
102
|
return;
|
|
112
103
|
}
|
|
@@ -114,81 +105,81 @@ function parseJsx(jsx, _options) {
|
|
|
114
105
|
context.builder = {
|
|
115
106
|
component: (0, create_mitosis_component_1.createMitosisComponent)(),
|
|
116
107
|
};
|
|
117
|
-
|
|
108
|
+
const keepStatements = path.node.body.filter((statement) => (0, helpers_1.isImportOrDefaultExport)(statement) || (0, component_types_1.isTypeOrInterface)(statement));
|
|
118
109
|
context.builder.component.exports = (0, exports_1.generateExports)(path);
|
|
119
110
|
subComponentFunctions = path.node.body
|
|
120
|
-
.filter(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
.map(function (node) { return "export default ".concat((0, generator_1.default)(node).code); });
|
|
124
|
-
var preComponentCode = (0, function_1.pipe)(path.node.body.filter(function (statement) { return !(0, helpers_1.isImportOrDefaultExport)(statement); }), (0, hooks_2.collectModuleScopeHooks)(context.builder.component, options), types.program, generator_1.default, function (generatorResult) { return generatorResult.code; });
|
|
111
|
+
.filter((node) => !types.isExportDefaultDeclaration(node) && types.isFunctionDeclaration(node))
|
|
112
|
+
.map((node) => `export default ${(0, generator_1.default)(node).code}`);
|
|
113
|
+
const preComponentCode = (0, function_1.pipe)(path.node.body.filter((statement) => !(0, helpers_1.isImportOrDefaultExport)(statement)), (0, hooks_2.collectModuleScopeHooks)(context.builder.component, options), types.program, generator_1.default, (generatorResult) => generatorResult.code);
|
|
125
114
|
// TODO: support multiple? e.g. for others to add imports?
|
|
126
115
|
context.builder.component.hooks.preComponent = { code: preComponentCode };
|
|
127
116
|
path.replaceWith(types.program(keepStatements));
|
|
128
117
|
},
|
|
129
|
-
FunctionDeclaration
|
|
130
|
-
|
|
118
|
+
FunctionDeclaration(path, context) {
|
|
119
|
+
const { node } = path;
|
|
131
120
|
if (types.isIdentifier(node.id)) {
|
|
132
|
-
|
|
133
|
-
if (
|
|
121
|
+
const name = node.id.name;
|
|
122
|
+
if (name[0].toUpperCase() === name[0]) {
|
|
134
123
|
path.traverse({
|
|
135
124
|
/**
|
|
136
125
|
* Plugin to find all `useTarget()` assignment calls inside of the component function body
|
|
137
126
|
* and replace them with a magic string.
|
|
138
127
|
*/
|
|
139
|
-
CallExpression
|
|
140
|
-
var _a;
|
|
128
|
+
CallExpression(path) {
|
|
141
129
|
if (!types.isCallExpression(path.node))
|
|
142
130
|
return;
|
|
143
131
|
if (!types.isIdentifier(path.node.callee))
|
|
144
132
|
return;
|
|
145
133
|
if (path.node.callee.name !== hooks_1.HOOKS.TARGET)
|
|
146
134
|
return;
|
|
147
|
-
|
|
135
|
+
const targetBlock = (0, use_target_1.getUseTargetStatements)(path);
|
|
148
136
|
if (!targetBlock)
|
|
149
137
|
return;
|
|
150
|
-
|
|
138
|
+
const blockId = (0, use_target_1.getTargetId)(context.builder.component);
|
|
151
139
|
// replace the useTarget() call with a magic string
|
|
152
140
|
path.replaceWith(types.stringLiteral((0, use_target_1.getMagicString)(blockId)));
|
|
153
141
|
// store the target block in the component
|
|
154
|
-
context.builder.component.targetBlocks =
|
|
142
|
+
context.builder.component.targetBlocks = {
|
|
143
|
+
...context.builder.component.targetBlocks,
|
|
144
|
+
[blockId]: targetBlock,
|
|
145
|
+
};
|
|
155
146
|
},
|
|
156
147
|
});
|
|
157
148
|
path.replaceWith((0, ast_1.jsonToAst)((0, function_parser_1.componentFunctionToJson)(node, context)));
|
|
158
149
|
}
|
|
159
150
|
}
|
|
160
151
|
},
|
|
161
|
-
ImportDeclaration
|
|
162
|
-
(0, imports_1.handleImportDeclaration)({ options
|
|
152
|
+
ImportDeclaration(path, context) {
|
|
153
|
+
(0, imports_1.handleImportDeclaration)({ options, path, context });
|
|
163
154
|
},
|
|
164
|
-
ExportDefaultDeclaration
|
|
155
|
+
ExportDefaultDeclaration(path) {
|
|
165
156
|
path.replaceWith(path.node.declaration);
|
|
166
157
|
},
|
|
167
|
-
JSXElement
|
|
168
|
-
|
|
158
|
+
JSXElement(path) {
|
|
159
|
+
const { node } = path;
|
|
169
160
|
path.replaceWith((0, ast_1.jsonToAst)((0, element_parser_1.jsxElementToJson)(node)));
|
|
170
161
|
},
|
|
171
|
-
ExportNamedDeclaration
|
|
172
|
-
|
|
162
|
+
ExportNamedDeclaration(path, context) {
|
|
163
|
+
const { node } = path;
|
|
173
164
|
if (babel.types.isTSInterfaceDeclaration(node.declaration) ||
|
|
174
165
|
babel.types.isTSTypeAliasDeclaration(node.declaration)) {
|
|
175
166
|
(0, component_types_1.collectTypes)(path, context);
|
|
176
167
|
}
|
|
177
168
|
},
|
|
178
|
-
TSTypeAliasDeclaration
|
|
169
|
+
TSTypeAliasDeclaration(path, context) {
|
|
179
170
|
(0, component_types_1.collectTypes)(path, context);
|
|
180
171
|
},
|
|
181
|
-
TSInterfaceDeclaration
|
|
172
|
+
TSInterfaceDeclaration(path, context) {
|
|
182
173
|
(0, component_types_1.collectTypes)(path, context);
|
|
183
174
|
},
|
|
184
175
|
},
|
|
185
|
-
})
|
|
176
|
+
}),
|
|
186
177
|
],
|
|
187
178
|
});
|
|
188
179
|
if (!output || !output.code) {
|
|
189
180
|
throw new Error('Could not parse JSX');
|
|
190
181
|
}
|
|
191
|
-
|
|
182
|
+
const stringifiedMitosisComponent = (0, replace_new_lines_in_strings_1.stripNewlinesInStrings)(output.code
|
|
192
183
|
.trim()
|
|
193
184
|
// Occasional issues where comments get kicked to the top. Full fix should strip these sooner
|
|
194
185
|
.replace(/^\/\*[\s\S]*?\*\/\s*/, '')
|
|
@@ -197,46 +188,56 @@ function parseJsx(jsx, _options) {
|
|
|
197
188
|
.replace(/\n"/g, '"')
|
|
198
189
|
.replace(/^\({/, '{')
|
|
199
190
|
.replace(/}\);$/, '}'));
|
|
200
|
-
|
|
191
|
+
const mitosisComponent = (0, json_1.tryParseJson)(stringifiedMitosisComponent);
|
|
201
192
|
(0, state_1.mapStateIdentifiers)(mitosisComponent);
|
|
202
193
|
(0, context_1.extractContextComponents)(mitosisComponent);
|
|
203
|
-
mitosisComponent.subComponents = subComponentFunctions.map(
|
|
204
|
-
|
|
194
|
+
mitosisComponent.subComponents = subComponentFunctions.map((item) => parseJsx(item, options));
|
|
195
|
+
const signalTypeImportName = (0, signals_1.getSignalImportName)(jsxToUse);
|
|
205
196
|
if (signalTypeImportName) {
|
|
206
|
-
mitosisComponent.signals = { signalTypeImportName
|
|
197
|
+
mitosisComponent.signals = { signalTypeImportName };
|
|
207
198
|
}
|
|
208
199
|
if (options.tsProject && options.filePath) {
|
|
209
200
|
// identify optional props.
|
|
210
|
-
|
|
201
|
+
const optionalProps = (0, props_types_1.findOptionalProps)({
|
|
211
202
|
project: options.tsProject.project,
|
|
212
203
|
filePath: options.filePath,
|
|
213
204
|
});
|
|
214
|
-
optionalProps.forEach(
|
|
205
|
+
optionalProps.forEach((prop) => {
|
|
215
206
|
var _a;
|
|
216
|
-
|
|
217
|
-
|
|
207
|
+
mitosisComponent.props = {
|
|
208
|
+
...mitosisComponent.props,
|
|
209
|
+
[prop]: {
|
|
210
|
+
...(_a = mitosisComponent.props) === null || _a === void 0 ? void 0 : _a[prop],
|
|
211
|
+
optional: true,
|
|
212
|
+
},
|
|
213
|
+
};
|
|
218
214
|
});
|
|
219
|
-
|
|
215
|
+
const reactiveValues = (0, signals_2.findSignals)({
|
|
220
216
|
filePath: options.filePath,
|
|
221
217
|
project: options.tsProject.project,
|
|
222
218
|
});
|
|
223
|
-
reactiveValues.props.forEach(
|
|
219
|
+
reactiveValues.props.forEach((prop) => {
|
|
224
220
|
var _a;
|
|
225
|
-
|
|
226
|
-
|
|
221
|
+
mitosisComponent.props = {
|
|
222
|
+
...mitosisComponent.props,
|
|
223
|
+
[prop]: {
|
|
224
|
+
...(_a = mitosisComponent.props) === null || _a === void 0 ? void 0 : _a[prop],
|
|
225
|
+
propertyType: 'reactive',
|
|
226
|
+
},
|
|
227
|
+
};
|
|
227
228
|
});
|
|
228
|
-
reactiveValues.state.forEach(
|
|
229
|
+
reactiveValues.state.forEach((state) => {
|
|
229
230
|
if (!mitosisComponent.state[state])
|
|
230
231
|
return;
|
|
231
232
|
mitosisComponent.state[state].propertyType = 'reactive';
|
|
232
233
|
});
|
|
233
|
-
reactiveValues.context.forEach(
|
|
234
|
+
reactiveValues.context.forEach((context) => {
|
|
234
235
|
if (!mitosisComponent.context.get[context])
|
|
235
236
|
return;
|
|
236
237
|
mitosisComponent.context.get[context].type = 'reactive';
|
|
237
238
|
});
|
|
238
239
|
}
|
|
239
|
-
(0, traverse_nodes_1.traverseNodes)(mitosisComponent,
|
|
240
|
+
(0, traverse_nodes_1.traverseNodes)(mitosisComponent, (node) => {
|
|
240
241
|
node.children = node.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes);
|
|
241
242
|
});
|
|
242
243
|
return mitosisComponent;
|
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findOptionalProps = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const typescript_project_1 = require("../../helpers/typescript-project");
|
|
6
|
+
const findOptionalProps = (args) => {
|
|
7
|
+
const ast = args.project.getSourceFileOrThrow(args.filePath);
|
|
8
8
|
if (ast === undefined) {
|
|
9
9
|
throw new Error('Could not find AST. Please provide either `code` or `filePath` configs.');
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
const propsSymbol = (0, typescript_project_1.getPropsSymbol)(ast);
|
|
12
12
|
if (!propsSymbol)
|
|
13
13
|
return [];
|
|
14
14
|
return propsSymbol
|
|
15
15
|
.getDeclarations()[0]
|
|
16
16
|
.getType()
|
|
17
17
|
.getProperties()
|
|
18
|
-
.map(
|
|
19
|
-
.filter(
|
|
20
|
-
|
|
21
|
-
})
|
|
22
|
-
.map(function (k) { return k.getName(); });
|
|
18
|
+
.map((p) => p.getDeclarations()[0])
|
|
19
|
+
.filter((k) => ts_morph_1.PropertySignature.isPropertySignature(k) && k.hasQuestionToken())
|
|
20
|
+
.map((k) => k.getName());
|
|
23
21
|
};
|
|
24
22
|
exports.findOptionalProps = findOptionalProps;
|
|
@@ -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);
|
|
@@ -35,34 +24,37 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
35
24
|
};
|
|
36
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
26
|
exports.undoPropsDestructure = void 0;
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
const babel = __importStar(require("@babel/core"));
|
|
28
|
+
const { types } = babel;
|
|
40
29
|
function undoPropsDestructure(path) {
|
|
41
|
-
|
|
30
|
+
const { node } = path;
|
|
42
31
|
if (node.params.length && types.isObjectPattern(node.params[0])) {
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
const param = node.params[0];
|
|
33
|
+
const propsMap = param.properties.reduce((pre, cur) => {
|
|
45
34
|
if (types.isObjectProperty(cur) &&
|
|
46
35
|
types.isIdentifier(cur.key) &&
|
|
47
36
|
types.isIdentifier(cur.value)) {
|
|
48
|
-
pre[cur.value.name] =
|
|
37
|
+
pre[cur.value.name] = `props.${cur.key.name}`;
|
|
49
38
|
return pre;
|
|
50
39
|
}
|
|
51
40
|
return pre;
|
|
52
41
|
}, {});
|
|
53
42
|
if (param.typeAnnotation) {
|
|
54
43
|
node.params = [
|
|
55
|
-
|
|
44
|
+
{
|
|
45
|
+
...babel.types.identifier('props'),
|
|
46
|
+
typeAnnotation: param.typeAnnotation,
|
|
47
|
+
},
|
|
56
48
|
];
|
|
57
49
|
path.replaceWith(node);
|
|
58
50
|
}
|
|
59
51
|
path.traverse({
|
|
60
|
-
JSXExpressionContainer
|
|
61
|
-
|
|
52
|
+
JSXExpressionContainer(path) {
|
|
53
|
+
const { node } = path;
|
|
62
54
|
if (types.isIdentifier(node.expression)) {
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
path.replaceWith(babel.types.jsxExpressionContainer(babel.types.identifier(
|
|
55
|
+
const { name } = node.expression;
|
|
56
|
+
if (propsMap[name]) {
|
|
57
|
+
path.replaceWith(babel.types.jsxExpressionContainer(babel.types.identifier(propsMap[name])));
|
|
66
58
|
}
|
|
67
59
|
}
|
|
68
60
|
},
|