stylelint-plugin-enforce-atomics
Version:
stylelint plugin to enforce usage of atomic classes
31 lines (30 loc) • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseRootAndSeedData = void 0;
const property_value_pair_1 = require("../../types/property-value-pair");
function parseRootAndSeedData(rule, sourceMetadata) {
var _a;
const { selectorsToPropertyPairNode, propertyValuePairToSelector } = sourceMetadata;
// double container propertyValuePairToSelector
(_a = rule === null || rule === void 0 ? void 0 : rule.nodes) === null || _a === void 0 ? void 0 : _a.forEach((node) => {
const declaration = node;
const propertyValuePair = (0, property_value_pair_1.createPropertyValuePair)(declaration);
const selectorsForGivenPropertyPair = propertyValuePairToSelector.get(propertyValuePair);
if (!selectorsForGivenPropertyPair) {
return;
}
selectorsForGivenPropertyPair.forEach((selector) => {
const propertyPairNode = selectorsToPropertyPairNode.get(selector);
if (!propertyPairNode) {
throw new Error(`${selector} not exists in selectorsToPropertyPairNode`);
}
if (propertyPairNode === null || propertyPairNode === void 0 ? void 0 : propertyPairNode.has(propertyValuePair)) {
propertyPairNode.set(propertyValuePair, node);
}
else {
throw new Error(`Property value ${propertyValuePair} should be in propertyPairNode for selector ${selector}`);
}
});
});
}
exports.parseRootAndSeedData = parseRootAndSeedData;