@builder.io/mitosis
Version:
Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io
35 lines (34 loc) • 1.36 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseModule = void 0;
const astring_1 = require("astring");
const compiler_1 = require("svelte/compiler");
function handleExportNamedDeclaration(json, node) {
var _a, _b, _c;
const declarations = (_a = node.declaration) === null || _a === void 0 ? void 0 : _a.declarations;
if (declarations === null || declarations === void 0 ? void 0 : declarations.length) {
const declaration = declarations[0];
const property = declaration.id.name;
const isFunction = ((_b = declaration.init) === null || _b === void 0 ? void 0 : _b.type) === 'FunctionExpression' ||
((_c = declaration.init) === null || _c === void 0 ? void 0 : _c.type) === 'ArrowFunctionExpression';
const exportObject = {
[property]: {
code: (0, astring_1.generate)(node),
isFunction,
},
};
json.exports = { ...json.exports, ...exportObject };
}
}
function parseModule(ast, json) {
(0, compiler_1.walk)(ast.module, {
enter(node) {
switch (node.type) {
case 'ExportNamedDeclaration':
handleExportNamedDeclaration(json, node);
break;
}
},
});
}
exports.parseModule = parseModule;
;