@builder.io/mitosis 0.5.10 → 0.5.12
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/index.js +3 -3
- package/dist/src/generators/builder/generator.js +4 -3
- package/dist/src/generators/lit/generate.js +9 -9
- package/dist/src/generators/mitosis/generator.js +2 -2
- package/dist/src/generators/qwik/helpers/state.js +9 -6
- package/dist/src/generators/react/generator.js +1 -1
- package/dist/src/generators/vue/blocks.js +3 -3
- package/dist/src/parsers/jsx/element-parser.js +73 -18
- package/dist/src/parsers/jsx/state.js +26 -0
- package/package.json +1 -1
|
@@ -281,10 +281,10 @@ const blockToAngular = ({ root, json, options = {}, blockOptions = {
|
|
|
281
281
|
code: `${trackByFnName}(${indexName !== null && indexName !== void 0 ? indexName : '_'}, ${forName}) { return ${code}; }`,
|
|
282
282
|
type: 'method',
|
|
283
283
|
};
|
|
284
|
-
str += `<ng-container *ngFor="let ${forName} of ${(_e = json.bindings.each) === null || _e === void 0 ? void 0 : _e.code}${indexName ? `;
|
|
284
|
+
str += `<ng-container *ngFor="let ${forName !== null && forName !== void 0 ? forName : '_'} of ${(_e = json.bindings.each) === null || _e === void 0 ? void 0 : _e.code}${indexName ? `; index as ${indexName}` : ''}; trackBy: ${trackByFnName}">`;
|
|
285
285
|
}
|
|
286
286
|
else {
|
|
287
|
-
str += `<ng-container *ngFor="let ${forName} of ${(_f = json.bindings.each) === null || _f === void 0 ? void 0 : _f.code}${indexName ? `;
|
|
287
|
+
str += `<ng-container *ngFor="let ${forName !== null && forName !== void 0 ? forName : '_'} of ${(_f = json.bindings.each) === null || _f === void 0 ? void 0 : _f.code}${indexName ? `; index as ${indexName}` : ''}">`;
|
|
288
288
|
}
|
|
289
289
|
str += json.children
|
|
290
290
|
.map((item) => (0, exports.blockToAngular)({ root, json: item, options, blockOptions }))
|
|
@@ -825,7 +825,7 @@ const componentToAngular = (userOptions = {}) => ({ component: _component }) =>
|
|
|
825
825
|
${Array.from(refsForObjSpread)
|
|
826
826
|
.map((refName) => `@ViewChild('${refName}') ${refName}${options.typescript ? '!: ElementRef' : ''}`)
|
|
827
827
|
.join('\n')}
|
|
828
|
-
|
|
828
|
+
|
|
829
829
|
${Array.from(dynamicComponents)
|
|
830
830
|
.map((component) => `@ViewChild('${component
|
|
831
831
|
.split('.')[1]
|
|
@@ -126,17 +126,19 @@ const componentMappers = {
|
|
|
126
126
|
},
|
|
127
127
|
For(_node, options) {
|
|
128
128
|
var _a;
|
|
129
|
+
const node = _node;
|
|
129
130
|
// rename `index` var to `state.$index`
|
|
131
|
+
const target = node.scope.indexName || 'index';
|
|
130
132
|
const replaceIndex = (node) => {
|
|
131
133
|
(0, legacy_1.default)(node).forEach(function (thing) {
|
|
132
134
|
if ((0, is_mitosis_node_1.isMitosisNode)(thing)) {
|
|
133
135
|
for (const [key, value] of Object.entries(thing.bindings)) {
|
|
134
|
-
if (value === null || value === void 0 ? void 0 : value.code.includes(
|
|
136
|
+
if (value === null || value === void 0 ? void 0 : value.code.includes(target)) {
|
|
135
137
|
thing.bindings[key].code = (0, replace_identifiers_1.replaceNodes)({
|
|
136
138
|
code: value.code,
|
|
137
139
|
nodeMaps: [
|
|
138
140
|
{
|
|
139
|
-
from: core_1.types.identifier(
|
|
141
|
+
from: core_1.types.identifier(target),
|
|
140
142
|
to: core_1.types.memberExpression(core_1.types.identifier('state'), core_1.types.identifier('$index')),
|
|
141
143
|
},
|
|
142
144
|
],
|
|
@@ -147,7 +149,6 @@ const componentMappers = {
|
|
|
147
149
|
});
|
|
148
150
|
return node;
|
|
149
151
|
};
|
|
150
|
-
const node = _node;
|
|
151
152
|
return el({
|
|
152
153
|
component: {
|
|
153
154
|
name: 'Core:Fragment',
|
|
@@ -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;
|
|
39
|
+
var _a, _b, _c, _d, _e, _f;
|
|
40
40
|
if (json.properties._text) {
|
|
41
41
|
return json.properties._text;
|
|
42
42
|
}
|
|
@@ -44,7 +44,7 @@ const blockToLit = (json, options = {}) => {
|
|
|
44
44
|
return `\${${processBinding((_b = json.bindings) === null || _b === void 0 ? void 0 : _b._text.code)}}`;
|
|
45
45
|
}
|
|
46
46
|
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
47
|
-
return `\${${processBinding((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code)}?.map((${json.scope.forName}, index) => (
|
|
47
|
+
return `\${${processBinding((_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code)}?.map((${(_d = json.scope.forName) !== null && _d !== void 0 ? _d : '_'}, ${(_e = json.scope.indexName) !== null && _e !== void 0 ? _e : 'index'}) => (
|
|
48
48
|
html\`${json.children
|
|
49
49
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
50
50
|
.map((item) => blockToLit(item, options))
|
|
@@ -52,7 +52,7 @@ const blockToLit = (json, options = {}) => {
|
|
|
52
52
|
))}`;
|
|
53
53
|
}
|
|
54
54
|
else if (json.name === 'Show') {
|
|
55
|
-
return `\${${processBinding((
|
|
55
|
+
return `\${${processBinding((_f = json.bindings.when) === null || _f === void 0 ? void 0 : _f.code)} ?
|
|
56
56
|
html\`${json.children
|
|
57
57
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
58
58
|
.map((item) => blockToLit(item, options))
|
|
@@ -219,15 +219,15 @@ const componentToLit = (_options = {}) => ({ component }) => {
|
|
|
219
219
|
${(0, lodash_1.camelCase)(refName)}!: HTMLElement;
|
|
220
220
|
`)
|
|
221
221
|
.join('\n')}
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
|
|
223
|
+
|
|
224
224
|
${Array.from(props)
|
|
225
225
|
.map((item) => `@property() ${item}: any`)
|
|
226
226
|
.join('\n')}
|
|
227
227
|
|
|
228
228
|
${dataString}
|
|
229
229
|
${methodsString}
|
|
230
|
-
|
|
230
|
+
|
|
231
231
|
${json.hooks.onMount.length === 0
|
|
232
232
|
? ''
|
|
233
233
|
: `connectedCallback() { ${processBinding((0, on_mount_1.stringifySingleScopeOnMount)(json))} }`}
|
|
@@ -236,10 +236,10 @@ const componentToLit = (_options = {}) => ({ component }) => {
|
|
|
236
236
|
: `disconnectedCallback() { ${processBinding(json.hooks.onUnMount.code)} }`}
|
|
237
237
|
${!((_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.length)
|
|
238
238
|
? ''
|
|
239
|
-
: `updated() {
|
|
240
|
-
${json.hooks.onUpdate.map((hook) => processBinding(hook.code)).join('\n\n')}
|
|
239
|
+
: `updated() {
|
|
240
|
+
${json.hooks.onUpdate.map((hook) => processBinding(hook.code)).join('\n\n')}
|
|
241
241
|
}`}
|
|
242
|
-
|
|
242
|
+
|
|
243
243
|
render() {
|
|
244
244
|
return html\`
|
|
245
245
|
${options.useShadowDom || !css.length ? '' : `<style>${css}</style>`}
|
|
@@ -69,7 +69,7 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
|
|
|
69
69
|
const needsWrapper = json.children.length !== 1;
|
|
70
70
|
if (options.nativeLoops) {
|
|
71
71
|
const a = `${insideJsx ? '{' : ''}(${(_b = json.bindings.each) === null || _b === void 0 ? void 0 : _b.code}).map(
|
|
72
|
-
(${json.scope.forName}, ${json.scope.indexName || 'index'}) => (
|
|
72
|
+
(${json.scope.forName || '_'}, ${json.scope.indexName || 'index'}) => (
|
|
73
73
|
${needsWrapper ? '<>' : ''}
|
|
74
74
|
${json.children
|
|
75
75
|
.map((child) => (0, exports.blockToMitosis)(child, options, component, needsWrapper))
|
|
@@ -79,7 +79,7 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
|
|
|
79
79
|
return a;
|
|
80
80
|
}
|
|
81
81
|
return `<For each={${(_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code}}>
|
|
82
|
-
{(${json.scope.forName}, ${json.scope.indexName || 'index'}) =>
|
|
82
|
+
{(${json.scope.forName || '_'}, ${json.scope.indexName || 'index'}) =>
|
|
83
83
|
${needsWrapper ? '<>' : ''}
|
|
84
84
|
${json.children.map((child) => (0, exports.blockToMitosis)(child, options, component, needsWrapper))}}
|
|
85
85
|
${needsWrapper ? '</>' : ''}
|
|
@@ -39,18 +39,21 @@ function emitStateMethods(file, componentState, lexicalArgs) {
|
|
|
39
39
|
case 'method':
|
|
40
40
|
case 'function':
|
|
41
41
|
let code = stateValue.code;
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
prefixIdx
|
|
42
|
+
const isAsync = code.startsWith('async');
|
|
43
|
+
if (!isAsync) {
|
|
44
|
+
let prefixIdx = 0;
|
|
45
|
+
if (stateValue.type === 'function') {
|
|
46
|
+
prefixIdx += 'function '.length;
|
|
47
|
+
}
|
|
48
|
+
code = code.substring(prefixIdx);
|
|
49
|
+
code = (0, convert_method_to_function_1.convertMethodToFunction)(code, methodMap, lexicalArgs).replace('(', `(${lexicalArgs.join(',')},`);
|
|
45
50
|
}
|
|
46
|
-
code = code.substring(prefixIdx);
|
|
47
|
-
code = (0, convert_method_to_function_1.convertMethodToFunction)(code, methodMap, lexicalArgs).replace('(', `(${lexicalArgs.join(',')},`);
|
|
48
51
|
const functionName = code.split(/\(/)[0];
|
|
49
52
|
if (!file.options.isTypeScript) {
|
|
50
53
|
// Erase type information
|
|
51
54
|
code = (0, babel_transform_1.convertTypeScriptToJS)(code);
|
|
52
55
|
}
|
|
53
|
-
file.exportConst(functionName, 'function ' + code, true);
|
|
56
|
+
file.exportConst(isAsync ? key : functionName, isAsync ? code : 'function ' + code, true);
|
|
54
57
|
continue;
|
|
55
58
|
case 'property':
|
|
56
59
|
stateValues[key] = stateValue.code;
|
|
@@ -377,7 +377,7 @@ const _componentToReact = (json, options, isSubComponent = false) => {
|
|
|
377
377
|
if (type === 'getter')
|
|
378
378
|
return `${key} = function ${code.replace('get ', '')}`;
|
|
379
379
|
if (type === 'function')
|
|
380
|
-
return `${key} = function ${code}`;
|
|
380
|
+
return code.startsWith('async') ? code : `${key} = function ${code}`;
|
|
381
381
|
return code;
|
|
382
382
|
},
|
|
383
383
|
})
|
|
@@ -40,10 +40,10 @@ const NODE_MAPPERS = {
|
|
|
40
40
|
return childrenStr;
|
|
41
41
|
},
|
|
42
42
|
For(_json, options) {
|
|
43
|
-
var _a;
|
|
43
|
+
var _a, _b, _c, _d;
|
|
44
44
|
const json = _json;
|
|
45
|
-
const keyValue = json.bindings.key || { code: 'index', type: 'single' };
|
|
46
|
-
const forValue = `(${json.scope.forName}, index) in ${(
|
|
45
|
+
const keyValue = json.bindings.key || { code: (_a = json.scope.indexName) !== null && _a !== void 0 ? _a : 'index', type: 'single' };
|
|
46
|
+
const forValue = `(${(_b = json.scope.forName) !== null && _b !== void 0 ? _b : '_'}, ${(_c = json.scope.indexName) !== null && _c !== void 0 ? _c : 'index'}) in ${(_d = json.bindings.each) === null || _d === void 0 ? void 0 : _d.code}`;
|
|
47
47
|
// TODO: tmk key goes on different element (parent vs child) based on Vue 2 vs Vue 3
|
|
48
48
|
return `<template :key="${(0, helpers_1.encodeQuotes)((keyValue === null || keyValue === void 0 ? void 0 : keyValue.code) || 'index')}" v-for="${(0, helpers_1.encodeQuotes)(forValue)}">
|
|
49
49
|
${json.children.map((item) => (0, exports.blockToVue)(item, options)).join('\n')}
|
|
@@ -35,6 +35,22 @@ const create_mitosis_node_1 = require("../../helpers/create-mitosis-node");
|
|
|
35
35
|
const nullable_1 = require("../../helpers/nullable");
|
|
36
36
|
const helpers_1 = require("./helpers");
|
|
37
37
|
const { types } = babel;
|
|
38
|
+
const getBodyExpression = (node) => {
|
|
39
|
+
if (types.isArrowFunctionExpression(node) || types.isFunctionExpression(node)) {
|
|
40
|
+
const callback = node.body;
|
|
41
|
+
if (callback.type === 'BlockStatement') {
|
|
42
|
+
for (const statement of callback.body) {
|
|
43
|
+
if (statement.type === 'ReturnStatement') {
|
|
44
|
+
return statement.argument;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return callback;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
};
|
|
38
54
|
const getForArguments = (params) => {
|
|
39
55
|
const [forName, indexName, collectionName] = params
|
|
40
56
|
.filter((param) => types.isIdentifier(param))
|
|
@@ -65,22 +81,53 @@ const jsxElementToJson = (node) => {
|
|
|
65
81
|
if (types.isJSXExpressionContainer(node)) {
|
|
66
82
|
return (0, exports.jsxElementToJson)(node.expression);
|
|
67
83
|
}
|
|
68
|
-
if (types.isCallExpression(node) || types.isOptionalCallExpression(node))
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
if ((types.isCallExpression(node) || types.isOptionalCallExpression(node)) &&
|
|
85
|
+
(node.callee.type === 'MemberExpression' || node.callee.type === 'OptionalMemberExpression')) {
|
|
86
|
+
const isMap = node.callee.property.type === 'Identifier' && node.callee.property.name === 'map';
|
|
87
|
+
const isArrayFrom = node.callee.property.type === 'Identifier' &&
|
|
88
|
+
node.callee.property.name === 'from' &&
|
|
89
|
+
node.callee.object.type === 'Identifier' &&
|
|
90
|
+
node.callee.object.name === 'Array';
|
|
91
|
+
if (isMap) {
|
|
92
|
+
const callback = node.arguments[0];
|
|
93
|
+
const bodyExpression = getBodyExpression(callback);
|
|
94
|
+
if (bodyExpression) {
|
|
72
95
|
const forArguments = getForArguments(callback.params);
|
|
73
96
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
74
97
|
name: 'For',
|
|
75
98
|
bindings: {
|
|
76
99
|
each: (0, bindings_1.createSingleBinding)({
|
|
77
|
-
code: (0, generator_1.default)(node.callee
|
|
78
|
-
|
|
79
|
-
|
|
100
|
+
code: (0, generator_1.default)(node.callee.object, {
|
|
101
|
+
compact: true,
|
|
102
|
+
}).code,
|
|
80
103
|
}),
|
|
81
104
|
},
|
|
82
105
|
scope: forArguments,
|
|
83
|
-
children: [(0, exports.jsxElementToJson)(
|
|
106
|
+
children: [(0, exports.jsxElementToJson)(bodyExpression)],
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (isArrayFrom) {
|
|
111
|
+
// Array.from
|
|
112
|
+
const each = node.arguments[0];
|
|
113
|
+
const callback = node.arguments[1];
|
|
114
|
+
const bodyExpression = getBodyExpression(callback);
|
|
115
|
+
if (bodyExpression) {
|
|
116
|
+
const forArguments = getForArguments(callback.params);
|
|
117
|
+
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
118
|
+
name: 'For',
|
|
119
|
+
bindings: {
|
|
120
|
+
each: (0, bindings_1.createSingleBinding)({
|
|
121
|
+
code: (0, generator_1.default)({
|
|
122
|
+
...node,
|
|
123
|
+
arguments: [each],
|
|
124
|
+
}, {
|
|
125
|
+
compact: true,
|
|
126
|
+
}).code,
|
|
127
|
+
}),
|
|
128
|
+
},
|
|
129
|
+
scope: forArguments,
|
|
130
|
+
children: [(0, exports.jsxElementToJson)(bodyExpression)],
|
|
84
131
|
});
|
|
85
132
|
}
|
|
86
133
|
}
|
|
@@ -91,7 +138,11 @@ const jsxElementToJson = (node) => {
|
|
|
91
138
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
92
139
|
name: 'Show',
|
|
93
140
|
bindings: {
|
|
94
|
-
when: (0, bindings_1.createSingleBinding)({
|
|
141
|
+
when: (0, bindings_1.createSingleBinding)({
|
|
142
|
+
code: (0, generator_1.default)(node.left, {
|
|
143
|
+
compact: true,
|
|
144
|
+
}).code,
|
|
145
|
+
}),
|
|
95
146
|
},
|
|
96
147
|
children: [(0, exports.jsxElementToJson)(node.right)],
|
|
97
148
|
});
|
|
@@ -109,7 +160,7 @@ const jsxElementToJson = (node) => {
|
|
|
109
160
|
else: (0, exports.jsxElementToJson)(node.alternate),
|
|
110
161
|
},
|
|
111
162
|
bindings: {
|
|
112
|
-
when: (0, bindings_1.createSingleBinding)({ code: (0, generator_1.default)(node.test).code }),
|
|
163
|
+
when: (0, bindings_1.createSingleBinding)({ code: (0, generator_1.default)(node.test, { compact: true }).code }),
|
|
113
164
|
},
|
|
114
165
|
children: child === null ? [] : [child],
|
|
115
166
|
});
|
|
@@ -144,7 +195,7 @@ const jsxElementToJson = (node) => {
|
|
|
144
195
|
if (!types.isJSXElement(node)) {
|
|
145
196
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
146
197
|
bindings: {
|
|
147
|
-
_text: (0, bindings_1.createSingleBinding)({ code: (0, generator_1.default)(node).code }),
|
|
198
|
+
_text: (0, bindings_1.createSingleBinding)({ code: (0, generator_1.default)(node, { compact: true }).code }),
|
|
148
199
|
},
|
|
149
200
|
});
|
|
150
201
|
}
|
|
@@ -153,7 +204,7 @@ const jsxElementToJson = (node) => {
|
|
|
153
204
|
const whenAttr = node.openingElement.attributes.find((item) => types.isJSXAttribute(item) && item.name.name === 'when');
|
|
154
205
|
const elseAttr = node.openingElement.attributes.find((item) => types.isJSXAttribute(item) && item.name.name === 'else');
|
|
155
206
|
const whenValue = whenAttr && types.isJSXExpressionContainer(whenAttr.value)
|
|
156
|
-
? (0, generator_1.default)(whenAttr.value.expression).code
|
|
207
|
+
? (0, generator_1.default)(whenAttr.value.expression, { compact: true }).code
|
|
157
208
|
: undefined;
|
|
158
209
|
const elseValue = elseAttr &&
|
|
159
210
|
types.isJSXExpressionContainer(elseAttr.value) &&
|
|
@@ -178,7 +229,7 @@ const jsxElementToJson = (node) => {
|
|
|
178
229
|
const forArguments = getForArguments(childExpression === null || childExpression === void 0 ? void 0 : childExpression.params);
|
|
179
230
|
const forCode = (0, function_1.pipe)(node.openingElement.attributes[0], (attr) => {
|
|
180
231
|
if (types.isJSXAttribute(attr) && types.isJSXExpressionContainer(attr.value)) {
|
|
181
|
-
return (0, generator_1.default)(attr.value.expression).code;
|
|
232
|
+
return (0, generator_1.default)(attr.value.expression, { compact: true }).code;
|
|
182
233
|
}
|
|
183
234
|
else {
|
|
184
235
|
// TO-DO: is an empty string valid here?
|
|
@@ -228,7 +279,7 @@ const jsxElementToJson = (node) => {
|
|
|
228
279
|
? expression.params.map((node) => node === null || node === void 0 ? void 0 : node.name)
|
|
229
280
|
: [];
|
|
230
281
|
memo.bindings[key] = (0, bindings_1.createSingleBinding)({
|
|
231
|
-
code: (0, generator_1.default)(expression.body).code,
|
|
282
|
+
code: (0, generator_1.default)(expression.body, { compact: true }).code,
|
|
232
283
|
arguments: args.length ? args : undefined,
|
|
233
284
|
});
|
|
234
285
|
}
|
|
@@ -239,10 +290,14 @@ const jsxElementToJson = (node) => {
|
|
|
239
290
|
return memo;
|
|
240
291
|
memo.slots[key] = [slotNode];
|
|
241
292
|
// Temporarily keep the slot as a binding until we migrate generators to use the slots.
|
|
242
|
-
memo.bindings[key] = (0, bindings_1.createSingleBinding)({
|
|
293
|
+
memo.bindings[key] = (0, bindings_1.createSingleBinding)({
|
|
294
|
+
code: (0, generator_1.default)(expression, { compact: true }).code,
|
|
295
|
+
});
|
|
243
296
|
}
|
|
244
297
|
else {
|
|
245
|
-
memo.bindings[key] = (0, bindings_1.createSingleBinding)({
|
|
298
|
+
memo.bindings[key] = (0, bindings_1.createSingleBinding)({
|
|
299
|
+
code: (0, generator_1.default)(expression, { compact: true }).code,
|
|
300
|
+
});
|
|
246
301
|
}
|
|
247
302
|
return memo;
|
|
248
303
|
}
|
|
@@ -250,9 +305,9 @@ const jsxElementToJson = (node) => {
|
|
|
250
305
|
// TODO: potentially like Vue store bindings and properties as array of key value pairs
|
|
251
306
|
// too so can do this accurately when order matters. Also tempting to not support spread,
|
|
252
307
|
// as some frameworks do not support it (e.g. Angular) tho Angular may be the only one
|
|
253
|
-
const { code: key } = (0, generator_1.default)(item.argument);
|
|
308
|
+
const { code: key } = (0, generator_1.default)(item.argument, { compact: true });
|
|
254
309
|
memo.bindings[key] = {
|
|
255
|
-
code: types.stringLiteral((0, generator_1.default)(item.argument).code).value,
|
|
310
|
+
code: types.stringLiteral((0, generator_1.default)(item.argument, { compact: true }).code).value,
|
|
256
311
|
type: 'spread',
|
|
257
312
|
spreadType: 'normal',
|
|
258
313
|
};
|
|
@@ -128,6 +128,24 @@ const processStateObjectSlice = (item) => {
|
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
130
|
else if ((0, types_1.isArrowFunctionExpression)(item.value)) {
|
|
131
|
+
/**
|
|
132
|
+
* Arrow functions are normally converted to object methods to work around
|
|
133
|
+
* limitations with arrow functions in state in frameworks such as Svelte.
|
|
134
|
+
* However, this conversion does not work for async arrow functions due to
|
|
135
|
+
* how we handle parsing in `handleErrorOrExpression` for parsing
|
|
136
|
+
* expressions. That code does not detect async functions in order to apply
|
|
137
|
+
* its parsing workarounds. Even if it did, it does not consider async code
|
|
138
|
+
* when prefixing with "function". This would result in "function async foo()"
|
|
139
|
+
* which is not a valid function expression definition.
|
|
140
|
+
*/
|
|
141
|
+
// TODO ENG-7256 Find a way to do this without diverging code path
|
|
142
|
+
if (item.value.async) {
|
|
143
|
+
const func = (0, types_1.functionExpression)(item.key, item.value.params, item.value.body, false, true);
|
|
144
|
+
return {
|
|
145
|
+
code: (0, helpers_1.parseCode)(func).trim(),
|
|
146
|
+
type: 'function',
|
|
147
|
+
};
|
|
148
|
+
}
|
|
131
149
|
const n = (0, types_1.objectMethod)('method', item.key, item.value.params, item.value.body);
|
|
132
150
|
const code = (0, helpers_1.parseCode)(n).trim();
|
|
133
151
|
return {
|
|
@@ -153,6 +171,14 @@ const processStateObjectSlice = (item) => {
|
|
|
153
171
|
}
|
|
154
172
|
}
|
|
155
173
|
else if ((0, types_1.isObjectMethod)(item)) {
|
|
174
|
+
// TODO ENG-7256 Find a way to do this without diverging code path
|
|
175
|
+
if (item.async) {
|
|
176
|
+
const func = (0, types_1.functionExpression)(item.key, item.params, item.body, false, true);
|
|
177
|
+
return {
|
|
178
|
+
code: (0, helpers_1.parseCode)(func).trim(),
|
|
179
|
+
type: 'function',
|
|
180
|
+
};
|
|
181
|
+
}
|
|
156
182
|
const n = (0, helpers_1.parseCode)({ ...item, returnType: null }).trim();
|
|
157
183
|
const isGetter = item.kind === 'get';
|
|
158
184
|
return {
|