@builder.io/mitosis
Version:
Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io
27 lines (26 loc) • 1.36 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.replaceSlotsInString = exports.toKebabSlot = exports.stripSlotPrefix = exports.isSlotProperty = void 0;
const core_1 = require("@babel/core");
const function_1 = require("fp-ts/function");
const lodash_1 = require("lodash");
const babel_transform_1 = require("./babel-transform");
const SLOT_PREFIX = 'slot';
const isSlotProperty = (key, slotPrefix = SLOT_PREFIX) => key.startsWith(slotPrefix);
exports.isSlotProperty = isSlotProperty;
const stripSlotPrefix = (key, slotPrefix = SLOT_PREFIX) => (0, exports.isSlotProperty)(key, slotPrefix) ? key.substring(slotPrefix.length) : key;
exports.stripSlotPrefix = stripSlotPrefix;
const toKebabSlot = (key, slotPrefix = SLOT_PREFIX) => (0, function_1.pipe)((0, exports.stripSlotPrefix)(key, slotPrefix), lodash_1.kebabCase);
exports.toKebabSlot = toKebabSlot;
function replaceSlotsInString(code, mapper) {
return (0, babel_transform_1.babelTransformExpression)(code, {
Identifier(path) {
const name = path.node.name;
const isSlot = (0, exports.isSlotProperty)(name);
if (isSlot) {
path.replaceWith(core_1.types.identifier(mapper((0, exports.stripSlotPrefix)(name).toLowerCase())));
}
},
});
}
exports.replaceSlotsInString = replaceSlotsInString;
;