Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit internal nth child tagnames when direct child #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

type Knot = {
name: string
nameAsChild?: string
penalty: number
level?: number
}
Expand Down Expand Up @@ -154,11 +155,15 @@ function findUniquePath(
function selector(path: Path): string {
let node = path[0]
let query = node.name
let queryAsChild = node.nameAsChild || node.name
for (let i = 1; i < path.length; i++) {
const level = path[i].level || 0
let nameAsChild = path[i].nameAsChild || path[i].name
if (node.level === level - 1) {
query = `${path[i].name} > ${query}`
query = `${path[i].name} > ${queryAsChild}`
queryAsChild = `${nameAsChild} > ${queryAsChild}`
} else {
queryAsChild = `${nameAsChild} ${query}`
query = `${path[i].name} ${query}`
}
node = path[i]
Expand Down Expand Up @@ -265,6 +270,7 @@ function index(input: Element): number | null {
function nthChild(node: Knot, i: number): Knot {
return {
name: node.name + `:nth-child(${i})`,
nameAsChild: `:nth-child(${i})`,
penalty: node.penalty + 1,
}
}
Expand Down