Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
astro-wt
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
4acd3583
authored
2024-11-22 10:32:35 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Fix first-child/last-child matching.
1 parent
abfc737a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
3 deletions
lib/html.ts
lib/html.ts
View file @
4acd358
...
...
@@ -237,16 +237,19 @@ const compileMatcher = (ast: AST, selector: string): MatcherProducer => {
}
case
'first-child'
:
return
(
context
,
node
,
parent
,
i
,
debug
)
=>
{
return
parent
?.
children
.
findFirst
(
child
=>
child
.
type
===
ELEMENT_NODE
)
===
node
const
children
=
findChildren
(
context
,
parent
,
'ELEMENT'
,
filterChildElementsMatcher
)
return
children
[
0
]
==
node
}
case
'last-child'
:
return
(
context
,
node
,
parent
,
i
,
debug
)
=>
{
return
parent
?.
children
.
findLast
(
child
=>
child
.
type
===
ELEMENT_NODE
)
===
node
const
children
=
findChildren
(
context
,
parent
,
'ELEMENT'
,
filterChildElementsMatcher
)
return
children
[
children
.
length
-
1
]
==
node
}
case
'only-child'
:
return
(
context
,
node
,
parent
,
i
,
debug
)
=>
{
// TODO: This can break-early after it finds the second element
return
findChildren
(
context
,
parent
,
'ELEMENT'
,
filterChildElementsMatcher
).
length
===
1
const
children
=
findChildren
(
context
,
parent
,
'ELEMENT'
,
filterChildElementsMatcher
)
return
children
.
length
===
1
}
// case 'nth-of-type':
// case 'nth-last-of-type':
...
...
Please
register
or
sign in
to post a comment