@builder.io/mitosis 0.0.56-98 → 0.0.57
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/__tests__/data/blocks/content-slot-jsx.raw.jsx +4 -1
- package/dist/src/__tests__/data/blocks/form.raw.jsx +5 -5
- package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.d.ts +5 -1
- package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.jsx +3 -3
- package/dist/src/__tests__/data/jsx-json.spec.d.ts +2 -0
- package/dist/src/__tests__/data/jsx-json.spec.js +10226 -0
- package/dist/src/__tests__/shared.d.ts +7 -2
- package/dist/src/__tests__/shared.js +66 -9
- package/dist/src/constants/method-literal-prefix.d.ts +0 -1
- package/dist/src/constants/method-literal-prefix.js +0 -3
- package/dist/src/generators/angular.d.ts +2 -2
- package/dist/src/generators/angular.js +5 -3
- package/dist/src/generators/builder.d.ts +4 -11
- package/dist/src/generators/builder.js +3 -2
- package/dist/src/generators/context/svelte.d.ts +3 -0
- package/dist/src/generators/context/svelte.js +3 -0
- package/dist/src/generators/helpers/functions.d.ts +2 -0
- package/dist/src/generators/helpers/functions.js +28 -0
- package/dist/src/generators/html.d.ts +3 -3
- package/dist/src/generators/html.js +9 -7
- package/dist/src/generators/liquid.d.ts +2 -2
- package/dist/src/generators/liquid.js +4 -4
- package/dist/src/generators/lit/generate.d.ts +2 -2
- package/dist/src/generators/lit/generate.js +14 -6
- package/dist/src/generators/marko/generate.d.ts +2 -2
- package/dist/src/generators/marko/generate.js +10 -8
- package/dist/src/generators/mitosis.d.ts +3 -4
- package/dist/src/generators/mitosis.js +3 -2
- package/dist/src/generators/qwik/component-generator.d.ts +2 -2
- package/dist/src/generators/qwik/component-generator.js +49 -55
- package/dist/src/generators/qwik/component.d.ts +0 -1
- package/dist/src/generators/qwik/component.js +22 -19
- package/dist/src/generators/qwik/directives.d.ts +1 -0
- package/dist/src/generators/qwik/directives.js +11 -14
- package/dist/src/generators/qwik/jsx.d.ts +1 -1
- package/dist/src/generators/qwik/jsx.js +9 -5
- package/dist/src/generators/qwik/src-generator.js +9 -3
- package/dist/src/generators/qwik/stable-serialize.d.ts +6 -0
- package/dist/src/generators/qwik/stable-serialize.js +51 -0
- package/dist/src/generators/react/generator.d.ts +6 -0
- package/dist/src/generators/{react.js → react/generator.js} +58 -150
- package/dist/src/generators/react/helpers.d.ts +2 -0
- package/dist/src/generators/react/helpers.js +14 -0
- package/dist/src/generators/react/index.d.ts +2 -0
- package/dist/src/generators/react/index.js +18 -0
- package/dist/src/generators/react/state.d.ts +9 -0
- package/dist/src/generators/react/state.js +107 -0
- package/dist/src/generators/react/types.d.ts +10 -0
- package/dist/src/{types/string-map.js → generators/react/types.js} +0 -0
- package/dist/src/generators/react-native.d.ts +2 -2
- package/dist/src/generators/solid/index.d.ts +3 -0
- package/dist/src/generators/{solid.js → solid/index.js} +80 -40
- package/dist/src/generators/solid/state.d.ts +19 -0
- package/dist/src/generators/solid/state.js +144 -0
- package/dist/src/generators/solid/types.d.ts +6 -0
- package/dist/src/generators/solid/types.js +2 -0
- package/dist/src/generators/stencil/generate.d.ts +2 -2
- package/dist/src/generators/stencil/generate.js +5 -2
- package/dist/src/generators/svelte.d.ts +6 -7
- package/dist/src/generators/svelte.js +43 -40
- package/dist/src/generators/swift-ui.d.ts +3 -5
- package/dist/src/generators/swift-ui.js +3 -2
- package/dist/src/generators/template.d.ts +2 -2
- package/dist/src/generators/template.js +3 -2
- package/dist/src/generators/vue.d.ts +5 -3
- package/dist/src/generators/vue.js +256 -113
- package/dist/src/helpers/babel-transform.d.ts +3 -1
- package/dist/src/helpers/babel-transform.js +52 -56
- package/dist/src/helpers/get-bindings.js +3 -5
- package/dist/src/helpers/get-props.js +14 -1
- package/dist/src/helpers/get-state-object-string.js +24 -21
- package/dist/src/helpers/getters-to-functions.js +1 -11
- package/dist/src/helpers/map-refs.js +25 -25
- package/dist/src/helpers/nodes/for.d.ts +4 -0
- package/dist/src/helpers/nodes/for.js +13 -0
- package/dist/src/helpers/nullable.d.ts +2 -0
- package/dist/src/helpers/nullable.js +7 -0
- package/dist/src/helpers/patterns.d.ts +2 -0
- package/dist/src/helpers/patterns.js +5 -1
- package/dist/src/helpers/render-imports.js +3 -3
- package/dist/src/helpers/replace-identifiers.d.ts +5 -0
- package/dist/src/helpers/{replace-idenifiers.js → replace-identifiers.js} +2 -1
- package/dist/src/helpers/slots.d.ts +2 -0
- package/dist/src/helpers/slots.js +15 -1
- package/dist/src/helpers/state.d.ts +0 -2
- package/dist/src/helpers/state.js +1 -10
- package/dist/src/helpers/strip-state-and-props-refs.d.ts +1 -1
- package/dist/src/helpers/strip-state-and-props-refs.js +43 -31
- package/dist/src/helpers/styles/helpers.d.ts +1 -0
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -2
- package/dist/src/parsers/angular.js +2 -2
- package/dist/src/parsers/builder.d.ts +2 -2
- package/dist/src/parsers/builder.js +61 -43
- package/dist/src/parsers/constants/outdated-prefixes.d.ts +10 -0
- package/dist/src/parsers/constants/outdated-prefixes.js +13 -0
- package/dist/src/parsers/context.js +2 -2
- package/dist/src/parsers/helpers/state.d.ts +3 -0
- package/dist/src/parsers/helpers/state.js +30 -0
- package/dist/src/parsers/jsx/component-types.d.ts +1 -1
- package/dist/src/parsers/jsx/component-types.js +15 -2
- package/dist/src/parsers/jsx/context.js +1 -1
- package/dist/src/parsers/jsx/element-parser.d.ts +6 -0
- package/dist/src/parsers/jsx/element-parser.js +243 -0
- package/dist/src/parsers/jsx/exports.d.ts +3 -0
- package/dist/src/parsers/jsx/exports.js +78 -0
- package/dist/src/parsers/jsx/function-parser.d.ts +7 -0
- package/dist/src/parsers/jsx/function-parser.js +291 -0
- package/dist/src/parsers/jsx/helpers.d.ts +2 -0
- package/dist/src/parsers/jsx/helpers.js +30 -1
- package/dist/src/parsers/jsx/imports.d.ts +7 -0
- package/dist/src/parsers/jsx/imports.js +65 -0
- package/dist/src/parsers/jsx/index.d.ts +1 -1
- package/dist/src/parsers/jsx/index.js +1 -2
- package/dist/src/parsers/jsx/jsx.js +29 -516
- package/dist/src/parsers/jsx/state.d.ts +2 -3
- package/dist/src/parsers/jsx/state.js +15 -22
- package/dist/src/plugins/compile-away-builder-components.js +6 -0
- package/dist/src/symbols/symbol-processor.js +3 -0
- package/dist/src/targets.d.ts +21 -28
- package/dist/src/targets.js +2 -2
- package/dist/src/types/config.d.ts +11 -1
- package/dist/src/types/mitosis-component.d.ts +12 -6
- package/dist/src/types/mitosis-component.js +11 -0
- package/dist/src/types/mitosis-context.d.ts +2 -2
- package/dist/src/types/mitosis-node.d.ts +14 -5
- package/dist/src/types/mitosis-node.js +3 -0
- package/dist/src/types/transpiler.d.ts +6 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/dist/src/__tests__/angular.test.d.ts +0 -1
- package/dist/src/__tests__/angular.test.js +0 -10
- package/dist/src/__tests__/builder.test.d.ts +0 -1
- package/dist/src/__tests__/builder.test.js +0 -235
- package/dist/src/__tests__/context.test.d.ts +0 -1
- package/dist/src/__tests__/context.test.js +0 -35
- package/dist/src/__tests__/data/blocks/builder-render-block.raw.d.ts +0 -6
- package/dist/src/__tests__/data/blocks/builder-render-block.raw.jsx +0 -90
- package/dist/src/__tests__/data/blocks/builder-render-content.raw.d.ts +0 -10
- package/dist/src/__tests__/data/blocks/builder-render-content.raw.jsx +0 -69
- package/dist/src/__tests__/hash-code.test.d.ts +0 -1
- package/dist/src/__tests__/hash-code.test.js +0 -11
- package/dist/src/__tests__/html.test.d.ts +0 -1
- package/dist/src/__tests__/html.test.js +0 -7
- package/dist/src/__tests__/liquid.test.d.ts +0 -1
- package/dist/src/__tests__/liquid.test.js +0 -7
- package/dist/src/__tests__/lit.test.d.ts +0 -1
- package/dist/src/__tests__/lit.test.js +0 -7
- package/dist/src/__tests__/marko.test.d.ts +0 -1
- package/dist/src/__tests__/marko.test.js +0 -14
- package/dist/src/__tests__/parse-jsx.test.d.ts +0 -1
- package/dist/src/__tests__/parse-jsx.test.js +0 -37
- package/dist/src/__tests__/qwik/convert-method-to-function.test.d.ts +0 -1
- package/dist/src/__tests__/qwik/convert-method-to-function.test.js +0 -37
- package/dist/src/__tests__/qwik/src-generator.test.d.ts +0 -1
- package/dist/src/__tests__/qwik/src-generator.test.js +0 -65
- package/dist/src/__tests__/qwik.directive.test.d.ts +0 -1
- package/dist/src/__tests__/qwik.directive.test.js +0 -108
- package/dist/src/__tests__/qwik.test.d.ts +0 -1
- package/dist/src/__tests__/qwik.test.js +0 -465
- package/dist/src/__tests__/react-native.test.d.ts +0 -1
- package/dist/src/__tests__/react-native.test.js +0 -7
- package/dist/src/__tests__/react.test.d.ts +0 -1
- package/dist/src/__tests__/react.test.js +0 -20
- package/dist/src/__tests__/solid.test.d.ts +0 -1
- package/dist/src/__tests__/solid.test.js +0 -10
- package/dist/src/__tests__/stencil.test.d.ts +0 -1
- package/dist/src/__tests__/stencil.test.js +0 -7
- package/dist/src/__tests__/styles.test.d.ts +0 -1
- package/dist/src/__tests__/styles.test.js +0 -23
- package/dist/src/__tests__/svelte.test.d.ts +0 -1
- package/dist/src/__tests__/svelte.test.js +0 -7
- package/dist/src/__tests__/vue.test.d.ts +0 -1
- package/dist/src/__tests__/vue.test.js +0 -7
- package/dist/src/__tests__/webcomponent.test.d.ts +0 -1
- package/dist/src/__tests__/webcomponent.test.js +0 -15
- package/dist/src/constants/function-literal-prefix.d.ts +0 -1
- package/dist/src/constants/function-literal-prefix.js +0 -4
- package/dist/src/generators/qwik/convertMethodToFunction.d.ts +0 -1
- package/dist/src/generators/qwik/convertMethodToFunction.js +0 -161
- package/dist/src/generators/react.d.ts +0 -14
- package/dist/src/generators/solid.d.ts +0 -5
- package/dist/src/helpers/babel-transform.test.d.ts +0 -1
- package/dist/src/helpers/babel-transform.test.js +0 -7
- package/dist/src/helpers/generic-format.test.d.ts +0 -1
- package/dist/src/helpers/generic-format.test.js +0 -8
- package/dist/src/helpers/map-to-attributes.d.ts +0 -2
- package/dist/src/helpers/map-to-attributes.js +0 -19
- package/dist/src/helpers/map-to-css.d.ts +0 -2
- package/dist/src/helpers/map-to-css.js +0 -16
- package/dist/src/helpers/parse-reactive-script.d.ts +0 -7
- package/dist/src/helpers/parse-reactive-script.js +0 -87
- package/dist/src/helpers/remove-surrounding-block.test.d.ts +0 -1
- package/dist/src/helpers/remove-surrounding-block.test.js +0 -9
- package/dist/src/helpers/render-imports.test.d.ts +0 -1
- package/dist/src/helpers/render-imports.test.js +0 -33
- package/dist/src/helpers/replace-idenifiers.d.ts +0 -1
- package/dist/src/helpers/styles/collect-css.test.d.ts +0 -1
- package/dist/src/helpers/styles/collect-css.test.js +0 -18
- package/dist/src/parsers/html.d.ts +0 -0
- package/dist/src/parsers/html.js +0 -2
- package/dist/src/parsers/liquid.d.ts +0 -70
- package/dist/src/parsers/liquid.js +0 -2538
- package/dist/src/types/string-map.d.ts +0 -3
- package/dist/test/qwik/Accordion/high.jsx +0 -0
- package/dist/test/qwik/Accordion/low.jsx +0 -240
- package/dist/test/qwik/Accordion/med.jsx +0 -4
- package/dist/test/qwik/For/high.jsx +0 -0
- package/dist/test/qwik/For/low.jsx +0 -52
- package/dist/test/qwik/For/med.jsx +0 -4
- package/dist/test/qwik/Image/high.js +0 -9
- package/dist/test/qwik/Image/low.js +0 -0
- package/dist/test/qwik/Image/med.js +0 -155
- package/dist/test/qwik/Image.slow/high.js +0 -9
- package/dist/test/qwik/Image.slow/low.js +0 -0
- package/dist/test/qwik/Image.slow/med.js +0 -155
- package/dist/test/qwik/bindings/high.cjs +0 -0
- package/dist/test/qwik/bindings/low.cjs +0 -45
- package/dist/test/qwik/bindings/med.cjs +0 -3
- package/dist/test/qwik/button/high.js +0 -3
- package/dist/test/qwik/button/low.js +0 -25
- package/dist/test/qwik/button/med.js +0 -31
- package/dist/test/qwik/component/bindings/high.jsx +0 -0
- package/dist/test/qwik/component/bindings/low.jsx +0 -104
- package/dist/test/qwik/component/bindings/med.jsx +0 -7
- package/dist/test/qwik/component/component/inputs/high.cjsx +0 -9
- package/dist/test/qwik/component/component/inputs/low.cjsx +0 -0
- package/dist/test/qwik/component/component/inputs/med.cjsx +0 -68
- package/dist/test/qwik/for-loop.bindings/high.cjs +0 -0
- package/dist/test/qwik/for-loop.bindings/low.cjs +0 -56
- package/dist/test/qwik/for-loop.bindings/med.cjs +0 -5
- package/dist/test/qwik/hello_world/stylesheet/high.jsx +0 -0
- package/dist/test/qwik/hello_world/stylesheet/low.jsx +0 -26
- package/dist/test/qwik/hello_world/stylesheet/med.jsx +0 -4
- package/dist/test/qwik/mount/high.cjs +0 -0
- package/dist/test/qwik/mount/low.cjs +0 -47
- package/dist/test/qwik/mount/med.cjs +0 -3
- package/dist/test/qwik/page-with-symbol/high.js +0 -0
- package/dist/test/qwik/page-with-symbol/low.js +0 -33
- package/dist/test/qwik/page-with-symbol/med.js +0 -4
- package/dist/test/qwik/show-hide/high.jsx +0 -9
- package/dist/test/qwik/show-hide/low.jsx +0 -0
- package/dist/test/qwik/show-hide/med.jsx +0 -181
- package/dist/test/qwik/svg/high.js +0 -0
- package/dist/test/qwik/svg/low.js +0 -30
- package/dist/test/qwik/svg/med.js +0 -4
- package/dist/test/qwik/todo/Todo.cjs/high.cjs +0 -19
- package/dist/test/qwik/todo/Todo.cjs/low.cjs +0 -0
- package/dist/test/qwik/todo/Todo.cjs/med.cjs +0 -51
- package/dist/test/qwik/todo/Todo.js/high.js +0 -19
- package/dist/test/qwik/todo/Todo.js/low.js +0 -0
- package/dist/test/qwik/todo/Todo.js/med.js +0 -47
- package/dist/test/qwik/todo/Todo.tsx/high.tsx +0 -19
- package/dist/test/qwik/todo/Todo.tsx/low.tsx +0 -0
- package/dist/test/qwik/todo/Todo.tsx/med.tsx +0 -43
- package/dist/test/qwik/todos/Todo.tsx/high.tsx +0 -7
- package/dist/test/qwik/todos/Todo.tsx/low.tsx +0 -32
- package/dist/test/qwik/todos/Todo.tsx/med.tsx +0 -4
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -26,7 +26,6 @@ export declare const useDefaultProps: <T = {
|
|
|
26
26
|
export * from './parsers/jsx';
|
|
27
27
|
export * from './parsers/builder';
|
|
28
28
|
export * from './parsers/angular';
|
|
29
|
-
export * from './parsers/liquid';
|
|
30
29
|
export * from './parsers/context';
|
|
31
30
|
export * from './generators/vue';
|
|
32
31
|
export * from './generators/angular';
|
|
@@ -50,7 +49,6 @@ export * from './generators/template';
|
|
|
50
49
|
export * from './generators/swift-ui';
|
|
51
50
|
export * from './generators/lit';
|
|
52
51
|
export * from './generators/react-native';
|
|
53
|
-
export * from './helpers/parse-reactive-script';
|
|
54
52
|
export * from './helpers/is-mitosis-node';
|
|
55
53
|
export * from './types/mitosis-node';
|
|
56
54
|
export * from './types/mitosis-component';
|
package/dist/src/index.js
CHANGED
|
@@ -64,7 +64,6 @@ exports.useDefaultProps = useDefaultProps;
|
|
|
64
64
|
__exportStar(require("./parsers/jsx"), exports);
|
|
65
65
|
__exportStar(require("./parsers/builder"), exports);
|
|
66
66
|
__exportStar(require("./parsers/angular"), exports);
|
|
67
|
-
__exportStar(require("./parsers/liquid"), exports);
|
|
68
67
|
__exportStar(require("./parsers/context"), exports);
|
|
69
68
|
__exportStar(require("./generators/vue"), exports);
|
|
70
69
|
__exportStar(require("./generators/angular"), exports);
|
|
@@ -88,7 +87,6 @@ __exportStar(require("./generators/template"), exports);
|
|
|
88
87
|
__exportStar(require("./generators/swift-ui"), exports);
|
|
89
88
|
__exportStar(require("./generators/lit"), exports);
|
|
90
89
|
__exportStar(require("./generators/react-native"), exports);
|
|
91
|
-
__exportStar(require("./helpers/parse-reactive-script"), exports);
|
|
92
90
|
__exportStar(require("./helpers/is-mitosis-node"), exports);
|
|
93
91
|
__exportStar(require("./types/mitosis-node"), exports);
|
|
94
92
|
__exportStar(require("./types/mitosis-component"), exports);
|
|
@@ -63,8 +63,8 @@ var angularTemplateNodeToMitosisNode = function (node, options) {
|
|
|
63
63
|
bindings: {
|
|
64
64
|
each: { code: transformBinding(expression, options) },
|
|
65
65
|
},
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
scope: {
|
|
67
|
+
forName: itemName,
|
|
68
68
|
},
|
|
69
69
|
children: [angularTemplateNodeToMitosisNode((0, lodash_1.omit)(node, 'templateAttrs'), options)],
|
|
70
70
|
});
|
|
@@ -40,7 +40,7 @@ export declare const builderContentToMitosisComponent: (builderContent: BuilderC
|
|
|
40
40
|
useMetadata?: JSONObject | undefined;
|
|
41
41
|
};
|
|
42
42
|
inputs: import("..").MitosisComponentInput[];
|
|
43
|
-
state: import("
|
|
43
|
+
state: import("..").MitosisState;
|
|
44
44
|
context: {
|
|
45
45
|
get: import("..").ContextGet;
|
|
46
46
|
set: import("..").ContextSet;
|
|
@@ -74,7 +74,7 @@ export declare const builderContentToMitosisComponent: (builderContent: BuilderC
|
|
|
74
74
|
useMetadata?: JSONObject | undefined;
|
|
75
75
|
};
|
|
76
76
|
inputs: import("..").MitosisComponentInput[];
|
|
77
|
-
state: import("
|
|
77
|
+
state: import("..").MitosisState;
|
|
78
78
|
context: {
|
|
79
79
|
get: import("..").ContextGet;
|
|
80
80
|
set: import("..").ContextSet;
|
|
@@ -51,7 +51,7 @@ var create_mitosis_node_1 = require("../helpers/create-mitosis-node");
|
|
|
51
51
|
var jsx_1 = require("./jsx");
|
|
52
52
|
var parsers_1 = require("../helpers/parsers");
|
|
53
53
|
var __1 = require("..");
|
|
54
|
-
var state_1 = require("
|
|
54
|
+
var state_1 = require("./helpers/state");
|
|
55
55
|
// Omit some superflous styles that can come from Builder's web importer
|
|
56
56
|
var styleOmitList = [
|
|
57
57
|
'backgroundRepeatX',
|
|
@@ -299,8 +299,8 @@ var componentMappers = __assign(__assign({ Symbol: function (block, options) {
|
|
|
299
299
|
bindings: {
|
|
300
300
|
each: { code: "state.".concat(block.component.options.repeat.collection) },
|
|
301
301
|
},
|
|
302
|
-
|
|
303
|
-
|
|
302
|
+
scope: {
|
|
303
|
+
forName: block.component.options.repeat.itemName,
|
|
304
304
|
},
|
|
305
305
|
children: (block.children || []).map(function (child) { return (0, exports.builderElementToMitosisNode)(child, options); }),
|
|
306
306
|
});
|
|
@@ -380,27 +380,29 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
|
|
|
380
380
|
// Special builder properties
|
|
381
381
|
// TODO: support hide and repeat
|
|
382
382
|
var blockBindings = getBlockBindings(block, options);
|
|
383
|
-
var
|
|
384
|
-
if (
|
|
383
|
+
var code = undefined;
|
|
384
|
+
if (blockBindings.show) {
|
|
385
|
+
code = wrapBindingIfNeeded(blockBindings.show, options);
|
|
386
|
+
}
|
|
387
|
+
else if (blockBindings.hide) {
|
|
388
|
+
code = "!(".concat(wrapBindingIfNeeded(blockBindings.hide, options), ")");
|
|
389
|
+
}
|
|
390
|
+
if (code) {
|
|
385
391
|
var isFragment = ((_c = block.component) === null || _c === void 0 ? void 0 : _c.name) === 'Fragment';
|
|
386
392
|
// TODO: handle having other things, like a repeat too
|
|
387
393
|
if (isFragment) {
|
|
388
394
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
389
395
|
name: 'Show',
|
|
390
|
-
bindings: {
|
|
391
|
-
when: { code: wrapBindingIfNeeded(showBinding, options) },
|
|
392
|
-
},
|
|
396
|
+
bindings: { when: { code: code } },
|
|
393
397
|
children: ((_d = block.children) === null || _d === void 0 ? void 0 : _d.map(function (child) { return (0, exports.builderElementToMitosisNode)(child, options); })) || [],
|
|
394
398
|
});
|
|
395
399
|
}
|
|
396
400
|
else {
|
|
397
401
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
398
402
|
name: 'Show',
|
|
399
|
-
bindings: {
|
|
400
|
-
when: { code: wrapBindingIfNeeded(showBinding, options) },
|
|
401
|
-
},
|
|
403
|
+
bindings: { when: { code: code } },
|
|
402
404
|
children: [
|
|
403
|
-
(0, exports.builderElementToMitosisNode)(__assign(__assign({}, block), { code: __assign(__assign({}, block.code), { bindings: (0, lodash_1.omit)(blockBindings, 'show') }), bindings: (0, lodash_1.omit)(blockBindings, 'show') }), options),
|
|
405
|
+
(0, exports.builderElementToMitosisNode)(__assign(__assign({}, block), { code: __assign(__assign({}, block.code), { bindings: (0, lodash_1.omit)(blockBindings, 'show', 'hide') }), bindings: (0, lodash_1.omit)(blockBindings, 'show', 'hide') }), options),
|
|
404
406
|
],
|
|
405
407
|
});
|
|
406
408
|
}
|
|
@@ -417,8 +419,8 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
|
|
|
417
419
|
code: wrapBindingIfNeeded((_g = block.repeat) === null || _g === void 0 ? void 0 : _g.collection, options),
|
|
418
420
|
},
|
|
419
421
|
},
|
|
420
|
-
|
|
421
|
-
|
|
422
|
+
scope: {
|
|
423
|
+
forName: ((_h = block.repeat) === null || _h === void 0 ? void 0 : _h.itemName) || 'item',
|
|
422
424
|
},
|
|
423
425
|
children: ((_j = block.children) === null || _j === void 0 ? void 0 : _j.map(function (child) { return (0, exports.builderElementToMitosisNode)(child, options); })) || [],
|
|
424
426
|
});
|
|
@@ -434,8 +436,8 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
|
|
|
434
436
|
code: wrapBindingIfNeeded((_m = block.repeat) === null || _m === void 0 ? void 0 : _m.collection, options),
|
|
435
437
|
},
|
|
436
438
|
},
|
|
437
|
-
|
|
438
|
-
|
|
439
|
+
scope: {
|
|
440
|
+
forName: ((_o = block.repeat) === null || _o === void 0 ? void 0 : _o.itemName) || 'item',
|
|
439
441
|
},
|
|
440
442
|
children: [(0, exports.builderElementToMitosisNode)((0, lodash_1.omit)(useBlock, 'repeat'), options)],
|
|
441
443
|
});
|
|
@@ -465,9 +467,9 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
|
|
|
465
467
|
}
|
|
466
468
|
}
|
|
467
469
|
}
|
|
468
|
-
var properties = __assign(__assign({}, block.properties), (options.includeBuilderExtras && (_a = {},
|
|
470
|
+
var properties = __assign(__assign(__assign({}, block.properties), (options.includeBuilderExtras && (_a = {},
|
|
469
471
|
_a['builder-id'] = block.id,
|
|
470
|
-
_a)));
|
|
472
|
+
_a))), (options.includeBuilderExtras && getBuilderPropsForSymbol(block)));
|
|
471
473
|
if (block.layerName) {
|
|
472
474
|
properties.$name = block.layerName;
|
|
473
475
|
}
|
|
@@ -502,11 +504,7 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
|
|
|
502
504
|
name: ((_r = (_q = block.component) === null || _q === void 0 ? void 0 : _q.name) === null || _r === void 0 ? void 0 : _r.replace(/[^a-z0-9]/gi, '')) ||
|
|
503
505
|
block.tagName ||
|
|
504
506
|
(block.linkUrl ? 'a' : 'div'),
|
|
505
|
-
properties: __assign(__assign({}, (block.component
|
|
506
|
-
? {
|
|
507
|
-
$tagName: block.tagName,
|
|
508
|
-
}
|
|
509
|
-
: null)), properties),
|
|
507
|
+
properties: __assign(__assign(__assign({}, (block.component && { $tagName: block.tagName })), (block.class && { class: block.class })), properties),
|
|
510
508
|
bindings: __assign(__assign(__assign(__assign({}, bindings), actionBindings), (styleString && {
|
|
511
509
|
style: { code: styleString },
|
|
512
510
|
})), (css &&
|
|
@@ -530,6 +528,17 @@ var builderElementToMitosisNode = function (block, options, _internalOptions) {
|
|
|
530
528
|
return node;
|
|
531
529
|
};
|
|
532
530
|
exports.builderElementToMitosisNode = builderElementToMitosisNode;
|
|
531
|
+
var getBuilderPropsForSymbol = function (block) {
|
|
532
|
+
var _a, _b;
|
|
533
|
+
if (((_a = block.children) === null || _a === void 0 ? void 0 : _a.length) === 1) {
|
|
534
|
+
var child = block.children[0];
|
|
535
|
+
var builderContentId = (_b = child.properties) === null || _b === void 0 ? void 0 : _b['builder-content-id'];
|
|
536
|
+
if (builderContentId) {
|
|
537
|
+
return { 'builder-content-id': builderContentId };
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return undefined;
|
|
541
|
+
};
|
|
533
542
|
var getHooks = function (content) {
|
|
534
543
|
var _a, _b;
|
|
535
544
|
var code = convertExportDefaultToReturn(((_a = content.data) === null || _a === void 0 ? void 0 : _a.tsCode) || ((_b = content.data) === null || _b === void 0 ? void 0 : _b.jsCode) || '');
|
|
@@ -589,19 +598,30 @@ function extractStateHook(code) {
|
|
|
589
598
|
}
|
|
590
599
|
exports.extractStateHook = extractStateHook;
|
|
591
600
|
function convertExportDefaultToReturn(code) {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
var
|
|
597
|
-
|
|
598
|
-
if (types.
|
|
599
|
-
types.
|
|
600
|
-
|
|
601
|
+
try {
|
|
602
|
+
var types = babel.types;
|
|
603
|
+
var body = (0, parsers_1.parseCode)(code);
|
|
604
|
+
var newBody = body.slice();
|
|
605
|
+
for (var i = 0; i < body.length; i++) {
|
|
606
|
+
var statement = body[i];
|
|
607
|
+
if (types.isExportDefaultDeclaration(statement)) {
|
|
608
|
+
if (types.isCallExpression(statement.declaration) ||
|
|
609
|
+
types.isExpression(statement.declaration)) {
|
|
610
|
+
newBody[i] = types.returnStatement(statement.declaration);
|
|
611
|
+
}
|
|
601
612
|
}
|
|
602
613
|
}
|
|
614
|
+
return (0, generator_1.default)(types.program(newBody)).code || '';
|
|
615
|
+
}
|
|
616
|
+
catch (e) {
|
|
617
|
+
var error = e;
|
|
618
|
+
if (error.code === 'BABEL_PARSE_ERROR') {
|
|
619
|
+
return code;
|
|
620
|
+
}
|
|
621
|
+
else {
|
|
622
|
+
throw e;
|
|
623
|
+
}
|
|
603
624
|
}
|
|
604
|
-
return (0, generator_1.default)(types.program(newBody)).code || '';
|
|
605
625
|
}
|
|
606
626
|
exports.convertExportDefaultToReturn = convertExportDefaultToReturn;
|
|
607
627
|
// TODO: maybe this should be part of the builder -> Mitosis part
|
|
@@ -650,7 +670,7 @@ var isBuilderElement = function (el) {
|
|
|
650
670
|
};
|
|
651
671
|
exports.isBuilderElement = isBuilderElement;
|
|
652
672
|
var builderContentPartToMitosisComponent = function (builderContent, options) {
|
|
653
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
673
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
654
674
|
if (options === void 0) { options = {}; }
|
|
655
675
|
builderContent = (0, fast_clone_1.fastClone)(builderContent);
|
|
656
676
|
(0, traverse_1.default)(builderContent).forEach(function (elem) {
|
|
@@ -679,24 +699,22 @@ var builderContentPartToMitosisComponent = function (builderContent, options) {
|
|
|
679
699
|
}
|
|
680
700
|
}
|
|
681
701
|
});
|
|
682
|
-
var
|
|
702
|
+
var _k = extractStateHook(((_a = builderContent === null || builderContent === void 0 ? void 0 : builderContent.data) === null || _a === void 0 ? void 0 : _a.tsCode) || ((_b = builderContent === null || builderContent === void 0 ? void 0 : builderContent.data) === null || _b === void 0 ? void 0 : _b.jsCode) || ''), state = _k.state, code = _k.code;
|
|
683
703
|
var customCode = convertExportDefaultToReturn(code);
|
|
684
704
|
var parsed = getHooks(builderContent);
|
|
685
705
|
var componentJson = (0, create_mitosis_component_1.createMitosisComponent)({
|
|
686
|
-
meta: {
|
|
687
|
-
useMetadata: {
|
|
706
|
+
meta: __assign({ useMetadata: {
|
|
688
707
|
httpRequests: (_c = builderContent.data) === null || _c === void 0 ? void 0 : _c.httpRequests,
|
|
689
|
-
},
|
|
690
|
-
|
|
691
|
-
inputs: (_e = (_d = builderContent.data) === null || _d === void 0 ? void 0 : _d.inputs) === null || _e === void 0 ? void 0 : _e.map(function (input) { return ({
|
|
708
|
+
} }, (((_d = builderContent.data) === null || _d === void 0 ? void 0 : _d.cssCode) && { cssCode: builderContent.data.cssCode })),
|
|
709
|
+
inputs: (_f = (_e = builderContent.data) === null || _e === void 0 ? void 0 : _e.inputs) === null || _f === void 0 ? void 0 : _f.map(function (input) { return ({
|
|
692
710
|
name: input.name,
|
|
693
711
|
defaultValue: input.defaultValue,
|
|
694
712
|
}); }),
|
|
695
|
-
state: (parsed === null || parsed === void 0 ? void 0 : parsed.state) || __assign(__assign({}, state), (0, state_1.mapJsonObjectToStateValue)((
|
|
696
|
-
hooks: __assign({}, ((((
|
|
713
|
+
state: (parsed === null || parsed === void 0 ? void 0 : parsed.state) || __assign(__assign({}, state), (0, state_1.mapJsonObjectToStateValue)((_g = builderContent.data) === null || _g === void 0 ? void 0 : _g.state)),
|
|
714
|
+
hooks: __assign({}, ((((_h = parsed === null || parsed === void 0 ? void 0 : parsed.hooks.onMount) === null || _h === void 0 ? void 0 : _h.code) || (customCode && { code: customCode })) && {
|
|
697
715
|
onMount: (parsed === null || parsed === void 0 ? void 0 : parsed.hooks.onMount) || { code: customCode },
|
|
698
716
|
})),
|
|
699
|
-
children: (((
|
|
717
|
+
children: (((_j = builderContent.data) === null || _j === void 0 ? void 0 : _j.blocks) || [])
|
|
700
718
|
.filter(function (item) {
|
|
701
719
|
var _a, _b;
|
|
702
720
|
if ((_b = (_a = item.properties) === null || _a === void 0 ? void 0 : _a.src) === null || _b === void 0 ? void 0 : _b.includes('/api/v1/pixel')) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DO NOT USE THIS PREFIX. It's only used for legacy purposes, within a very small subset of logic in the JSX & Builder parsers.
|
|
3
|
+
* It will be eliminated in the future, and generators should not need to rely on these prefixes for any reason.
|
|
4
|
+
*/
|
|
5
|
+
export declare const __DO_NOT_USE_FUNCTION_LITERAL_PREFIX = "@builder.io/mitosis/function:";
|
|
6
|
+
/**
|
|
7
|
+
* DO NOT USE THIS PREFIX. It's only used for legacy purposes, within a very small subset of logic in the JSX & Builder parsers.
|
|
8
|
+
* It will be eliminated in the future, and generators should not need to rely on these prefixes for any reason.
|
|
9
|
+
*/
|
|
10
|
+
export declare const __DO_NOT_USE_METHOD_LITERAL_PREFIX = "@builder.io/mitosis/method:";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__DO_NOT_USE_METHOD_LITERAL_PREFIX = exports.__DO_NOT_USE_FUNCTION_LITERAL_PREFIX = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* DO NOT USE THIS PREFIX. It's only used for legacy purposes, within a very small subset of logic in the JSX & Builder parsers.
|
|
6
|
+
* It will be eliminated in the future, and generators should not need to rely on these prefixes for any reason.
|
|
7
|
+
*/
|
|
8
|
+
exports.__DO_NOT_USE_FUNCTION_LITERAL_PREFIX = "@builder.io/mitosis/function:";
|
|
9
|
+
/**
|
|
10
|
+
* DO NOT USE THIS PREFIX. It's only used for legacy purposes, within a very small subset of logic in the JSX & Builder parsers.
|
|
11
|
+
* It will be eliminated in the future, and generators should not need to rely on these prefixes for any reason.
|
|
12
|
+
*/
|
|
13
|
+
exports.__DO_NOT_USE_METHOD_LITERAL_PREFIX = "@builder.io/mitosis/method:";
|
|
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.parseContext = void 0;
|
|
27
27
|
var babel = __importStar(require("@babel/core"));
|
|
28
28
|
var create_mitosis_context_1 = require("../helpers/create-mitosis-context");
|
|
29
|
-
var
|
|
29
|
+
var state_1 = require("./jsx/state");
|
|
30
30
|
var types = babel.types;
|
|
31
31
|
var tsPreset = require('@babel/preset-typescript');
|
|
32
32
|
function parseContext(code, options) {
|
|
@@ -51,7 +51,7 @@ function parseContext(code, options) {
|
|
|
51
51
|
if (types.isObjectExpression(firstArg)) {
|
|
52
52
|
// TODO: support non object values by parsing any node type
|
|
53
53
|
// like the logic within each property value of parseStateObject
|
|
54
|
-
context.value = (0,
|
|
54
|
+
context.value = (0, state_1.parseStateObjectToMitosisState)(firstArg);
|
|
55
55
|
found = true;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapJsonObjectToStateValue = void 0;
|
|
4
|
+
var lodash_1 = require("lodash");
|
|
5
|
+
var patterns_1 = require("../../helpers/patterns");
|
|
6
|
+
var outdated_prefixes_1 = require("../constants/outdated-prefixes");
|
|
7
|
+
/**
|
|
8
|
+
* Sets StateTypeValue based on the string prefixes we've set previously.
|
|
9
|
+
*
|
|
10
|
+
* This is a temporary workaround until we eliminate the prefixes and make this StateValueType the
|
|
11
|
+
* source of truth.
|
|
12
|
+
*/
|
|
13
|
+
var mapJsonToStateValue = function (value) {
|
|
14
|
+
if (typeof value === 'string') {
|
|
15
|
+
if (value.startsWith(outdated_prefixes_1.__DO_NOT_USE_FUNCTION_LITERAL_PREFIX)) {
|
|
16
|
+
return { type: 'function', code: value.replace(outdated_prefixes_1.__DO_NOT_USE_FUNCTION_LITERAL_PREFIX, '') };
|
|
17
|
+
}
|
|
18
|
+
else if (value.startsWith(outdated_prefixes_1.__DO_NOT_USE_METHOD_LITERAL_PREFIX)) {
|
|
19
|
+
var strippedValue = value.replace(outdated_prefixes_1.__DO_NOT_USE_METHOD_LITERAL_PREFIX, '');
|
|
20
|
+
var isGet = Boolean(strippedValue.match(patterns_1.GETTER));
|
|
21
|
+
var type = isGet ? 'getter' : 'method';
|
|
22
|
+
return { type: type, code: strippedValue };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { type: 'property', code: value };
|
|
26
|
+
};
|
|
27
|
+
var mapJsonObjectToStateValue = function (value) {
|
|
28
|
+
return (0, lodash_1.mapValues)(value, mapJsonToStateValue);
|
|
29
|
+
};
|
|
30
|
+
exports.mapJsonObjectToStateValue = mapJsonObjectToStateValue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as babel from '@babel/core';
|
|
2
2
|
import { Context } from './types';
|
|
3
3
|
export declare const getPropsTypeRef: (node: babel.types.FunctionDeclaration, context: Context) => string | undefined;
|
|
4
|
-
export declare const isTypeImport: (node: babel.Node) => boolean;
|
|
5
4
|
export declare const isTypeOrInterface: (node: babel.Node) => boolean;
|
|
6
5
|
export declare const collectTypes: (node: babel.Node, context: Context) => void;
|
|
6
|
+
export declare function handleTypeImports(path: babel.NodePath<babel.types.Program>, context: Context): void;
|
|
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.
|
|
38
|
+
exports.handleTypeImports = exports.collectTypes = exports.isTypeOrInterface = exports.getPropsTypeRef = void 0;
|
|
39
39
|
var babel = __importStar(require("@babel/core"));
|
|
40
40
|
var generator_1 = __importDefault(require("@babel/generator"));
|
|
41
41
|
var types = babel.types;
|
|
@@ -71,7 +71,6 @@ var isTypeImport = function (node) {
|
|
|
71
71
|
// Babel adds an implicit JSX type import that we don't want
|
|
72
72
|
((_a = node.specifiers[0]) === null || _a === void 0 ? void 0 : _a.local.name) !== 'JSX';
|
|
73
73
|
};
|
|
74
|
-
exports.isTypeImport = isTypeImport;
|
|
75
74
|
var isTypeOrInterface = function (node) {
|
|
76
75
|
return types.isTSTypeAliasDeclaration(node) ||
|
|
77
76
|
types.isTSInterfaceDeclaration(node) ||
|
|
@@ -86,3 +85,17 @@ var collectTypes = function (node, context) {
|
|
|
86
85
|
context.builder.component.types = types.filter(Boolean);
|
|
87
86
|
};
|
|
88
87
|
exports.collectTypes = collectTypes;
|
|
88
|
+
function handleTypeImports(path, context) {
|
|
89
|
+
for (var _i = 0, _a = path.node.body; _i < _a.length; _i++) {
|
|
90
|
+
var statement = _a[_i];
|
|
91
|
+
if (isTypeImport(statement)) {
|
|
92
|
+
var importDeclaration = statement;
|
|
93
|
+
// Remove .lite from path if exists, as that will be stripped
|
|
94
|
+
if (importDeclaration.source.value.endsWith('.lite')) {
|
|
95
|
+
importDeclaration.source.value = importDeclaration.source.value.replace(/\.lite$/, '');
|
|
96
|
+
}
|
|
97
|
+
(0, exports.collectTypes)(statement, context);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.handleTypeImports = handleTypeImports;
|
|
@@ -52,7 +52,7 @@ function extractContextComponents(json) {
|
|
|
52
52
|
json.context.set[refPath] = {
|
|
53
53
|
name: name_1,
|
|
54
54
|
value: value
|
|
55
|
-
? (0, state_1.
|
|
55
|
+
? (0, state_1.parseStateObjectToMitosisState)(expressionToNode(value))
|
|
56
56
|
: undefined,
|
|
57
57
|
};
|
|
58
58
|
this.update((0, create_mitosis_node_1.createMitosisNode)({
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as babel from '@babel/core';
|
|
2
|
+
import { MitosisNode } from '../../types/mitosis-node';
|
|
3
|
+
/**
|
|
4
|
+
* Parses a JSX element into a MitosisNode.
|
|
5
|
+
*/
|
|
6
|
+
export declare const jsxElementToJson: (node: babel.types.JSXElement | babel.types.JSXExpressionContainer | babel.types.JSXFragment | babel.types.JSXSpreadChild | babel.types.JSXText) => MitosisNode | null;
|
|
@@ -0,0 +1,243 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.jsxElementToJson = void 0;
|
|
41
|
+
var babel = __importStar(require("@babel/core"));
|
|
42
|
+
var generator_1 = __importDefault(require("@babel/generator"));
|
|
43
|
+
var nullable_1 = require("../../helpers/nullable");
|
|
44
|
+
var create_mitosis_node_1 = require("../../helpers/create-mitosis-node");
|
|
45
|
+
var function_1 = require("fp-ts/lib/function");
|
|
46
|
+
var types = babel.types;
|
|
47
|
+
var getForArguments = function (params) {
|
|
48
|
+
var _a = params
|
|
49
|
+
.filter(function (param) { return types.isIdentifier(param); })
|
|
50
|
+
.map(function (param) { return param.name; })
|
|
51
|
+
.filter(nullable_1.checkIsDefined), forName = _a[0], indexName = _a[1], collectionName = _a[2];
|
|
52
|
+
return {
|
|
53
|
+
forName: forName,
|
|
54
|
+
collectionName: collectionName,
|
|
55
|
+
indexName: indexName,
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Parses a JSX element into a MitosisNode.
|
|
60
|
+
*/
|
|
61
|
+
var jsxElementToJson = function (node) {
|
|
62
|
+
if (types.isJSXText(node)) {
|
|
63
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
64
|
+
properties: {
|
|
65
|
+
_text: node.value,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (types.isJSXExpressionContainer(node)) {
|
|
70
|
+
if (types.isJSXEmptyExpression(node.expression)) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
// foo.map -> <For each={foo}>...</For>
|
|
74
|
+
if (types.isCallExpression(node.expression) ||
|
|
75
|
+
types.isOptionalCallExpression(node.expression)) {
|
|
76
|
+
var callback = node.expression.arguments[0];
|
|
77
|
+
if (types.isArrowFunctionExpression(callback)) {
|
|
78
|
+
if (types.isIdentifier(callback.params[0])) {
|
|
79
|
+
var forArguments = getForArguments(callback.params);
|
|
80
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
81
|
+
name: 'For',
|
|
82
|
+
bindings: {
|
|
83
|
+
each: {
|
|
84
|
+
code: (0, generator_1.default)(node.expression.callee)
|
|
85
|
+
.code // Remove .map or potentially ?.map
|
|
86
|
+
.replace(/\??\.map$/, ''),
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
scope: forArguments,
|
|
90
|
+
children: [(0, exports.jsxElementToJson)(callback.body)],
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// {foo && <div />} -> <Show when={foo}>...</Show>
|
|
96
|
+
if (types.isLogicalExpression(node.expression)) {
|
|
97
|
+
if (node.expression.operator === '&&') {
|
|
98
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
99
|
+
name: 'Show',
|
|
100
|
+
bindings: {
|
|
101
|
+
when: { code: (0, generator_1.default)(node.expression.left).code },
|
|
102
|
+
},
|
|
103
|
+
children: [(0, exports.jsxElementToJson)(node.expression.right)],
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// TODO: good warning system for unsupported operators
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// {foo ? <div /> : <span />} -> <Show when={foo} else={<span />}>...</Show>
|
|
111
|
+
if (types.isConditionalExpression(node.expression)) {
|
|
112
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
113
|
+
name: 'Show',
|
|
114
|
+
meta: {
|
|
115
|
+
else: (0, exports.jsxElementToJson)(node.expression.alternate),
|
|
116
|
+
},
|
|
117
|
+
bindings: {
|
|
118
|
+
when: { code: (0, generator_1.default)(node.expression.test).code },
|
|
119
|
+
},
|
|
120
|
+
children: [(0, exports.jsxElementToJson)(node.expression.consequent)],
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// TODO: support {foo ? bar : baz}
|
|
124
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
125
|
+
bindings: {
|
|
126
|
+
_text: { code: (0, generator_1.default)(node.expression).code },
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (types.isJSXFragment(node)) {
|
|
131
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
132
|
+
name: 'Fragment',
|
|
133
|
+
children: node.children.map(exports.jsxElementToJson).filter(nullable_1.checkIsDefined),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
// TODO: support spread attributes
|
|
137
|
+
if (types.isJSXSpreadChild(node)) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
var nodeName = (0, generator_1.default)(node.openingElement.name).code;
|
|
141
|
+
if (nodeName === 'Show') {
|
|
142
|
+
var whenAttr = node.openingElement.attributes.find(function (item) { return types.isJSXAttribute(item) && item.name.name === 'when'; });
|
|
143
|
+
var elseAttr = node.openingElement.attributes.find(function (item) { return types.isJSXAttribute(item) && item.name.name === 'else'; });
|
|
144
|
+
var whenValue = whenAttr && types.isJSXExpressionContainer(whenAttr.value)
|
|
145
|
+
? (0, generator_1.default)(whenAttr.value.expression).code
|
|
146
|
+
: undefined;
|
|
147
|
+
var elseValue = elseAttr &&
|
|
148
|
+
types.isJSXExpressionContainer(elseAttr.value) &&
|
|
149
|
+
(0, exports.jsxElementToJson)(elseAttr.value.expression);
|
|
150
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
151
|
+
name: 'Show',
|
|
152
|
+
meta: {
|
|
153
|
+
else: elseValue || undefined,
|
|
154
|
+
},
|
|
155
|
+
bindings: __assign({}, (whenValue ? { when: { code: whenValue } } : {})),
|
|
156
|
+
children: node.children.map(exports.jsxElementToJson).filter(nullable_1.checkIsDefined),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
// <For ...> control flow component
|
|
160
|
+
if (nodeName === 'For') {
|
|
161
|
+
var child = node.children.find(function (item) {
|
|
162
|
+
return types.isJSXExpressionContainer(item);
|
|
163
|
+
});
|
|
164
|
+
if ((0, nullable_1.checkIsDefined)(child)) {
|
|
165
|
+
var childExpression = child.expression;
|
|
166
|
+
if (types.isArrowFunctionExpression(childExpression)) {
|
|
167
|
+
var forArguments = getForArguments(childExpression === null || childExpression === void 0 ? void 0 : childExpression.params);
|
|
168
|
+
var forCode = (0, function_1.pipe)(node.openingElement.attributes[0], function (attr) {
|
|
169
|
+
if (types.isJSXAttribute(attr) && types.isJSXExpressionContainer(attr.value)) {
|
|
170
|
+
return (0, generator_1.default)(attr.value.expression).code;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
// TO-DO: is an empty string valid here?
|
|
174
|
+
return '';
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
178
|
+
name: 'For',
|
|
179
|
+
bindings: {
|
|
180
|
+
each: {
|
|
181
|
+
code: forCode,
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
scope: forArguments,
|
|
185
|
+
children: [(0, exports.jsxElementToJson)(childExpression.body)],
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
191
|
+
name: nodeName,
|
|
192
|
+
properties: node.openingElement.attributes.reduce(function (memo, item) {
|
|
193
|
+
if (types.isJSXAttribute(item)) {
|
|
194
|
+
var key = item.name.name;
|
|
195
|
+
var value = item.value;
|
|
196
|
+
if (types.isStringLiteral(value)) {
|
|
197
|
+
memo[key] = value.value;
|
|
198
|
+
return memo;
|
|
199
|
+
}
|
|
200
|
+
if (types.isJSXExpressionContainer(value) && types.isStringLiteral(value.expression)) {
|
|
201
|
+
memo[key] = value.expression.value;
|
|
202
|
+
return memo;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return memo;
|
|
206
|
+
}, {}),
|
|
207
|
+
bindings: node.openingElement.attributes.reduce(function (memo, item) {
|
|
208
|
+
if (types.isJSXAttribute(item)) {
|
|
209
|
+
var key = item.name.name;
|
|
210
|
+
var value = item.value;
|
|
211
|
+
if (types.isJSXExpressionContainer(value) && !types.isStringLiteral(value.expression)) {
|
|
212
|
+
var expression = value.expression;
|
|
213
|
+
if (types.isArrowFunctionExpression(expression)) {
|
|
214
|
+
if (key.startsWith('on')) {
|
|
215
|
+
memo[key] = {
|
|
216
|
+
code: (0, generator_1.default)(expression.body).code,
|
|
217
|
+
arguments: expression.params.map(function (node) { return node === null || node === void 0 ? void 0 : node.name; }),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
memo[key] = { code: (0, generator_1.default)(expression.body).code };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
memo[key] = { code: (0, generator_1.default)(expression).code };
|
|
226
|
+
}
|
|
227
|
+
return memo;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else if (types.isJSXSpreadAttribute(item)) {
|
|
231
|
+
// TODO: potentially like Vue store bindings and properties as array of key value pairs
|
|
232
|
+
// too so can do this accurately when order matters. Also tempting to not support spread,
|
|
233
|
+
// as some frameworks do not support it (e.g. Angular) tho Angular may be the only one
|
|
234
|
+
memo._spread = {
|
|
235
|
+
code: types.stringLiteral((0, generator_1.default)(item.argument).code).value,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
return memo;
|
|
239
|
+
}, {}),
|
|
240
|
+
children: node.children.map(exports.jsxElementToJson).filter(nullable_1.checkIsDefined),
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
exports.jsxElementToJson = jsxElementToJson;
|