Skip to content

Commit e417f30

Browse files
Add additional asserts, and make code more unified.
1 parent d37fdfe commit e417f30

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/compiler/parser.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ module ts {
400400
}
401401

402402
function visitArray(array: IncrementalNodeArray) {
403+
array._children = undefined;
403404
array.pos += delta;
404405
array.end += delta;
405406

@@ -412,6 +413,7 @@ module ts {
412413
function adjustIntersectingElement(element: IncrementalElement, changeStart: number, changeRangeOldEnd: number, changeRangeNewEnd: number, delta: number) {
413414
Debug.assert(element.end >= changeStart, "Adjusting an element that was entirely before the change range");
414415
Debug.assert(element.pos <= changeRangeOldEnd, "Adjusting an element that was entirely after the change range");
416+
Debug.assert(element.pos <= element.end);
415417

416418
// We have an element that intersects the change range in some way. It may have its
417419
// start, or its end (or both) in the changed range. We want to adjust any part
@@ -522,6 +524,7 @@ module ts {
522524
var fullEnd = child.end;
523525
if (fullEnd >= changeStart) {
524526
child.intersectsChange = true;
527+
child._children = undefined;
525528

526529
// Adjust the pos or end (or both) of the intersecting element accordingly.
527530
adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
@@ -541,25 +544,27 @@ module ts {
541544
// Array is entirely after the change range. We need to move it, and move any of
542545
// its children.
543546
moveElementEntirelyPastChangeRange(array, /*isArray:*/ true, delta, oldText, newText, aggressiveChecks);
547+
return;
544548
}
545-
else {
546-
// Check if the element intersects the change range. If it does, then it is not
547-
// reusable. Also, we'll need to recurse to see what constituent portions we may
548-
// be able to use.
549-
var fullEnd = array.end;
550-
if (fullEnd >= changeStart) {
551-
array.intersectsChange = true;
552-
553-
// Adjust the pos or end (or both) of the intersecting array accordingly.
554-
adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
555-
for (var i = 0, n = array.length; i < n; i++) {
556-
visitNode(array[i]);
557-
}
549+
550+
// Check if the element intersects the change range. If it does, then it is not
551+
// reusable. Also, we'll need to recurse to see what constituent portions we may
552+
// be able to use.
553+
var fullEnd = array.end;
554+
if (fullEnd >= changeStart) {
555+
array.intersectsChange = true;
556+
array._children = undefined;
557+
558+
// Adjust the pos or end (or both) of the intersecting array accordingly.
559+
adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
560+
for (var i = 0, n = array.length; i < n; i++) {
561+
visitNode(array[i]);
558562
}
559-
// else {
560-
// Otherwise, the array is entirely before the change range. No need to do anything with it.
561-
// }
563+
return;
562564
}
565+
566+
// Otherwise, the array is entirely before the change range. No need to do anything with it.
567+
Debug.assert(fullEnd < changeStart);
563568
}
564569
}
565570

0 commit comments

Comments
 (0)