Skip to content

Commit

Permalink
Use LEFT_SIDE and RIGHT_SIDE constants instead of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark authored and michaelficarra committed Mar 9, 2017
1 parent b171617 commit 8e64df1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions esquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
return {}.toString.call(array) === '[object Array]';
};

var LEFT_SIDE = {};
var RIGHT_SIDE = {};

function esqueryModule() {

/**
Expand Down Expand Up @@ -122,16 +125,16 @@

case 'sibling':
return matches(node, selector.right, ancestry) &&
sibling(node, selector.left, ancestry, 'left') ||
sibling(node, selector.left, ancestry, LEFT_SIDE) ||
matches(node, selector.left, ancestry) &&
sibling(node, selector.right, ancestry, 'right') &&
sibling(node, selector.right, ancestry, RIGHT_SIDE) &&
selector.left.subject;

case 'adjacent':
return matches(node, selector.right, ancestry) &&
adjacent(node, selector.left, ancestry, 'left') ||
adjacent(node, selector.left, ancestry, LEFT_SIDE) ||
matches(node, selector.left, ancestry) &&
adjacent(node, selector.right, ancestry, 'right') &&
adjacent(node, selector.right, ancestry, RIGHT_SIDE) &&
selector.left.subject;

case 'nth-child':
Expand Down Expand Up @@ -183,7 +186,7 @@
if (isArray(listProp)) {
startIndex = listProp.indexOf(node);
if (startIndex < 0) { continue; }
if (side === 'left') {
if (side === LEFT_SIDE) {
lowerBound = 0;
upperBound = startIndex;
} else {
Expand Down Expand Up @@ -212,10 +215,10 @@
if (isArray(listProp)) {
idx = listProp.indexOf(node);
if (idx < 0) { continue; }
if (side === 'left' && idx > 0 && matches(listProp[idx - 1], selector, ancestry)) {
if (side === LEFT_SIDE && idx > 0 && matches(listProp[idx - 1], selector, ancestry)) {
return true;
}
if (side === 'right' && idx < listProp.length - 1 && matches(listProp[idx + 1], selector, ancestry)) {
if (side === RIGHT_SIDE && idx < listProp.length - 1 && matches(listProp[idx + 1], selector, ancestry)) {
return true;
}
}
Expand Down

0 comments on commit 8e64df1

Please sign in to comment.