1
- 'use strict'
2
-
3
- module . exports = match
4
-
5
- var zwitch = require ( 'zwitch' )
1
+ import { zwitch } from 'zwitch'
6
2
7
3
var own = { } . hasOwnProperty
8
4
@@ -17,36 +13,38 @@ var handle = zwitch('nestingOperator', {
17
13
}
18
14
} )
19
15
20
- function match ( query , node , index , parent , state ) {
16
+ export function nest ( query , node , index , parent , state ) {
21
17
return handle ( query , node , index , parent , state )
22
18
}
23
19
24
- /* istanbul ignore next - Shouldn’t be invoked, parser gives correct data. */
20
+ // Shouldn’t be invoked, parser gives correct data.
21
+ /* c8 ignore next 3 */
25
22
function unknownNesting ( query ) {
26
23
throw new Error ( 'Unexpected nesting `' + query . nestingOperator + '`' )
27
24
}
28
25
29
26
function topScan ( query , node , index , parent , state ) {
30
- /* istanbul ignore if - Shouldn’t happen. */
27
+ // Shouldn’t happen.
28
+ /* c8 ignore next 3 */
31
29
if ( parent ) {
32
30
throw new Error ( 'topScan is supposed to be called from the root node' )
33
31
}
34
32
35
- state . iterator . apply ( null , arguments )
33
+ state . iterator ( ... arguments )
36
34
37
- if ( ! state . shallow ) descendant . apply ( this , arguments )
35
+ if ( ! state . shallow ) descendant . call ( this , ... arguments )
38
36
}
39
37
40
38
function descendant ( query , node , index , parent , state ) {
41
39
var previous = state . iterator
42
40
43
41
state . iterator = iterator
44
42
45
- child . apply ( this , arguments )
43
+ child . call ( this , ... arguments )
46
44
47
45
function iterator ( _ , node , index , parent , state ) {
48
46
state . iterator = previous
49
- previous . apply ( this , arguments )
47
+ previous . call ( this , ... arguments )
50
48
state . iterator = iterator
51
49
52
50
if ( state . one && state . found ) return
@@ -56,13 +54,14 @@ function descendant(query, node, index, parent, state) {
56
54
}
57
55
58
56
function child ( query , node , index , parent , state ) {
59
- if ( ! node . children || ! node . children . length ) return
57
+ if ( ! node . children || node . children . length === 0 ) return
60
58
61
59
walkIterator ( query , node , state ) . each ( ) . done ( )
62
60
}
63
61
64
62
function adjacentSibling ( query , node , index , parent , state ) {
65
- /* istanbul ignore if - Shouldn’t happen. */
63
+ // Shouldn’t happen.
64
+ /* c8 ignore next */
66
65
if ( ! parent ) return
67
66
68
67
walkIterator ( query , parent , state )
@@ -73,7 +72,8 @@ function adjacentSibling(query, node, index, parent, state) {
73
72
}
74
73
75
74
function generalSibling ( query , node , index , parent , state ) {
76
- /* istanbul ignore if - Shouldn’t happen. */
75
+ // Shouldn’t happen.
76
+ /* c8 ignore next */
77
77
if ( ! parent ) return
78
78
79
79
walkIterator ( query , parent , state )
@@ -91,7 +91,7 @@ function walkIterator(query, parent, state) {
91
91
return {
92
92
prefillTypeIndex : rangeDefaults ( prefillTypeIndex ) ,
93
93
each : rangeDefaults ( each ) ,
94
- done : done
94
+ done
95
95
}
96
96
97
97
function done ( ) {
@@ -149,8 +149,9 @@ function walkIterator(query, parent, state) {
149
149
return rangeDefault
150
150
151
151
function rangeDefault ( start , end ) {
152
- if ( start == null || start < 0 ) start = 0
153
- if ( end == null || end > siblings . length ) end = siblings . length
152
+ if ( start === null || start === undefined || start < 0 ) start = 0
153
+ if ( end === null || end === undefined || end > siblings . length )
154
+ end = siblings . length
154
155
return iterator . call ( this , start , end )
155
156
}
156
157
}
0 commit comments