How to use the postcss-selector-parser.className 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 kaola-fed / megalo-aot / packages / target / lib / postcss-plugins / scoped.js View on Github external
}
          // /deep/ alias for >>>, since >>> doesn't work in SASS
          if (n.type === 'combinator' && n.value === '/deep/') {
            n.value = ' '
            n.spaces.before = n.spaces.after = ''
            return false
          }
          if (n.type !== 'pseudo' && n.type !== 'combinator') {
            node = n
          }
        })
        if (node) {
          node.spaces.after = ''
          selector.insertAfter(
            node,
            selectorParser.className( {
              value: id
            } )
          )
        }
      })
    }).processSync(node.selector)
github mpvue / mpvue-loader / lib / style-compiler / plugins / scope-id.js View on Github external
}
            // /deep/ alias for >>>, since >>> doesn't work in SASS
            if (n.type === 'tag' && n.value === '/deep/') {
              var next = n.next()
              if (next.type === 'combinator' && next.value === ' ') {
                next.remove()
              }
              n.remove()
              return false
            }
            if (n.type !== 'pseudo' && n.type !== 'combinator') {
              node = n
            }
          })

          selector.insertAfter(node, selectorParser.className({
            value: opts.id
          }))
          // TODO, options for mp
          // selector.insertAfter(node, selectorParser.attribute({
          //   attribute: opts.id
          // }))
          // selector.prepend(selectorParser.className({
          //   value: `${opts.id} `
          // }))
        })
      }).process(node.selector).result
github linkedin / opticss / packages / opticss / src / optimizations / MergeDeclarations / OptimizationContext.ts View on Github external
constructor(key: string, scope: RuleScope, root: postcss.Root, selectorContext: ParsedSelector | undefined) {
    this.key = key;
    this.scopes = [scope];
    this.root = root;
    this.selectorContext = selectorContext;
    this.declarationMap = new Dictionary>();
    this.authoredProps = new Set();
    this.declarationInfos = new Set();
    let specificitySelector = selectorContext &&
      selectorContext.toContext(selectorParser.className({ value: "foo" }));
    this.specificity = specificitySelector &&
      specificity.calculate(specificitySelector.toString())[0];
  }
github sinnerschrader / schlump / src / css.js View on Github external
if (isOnlyPseudoRootSelector(selector)) {
						selector.first.replaceWith(selectorParser.className({value: `${ns}-root`}));
						map[sourceSelector] = String(`${ns}-root`).replace(/^\./, '');
					} else {
						for (let i = 0, n = selector.nodes.length; i < n; i++) {
							if (isClassSelectorNode(selector, i)) {
								let newClass = classNameCache.get(selector.nodes[i].value);
								if (!newClass) {
									newClass = selectorParser.className({value: `${ns}-${selector.nodes[i].value}`});
									classNameCache.set(selector.nodes[i].value, newClass);
								}
								selector.nodes[i].replaceWith(newClass);
								map[sourceSelector] = String(selector.last).replace(/^\./, '');
							} else if (isClassWithAttributeSelectorNode(selector, i)) {
								const classSelector = selectorParser.className({value: ns});
								selector.insertBefore(selector.nodes[i], classSelector);
								map[sourceSelector] = String(classSelector).replace(/^\./, '');
							}
						}
						if (selector.last.type === selectorParser.TAG) {
							selector.last.replaceWith(selectorParser.className({value:
								`${ns}-${selector.last.value}`}));
							map[sourceSelector] = String(selector.last).replace(/^\./, '');
						}
					}
				});
			};
github tivac / modular-css / packages / processor / plugins / externals.js View on Github external
file.exports[name].forEach((value) =>
            s.append(selector.className({ value }))
        );
github linkedin / css-blocks / src / BlockParser.ts View on Github external
private mutate(e: Exportable, selComponent, selector, contextCB: (newClass:any) => void) {
    let newClass = selectorParser.className({value: e.cssClass(this.opts)});
    if (selComponent.parent === selector) { contextCB(newClass); }
    return [selComponent, newClass];
  }
github iddan / stylesheet / postcss / parse-attribute-nodes.js View on Github external
nodes.map(node => {
    const { operator, attribute, raws: { unquoted, insensitive }} = node;
    const attributeId = operator ? unique(operator + unquoted) : '';
    const attributeClassName = `${ componentName }-${ attribute }_${ attributeId }_${ id }`;
    node.replaceWith(parser.className({ value: attributeClassName }));
    return {
      operator,
      name: attribute,
      value: unquoted,
      insensitive,
      className: attributeClassName,
    };
  });
github iddan / stylesheet / postcss / index.js View on Github external
nextCombinatorIndex = selector.nodes.length;
              blockComponents.add(componentName);
            }
            const attributeNodes = getAttributeNodes(tagIndex, nextCombinatorIndex, selector.nodes);
            components = _.update(
              componentName,
              _.flow([
                _.set('className', componentClassName),
                _.update('attributes', (attributes = []) => [
                  ...attributes,
                  ...parseAttributeNodes(id, componentName, attributeNodes),
                ]),
              ]),
              components
            );
            tag.replaceWith(parser.className({ value: componentClassName }));
          }
        }
      };
      try {
github jacobp100 / cssta / src / web / extractRules.js View on Github external
container.walkNesting(node => {
        const className = getDefaultClassName();
        const replacementNode = selectorParser.className({ value: className });
        node.replaceWith(replacementNode);
      });