{\itshape Please use only this documented API when working with the parser. Methods not documented here are subject to change at any point.}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21383}{}\doxysection{$<$tt$>$parser$<$/tt$>$ function}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21383}
This is the module\textquotesingle{}s main entry point.


\begin{DoxyCode}{0}
\DoxyCodeLine{const parser = require('postcss-\/selector-\/parser'); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21384}{}\doxysubsection{$<$tt$>$parser(\mbox{[}transform\mbox{]}, \mbox{[}options\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21384}
Creates a new {\ttfamily processor} instance


\begin{DoxyCode}{0}
\DoxyCodeLine{const processor = parser();}
\DoxyCodeLine{}
\DoxyCodeLine{// or, with optional transform function}
\DoxyCodeLine{const transform = selectors => \{}
\DoxyCodeLine{    selectors.walkUniversals(selector => \{}
\DoxyCodeLine{        selector.remove();}
\DoxyCodeLine{    \});}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{const processor = parser(transform)}
\DoxyCodeLine{}
\DoxyCodeLine{// Example}
\DoxyCodeLine{const result = processor.processSync('*.class');}
\DoxyCodeLine{// => .class }

\end{DoxyCode}


\href{\#processor}{\texttt{ See processor documentation}}

Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily transform (function)}\+: Provide a function to work with the parsed AST.
\item {\ttfamily options (object)}\+: Provide default options for all calls on the returned {\ttfamily Processor}.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21385}{}\doxysubsection{$<$tt$>$parser.\+attribute(\mbox{[}props\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21385}
Creates a new attribute selector.


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.attribute(\{attribute: 'href'\});}
\DoxyCodeLine{// => [href] }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily props (object)}\+: The new node\textquotesingle{}s properties.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21386}{}\doxysubsection{$<$tt$>$parser.\+class\+Name(\mbox{[}props\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21386}
Creates a new class selector.


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.className(\{value: 'button'\});}
\DoxyCodeLine{// => .button }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily props (object)}\+: The new node\textquotesingle{}s properties.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21387}{}\doxysubsection{$<$tt$>$parser.\+combinator(\mbox{[}props\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21387}
Creates a new selector combinator.


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.combinator(\{value: '+'\});}
\DoxyCodeLine{// => + }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily props (object)}\+: The new node\textquotesingle{}s properties.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21388}{}\doxysubsection{$<$tt$>$parser.\+comment(\mbox{[}props\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21388}
Creates a new comment.


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.comment(\{value: '/* Affirmative, Dave. I read you. */'\});}
\DoxyCodeLine{// => /* Affirmative, Dave. I read you. */ }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily props (object)}\+: The new node\textquotesingle{}s properties.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21389}{}\doxysubsection{$<$tt$>$parser.\+id(\mbox{[}props\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21389}
Creates a new id selector.


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.id(\{value: 'search'\});}
\DoxyCodeLine{// => \#search }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily props (object)}\+: The new node\textquotesingle{}s properties.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21390}{}\doxysubsection{$<$tt$>$parser.\+nesting(\mbox{[}props\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21390}
Creates a new nesting selector.


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.nesting();}
\DoxyCodeLine{// => \& }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily props (object)}\+: The new node\textquotesingle{}s properties.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21391}{}\doxysubsection{$<$tt$>$parser.\+pseudo(\mbox{[}props\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21391}
Creates a new pseudo selector.


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.pseudo(\{value: '::before'\});}
\DoxyCodeLine{// => ::before }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily props (object)}\+: The new node\textquotesingle{}s properties.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21392}{}\doxysubsection{$<$tt$>$parser.\+root(\mbox{[}props\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21392}
Creates a new root node.


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.root();}
\DoxyCodeLine{// => (empty) }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily props (object)}\+: The new node\textquotesingle{}s properties.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21393}{}\doxysubsection{$<$tt$>$parser.\+selector(\mbox{[}props\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21393}
Creates a new selector node.


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.selector();}
\DoxyCodeLine{// => (empty) }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily props (object)}\+: The new node\textquotesingle{}s properties.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21394}{}\doxysubsection{$<$tt$>$parser.\+string(\mbox{[}props\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21394}
Creates a new string node.


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.string();}
\DoxyCodeLine{// => (empty) }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily props (object)}\+: The new node\textquotesingle{}s properties.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21395}{}\doxysubsection{$<$tt$>$parser.\+tag(\mbox{[}props\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21395}
Creates a new tag selector.


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.tag(\{value: 'button'\});}
\DoxyCodeLine{// => button }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily props (object)}\+: The new node\textquotesingle{}s properties.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21396}{}\doxysubsection{$<$tt$>$parser.\+universal(\mbox{[}props\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21396}
Creates a new universal selector.


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.universal();}
\DoxyCodeLine{// => * }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily props (object)}\+: The new node\textquotesingle{}s properties.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21397}{}\doxysection{Node types}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21397}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21398}{}\doxysubsection{$<$tt$>$node.\+type$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21398}
A string representation of the selector type. It can be one of the following; {\ttfamily attribute}, {\ttfamily class}, {\ttfamily combinator}, {\ttfamily comment}, {\ttfamily id}, {\ttfamily nesting}, {\ttfamily pseudo}, {\ttfamily root}, {\ttfamily selector}, {\ttfamily string}, {\ttfamily tag}, or {\ttfamily universal}. Note that for convenience, these constants are exposed on the main {\ttfamily parser} as uppercased keys. So for example you can get {\ttfamily id} by querying {\ttfamily parser.\+ID}.


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.attribute(\{attribute: 'href'\}).type;}
\DoxyCodeLine{// => 'attribute' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21399}{}\doxysubsection{$<$tt$>$node.\+parent$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21399}
Returns the parent node.


\begin{DoxyCode}{0}
\DoxyCodeLine{root.nodes[0].parent === root; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21400}{}\doxysubsection{$<$tt$>$node.\+to\+String()$<$/tt$>$, $<$tt$>$\+String(node)$<$/tt$>$, or ‘’\textquotesingle{} + node\`{}}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21400}
Returns a string representation of the node.


\begin{DoxyCode}{0}
\DoxyCodeLine{const id = parser.id(\{value: 'search'\});}
\DoxyCodeLine{console.log(String(id));}
\DoxyCodeLine{// => \#search }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21401}{}\doxysubsection{$<$tt$>$node.\+next()$<$/tt$>$ \& $<$tt$>$node.\+prev()$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21401}
Returns the next/previous child of the parent node.


\begin{DoxyCode}{0}
\DoxyCodeLine{const next = id.next();}
\DoxyCodeLine{if (next \&\& next.type !== 'combinator') \{}
\DoxyCodeLine{    throw new Error('Qualified IDs are not allowed!');}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21402}{}\doxysubsection{$<$tt$>$node.\+replace\+With(node)$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21402}
Replace a node with another.


\begin{DoxyCode}{0}
\DoxyCodeLine{const attr = selectors.first.first;}
\DoxyCodeLine{const className = parser.className(\{value: 'test'\});}
\DoxyCodeLine{attr.replaceWith(className); }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily node}\+: The node to substitute the original with.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21403}{}\doxysubsection{$<$tt$>$node.\+remove()$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21403}
Removes the node from its parent node.


\begin{DoxyCode}{0}
\DoxyCodeLine{if (node.type === 'id') \{}
\DoxyCodeLine{    node.remove();}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21404}{}\doxysubsection{$<$tt$>$node.\+clone()$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21404}
Returns a copy of a node, detached from any parent containers that the original might have had.


\begin{DoxyCode}{0}
\DoxyCodeLine{const cloned = parser.id(\{value: 'search'\});}
\DoxyCodeLine{String(cloned);}
\DoxyCodeLine{}
\DoxyCodeLine{// => \#search }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21405}{}\doxysubsection{$<$tt$>$node.\+spaces$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21405}
Extra whitespaces around the node will be moved into {\ttfamily node.\+spaces.\+before} and {\ttfamily node.\+spaces.\+after}. So for example, these spaces will be moved as they have no semantic meaning\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{h1     ,     h2   \{\} }

\end{DoxyCode}


However, {\itshape combinating} spaces will form a {\ttfamily combinator} node\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{h1        h2 \{\} }

\end{DoxyCode}


A {\ttfamily combinator} node may only have the {\ttfamily spaces} property set if the combinator value is a non-\/whitespace character, such as {\ttfamily +}, {\ttfamily $\sim$} or {\ttfamily $>$}. Otherwise, the combinator value will contain all of the spaces between selectors.\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21406}{}\doxysubsection{$<$tt$>$node.\+source$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21406}
An object describing the node\textquotesingle{}s start/end, line/column source position.

Within the following CSS, the {\ttfamily .bar} class node ...


\begin{DoxyCode}{0}
\DoxyCodeLine{.foo,}
\DoxyCodeLine{  .bar \{\} }

\end{DoxyCode}


... will contain the following {\ttfamily source} object.


\begin{DoxyCode}{0}
\DoxyCodeLine{source: \{}
\DoxyCodeLine{    start: \{}
\DoxyCodeLine{        line: 2,}
\DoxyCodeLine{        column: 3}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    end: \{}
\DoxyCodeLine{        line: 2,}
\DoxyCodeLine{        column: 6}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21407}{}\doxysubsection{$<$tt$>$node.\+source\+Index$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21407}
The zero-\/based index of the node within the original source string.

Within the following CSS, the {\ttfamily .baz} class node will have a {\ttfamily source\+Index} of {\ttfamily 12}.


\begin{DoxyCode}{0}
\DoxyCodeLine{.foo, .bar, .baz \{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21408}{}\doxysection{Container types}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21408}
The {\ttfamily root}, {\ttfamily selector}, and {\ttfamily pseudo} nodes have some helper methods for working with their children.\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21409}{}\doxysubsection{$<$tt$>$container.\+nodes$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21409}
An array of the container\textquotesingle{}s children.


\begin{DoxyCode}{0}
\DoxyCodeLine{// Input: h1 h2}
\DoxyCodeLine{selectors.at(0).nodes.length   // => 3}
\DoxyCodeLine{selectors.at(0).nodes[0].value // => 'h1'}
\DoxyCodeLine{selectors.at(0).nodes[1].value // => ' ' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21410}{}\doxysubsection{$<$tt$>$container.\+first$<$/tt$>$ \& $<$tt$>$container.\+last$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21410}
The first/last child of the container.


\begin{DoxyCode}{0}
\DoxyCodeLine{selector.first === selector.nodes[0];}
\DoxyCodeLine{selector.last === selector.nodes[selector.nodes.length -\/ 1]; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21411}{}\doxysubsection{$<$tt$>$container.\+at(index)$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21411}
Returns the node at position {\ttfamily index}.


\begin{DoxyCode}{0}
\DoxyCodeLine{selector.at(0) === selector.first;}
\DoxyCodeLine{selector.at(0) === selector.nodes[0]; }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily index}\+: The index of the node to return.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21412}{}\doxysubsection{$<$tt$>$container.\+index(node)$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21412}
Return the index of the node within its container.


\begin{DoxyCode}{0}
\DoxyCodeLine{selector.index(selector.nodes[2]) // => 2 }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily node}\+: A node within the current container.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21413}{}\doxysubsection{$<$tt$>$container.\+length$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21413}
Proxy to the length of the container\textquotesingle{}s nodes.


\begin{DoxyCode}{0}
\DoxyCodeLine{container.length === container.nodes.length }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21414}{}\doxysubsection{$<$tt$>$container$<$/tt$>$ Array iterators}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21414}
The container class provides proxies to certain Array methods; these are\+:


\begin{DoxyItemize}
\item {\ttfamily container.\+map === container.\+nodes.\+map}
\item {\ttfamily container.\+reduce === container.\+nodes.\+reduce}
\item {\ttfamily container.\+every === container.\+nodes.\+every}
\item {\ttfamily container.\+some === container.\+nodes.\+some}
\item {\ttfamily container.\+filter === container.\+nodes.\+filter}
\item {\ttfamily container.\+sort === container.\+nodes.\+sort}
\end{DoxyItemize}

Note that these methods only work on a container\textquotesingle{}s immediate children; recursive iteration is provided by {\ttfamily container.\+walk}.\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21415}{}\doxysubsection{$<$tt$>$container.\+each(callback)$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21415}
Iterate the container\textquotesingle{}s immediate children, calling {\ttfamily callback} for each child. You may return {\ttfamily false} within the callback to break the iteration.


\begin{DoxyCode}{0}
\DoxyCodeLine{let className;}
\DoxyCodeLine{selectors.each((selector, index) => \{}
\DoxyCodeLine{    if (selector.type === 'class') \{}
\DoxyCodeLine{        className = selector.value;}
\DoxyCodeLine{        return false;}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


Note that unlike {\ttfamily Array\#for\+Each()}, this iterator is safe to use whilst adding or removing nodes from the container.

Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily callback (function)}\+: A function to call for each node, which receives {\ttfamily node} and {\ttfamily index} arguments.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21416}{}\doxysubsection{$<$tt$>$container.\+walk(callback)$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21416}
Like {\ttfamily container\#each}, but will also iterate child nodes as long as they are {\ttfamily container} types.


\begin{DoxyCode}{0}
\DoxyCodeLine{selectors.walk((selector, index) => \{}
\DoxyCodeLine{    // all nodes}
\DoxyCodeLine{\}); }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily callback (function)}\+: A function to call for each node, which receives {\ttfamily node} and {\ttfamily index} arguments.
\end{DoxyItemize}

This iterator is safe to use whilst mutating {\ttfamily container.\+nodes}, like {\ttfamily container\#each}.\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21417}{}\doxysubsection{$<$tt$>$container.\+walk$<$/tt$>$ proxies}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21417}
The container class provides proxy methods for iterating over types of nodes, so that it is easier to write modules that target specific selectors. Those methods are\+:


\begin{DoxyItemize}
\item {\ttfamily container.\+walk\+Attributes}
\item {\ttfamily container.\+walk\+Classes}
\item {\ttfamily container.\+walk\+Combinators}
\item {\ttfamily container.\+walk\+Comments}
\item {\ttfamily container.\+walk\+Ids}
\item {\ttfamily container.\+walk\+Nesting}
\item {\ttfamily container.\+walk\+Pseudos}
\item {\ttfamily container.\+walk\+Tags}
\item {\ttfamily container.\+walk\+Universals}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21418}{}\doxysubsection{$<$tt$>$container.\+split(callback)$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21418}
This method allows you to split a group of nodes by returning {\ttfamily true} from a callback. It returns an array of arrays, where each inner array corresponds to the groups that you created via the callback.


\begin{DoxyCode}{0}
\DoxyCodeLine{// (input) => h1 h2>>h3}
\DoxyCodeLine{const list = selectors.first.split(selector => \{}
\DoxyCodeLine{    return selector.type === 'combinator';}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{// (node values) => [['h1', ' '], ['h2', '>>'], ['h3']] }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily callback (function)}\+: A function to call for each node, which receives {\ttfamily node} as an argument.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21419}{}\doxysubsection{$<$tt$>$container.\+prepend(node)$<$/tt$>$ \& $<$tt$>$container.\+append(node)$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21419}
Add a node to the start/end of the container. Note that doing so will set the parent property of the node to this container.


\begin{DoxyCode}{0}
\DoxyCodeLine{const id = parser.id(\{value: 'search'\});}
\DoxyCodeLine{selector.append(id); }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily node}\+: The node to add.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21420}{}\doxysubsection{$<$tt$>$container.\+insert\+Before(old, new)$<$/tt$>$ \& $<$tt$>$container.\+insert\+After(old, new)$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21420}
Add a node before or after an existing node in a container\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{selectors.walk(selector => \{}
\DoxyCodeLine{    if (selector.type !== 'class') \{}
\DoxyCodeLine{        const className = parser.className(\{value: 'theme-\/name'\});}
\DoxyCodeLine{        selector.parent.insertAfter(selector, className);}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily old}\+: The existing node in the container.
\item {\ttfamily new}\+: The new node to add before/after the existing node.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21421}{}\doxysubsection{$<$tt$>$container.\+remove\+Child(node)$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21421}
Remove the node from the container. Note that you can also use {\ttfamily node.\+remove()} if you would like to remove just a single node.


\begin{DoxyCode}{0}
\DoxyCodeLine{selector.length // => 2}
\DoxyCodeLine{selector.remove(id)}
\DoxyCodeLine{selector.length // => 1;}
\DoxyCodeLine{id.parent       // undefined }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily node}\+: The node to remove.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21422}{}\doxysubsection{$<$tt$>$container.\+remove\+All()$<$/tt$>$ or $<$tt$>$container.\+empty()$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21422}
Remove all children from the container.


\begin{DoxyCode}{0}
\DoxyCodeLine{selector.removeAll();}
\DoxyCodeLine{selector.length // => 0 }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21423}{}\doxysection{Root nodes}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21423}
A root node represents a comma separated list of selectors. Indeed, all a root\textquotesingle{}s {\ttfamily to\+String()} method does is join its selector children with a \textquotesingle{},\textquotesingle{}. Other than this, it has no special functionality and acts like a container.\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21424}{}\doxysubsection{$<$tt$>$root.\+trailing\+Comma$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21424}
This will be set to {\ttfamily true} if the input has a trailing comma, in order to support parsing of legacy CSS hacks.\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21425}{}\doxysection{Selector nodes}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21425}
A selector node represents a single compound selector. For example, this selector string {\ttfamily h1 h2 h3, \mbox{[}href\mbox{]} $>$ p}, is represented as two selector nodes. It has no special functionality of its own.\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21426}{}\doxysection{Pseudo nodes}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21426}
A pseudo selector extends a container node; if it has any parameters of its own (such as {\ttfamily h1\+:not(h2, h3)}), they will be its children. Note that the pseudo {\ttfamily value} will always contain the colons preceding the pseudo identifier. This is so that both {\ttfamily \+:before} and {\ttfamily \+::before} are properly represented in the AST.\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21427}{}\doxysection{Attribute nodes}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21427}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21428}{}\doxysubsection{$<$tt$>$attribute.\+quoted$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21428}
Returns {\ttfamily true} if the attribute\textquotesingle{}s value is wrapped in quotation marks, false if it is not. Remains {\ttfamily undefined} if there is no attribute value.


\begin{DoxyCode}{0}
\DoxyCodeLine{[href=foo] /* false */}
\DoxyCodeLine{[href='foo'] /* true */}
\DoxyCodeLine{[href="{}foo"{}] /* true */}
\DoxyCodeLine{[href] /* undefined */ }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21429}{}\doxysubsection{$<$tt$>$attribute.\+qualified\+Attribute$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21429}
Returns the attribute name qualified with the namespace if one is given.\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21430}{}\doxysubsection{$<$tt$>$attribute.\+offset\+Of(part)$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21430}
Returns the offset of the attribute part specified relative to the start of the node of the output string. This is useful in raising error messages about a specific part of the attribute, especially in combination with {\ttfamily attribute.\+source\+Index}.

Returns {\ttfamily -\/1} if the name is invalid or the value doesn\textquotesingle{}t exist in this attribute.

The legal values for {\ttfamily part} are\+:


\begin{DoxyItemize}
\item {\ttfamily \char`\"{}ns\char`\"{}} -\/ alias for \char`\"{}namespace\char`\"{}
\item {\ttfamily \char`\"{}namespace\char`\"{}} -\/ the namespace if it exists.
\item {\ttfamily \char`\"{}attribute\char`\"{}} -\/ the attribute name
\item {\ttfamily \char`\"{}attribute\+NS\char`\"{}} -\/ the start of the attribute or its namespace
\item {\ttfamily \char`\"{}operator\char`\"{}} -\/ the match operator of the attribute
\item {\ttfamily \char`\"{}value\char`\"{}} -\/ The value (string or identifier)
\item {\ttfamily \char`\"{}insensitive\char`\"{}} -\/ the case insensitivity flag
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21431}{}\doxysubsection{$<$tt$>$attribute.\+raws.\+unquoted$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21431}
Returns the unquoted content of the attribute\textquotesingle{}s value. Remains {\ttfamily undefined} if there is no attribute value.


\begin{DoxyCode}{0}
\DoxyCodeLine{[href=foo] /* foo */}
\DoxyCodeLine{[href='foo'] /* foo */}
\DoxyCodeLine{[href="{}foo"{}] /* foo */}
\DoxyCodeLine{[href] /* undefined */ }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21432}{}\doxysubsection{$<$tt$>$attribute.\+spaces$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21432}
Like {\ttfamily node.\+spaces} with the {\ttfamily before} and {\ttfamily after} values containing the spaces around the element, the parts of the attribute can also have spaces before and after them. The for each of {\ttfamily attribute}, {\ttfamily operator}, {\ttfamily value} and {\ttfamily insensitive} there is corresponding property of the same nam in {\ttfamily node.\+spaces} that has an optional {\ttfamily before} or {\ttfamily after} string containing only whitespace.

Note that corresponding values in {\ttfamily attributes.\+raws.\+spaces} contain values including any comments. If set, these values will override the {\ttfamily attribute.\+spaces} value. Take care to remove them if changing {\ttfamily attribute.\+spaces}.\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21433}{}\doxysubsection{$<$tt$>$attribute.\+raws$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21433}
The raws object stores comments and other information necessary to re-\/render the node exactly as it was in the source.

If a comment is embedded within the identifiers for the {\ttfamily namespace}, {\ttfamily attribute} or {\ttfamily value} then a property is placed in the raws for that value containing the full source of the propery including comments.

If a comment is embedded within the space between parts of the attribute then the raw for that space is set accordingly.

Setting an attribute\textquotesingle{}s property {\ttfamily raws} value to be deleted.

For now, changing the spaces required also updating or removing any of the raws values that override them.

Example\+: {\ttfamily \mbox{[} /$\ast$before$\ast$/ href /$\ast$ after-\/attr $\ast$/ = /$\ast$ after-\/operator $\ast$/ te/$\ast$inside-\/value$\ast$/st/$\ast$ wow $\ast$/ /$\ast$omg$\ast$/i/$\ast$bbq$\ast$/ /$\ast$whodoesthis$\ast$/\mbox{]}} would parse as\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  attribute: "{}href"{},}
\DoxyCodeLine{  operatator: "{}="{},}
\DoxyCodeLine{  value: "{}test"{},}
\DoxyCodeLine{  spaces: \{}
\DoxyCodeLine{    before: '',}
\DoxyCodeLine{    after: '',}
\DoxyCodeLine{    attribute: \{ before: '  ', after: '  ' \},}
\DoxyCodeLine{    operator: \{ after: '  ' \},}
\DoxyCodeLine{    value: \{ after: ' ' \},}
\DoxyCodeLine{    insensitive: \{ after: ' ' \}}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  raws: \{}
\DoxyCodeLine{    spaces: \{}
\DoxyCodeLine{      attribute: \{ before: ' /*before*/ ', after: ' /* after-\/attr */ ' \},}
\DoxyCodeLine{      operator: \{ after: ' /* after-\/operator */ ' \},}
\DoxyCodeLine{      value: \{ after: '/* wow */ /*omg*/' \},}
\DoxyCodeLine{      insensitive: \{ after: '/*bbq*/ /*whodoesthis*/' \}}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    unquoted: 'test',}
\DoxyCodeLine{    value: 'te/*inside-\/value*/st'}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21434}{}\doxysection{$<$tt$>$\+Processor$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21434}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21435}{}\doxysubsection{$<$tt$>$\+Processor\+Options$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21435}

\begin{DoxyItemize}
\item {\ttfamily lossless} -\/ When {\ttfamily true}, whitespace is preserved. Defaults to {\ttfamily true}.
\item {\ttfamily update\+Selector} -\/ When {\ttfamily true}, if any processor methods are passed a postcss {\ttfamily Rule} node instead of a string, then that Rule\textquotesingle{}s selector is updated with the results of the processing. Defaults to {\ttfamily true}.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21436}{}\doxysubsection{$<$tt$>$process$\vert$process\+Sync(selectors, \mbox{[}options\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21436}
Processes the {\ttfamily selectors}, returning a string from the result of processing.

Note\+: when the {\ttfamily update\+Selector} option is set, the rule\textquotesingle{}s selector will be updated with the resulting string.

{\bfseries{Example\+:}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const parser = require("{}postcss-\/selector-\/parser"{});}
\DoxyCodeLine{const processor = parser();}
\DoxyCodeLine{}
\DoxyCodeLine{let result = processor.processSync(' .class');}
\DoxyCodeLine{console.log(result);}
\DoxyCodeLine{// =>  .class}
\DoxyCodeLine{}
\DoxyCodeLine{// Asynchronous operation}
\DoxyCodeLine{let promise = processor.process(' .class').then(result => \{}
\DoxyCodeLine{    console.log(result)}
\DoxyCodeLine{    // => .class}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{// To have the parser normalize whitespace values, utilize the options}
\DoxyCodeLine{result = processor.processSync('  .class  ', \{lossless: false\});}
\DoxyCodeLine{console.log(result);}
\DoxyCodeLine{// => .class}
\DoxyCodeLine{}
\DoxyCodeLine{// For better syntax errors, pass a PostCSS Rule node.}
\DoxyCodeLine{const postcss = require('postcss');}
\DoxyCodeLine{rule = postcss.rule(\{selector: ' \#foo    > a,  .class  '\});}
\DoxyCodeLine{processor.process(rule, \{lossless: false, updateSelector: true\}).then(result => \{}
\DoxyCodeLine{    console.log(result);}
\DoxyCodeLine{    // => \#foo>a,.class}
\DoxyCodeLine{    console.log("{}rule:"{}, rule.selector);}
\DoxyCodeLine{    // => rule: \#foo>a,.class}
\DoxyCodeLine{\}) }

\end{DoxyCode}


Arguments\+:


\begin{DoxyItemize}
\item {\ttfamily selectors (string$\vert$postcss.Rule)}\+: Either a selector string or a Post\+CSS Rule node.
\item {\ttfamily \mbox{[}options\mbox{]} (object)}\+: Process options
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21437}{}\doxysubsection{$<$tt$>$ast$\vert$ast\+Sync(selectors, \mbox{[}options\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21437}
Like {\ttfamily process()} and {\ttfamily process\+Sync()} but after processing the {\ttfamily selectors} these methods return the {\ttfamily Root} node of the result instead of a string.

Note\+: when the {\ttfamily update\+Selector} option is set, the rule\textquotesingle{}s selector will be updated with the resulting string.\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21438}{}\doxysubsection{$<$tt$>$transform$\vert$transform\+Sync(selectors, \mbox{[}options\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21438}
Like {\ttfamily process()} and {\ttfamily process\+Sync()} but after processing the {\ttfamily selectors} these methods return the value returned by the processor callback.

Note\+: when the {\ttfamily update\+Selector} option is set, the rule\textquotesingle{}s selector will be updated with the resulting string.\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21439}{}\doxysubsection{Error Handling Within Selector Processors}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21439}
The root node passed to the selector processor callback has a method {\ttfamily error(message, options)} that returns an error object. This method should always be used to raise errors relating to the syntax of selectors. The options to this method are passed to postcss\textquotesingle{}s error constructor (\href{http://api.postcss.org/Container.html\#error}{\texttt{ documentation}}).\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21440}{}\doxysubsubsection{Async Error Example}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21440}

\begin{DoxyCode}{0}
\DoxyCodeLine{let processor = (root) => \{}
\DoxyCodeLine{    return new Promise((resolve, reject) => \{}
\DoxyCodeLine{        root.walkClasses((classNode) => \{}
\DoxyCodeLine{            if (/\string^(.*)[-\/\_]/.test(classNode.value)) \{}
\DoxyCodeLine{                let msg = "{}classes may not have underscores or dashes in them"{};}
\DoxyCodeLine{                reject(root.error(msg, \{}
\DoxyCodeLine{                    index: classNode.sourceIndex + RegExp.\$1.length + 1,}
\DoxyCodeLine{                    word: classNode.value}
\DoxyCodeLine{                \}));}
\DoxyCodeLine{            \}}
\DoxyCodeLine{        \});}
\DoxyCodeLine{        resolve();}
\DoxyCodeLine{    \});}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{const postcss = require("{}postcss"{});}
\DoxyCodeLine{const parser = require("{}postcss-\/selector-\/parser"{});}
\DoxyCodeLine{const selectorProcessor = parser(processor);}
\DoxyCodeLine{const plugin = postcss.plugin('classValidator', (options) => \{}
\DoxyCodeLine{    return (root) => \{}
\DoxyCodeLine{        let promises = [];}
\DoxyCodeLine{        root.walkRules(rule => \{}
\DoxyCodeLine{            promises.push(selectorProcessor.process(rule));}
\DoxyCodeLine{        \});}
\DoxyCodeLine{        return Promise.all(promises);}
\DoxyCodeLine{    \};}
\DoxyCodeLine{\});}
\DoxyCodeLine{postcss(plugin()).process(`}
\DoxyCodeLine{.foo-\/bar \{}
\DoxyCodeLine{  color: red;}
\DoxyCodeLine{\}}
\DoxyCodeLine{`.trim(), \{from: 'test.css'\}).catch((e) => console.error(e.toString()));}
\DoxyCodeLine{}
\DoxyCodeLine{// CssSyntaxError: classValidator: ./test.css:1:5: classes may not have underscores or dashes in them}
\DoxyCodeLine{// }
\DoxyCodeLine{// > 1 | .foo-\/bar \{}
\DoxyCodeLine{//     |     \string^}
\DoxyCodeLine{//   2 |   color: red;}
\DoxyCodeLine{//   3 | \} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21441}{}\doxysubsubsection{Synchronous Error Example}\label{md_sfcode_node_modules_postcss_merge_rules_node_modules_postcss_selector_parser_API_autotoc_md21441}

\begin{DoxyCode}{0}
\DoxyCodeLine{let processor = (root) => \{}
\DoxyCodeLine{    root.walkClasses((classNode) => \{}
\DoxyCodeLine{        if (/.*[-\/\_]/.test(classNode.value)) \{}
\DoxyCodeLine{            let msg = "{}classes may not have underscores or dashes in them"{};}
\DoxyCodeLine{            throw root.error(msg, \{}
\DoxyCodeLine{                index: classNode.sourceIndex,}
\DoxyCodeLine{                word: classNode.value}
\DoxyCodeLine{            \});}
\DoxyCodeLine{        \}}
\DoxyCodeLine{    \});}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{const postcss = require("{}postcss"{});}
\DoxyCodeLine{const parser = require("{}postcss-\/selector-\/parser"{});}
\DoxyCodeLine{const selectorProcessor = parser(processor);}
\DoxyCodeLine{const plugin = postcss.plugin('classValidator', (options) => \{}
\DoxyCodeLine{    return (root) => \{}
\DoxyCodeLine{        root.walkRules(rule => \{}
\DoxyCodeLine{            selectorProcessor.processSync(rule);}
\DoxyCodeLine{        \});}
\DoxyCodeLine{    \};}
\DoxyCodeLine{\});}
\DoxyCodeLine{postcss(plugin()).process(`}
\DoxyCodeLine{.foo-\/bar \{}
\DoxyCodeLine{  color: red;}
\DoxyCodeLine{\}}
\DoxyCodeLine{`.trim(), \{from: 'test.css'\}).catch((e) => console.error(e.toString()));}
\DoxyCodeLine{}
\DoxyCodeLine{// CssSyntaxError: classValidator: ./test.css:1:5: classes may not have underscores or dashes in them}
\DoxyCodeLine{// }
\DoxyCodeLine{// > 1 | .foo-\/bar \{}
\DoxyCodeLine{//     |     \string^}
\DoxyCodeLine{//   2 |   color: red;}
\DoxyCodeLine{//   3 | \} }

\end{DoxyCode}
 