@builder.io/mitosis 0.5.14 → 0.5.16
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.
|
@@ -151,46 +151,29 @@ const componentMappers = {
|
|
|
151
151
|
if (value.type === 'single' && value.bindingType === 'function') {
|
|
152
152
|
try {
|
|
153
153
|
const code = value.code;
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (core_1.types.isVariableDeclarator(path) &&
|
|
178
|
-
core_1.types.isIdentifier(path.id) &&
|
|
179
|
-
path.id.name === target) {
|
|
180
|
-
hasTargetDeclaration = true;
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
if (hasTargetDeclaration) {
|
|
185
|
-
stopProcessing = true;
|
|
186
|
-
processedLines.push(generatedLine);
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
// Replace identifiers in this statement
|
|
190
|
-
processedLines.push(appendSemicolonIfNeeded(replaceIndexNode(generatedLine)));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
thing.bindings[key].code = '{' + processedLines.join('\n') + '}';
|
|
154
|
+
const programNode = (0, parsers_1.parseCodeToAst)(code);
|
|
155
|
+
if (!programNode)
|
|
156
|
+
continue;
|
|
157
|
+
(0, core_1.traverse)(programNode, {
|
|
158
|
+
Program(path) {
|
|
159
|
+
if (path.scope.hasBinding(target))
|
|
160
|
+
return;
|
|
161
|
+
const x = {
|
|
162
|
+
id: core_1.types.identifier(target),
|
|
163
|
+
init: core_1.types.identifier('PLACEHOLDER'),
|
|
164
|
+
};
|
|
165
|
+
path.scope.push(x);
|
|
166
|
+
path.scope.rename(target, 'state.$index');
|
|
167
|
+
path.traverse({
|
|
168
|
+
VariableDeclaration(p) {
|
|
169
|
+
if (p.node.declarations.length === 1 && p.node.declarations[0].id === x.id) {
|
|
170
|
+
p.remove();
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
thing.bindings[key].code = (0, generator_1.default)(programNode).code;
|
|
194
177
|
}
|
|
195
178
|
catch (error) {
|
|
196
179
|
console.error('Error processing function binding. Falling back to simple replacement.', error);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as babel from '@babel/core';
|
|
2
|
+
export declare function parseCodeToAst(code: string): babel.ParseResult | null;
|
|
2
3
|
export declare function parseCode(code: string): babel.types.Statement[];
|
|
3
4
|
export declare const isCodeBodyExpression: (body: babel.types.Statement[]) => boolean;
|
|
4
5
|
/**
|
|
@@ -26,25 +26,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.isCodeBodyIdentifier = exports.isExpression = exports.isCodeBodyExpression = exports.parseCode = void 0;
|
|
29
|
+
exports.isCodeBodyIdentifier = exports.isExpression = exports.isCodeBodyExpression = exports.parseCode = exports.parseCodeToAst = void 0;
|
|
30
30
|
const babel = __importStar(require("@babel/core"));
|
|
31
31
|
const plugin_syntax_decorators_1 = __importDefault(require("@babel/plugin-syntax-decorators"));
|
|
32
32
|
const plugin_syntax_typescript_1 = __importDefault(require("@babel/plugin-syntax-typescript"));
|
|
33
33
|
const preset_typescript_1 = __importDefault(require("@babel/preset-typescript"));
|
|
34
|
-
function
|
|
35
|
-
|
|
34
|
+
function parseCodeToAst(code) {
|
|
35
|
+
return babel.parse(code, {
|
|
36
36
|
presets: [[preset_typescript_1.default, { isTSX: true, allExtensions: true }]],
|
|
37
37
|
plugins: [
|
|
38
38
|
[plugin_syntax_typescript_1.default, { isTSX: true }],
|
|
39
39
|
[plugin_syntax_decorators_1.default, { legacy: true }],
|
|
40
40
|
],
|
|
41
41
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return body;
|
|
42
|
+
}
|
|
43
|
+
exports.parseCodeToAst = parseCodeToAst;
|
|
44
|
+
function parseCode(code) {
|
|
45
|
+
const ast = parseCodeToAst(code);
|
|
46
|
+
return babel.types.isFile(ast) ? ast.program.body : babel.types.isProgram(ast) ? ast.body : [];
|
|
48
47
|
}
|
|
49
48
|
exports.parseCode = parseCode;
|
|
50
49
|
const isCodeBodyExpression = (body) => body.length == 1 &&
|