@@ -33,7 +33,7 @@ const RIGHT_SIDE = 'RIGHT_SIDE';
33
33
* @returns {undefined|boolean|string|number|external:AST }
34
34
*/
35
35
function getPath ( obj , keys ) {
36
- for ( let i = 0 ; i < keys . length ; i ++ ) {
36
+ for ( let i = 0 ; i < keys . length ; ++ i ) {
37
37
if ( obj == null ) { return obj ; }
38
38
obj = obj [ keys [ i ] ] ;
39
39
}
@@ -51,14 +51,14 @@ function getPath(obj, keys) {
51
51
*/
52
52
function inPath ( node , ancestor , path , fromPathIndex ) {
53
53
let current = ancestor ;
54
- for ( let i = fromPathIndex ; i < path . length ; i ++ ) {
54
+ for ( let i = fromPathIndex ; i < path . length ; ++ i ) {
55
55
if ( current == null ) {
56
56
return false ;
57
57
}
58
58
const field = current [ path [ i ] ] ;
59
59
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 ) ) {
62
62
return true ;
63
63
}
64
64
}
@@ -89,7 +89,7 @@ function createMatcher(selector) {
89
89
case 'matches' : {
90
90
const { selectors } = selector ;
91
91
return ( node , ancestry , options ) => {
92
- for ( let i = 0 ; i < selectors . length ; i ++ ) {
92
+ for ( let i = 0 ; i < selectors . length ; ++ i ) {
93
93
if ( matches ( node , selectors [ i ] , ancestry , options ) ) { return true ; }
94
94
}
95
95
return false ;
@@ -99,7 +99,7 @@ function createMatcher(selector) {
99
99
case 'compound' : {
100
100
const { selectors } = selector ;
101
101
return ( node , ancestry , options ) => {
102
- for ( let i = 0 ; i < selectors . length ; i ++ ) {
102
+ for ( let i = 0 ; i < selectors . length ; ++ i ) {
103
103
if ( ! matches ( node , selectors [ i ] , ancestry , options ) ) { return false ; }
104
104
}
105
105
return true ;
@@ -109,7 +109,7 @@ function createMatcher(selector) {
109
109
case 'not' : {
110
110
const { selectors } = selector ;
111
111
return ( node , ancestry , options ) => {
112
- for ( let i = 0 ; i < selectors . length ; i ++ ) {
112
+ for ( let i = 0 ; i < selectors . length ; ++ i ) {
113
113
if ( matches ( node , selectors [ i ] , ancestry , options ) ) { return false ; }
114
114
}
115
115
return true ;
@@ -126,7 +126,7 @@ function createMatcher(selector) {
126
126
enter ( node , parent ) {
127
127
if ( parent != null ) { a . unshift ( parent ) ; }
128
128
129
- for ( let i = 0 ; i < selectors . length ; i ++ ) {
129
+ for ( let i = 0 ; i < selectors . length ; ++ i ) {
130
130
if ( matches ( node , selectors [ i ] , a , options ) ) {
131
131
result = true ;
132
132
this . break ( ) ;
@@ -175,29 +175,22 @@ function createMatcher(selector) {
175
175
} ;
176
176
case 'literal' : {
177
177
const literal = `${ selector . value . value } ` ;
178
- return ( node ) => {
179
- return literal === `${ getPath ( node , path ) } ` ;
180
- } ;
178
+ return ( node ) => literal === `${ getPath ( node , path ) } ` ;
181
179
}
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 ) ;
185
182
}
186
183
throw new Error ( `Unknown selector value type: ${ selector . value . type } ` ) ;
187
184
case '!=' :
188
185
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 ) ) ;
192
188
case 'literal' : {
193
189
const literal = `${ selector . value . value } ` ;
194
- return ( node ) => {
195
- return literal !== `${ getPath ( node , path ) } ` ;
196
- } ;
190
+ return ( node ) => literal !== `${ getPath ( node , path ) } ` ;
197
191
}
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 ) ;
201
194
}
202
195
throw new Error ( `Unknown selector value type: ${ selector . value . type } ` ) ;
203
196
case '<=' : return ( node ) => getPath ( node , path ) <= selector . value . value ;
@@ -354,7 +347,7 @@ function sibling(node, selector, ancestry, side, options) {
354
347
const [ parent ] = ancestry ;
355
348
if ( ! parent ) { return false ; }
356
349
const keys = getVisitorKeys ( parent , options ) ;
357
- for ( let i = 0 ; i < keys . length ; i ++ ) {
350
+ for ( let i = 0 ; i < keys . length ; ++ i ) {
358
351
const listProp = parent [ keys [ i ] ] ;
359
352
if ( Array . isArray ( listProp ) ) {
360
353
const startIndex = listProp . indexOf ( node ) ;
@@ -391,7 +384,7 @@ function adjacent(node, selector, ancestry, side, options) {
391
384
const [ parent ] = ancestry ;
392
385
if ( ! parent ) { return false ; }
393
386
const keys = getVisitorKeys ( parent , options ) ;
394
- for ( let i = 0 ; i < keys . length ; i ++ ) {
387
+ for ( let i = 0 ; i < keys . length ; ++ i ) {
395
388
const listProp = parent [ keys [ i ] ] ;
396
389
if ( Array . isArray ( listProp ) ) {
397
390
const idx = listProp . indexOf ( node ) ;
@@ -422,10 +415,10 @@ function nthChild(node, ancestry, nth, fromEnd, options) {
422
415
const [ parent ] = ancestry ;
423
416
if ( ! parent ) { return false ; }
424
417
const keys = getVisitorKeys ( parent , options ) ;
425
- for ( let i = 0 ; i < keys . length ; i ++ ) {
418
+ for ( let i = 0 ; i < keys . length ; ++ i ) {
426
419
const listProp = parent [ keys [ i ] ] ;
427
420
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 ) {
429
422
return true ;
430
423
}
431
424
}
@@ -445,7 +438,7 @@ function subjects(selector, ancestor) {
445
438
if ( ancestor == null ) { ancestor = selector ; }
446
439
const results = selector . subject ? [ ancestor ] : [ ] ;
447
440
const keys = Object . keys ( selector ) ;
448
- for ( let i = 0 ; i < keys . length ; i ++ ) {
441
+ for ( let i = 0 ; i < keys . length ; ++ i ) {
449
442
const p = keys [ i ] ;
450
443
const sel = selector [ p ] ;
451
444
results . push ( ...subjects ( sel , p === 'left' ? sel : ancestor ) ) ;
0 commit comments