@builder.io/mitosis
Version:
Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io
29 lines (28 loc) • 1 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPropFunctions = void 0;
const legacy_1 = __importDefault(require("neotraverse/legacy"));
const propsRegex = /props\s*\.\s*([a-zA-Z0-9_\x04]+)\(/;
const allPropsMatchesRegex = new RegExp(propsRegex, 'g');
/**
* Get props used in the components by reference
*/
const getPropFunctions = (json) => {
const props = [];
(0, legacy_1.default)(json).forEach(function (item) {
if (typeof item === 'string') {
// TODO: proper babel ref matching
const matches = item.match(allPropsMatchesRegex);
if (matches) {
for (const match of matches) {
props.push(match.match(propsRegex)[1]);
}
}
}
});
return props;
};
exports.getPropFunctions = getPropFunctions;
;