@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,86 +1,67 @@
|
|
|
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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.getStateObjectStringFromComponent = exports.stringifyContextValue = exports.getMemberObjectString = void 0;
|
|
15
|
-
|
|
4
|
+
const DEFAULT_OPTIONS = {
|
|
16
5
|
format: 'object',
|
|
17
6
|
keyPrefix: '',
|
|
18
|
-
valueMapper:
|
|
7
|
+
valueMapper: (val) => val,
|
|
19
8
|
data: true,
|
|
20
9
|
functions: true,
|
|
21
10
|
getters: true,
|
|
22
11
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
case 'function': {
|
|
34
|
-
if (functions === false || typeof code !== 'string') {
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
return "".concat(keyPrefix, " ").concat(key, " ").concat(keyValueDelimiter, " ").concat(valueMapper(code, 'function', typeParameter, key));
|
|
12
|
+
const convertStateMemberToString = ({ data, format, functions, getters, keyPrefix, valueMapper }) => ([key, state]) => {
|
|
13
|
+
const keyValueDelimiter = format === 'object' ? ':' : '=';
|
|
14
|
+
if (!state) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const { code, typeParameter } = state;
|
|
18
|
+
switch (state.type) {
|
|
19
|
+
case 'function': {
|
|
20
|
+
if (functions === false || typeof code !== 'string') {
|
|
21
|
+
return undefined;
|
|
38
22
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return
|
|
23
|
+
return `${keyPrefix} ${key} ${keyValueDelimiter} ${valueMapper(code, 'function', typeParameter, key)}`;
|
|
24
|
+
}
|
|
25
|
+
case 'method': {
|
|
26
|
+
if (functions === false || typeof code !== 'string') {
|
|
27
|
+
return undefined;
|
|
44
28
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return
|
|
29
|
+
return `${keyPrefix} ${valueMapper(code, 'function', typeParameter, key)}`;
|
|
30
|
+
}
|
|
31
|
+
case 'getter': {
|
|
32
|
+
if (getters === false || typeof code !== 'string') {
|
|
33
|
+
return undefined;
|
|
50
34
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return
|
|
35
|
+
return `${keyPrefix} ${valueMapper(code, 'getter', typeParameter, key)}`;
|
|
36
|
+
}
|
|
37
|
+
case 'property': {
|
|
38
|
+
if (data === false) {
|
|
39
|
+
return undefined;
|
|
56
40
|
}
|
|
57
|
-
|
|
58
|
-
break;
|
|
41
|
+
return `${keyPrefix} ${key}${keyValueDelimiter} ${valueMapper(code, 'data', typeParameter, key)}`;
|
|
59
42
|
}
|
|
60
|
-
|
|
43
|
+
default:
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
61
46
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var stringifiedProperties = Object.entries(object)
|
|
47
|
+
const getMemberObjectString = (object, userOptions = {}) => {
|
|
48
|
+
const options = { ...DEFAULT_OPTIONS, ...userOptions };
|
|
49
|
+
const lineItemDelimiter = options.format === 'object' ? ',' : '\n';
|
|
50
|
+
const stringifiedProperties = Object.entries(object)
|
|
67
51
|
.map(convertStateMemberToString(options))
|
|
68
|
-
.filter(
|
|
52
|
+
.filter((x) => x !== undefined)
|
|
69
53
|
.join(lineItemDelimiter);
|
|
70
|
-
|
|
71
|
-
|
|
54
|
+
const prefix = options.format === 'object' ? '{' : '';
|
|
55
|
+
const suffix = options.format === 'object' ? '}' : '';
|
|
72
56
|
// NOTE: we add a `lineItemDelimiter` at the very end because other functions will sometimes append more properties.
|
|
73
57
|
// If the delimiter is a comma and the format is `object`, then we need to make sure we have an extra comma at the end,
|
|
74
58
|
// or the object will become invalid JS.
|
|
75
59
|
// We also have to make sure that `stringifiedProperties` isn't empty, or we will get `{,}` which is invalid
|
|
76
|
-
|
|
77
|
-
return
|
|
60
|
+
const extraDelimiter = stringifiedProperties.length > 0 ? lineItemDelimiter : '';
|
|
61
|
+
return `${prefix}${stringifiedProperties}${extraDelimiter}${suffix}`;
|
|
78
62
|
};
|
|
79
63
|
exports.getMemberObjectString = getMemberObjectString;
|
|
80
|
-
|
|
81
|
-
if (userOptions === void 0) { userOptions = {}; }
|
|
82
|
-
return (0, exports.getMemberObjectString)(object, userOptions);
|
|
83
|
-
};
|
|
64
|
+
const stringifyContextValue = (object, userOptions = {}) => (0, exports.getMemberObjectString)(object, userOptions);
|
|
84
65
|
exports.stringifyContextValue = stringifyContextValue;
|
|
85
|
-
|
|
66
|
+
const getStateObjectStringFromComponent = (component, options) => (0, exports.getMemberObjectString)(component.state, options);
|
|
86
67
|
exports.getStateObjectStringFromComponent = getStateObjectStringFromComponent;
|
|
@@ -4,21 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getStateUsed = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
8
|
+
const stateAccessRegex = /state\s*\.\s*([a-zA-Z0-9_\$]+)/;
|
|
9
|
+
const allStateMatchesRegex = new RegExp(stateAccessRegex, 'g');
|
|
10
10
|
/**
|
|
11
11
|
* Get state used in the components by reference
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const getStateUsed = (json) => {
|
|
14
|
+
const stateProperties = new Set();
|
|
15
15
|
(0, legacy_1.default)(json).forEach(function (item) {
|
|
16
16
|
if (typeof item === 'string') {
|
|
17
17
|
// TODO: proper babel ref matching
|
|
18
|
-
|
|
18
|
+
const matches = item.match(allStateMatchesRegex);
|
|
19
19
|
if (matches) {
|
|
20
|
-
for (
|
|
21
|
-
var match = matches_1[_i];
|
|
20
|
+
for (const match of matches) {
|
|
22
21
|
stateProperties.add(match.match(stateAccessRegex)[1]);
|
|
23
22
|
}
|
|
24
23
|
}
|
|
@@ -4,15 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.setStyles = exports.getStyles = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const json5_1 = __importDefault(require("json5"));
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const bindings_1 = require("./bindings");
|
|
10
|
+
const getStyles = (json) => {
|
|
11
11
|
var _a;
|
|
12
12
|
if (!json.bindings.css) {
|
|
13
13
|
return null;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
let css;
|
|
16
16
|
try {
|
|
17
17
|
css = json5_1.default.parse((_a = json.bindings.css) === null || _a === void 0 ? void 0 : _a.code);
|
|
18
18
|
}
|
|
@@ -23,7 +23,7 @@ var getStyles = function (json) {
|
|
|
23
23
|
return css;
|
|
24
24
|
};
|
|
25
25
|
exports.getStyles = getStyles;
|
|
26
|
-
|
|
26
|
+
const setStyles = (json, styles) => {
|
|
27
27
|
if (!(0, lodash_1.size)(styles)) {
|
|
28
28
|
delete json.bindings.css;
|
|
29
29
|
}
|
|
@@ -4,32 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.gettersToFunctions = void 0;
|
|
7
|
-
|
|
7
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
8
8
|
/**
|
|
9
9
|
* Map getters like `useStore({ get foo() { ... }})` from `state.foo` to `foo()`
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const gettersToFunctions = (json) => {
|
|
12
|
+
const getterKeys = Object.keys(json.state).filter((item) => { var _a; return ((_a = json.state[item]) === null || _a === void 0 ? void 0 : _a.type) === 'getter'; });
|
|
13
13
|
(0, legacy_1.default)(json).forEach(function (item) {
|
|
14
14
|
// TODO: not all strings are expressions!
|
|
15
15
|
if (typeof item === 'string') {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
let value = item;
|
|
17
|
+
for (const key of getterKeys) {
|
|
18
18
|
try {
|
|
19
|
-
value = value.replace(new RegExp(
|
|
19
|
+
value = value.replace(new RegExp(`state\\s*\\.\\s*${key}([^a-z0-9]|$)`, 'gi'), (match, group1) => {
|
|
20
20
|
if (match.endsWith('?')) {
|
|
21
|
-
return
|
|
21
|
+
return `${key}?.()${group1}`;
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return `${key}()${group1}`;
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
catch (err) {
|
|
27
27
|
console.error('Could not update getter ref', err);
|
|
28
28
|
}
|
|
29
|
-
};
|
|
30
|
-
for (var _i = 0, getterKeys_1 = getterKeys; _i < getterKeys_1.length; _i++) {
|
|
31
|
-
var key = getterKeys_1[_i];
|
|
32
|
-
_loop_1(key);
|
|
33
29
|
}
|
|
34
30
|
if (value !== item) {
|
|
35
31
|
this.update(value);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handleMissingState = void 0;
|
|
4
|
-
|
|
4
|
+
const get_state_used_1 = require("./get-state-used");
|
|
5
5
|
function handleMissingState(json) {
|
|
6
|
-
|
|
7
|
-
Array.from(stateUsed).forEach(
|
|
6
|
+
const stateUsed = (0, get_state_used_1.getStateUsed)(json);
|
|
7
|
+
Array.from(stateUsed).forEach((property) => {
|
|
8
8
|
if (!(property in json.state)) {
|
|
9
9
|
json.state[property] = { code: 'null', type: 'property', propertyType: 'normal' };
|
|
10
10
|
}
|
|
@@ -4,14 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.hasBindingsText = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
8
|
+
const is_children_1 = __importDefault(require("./is-children"));
|
|
9
|
+
const is_mitosis_node_1 = require("./is-mitosis-node");
|
|
10
|
+
const hasBindingsText = (json) => {
|
|
11
|
+
let has = false;
|
|
12
12
|
(0, legacy_1.default)(json).forEach(function (node) {
|
|
13
13
|
var _a;
|
|
14
|
-
if ((0, is_mitosis_node_1.isMitosisNode)(node) && !(0, is_children_1.default)({ node
|
|
14
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(node) && !(0, is_children_1.default)({ node }) && ((_a = node.bindings._text) === null || _a === void 0 ? void 0 : _a.code)) {
|
|
15
15
|
has = true;
|
|
16
16
|
this.stop();
|
|
17
17
|
}
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.hasComponent = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
8
|
+
const is_mitosis_node_1 = require("./is-mitosis-node");
|
|
9
|
+
const hasComponent = (name, json) => {
|
|
10
|
+
let has = false;
|
|
11
11
|
(0, legacy_1.default)(json).forEach(function (item) {
|
|
12
12
|
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
13
13
|
if (item.name === name) {
|
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.hasProps = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
8
|
+
const hasProps = (json) => {
|
|
9
|
+
let has = false;
|
|
10
10
|
(0, legacy_1.default)(json).forEach(function (item) {
|
|
11
11
|
// TODO: use proper reference tracking
|
|
12
12
|
if (typeof item === 'string' && item.match(/(^|\W)props\s*\./)) {
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.hasStatefulDom = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
8
|
+
const is_mitosis_node_1 = require("./is-mitosis-node");
|
|
9
|
+
const hasStatefulDom = (json) => {
|
|
10
|
+
let has = false;
|
|
11
11
|
(0, legacy_1.default)(json).forEach(function (item) {
|
|
12
12
|
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
13
13
|
if (/input|textarea|select/.test(item.name)) {
|
package/dist/src/helpers/has.js
CHANGED
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.has = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
8
|
+
const is_mitosis_node_1 = require("./is-mitosis-node");
|
|
9
9
|
/**
|
|
10
10
|
* Test if the component has something
|
|
11
11
|
*
|
|
@@ -13,7 +13,7 @@ var is_mitosis_node_1 = require("./is-mitosis-node");
|
|
|
13
13
|
* const hasSpread = has(component, node => some(node.bindings, { type: 'spread' }));
|
|
14
14
|
*/
|
|
15
15
|
function has(json, test) {
|
|
16
|
-
|
|
16
|
+
let found = false;
|
|
17
17
|
(0, legacy_1.default)(json).forEach(function (thing) {
|
|
18
18
|
if ((0, is_mitosis_node_1.isMitosisNode)(thing)) {
|
|
19
19
|
if (test(thing)) {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.indent = void 0;
|
|
4
|
-
function indent(str, spaces) {
|
|
5
|
-
|
|
6
|
-
return str.replace(/\n([^\n])/g, "\n".concat(' '.repeat(spaces), "$1"));
|
|
4
|
+
function indent(str, spaces = 4) {
|
|
5
|
+
return str.replace(/\n([^\n])/g, `\n${' '.repeat(spaces)}$1`);
|
|
7
6
|
}
|
|
8
7
|
exports.indent = indent;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTextValue = void 0;
|
|
4
|
-
|
|
4
|
+
const getTextValue = (node) => {
|
|
5
5
|
var _a;
|
|
6
|
-
|
|
6
|
+
const textValue = ((_a = node.bindings._text) === null || _a === void 0 ? void 0 : _a.code) || node.properties.__text || '';
|
|
7
7
|
return textValue.replace(/\s+/g, '');
|
|
8
8
|
};
|
|
9
9
|
exports.getTextValue = getTextValue;
|
|
10
|
-
function isChildren(
|
|
11
|
-
|
|
12
|
-
var textValue = (0, exports.getTextValue)(node);
|
|
10
|
+
function isChildren({ node, extraMatches = [], }) {
|
|
11
|
+
const textValue = (0, exports.getTextValue)(node);
|
|
13
12
|
return ['props.children', 'children'].concat(extraMatches).includes(textValue);
|
|
14
13
|
}
|
|
15
14
|
exports.default = isChildren;
|
|
@@ -4,5 +4,5 @@ exports.isComponent = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* This node is a component, vs a plain html tag (<Foo> vs <div>)
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
const isComponent = (json) => json.name.toLowerCase() !== json.name;
|
|
8
8
|
exports.isComponent = isComponent;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.isHtmlAttribute = exports.htmlElementAttributes = void 0;
|
|
13
4
|
exports.htmlElementAttributes = {
|
|
@@ -370,11 +361,11 @@ exports.htmlElementAttributes = {
|
|
|
370
361
|
'width',
|
|
371
362
|
],
|
|
372
363
|
};
|
|
373
|
-
|
|
364
|
+
const isHtmlAttribute = (attr, tagName) => {
|
|
374
365
|
if (/role|aria-/.test(attr)) {
|
|
375
366
|
return true;
|
|
376
367
|
}
|
|
377
|
-
|
|
368
|
+
const getAttr = [...exports.htmlElementAttributes['*'], ...(exports.htmlElementAttributes[tagName] || [])].find((attribute) => attr === attribute);
|
|
378
369
|
return Boolean(getAttr);
|
|
379
370
|
};
|
|
380
371
|
exports.isHtmlAttribute = isHtmlAttribute;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isMitosisNode = void 0;
|
|
4
|
-
|
|
4
|
+
const isMitosisNode = (thing) => {
|
|
5
5
|
return Boolean(thing && thing['@type'] === '@builder.io/mitosis/node');
|
|
6
6
|
};
|
|
7
7
|
exports.isMitosisNode = isMitosisNode;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isTextNode = exports.isRootTextNode = void 0;
|
|
4
4
|
function isRootTextNode(json) {
|
|
5
|
-
|
|
5
|
+
const firstChild = json.children[0];
|
|
6
6
|
return Boolean(json.children.length === 1 && firstChild && isTextNode(firstChild));
|
|
7
7
|
}
|
|
8
8
|
exports.isRootTextNode = isRootTextNode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isUpperCase = void 0;
|
|
4
|
-
|
|
4
|
+
const isUpperCase = (str) => str.toUpperCase() === str;
|
|
5
5
|
exports.isUpperCase = isUpperCase;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isValidAttributeName = void 0;
|
|
4
|
-
|
|
4
|
+
const isValidAttributeName = (str) => {
|
|
5
5
|
return Boolean(str && /^[a-z0-9\-_:]+$/i.test(str));
|
|
6
6
|
};
|
|
7
7
|
exports.isValidAttributeName = isValidAttributeName;
|
package/dist/src/helpers/json.js
CHANGED
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.tryParseJson = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const json5_1 = __importDefault(require("json5"));
|
|
8
|
+
const tryParseJson = (jsonStr) => {
|
|
9
9
|
try {
|
|
10
10
|
return json5_1.default.parse(jsonStr);
|
|
11
11
|
}
|
|
@@ -1,52 +1,40 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.mapRefs = void 0;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
const core_1 = require("@babel/core");
|
|
8
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
9
|
+
const babel_transform_1 = require("./babel-transform");
|
|
10
|
+
const get_refs_1 = require("./get-refs");
|
|
11
|
+
const is_mitosis_node_1 = require("./is-mitosis-node");
|
|
12
|
+
const patterns_1 = require("./patterns");
|
|
13
|
+
const replaceRefsInString = (code, refs, mapper) => {
|
|
25
14
|
return (0, babel_transform_1.babelTransformExpression)(code, {
|
|
26
|
-
Identifier
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
Identifier(path) {
|
|
16
|
+
const name = path.node.name;
|
|
17
|
+
const isRef = refs.includes(name);
|
|
29
18
|
if (isRef) {
|
|
30
19
|
path.replaceWith(core_1.types.identifier(mapper(name)));
|
|
31
20
|
}
|
|
32
21
|
},
|
|
33
22
|
});
|
|
34
23
|
};
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
const mapRefs = (component, mapper) => {
|
|
25
|
+
const refSet = (0, get_refs_1.getRefs)(component);
|
|
37
26
|
// grab refs not used for bindings
|
|
38
|
-
Object.keys(component.refs).forEach(
|
|
39
|
-
|
|
40
|
-
for (
|
|
41
|
-
|
|
42
|
-
var stateVal = component.state[key];
|
|
27
|
+
Object.keys(component.refs).forEach((ref) => refSet.add(ref));
|
|
28
|
+
const refs = Array.from(refSet);
|
|
29
|
+
for (const key of Object.keys(component.state)) {
|
|
30
|
+
const stateVal = component.state[key];
|
|
43
31
|
if (typeof (stateVal === null || stateVal === void 0 ? void 0 : stateVal.code) === 'string') {
|
|
44
|
-
|
|
32
|
+
const value = stateVal.code;
|
|
45
33
|
switch (stateVal.type) {
|
|
46
34
|
case 'method':
|
|
47
35
|
case 'getter':
|
|
48
|
-
|
|
49
|
-
|
|
36
|
+
const isGet = stateVal.type === 'getter';
|
|
37
|
+
const isSet = Boolean(value.match(patterns_1.SETTER));
|
|
50
38
|
component.state[key] = {
|
|
51
39
|
code: replaceRefsInString(value.replace(/^(get |set )?/, 'function '), refs, mapper).replace(/^function /, isGet ? 'get ' : isSet ? 'set ' : ''),
|
|
52
40
|
type: stateVal.type,
|
|
@@ -65,20 +53,21 @@ var mapRefs = function (component, mapper) {
|
|
|
65
53
|
}
|
|
66
54
|
(0, legacy_1.default)(component).forEach(function (item) {
|
|
67
55
|
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
68
|
-
for (
|
|
69
|
-
|
|
70
|
-
var value = item.bindings[key];
|
|
56
|
+
for (const key of Object.keys(item.bindings)) {
|
|
57
|
+
const value = item.bindings[key];
|
|
71
58
|
if (typeof value === 'object' && key !== 'ref') {
|
|
72
|
-
item.bindings[key] =
|
|
59
|
+
item.bindings[key] = {
|
|
60
|
+
...value,
|
|
61
|
+
code: replaceRefsInString(value.code, refs, mapper),
|
|
62
|
+
};
|
|
73
63
|
}
|
|
74
64
|
}
|
|
75
65
|
}
|
|
76
66
|
});
|
|
77
|
-
for (
|
|
78
|
-
|
|
79
|
-
var hooks = component.hooks[key];
|
|
67
|
+
for (const key of Object.keys(component.hooks)) {
|
|
68
|
+
const hooks = component.hooks[key];
|
|
80
69
|
if (Array.isArray(hooks)) {
|
|
81
|
-
hooks.forEach(
|
|
70
|
+
hooks.forEach((hook) => {
|
|
82
71
|
if (hook.code) {
|
|
83
72
|
hook.code = replaceRefsInString(hook.code, refs, mapper);
|
|
84
73
|
}
|
|
@@ -88,7 +77,7 @@ var mapRefs = function (component, mapper) {
|
|
|
88
77
|
});
|
|
89
78
|
}
|
|
90
79
|
else {
|
|
91
|
-
|
|
80
|
+
const hookCode = hooks === null || hooks === void 0 ? void 0 : hooks.code;
|
|
92
81
|
if (hookCode) {
|
|
93
82
|
hooks.code = replaceRefsInString(hookCode, refs, mapper);
|
|
94
83
|
}
|