Skip to content

Commit 8e64df1

Browse files
not-an-aardvarkmichaelficarra
authored andcommitted
Use LEFT_SIDE and RIGHT_SIDE constants instead of strings
1 parent b171617 commit 8e64df1

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

esquery.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
return {}.toString.call(array) === '[object Array]';
99
};
1010

11+
var LEFT_SIDE = {};
12+
var RIGHT_SIDE = {};
13+
1114
function esqueryModule() {
1215

1316
/**
@@ -122,16 +125,16 @@
122125

123126
case 'sibling':
124127
return matches(node, selector.right, ancestry) &&
125-
sibling(node, selector.left, ancestry, 'left') ||
128+
sibling(node, selector.left, ancestry, LEFT_SIDE) ||
126129
matches(node, selector.left, ancestry) &&
127-
sibling(node, selector.right, ancestry, 'right') &&
130+
sibling(node, selector.right, ancestry, RIGHT_SIDE) &&
128131
selector.left.subject;
129132

130133
case 'adjacent':
131134
return matches(node, selector.right, ancestry) &&
132-
adjacent(node, selector.left, ancestry, 'left') ||
135+
adjacent(node, selector.left, ancestry, LEFT_SIDE) ||
133136
matches(node, selector.left, ancestry) &&
134-
adjacent(node, selector.right, ancestry, 'right') &&
137+
adjacent(node, selector.right, ancestry, RIGHT_SIDE) &&
135138
selector.left.subject;
136139

137140
case 'nth-child':
@@ -183,7 +186,7 @@
183186
if (isArray(listProp)) {
184187
startIndex = listProp.indexOf(node);
185188
if (startIndex < 0) { continue; }
186-
if (side === 'left') {
189+
if (side === LEFT_SIDE) {
187190
lowerBound = 0;
188191
upperBound = startIndex;
189192
} else {
@@ -212,10 +215,10 @@
212215
if (isArray(listProp)) {
213216
idx = listProp.indexOf(node);
214217
if (idx < 0) { continue; }
215-
if (side === 'left' && idx > 0 && matches(listProp[idx - 1], selector, ancestry)) {
218+
if (side === LEFT_SIDE && idx > 0 && matches(listProp[idx - 1], selector, ancestry)) {
216219
return true;
217220
}
218-
if (side === 'right' && idx < listProp.length - 1 && matches(listProp[idx + 1], selector, ancestry)) {
221+
if (side === RIGHT_SIDE && idx < listProp.length - 1 && matches(listProp[idx + 1], selector, ancestry)) {
219222
return true;
220223
}
221224
}

0 commit comments

Comments
 (0)