@builder.io/mitosis 0.0.72-5 → 0.0.73
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/angular.js +3 -3
- package/dist/src/generators/html.js +4 -4
- package/dist/src/generators/lit/generate.js +8 -8
- package/dist/src/generators/marko/generate.js +8 -8
- package/dist/src/generators/mitosis.js +5 -8
- package/dist/src/generators/qwik/component-generator.js +1 -1
- package/dist/src/generators/qwik/jsx.js +2 -2
- package/dist/src/generators/qwik/src-generator.js +1 -1
- package/dist/src/generators/react/generator.js +5 -8
- package/dist/src/generators/react/state.js +1 -0
- package/dist/src/generators/solid/index.js +8 -10
- package/dist/src/generators/stencil/generate.js +7 -7
- package/dist/src/generators/svelte.js +13 -12
- package/dist/src/generators/template.js +3 -3
- package/dist/src/generators/vue/blocks.js +17 -7
- package/dist/src/generators/vue/compositionApi.js +42 -7
- package/dist/src/helpers/get-props.js +6 -1
- package/dist/src/helpers/has.d.ts +1 -1
- package/dist/src/helpers/has.js +1 -1
- package/dist/src/parsers/jsx/element-parser.js +3 -1
- package/dist/src/parsers/jsx/function-parser.d.ts +3 -0
- package/dist/src/parsers/jsx/function-parser.js +26 -19
- package/dist/src/parsers/jsx/metadata.js +17 -6
- package/dist/src/parsers/jsx/state.js +4 -1
- package/dist/src/types/mitosis-node.d.ts +6 -4
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -3
|
@@ -85,7 +85,7 @@ var BINDINGS_MAPPER = {
|
|
|
85
85
|
style: 'ngStyle',
|
|
86
86
|
};
|
|
87
87
|
var blockToAngular = function (json, options, blockOptions) {
|
|
88
|
-
var _a, _b, _c, _d, _e, _f;
|
|
88
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
89
89
|
if (options === void 0) { options = {}; }
|
|
90
90
|
if (blockOptions === void 0) { blockOptions = {}; }
|
|
91
91
|
var contextVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.contextVars) || [];
|
|
@@ -153,13 +153,13 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
153
153
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
154
154
|
}
|
|
155
155
|
for (var key in json.bindings) {
|
|
156
|
-
if (key === '
|
|
156
|
+
if (((_g = json.bindings[key]) === null || _g === void 0 ? void 0 : _g.type) === 'spread') {
|
|
157
157
|
continue;
|
|
158
158
|
}
|
|
159
159
|
if (key.startsWith('$')) {
|
|
160
160
|
continue;
|
|
161
161
|
}
|
|
162
|
-
var
|
|
162
|
+
var _h = json.bindings[key], code = _h.code, _j = _h.arguments, cusArgs = _j === void 0 ? ['event'] : _j;
|
|
163
163
|
// TODO: proper babel transform to replace. Util for this
|
|
164
164
|
var useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
165
165
|
contextVars: contextVars,
|
|
@@ -191,7 +191,7 @@ var addOnChangeJs = function (id, options, code) {
|
|
|
191
191
|
};
|
|
192
192
|
// TODO: spread support
|
|
193
193
|
var blockToHtml = function (json, options, blockOptions) {
|
|
194
|
-
var _a, _b, _c, _d, _e, _f;
|
|
194
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
195
195
|
if (blockOptions === void 0) { blockOptions = {}; }
|
|
196
196
|
var ComponentName = blockOptions.ComponentName;
|
|
197
197
|
var scopeVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.scopeVars) || [];
|
|
@@ -280,11 +280,11 @@ var blockToHtml = function (json, options, blockOptions) {
|
|
|
280
280
|
var injectOnce = false;
|
|
281
281
|
var startInjectVar = '%%START_VARS%%';
|
|
282
282
|
for (var key in json.bindings) {
|
|
283
|
-
if (key === '
|
|
283
|
+
if (((_e = json.bindings[key]) === null || _e === void 0 ? void 0 : _e.type) === 'spread' || key === 'css') {
|
|
284
284
|
continue;
|
|
285
285
|
}
|
|
286
|
-
var value = (
|
|
287
|
-
var cusArg = ((
|
|
286
|
+
var value = (_f = json.bindings[key]) === null || _f === void 0 ? void 0 : _f.code;
|
|
287
|
+
var cusArg = ((_g = json.bindings[key]) === null || _g === void 0 ? void 0 : _g.arguments) || ['event'];
|
|
288
288
|
// TODO: proper babel transform to replace. Util for this
|
|
289
289
|
var useValue = value;
|
|
290
290
|
if (key.startsWith('on')) {
|
|
@@ -41,7 +41,7 @@ var getCustomTagName = function (name, options) {
|
|
|
41
41
|
return kebabCaseName;
|
|
42
42
|
};
|
|
43
43
|
var blockToLit = function (json, options) {
|
|
44
|
-
var _a, _b, _c, _d
|
|
44
|
+
var _a, _b, _c, _d;
|
|
45
45
|
if (options === void 0) { options = {}; }
|
|
46
46
|
if (json.properties._text) {
|
|
47
47
|
return json.properties._text;
|
|
@@ -68,19 +68,19 @@ var blockToLit = function (json, options) {
|
|
|
68
68
|
if (classString) {
|
|
69
69
|
str += " class=".concat(classString, " ");
|
|
70
70
|
}
|
|
71
|
-
if ((_e = json.bindings._spread) === null || _e === void 0 ? void 0 : _e.code) {
|
|
72
|
-
str += " ${spread(".concat(json.bindings._spread.code, ")} ");
|
|
73
|
-
}
|
|
74
71
|
for (var key in json.properties) {
|
|
75
72
|
var value = json.properties[key];
|
|
76
73
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
77
74
|
}
|
|
78
75
|
for (var key in json.bindings) {
|
|
79
|
-
var
|
|
80
|
-
if (key === '
|
|
76
|
+
var _e = json.bindings[key], code = _e.code, _f = _e.arguments, cusArgs = _f === void 0 ? ['event'] : _f, type = _e.type;
|
|
77
|
+
if (key === '_forName') {
|
|
81
78
|
continue;
|
|
82
79
|
}
|
|
83
|
-
if (
|
|
80
|
+
if (type === 'spread') {
|
|
81
|
+
str += " ${spread(".concat(code, ")} ");
|
|
82
|
+
}
|
|
83
|
+
else if (key === 'ref') {
|
|
84
84
|
// TODO: maybe use ref directive instead
|
|
85
85
|
// https://lit.dev/docs/templates/directives/#ref
|
|
86
86
|
str += " ref=\"".concat(code, "\" ");
|
|
@@ -160,7 +160,7 @@ var componentToLit = function (options) {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
var html = json.children.map(function (item) { return blockToLit(item, options); }).join('\n');
|
|
163
|
-
var hasSpread = (0, has_1.has)(json, function (node) { return
|
|
163
|
+
var hasSpread = (0, has_1.has)(json, function (node) { return (0, lodash_1.some)(node.bindings, { type: 'spread' }); });
|
|
164
164
|
if (options.prettier !== false) {
|
|
165
165
|
try {
|
|
166
166
|
css = (0, standalone_1.format)(css, {
|
|
@@ -48,7 +48,7 @@ function getStatePropertyNames(json) {
|
|
|
48
48
|
return Object.keys(json.state).filter(function (key) { var _a; return ((_a = json.state[key]) === null || _a === void 0 ? void 0 : _a.type) === 'property'; });
|
|
49
49
|
}
|
|
50
50
|
var blockToMarko = function (json, options) {
|
|
51
|
-
var _a, _b, _c, _d, _e
|
|
51
|
+
var _a, _b, _c, _d, _e;
|
|
52
52
|
if (json.properties._text) {
|
|
53
53
|
return json.properties._text;
|
|
54
54
|
}
|
|
@@ -73,19 +73,19 @@ var blockToMarko = function (json, options) {
|
|
|
73
73
|
}
|
|
74
74
|
var str = '';
|
|
75
75
|
str += "<".concat(json.name, " ");
|
|
76
|
-
if ((_e = json.bindings._spread) === null || _e === void 0 ? void 0 : _e.code) {
|
|
77
|
-
str += " ...(".concat(json.bindings._spread.code, ") ");
|
|
78
|
-
}
|
|
79
76
|
for (var key in json.properties) {
|
|
80
77
|
var value = json.properties[key];
|
|
81
78
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
82
79
|
}
|
|
83
80
|
for (var key in json.bindings) {
|
|
84
|
-
var
|
|
85
|
-
if (key === '
|
|
81
|
+
var _f = json.bindings[key], code = _f.code, _g = _f.arguments, cusArgs = _g === void 0 ? ['event'] : _g, type = _f.type;
|
|
82
|
+
if (key === '_forName') {
|
|
86
83
|
continue;
|
|
87
84
|
}
|
|
88
|
-
if (
|
|
85
|
+
if (type === 'spread') {
|
|
86
|
+
str += " ...(".concat(code, ") ");
|
|
87
|
+
}
|
|
88
|
+
else if (key === 'ref') {
|
|
89
89
|
str += " key=\"".concat((0, lodash_1.camelCase)(code), "\" ");
|
|
90
90
|
}
|
|
91
91
|
else if (key.startsWith('on')) {
|
|
@@ -100,7 +100,7 @@ var blockToMarko = function (json, options) {
|
|
|
100
100
|
return str + ' />';
|
|
101
101
|
}
|
|
102
102
|
str += '>';
|
|
103
|
-
if ((
|
|
103
|
+
if ((_e = json.bindings.innerHTML) === null || _e === void 0 ? void 0 : _e.code) {
|
|
104
104
|
str += "$!{".concat(processBinding(options.component, json.bindings.innerHTML.code), "}");
|
|
105
105
|
}
|
|
106
106
|
if (json.children) {
|
|
@@ -47,7 +47,7 @@ var isValidAttributeName = function (str) {
|
|
|
47
47
|
return Boolean(str && /^[$a-z0-9\-_:]+$/i.test(str));
|
|
48
48
|
};
|
|
49
49
|
var blockToMitosis = function (json, toMitosisOptions) {
|
|
50
|
-
var _a, _b, _c, _d, _e;
|
|
50
|
+
var _a, _b, _c, _d, _e, _f;
|
|
51
51
|
if (toMitosisOptions === void 0) { toMitosisOptions = {}; }
|
|
52
52
|
var options = __assign({ format: exports.DEFAULT_FORMAT }, toMitosisOptions);
|
|
53
53
|
if (options.format === 'react') {
|
|
@@ -70,9 +70,6 @@ var blockToMitosis = function (json, toMitosisOptions) {
|
|
|
70
70
|
}
|
|
71
71
|
var str = '';
|
|
72
72
|
str += "<".concat(json.name, " ");
|
|
73
|
-
if ((_d = json.bindings._spread) === null || _d === void 0 ? void 0 : _d.code) {
|
|
74
|
-
str += " {...(".concat(json.bindings._spread.code, ")} ");
|
|
75
|
-
}
|
|
76
73
|
for (var key in json.properties) {
|
|
77
74
|
var value = (json.properties[key] || '').replace(/"/g, '"').replace(/\n/g, '\\n');
|
|
78
75
|
if (!isValidAttributeName(key)) {
|
|
@@ -83,11 +80,11 @@ var blockToMitosis = function (json, toMitosisOptions) {
|
|
|
83
80
|
}
|
|
84
81
|
}
|
|
85
82
|
for (var key in json.bindings) {
|
|
86
|
-
var value = (
|
|
87
|
-
if (key === '
|
|
88
|
-
|
|
83
|
+
var value = (_d = json.bindings[key]) === null || _d === void 0 ? void 0 : _d.code;
|
|
84
|
+
if (((_e = json.bindings[key]) === null || _e === void 0 ? void 0 : _e.type) === 'spread') {
|
|
85
|
+
str += " {...(".concat((_f = json.bindings[key]) === null || _f === void 0 ? void 0 : _f.code, ")} ");
|
|
89
86
|
}
|
|
90
|
-
if (key.startsWith('on')) {
|
|
87
|
+
else if (key.startsWith('on')) {
|
|
91
88
|
str += " ".concat(key, "={event => ").concat(value.replace(/\s*;$/, ''), "} ");
|
|
92
89
|
}
|
|
93
90
|
else {
|
|
@@ -76,7 +76,7 @@ var componentToQwik = function (userOptions) {
|
|
|
76
76
|
emitTagNameHack(file, component, (_b = component.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.componentElementTag);
|
|
77
77
|
emitJSX(file, component, mutable_1);
|
|
78
78
|
},
|
|
79
|
-
], [component.propsTypeRef + (isLightComponent ? '&{key?:any}' : '')
|
|
79
|
+
], [(component.propsTypeRef || 'any') + (isLightComponent ? '&{key?:any}' : '')]);
|
|
80
80
|
file.src.const(component.name, isLightComponent
|
|
81
81
|
? componentFn
|
|
82
82
|
: (0, src_generator_1.invoke)(file.import(file.qwikModule, 'component$'), [componentFn]), true, true);
|
|
@@ -183,7 +183,7 @@ function isSlotProjection(child) {
|
|
|
183
183
|
* @returns
|
|
184
184
|
*/
|
|
185
185
|
function rewriteHandlers(file, handlers, bindings, symbolBindings, mutablePredicate) {
|
|
186
|
-
var _a;
|
|
186
|
+
var _a, _b;
|
|
187
187
|
var outBindings = {};
|
|
188
188
|
for (var key in bindings) {
|
|
189
189
|
if (Object.prototype.hasOwnProperty.call(bindings, key)) {
|
|
@@ -211,7 +211,7 @@ function rewriteHandlers(file, handlers, bindings, symbolBindings, mutablePredic
|
|
|
211
211
|
file.import(file.qwikModule, 'mutable');
|
|
212
212
|
bindingExpr = "mutable(".concat(bindingExpr, ")");
|
|
213
213
|
}
|
|
214
|
-
outBindings[key] = { code: bindingExpr };
|
|
214
|
+
outBindings[key] = { code: bindingExpr, type: (_b = bindings === null || bindings === void 0 ? void 0 : bindings[key]) === null || _b === void 0 ? void 0 : _b.type };
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
}
|
|
@@ -301,7 +301,7 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
var _loop_1 = function (rawKey) {
|
|
304
|
-
if (rawKey === '
|
|
304
|
+
if (bindings[rawKey].type === 'spread') {
|
|
305
305
|
if (this_1.isJSX) {
|
|
306
306
|
this_1.emit('{...', bindings[rawKey].code, '}');
|
|
307
307
|
}
|
|
@@ -145,9 +145,6 @@ var blockToReact = function (json, options, parentSlots) {
|
|
|
145
145
|
}
|
|
146
146
|
var str = '';
|
|
147
147
|
str += "<".concat(json.name, " ");
|
|
148
|
-
if ((_b = json.bindings._spread) === null || _b === void 0 ? void 0 : _b.code) {
|
|
149
|
-
str += " {...(".concat((0, helpers_2.processBinding)(json.bindings._spread.code, options), ")} ");
|
|
150
|
-
}
|
|
151
148
|
for (var key in json.properties) {
|
|
152
149
|
var value = (json.properties[key] || '').replace(/"/g, '"').replace(/\n/g, '\\n');
|
|
153
150
|
if (key === 'class') {
|
|
@@ -170,15 +167,15 @@ var blockToReact = function (json, options, parentSlots) {
|
|
|
170
167
|
}
|
|
171
168
|
}
|
|
172
169
|
for (var key in json.bindings) {
|
|
173
|
-
var value = String((
|
|
174
|
-
if (key === '_spread') {
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
170
|
+
var value = String((_b = json.bindings[key]) === null || _b === void 0 ? void 0 : _b.code);
|
|
177
171
|
if (key === 'css' && value.trim() === '{}') {
|
|
178
172
|
continue;
|
|
179
173
|
}
|
|
180
174
|
var useBindingValue = (0, helpers_2.processBinding)(value, options);
|
|
181
|
-
if (key.
|
|
175
|
+
if (((_c = json.bindings[key]) === null || _c === void 0 ? void 0 : _c.type) === 'spread') {
|
|
176
|
+
str += " {...(".concat(value, ")} ");
|
|
177
|
+
}
|
|
178
|
+
else if (key.startsWith('on')) {
|
|
182
179
|
var _e = json.bindings[key].arguments, cusArgs = _e === void 0 ? ['event'] : _e;
|
|
183
180
|
str += " ".concat(key, "={(").concat(cusArgs.join(','), ") => ").concat((0, state_2.updateStateSettersInCode)(useBindingValue, options), " } ");
|
|
184
181
|
}
|
|
@@ -77,6 +77,7 @@ var updateStateSetters = function (json, options) {
|
|
|
77
77
|
item.bindings[key] = {
|
|
78
78
|
code: newValue,
|
|
79
79
|
arguments: values === null || values === void 0 ? void 0 : values.arguments,
|
|
80
|
+
type: values === null || values === void 0 ? void 0 : values.type,
|
|
80
81
|
};
|
|
81
82
|
}
|
|
82
83
|
}
|
|
@@ -160,12 +160,13 @@ var preProcessBlockCode = function (_a) {
|
|
|
160
160
|
json.bindings[key] = {
|
|
161
161
|
arguments: value.arguments,
|
|
162
162
|
code: (0, helpers_2.updateStateCode)({ options: options, component: component, updateSetters: true })(value.code),
|
|
163
|
+
type: value === null || value === void 0 ? void 0 : value.type,
|
|
163
164
|
};
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
167
|
};
|
|
167
168
|
var blockToSolid = function (_a) {
|
|
168
|
-
var _b, _c
|
|
169
|
+
var _b, _c;
|
|
169
170
|
var json = _a.json, options = _a.options, component = _a.component;
|
|
170
171
|
preProcessBlockCode({ json: json, options: options, component: component });
|
|
171
172
|
if (json.properties._text) {
|
|
@@ -196,21 +197,21 @@ var blockToSolid = function (_a) {
|
|
|
196
197
|
if (classString) {
|
|
197
198
|
str += " class=".concat(classString, " ");
|
|
198
199
|
}
|
|
199
|
-
if ((_d = json.bindings._spread) === null || _d === void 0 ? void 0 : _d.code) {
|
|
200
|
-
str += " {...(".concat(json.bindings._spread.code, ")} ");
|
|
201
|
-
}
|
|
202
200
|
for (var key in json.properties) {
|
|
203
201
|
var value = json.properties[key];
|
|
204
202
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
205
203
|
}
|
|
206
204
|
for (var key in json.bindings) {
|
|
207
|
-
var
|
|
208
|
-
if (key === '
|
|
205
|
+
var _d = json.bindings[key], code = _d.code, _e = _d.arguments, cusArg = _e === void 0 ? ['event'] : _e, type = _d.type;
|
|
206
|
+
if (key === '_forName') {
|
|
209
207
|
continue;
|
|
210
208
|
}
|
|
211
209
|
if (!code)
|
|
212
210
|
continue;
|
|
213
|
-
if (
|
|
211
|
+
if (type === 'spread') {
|
|
212
|
+
str += " {...(".concat(code, ")} ");
|
|
213
|
+
}
|
|
214
|
+
else if (key.startsWith('on')) {
|
|
214
215
|
var useKey = key === 'onChange' && json.name === 'input' ? 'onInput' : key;
|
|
215
216
|
str += " ".concat(useKey, "={(").concat(cusArg.join(','), ") => ").concat(code, "} ");
|
|
216
217
|
}
|
|
@@ -350,9 +351,6 @@ var componentToSolid = function (passedOptions) {
|
|
|
350
351
|
? // We add the jsx attribute so prettier formats this nicely
|
|
351
352
|
"<style jsx>{`".concat(css, "`}</style>")
|
|
352
353
|
: '', addWrapper ? '</>' : '', json.name);
|
|
353
|
-
// HACK: for some reason we are generating `state.state.foo` instead of `state.foo`
|
|
354
|
-
// need a full fix, but this unblocks a lot in the short term
|
|
355
|
-
str = str.replace(/state\.state\./g, 'state.');
|
|
356
354
|
if (options.plugins) {
|
|
357
355
|
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
358
356
|
}
|
|
@@ -27,7 +27,7 @@ var indent_1 = require("../../helpers/indent");
|
|
|
27
27
|
var map_refs_1 = require("../../helpers/map-refs");
|
|
28
28
|
var for_1 = require("../../helpers/nodes/for");
|
|
29
29
|
var blockToStencil = function (json, options) {
|
|
30
|
-
var _a, _b, _c, _d
|
|
30
|
+
var _a, _b, _c, _d;
|
|
31
31
|
if (options === void 0) { options = {}; }
|
|
32
32
|
if (json.properties._text) {
|
|
33
33
|
return json.properties._text;
|
|
@@ -56,19 +56,19 @@ var blockToStencil = function (json, options) {
|
|
|
56
56
|
if (classString) {
|
|
57
57
|
str += " class=".concat(classString, " ");
|
|
58
58
|
}
|
|
59
|
-
if ((_e = json.bindings._spread) === null || _e === void 0 ? void 0 : _e.code) {
|
|
60
|
-
str += " {...(".concat(json.bindings._spread.code, ")} ");
|
|
61
|
-
}
|
|
62
59
|
for (var key in json.properties) {
|
|
63
60
|
var value = json.properties[key];
|
|
64
61
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
65
62
|
}
|
|
66
63
|
for (var key in json.bindings) {
|
|
67
|
-
var
|
|
68
|
-
if (key === '
|
|
64
|
+
var _e = json.bindings[key], code = _e.code, _f = _e.arguments, cusArgs = _f === void 0 ? ['event'] : _f, type = _e.type;
|
|
65
|
+
if (key === '_forName') {
|
|
69
66
|
continue;
|
|
70
67
|
}
|
|
71
|
-
if (
|
|
68
|
+
if (type === 'spread') {
|
|
69
|
+
str += " {...(".concat(code, ")} ");
|
|
70
|
+
}
|
|
71
|
+
else if (key === 'ref') {
|
|
72
72
|
str += " ref={(el) => this.".concat(code, " = el} ");
|
|
73
73
|
}
|
|
74
74
|
else if (key.startsWith('on')) {
|
|
@@ -173,7 +173,7 @@ var stripStateAndProps = function (code, options) {
|
|
|
173
173
|
});
|
|
174
174
|
};
|
|
175
175
|
var blockToSvelte = function (_a) {
|
|
176
|
-
var _b, _c, _d, _e
|
|
176
|
+
var _b, _c, _d, _e;
|
|
177
177
|
var json = _a.json, options = _a.options, parentComponent = _a.parentComponent;
|
|
178
178
|
if (mappers[json.name]) {
|
|
179
179
|
return mappers[json.name]({
|
|
@@ -199,12 +199,9 @@ var blockToSvelte = function (_a) {
|
|
|
199
199
|
}
|
|
200
200
|
var str = '';
|
|
201
201
|
str += "<".concat(tagName, " ");
|
|
202
|
-
if ((_c = json.bindings._spread) === null || _c === void 0 ? void 0 : _c.code) {
|
|
203
|
-
str += "{...".concat(stripStateAndProps(json.bindings._spread.code, options), "}");
|
|
204
|
-
}
|
|
205
202
|
var isComponent = Boolean(tagName[0] && (0, is_upper_case_1.isUpperCase)(tagName[0]));
|
|
206
|
-
if ((((
|
|
207
|
-
var useValue = stripStateAndProps(((
|
|
203
|
+
if ((((_c = json.bindings.style) === null || _c === void 0 ? void 0 : _c.code) || json.properties.style) && !isComponent) {
|
|
204
|
+
var useValue = stripStateAndProps(((_d = json.bindings.style) === null || _d === void 0 ? void 0 : _d.code) || json.properties.style, options);
|
|
208
205
|
str += "use:mitosis_styling={".concat(useValue, "}");
|
|
209
206
|
delete json.bindings.style;
|
|
210
207
|
delete json.properties.style;
|
|
@@ -217,13 +214,17 @@ var blockToSvelte = function (_a) {
|
|
|
217
214
|
if (key === 'innerHTML') {
|
|
218
215
|
continue;
|
|
219
216
|
}
|
|
220
|
-
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
var _g = json.bindings[key], value = _g.code, _h = _g.arguments, cusArgs = _h === void 0 ? ['event'] : _h;
|
|
217
|
+
var _f = json.bindings[key], value = _f.code, _g = _f.arguments, cusArgs = _g === void 0 ? ['event'] : _g, type = _f.type;
|
|
224
218
|
// TODO: proper babel transform to replace. Util for this
|
|
225
219
|
var useValue = stripStateAndProps(value, options);
|
|
226
|
-
if (
|
|
220
|
+
if (type === 'spread') {
|
|
221
|
+
str += ' {...';
|
|
222
|
+
if (key === 'props') {
|
|
223
|
+
str += "$$";
|
|
224
|
+
}
|
|
225
|
+
str += "".concat(useValue, "}");
|
|
226
|
+
}
|
|
227
|
+
else if (key.startsWith('on')) {
|
|
227
228
|
var event_1 = key.replace('on', '').toLowerCase();
|
|
228
229
|
// TODO: handle quotes in event handler values
|
|
229
230
|
var valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(useValue);
|
|
@@ -243,7 +244,7 @@ var blockToSvelte = function (_a) {
|
|
|
243
244
|
}
|
|
244
245
|
// if we have innerHTML, it doesn't matter whether we have closing tags or not, or children or not.
|
|
245
246
|
// we use the innerHTML content as children and don't render the self-closing tag.
|
|
246
|
-
if ((
|
|
247
|
+
if ((_e = json.bindings.innerHTML) === null || _e === void 0 ? void 0 : _e.code) {
|
|
247
248
|
str += '>';
|
|
248
249
|
str += BINDINGS_MAPPER.innerHTML(json, options);
|
|
249
250
|
str += "</".concat(tagName, ">");
|
|
@@ -23,7 +23,7 @@ var mappers = {
|
|
|
23
23
|
};
|
|
24
24
|
// TODO: spread support
|
|
25
25
|
var blockToTemplate = function (json, options) {
|
|
26
|
-
var _a, _b, _c, _d;
|
|
26
|
+
var _a, _b, _c, _d, _e;
|
|
27
27
|
if (options === void 0) { options = {}; }
|
|
28
28
|
if (mappers[json.name]) {
|
|
29
29
|
return mappers[json.name](json, options);
|
|
@@ -64,10 +64,10 @@ var blockToTemplate = function (json, options) {
|
|
|
64
64
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
65
65
|
}
|
|
66
66
|
for (var key in json.bindings) {
|
|
67
|
-
if (key === '
|
|
67
|
+
if (((_d = json.bindings[key]) === null || _d === void 0 ? void 0 : _d.type) === 'spread' || key === 'ref' || key === 'css') {
|
|
68
68
|
continue;
|
|
69
69
|
}
|
|
70
|
-
var value = (
|
|
70
|
+
var value = (_e = json.bindings[key]) === null || _e === void 0 ? void 0 : _e.code;
|
|
71
71
|
// TODO: proper babel transform to replace. Util for this
|
|
72
72
|
var useValue = value;
|
|
73
73
|
if (key.startsWith('on')) {
|
|
@@ -16,6 +16,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.blockToVue = void 0;
|
|
18
18
|
var function_1 = require("fp-ts/lib/function");
|
|
19
|
+
var lodash_1 = require("lodash");
|
|
19
20
|
var filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
|
|
20
21
|
var is_children_1 = __importDefault(require("../../helpers/is-children"));
|
|
21
22
|
var is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
@@ -186,9 +187,10 @@ var NODE_MAPPERS = {
|
|
|
186
187
|
};
|
|
187
188
|
var stringifyBinding = function (node) {
|
|
188
189
|
return function (_a) {
|
|
190
|
+
var _b;
|
|
189
191
|
var key = _a[0], value = _a[1];
|
|
190
|
-
if (key === '
|
|
191
|
-
return '';
|
|
192
|
+
if (((_b = node.bindings[key]) === null || _b === void 0 ? void 0 : _b.type) === 'spread') {
|
|
193
|
+
return ''; // we handle this after
|
|
192
194
|
}
|
|
193
195
|
else if (key === 'class') {
|
|
194
196
|
return " :class=\"_classStringToObject(".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value === null || value === void 0 ? void 0 : value.code, {
|
|
@@ -201,7 +203,7 @@ var stringifyBinding = function (node) {
|
|
|
201
203
|
// TODO: proper babel transform to replace. Util for this
|
|
202
204
|
var useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value === null || value === void 0 ? void 0 : value.code);
|
|
203
205
|
if (key.startsWith('on')) {
|
|
204
|
-
var
|
|
206
|
+
var _c = value.arguments, cusArgs = _c === void 0 ? ['event'] : _c;
|
|
205
207
|
var event_1 = key.replace('on', '').toLowerCase();
|
|
206
208
|
if (event_1 === 'change' && node.name === 'input') {
|
|
207
209
|
event_1 = 'input';
|
|
@@ -233,7 +235,7 @@ var stringifyBinding = function (node) {
|
|
|
233
235
|
};
|
|
234
236
|
};
|
|
235
237
|
var blockToVue = function (node, options, scope) {
|
|
236
|
-
var _a
|
|
238
|
+
var _a;
|
|
237
239
|
var nodeMapper = NODE_MAPPERS[node.name];
|
|
238
240
|
if (nodeMapper) {
|
|
239
241
|
return nodeMapper(node, options, scope);
|
|
@@ -260,9 +262,6 @@ var blockToVue = function (node, options, scope) {
|
|
|
260
262
|
}
|
|
261
263
|
var str = '';
|
|
262
264
|
str += "<".concat(node.name, " ");
|
|
263
|
-
if ((_b = node.bindings._spread) === null || _b === void 0 ? void 0 : _b.code) {
|
|
264
|
-
str += "v-bind=\"".concat((0, helpers_1.encodeQuotes)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(node.bindings._spread.code)), "\"");
|
|
265
|
-
}
|
|
266
265
|
for (var key in node.properties) {
|
|
267
266
|
var value = node.properties[key];
|
|
268
267
|
if (key === 'className') {
|
|
@@ -282,6 +281,17 @@ var blockToVue = function (node, options, scope) {
|
|
|
282
281
|
})
|
|
283
282
|
.join('');
|
|
284
283
|
str += stringifiedBindings;
|
|
284
|
+
// spreads
|
|
285
|
+
var spreads = (0, lodash_1.filter)(node.bindings, function (binding) { return (binding === null || binding === void 0 ? void 0 : binding.type) === 'spread'; }).map(function (value) { return value === null || value === void 0 ? void 0 : value.code; });
|
|
286
|
+
if (spreads === null || spreads === void 0 ? void 0 : spreads.length) {
|
|
287
|
+
if (spreads.length > 1) {
|
|
288
|
+
var spreadsString = "{...".concat(spreads.join(', ...'), "}");
|
|
289
|
+
str += " v-bind=\"".concat((0, helpers_1.encodeQuotes)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(spreadsString)), "\"");
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
str += " v-bind=\"".concat((0, helpers_1.encodeQuotes)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(spreads.join(''))), "\"");
|
|
293
|
+
}
|
|
294
|
+
}
|
|
285
295
|
if (jsx_1.selfClosingTags.has(node.name)) {
|
|
286
296
|
return str + ' />';
|
|
287
297
|
}
|
|
@@ -3,6 +3,15 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
3
3
|
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
4
|
return cooked;
|
|
5
5
|
};
|
|
6
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
7
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
8
|
+
if (ar || !(i in from)) {
|
|
9
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
10
|
+
ar[i] = from[i];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
14
|
+
};
|
|
6
15
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
16
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
17
|
};
|
|
@@ -31,17 +40,43 @@ var getCompositionPropDefinition = function (_a) {
|
|
|
31
40
|
}
|
|
32
41
|
return str;
|
|
33
42
|
};
|
|
43
|
+
function shouldAppendValueToRef(path) {
|
|
44
|
+
var parent = path.parent, node = path.node;
|
|
45
|
+
if (core_1.types.isFunctionDeclaration(parent) && parent.id === node) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (core_1.types.isCallExpression(parent)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
var isMemberExpression = core_1.types.isMemberExpression(parent);
|
|
52
|
+
if (isMemberExpression &&
|
|
53
|
+
core_1.types.isThisExpression(parent.object) &&
|
|
54
|
+
core_1.types.isProgram(path.scope.block) &&
|
|
55
|
+
path.scope.hasReference(node.name)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (isMemberExpression &&
|
|
59
|
+
core_1.types.isIdentifier(parent.object) &&
|
|
60
|
+
core_1.types.isIdentifier(parent.property) &&
|
|
61
|
+
parent.property.name === node.name) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
if (Object.keys(path.scope.bindings).includes(path.node.name)) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (path.parentPath.listKey === 'arguments' || path.parentPath.listKey === 'params') {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
34
72
|
function appendValueToRefs(input, component, options) {
|
|
35
|
-
var refKeys = Object.keys(
|
|
73
|
+
var refKeys = Object.keys(component.refs);
|
|
74
|
+
var stateKeys = Object.keys((0, lodash_1.pickBy)(component.state, function (i) { return (i === null || i === void 0 ? void 0 : i.type) === 'property'; }));
|
|
75
|
+
var allKeys = __spreadArray(__spreadArray([], refKeys, true), stateKeys, true);
|
|
36
76
|
var output = (0, helpers_1.processBinding)({ code: input, options: options, json: component, includeProps: false });
|
|
37
77
|
return (0, babel_transform_1.babelTransformExpression)(output, {
|
|
38
78
|
Identifier: function (path) {
|
|
39
|
-
if (
|
|
40
|
-
!core_1.types.isCallExpression(path.parent) &&
|
|
41
|
-
(!core_1.types.isMemberExpression(path.parent) || core_1.types.isThisExpression(path.parent.object)) &&
|
|
42
|
-
path.parentPath.listKey !== 'arguments' &&
|
|
43
|
-
path.parentPath.listKey !== 'params' &&
|
|
44
|
-
refKeys.includes(path.node.name)) {
|
|
79
|
+
if (allKeys.includes(path.node.name) && shouldAppendValueToRef(path)) {
|
|
45
80
|
path.replaceWith(core_1.types.identifier("".concat(path.node.name, ".value")));
|
|
46
81
|
}
|
|
47
82
|
},
|
|
@@ -12,7 +12,12 @@ var allPropsMatchesRegex = new RegExp(propsRegex, 'g');
|
|
|
12
12
|
var prohibitedKeywordRE = new RegExp('\\b' +
|
|
13
13
|
('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
|
|
14
14
|
'super,throw,while,yield,delete,export,import,return,switch,default,' +
|
|
15
|
-
'extends,finally,continue,debugger,function,arguments,typeof,void'
|
|
15
|
+
'extends,finally,continue,debugger,function,arguments,typeof,void,' +
|
|
16
|
+
// both below conditions added based on https://github.com/vuejs/vue/blob/e80cd09fff570df57d608f8f5aaccee6d7f31917/src/core/instance/state.ts#L89-L96
|
|
17
|
+
// below line added from https://github.com/vuejs/vue/blob/8880b55d52f8d873f79ef67436217c8752cddef5/src/shared/util.ts#L130
|
|
18
|
+
'key,ref,slot,slot-scope,is,' +
|
|
19
|
+
// below line added from https://github.com/vuejs/vue/blob/72aed6a149b94b5b929fb47370a7a6d4cb7491c5/src/platforms/web/util/attrs.ts#L5
|
|
20
|
+
'style')
|
|
16
21
|
.split(',')
|
|
17
22
|
.join('\\b|\\b') +
|
|
18
23
|
'\\b');
|
|
@@ -4,6 +4,6 @@ import { MitosisNode } from '../types/mitosis-node';
|
|
|
4
4
|
* Test if the component has something
|
|
5
5
|
*
|
|
6
6
|
* e.g.
|
|
7
|
-
* const hasSpread = has(component, node =>
|
|
7
|
+
* const hasSpread = has(component, node => some(node.bindings, { type: 'spread' }));
|
|
8
8
|
*/
|
|
9
9
|
export declare function has(json: MitosisComponent, test: (node: MitosisNode) => boolean): boolean;
|
package/dist/src/helpers/has.js
CHANGED
|
@@ -10,7 +10,7 @@ var is_mitosis_node_1 = require("./is-mitosis-node");
|
|
|
10
10
|
* Test if the component has something
|
|
11
11
|
*
|
|
12
12
|
* e.g.
|
|
13
|
-
* const hasSpread = has(component, node =>
|
|
13
|
+
* const hasSpread = has(component, node => some(node.bindings, { type: 'spread' }));
|
|
14
14
|
*/
|
|
15
15
|
function has(json, test) {
|
|
16
16
|
var found = false;
|
|
@@ -238,8 +238,10 @@ var jsxElementToJson = function (node) {
|
|
|
238
238
|
// TODO: potentially like Vue store bindings and properties as array of key value pairs
|
|
239
239
|
// too so can do this accurately when order matters. Also tempting to not support spread,
|
|
240
240
|
// as some frameworks do not support it (e.g. Angular) tho Angular may be the only one
|
|
241
|
-
|
|
241
|
+
var key = (0, generator_1.default)(item.argument).code;
|
|
242
|
+
memo[key] = {
|
|
242
243
|
code: types.stringLiteral((0, generator_1.default)(item.argument).code).value,
|
|
244
|
+
type: 'spread',
|
|
243
245
|
};
|
|
244
246
|
}
|
|
245
247
|
return memo;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import * as babel from '@babel/core';
|
|
2
2
|
import { JSONOrNode } from '../../types/json';
|
|
3
|
+
import { MitosisComponent } from '../../types/mitosis-component';
|
|
3
4
|
import { Context } from './types';
|
|
5
|
+
export declare function generateUseStyleCode(expression: babel.types.CallExpression): string;
|
|
6
|
+
export declare function parseDefaultPropsHook(component: MitosisComponent, expression: babel.types.CallExpression): void;
|
|
4
7
|
/**
|
|
5
8
|
* Parses function declarations within the Mitosis copmonent's body to JSON
|
|
6
9
|
*/
|