UNPKG

@builder.io/mitosis

Version:

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

25 lines (24 loc) 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformStateSetters = void 0; const core_1 = require("@babel/core"); const babel_transform_1 = require("./babel-transform"); /** * Finds instances of state being set in `value`, and transforms them using the * provided `transformer`. */ const transformStateSetters = ({ value, transformer, }) => (0, babel_transform_1.babelTransformExpression)(value, { AssignmentExpression(path) { const { node } = path; if (core_1.types.isMemberExpression(node.left) && core_1.types.isIdentifier(node.left.object) && // TODO: utillity to properly trace this reference to the beginning node.left.object.name === 'state') { // TODO: ultimately support other property access like strings const propertyName = node.left.property.name; const newExpression = transformer({ path, propertyName }); path.replaceWith(newExpression); } }, }); exports.transformStateSetters = transformStateSetters;