UNPKG

postcss-d-ts

Version:

PostCSS plugin to generate `.d.ts` of all used CSS classes and ids in imported stylesheets

26 lines (25 loc) 1.05 kB
"use strict"; function collector(identifiers, { identifierParser, identifierMatchIndex, identifierCleanupParser, identifierCleanupReplace, allowedAtRuleNames }) { return ({ selectors, parent }) => { if ((parent === null || parent === void 0 ? void 0 : parent.type) === "atrule") { const { name } = parent; if (name && !allowedAtRuleNames.has(name)) return; } const { length } = selectors; for (let i = length; i--;) { const selector = selectors[i]; let parsed, lastIndex = undefined; while (parsed = identifierParser.exec(selector)) { const { index } = parsed; if (index === lastIndex) return; lastIndex = index; const identifier = parsed[identifierMatchIndex] .replace(identifierCleanupParser, identifierCleanupReplace); identifiers[identifier] = true; } } }; } module.exports = collector;