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
4686c066
authored
2024-11-22 10:34:41 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
In complex, rename 'seen' to leftMatches.
1 parent
4acd3583
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
lib/html.ts
lib/html.ts
View file @
4686c06
...
...
@@ -152,39 +152,39 @@ const compileMatcher = (ast: AST, selector: string): MatcherProducer => {
case
'complex'
:
{
const
{
left
,
right
,
combinator
,
pos
}
=
ast
const
leftMatcher
=
makeMatcher
(
left
)
const
leftCounter
=
counter
++
neededContext
[
leftCounter
]
=
()
=>
new
WeakSet
()
const
rightMatcher
=
makeMatcher
(
right
)
const
setCounter
=
counter
++
neededContext
[
setCounter
]
=
()
=>
new
WeakSet
()
return
(
context
,
node
,
parent
,
i
,
debug
)
=>
{
const
seen
=
context
[
setCounter
]
const
{
[
leftCounter
]:
leftMatches
}
=
context
if
(
leftMatcher
(
context
,
node
,
parent
,
i
,
debug
))
{
if
(
debug
)
console
.
log
(
'matched on left'
,
{
left
,
right
,
combinator
,
pos
,
parent
})
// TODO: Check
seen
.has(), and maybe skip calling leftMatcher?
seen
.
add
(
node
)
}
else
if
(
parent
&&
seen
.
has
(
parent
)
&&
combinator
===
' '
)
{
seen
.
add
(
node
)
// TODO: Check
leftMatches
.has(), and maybe skip calling leftMatcher?
leftMatches
.
add
(
node
)
}
else
if
(
parent
&&
leftMatches
.
has
(
parent
)
&&
combinator
===
' '
)
{
leftMatches
.
add
(
node
)
}
if
(
!
rightMatcher
(
context
,
node
,
parent
,
i
,
debug
))
return
false
seen
.
add
(
node
)
leftMatches
.
add
(
node
)
if
(
debug
)
console
.
log
(
'matched on right'
,
{
left
,
right
,
combinator
,
pos
,
node
,
parent
})
switch
(
combinator
)
{
case
' '
:
let
parentPtr
=
parent
while
(
parentPtr
)
{
if
(
seen
.
has
(
parentPtr
))
return
true
if
(
leftMatches
.
has
(
parentPtr
))
return
true
parentPtr
=
parentPtr
.
parent
}
return
false
case
'>'
:
if
(
debug
)
console
.
log
(
'
seen parent'
,
seen
.
has
(
parent
))
return
parent
?
seen
.
has
(
parent
)
:
false
if
(
debug
)
console
.
log
(
'
leftMatches parent'
,
leftMatches
.
has
(
parent
))
return
parent
?
leftMatches
.
has
(
parent
)
:
false
case
'+'
:
{
if
(
!
parent
)
return
false
let
prevSiblings
=
parent
.
children
.
slice
(
0
,
i
).
filter
((
el
)
=>
el
.
type
===
ELEMENT_NODE
)
if
(
prevSiblings
.
length
===
0
)
return
false
const
prev
=
prevSiblings
[
prevSiblings
.
length
-
1
]
if
(
!
prev
)
return
false
if
(
seen
.
has
(
prev
))
return
true
if
(
leftMatches
.
has
(
prev
))
return
true
return
false
}
case
'~'
:
{
...
...
@@ -192,7 +192,7 @@ const compileMatcher = (ast: AST, selector: string): MatcherProducer => {
let
prevSiblings
=
parent
.
children
.
slice
(
0
,
i
).
filter
((
el
)
=>
el
.
type
===
ELEMENT_NODE
)
if
(
prevSiblings
.
length
===
0
)
return
false
for
(
const
prev
of
prevSiblings
)
{
if
(
seen
.
has
(
prev
))
return
true
if
(
leftMatches
.
has
(
prev
))
return
true
}
return
false
}
...
...
Please
register
or
sign in
to post a comment