@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,48 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findSignals = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const typescript_project_1 = require("../../helpers/typescript-project");
|
|
6
|
+
const MITOSIS_IMPORT_PATHS = [
|
|
7
7
|
// actual production path
|
|
8
8
|
'/node_modules/@builder.io/mitosis/',
|
|
9
9
|
// possible path if symlinking mitosis locally
|
|
10
10
|
'/mitosis/packages/core/',
|
|
11
11
|
];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var ast = project.getSourceFileOrThrow(filePath);
|
|
12
|
+
const findSignals = ({ filePath, project }) => {
|
|
13
|
+
const ast = project.getSourceFileOrThrow(filePath);
|
|
15
14
|
if (ast === undefined) {
|
|
16
15
|
throw new Error('Could not find AST. Please provide a correct `filePath`.');
|
|
17
16
|
}
|
|
18
|
-
|
|
17
|
+
const reactiveValues = {
|
|
19
18
|
props: new Set(),
|
|
20
19
|
state: new Set(),
|
|
21
20
|
context: new Set(),
|
|
22
21
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const propsSymbol = (0, typescript_project_1.getPropsSymbol)(ast);
|
|
23
|
+
const contextSymbols = (0, typescript_project_1.getContextSymbols)(ast);
|
|
24
|
+
const checkIsSignalSymbol = (type) => {
|
|
26
25
|
var _a;
|
|
27
|
-
|
|
26
|
+
const symbol = (_a = type.getTargetType()) === null || _a === void 0 ? void 0 : _a.getAliasSymbol();
|
|
28
27
|
if (!symbol || symbol.getName() !== 'Signal')
|
|
29
28
|
return false;
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const compilerSymbol = symbol === null || symbol === void 0 ? void 0 : symbol.compilerSymbol;
|
|
30
|
+
const parent = compilerSymbol.parent;
|
|
32
31
|
if (!parent)
|
|
33
32
|
return false;
|
|
34
|
-
if (MITOSIS_IMPORT_PATHS.some(
|
|
33
|
+
if (MITOSIS_IMPORT_PATHS.some((path) => parent.getName().includes(path))) {
|
|
35
34
|
return true;
|
|
36
35
|
}
|
|
37
36
|
return false;
|
|
38
37
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
const checkIsOptionalSignal = (node) => {
|
|
39
|
+
let hasUndefined = false;
|
|
40
|
+
let hasSignal = false;
|
|
41
|
+
const perfectMatch = node
|
|
43
42
|
.getType()
|
|
44
43
|
.getUnionTypes()
|
|
45
|
-
.every(
|
|
44
|
+
.every((type) => {
|
|
46
45
|
if (type.isUndefined()) {
|
|
47
46
|
hasUndefined = true;
|
|
48
47
|
return true;
|
|
@@ -55,34 +54,34 @@ var findSignals = function (_a) {
|
|
|
55
54
|
});
|
|
56
55
|
return perfectMatch && hasUndefined && hasSignal;
|
|
57
56
|
};
|
|
58
|
-
ast.forEachDescendant(
|
|
57
|
+
ast.forEachDescendant((parentNode) => {
|
|
59
58
|
if (ts_morph_1.Node.isPropertyAccessExpression(parentNode)) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
const node = parentNode.getExpression();
|
|
60
|
+
const isOptionalAccess = parentNode.hasQuestionDotToken();
|
|
61
|
+
const isSignal = isOptionalAccess
|
|
63
62
|
? checkIsOptionalSignal(node)
|
|
64
63
|
: checkIsSignalSymbol(node.getType());
|
|
65
64
|
if (!isSignal)
|
|
66
65
|
return;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
node.getParentWhile(
|
|
66
|
+
let isInsideType = false;
|
|
67
|
+
let isInsideDeclaration = false;
|
|
68
|
+
node.getParentWhile((parent, child) => {
|
|
70
69
|
// stop once we hit the function block
|
|
71
70
|
if (ts_morph_1.Node.isBlock(child) || ts_morph_1.Node.isBlock(parent)) {
|
|
72
71
|
return false;
|
|
73
72
|
}
|
|
74
73
|
// crawl up parents to make sure we're not inside a type
|
|
75
74
|
if (ts_morph_1.Node.isTypeNode(parent) || ts_morph_1.Node.isTypeAliasDeclaration(parent)) {
|
|
76
|
-
|
|
75
|
+
isInsideType = true;
|
|
77
76
|
return false;
|
|
78
77
|
}
|
|
79
78
|
return true;
|
|
80
79
|
});
|
|
81
|
-
if (
|
|
80
|
+
if (isInsideType)
|
|
82
81
|
return;
|
|
83
82
|
if (isInsideDeclaration)
|
|
84
83
|
return;
|
|
85
|
-
|
|
84
|
+
const nodeSymbol = node.getSymbol();
|
|
86
85
|
if (ts_morph_1.Node.isPropertyAccessExpression(node) &&
|
|
87
86
|
node.getExpression().getSymbol() === propsSymbol) {
|
|
88
87
|
reactiveValues.props.add(node.getNameNode().getText());
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as babel from '@babel/core';
|
|
2
1
|
import { MitosisComponent, MitosisState } from '../../types/mitosis-component';
|
|
3
|
-
|
|
2
|
+
import { ObjectExpression } from '@babel/types';
|
|
4
3
|
/**
|
|
5
4
|
* Convert state identifiers from React hooks format to the state.* format Mitosis needs
|
|
6
5
|
* e.g.
|
|
@@ -8,5 +7,4 @@ declare const types: typeof babel.types;
|
|
|
8
7
|
* setText(...) -> state.text = ...
|
|
9
8
|
*/
|
|
10
9
|
export declare function mapStateIdentifiers(json: MitosisComponent): void;
|
|
11
|
-
export declare const parseStateObjectToMitosisState: (object:
|
|
12
|
-
export {};
|
|
10
|
+
export declare const parseStateObjectToMitosisState: (object: ObjectExpression, isState?: boolean) => MitosisState;
|
|
@@ -1,79 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
-
}
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
4
|
};
|
|
39
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
6
|
exports.parseStateObjectToMitosisState = exports.mapStateIdentifiers = void 0;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
var types = babel.types;
|
|
7
|
+
const babel_transform_1 = require("../../helpers/babel-transform");
|
|
8
|
+
const capitalize_1 = require("../../helpers/capitalize");
|
|
9
|
+
const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
10
|
+
const process_code_1 = require("../../helpers/plugins/process-code");
|
|
11
|
+
const types_1 = require("@babel/types");
|
|
12
|
+
const function_1 = require("fp-ts/lib/function");
|
|
13
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
14
|
+
const helpers_1 = require("./helpers");
|
|
50
15
|
function mapStateIdentifiersInExpression(expression, stateProperties) {
|
|
51
|
-
|
|
16
|
+
const setExpressions = stateProperties.map((propertyName) => `set${(0, capitalize_1.capitalize)(propertyName)}`);
|
|
52
17
|
return (0, function_1.pipe)((0, babel_transform_1.babelTransformExpression)(expression, {
|
|
53
|
-
Identifier
|
|
18
|
+
Identifier(path) {
|
|
54
19
|
if (stateProperties.includes(path.node.name)) {
|
|
55
20
|
if (
|
|
56
21
|
// ignore member expressions, as the `stateProperty` is going to be at the module scope.
|
|
57
|
-
!(
|
|
58
|
-
!(
|
|
22
|
+
!((0, types_1.isMemberExpression)(path.parent) && path.parent.property === path.node) &&
|
|
23
|
+
!((0, types_1.isOptionalMemberExpression)(path.parent) && path.parent.property === path.node) &&
|
|
59
24
|
// ignore declarations of that state property, e.g. `function foo() {}`
|
|
60
|
-
!
|
|
61
|
-
!
|
|
62
|
-
!(
|
|
25
|
+
!(0, types_1.isDeclaration)(path.parent) &&
|
|
26
|
+
!(0, types_1.isFunctionDeclaration)(path.parent) &&
|
|
27
|
+
!((0, types_1.isFunctionExpression)(path.parent) && path.parent.id === path.node) &&
|
|
63
28
|
// ignore object keys
|
|
64
|
-
!(
|
|
65
|
-
|
|
66
|
-
path.findParent(
|
|
67
|
-
if (
|
|
68
|
-
|
|
29
|
+
!((0, types_1.isObjectProperty)(path.parent) && path.parent.key === path.node)) {
|
|
30
|
+
let hasTypeParent = false;
|
|
31
|
+
path.findParent((parent) => {
|
|
32
|
+
if ((0, types_1.isTSType)(parent) || (0, types_1.isTSInterfaceBody)(parent)) {
|
|
33
|
+
hasTypeParent = true;
|
|
69
34
|
return true;
|
|
70
35
|
}
|
|
71
36
|
return false;
|
|
72
37
|
});
|
|
73
|
-
if (
|
|
38
|
+
if (hasTypeParent) {
|
|
74
39
|
return;
|
|
75
40
|
}
|
|
76
|
-
|
|
41
|
+
const newExpression = (0, types_1.memberExpression)((0, types_1.identifier)('state'), (0, types_1.identifier)(path.node.name));
|
|
77
42
|
try {
|
|
78
43
|
path.replaceWith(newExpression);
|
|
79
44
|
}
|
|
@@ -89,19 +54,19 @@ function mapStateIdentifiersInExpression(expression, stateProperties) {
|
|
|
89
54
|
}
|
|
90
55
|
}
|
|
91
56
|
},
|
|
92
|
-
CallExpression
|
|
93
|
-
if (
|
|
57
|
+
CallExpression(path) {
|
|
58
|
+
if ((0, types_1.isIdentifier)(path.node.callee)) {
|
|
94
59
|
if (setExpressions.includes(path.node.callee.name)) {
|
|
95
60
|
// setFoo -> foo
|
|
96
|
-
|
|
61
|
+
const statePropertyName = (0, helpers_1.uncapitalize)(path.node.callee.name.slice(3));
|
|
97
62
|
// setFoo(...) -> state.foo = ...
|
|
98
|
-
path.replaceWith(
|
|
63
|
+
path.replaceWith((0, types_1.assignmentExpression)('=', (0, types_1.identifier)(`state.${statePropertyName}`), path.node.arguments[0]));
|
|
99
64
|
}
|
|
100
65
|
}
|
|
101
66
|
},
|
|
102
|
-
}),
|
|
67
|
+
}), (code) => code.trim());
|
|
103
68
|
}
|
|
104
|
-
|
|
69
|
+
const consolidateClassBindings = (item) => {
|
|
105
70
|
if (item.bindings.className) {
|
|
106
71
|
if (item.bindings.class) {
|
|
107
72
|
// TO-DO: it's too much work to merge 2 bindings, so just remove the old one for now.
|
|
@@ -114,7 +79,7 @@ var consolidateClassBindings = function (item) {
|
|
|
114
79
|
}
|
|
115
80
|
if (item.properties.className) {
|
|
116
81
|
if (item.properties.class) {
|
|
117
|
-
item.properties.class =
|
|
82
|
+
item.properties.class = `${item.properties.class} ${item.properties.className}`;
|
|
118
83
|
}
|
|
119
84
|
else {
|
|
120
85
|
item.properties.class = item.properties.className;
|
|
@@ -122,7 +87,7 @@ var consolidateClassBindings = function (item) {
|
|
|
122
87
|
delete item.properties.className;
|
|
123
88
|
}
|
|
124
89
|
if (item.properties.class && item.bindings.class) {
|
|
125
|
-
console.warn(
|
|
90
|
+
console.warn(`[${item.name}]: Ended up with both a property and binding for 'class'.`);
|
|
126
91
|
}
|
|
127
92
|
};
|
|
128
93
|
/**
|
|
@@ -132,8 +97,8 @@ var consolidateClassBindings = function (item) {
|
|
|
132
97
|
* setText(...) -> state.text = ...
|
|
133
98
|
*/
|
|
134
99
|
function mapStateIdentifiers(json) {
|
|
135
|
-
|
|
136
|
-
|
|
100
|
+
const stateProperties = Object.keys(json.state);
|
|
101
|
+
const plugin = (0, process_code_1.createCodeProcessorPlugin)(() => (code) => mapStateIdentifiersInExpression(code, stateProperties));
|
|
137
102
|
plugin(json);
|
|
138
103
|
(0, legacy_1.default)(json).forEach(function (item) {
|
|
139
104
|
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
@@ -142,17 +107,17 @@ function mapStateIdentifiers(json) {
|
|
|
142
107
|
});
|
|
143
108
|
}
|
|
144
109
|
exports.mapStateIdentifiers = mapStateIdentifiers;
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
if (
|
|
110
|
+
const processStateObjectSlice = (item) => {
|
|
111
|
+
if ((0, types_1.isObjectProperty)(item)) {
|
|
112
|
+
if ((0, types_1.isFunctionExpression)(item.value)) {
|
|
148
113
|
return {
|
|
149
114
|
code: (0, helpers_1.parseCode)(item.value).trim(),
|
|
150
115
|
type: 'function',
|
|
151
116
|
};
|
|
152
117
|
}
|
|
153
|
-
else if (
|
|
154
|
-
|
|
155
|
-
|
|
118
|
+
else if ((0, types_1.isArrowFunctionExpression)(item.value)) {
|
|
119
|
+
const n = (0, types_1.objectMethod)('method', item.key, item.value.params, item.value.body);
|
|
120
|
+
const code = (0, helpers_1.parseCode)(n).trim();
|
|
156
121
|
return {
|
|
157
122
|
code: code,
|
|
158
123
|
type: 'method',
|
|
@@ -161,7 +126,7 @@ var processStateObjectSlice = function (item) {
|
|
|
161
126
|
else {
|
|
162
127
|
// Remove typescript types, e.g. from
|
|
163
128
|
// { foo: ('string' as SomeType) }
|
|
164
|
-
if (
|
|
129
|
+
if ((0, types_1.isTSAsExpression)(item.value)) {
|
|
165
130
|
return {
|
|
166
131
|
code: (0, helpers_1.parseCode)(item.value.expression).trim(),
|
|
167
132
|
type: 'property',
|
|
@@ -175,9 +140,9 @@ var processStateObjectSlice = function (item) {
|
|
|
175
140
|
};
|
|
176
141
|
}
|
|
177
142
|
}
|
|
178
|
-
else if (
|
|
179
|
-
|
|
180
|
-
|
|
143
|
+
else if ((0, types_1.isObjectMethod)(item)) {
|
|
144
|
+
const n = (0, helpers_1.parseCode)({ ...item, returnType: null }).trim();
|
|
145
|
+
const isGetter = item.kind === 'get';
|
|
181
146
|
return {
|
|
182
147
|
code: n,
|
|
183
148
|
type: isGetter ? 'getter' : 'method',
|
|
@@ -187,9 +152,9 @@ var processStateObjectSlice = function (item) {
|
|
|
187
152
|
throw new Error('Unexpected state value type', item);
|
|
188
153
|
}
|
|
189
154
|
};
|
|
190
|
-
|
|
191
|
-
if (
|
|
192
|
-
if (
|
|
155
|
+
const processDefaultPropsSlice = (item) => {
|
|
156
|
+
if ((0, types_1.isObjectProperty)(item)) {
|
|
157
|
+
if ((0, types_1.isFunctionExpression)(item.value) || (0, types_1.isArrowFunctionExpression)(item.value)) {
|
|
193
158
|
return {
|
|
194
159
|
code: (0, helpers_1.parseCode)(item.value),
|
|
195
160
|
type: 'method',
|
|
@@ -198,7 +163,7 @@ var processDefaultPropsSlice = function (item) {
|
|
|
198
163
|
else {
|
|
199
164
|
// Remove typescript types, e.g. from
|
|
200
165
|
// { foo: ('string' as SomeType) }
|
|
201
|
-
if (
|
|
166
|
+
if ((0, types_1.isTSAsExpression)(item.value)) {
|
|
202
167
|
return {
|
|
203
168
|
code: (0, helpers_1.parseCode)(item.value.expression),
|
|
204
169
|
type: 'property',
|
|
@@ -212,9 +177,9 @@ var processDefaultPropsSlice = function (item) {
|
|
|
212
177
|
};
|
|
213
178
|
}
|
|
214
179
|
}
|
|
215
|
-
else if (
|
|
216
|
-
|
|
217
|
-
|
|
180
|
+
else if ((0, types_1.isObjectMethod)(item)) {
|
|
181
|
+
const n = (0, helpers_1.parseCode)({ ...item, returnType: null });
|
|
182
|
+
const isGetter = item.kind === 'get';
|
|
218
183
|
return {
|
|
219
184
|
code: n,
|
|
220
185
|
type: isGetter ? 'getter' : 'method',
|
|
@@ -224,20 +189,21 @@ var processDefaultPropsSlice = function (item) {
|
|
|
224
189
|
throw new Error('Unexpected state value type', item);
|
|
225
190
|
}
|
|
226
191
|
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (types.isSpreadElement(x)) {
|
|
192
|
+
const parseStateObjectToMitosisState = (object, isState = true) => {
|
|
193
|
+
const state = {};
|
|
194
|
+
object.properties.forEach((x) => {
|
|
195
|
+
if ((0, types_1.isSpreadElement)(x)) {
|
|
232
196
|
throw new Error('Parse Error: Mitosis cannot consume spread element in state object: ' + x);
|
|
233
197
|
}
|
|
234
|
-
if (
|
|
198
|
+
if ((0, types_1.isPrivateName)(x.key)) {
|
|
235
199
|
throw new Error('Parse Error: Mitosis cannot consume private name in state object: ' + x.key);
|
|
236
200
|
}
|
|
237
|
-
if (!
|
|
238
|
-
throw new Error('Parse Error: Mitosis cannot consume non-identifier key in state object: ' +
|
|
201
|
+
if (!(0, types_1.isIdentifier)(x.key) && !(0, types_1.isStringLiteral)(x.key)) {
|
|
202
|
+
throw new Error('Parse Error: Mitosis cannot consume non-identifier and non-string key in state object: ' +
|
|
203
|
+
x.key);
|
|
239
204
|
}
|
|
240
|
-
|
|
205
|
+
const keyName = (0, types_1.isStringLiteral)(x.key) ? x.key.value : x.key.name;
|
|
206
|
+
state[keyName] = isState ? processStateObjectSlice(x) : processDefaultPropsSlice(x);
|
|
241
207
|
});
|
|
242
208
|
return state;
|
|
243
209
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseCss = void 0;
|
|
4
|
-
|
|
4
|
+
const parseCss = (ast, json) => {
|
|
5
5
|
var _a;
|
|
6
6
|
json.style = (_a = ast.css) === null || _a === void 0 ? void 0 : _a.content.styles;
|
|
7
7
|
};
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.processBindings = void 0;
|
|
4
|
-
|
|
5
|
-
function replaceGroupWithChecked(node, isArray) {
|
|
4
|
+
const bindings_1 = require("../../../helpers/bindings");
|
|
5
|
+
function replaceGroupWithChecked(node, isArray = false) {
|
|
6
6
|
var _a, _b, _c;
|
|
7
|
-
if (isArray === void 0) { isArray = false; }
|
|
8
7
|
if ((_b = (_a = node.bindings.group) === null || _a === void 0 ? void 0 : _a.code) === null || _b === void 0 ? void 0 : _b.length) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
const bindingValue = (_c = node.bindings.value) === null || _c === void 0 ? void 0 : _c.code;
|
|
9
|
+
const propertyValue = node.properties.value;
|
|
10
|
+
const groupBinding = node.bindings.group.code;
|
|
11
|
+
let code = '';
|
|
13
12
|
if (isArray) {
|
|
14
13
|
code = bindingValue
|
|
15
|
-
?
|
|
16
|
-
:
|
|
14
|
+
? `${groupBinding}.includes(${bindingValue})`
|
|
15
|
+
: `${groupBinding}.includes('${propertyValue}')`;
|
|
17
16
|
}
|
|
18
17
|
else {
|
|
19
18
|
code = bindingValue
|
|
20
|
-
?
|
|
21
|
-
:
|
|
19
|
+
? `${groupBinding} === ${bindingValue}`
|
|
20
|
+
: `${groupBinding} === '${propertyValue}'`;
|
|
22
21
|
}
|
|
23
22
|
node.bindings['checked'] = (0, bindings_1.createSingleBinding)({
|
|
24
|
-
code
|
|
23
|
+
code,
|
|
25
24
|
});
|
|
26
25
|
delete node.bindings.group;
|
|
27
26
|
}
|
|
@@ -36,15 +35,15 @@ function replaceGroupWithChecked(node, isArray) {
|
|
|
36
35
|
*/
|
|
37
36
|
function processBindings(json, node) {
|
|
38
37
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
let name;
|
|
39
|
+
let target = 'event.target.value';
|
|
40
|
+
let binding = '';
|
|
41
|
+
let isArray = false;
|
|
43
42
|
if (Object.prototype.hasOwnProperty.call(node.bindings, 'group')) {
|
|
44
43
|
name = 'group';
|
|
45
44
|
binding = (_b = (_a = node.bindings.group) === null || _a === void 0 ? void 0 : _a.code) !== null && _b !== void 0 ? _b : '';
|
|
46
45
|
if (binding.startsWith('state.')) {
|
|
47
|
-
|
|
46
|
+
const stateObject = json.state[binding.replace(/^state\./, '')];
|
|
48
47
|
isArray = Array.isArray(stateObject === null || stateObject === void 0 ? void 0 : stateObject.code);
|
|
49
48
|
}
|
|
50
49
|
replaceGroupWithChecked(node, isArray);
|
|
@@ -61,10 +60,10 @@ function processBindings(json, node) {
|
|
|
61
60
|
target = 'event.target.checked';
|
|
62
61
|
binding = (_f = (_e = node.bindings.onChange) === null || _e === void 0 ? void 0 : _e.code.split('=')[0]) !== null && _f !== void 0 ? _f : '';
|
|
63
62
|
}
|
|
64
|
-
|
|
63
|
+
let onChangeCode = `${binding} = ${target}`;
|
|
65
64
|
// If the binding is an array, we should push / splice rather than assigning
|
|
66
65
|
if (isArray) {
|
|
67
|
-
onChangeCode =
|
|
66
|
+
onChangeCode = `event.target.checked ? ${binding}.push(${target}) : ${binding}.splice(${binding}.indexOf(${node.properties.value ? `'${node.properties.value}'` : (_g = node.bindings.value) === null || _g === void 0 ? void 0 : _g.code}), 1)`;
|
|
68
67
|
}
|
|
69
68
|
if (name !== 'ref' && binding) {
|
|
70
69
|
node.bindings['onChange'] = (0, bindings_1.createSingleBinding)({
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseChildren = exports.filterChildren = void 0;
|
|
4
|
-
|
|
4
|
+
const html_1 = require("../html");
|
|
5
5
|
function filterChildren(children) {
|
|
6
6
|
var _a;
|
|
7
|
-
return ((_a = children === null || children === void 0 ? void 0 : children.filter(
|
|
7
|
+
return ((_a = children === null || children === void 0 ? void 0 : children.filter((n) => { var _a; return n.type !== 'Comment' && (n.type !== 'Text' || ((_a = n.data) === null || _a === void 0 ? void 0 : _a.trim().length)); })) !== null && _a !== void 0 ? _a : []);
|
|
8
8
|
}
|
|
9
9
|
exports.filterChildren = filterChildren;
|
|
10
10
|
function parseChildren(json, node) {
|
|
11
|
-
|
|
11
|
+
const children = [];
|
|
12
12
|
if (node.children) {
|
|
13
|
-
for (
|
|
14
|
-
|
|
15
|
-
var mitosisNode = (0, html_1.parseHtmlNode)(json, child);
|
|
13
|
+
for (const child of filterChildren(node.children)) {
|
|
14
|
+
const mitosisNode = (0, html_1.parseHtmlNode)(json, child);
|
|
16
15
|
if (mitosisNode) {
|
|
17
16
|
children.push(mitosisNode);
|
|
18
17
|
}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseObjectExpression = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const astring_1 = require("astring");
|
|
5
|
+
const references_1 = require("../instance/references");
|
|
6
6
|
function parseObjectExpression(json, node) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var node_ = n;
|
|
7
|
+
const properties = node.properties.map((n) => {
|
|
8
|
+
const node_ = n;
|
|
10
9
|
return {
|
|
11
10
|
key: (0, astring_1.generate)(node_.key),
|
|
12
11
|
value: (0, references_1.getParsedValue)(json, node_.value),
|
|
13
12
|
};
|
|
14
13
|
});
|
|
15
|
-
|
|
16
|
-
for (
|
|
17
|
-
|
|
18
|
-
Object.assign(c, (_a = {}, _a[item.key] = item.value, _a));
|
|
14
|
+
const c = {};
|
|
15
|
+
for (const item of properties) {
|
|
16
|
+
Object.assign(c, { [item.key]: item.value });
|
|
19
17
|
}
|
|
20
18
|
return c;
|
|
21
19
|
}
|
|
@@ -4,11 +4,11 @@ exports.addToOnInitHook = void 0;
|
|
|
4
4
|
function addToOnInitHook(json, code) {
|
|
5
5
|
var _a;
|
|
6
6
|
if ((_a = json.hooks.onInit) === null || _a === void 0 ? void 0 : _a.code.length) {
|
|
7
|
-
json.hooks.onInit.code +=
|
|
7
|
+
json.hooks.onInit.code += `\n ${code}`;
|
|
8
8
|
}
|
|
9
9
|
else {
|
|
10
10
|
json.hooks.onInit = {
|
|
11
|
-
code
|
|
11
|
+
code,
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
}
|