UNPKG

@builder.io/mitosis

Version:

Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io

34 lines (33 loc) 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseReactive = void 0; const astring_1 = require("astring"); function parseReactive(json, node) { const body = node.body; const expression = body === null || body === void 0 ? void 0 : body.expression; if (!expression) { const wrap = node.body.type !== 'BlockStatement'; const name = `reactive${Object.values(json.state).filter((index) => (index === null || index === void 0 ? void 0 : index.type) === 'getter').length}`; json.state[name] = { code: `get ${name}() ${wrap ? '{' : ''}${(0, astring_1.generate)(node.body)}${wrap ? '}' : ''}`, type: 'getter', }; } else if (expression.type === 'AssignmentExpression') { const { name } = expression.left; json.state[name] = { code: `get ${name}() {\n return ${(0, astring_1.generate)(expression.right)}}`, type: 'getter', }; } else if (expression.type === 'CallExpression') { if (node.body.type === 'ExpressionStatement') { json.hooks.onUpdate = json.hooks.onUpdate || []; json.hooks.onUpdate.push({ code: (0, astring_1.generate)(node.body), deps: `[${expression.arguments.map((arg) => (0, astring_1.generate)(arg))}]`, }); } } } exports.parseReactive = parseReactive;