@builder.io/mitosis 0.0.144 → 0.0.146
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/react/blocks.js +9 -4
- package/dist/src/generators/svelte/svelte.js +23 -1
- package/dist/src/generators/vue/compositionApi.js +1 -2
- package/dist/src/helpers/filter-empty-text-nodes.d.ts +1 -0
- package/dist/src/helpers/filter-empty-text-nodes.js +5 -3
- package/dist/src/helpers/is-root-text-node.js +1 -1
- package/dist/src/helpers/typescript-project.js +1 -1
- package/dist/src/parsers/jsx/jsx.js +5 -0
- package/package.json +1 -1
|
@@ -59,13 +59,13 @@ var NODE_MAPPERS = {
|
|
|
59
59
|
return '';
|
|
60
60
|
}
|
|
61
61
|
var children = (0, helpers_1.processBinding)('props.children', options);
|
|
62
|
-
return "{".concat(children, " ").concat(hasChildren ? "|| (".concat(renderChildren(), ")") : '', "}");
|
|
62
|
+
return "<>{".concat(children, " ").concat(hasChildren ? "|| (".concat(renderChildren(), ")") : '', "}</>");
|
|
63
63
|
}
|
|
64
64
|
var slotProp = (0, helpers_1.processBinding)(slotName, options).replace('name=', '');
|
|
65
65
|
if (!slotProp.startsWith('props.')) {
|
|
66
66
|
slotProp = "props.".concat(slotProp);
|
|
67
67
|
}
|
|
68
|
-
return "{".concat(slotProp, " ").concat(hasChildren ? "|| (".concat(renderChildren(), ")") : '', "}");
|
|
68
|
+
return "<>{".concat(slotProp, " ").concat(hasChildren ? "|| (".concat(renderChildren(), ")") : '', "}</>");
|
|
69
69
|
},
|
|
70
70
|
Fragment: function (json, options, component) {
|
|
71
71
|
var wrap = (0, helpers_1.wrapInFragment)(json);
|
|
@@ -85,7 +85,12 @@ var NODE_MAPPERS = {
|
|
|
85
85
|
},
|
|
86
86
|
Show: function (json, options, component) {
|
|
87
87
|
var _a;
|
|
88
|
-
var wrap = (0, helpers_1.wrapInFragment)(json) ||
|
|
88
|
+
var wrap = (0, helpers_1.wrapInFragment)(json) ||
|
|
89
|
+
(0, is_root_text_node_1.isRootTextNode)(json) ||
|
|
90
|
+
component.children[0] === json ||
|
|
91
|
+
// when `<Show><For>...</For></Show>`, we need to wrap the For generated code in a fragment
|
|
92
|
+
// since it's a `.map()` call
|
|
93
|
+
(json.children.length === 1 && ['For', 'Show'].includes(json.children[0].name));
|
|
89
94
|
var wrapElse = json.meta.else &&
|
|
90
95
|
((0, helpers_1.wrapInFragment)(json.meta.else) || (0, mitosis_node_1.checkIsForNode)(json.meta.else));
|
|
91
96
|
return "{".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
|
|
@@ -219,7 +224,7 @@ var blockToReact = function (json, options, component, parentSlots) {
|
|
|
219
224
|
if (json.children) {
|
|
220
225
|
childrenNodes = json.children
|
|
221
226
|
.map(function (item) { return (0, exports.blockToReact)(item, options, component, needsToRenderSlots); })
|
|
222
|
-
.join('
|
|
227
|
+
.join('');
|
|
223
228
|
}
|
|
224
229
|
if (needsToRenderSlots.length) {
|
|
225
230
|
needsToRenderSlots.forEach(function (_a) {
|
|
@@ -312,7 +312,29 @@ var componentToSvelte = function (userProvidedOptions) {
|
|
|
312
312
|
return "afterUpdate(() => { ".concat(code, " });");
|
|
313
313
|
}
|
|
314
314
|
var fnName = "onUpdateFn_".concat(index);
|
|
315
|
-
|
|
315
|
+
var depsArray = deps
|
|
316
|
+
.slice(1, deps.length - 1)
|
|
317
|
+
.split(',')
|
|
318
|
+
.map(function (x) { return x.trim(); });
|
|
319
|
+
var getReactiveDepName = function (dep) {
|
|
320
|
+
return "".concat(fnName, "_").concat(dep.slice(1).replace(/(\.|\?)/g, '_'));
|
|
321
|
+
};
|
|
322
|
+
var isStoreAccessDep = function (dep) { return dep.startsWith('$'); };
|
|
323
|
+
var reactiveDepsWorkaround = depsArray
|
|
324
|
+
.filter(isStoreAccessDep)
|
|
325
|
+
.map(function (dep) { return "$: ".concat(getReactiveDepName(dep), " = ").concat(dep, ";"); })
|
|
326
|
+
.join('\n');
|
|
327
|
+
var depsArrayStr = depsArray
|
|
328
|
+
.map(function (x) { return (isStoreAccessDep(x) ? getReactiveDepName(x) : x); })
|
|
329
|
+
.join(', ');
|
|
330
|
+
/**
|
|
331
|
+
* We create a reactive value for each `onUpdate`'s dependency that
|
|
332
|
+
* accesses a store so that Svelte has accurate dependency tracking.
|
|
333
|
+
*
|
|
334
|
+
* Otherwise, if the dependency is a value within a store, Svelte will
|
|
335
|
+
* rerun the effect every time the parent store is changed in any way.
|
|
336
|
+
*/
|
|
337
|
+
return "\n function ".concat(fnName, "(..._args").concat(options.typescript ? ': any[]' : '', ") {\n ").concat(code, "\n }\n ").concat(reactiveDepsWorkaround, "\n $: ").concat(fnName, "(...[").concat(depsArrayStr, "]);\n ");
|
|
316
338
|
}).join(';')) || '',
|
|
317
339
|
// make sure this is after all other state/code is initialized
|
|
318
340
|
setContextCode({ json: json, options: options }), !((_k = json.hooks.onUnMount) === null || _k === void 0 ? void 0 : _k.code) ? '' : "onDestroy(() => { ".concat(json.hooks.onUnMount.code, " });"), json.children
|
|
@@ -10,7 +10,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.generateCompositionApiScript = void 0;
|
|
11
11
|
var dedent_1 = require("../../helpers/dedent");
|
|
12
12
|
var get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
13
|
-
var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
14
13
|
var json5_1 = __importDefault(require("json5"));
|
|
15
14
|
var lodash_1 = require("lodash");
|
|
16
15
|
var helpers_1 = require("./helpers");
|
|
@@ -93,7 +92,7 @@ function generateCompositionApiScript(component, options, template, props, onUpd
|
|
|
93
92
|
code: hook.deps || '',
|
|
94
93
|
options: options,
|
|
95
94
|
json: component,
|
|
96
|
-
}), ", (
|
|
95
|
+
}), ", () => { ").concat(hook.code, " }, {immediate: true})");
|
|
97
96
|
}).join('\n')) || '', methods !== null && methods !== void 0 ? methods : '');
|
|
98
97
|
return str;
|
|
99
98
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.filterEmptyTextNodes = void 0;
|
|
4
|
-
var
|
|
5
|
-
return
|
|
3
|
+
exports.filterEmptyTextNodes = exports.isEmptyTextNode = void 0;
|
|
4
|
+
var isEmptyTextNode = function (node) {
|
|
5
|
+
return typeof node.properties._text === 'string' && node.properties._text.trim().length === 0;
|
|
6
6
|
};
|
|
7
|
+
exports.isEmptyTextNode = isEmptyTextNode;
|
|
8
|
+
var filterEmptyTextNodes = function (node) { return !(0, exports.isEmptyTextNode)(node); };
|
|
7
9
|
exports.filterEmptyTextNodes = filterEmptyTextNodes;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isTextNode = exports.isRootTextNode = void 0;
|
|
4
4
|
function isRootTextNode(json) {
|
|
5
5
|
var firstChild = json.children[0];
|
|
6
|
-
return Boolean(firstChild && isTextNode(firstChild));
|
|
6
|
+
return Boolean(json.children.length === 1 && firstChild && isTextNode(firstChild));
|
|
7
7
|
}
|
|
8
8
|
exports.isRootTextNode = isRootTextNode;
|
|
9
9
|
function isTextNode(node) {
|
|
@@ -53,7 +53,7 @@ var getProject = function (tsConfigFilePath) {
|
|
|
53
53
|
return new ts_morph_1.Project({ tsConfigFilePath: tsConfigFilePath });
|
|
54
54
|
}
|
|
55
55
|
catch (err) {
|
|
56
|
-
throw new Error(
|
|
56
|
+
throw new Error("Error creating Typescript Project. Make sure `tsConfigFilePath` points to a valid tsconfig.json file.\n Path received: \"".concat(tsConfigFilePath, "\"\n "));
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
var createTypescriptProject = function (tsConfigFilePath) {
|
|
@@ -38,6 +38,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
};
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.parseJsx = void 0;
|
|
41
|
+
var filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
|
|
42
|
+
var traverse_nodes_1 = require("../../helpers/traverse-nodes");
|
|
41
43
|
var babel = __importStar(require("@babel/core"));
|
|
42
44
|
var generator_1 = __importDefault(require("@babel/generator"));
|
|
43
45
|
var plugin_syntax_typescript_1 = __importDefault(require("@babel/plugin-syntax-typescript"));
|
|
@@ -234,6 +236,9 @@ function parseJsx(jsx, _options) {
|
|
|
234
236
|
mitosisComponent.context.get[context].type = 'reactive';
|
|
235
237
|
});
|
|
236
238
|
}
|
|
239
|
+
(0, traverse_nodes_1.traverseNodes)(mitosisComponent, function (node) {
|
|
240
|
+
node.children = node.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes);
|
|
241
|
+
});
|
|
237
242
|
return mitosisComponent;
|
|
238
243
|
}
|
|
239
244
|
exports.parseJsx = parseJsx;
|