Skip to content

Commit 84c63c2

Browse files
not-an-aardvarkmichaelficarra
authored andcommitted
Check whether a sibling/adjacent query is necessary before running it
This improves performance for sibling matches that don't use subject indicators.
1 parent 8e64df1 commit 84c63c2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

esquery.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,16 @@
126126
case 'sibling':
127127
return matches(node, selector.right, ancestry) &&
128128
sibling(node, selector.left, ancestry, LEFT_SIDE) ||
129+
selector.left.subject &&
129130
matches(node, selector.left, ancestry) &&
130-
sibling(node, selector.right, ancestry, RIGHT_SIDE) &&
131-
selector.left.subject;
131+
sibling(node, selector.right, ancestry, RIGHT_SIDE);
132132

133133
case 'adjacent':
134134
return matches(node, selector.right, ancestry) &&
135135
adjacent(node, selector.left, ancestry, LEFT_SIDE) ||
136+
selector.right.subject &&
136137
matches(node, selector.left, ancestry) &&
137-
adjacent(node, selector.right, ancestry, RIGHT_SIDE) &&
138-
selector.left.subject;
138+
adjacent(node, selector.right, ancestry, RIGHT_SIDE);
139139

140140
case 'nth-child':
141141
return matches(node, selector.right, ancestry) &&

0 commit comments

Comments
 (0)