@builder.io/mitosis 0.5.12 → 0.5.13
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/builder/generator.js +16 -6
- package/dist/src/generators/html/generator.js +16 -15
- package/dist/src/generators/lit/generate.js +4 -3
- package/dist/src/generators/marko/generate.js +6 -5
- package/dist/src/generators/mitosis/generator.js +3 -1
- package/dist/src/generators/react/blocks.js +3 -2
- package/dist/src/generators/solid/blocks.js +3 -2
- package/dist/src/generators/stencil/blocks.js +3 -2
- package/dist/src/generators/svelte/blocks.js +4 -3
- package/dist/src/generators/vue/blocks.js +12 -6
- package/dist/src/parsers/builder/builder.js +11 -2
- package/dist/src/parsers/jsx/element-parser.js +1 -0
- package/dist/src/types/mitosis-node.d.ts +1 -0
- package/package.json +1 -1
|
@@ -240,7 +240,7 @@ function tryFormat(code) {
|
|
|
240
240
|
return str;
|
|
241
241
|
}
|
|
242
242
|
const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
243
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
243
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
244
244
|
const mapper = !_internalOptions.skipMapper && componentMappers[json.name];
|
|
245
245
|
if (mapper) {
|
|
246
246
|
return mapper(json, options);
|
|
@@ -272,8 +272,18 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
|
272
272
|
const eventBindingKeyRegex = /^on([A-Z])/;
|
|
273
273
|
const firstCharMatchForEventBindingKey = (_d = key.match(eventBindingKeyRegex)) === null || _d === void 0 ? void 0 : _d[1];
|
|
274
274
|
if (firstCharMatchForEventBindingKey) {
|
|
275
|
+
let actionBody = ((_e = bindings[key]) === null || _e === void 0 ? void 0 : _e.async)
|
|
276
|
+
? `(async () => ${(_f = bindings[key]) === null || _f === void 0 ? void 0 : _f.code})()`
|
|
277
|
+
: (0, remove_surrounding_block_1.removeSurroundingBlock)((_g = bindings[key]) === null || _g === void 0 ? void 0 : _g.code);
|
|
278
|
+
const eventIdentifier = (_j = (_h = bindings[key]) === null || _h === void 0 ? void 0 : _h.arguments) === null || _j === void 0 ? void 0 : _j[0];
|
|
279
|
+
if (typeof eventIdentifier === 'string' && eventIdentifier !== 'event') {
|
|
280
|
+
actionBody = (0, replace_identifiers_1.replaceNodes)({
|
|
281
|
+
code: actionBody,
|
|
282
|
+
nodeMaps: [{ from: core_1.types.identifier(eventIdentifier), to: core_1.types.identifier('event') }],
|
|
283
|
+
});
|
|
284
|
+
}
|
|
275
285
|
actions[key.replace(eventBindingKeyRegex, firstCharMatchForEventBindingKey.toLowerCase())] =
|
|
276
|
-
|
|
286
|
+
actionBody;
|
|
277
287
|
delete bindings[key];
|
|
278
288
|
}
|
|
279
289
|
}
|
|
@@ -290,7 +300,7 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
|
290
300
|
componentOptions[key] = parsed;
|
|
291
301
|
}
|
|
292
302
|
else {
|
|
293
|
-
if (!((
|
|
303
|
+
if (!((_k = json.slots) === null || _k === void 0 ? void 0 : _k[key])) {
|
|
294
304
|
builderBindings[`component.options.${key}`] = bindings[key].code;
|
|
295
305
|
}
|
|
296
306
|
}
|
|
@@ -299,12 +309,12 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
|
299
309
|
for (const key in json.slots) {
|
|
300
310
|
componentOptions[key] = json.slots[key].map((node) => (0, exports.blockToBuilder)(node, options));
|
|
301
311
|
}
|
|
302
|
-
const hasCss = !!((
|
|
312
|
+
const hasCss = !!((_l = bindings.css) === null || _l === void 0 ? void 0 : _l.code);
|
|
303
313
|
let responsiveStyles = {
|
|
304
314
|
large: {},
|
|
305
315
|
};
|
|
306
316
|
if (hasCss) {
|
|
307
|
-
const cssRules = json5_1.default.parse((
|
|
317
|
+
const cssRules = json5_1.default.parse((_m = bindings.css) === null || _m === void 0 ? void 0 : _m.code);
|
|
308
318
|
const cssRuleKeys = Object.keys(cssRules);
|
|
309
319
|
for (const ruleKey of cssRuleKeys) {
|
|
310
320
|
const mediaQueryMatch = ruleKey.match(media_sizes_1.mediaQueryRegex);
|
|
@@ -328,7 +338,7 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
|
328
338
|
}
|
|
329
339
|
if (thisIsComponent) {
|
|
330
340
|
for (const key in json.bindings) {
|
|
331
|
-
if (!((
|
|
341
|
+
if (!((_o = json.slots) === null || _o === void 0 ? void 0 : _o[key])) {
|
|
332
342
|
builderBindings[`component.options.${key}`] = json.bindings[key].code;
|
|
333
343
|
}
|
|
334
344
|
}
|
|
@@ -192,7 +192,7 @@ const addOnChangeJs = (id, options, code) => {
|
|
|
192
192
|
};
|
|
193
193
|
// TODO: spread support
|
|
194
194
|
const blockToHtml = (json, options, blockOptions = {}) => {
|
|
195
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
195
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
196
196
|
const ComponentName = blockOptions.ComponentName;
|
|
197
197
|
const scopeVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.scopeVars) || [];
|
|
198
198
|
const childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
|
|
@@ -303,11 +303,12 @@ const blockToHtml = (json, options, blockOptions = {}) => {
|
|
|
303
303
|
}
|
|
304
304
|
const fnName = (0, lodash_1.camelCase)(`on-${elId}-${event}`);
|
|
305
305
|
const codeContent = (0, remove_surrounding_block_1.removeSurroundingBlock)(updateReferencesInCode(useValue, options, blockOptions));
|
|
306
|
+
const asyncKeyword = ((_h = json.bindings[key]) === null || _h === void 0 ? void 0 : _h.async) ? 'async ' : '';
|
|
306
307
|
options.js += `
|
|
307
308
|
// Event handler for '${event}' event on ${elId}
|
|
308
309
|
${options.format === 'class'
|
|
309
|
-
? `this.${fnName} = (${cusArg.join(',')}) => {`
|
|
310
|
-
:
|
|
310
|
+
? `this.${fnName} = ${asyncKeyword}(${cusArg.join(',')}) => {`
|
|
311
|
+
: `${asyncKeyword}function ${fnName} (${cusArg.join(',')}) {`}
|
|
311
312
|
${addScopeVars(scopeVars, codeContent, (scopeVar) => `const ${scopeVar} = ${options.format === 'class' ? 'this.' : ''}getScope(event.currentTarget, "${scopeVar}");`)}
|
|
312
313
|
${codeContent}
|
|
313
314
|
}
|
|
@@ -469,7 +470,7 @@ const componentToHtml = (_options = {}) => ({ component }) => {
|
|
|
469
470
|
${!hasChangeListeners
|
|
470
471
|
? ''
|
|
471
472
|
: `
|
|
472
|
-
|
|
473
|
+
|
|
473
474
|
// Function to update data bindings and loops
|
|
474
475
|
// call update() when you mutate state and need the updates to reflect
|
|
475
476
|
// in the dom
|
|
@@ -500,7 +501,7 @@ const componentToHtml = (_options = {}) => ({ component }) => {
|
|
|
500
501
|
${json.hooks.onUpdate.reduce((code, hook) => {
|
|
501
502
|
code += addUpdateAfterSetInCode(updateReferencesInCode(hook.code, options), options);
|
|
502
503
|
return code + '\n';
|
|
503
|
-
}, '')}
|
|
504
|
+
}, '')}
|
|
504
505
|
`}
|
|
505
506
|
|
|
506
507
|
pendingUpdate = false;
|
|
@@ -526,7 +527,7 @@ const componentToHtml = (_options = {}) => ({ component }) => {
|
|
|
526
527
|
: // TODO: make prettier by grabbing only the function body
|
|
527
528
|
`
|
|
528
529
|
// onMount
|
|
529
|
-
${updateReferencesInCode(addUpdateAfterSetInCode((0, on_mount_1.stringifySingleScopeOnMount)(json), options), options)}
|
|
530
|
+
${updateReferencesInCode(addUpdateAfterSetInCode((0, on_mount_1.stringifySingleScopeOnMount)(json), options), options)}
|
|
530
531
|
`}
|
|
531
532
|
|
|
532
533
|
${!hasShow
|
|
@@ -537,8 +538,8 @@ const componentToHtml = (_options = {}) => ({ component }) => {
|
|
|
537
538
|
// grabs the content of a node that is between <template> tags
|
|
538
539
|
// iterates through child nodes to register all content including text elements
|
|
539
540
|
// attaches the content after the template
|
|
540
|
-
|
|
541
|
-
|
|
541
|
+
|
|
542
|
+
|
|
542
543
|
const elementFragment = el.content.cloneNode(true);
|
|
543
544
|
const children = Array.from(elementFragment.childNodes)
|
|
544
545
|
children.forEach(child => {
|
|
@@ -552,7 +553,7 @@ const componentToHtml = (_options = {}) => ({ component }) => {
|
|
|
552
553
|
});
|
|
553
554
|
el.after(elementFragment);
|
|
554
555
|
}
|
|
555
|
-
|
|
556
|
+
|
|
556
557
|
`}
|
|
557
558
|
${!hasTextBinding
|
|
558
559
|
? ''
|
|
@@ -770,9 +771,9 @@ const componentToCustomElement = (_options = {}) => ({ component }) => {
|
|
|
770
771
|
})}
|
|
771
772
|
/**
|
|
772
773
|
* Usage:
|
|
773
|
-
*
|
|
774
|
+
*
|
|
774
775
|
* <${kebabName}></${kebabName}>
|
|
775
|
-
*
|
|
776
|
+
*
|
|
776
777
|
*/
|
|
777
778
|
class ${ComponentName} extends ${((_h = options === null || options === void 0 ? void 0 : options.experimental) === null || _h === void 0 ? void 0 : _h.classExtends)
|
|
778
779
|
? (_j = options === null || options === void 0 ? void 0 : options.experimental) === null || _j === void 0 ? void 0 : _j.classExtends(json, options)
|
|
@@ -940,8 +941,8 @@ const componentToCustomElement = (_options = {}) => ({ component }) => {
|
|
|
940
941
|
// grabs the content of a node that is between <template> tags
|
|
941
942
|
// iterates through child nodes to register all content including text elements
|
|
942
943
|
// attaches the content after the template
|
|
943
|
-
|
|
944
|
-
|
|
944
|
+
|
|
945
|
+
|
|
945
946
|
const elementFragment = el.content.cloneNode(true);
|
|
946
947
|
const children = Array.from(elementFragment.childNodes)
|
|
947
948
|
children.forEach(child => {
|
|
@@ -1008,7 +1009,7 @@ const componentToCustomElement = (_options = {}) => ({ component }) => {
|
|
|
1008
1009
|
`;
|
|
1009
1010
|
}
|
|
1010
1011
|
return code + '\n';
|
|
1011
|
-
}, '')}
|
|
1012
|
+
}, '')}
|
|
1012
1013
|
`}
|
|
1013
1014
|
}
|
|
1014
1015
|
|
|
@@ -1099,7 +1100,7 @@ const componentToCustomElement = (_options = {}) => ({ component }) => {
|
|
|
1099
1100
|
? `
|
|
1100
1101
|
${(_g = options === null || options === void 0 ? void 0 : options.experimental) === null || _g === void 0 ? void 0 : _g.generateQuerySelectorAll(key, code)}
|
|
1101
1102
|
`
|
|
1102
|
-
: `
|
|
1103
|
+
: `
|
|
1103
1104
|
this._root.querySelectorAll("[data-el='${key}']").forEach((el) => {
|
|
1104
1105
|
${code}
|
|
1105
1106
|
})
|
|
@@ -36,7 +36,7 @@ const getCustomTagName = (name, options) => {
|
|
|
36
36
|
return kebabCaseName;
|
|
37
37
|
};
|
|
38
38
|
const blockToLit = (json, options = {}) => {
|
|
39
|
-
var _a, _b, _c, _d, _e, _f;
|
|
39
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
40
40
|
if (json.properties._text) {
|
|
41
41
|
return json.properties._text;
|
|
42
42
|
}
|
|
@@ -82,8 +82,9 @@ const blockToLit = (json, options = {}) => {
|
|
|
82
82
|
}
|
|
83
83
|
else if (key.startsWith('on')) {
|
|
84
84
|
let useKey = key === 'onChange' && json.name === 'input' ? 'onInput' : key;
|
|
85
|
+
const asyncKeyword = ((_g = json.bindings[key]) === null || _g === void 0 ? void 0 : _g.async) ? 'async ' : '';
|
|
85
86
|
useKey = '@' + useKey.substring(2).toLowerCase();
|
|
86
|
-
str += ` ${useKey}=\${${cusArgs.join(',')} => ${processBinding(code)}} `;
|
|
87
|
+
str += ` ${useKey}=\${${asyncKeyword}(${cusArgs.join(',')}) => ${processBinding(code)}} `;
|
|
87
88
|
}
|
|
88
89
|
else {
|
|
89
90
|
const value = processBinding(code);
|
|
@@ -172,7 +173,7 @@ const componentToLit = (_options = {}) => ({ component }) => {
|
|
|
172
173
|
}
|
|
173
174
|
catch (err) {
|
|
174
175
|
// If can't format HTML (this can happen with lit given it is tagged template strings),
|
|
175
|
-
// at least remove excess
|
|
176
|
+
// at least remove excess fspace
|
|
176
177
|
html = html.replace(/\n{3,}/g, '\n\n');
|
|
177
178
|
}
|
|
178
179
|
}
|
|
@@ -69,7 +69,7 @@ const blockToMarko = (json, options) => {
|
|
|
69
69
|
str += ` ${key}="${value}" `;
|
|
70
70
|
}
|
|
71
71
|
for (const key in json.bindings) {
|
|
72
|
-
const { code, arguments: cusArgs = ['event'], type } = json.bindings[key];
|
|
72
|
+
const { code, arguments: cusArgs = ['event'], type, async } = json.bindings[key];
|
|
73
73
|
if (type === 'spread') {
|
|
74
74
|
str += ` ...(${code}) `;
|
|
75
75
|
}
|
|
@@ -77,8 +77,9 @@ const blockToMarko = (json, options) => {
|
|
|
77
77
|
str += ` key="${(0, lodash_1.camelCase)(code)}" `;
|
|
78
78
|
}
|
|
79
79
|
else if (key.startsWith('on')) {
|
|
80
|
+
const asyncKeyword = async ? 'async ' : '';
|
|
80
81
|
const useKey = key === 'onChange' && json.name === 'input' ? 'onInput' : key;
|
|
81
|
-
str += ` ${(0, dash_case_1.dashCase)(useKey)}=(${cusArgs.join(',')} => ${processBinding(options.component, code)}) `;
|
|
82
|
+
str += ` ${(0, dash_case_1.dashCase)(useKey)}=(${asyncKeyword}(${cusArgs.join(',')}) => ${processBinding(options.component, code)}) `;
|
|
82
83
|
}
|
|
83
84
|
else if (key !== 'innerHTML') {
|
|
84
85
|
str += ` ${key}=(${processBinding(options.component, code)}) `;
|
|
@@ -187,11 +188,11 @@ const componentToMarko = (userOptions = {}) => ({ component }) => {
|
|
|
187
188
|
}`}
|
|
188
189
|
|
|
189
190
|
${Array.from(domRefs)
|
|
190
|
-
.map((refName) => `get ${(0, lodash_1.camelCase)(refName)}() {
|
|
191
|
+
.map((refName) => `get ${(0, lodash_1.camelCase)(refName)}() {
|
|
191
192
|
return this.getEl('${(0, lodash_1.camelCase)(refName)}')
|
|
192
193
|
}`)
|
|
193
194
|
.join('\n')}
|
|
194
|
-
|
|
195
|
+
|
|
195
196
|
${!json.hooks.onMount.length
|
|
196
197
|
? ''
|
|
197
198
|
: `onMount() { ${processBinding(json, (0, on_mount_1.stringifySingleScopeOnMount)(json), 'class')} }`}
|
|
@@ -207,7 +208,7 @@ const componentToMarko = (userOptions = {}) => ({ component }) => {
|
|
|
207
208
|
`;
|
|
208
209
|
let htmlString = json.children.map((item) => blockToMarko(item, options)).join('\n');
|
|
209
210
|
const cssString = css.length
|
|
210
|
-
? `style {
|
|
211
|
+
? `style {
|
|
211
212
|
${(0, indent_1.indent)(css, 2).trim()}
|
|
212
213
|
}`
|
|
213
214
|
: '';
|
|
@@ -121,7 +121,9 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
|
|
|
121
121
|
str += ` {...(${(_h = json.bindings[key]) === null || _h === void 0 ? void 0 : _h.code})} `;
|
|
122
122
|
}
|
|
123
123
|
else if (key.startsWith('on')) {
|
|
124
|
-
|
|
124
|
+
const { arguments: cusArgs = ['event'], async } = json.bindings[key];
|
|
125
|
+
const asyncKeyword = async ? 'async ' : '';
|
|
126
|
+
str += ` ${key}={${asyncKeyword}(${cusArgs.join(',')}) => ${value.replace(/\s*;$/, '')}} `;
|
|
125
127
|
}
|
|
126
128
|
else {
|
|
127
129
|
if (!isValidAttributeName(key)) {
|
|
@@ -139,7 +139,7 @@ const NATIVE_EVENT_MAPPER = {
|
|
|
139
139
|
onClick: 'onPress',
|
|
140
140
|
};
|
|
141
141
|
const blockToReact = (json, options, component, insideJsx, parentSlots = []) => {
|
|
142
|
-
var _a, _b, _c, _d;
|
|
142
|
+
var _a, _b, _c, _d, _e;
|
|
143
143
|
const needsToRenderSlots = [];
|
|
144
144
|
if (NODE_MAPPERS[json.name]) {
|
|
145
145
|
return NODE_MAPPERS[json.name](json, options, component, insideJsx, parentSlots);
|
|
@@ -244,9 +244,10 @@ const blockToReact = (json, options, component, insideJsx, parentSlots = []) =>
|
|
|
244
244
|
str += ` {...(${value})} `;
|
|
245
245
|
}
|
|
246
246
|
else if (key.startsWith('on')) {
|
|
247
|
+
const asyncKeyword = ((_e = json.bindings[key]) === null || _e === void 0 ? void 0 : _e.async) ? 'async ' : '';
|
|
247
248
|
const { arguments: cusArgs = ['event'] } = json.bindings[key];
|
|
248
249
|
const eventName = options.type === 'native' ? NATIVE_EVENT_MAPPER[key] || key : key;
|
|
249
|
-
str += ` ${eventName}={(${cusArgs.join(',')}) => ${(0, state_1.updateStateSettersInCode)(useBindingValue, options)} } `;
|
|
250
|
+
str += ` ${eventName}={${asyncKeyword}(${cusArgs.join(',')}) => ${(0, state_1.updateStateSettersInCode)(useBindingValue, options)} } `;
|
|
250
251
|
}
|
|
251
252
|
else if (key.startsWith('slot')) {
|
|
252
253
|
// <Component slotProjected={<AnotherComponent />} />
|
|
@@ -19,7 +19,7 @@ const transformAttributeName = (name) => {
|
|
|
19
19
|
return name;
|
|
20
20
|
};
|
|
21
21
|
const blockToSolid = (json, component, options, insideJsx) => {
|
|
22
|
-
var _a, _b, _c;
|
|
22
|
+
var _a, _b, _c, _d;
|
|
23
23
|
if (insideJsx) {
|
|
24
24
|
if (json.properties._text) {
|
|
25
25
|
return json.properties._text;
|
|
@@ -77,7 +77,8 @@ const blockToSolid = (json, component, options, insideJsx) => {
|
|
|
77
77
|
}
|
|
78
78
|
else if (key.startsWith('on')) {
|
|
79
79
|
const useKey = key === 'onChange' && json.name === 'input' ? 'onInput' : key;
|
|
80
|
-
|
|
80
|
+
const asyncKeyword = ((_d = json.bindings[key]) === null || _d === void 0 ? void 0 : _d.async) ? 'async ' : '';
|
|
81
|
+
str += ` ${useKey}={${asyncKeyword}(${cusArg.join(',')}) => ${code}} `;
|
|
81
82
|
}
|
|
82
83
|
else if (key === 'ref' && options.typescript) {
|
|
83
84
|
str += ` ${key}={${code}!} `;
|
|
@@ -8,7 +8,7 @@ const filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes
|
|
|
8
8
|
const for_1 = require("../../helpers/nodes/for");
|
|
9
9
|
const mitosis_node_1 = require("../../types/mitosis-node");
|
|
10
10
|
const blockToStencil = (json, options = {}, insideJsx, childComponents) => {
|
|
11
|
-
var _a, _b, _c, _d, _e, _f;
|
|
11
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
12
12
|
let blockName = childComponents.find((impName) => impName === json.name)
|
|
13
13
|
? (0, helpers_1.getTagName)(json.name, options)
|
|
14
14
|
: json.name;
|
|
@@ -87,7 +87,8 @@ const blockToStencil = (json, options = {}, insideJsx, childComponents) => {
|
|
|
87
87
|
}
|
|
88
88
|
else if ((0, helpers_1.isEvent)(key)) {
|
|
89
89
|
const useKey = key === 'onChange' && blockName === 'input' ? 'onInput' : key;
|
|
90
|
-
|
|
90
|
+
const asyncKeyword = ((_g = json.bindings[key]) === null || _g === void 0 ? void 0 : _g.async) ? 'async ' : '';
|
|
91
|
+
str += ` ${useKey}={${asyncKeyword}(${cusArgs.join(',')}) => ${code}} `;
|
|
91
92
|
}
|
|
92
93
|
else {
|
|
93
94
|
str += ` ${key}={${code}} `;
|
|
@@ -168,7 +168,7 @@ const stringifyBinding = (node, options) => ([key, binding]) => {
|
|
|
168
168
|
if (key === 'innerHTML' || !binding) {
|
|
169
169
|
return '';
|
|
170
170
|
}
|
|
171
|
-
const { code, arguments: cusArgs = ['event'], type } = binding;
|
|
171
|
+
const { code, arguments: cusArgs = ['event'], type, async } = binding;
|
|
172
172
|
const isValidHtmlTag = html_tags_1.VALID_HTML_TAGS.includes(node.name) || node.name === 'svelte:element';
|
|
173
173
|
if (type === 'spread') {
|
|
174
174
|
const spreadValue = key === 'props' ? '$$props' : code;
|
|
@@ -179,11 +179,12 @@ const stringifyBinding = (node, options) => ([key, binding]) => {
|
|
|
179
179
|
const event = key.replace('on', '').toLowerCase();
|
|
180
180
|
// TODO: handle quotes in event handler values
|
|
181
181
|
const valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(code);
|
|
182
|
-
if (valueWithoutBlock === key) {
|
|
182
|
+
if (valueWithoutBlock === key && !async) {
|
|
183
183
|
return ` on:${event}={${valueWithoutBlock}} `;
|
|
184
184
|
}
|
|
185
185
|
else {
|
|
186
|
-
|
|
186
|
+
const asyncKeyword = async ? 'async ' : '';
|
|
187
|
+
return ` on:${event}="{${asyncKeyword}(${cusArgs.join(',')}) => {${valueWithoutBlock}}}" `;
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
190
|
else if (key.startsWith('on')) {
|
|
@@ -105,14 +105,20 @@ const stringifyBinding = (node, options) => ([key, value]) => {
|
|
|
105
105
|
const useValue = (value === null || value === void 0 ? void 0 : value.code) || '';
|
|
106
106
|
if (key.startsWith('on') && isValidHtmlTag) {
|
|
107
107
|
// handle html native on[event] props
|
|
108
|
-
const { arguments: cusArgs = ['event'] } = value;
|
|
108
|
+
const { arguments: cusArgs = ['event'], async } = value;
|
|
109
109
|
let event = key.replace('on', '').toLowerCase();
|
|
110
110
|
const isAssignmentExpression = useValue.includes('=');
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
let eventHandlerValue;
|
|
112
|
+
if (async) {
|
|
113
|
+
eventHandlerValue = (0, function_1.pipe)((0, replace_identifiers_1.replaceIdentifiers)({
|
|
114
|
+
code: useValue,
|
|
115
|
+
from: cusArgs[0],
|
|
116
|
+
to: '$event',
|
|
117
|
+
}), isAssignmentExpression ? function_1.identity : remove_surrounding_block_1.removeSurroundingBlock, remove_surrounding_block_1.removeSurroundingBlock, helpers_1.encodeQuotes);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
eventHandlerValue = `async (${cusArgs.join(', ')}) => ${useValue}`;
|
|
121
|
+
}
|
|
116
122
|
const eventHandlerKey = `${SPECIAL_PROPERTIES.V_ON_AT}${event}`;
|
|
117
123
|
return `${eventHandlerKey}="${eventHandlerValue}"`;
|
|
118
124
|
}
|
|
@@ -92,7 +92,7 @@ const getActionBindingsFromBlock = (block, options) => {
|
|
|
92
92
|
const actionKeys = Object.keys(actions);
|
|
93
93
|
if (actionKeys.length) {
|
|
94
94
|
for (const key of actionKeys) {
|
|
95
|
-
|
|
95
|
+
let value = actions[key];
|
|
96
96
|
// Skip empty values
|
|
97
97
|
if (!value.trim()) {
|
|
98
98
|
continue;
|
|
@@ -103,7 +103,16 @@ const getActionBindingsFromBlock = (block, options) => {
|
|
|
103
103
|
continue;
|
|
104
104
|
}
|
|
105
105
|
const useKey = `on${(0, lodash_1.upperFirst)(key)}`;
|
|
106
|
-
|
|
106
|
+
const asyncPrefix = `(async () =>`;
|
|
107
|
+
const asyncSuffix = ')()';
|
|
108
|
+
const isAsync = value.startsWith(asyncPrefix) && value.endsWith(asyncSuffix);
|
|
109
|
+
if (isAsync) {
|
|
110
|
+
value = value.slice(asyncPrefix.length, -asyncSuffix.length);
|
|
111
|
+
}
|
|
112
|
+
bindings[useKey] = (0, bindings_1.createSingleBinding)({
|
|
113
|
+
code: `${wrapBindingIfNeeded(value, options)}`,
|
|
114
|
+
async: isAsync ? true : undefined,
|
|
115
|
+
});
|
|
107
116
|
}
|
|
108
117
|
}
|
|
109
118
|
return bindings;
|
|
@@ -280,6 +280,7 @@ const jsxElementToJson = (node) => {
|
|
|
280
280
|
: [];
|
|
281
281
|
memo.bindings[key] = (0, bindings_1.createSingleBinding)({
|
|
282
282
|
code: (0, generator_1.default)(expression.body, { compact: true }).code,
|
|
283
|
+
async: expression.async === true ? true : undefined,
|
|
283
284
|
arguments: args.length ? args : undefined,
|
|
284
285
|
});
|
|
285
286
|
}
|