Skip to content

Commit

Permalink
refactor: Inline siblingTraversal
Browse files Browse the repository at this point in the history
No need to use a `Set`
  • Loading branch information
fb55 committed May 16, 2022
1 parent 8ba4fc8 commit 9e949dd
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,6 @@ export function select(
return DomUtils.uniqueSort(results.reduce((a, b) => [...a, ...b]));
}

// Traversals that are treated differently in css-select.
const siblingTraversal = new Set<SelectorType>([
SelectorType.Sibling,
SelectorType.Adjacent,
]);

/**
*
* @param root Element(s) to search from.
Expand Down Expand Up @@ -284,7 +278,12 @@ function findFilterElements(

if (remainingHasTraversal) {
if (isTraversal(remainingSelector[0])) {
if (siblingTraversal.has(remainingSelector[0].type)) {
const { type } = remainingSelector[0];

if (
type === SelectorType.Sibling ||
type === SelectorType.Adjacent
) {
// If we have a sibling traversal, we need to also look at the siblings.
result = prepareContext(result, DomUtils, true) as Element[];
}
Expand Down

0 comments on commit 9e949dd

Please sign in to comment.