@@ -5,57 +5,59 @@ var TypeIndex = require('./type-index');
5
5
var walkers = exports ;
6
6
7
7
8
- walkers . topScan = function ( node , nodeIndex , parent , iterator , opts ) {
8
+ walkers . topScan = function ( node , nodeIndex , parent , opts ) {
9
9
if ( parent ) {
10
10
// We would like to avoid spinning an extra loop through the starting
11
11
// node's siblings just to count its typeIndex.
12
12
throw Error ( 'topScan is supposed to be called from the root node' ) ;
13
13
}
14
14
15
- iterator ( node , nodeIndex , parent ) ;
15
+ if ( ! opts . typeIndex ) {
16
+ opts . iterator ( node , nodeIndex , parent ) ;
17
+ }
16
18
walkers . descendant . apply ( this , arguments ) ;
17
19
} ;
18
20
19
21
20
- walkers . descendant = function ( node , nodeIndex , parent , iterator , opts ) {
22
+ walkers . descendant = function ( node , nodeIndex , parent , opts ) {
21
23
if ( ! node . children || ! node . children . length ) {
22
24
return ;
23
25
}
24
26
25
- if ( ( opts = opts || { } ) . typeIndex ) {
27
+ if ( opts . typeIndex ) {
26
28
var typeIndex = TypeIndex ( ) ;
27
29
}
28
30
29
31
node . children . forEach ( function ( child , childIndex ) {
30
- iterator ( child , childIndex , node ,
31
- opts . typeIndex ? { typeIndex : typeIndex ( child ) } : undefined ) ;
32
- walkers . descendant ( child , childIndex , node , iterator , opts ) ;
32
+ opts . iterator ( child , childIndex , node ,
33
+ opts . typeIndex ? { typeIndex : typeIndex ( child ) } : undefined ) ;
34
+ walkers . descendant ( child , childIndex , node , opts ) ;
33
35
} ) ;
34
36
} ;
35
37
36
38
37
- walkers . child = function ( node , nodeIndex , parent , iterator , opts ) {
39
+ walkers . child = function ( node , nodeIndex , parent , opts ) {
38
40
if ( ! node . children || ! node . children . length ) {
39
41
return ;
40
42
}
41
43
42
- if ( ( opts = opts || { } ) . typeIndex ) {
44
+ if ( opts . typeIndex ) {
43
45
var typeIndex = TypeIndex ( ) ;
44
46
}
45
47
46
48
node . children . forEach ( function ( child , childIndex ) {
47
- iterator ( child , childIndex , node ,
48
- opts . typeIndex ? { typeIndex : typeIndex ( child ) } : undefined ) ;
49
+ opts . iterator ( child , childIndex , node ,
50
+ opts . typeIndex ? { typeIndex : typeIndex ( child ) } : undefined ) ;
49
51
} ) ;
50
52
} ;
51
53
52
54
53
- walkers . adjacentSibling = function ( node , nodeIndex , parent , iterator , opts ) {
55
+ walkers . adjacentSibling = function ( node , nodeIndex , parent , opts ) {
54
56
if ( ! parent ) {
55
57
return ;
56
58
}
57
59
58
- if ( ( opts = opts || { } ) . typeIndex ) {
60
+ if ( opts . typeIndex ) {
59
61
var typeIndex = TypeIndex ( ) ;
60
62
61
63
// Prefill type indexes with preceding nodes.
@@ -66,18 +68,18 @@ walkers.adjacentSibling = function (node, nodeIndex, parent, iterator, opts) {
66
68
67
69
if ( ++ nodeIndex < parent . children . length ) {
68
70
node = parent . children [ nodeIndex ] ;
69
- iterator ( node , nodeIndex , parent ,
70
- opts . typeIndex ? { typeIndex : typeIndex ( node ) } : undefined ) ;
71
+ opts . iterator ( node , nodeIndex , parent ,
72
+ opts . typeIndex ? { typeIndex : typeIndex ( node ) } : undefined ) ;
71
73
}
72
74
} ;
73
75
74
76
75
- walkers . generalSibling = function ( node , nodeIndex , parent , iterator , opts ) {
77
+ walkers . generalSibling = function ( node , nodeIndex , parent , opts ) {
76
78
if ( ! parent ) {
77
79
return ;
78
80
}
79
81
80
- if ( ( opts = opts || { } ) . typeIndex ) {
82
+ if ( opts . typeIndex ) {
81
83
var typeIndex = TypeIndex ( ) ;
82
84
83
85
// Prefill type indexes with preceding nodes.
@@ -88,7 +90,7 @@ walkers.generalSibling = function (node, nodeIndex, parent, iterator, opts) {
88
90
89
91
while ( ++ nodeIndex < parent . children . length ) {
90
92
node = parent . children [ nodeIndex ] ;
91
- iterator ( node , nodeIndex , parent ,
92
- opts . typeIndex ? { typeIndex : typeIndex ( node ) } : undefined ) ;
93
+ opts . iterator ( node , nodeIndex , parent ,
94
+ opts . typeIndex ? { typeIndex : typeIndex ( node ) } : undefined ) ;
93
95
}
94
96
} ;
0 commit comments