UNPKG

stylelint-plugin-enforce-atomics

Version:

stylelint plugin to enforce usage of atomic classes

27 lines (26 loc) 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseSourceAndSeedMataData = void 0; const property_value_pair_1 = require("../../types/property-value-pair"); function parseSourceAndSeedMataData(rule, selectorsToPropertyPairNode, propertyValuePairToSelector) { var _a; const propertyValuePairToNode = new Map(); if (!rule.selector.match("^[\\.]+([a-z]+[-]*[a-z]+[-]*)+$")) { return; } (_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 propertiesArr = propertyValuePairToSelector.get(propertyValuePair) || []; propertyValuePairToSelector.set(propertyValuePair, [...propertiesArr, rule.selector]); propertyValuePairToNode.set(propertyValuePair, null); }); if (!parentIsMediaQuery(rule)) { selectorsToPropertyPairNode.set(rule.selector, new Map(propertyValuePairToNode)); } } exports.parseSourceAndSeedMataData = parseSourceAndSeedMataData; function parentIsMediaQuery(rule) { var _a, _b; return ((_a = rule === null || rule === void 0 ? void 0 : rule.parent) === null || _a === void 0 ? void 0 : _a.type) === "atrule" && ((_b = rule === null || rule === void 0 ? void 0 : rule.parent) === null || _b === void 0 ? void 0 : _b.name) === "media"; }