Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ro0gr committed Oct 21, 2023
1 parent 5385202 commit 1a189dd
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions addon/src/-private/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export class Query {
* @param {boolean} locator.testContainer - Filter by using :visible pseudo-class
*/
constructor(node, options) {
const fullPath = toArray(node)
const fullPath = allNodesToTheRoot(node)
.reverse()
.map((node) => {
return {
scope: buildLocator(node.scope),
Expand All @@ -47,13 +48,9 @@ export class Query {

const leafLocator = buildLocator(options);
if (leafLocator) {
fullPath.push(
leafLocator
? {
scope: leafLocator,
}
: null
);
fullPath.push({
scope: leafLocator,
});
}

this.testContainer =
Expand Down Expand Up @@ -88,23 +85,23 @@ export class Query {
);
}

// @todo: tests for filters via findOne
// TODO: tests for filters via findOne
toString() {
return this.path.map((p) => p.toString()).join(' ');
}
}

function toArray(node) {
function allNodesToTheRoot(node) {
let iterator = node;
let values = [];
let nodes = [];

while (typeof iterator !== 'undefined') {
values.push(iterator);
nodes.push(iterator);

iterator = Ceibo.parent(iterator);
}

return values.reverse();
return nodes;
}

function buildLocator(options) {
Expand Down

0 comments on commit 1a189dd

Please sign in to comment.