(child)
| 38694 | } |
| 38695 | } |
| 38696 | function visit(child) { |
| 38697 | if (ts.nodeIsMissing(child)) { |
| 38698 | // Missing nodes are effectively invisible to us. We never even consider them |
| 38699 | // When trying to find the nearest node before us. |
| 38700 | return; |
| 38701 | } |
| 38702 | // If the child intersects this position, then this node is currently the nearest |
| 38703 | // node that starts before the position. |
| 38704 | if (child.pos <= position) { |
| 38705 | if (child.pos >= bestResult.pos) { |
| 38706 | // This node starts before the position, and is closer to the position than |
| 38707 | // the previous best node we found. It is now the new best node. |
| 38708 | bestResult = child; |
| 38709 | } |
| 38710 | // Now, the node may overlap the position, or it may end entirely before the |
| 38711 | // position. If it overlaps with the position, then either it, or one of its |
| 38712 | // children must be the nearest node before the position. So we can just |
| 38713 | // recurse into this child to see if we can find something better. |
| 38714 | if (position < child.end) { |
| 38715 | // The nearest node is either this child, or one of the children inside |
| 38716 | // of it. We've already marked this child as the best so far. Recurse |
| 38717 | // in case one of the children is better. |
| 38718 | forEachChild(child, visit); |
| 38719 | // Once we look at the children of this node, then there's no need to |
| 38720 | // continue any further. |
| 38721 | return true; |
| 38722 | } |
| 38723 | else { |
| 38724 | ts.Debug.assert(child.end <= position); |
| 38725 | // The child ends entirely before this position. Say you have the following |
| 38726 | // (where $ is the position) |
| 38727 | // |
| 38728 | // <complex expr 1> ? <complex expr 2> $ : <...> <...> |
| 38729 | // |
| 38730 | // We would want to find the nearest preceding node in "complex expr 2". |
| 38731 | // To support that, we keep track of this node, and once we're done searching |
| 38732 | // for a best node, we recurse down this node to see if we can find a good |
| 38733 | // result in it. |
| 38734 | // |
| 38735 | // This approach allows us to quickly skip over nodes that are entirely |
| 38736 | // before the position, while still allowing us to find any nodes in the |
| 38737 | // last one that might be what we want. |
| 38738 | lastNodeEntirelyBeforePosition = child; |
| 38739 | } |
| 38740 | } |
| 38741 | else { |
| 38742 | ts.Debug.assert(child.pos > position); |
| 38743 | // We're now at a node that is entirely past the position we're searching for. |
| 38744 | // This node (and all following nodes) could never contribute to the result, |
| 38745 | // so just skip them by returning 'true' here. |
| 38746 | return true; |
| 38747 | } |
| 38748 | } |
| 38749 | } |
| 38750 | function checkChangeRange(sourceFile, newText, textChangeRange, aggressiveChecks) { |
| 38751 | var oldText = sourceFile.text; |
no test coverage detected
searching dependent graphs…