| 638 | |
| 639 | // TODO: docs |
| 640 | _recurse(filename, ast) { |
| 641 | const self = this; |
| 642 | const state = { |
| 643 | filename: filename, |
| 644 | nodes: [], |
| 645 | scopes: [] |
| 646 | }; |
| 647 | |
| 648 | function logUnknownNodeType({type}) { |
| 649 | logger.debug('Found a node with unrecognized type %s. Ignoring the node and its ' + |
| 650 | 'descendants.', type); |
| 651 | } |
| 652 | |
| 653 | function cb(node, parent, cbState) { |
| 654 | let currentScope; |
| 655 | |
| 656 | const isScope = astnode.isScope(node); |
| 657 | |
| 658 | astnode.addNodeProperties(node); |
| 659 | node.parent = parent || null; |
| 660 | |
| 661 | currentScope = getCurrentScope(cbState.scopes); |
| 662 | if (currentScope) { |
| 663 | node.enclosingScope = currentScope; |
| 664 | } |
| 665 | |
| 666 | if (isScope) { |
| 667 | cbState.scopes.push(node); |
| 668 | } |
| 669 | cbState.nodes.push(node); |
| 670 | |
| 671 | if (!self._walkers[node.type]) { |
| 672 | logUnknownNodeType(node); |
| 673 | } else { |
| 674 | self._walkers[node.type](node, parent, cbState, cb); |
| 675 | } |
| 676 | |
| 677 | if (isScope) { |
| 678 | cbState.scopes.pop(); |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | cb(ast, null, state); |
| 683 | |
| 684 | return state; |
| 685 | } |
| 686 | |
| 687 | // TODO: docs |
| 688 | recurse(ast, visitor, filename) { |