Skip to content

Commit

Permalink
feat(parse): Add isTraversal function
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Oct 12, 2020
1 parent f2bed80 commit 8f64671
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ const unpackPseudos = new Set([
"host-context",
]);

const traversalNames = new Set<TraversalType>([
"descendant",
...Object.keys(Traversals).map((k) => Traversals[k]),
]);

/**
* Checks whether a specific selector is a traversal.
* This is useful eg. in swapping the order of elements that
* are not traversals.
*
* @param selector Selector to check.
*/
export function isTraversal(selector: Selector): selector is Traversal {
return traversalNames.has(selector.type as TraversalType);
}

const stripQuotesFromPseudos = new Set(["contains", "icontains"]);

const quotes = new Set(['"', "'"]);
Expand Down

0 comments on commit 8f64671

Please sign in to comment.