How to use the postcss-selector-parser.isCombinator function in postcss-selector-parser

To help you get started, we’ve selected a few postcss-selector-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github salesforce / lwc / packages / lwc-style-compiler / src / selector-scoping / validate.ts View on Github external
// Let's check if the attribute name is either a Global HTML attribute, an ARIA attribute
            // or a data-* attribute since those are available on all the elements.
            if (isGlobalAttribute(attributeName) || isAriaAttribute(attributeName) || isDataAttribute(attributeName)) {
                return;
            }

            // If the attribute name is not a globally available attribute, the attribute selector is required
            // to be associated with a tag selector, so we can validate its usage. Let's walk the compound selector
            // backward to find the associated tag selector.
            let tagSelector: Tag | undefined = undefined;
            let runner = node.prev();

            while (
                tagSelector === undefined &&
                runner !== undefined &&
                !isCombinator(runner)
            ) {
                if (isTag(runner)) {
                    tagSelector = runner;
                } else {
                    runner = runner.prev();
                }
            }

            // If the tag selector is not present in the compound selector, we need to warn the user that
            // the compound selector need to be more specific.
            if (tagSelector === undefined) {
                const message = [
                    `Invalid usage of attribute selector "${attributeName}". `,
                    `For validation purposes, attributes that are not global attributes must be associated `,
                    `with a tag name when used in a CSS selector. (e.g., "input[min]" instead of "[min]")`,
                ];
github salesforce / lwc / packages / @lwc / style-compiler / src / selector-scoping / transform.ts View on Github external
selector.each(node => {
        if (isCombinator(node)) {
            compoundSelectors.push([]);
        } else {
            const current = compoundSelectors[compoundSelectors.length - 1];
            current.push(node);
        }
    });
github lttb / reshadow / packages / postcss / transform.js View on Github external
selectors.walkTags(node => {
            /**
             * Workaround for the nested namespaced elements
             */
            const prev = node.prev();
            if (parser.isCombinator(prev) && prev.value === '|') {
                prev.value = '';
                node.namespace = true;
            }

            if (!processNamespace(node)) {
                return;
            }

            const {value} = node;

            let name;

            if (node.namespace) {
                name = `${scope}--${value}`;
            } else {
                name = value;
github lttb / reshadow / packages / postcss / transform.js View on Github external
const addMod = node => {
        let {attribute, value = ''} = node;

        let prev = node.prev();

        while (
            prev &&
            !(parser.isTag(prev) || parser.isIdentifier(prev)) &&
            !parser.isCombinator(prev)
        ) {
            const curr = prev;
            prev = curr.prev();

            if (parser.isPseudo(curr)) {
                continue;
            } else if (!parser.isAttribute(curr)) {
                continue;
            }
        }

        const tag = (prev && prev.value) || '__common__';

        value = value.replace(/^['"]/, '').replace(/['"]$/, '');

        let name;
github salesforce / lwc / packages / lwc-style-compiler / src / selector-scoping / transform.ts View on Github external
selector.each(node => {
        if (isCombinator(node)) {
            compoundSelectors.push([]);
        } else {
            const current = compoundSelectors[compoundSelectors.length - 1];
            current.push(node);
        }
    });