@builder.io/mitosis 0.3.5 → 0.3.6
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/generators/mitosis.js +1 -1
- package/dist/src/generators/qwik/component-generator.js +1 -1
- package/dist/src/generators/react/blocks.d.ts +1 -1
- package/dist/src/generators/react/blocks.js +30 -18
- package/dist/src/generators/react/generator.js +2 -2
- package/dist/src/generators/stencil/generate.js +29 -14
- package/dist/src/parsers/jsx/element-parser.d.ts +1 -1
- package/dist/src/parsers/jsx/element-parser.js +64 -46
- package/dist/src/parsers/jsx/function-parser.js +4 -1
- package/package.json +1 -1
|
@@ -60,7 +60,7 @@ var blockToMitosis = function (json, toMitosisOptions, component) {
|
|
|
60
60
|
stylesType: 'emotion',
|
|
61
61
|
type: 'dom',
|
|
62
62
|
prettier: options.prettier,
|
|
63
|
-
}, component);
|
|
63
|
+
}, component, true);
|
|
64
64
|
}
|
|
65
65
|
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
66
66
|
var needsWrapper = json.children.length !== 1;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { MitosisComponent } from '../../types/mitosis-component';
|
|
2
2
|
import { MitosisNode } from '../../types/mitosis-node';
|
|
3
3
|
import { ToReactOptions } from './types';
|
|
4
|
-
export declare const blockToReact: (json: MitosisNode, options: ToReactOptions, component: MitosisComponent, parentSlots?: any[]) => string;
|
|
4
|
+
export declare const blockToReact: (json: MitosisNode, options: ToReactOptions, component: MitosisComponent, insideJsx: boolean, parentSlots?: any[]) => string;
|
|
@@ -26,13 +26,13 @@ var html_tags_1 = require("../../constants/html_tags");
|
|
|
26
26
|
var helpers_1 = require("./helpers");
|
|
27
27
|
var state_1 = require("./state");
|
|
28
28
|
var NODE_MAPPERS = {
|
|
29
|
-
Slot: function (json, options, component, parentSlots) {
|
|
29
|
+
Slot: function (json, options, component, _insideJsx, parentSlots) {
|
|
30
30
|
var _a, _b;
|
|
31
31
|
var slotName = ((_a = json.bindings.name) === null || _a === void 0 ? void 0 : _a.code) || json.properties.name;
|
|
32
32
|
var hasChildren = json.children.length;
|
|
33
33
|
var renderChildren = function () {
|
|
34
34
|
var _a;
|
|
35
|
-
var childrenStr = (_a = json.children) === null || _a === void 0 ? void 0 : _a.map(function (item) { return (0, exports.blockToReact)(item, options, component); }).join('\n').trim();
|
|
35
|
+
var childrenStr = (_a = json.children) === null || _a === void 0 ? void 0 : _a.map(function (item) { return (0, exports.blockToReact)(item, options, component, true); }).join('\n').trim();
|
|
36
36
|
/**
|
|
37
37
|
* Ad-hoc way of figuring out if the children defaultProp is:
|
|
38
38
|
* - a JSX element, e.g. `<div>foo</div>`
|
|
@@ -70,20 +70,26 @@ var NODE_MAPPERS = {
|
|
|
70
70
|
Fragment: function (json, options, component) {
|
|
71
71
|
var wrap = (0, helpers_1.wrapInFragment)(json) || (0, is_root_text_node_1.isRootTextNode)(json);
|
|
72
72
|
return "".concat(wrap ? (0, helpers_1.getFragment)('open', options) : '').concat(json.children
|
|
73
|
-
.map(function (item) { return (0, exports.blockToReact)(item, options, component); })
|
|
73
|
+
.map(function (item) { return (0, exports.blockToReact)(item, options, component, wrap); })
|
|
74
74
|
.join('\n')).concat(wrap ? (0, helpers_1.getFragment)('close', options) : '');
|
|
75
75
|
},
|
|
76
|
-
For: function (_json, options, component) {
|
|
76
|
+
For: function (_json, options, component, insideJsx) {
|
|
77
77
|
var _a;
|
|
78
78
|
var json = _json;
|
|
79
79
|
var wrap = (0, helpers_1.wrapInFragment)(json);
|
|
80
80
|
var forArguments = (0, for_1.getForArguments)(json).join(', ');
|
|
81
|
-
|
|
81
|
+
var expression = "".concat((0, helpers_1.processBinding)((_a = json.bindings.each) === null || _a === void 0 ? void 0 : _a.code, options), "?.map((").concat(forArguments, ") => (\n ").concat(wrap ? (0, helpers_1.openFrag)(options) : '').concat(json.children
|
|
82
82
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
83
|
-
.map(function (item) { return (0, exports.blockToReact)(item, options, component); })
|
|
84
|
-
.join('\n')).concat(wrap ? (0, helpers_1.closeFrag)(options) : '', "\n ))
|
|
83
|
+
.map(function (item) { return (0, exports.blockToReact)(item, options, component, wrap); })
|
|
84
|
+
.join('\n')).concat(wrap ? (0, helpers_1.closeFrag)(options) : '', "\n ))");
|
|
85
|
+
if (insideJsx) {
|
|
86
|
+
return "{".concat(expression, "}");
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return expression;
|
|
90
|
+
}
|
|
85
91
|
},
|
|
86
|
-
Show: function (json, options, component) {
|
|
92
|
+
Show: function (json, options, component, insideJsx) {
|
|
87
93
|
var _a;
|
|
88
94
|
var wrap = (0, helpers_1.wrapInFragment)(json) ||
|
|
89
95
|
(0, is_root_text_node_1.isRootTextNode)(json) ||
|
|
@@ -91,16 +97,22 @@ var NODE_MAPPERS = {
|
|
|
91
97
|
// when `<Show><For>...</For></Show>`, we need to wrap the For generated code in a fragment
|
|
92
98
|
// since it's a `.map()` call
|
|
93
99
|
(json.children.length === 1 && ['For', 'Show'].includes(json.children[0].name));
|
|
94
|
-
var wrapElse = json.meta.else &&
|
|
95
|
-
((0, helpers_1.wrapInFragment)(json.meta.else) || (0, mitosis_node_1.checkIsForNode)(json.meta.else));
|
|
96
|
-
|
|
100
|
+
var wrapElse = !!(json.meta.else &&
|
|
101
|
+
((0, helpers_1.wrapInFragment)(json.meta.else) || (0, mitosis_node_1.checkIsForNode)(json.meta.else)));
|
|
102
|
+
var expression = "".concat((0, helpers_1.processBinding)((_a = json.bindings.when) === null || _a === void 0 ? void 0 : _a.code, options), " ? (\n ").concat(wrap ? (0, helpers_1.openFrag)(options) : '').concat(json.children
|
|
97
103
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
98
|
-
.map(function (item) { return (0, exports.blockToReact)(item, options, component); })
|
|
104
|
+
.map(function (item) { return (0, exports.blockToReact)(item, options, component, wrap); })
|
|
99
105
|
.join('\n')).concat(wrap ? (0, helpers_1.closeFrag)(options) : '', "\n ) : ").concat(!json.meta.else
|
|
100
106
|
? 'null'
|
|
101
107
|
: (wrapElse ? (0, helpers_1.openFrag)(options) : '') +
|
|
102
|
-
(0, exports.blockToReact)(json.meta.else, options, component) +
|
|
103
|
-
(wrapElse ? (0, helpers_1.closeFrag)(options) : '')
|
|
108
|
+
(0, exports.blockToReact)(json.meta.else, options, component, wrapElse) +
|
|
109
|
+
(wrapElse ? (0, helpers_1.closeFrag)(options) : ''));
|
|
110
|
+
if (insideJsx) {
|
|
111
|
+
return "{".concat(expression, "}");
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
return expression;
|
|
115
|
+
}
|
|
104
116
|
},
|
|
105
117
|
};
|
|
106
118
|
var ATTTRIBUTE_MAPPERS = {
|
|
@@ -129,11 +141,11 @@ var BINDING_MAPPERS = __assign({ ref: function (ref, value, options) {
|
|
|
129
141
|
var NATIVE_EVENT_MAPPER = {
|
|
130
142
|
onClick: 'onPress',
|
|
131
143
|
};
|
|
132
|
-
var blockToReact = function (json, options, component, parentSlots) {
|
|
144
|
+
var blockToReact = function (json, options, component, insideJsx, parentSlots) {
|
|
133
145
|
var _a, _b, _c, _d;
|
|
134
146
|
if (parentSlots === void 0) { parentSlots = []; }
|
|
135
147
|
if (NODE_MAPPERS[json.name]) {
|
|
136
|
-
return NODE_MAPPERS[json.name](json, options, component, parentSlots);
|
|
148
|
+
return NODE_MAPPERS[json.name](json, options, component, insideJsx, parentSlots);
|
|
137
149
|
}
|
|
138
150
|
if (json.properties._text) {
|
|
139
151
|
var text = json.properties._text;
|
|
@@ -235,7 +247,7 @@ var blockToReact = function (json, options, component, parentSlots) {
|
|
|
235
247
|
if (!(value === null || value === void 0 ? void 0 : value.length)) {
|
|
236
248
|
continue;
|
|
237
249
|
}
|
|
238
|
-
var reactComponents = value.map(function (node) { return (0, exports.blockToReact)(node, options, component); });
|
|
250
|
+
var reactComponents = value.map(function (node) { return (0, exports.blockToReact)(node, options, component, true); });
|
|
239
251
|
var slotStringValue = reactComponents.length === 1 ? reactComponents[0] : "<>".concat(reactComponents.join('\n'), "</>");
|
|
240
252
|
str += " ".concat(key, "={").concat(slotStringValue, "} ");
|
|
241
253
|
}
|
|
@@ -253,7 +265,7 @@ var blockToReact = function (json, options, component, parentSlots) {
|
|
|
253
265
|
var childrenNodes = '';
|
|
254
266
|
if (json.children) {
|
|
255
267
|
childrenNodes = json.children
|
|
256
|
-
.map(function (item) { return (0, exports.blockToReact)(item, options, component, needsToRenderSlots); })
|
|
268
|
+
.map(function (item) { return (0, exports.blockToReact)(item, options, component, true, needsToRenderSlots); })
|
|
257
269
|
.join('');
|
|
258
270
|
}
|
|
259
271
|
if (needsToRenderSlots.length) {
|
|
@@ -363,7 +363,7 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
363
363
|
var componentArgs = ["props".concat(options.typescript ? ":".concat(propType) : ''), options.forwardRef]
|
|
364
364
|
.filter(Boolean)
|
|
365
365
|
.join(',');
|
|
366
|
-
var componentBody = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n
|
|
366
|
+
var componentBody = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n );\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n );\n "])), options.contextType === 'prop-drill'
|
|
367
367
|
? "const ".concat(exports.contextPropDrillingKey, " = { ...props['").concat(exports.contextPropDrillingKey, "'] };")
|
|
368
368
|
: '', hasStateArgument ? '' : refsString, hasState
|
|
369
369
|
? options.stateType === 'mobx'
|
|
@@ -410,7 +410,7 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
410
410
|
str: json.hooks.onUnMount.code,
|
|
411
411
|
options: options,
|
|
412
412
|
}), "\n }\n }, [])")
|
|
413
|
-
: '', wrap ? (0, helpers_2.openFrag)(options) : '', json.children.map(function (item) { return (0, blocks_1.blockToReact)(item, options, json, []); }).join('\n'), componentHasStyles && options.stylesType === 'styled-jsx'
|
|
413
|
+
: '', wrap ? (0, helpers_2.openFrag)(options) : '', json.children.map(function (item) { return (0, blocks_1.blockToReact)(item, options, json, wrap, []); }).join('\n'), componentHasStyles && options.stylesType === 'styled-jsx'
|
|
414
414
|
? "<style jsx>{`".concat(css, "`}</style>")
|
|
415
415
|
: '', componentHasStyles && options.stylesType === 'style-tag'
|
|
416
416
|
? "<style>{`".concat(css, "`}</style>")
|
|
@@ -25,29 +25,44 @@ var html_tags_1 = require("../../constants/html_tags");
|
|
|
25
25
|
var plugins_1 = require("../../modules/plugins");
|
|
26
26
|
var on_mount_1 = require("../helpers/on-mount");
|
|
27
27
|
var collect_class_string_1 = require("./collect-class-string");
|
|
28
|
-
var blockToStencil = function (json, options) {
|
|
28
|
+
var blockToStencil = function (json, options, insideJsx) {
|
|
29
29
|
var _a, _b, _c, _d;
|
|
30
30
|
if (options === void 0) { options = {}; }
|
|
31
31
|
if (json.properties._text) {
|
|
32
32
|
return json.properties._text;
|
|
33
33
|
}
|
|
34
34
|
if ((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code) {
|
|
35
|
-
|
|
35
|
+
if (insideJsx) {
|
|
36
|
+
return "{".concat(processBinding(json.bindings._text.code), "}");
|
|
37
|
+
}
|
|
38
|
+
return processBinding((_b = json.bindings) === null || _b === void 0 ? void 0 : _b._text.code);
|
|
36
39
|
}
|
|
37
40
|
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
38
|
-
var
|
|
41
|
+
var wrap_1 = json.children.length !== 1;
|
|
39
42
|
var forArgs = (0, for_1.getForArguments)(json).join(', ');
|
|
40
|
-
|
|
43
|
+
var expression = "".concat(processBinding((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code), "?.map((").concat(forArgs, ") => (\n ").concat(wrap_1 ? '<>' : '').concat(json.children
|
|
41
44
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
42
|
-
.map(function (item) { return blockToStencil(item, options); })
|
|
43
|
-
.join('\n')).concat(
|
|
45
|
+
.map(function (item) { return blockToStencil(item, options, wrap_1); })
|
|
46
|
+
.join('\n')).concat(wrap_1 ? '</>' : '', "\n ))");
|
|
47
|
+
if (insideJsx) {
|
|
48
|
+
return "{".concat(expression, "}");
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return expression;
|
|
52
|
+
}
|
|
44
53
|
}
|
|
45
54
|
else if (json.name === 'Show') {
|
|
46
|
-
var
|
|
47
|
-
|
|
55
|
+
var wrap_2 = json.children.length !== 1;
|
|
56
|
+
var expression = "".concat(processBinding((_d = json.bindings.when) === null || _d === void 0 ? void 0 : _d.code), " ? (\n ").concat(wrap_2 ? '<>' : '').concat(json.children
|
|
48
57
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
49
|
-
.map(function (item) { return blockToStencil(item, options); })
|
|
50
|
-
.join('\n')).concat(
|
|
58
|
+
.map(function (item) { return blockToStencil(item, options, wrap_2); })
|
|
59
|
+
.join('\n')).concat(wrap_2 ? '</>' : '', "\n ) : ").concat(!json.meta.else ? 'null' : blockToStencil(json.meta.else, options, false));
|
|
60
|
+
if (insideJsx) {
|
|
61
|
+
return "{".concat(expression, "}");
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return expression;
|
|
65
|
+
}
|
|
51
66
|
}
|
|
52
67
|
var str = '';
|
|
53
68
|
str += "<".concat(json.name, " ");
|
|
@@ -80,7 +95,7 @@ var blockToStencil = function (json, options) {
|
|
|
80
95
|
}
|
|
81
96
|
str += '>';
|
|
82
97
|
if (json.children) {
|
|
83
|
-
str += json.children.map(function (item) { return blockToStencil(item, options); }).join('\n');
|
|
98
|
+
str += json.children.map(function (item) { return blockToStencil(item, options, true); }).join('\n');
|
|
84
99
|
}
|
|
85
100
|
str += "</".concat(json.name, ">");
|
|
86
101
|
return str;
|
|
@@ -132,7 +147,7 @@ var componentToStencil = function (_options) {
|
|
|
132
147
|
console.warn('Could not format css', err);
|
|
133
148
|
}
|
|
134
149
|
}
|
|
135
|
-
var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n\n import { Component, Prop, h, State, Fragment } from '@stencil/core';\n\n @Component({\n tag: '", "',\n ", "\n })\n export default class ", " {\n
|
|
150
|
+
var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n\n import { Component, Prop, h, State, Fragment } from '@stencil/core';\n\n @Component({\n tag: '", "',\n ", "\n })\n export default class ", " {\n\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n ", "\n\n render() {\n return (", "\n\n ", "\n\n ", ")\n }\n }\n "], ["\n ", "\n\n import { Component, Prop, h, State, Fragment } from '@stencil/core';\n\n @Component({\n tag: '"
|
|
136
151
|
/**
|
|
137
152
|
* You can set the tagName in your Mitosis component as
|
|
138
153
|
*
|
|
@@ -142,7 +157,7 @@ var componentToStencil = function (_options) {
|
|
|
142
157
|
*
|
|
143
158
|
* export default function ...
|
|
144
159
|
*/
|
|
145
|
-
, "',\n ", "\n })\n export default class ", " {\n
|
|
160
|
+
, "',\n ", "\n })\n export default class ", " {\n\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n ", "\n\n render() {\n return (", "\n\n ", "\n\n ", ")\n }\n }\n "])), (0, render_imports_1.renderPreComponent)({
|
|
146
161
|
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
147
162
|
component: json,
|
|
148
163
|
target: 'stencil',
|
|
@@ -166,7 +181,7 @@ var componentToStencil = function (_options) {
|
|
|
166
181
|
? ''
|
|
167
182
|
: "disconnectedCallback() { ".concat(processBinding(json.hooks.onUnMount.code), " }"), !((_d = json.hooks.onUpdate) === null || _d === void 0 ? void 0 : _d.length)
|
|
168
183
|
? ''
|
|
169
|
-
: json.hooks.onUpdate.map(function (hook) { return "componentDidUpdate() { ".concat(processBinding(hook.code), " }"); }), wrap ? '<>' : '', json.children.map(function (item) { return blockToStencil(item, options); }).join('\n'), wrap ? '</>' : '');
|
|
184
|
+
: json.hooks.onUpdate.map(function (hook) { return "componentDidUpdate() { ".concat(processBinding(hook.code), " }"); }), wrap ? '<>' : '', json.children.map(function (item) { return blockToStencil(item, options, true); }).join('\n'), wrap ? '</>' : '');
|
|
170
185
|
if (options.plugins) {
|
|
171
186
|
str = (0, plugins_1.runPreCodePlugins)({ json: json, code: str, plugins: options.plugins });
|
|
172
187
|
}
|
|
@@ -4,5 +4,5 @@ declare const types: typeof babel.types;
|
|
|
4
4
|
/**
|
|
5
5
|
* Parses a JSX element into a MitosisNode.
|
|
6
6
|
*/
|
|
7
|
-
export declare const jsxElementToJson: (node: babel.types.
|
|
7
|
+
export declare const jsxElementToJson: (node: babel.types.Expression | babel.types.JSX) => MitosisNode | null;
|
|
8
8
|
export {};
|
|
@@ -68,77 +68,95 @@ var jsxElementToJson = function (node) {
|
|
|
68
68
|
},
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
+
if (types.isJSXEmptyExpression(node)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
71
74
|
if (types.isJSXExpressionContainer(node)) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (types.
|
|
77
|
-
types.
|
|
78
|
-
|
|
79
|
-
if (types.isArrowFunctionExpression(callback)) {
|
|
80
|
-
if (types.isIdentifier(callback.params[0])) {
|
|
81
|
-
var forArguments = getForArguments(callback.params);
|
|
82
|
-
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
83
|
-
name: 'For',
|
|
84
|
-
bindings: {
|
|
85
|
-
each: (0, bindings_1.createSingleBinding)({
|
|
86
|
-
code: (0, generator_1.default)(node.expression.callee)
|
|
87
|
-
.code // Remove .map or potentially ?.map
|
|
88
|
-
.replace(/\??\.map$/, ''),
|
|
89
|
-
}),
|
|
90
|
-
},
|
|
91
|
-
scope: forArguments,
|
|
92
|
-
children: [(0, exports.jsxElementToJson)(callback.body)],
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
// {foo && <div />} -> <Show when={foo}>...</Show>
|
|
98
|
-
if (types.isLogicalExpression(node.expression)) {
|
|
99
|
-
if (node.expression.operator === '&&') {
|
|
75
|
+
return (0, exports.jsxElementToJson)(node.expression);
|
|
76
|
+
}
|
|
77
|
+
if (types.isCallExpression(node) || types.isOptionalCallExpression(node)) {
|
|
78
|
+
var callback = node.arguments[0];
|
|
79
|
+
if (types.isArrowFunctionExpression(callback)) {
|
|
80
|
+
if (types.isIdentifier(callback.params[0])) {
|
|
81
|
+
var forArguments = getForArguments(callback.params);
|
|
100
82
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
101
|
-
name: '
|
|
83
|
+
name: 'For',
|
|
102
84
|
bindings: {
|
|
103
|
-
|
|
85
|
+
each: (0, bindings_1.createSingleBinding)({
|
|
86
|
+
code: (0, generator_1.default)(node.callee)
|
|
87
|
+
.code // Remove .map or potentially ?.map
|
|
88
|
+
.replace(/\??\.map$/, ''),
|
|
89
|
+
}),
|
|
104
90
|
},
|
|
105
|
-
|
|
91
|
+
scope: forArguments,
|
|
92
|
+
children: [(0, exports.jsxElementToJson)(callback.body)],
|
|
106
93
|
});
|
|
107
94
|
}
|
|
108
|
-
else {
|
|
109
|
-
// TODO: good warning system for unsupported operators
|
|
110
|
-
}
|
|
111
95
|
}
|
|
112
|
-
|
|
113
|
-
|
|
96
|
+
}
|
|
97
|
+
else if (types.isLogicalExpression(node)) {
|
|
98
|
+
// {foo && <div />} -> <Show when={foo}>...</Show>
|
|
99
|
+
if (node.operator === '&&') {
|
|
114
100
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
115
101
|
name: 'Show',
|
|
116
|
-
meta: {
|
|
117
|
-
else: (0, exports.jsxElementToJson)(node.expression.alternate),
|
|
118
|
-
},
|
|
119
102
|
bindings: {
|
|
120
|
-
when: (0, bindings_1.createSingleBinding)({ code: (0, generator_1.default)(node.
|
|
103
|
+
when: (0, bindings_1.createSingleBinding)({ code: (0, generator_1.default)(node.left).code }),
|
|
121
104
|
},
|
|
122
|
-
children: [(0, exports.jsxElementToJson)(node.
|
|
105
|
+
children: [(0, exports.jsxElementToJson)(node.right)],
|
|
123
106
|
});
|
|
124
107
|
}
|
|
125
|
-
|
|
108
|
+
else {
|
|
109
|
+
// TODO: good warning system for unsupported operators
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (types.isConditionalExpression(node)) {
|
|
113
|
+
// {foo ? <div /> : <span />} -> <Show when={foo} else={<span />}>...</Show>
|
|
114
|
+
var child = (0, exports.jsxElementToJson)(node.consequent);
|
|
126
115
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
116
|
+
name: 'Show',
|
|
117
|
+
meta: {
|
|
118
|
+
else: (0, exports.jsxElementToJson)(node.alternate),
|
|
119
|
+
},
|
|
127
120
|
bindings: {
|
|
128
|
-
|
|
121
|
+
when: (0, bindings_1.createSingleBinding)({ code: (0, generator_1.default)(node.test).code }),
|
|
129
122
|
},
|
|
123
|
+
children: child === null ? [] : [child],
|
|
130
124
|
});
|
|
131
125
|
}
|
|
132
|
-
if (types.isJSXFragment(node)) {
|
|
126
|
+
else if (types.isJSXFragment(node)) {
|
|
133
127
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
134
128
|
name: 'Fragment',
|
|
135
129
|
children: node.children.map(exports.jsxElementToJson).filter(nullable_1.checkIsDefined),
|
|
136
130
|
});
|
|
137
131
|
}
|
|
138
|
-
|
|
139
|
-
|
|
132
|
+
else if (types.isJSXSpreadChild(node)) {
|
|
133
|
+
// TODO: support spread attributes
|
|
140
134
|
return null;
|
|
141
135
|
}
|
|
136
|
+
else if (types.isNullLiteral(node) || types.isBooleanLiteral(node)) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
else if (types.isNumericLiteral(node)) {
|
|
140
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
141
|
+
properties: {
|
|
142
|
+
_text: String(node.value),
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else if (types.isStringLiteral(node)) {
|
|
147
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
148
|
+
properties: {
|
|
149
|
+
_text: node.value,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (!types.isJSXElement(node)) {
|
|
154
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
155
|
+
bindings: {
|
|
156
|
+
_text: (0, bindings_1.createSingleBinding)({ code: (0, generator_1.default)(node).code }),
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
}
|
|
142
160
|
var nodeName = (0, generator_1.default)(node.openingElement.name).code;
|
|
143
161
|
if (nodeName === 'Show') {
|
|
144
162
|
var whenAttr = node.openingElement.attributes.find(function (item) { return types.isJSXAttribute(item) && item.name.name === 'when'; });
|
|
@@ -322,7 +322,10 @@ var componentFunctionToJson = function (node, context) {
|
|
|
322
322
|
if (theReturn) {
|
|
323
323
|
var value = theReturn.argument;
|
|
324
324
|
if (types.isJSXElement(value) || types.isJSXFragment(value)) {
|
|
325
|
-
|
|
325
|
+
var jsxElement = (0, element_parser_1.jsxElementToJson)(value);
|
|
326
|
+
if (jsxElement) {
|
|
327
|
+
children.push(jsxElement);
|
|
328
|
+
}
|
|
326
329
|
}
|
|
327
330
|
}
|
|
328
331
|
var localExports = context.builder.component.exports;
|