import { trueFunc , falseFunc } from "boolbase" ; import type { CompiledQuery , InternalOptions , CompileToken } from "../types" ; import { parse , PseudoSelector } from "css-what" ; import { filters } from "./filters" ; import { pseudos , verifyPseudoArgs } from "./pseudos" ; import { aliases } from "./aliases" ; import { subselects } from "./subselects" ; export { filters , pseudos , aliases } ; export function compilePseudoSelector < Node , ElementNode extends Node > ( next , selector , options , context , compileToken ) { const { name , data } = selector ; if ( Array . isArray ( data ) ) { return subselects [ name ] ( next , data , options , context , compileToken ) ; } if ( name in aliases ) { if ( data != null ) { throw new Error ( `Pseudo ${ name } doesn't have any arguments` ) ; } const alias = parse ( aliases [ name ] ) ; return subselects . is ( next , alias , options , context , compileToken ) ; } if ( name in filters ) { return filters [ name ] ( next , data as string , options , context ) ; } if ( name in pseudos ) { const pseudo = pseudos [ name ] ; verifyPseudoArgs ( pseudo , name , data ) ; return pseudo === falseFunc ? falseFunc : next === trueFunc ? ( elem ) => pseudo ( elem , options , data ) : ( elem ) => pseudo ( elem , options , data ) && next ( elem ) ; } throw new Error ( `unmatched pseudo-class :${ name }` ) ; }