@@ -29,32 +29,30 @@ DeepIterator.prototype.next = function () {
2929 // eslint-disable-next-line default-case
3030 switch ( this . _direction ) {
3131 case DOWNWARD :
32- this . _tree . _middle = this . _tree . _middle . _force ( ) ;
33- if ( this . _tree . _middle instanceof Deep ) {
34- this . _treeStack . push ( this . _tree ) ;
35- this . _tree = this . _tree . _middle ;
36- this . _downwardStep ( ) ;
32+ // eslint-disable-next-line no-case-declarations
33+ const tree = this . _treeStack . pop ( ) . _force ( ) ;
34+ if ( tree instanceof Deep ) {
35+ this . _downwardStep ( tree ) ;
3736 ++ this . _currentLevel ;
38- this . _level = this . _stack . map ( ( ) => this . _currentLevel ) ;
37+ this . _treeStack . push ( tree , tree . _middle ) ;
3938 break ;
4039 } else {
40+ assert ( this . _treeStack . length >= 1 ) ;
4141 this . _direction = UPWARD ;
42- if ( this . _tree . _middle instanceof Single ) {
43- this . _stack = [ this . _tree . _middle . a ] ;
44- this . _level = [ this . _currentLevel + 1 ] ;
42+ if ( tree instanceof Single ) {
43+ this . _stack . push ( tree . a ) ;
44+ this . _level . push ( this . _currentLevel ) ;
4545 break ;
4646 }
4747
48- assert ( this . _tree . _middle instanceof Empty ) ;
48+ assert ( tree instanceof Empty ) ;
4949 }
5050
5151 case UPWARD :
52- if ( this . _currentLevel === - 1 ) return { done : true } ;
53- assert ( this . _tree instanceof Deep ) ;
52+ if ( this . _currentLevel === 0 ) return { done : true } ;
53+ assert ( this . _treeStack [ this . _treeStack . length - 1 ] instanceof Deep ) ;
54+ -- this . _currentLevel ;
5455 this . _upwardStep ( ) ;
55- this . _level = this . _stack . map ( ( ) => this . _currentLevel ) ;
56-
57- this . _tree = -- this . _currentLevel === - 1 ? null : this . _treeStack . pop ( ) ;
5856 }
5957 /* eslint-enable no-fallthrough */
6058 }
0 commit comments