@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,25 +1,14 @@
|
|
|
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.parseIfElse = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
const astring_1 = require("astring");
|
|
5
|
+
const _1 = require(".");
|
|
6
|
+
const children_1 = require("../helpers/children");
|
|
7
|
+
const mitosis_node_1 = require("../helpers/mitosis-node");
|
|
8
|
+
const bindings_1 = require("../../../helpers/bindings");
|
|
20
9
|
function parseIfElse(json, node) {
|
|
21
10
|
var _a, _b, _c;
|
|
22
|
-
|
|
11
|
+
const mitosisNode = (0, mitosis_node_1.createMitosisNode)();
|
|
23
12
|
mitosisNode.name = 'Show';
|
|
24
13
|
mitosisNode.bindings = {
|
|
25
14
|
when: (0, bindings_1.createSingleBinding)({
|
|
@@ -31,7 +20,11 @@ function parseIfElse(json, node) {
|
|
|
31
20
|
mitosisNode.meta.else =
|
|
32
21
|
((_a = node.else.children) === null || _a === void 0 ? void 0 : _a.length) === 1
|
|
33
22
|
? (0, _1.parseHtmlNode)(json, node.else.children[0])
|
|
34
|
-
:
|
|
23
|
+
: {
|
|
24
|
+
...(0, mitosis_node_1.createMitosisNode)(),
|
|
25
|
+
name: 'div',
|
|
26
|
+
children: (_c = (_b = node.else.children) === null || _b === void 0 ? void 0 : _b.map((n) => (0, _1.parseHtmlNode)(json, n))) !== null && _c !== void 0 ? _c : [],
|
|
27
|
+
};
|
|
35
28
|
}
|
|
36
29
|
return mitosisNode;
|
|
37
30
|
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseHtmlNode = exports.parseHtml = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
const compiler_1 = require("svelte/compiler");
|
|
5
|
+
const each_1 = require("./each");
|
|
6
|
+
const element_1 = require("./element");
|
|
7
|
+
const fragment_1 = require("./fragment");
|
|
8
|
+
const if_else_1 = require("./if-else");
|
|
9
|
+
const mustache_tag_1 = require("./mustache-tag");
|
|
10
|
+
const slot_1 = require("./slot");
|
|
11
|
+
const text_1 = require("./text");
|
|
12
12
|
function parseHtml(ast, json) {
|
|
13
13
|
var _a, _b;
|
|
14
14
|
// todo: should filter children and check if just 1 has length
|
|
15
|
-
|
|
15
|
+
const html = ((_a = ast.html.children) === null || _a === void 0 ? void 0 : _a.length) === 2 && ((_b = ast.html.children[0].raw) === null || _b === void 0 ? void 0 : _b.trim().length) === 0
|
|
16
16
|
? ast.html.children[1]
|
|
17
17
|
: ast.html;
|
|
18
18
|
(0, compiler_1.walk)(html, {
|
|
19
|
-
enter
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
enter(node, parent) {
|
|
20
|
+
const templateNode = node;
|
|
21
|
+
const parentTemplateNode = parent;
|
|
22
22
|
if ((parentTemplateNode === null || parentTemplateNode === void 0 ? void 0 : parentTemplateNode.children) || templateNode.data === '\n\n') {
|
|
23
23
|
this.skip();
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
const mitosisNode = parseHtmlNode(json, templateNode);
|
|
27
27
|
if (mitosisNode) {
|
|
28
28
|
json.children.push(mitosisNode);
|
|
29
29
|
}
|
|
@@ -32,7 +32,7 @@ function parseHtml(ast, json) {
|
|
|
32
32
|
}
|
|
33
33
|
exports.parseHtml = parseHtml;
|
|
34
34
|
function parseHtmlNode(json, node) {
|
|
35
|
-
|
|
35
|
+
const mitosisNode = {
|
|
36
36
|
'@type': '@builder.io/mitosis/node',
|
|
37
37
|
name: '',
|
|
38
38
|
meta: {},
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseRawMustacheTag = exports.parseMustacheTag = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const astring_1 = require("astring");
|
|
5
|
+
const bindings_1 = require("../../../helpers/bindings");
|
|
6
|
+
const mitosis_node_1 = require("../helpers/mitosis-node");
|
|
7
7
|
function parseMustacheTag(node) {
|
|
8
|
-
|
|
8
|
+
const mitosisNode = (0, mitosis_node_1.createMitosisNode)();
|
|
9
9
|
mitosisNode.name = 'div';
|
|
10
10
|
mitosisNode.bindings['_text'] = (0, bindings_1.createSingleBinding)({
|
|
11
11
|
code: (0, astring_1.generate)(node.expression),
|
|
@@ -14,7 +14,7 @@ function parseMustacheTag(node) {
|
|
|
14
14
|
}
|
|
15
15
|
exports.parseMustacheTag = parseMustacheTag;
|
|
16
16
|
function parseRawMustacheTag(node) {
|
|
17
|
-
|
|
17
|
+
const mitosisNode = (0, mitosis_node_1.createMitosisNode)();
|
|
18
18
|
mitosisNode.name = 'div';
|
|
19
19
|
mitosisNode.bindings.innerHTML = (0, bindings_1.createSingleBinding)({
|
|
20
20
|
code: (0, astring_1.generate)(node.expression),
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseSlot = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const children_1 = require("../helpers/children");
|
|
6
|
+
const mitosis_node_1 = require("../helpers/mitosis-node");
|
|
7
7
|
function parseSlot(json, node) {
|
|
8
8
|
var _a, _b;
|
|
9
|
-
|
|
9
|
+
const mitosisNode = (0, mitosis_node_1.createMitosisNode)();
|
|
10
10
|
mitosisNode.name = 'Slot';
|
|
11
11
|
if (node.attributes.length > 0 &&
|
|
12
12
|
node.attributes[0].value.length > 0 &&
|
|
13
13
|
((_a = node.attributes[0].value[0].data) === null || _a === void 0 ? void 0 : _a.trim().length)) {
|
|
14
|
-
|
|
14
|
+
const slotName = (0, lodash_1.upperFirst)((0, lodash_1.camelCase)((_b = node.attributes[0].value[0]) === null || _b === void 0 ? void 0 : _b.data));
|
|
15
15
|
mitosisNode.properties.name = slotName;
|
|
16
16
|
}
|
|
17
17
|
mitosisNode.children = (0, children_1.parseChildren)(json, node);
|
|
@@ -1,21 +1,14 @@
|
|
|
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.parseText = void 0;
|
|
15
|
-
|
|
4
|
+
const mitosis_node_1 = require("../helpers/mitosis-node");
|
|
16
5
|
function parseText(node) {
|
|
17
|
-
return
|
|
6
|
+
return {
|
|
7
|
+
...(0, mitosis_node_1.createMitosisNode)(),
|
|
8
|
+
name: 'div',
|
|
9
|
+
properties: {
|
|
18
10
|
_text: node.data,
|
|
19
|
-
}
|
|
11
|
+
},
|
|
12
|
+
};
|
|
20
13
|
}
|
|
21
14
|
exports.parseText = parseText;
|
|
@@ -1,58 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.parseSvelte = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
function mapAstToMitosisJson(ast, name, string_, usesTypescript) {
|
|
53
|
-
|
|
54
|
-
if (usesTypescript === void 0) { usesTypescript = false; }
|
|
55
|
-
var json = {
|
|
7
|
+
const lodash_1 = require("lodash");
|
|
8
|
+
const svelte_preprocess_1 = __importDefault(require("svelte-preprocess"));
|
|
9
|
+
const compiler_1 = require("svelte/compiler");
|
|
10
|
+
const css_1 = require("./css");
|
|
11
|
+
const post_process_1 = require("./helpers/post-process");
|
|
12
|
+
const html_1 = require("./html");
|
|
13
|
+
const instance_1 = require("./instance");
|
|
14
|
+
const module_1 = require("./module");
|
|
15
|
+
const typescript_1 = require("./typescript");
|
|
16
|
+
function mapAstToMitosisJson(ast, name, string_ = '', usesTypescript = false) {
|
|
17
|
+
const json = {
|
|
56
18
|
'@type': '@builder.io/mitosis/component',
|
|
57
19
|
inputs: [],
|
|
58
20
|
state: {},
|
|
@@ -67,7 +29,7 @@ function mapAstToMitosisJson(ast, name, string_, usesTypescript) {
|
|
|
67
29
|
context: { get: {}, set: {} },
|
|
68
30
|
subComponents: [],
|
|
69
31
|
meta: {},
|
|
70
|
-
name
|
|
32
|
+
name,
|
|
71
33
|
style: undefined,
|
|
72
34
|
};
|
|
73
35
|
(0, module_1.parseModule)(ast, json);
|
|
@@ -80,29 +42,18 @@ function mapAstToMitosisJson(ast, name, string_, usesTypescript) {
|
|
|
80
42
|
}
|
|
81
43
|
return (0, lodash_1.omit)(json, ['props']);
|
|
82
44
|
}
|
|
83
|
-
|
|
45
|
+
const parseSvelte = async function (string_, path = 'MyComponent.svelte') {
|
|
84
46
|
var _a, _b;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return [4 /*yield*/, (0, compiler_1.preprocess)(string_, [
|
|
93
|
-
(0, svelte_preprocess_1.default)({
|
|
94
|
-
typescript: usesTypescript ? { tsconfigFile: false } : false,
|
|
95
|
-
}),
|
|
96
|
-
], {
|
|
97
|
-
filename: path.split('/').pop(),
|
|
98
|
-
})];
|
|
99
|
-
case 1:
|
|
100
|
-
processedString = _c.sent();
|
|
101
|
-
ast = (0, compiler_1.parse)(processedString.code);
|
|
102
|
-
componentName = (_b = (_a = path.split('/').pop()) === null || _a === void 0 ? void 0 : _a.split('.')[0]) !== null && _b !== void 0 ? _b : 'MyComponent';
|
|
103
|
-
return [2 /*return*/, mapAstToMitosisJson(ast, componentName, string_, usesTypescript)];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
47
|
+
const usesTypescript = (0, typescript_1.isTypeScriptComponent)(string_);
|
|
48
|
+
const processedString = await (0, compiler_1.preprocess)(string_, [
|
|
49
|
+
(0, svelte_preprocess_1.default)({
|
|
50
|
+
typescript: usesTypescript ? { tsconfigFile: false } : false,
|
|
51
|
+
}),
|
|
52
|
+
], {
|
|
53
|
+
filename: path.split('/').pop(),
|
|
106
54
|
});
|
|
55
|
+
const ast = (0, compiler_1.parse)(processedString.code);
|
|
56
|
+
const componentName = (_b = (_a = path.split('/').pop()) === null || _a === void 0 ? void 0 : _a.split('.')[0]) !== null && _b !== void 0 ? _b : 'MyComponent';
|
|
57
|
+
return mapAstToMitosisJson(ast, componentName, string_, usesTypescript);
|
|
107
58
|
};
|
|
108
59
|
exports.parseSvelte = parseSvelte;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseSetContext = exports.parseHasContext = exports.parseGetContext = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const astring_1 = require("astring");
|
|
5
|
+
const string_1 = require("../helpers/string");
|
|
6
6
|
function parseGetContext(json, node) {
|
|
7
7
|
var _a;
|
|
8
8
|
if (node.declarations.length > 0) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const declaration = node.declarations[0];
|
|
10
|
+
const { name } = declaration.id;
|
|
11
|
+
const arguments_ = (_a = declaration.init) === null || _a === void 0 ? void 0 : _a.arguments;
|
|
12
12
|
if (arguments === null || arguments === void 0 ? void 0 : arguments.length) {
|
|
13
|
-
|
|
14
|
-
json.context.get[
|
|
13
|
+
const argument = arguments_[0];
|
|
14
|
+
json.context.get[name] = {
|
|
15
15
|
name: (0, astring_1.generate)(argument),
|
|
16
16
|
path: '',
|
|
17
17
|
};
|
|
@@ -22,18 +22,18 @@ exports.parseGetContext = parseGetContext;
|
|
|
22
22
|
function parseHasContext(json, node) {
|
|
23
23
|
var _a;
|
|
24
24
|
if (node.declarations.length > 0) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const declaration = node.declarations[0];
|
|
26
|
+
const { name } = declaration.id;
|
|
27
|
+
const arguments_ = (_a = declaration.init) === null || _a === void 0 ? void 0 : _a.arguments;
|
|
28
28
|
if (arguments === null || arguments === void 0 ? void 0 : arguments.length) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const argument = arguments_[0];
|
|
30
|
+
const generatedArgument = (0, astring_1.generate)(argument);
|
|
31
31
|
json.context.get[(0, string_1.stripQuotes)(generatedArgument)] = {
|
|
32
32
|
name: generatedArgument,
|
|
33
33
|
path: '',
|
|
34
34
|
};
|
|
35
|
-
json.state[
|
|
36
|
-
code:
|
|
35
|
+
json.state[name] = {
|
|
36
|
+
code: `get ${name}() { return ${(0, string_1.stripQuotes)(generatedArgument)} !== undefined}`,
|
|
37
37
|
type: 'getter',
|
|
38
38
|
};
|
|
39
39
|
}
|
|
@@ -45,10 +45,10 @@ function parseSetContext(json, node) {
|
|
|
45
45
|
if (node.type === 'ExpressionStatement' &&
|
|
46
46
|
node.expression.type === 'CallExpression' &&
|
|
47
47
|
((_a = node.expression.arguments) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
48
|
-
|
|
48
|
+
const hook = node.expression.callee.name;
|
|
49
49
|
if (hook === 'setContext') {
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
const key = node.expression.arguments[0];
|
|
51
|
+
const value = node.expression.arguments[1];
|
|
52
52
|
json.context.set[key.value] = {
|
|
53
53
|
name: (0, astring_1.generate)(key),
|
|
54
54
|
ref: (0, astring_1.generate)(value),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseMemberExpression = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const astring_1 = require("astring");
|
|
5
|
+
const hooks_1 = require("../helpers/hooks");
|
|
6
6
|
function parseMemberExpression(json, node, parent) {
|
|
7
7
|
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Program') {
|
|
8
8
|
(0, hooks_1.addToOnInitHook)(json, (0, astring_1.generate)(node));
|
|
@@ -1,47 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseFunctions = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const types_1 = require("@babel/types");
|
|
5
|
+
const astring_1 = require("astring");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const compiler_1 = require("svelte/compiler");
|
|
8
|
+
const string_1 = require("../helpers/string");
|
|
9
9
|
function parseFunctions(json, node) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const id = node.id;
|
|
11
|
+
let dispatchEventName;
|
|
12
|
+
let code = (0, astring_1.generate)(node);
|
|
13
13
|
(0, compiler_1.walk)(node, {
|
|
14
|
-
enter
|
|
14
|
+
enter(node) {
|
|
15
15
|
switch (node.type) {
|
|
16
16
|
case 'CallExpression': {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const node_ = node;
|
|
18
|
+
const callee = node_.callee;
|
|
19
19
|
if ((callee === null || callee === void 0 ? void 0 : callee.name) === 'dispatch') {
|
|
20
|
-
|
|
21
|
-
dispatchEventName = event_1;
|
|
20
|
+
dispatchEventName = (0, astring_1.generate)(node_.arguments[0]);
|
|
22
21
|
}
|
|
23
22
|
break;
|
|
24
23
|
}
|
|
25
24
|
case 'UpdateExpression': {
|
|
26
|
-
if ((0, types_1.isUpdateExpression)(node)
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
if ((0, types_1.isUpdateExpression)(node)) {
|
|
26
|
+
const expression = node;
|
|
27
|
+
if ((0, types_1.isIdentifier)(expression.argument)) {
|
|
28
|
+
const argument = expression.argument.name;
|
|
29
|
+
if (expression.operator === '++') {
|
|
30
|
+
code = code.replace('++', ` = ${argument} + 1`);
|
|
31
|
+
}
|
|
32
|
+
else if (expression.operator === '--') {
|
|
33
|
+
code = code.replace('--', ` = ${argument} - 1`);
|
|
34
|
+
}
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
break;
|
|
36
38
|
}
|
|
37
39
|
case 'AssignmentExpression': {
|
|
38
|
-
if ((0, types_1.isAssignmentExpression)(node)
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
if ((0, types_1.isAssignmentExpression)(node)) {
|
|
41
|
+
const expression = node;
|
|
42
|
+
if ((0, types_1.isIdentifier)(expression.left)) {
|
|
43
|
+
const argument = expression.left.name;
|
|
44
|
+
if (expression.operator === '+=') {
|
|
45
|
+
code = code.replace('+=', `= ${argument} +`);
|
|
46
|
+
}
|
|
47
|
+
else if (expression.operator === '-=') {
|
|
48
|
+
code = code.replace('-=', `= ${argument} -`);
|
|
49
|
+
}
|
|
45
50
|
}
|
|
46
51
|
}
|
|
47
52
|
break;
|
|
@@ -50,11 +55,11 @@ function parseFunctions(json, node) {
|
|
|
50
55
|
},
|
|
51
56
|
});
|
|
52
57
|
if (dispatchEventName) {
|
|
53
|
-
|
|
54
|
-
code = code.replace(regex,
|
|
58
|
+
const regex = new RegExp(`dispatch\\(${dispatchEventName},?`);
|
|
59
|
+
code = code.replace(regex, `props.on${(0, lodash_1.capitalize)((0, string_1.stripQuotes)(dispatchEventName))}(`);
|
|
55
60
|
}
|
|
56
61
|
json.state[id.name] = {
|
|
57
|
-
code
|
|
62
|
+
code,
|
|
58
63
|
type: 'function',
|
|
59
64
|
};
|
|
60
65
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseAfterUpdate = exports.parseOnDestroy = exports.parseOnMount = void 0;
|
|
4
|
-
|
|
5
|
-
function parseHookBody(node, stripCurlyBraces) {
|
|
4
|
+
const astring_1 = require("astring");
|
|
5
|
+
function parseHookBody(node, stripCurlyBraces = true) {
|
|
6
6
|
var _a;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var code = (0, astring_1.generate)(arguments_[0].body);
|
|
7
|
+
const arguments_ = (_a = node.expression) === null || _a === void 0 ? void 0 : _a.arguments;
|
|
8
|
+
let code = (0, astring_1.generate)(arguments_[0].body);
|
|
10
9
|
if (stripCurlyBraces && (code === null || code === void 0 ? void 0 : code.trim().length) && code[0] === '{' && code[code.length - 1] === '}')
|
|
11
10
|
code = code.slice(1, -1);
|
|
12
11
|
return code;
|
|
@@ -1,38 +1,28 @@
|
|
|
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.parseImports = void 0;
|
|
13
4
|
function parseImports(json, node) {
|
|
14
5
|
var _a;
|
|
15
|
-
|
|
6
|
+
const source = (_a = node.source) === null || _a === void 0 ? void 0 : _a.value;
|
|
16
7
|
if (source === 'svelte')
|
|
17
8
|
return; // Do not import anything from svelte
|
|
18
9
|
// ^ Maybe this should even be stricter and only allow relative imports and alias ones
|
|
19
10
|
// as you can't import any other svelte specific libraries either...Or can we?
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
_a;
|
|
11
|
+
const importSpecifiers = Object.values(node.specifiers).map((index) => {
|
|
12
|
+
return {
|
|
13
|
+
[index.local.name]: index.type === 'ImportDefaultSpecifier' ? 'default' : index.local.name,
|
|
14
|
+
};
|
|
25
15
|
});
|
|
26
|
-
|
|
27
|
-
for (
|
|
28
|
-
var specifier = importSpecifiers_1[_i];
|
|
16
|
+
const imports = {};
|
|
17
|
+
for (const specifier of importSpecifiers) {
|
|
29
18
|
Object.assign(imports, specifier);
|
|
30
19
|
}
|
|
31
20
|
// only add imports which are actually used
|
|
32
21
|
if (Object.keys(imports).length > 0) {
|
|
33
|
-
json.imports =
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
json.imports = [
|
|
23
|
+
...json.imports,
|
|
24
|
+
{ imports, path: source.replace('.svelte', '.lite') },
|
|
25
|
+
];
|
|
36
26
|
// TODO: if import source already exist, combine them
|
|
37
27
|
// e.g. import { lowercase } from 'lodash';
|
|
38
28
|
// e.g. import { uppercase } from 'lodash';
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseInstance = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
const astring_1 = require("astring");
|
|
5
|
+
const compiler_1 = require("svelte/compiler");
|
|
6
|
+
const context_1 = require("./context");
|
|
7
|
+
const expressions_1 = require("./expressions");
|
|
8
|
+
const functions_1 = require("./functions");
|
|
9
|
+
const hooks_1 = require("./hooks");
|
|
10
|
+
const imports_1 = require("./imports");
|
|
11
|
+
const properties_1 = require("./properties");
|
|
12
|
+
const reactive_1 = require("./reactive");
|
|
13
|
+
const references_1 = require("./references");
|
|
14
|
+
const statements_1 = require("./statements");
|
|
15
|
+
const handleImportDeclaration = (json, node) => {
|
|
16
16
|
(0, imports_1.parseImports)(json, node);
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
const handleExportNamedDeclaration = (json, node) => {
|
|
19
19
|
(0, properties_1.parseProperties)(json, node);
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
const handleMemberExpression = (json, node, parent) => {
|
|
22
22
|
(0, expressions_1.parseMemberExpression)(json, node, parent);
|
|
23
23
|
};
|
|
24
|
-
|
|
24
|
+
const handleExpressionStatement = (json, node, parent) => {
|
|
25
25
|
if (node.expression.type === 'CallExpression') {
|
|
26
26
|
if (node.expression.callee.type === 'MemberExpression') {
|
|
27
27
|
handleMemberExpression(json, node, parent);
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
const callee = node.expression.callee;
|
|
31
31
|
switch (callee.name) {
|
|
32
32
|
case 'setContext': {
|
|
33
33
|
(0, context_1.parseSetContext)(json, node);
|
|
@@ -54,12 +54,12 @@ var handleExpressionStatement = function (json, node, parent) {
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
|
|
57
|
+
const handleFunctionDeclaration = (json, node) => {
|
|
58
58
|
(0, functions_1.parseFunctions)(json, node);
|
|
59
59
|
};
|
|
60
|
-
|
|
60
|
+
const handleVariableDeclaration = (json, node) => {
|
|
61
61
|
var _a, _b, _c, _d;
|
|
62
|
-
|
|
62
|
+
const init = (_a = node.declarations[0]) === null || _a === void 0 ? void 0 : _a.init;
|
|
63
63
|
if ((init === null || init === void 0 ? void 0 : init.type) === 'CallExpression' && ((_b = init === null || init === void 0 ? void 0 : init.callee) === null || _b === void 0 ? void 0 : _b.name) === 'getContext') {
|
|
64
64
|
(0, context_1.parseGetContext)(json, node);
|
|
65
65
|
}
|
|
@@ -75,19 +75,19 @@ var handleVariableDeclaration = function (json, node) {
|
|
|
75
75
|
(0, references_1.parseReferences)(json, node);
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
-
|
|
78
|
+
const handleLabeledStatement = (json, node) => {
|
|
79
79
|
if (node.label.name === '$') {
|
|
80
80
|
(0, reactive_1.parseReactive)(json, node);
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
-
|
|
83
|
+
const handleStatement = (json, node, parent) => {
|
|
84
84
|
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Program') {
|
|
85
85
|
(0, statements_1.parseStatementAtProgramLevel)(json, node);
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
function parseInstance(ast, json) {
|
|
89
89
|
(0, compiler_1.walk)(ast.instance, {
|
|
90
|
-
enter
|
|
90
|
+
enter(node, parent) {
|
|
91
91
|
switch (node.type) {
|
|
92
92
|
case 'ImportDeclaration':
|
|
93
93
|
handleImportDeclaration(json, node);
|