lib/transform-selectors-by-custom-selectors.js
function transformSelector(selector, customSelectors) {
	const transpiledSelectors = [];

	for (const index in selector.nodes) {
		const { value, nodes } = selector.nodes[index];

		if (value in customSelectors) {
			for (const replacementSelector of customSelectors[value].nodes) {
				const selectorClone = selector.clone();

				selectorClone.nodes.splice(index, 1, ...replacementSelector.clone().nodes.map(node => {
					// use spacing from the current usage
					node.spaces = { ...selector.nodes[index].spaces };

					return node;
				}));

				const retranspiledSelectors = transformSelector(selectorClone, customSelectors);

				adjustNodesBySelectorEnds(selectorClone.nodes, Number(index));

				if (retranspiledSelectors.length) {
					transpiledSelectors.push(...retranspiledSelectors);
				} else {
					transpiledSelectors.push(selectorClone);
				}
			}

			return transpiledSelectors;
		} else if (nodes && nodes.length) {
			transformSelectorList(selector.nodes[index], customSelectors);
		}
	}

	return transpiledSelectors;
}
function transformSelector(selector, customSelectors) {
	const transpiledSelectors = [];

	for (const index in selector.nodes) {
		const { value, nodes } = selector.nodes[index];

		if (value in customSelectors) {
			for (const replacementSelector of customSelectors[value].nodes) {
				const selectorClone = selector.clone();

				selectorClone.nodes.splice(index, 1, ...replacementSelector.clone().nodes.map(node => {
					// use spacing from the current usage
					node.spaces = { ...selector.nodes[index].spaces };

					return node;
				}));

				const retranspiledSelectors = transformSelector(selectorClone, customSelectors);

				adjustNodesBySelectorEnds(selectorClone.nodes, Number(index));

				if (retranspiledSelectors.length) {
					transpiledSelectors.push(...retranspiledSelectors);
				} else {
					transpiledSelectors.push(selectorClone);
				}
			}

			return transpiledSelectors;
		} else if (nodes && nodes.length) {
			transformSelectorList(selector.nodes[index], customSelectors);
		}
	}

	return transpiledSelectors;
}
function transformSelector ( selector , customSelectors ) { const transpiledSelectors = [ ] ; for ( const index in selector . nodes ) { const { value , nodes } = selector . nodes [ index ] ; if ( value in customSelectors ) { for ( const replacementSelector of customSelectors [ value ] . nodes ) { const selectorClone = selector . clone ( ) ; selectorClone . nodes . splice ( index , 1 , ... replacementSelector . clone ( ) . nodes . map ( node => { // use spacing from the current usage node . spaces = { ... selector . nodes [ index ] . spaces } ; return node ; } ) ) ; const retranspiledSelectors = transformSelector ( selectorClone , customSelectors ) ; adjustNodesBySelectorEnds ( selectorClone . nodes , Number ( index ) ) ; if ( retranspiledSelectors . length ) { transpiledSelectors . push ( ... retranspiledSelectors ) ; } else { transpiledSelectors . push ( selectorClone ) ; } } return transpiledSelectors ; } else if ( nodes && nodes . length ) { transformSelectorList ( selector . nodes [ index ] , customSelectors ) ; } } return transpiledSelectors ; }
return custom pseudo selectors replaced with custom selectors
return custom pseudo selectors replaced with custom selectors