@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.04 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStateUsed = void 0;
const legacy_1 = __importDefault(require("neotraverse/legacy"));
const stateAccessRegex = /state\s*\.\s*([a-zA-Z0-9_\$]+)/;
const allStateMatchesRegex = new RegExp(stateAccessRegex, 'g');
/**
* Get state used in the components by reference
*/
const getStateUsed = (json) => {
const stateProperties = new Set();
(0, legacy_1.default)(json).forEach(function (item) {
if (typeof item === 'string') {
// TODO: proper babel ref matching
const matches = item.match(allStateMatchesRegex);
if (matches) {
for (const match of matches) {
stateProperties.add(match.match(stateAccessRegex)[1]);
}
}
}
});
return stateProperties;
};
exports.getStateUsed = getStateUsed;
;