How to use the postcss-selector-parser.combinator 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 vuejs / vue-next / packages / compiler-sfc / src / stylePluginScoped.ts View on Github external
}

          if (n.type === 'pseudo') {
            // deep: inject [id] attribute at the node before the ::v-deep
            // combinator.
            if (n.value === '::v-deep') {
              if (n.nodes.length) {
                // .foo ::v-deep(.bar) -> .foo[xxxxxxx] .bar
                // replace the current node with ::v-deep's inner selector
                selector.insertAfter(n, n.nodes[0])
                // insert a space combinator before if it doesn't already have one
                const prev = selector.at(selector.index(n) - 1)
                if (!prev || !isSpaceCombinator(prev)) {
                  selector.insertAfter(
                    n,
                    selectorParser.combinator({
                      value: ' '
                    })
                  )
                }
                selector.removeChild(n)
              } else {
                // DEPRECATED usage
                // .foo ::v-deep .bar -> .foo[xxxxxxx] .bar
                console.warn(
                  `[@vue/compiler-sfc] ::v-deep usage as a combinator has ` +
                    `been deprecated. Use ::v-deep() instead.`
                )
                const prev = selector.at(selector.index(n) - 1)
                if (prev && isSpaceCombinator(prev)) {
                  selector.removeChild(prev)
                }
github makuga01 / dnsFookup / FE / node_modules / postcss-modules-local-by-default / index.js View on Github external
context.ignoreNextSpacing = context.lastWasSpacing
            ? node.value
            : false;

          context.enforceNoSpacing = context.lastWasSpacing
            ? false
            : node.value;

          context.global = node.value === ':global';
          context.explicit = true;

          // because this node has spacing that is lost when we remove it
          // we make up for it by adding an extra combinator in since adding
          // spacing on the parent selector doesn't work
          return addBackSpacing
            ? selectorParser.combinator({ value: ' ' })
            : null;
        }
        break;
      }
      case 'id':
      case 'class': {
        if (!node.value) {
          throw new Error('Invalid class or id selector syntax');
        }

        if (context.global) {
          break;
        }

        const isImportedValue = localAliasMap.has(node.value);
        const isImportedWithExplicitScope = isImportedValue && context.explicit;
github ktsn / vue-template-loader / lib / modules / add-scoped-id.js View on Github external
selector.each(n => {
    if (isDeepCombinator(n)) {
      // Use descendant combinator instead of deep combinator
      n.replaceWith(selectorParser.combinator({
        value: ' '
      }))
    }
  })
}
github flaviuse / mern-authentication / client / node_modules / postcss-modules-local-by-default / index.js View on Github external
context.ignoreNextSpacing = context.lastWasSpacing
            ? node.value
            : false;

          context.enforceNoSpacing = context.lastWasSpacing
            ? false
            : node.value;

          context.global = node.value === ':global';
          context.explicit = true;

          // because this node has spacing that is lost when we remove it
          // we make up for it by adding an extra combinator in since adding
          // spacing on the parent selector doesn't work
          return addBackSpacing
            ? selectorParser.combinator({ value: ' ' })
            : null;
        }
        break;
      }
      case 'id':
      case 'class': {
        if (!context.global) {
          const innerNode = node.clone();
          innerNode.spaces = { before: '', after: '' };

          node = selectorParser.pseudo({
            value: ':local',
            nodes: [innerNode],
            spaces: node.spaces,
          });
github salesforce / lwc / packages / postcss-plugin-lwc / src / index.js View on Github external
contextSelectors => {
                    const clone = selector.clone();

                    if (!hostNode) {
                        clone.prepend(hostPlaceholder());
                    }

                    clone.prepend(selectorParser.combinator({ value: ' ' }));

                    contextSelectors.each(node => {
                        trimNodeWhitespaces(node);
                        clone.prepend(node);
                    });

                    return clone;
                },
            );
github postcss / postcss-nested / index.js View on Github external
child.selectors.forEach(function (j) {
      var node = parse(j, child)
      var replaced = replace(node, parentNode)
      if (!replaced) {
        node.prepend(parser.combinator({ value: ' ' }))
        node.prepend(parentNode.clone())
      }
      result.push(node.toString())
    })
  })
github gimenete / unicycle / src / css-striper.ts View on Github external
selectors.each((selector: any) => {
      let node = null
      selector.each((n: any) => {
        if (n.type !== 'pseudo') node = n
      })
      selector.insertAfter(node, selectorParser.attribute({ attribute: value }))
      selector.prepend(selectorParser.combinator({ value: CSS_PLACEHOLDER }))
    })
  }