UNPKG

@atlaskit/eslint-plugin-ui-styling-standard

Version:

The eslint plugin to enforce and educate on Atlassian's UI Styling Standard

23 lines (22 loc) • 828 B
import cssSelectorParser from 'postcss-selector-parser'; import { getSourceCode } from '@atlaskit/eslint-utils/context-compat'; var cssSelectorProcessor = cssSelectorParser(); var selectorCache = new WeakMap(); /** * Parse each selector once per linted source file. Consumers treat the returned AST as read-only. */ export function parseSelector(context, selectorText) { var sourceCode = getSourceCode(context); var sourceFileCache = selectorCache.get(sourceCode); if (!sourceFileCache) { sourceFileCache = new Map(); selectorCache.set(sourceCode, sourceFileCache); } var cachedSelector = sourceFileCache.get(selectorText); if (cachedSelector) { return cachedSelector; } var selector = cssSelectorProcessor.astSync(selectorText); sourceFileCache.set(selectorText, selector); return selector; }