@@ -96,28 +96,28 @@ describe('Visitor', () => {
96
96
97
97
it ( 'validates ancestors argument' , ( ) => {
98
98
const ast = parse ( '{ a }' , { noLocation : true } ) ;
99
- const nodesInPath = [ ] ;
99
+ const visitedNodes = [ ] ;
100
100
101
101
visit ( ast , {
102
102
enter ( node , key , parent , path , ancestors ) {
103
103
const inArray = typeof key === 'number' ;
104
- const expectedAncestors = nodesInPath . slice ( 0 , path . length - 1 ) ;
105
- expect ( ancestors ) . to . deep . equal ( expectedAncestors ) ;
106
-
107
104
if ( inArray ) {
108
- nodesInPath . push ( parent ) ;
105
+ visitedNodes . push ( parent ) ;
109
106
}
110
- nodesInPath . push ( node ) ;
107
+ visitedNodes . push ( node ) ;
108
+
109
+ const expectedAncestors = visitedNodes . slice ( 0 , - 2 ) ;
110
+ expect ( ancestors ) . to . deep . equal ( expectedAncestors ) ;
111
111
} ,
112
112
leave ( node , key , parent , path , ancestors ) {
113
- const inArray = typeof key === 'number' ;
114
- const expectedAncestors = nodesInPath . slice ( 0 , path . length - 1 ) ;
113
+ const expectedAncestors = visitedNodes . slice ( 0 , - 2 ) ;
115
114
expect ( ancestors ) . to . deep . equal ( expectedAncestors ) ;
116
115
116
+ const inArray = typeof key === 'number' ;
117
117
if ( inArray ) {
118
- nodesInPath . pop ( ) ;
118
+ visitedNodes . pop ( ) ;
119
119
}
120
- nodesInPath . pop ( ) ;
120
+ visitedNodes . pop ( ) ;
121
121
} ,
122
122
} ) ;
123
123
} ) ;
0 commit comments