Skip to content

Commit 5394396

Browse files
jviidemichaelficarra
authored andcommitted
Fix code style issues
1 parent 3a1eedb commit 5394396

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

esquery.js

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const RIGHT_SIDE = 'RIGHT_SIDE';
3333
* @returns {undefined|boolean|string|number|external:AST}
3434
*/
3535
function getPath(obj, keys) {
36-
for (let i = 0; i < keys.length; i++) {
36+
for (let i = 0; i < keys.length; ++i) {
3737
if (obj == null) { return obj; }
3838
obj = obj[keys[i]];
3939
}
@@ -51,14 +51,14 @@ function getPath(obj, keys) {
5151
*/
5252
function inPath(node, ancestor, path, fromPathIndex) {
5353
let current = ancestor;
54-
for (let i = fromPathIndex; i < path.length; i++) {
54+
for (let i = fromPathIndex; i < path.length; ++i) {
5555
if (current == null) {
5656
return false;
5757
}
5858
const field = current[path[i]];
5959
if (Array.isArray(field)) {
60-
for (let j = 0; j < field.length; j++) {
61-
if (inPath(node, field[j], path, i + 1)) {
60+
for (let k = 0; k < field.length; k++) {
61+
if (inPath(node, field[k], path, i + 1)) {
6262
return true;
6363
}
6464
}
@@ -89,7 +89,7 @@ function createMatcher(selector) {
8989
case 'matches': {
9090
const { selectors } = selector;
9191
return (node, ancestry, options) => {
92-
for (let i = 0; i < selectors.length; i++) {
92+
for (let i = 0; i < selectors.length; ++i) {
9393
if (matches(node, selectors[i], ancestry, options)) { return true; }
9494
}
9595
return false;
@@ -99,7 +99,7 @@ function createMatcher(selector) {
9999
case 'compound': {
100100
const { selectors } = selector;
101101
return (node, ancestry, options) => {
102-
for (let i = 0; i < selectors.length; i++) {
102+
for (let i = 0; i < selectors.length; ++i) {
103103
if (!matches(node, selectors[i], ancestry, options)) { return false; }
104104
}
105105
return true;
@@ -109,7 +109,7 @@ function createMatcher(selector) {
109109
case 'not': {
110110
const { selectors } = selector;
111111
return (node, ancestry, options) => {
112-
for (let i = 0; i < selectors.length; i++) {
112+
for (let i = 0; i < selectors.length; ++i) {
113113
if (matches(node, selectors[i], ancestry, options)) { return false; }
114114
}
115115
return true;
@@ -126,7 +126,7 @@ function createMatcher(selector) {
126126
enter (node, parent) {
127127
if (parent != null) { a.unshift(parent); }
128128

129-
for (let i = 0; i < selectors.length; i++) {
129+
for (let i = 0; i < selectors.length; ++i) {
130130
if (matches(node, selectors[i], a, options)) {
131131
result = true;
132132
this.break();
@@ -175,29 +175,22 @@ function createMatcher(selector) {
175175
};
176176
case 'literal': {
177177
const literal = `${selector.value.value}`;
178-
return (node) => {
179-
return literal === `${getPath(node, path)}`;
180-
};
178+
return (node) => literal === `${getPath(node, path)}`;
181179
}
182-
case 'type': return (node) => {
183-
return selector.value.value === typeof getPath(node, path);
184-
};
180+
case 'type':
181+
return (node) => selector.value.value === typeof getPath(node, path);
185182
}
186183
throw new Error(`Unknown selector value type: ${selector.value.type}`);
187184
case '!=':
188185
switch (selector.value.type) {
189-
case 'regexp': return (node) => {
190-
return !selector.value.value.test(getPath(node, path));
191-
};
186+
case 'regexp':
187+
return (node) => !selector.value.value.test(getPath(node, path));
192188
case 'literal': {
193189
const literal = `${selector.value.value}`;
194-
return (node) => {
195-
return literal !== `${getPath(node, path)}`;
196-
};
190+
return (node) => literal !== `${getPath(node, path)}`;
197191
}
198-
case 'type': return (node) => {
199-
return selector.value.value !== typeof getPath(node, path);
200-
};
192+
case 'type':
193+
return (node) => selector.value.value !== typeof getPath(node, path);
201194
}
202195
throw new Error(`Unknown selector value type: ${selector.value.type}`);
203196
case '<=': return (node) => getPath(node, path) <= selector.value.value;
@@ -354,7 +347,7 @@ function sibling(node, selector, ancestry, side, options) {
354347
const [parent] = ancestry;
355348
if (!parent) { return false; }
356349
const keys = getVisitorKeys(parent, options);
357-
for (let i = 0; i < keys.length; i++) {
350+
for (let i = 0; i < keys.length; ++i) {
358351
const listProp = parent[keys[i]];
359352
if (Array.isArray(listProp)) {
360353
const startIndex = listProp.indexOf(node);
@@ -391,7 +384,7 @@ function adjacent(node, selector, ancestry, side, options) {
391384
const [parent] = ancestry;
392385
if (!parent) { return false; }
393386
const keys = getVisitorKeys(parent, options);
394-
for (let i = 0; i < keys.length; i++) {
387+
for (let i = 0; i < keys.length; ++i) {
395388
const listProp = parent[keys[i]];
396389
if (Array.isArray(listProp)) {
397390
const idx = listProp.indexOf(node);
@@ -422,10 +415,10 @@ function nthChild(node, ancestry, nth, fromEnd, options) {
422415
const [parent] = ancestry;
423416
if (!parent) { return false; }
424417
const keys = getVisitorKeys(parent, options);
425-
for (let i = 0; i < keys.length; i++) {
418+
for (let i = 0; i < keys.length; ++i) {
426419
const listProp = parent[keys[i]];
427420
if (Array.isArray(listProp)){
428-
if (nth <= listProp.length && listProp[fromEnd ? listProp.length-nth : nth-1] === node) {
421+
if (nth <= listProp.length && listProp[fromEnd ? listProp.length - nth : nth - 1] === node) {
429422
return true;
430423
}
431424
}
@@ -445,7 +438,7 @@ function subjects(selector, ancestor) {
445438
if (ancestor == null) { ancestor = selector; }
446439
const results = selector.subject ? [ancestor] : [];
447440
const keys = Object.keys(selector);
448-
for (let i = 0; i < keys.length; i++) {
441+
for (let i = 0; i < keys.length; ++i) {
449442
const p = keys[i];
450443
const sel = selector[p];
451444
results.push(...subjects(sel, p === 'left' ? sel : ancestor));

0 commit comments

Comments
 (0)