e01f913d by Adam Heath

Add pseudo-element after/before handling; this is not actually used yet

during rendering anywhere.
1 parent 124aa3c4
......@@ -37,7 +37,8 @@ const nthChildPos = (node, parent) => filterChildElements(parent).findIndex((chi
const filterChildElementsMatcher = (context, child, parent, i) => child.type === ELEMENT_NODE
type Matcher = (context, node: NodeType, parent?: NodeType, i: number, debug: number) => boolean
type NodePosition = number | 'before' | 'after'
type Matcher = (context, node: NodeType, parent?: NodeType, i: NodePosition, debug: number) => boolean
type MatcherProducer = () => Matcher
type AttrValueMatch = (string) => string
......@@ -295,6 +296,16 @@ const compileMatcher = (ast: AST, selector: string): MatcherProducer => {
}
case 'universal':
return (context, node, parent, i, debug) => true
case 'pseudo-element':
switch (ast.name) {
case 'after':
return (context, node, parent, i, debug) => i === 'after'
case 'before':
return (context, node, parent, i, debug) => i === 'before'
default:
console.error('pseudo-class', nodeUtil.inspect({ selector, ast }, { depth: null, colors: true }))
throw new Error(`Unknown pseudo-class: ${ast.name}`)
}
default:
throw new Error(`Unhandled ast: ${ast.type}`)
}
......