@@ -371,8 +371,8 @@ module ts {
371
371
return false ;
372
372
}
373
373
374
- function moveElementEntirelyPastChangeRange ( element : IncrementalElement , delta : number , oldText : string , newText : string , aggressiveChecks : boolean ) {
375
- if ( element . length ) {
374
+ function moveElementEntirelyPastChangeRange ( element : IncrementalElement , isArray : boolean , delta : number , oldText : string , newText : string , aggressiveChecks : boolean ) {
375
+ if ( isArray ) {
376
376
visitArray ( < IncrementalNodeArray > element ) ;
377
377
}
378
378
else {
@@ -400,6 +400,7 @@ module ts {
400
400
}
401
401
402
402
function visitArray ( array : IncrementalNodeArray ) {
403
+ array . _children = undefined ;
403
404
array . pos += delta ;
404
405
array . end += delta ;
405
406
@@ -412,6 +413,7 @@ module ts {
412
413
function adjustIntersectingElement ( element : IncrementalElement , changeStart : number , changeRangeOldEnd : number , changeRangeNewEnd : number , delta : number ) {
413
414
Debug . assert ( element . end >= changeStart , "Adjusting an element that was entirely before the change range" ) ;
414
415
Debug . assert ( element . pos <= changeRangeOldEnd , "Adjusting an element that was entirely after the change range" ) ;
416
+ Debug . assert ( element . pos <= element . end ) ;
415
417
416
418
// We have an element that intersects the change range in some way. It may have its
417
419
// start, or its end (or both) in the changed range. We want to adjust any part
@@ -508,10 +510,11 @@ module ts {
508
510
return ;
509
511
510
512
function visitNode ( child : IncrementalNode ) {
513
+ Debug . assert ( child . pos <= child . end ) ;
511
514
if ( child . pos > changeRangeOldEnd ) {
512
515
// Node is entirely past the change range. We need to move both its pos and
513
516
// end, forward or backward appropriately.
514
- moveElementEntirelyPastChangeRange ( child , delta , oldText , newText , aggressiveChecks ) ;
517
+ moveElementEntirelyPastChangeRange ( child , /*isArray:*/ false , delta , oldText , newText , aggressiveChecks ) ;
515
518
return ;
516
519
}
517
520
@@ -521,6 +524,7 @@ module ts {
521
524
var fullEnd = child . end ;
522
525
if ( fullEnd >= changeStart ) {
523
526
child . intersectsChange = true ;
527
+ child . _children = undefined ;
524
528
525
529
// Adjust the pos or end (or both) of the intersecting element accordingly.
526
530
adjustIntersectingElement ( child , changeStart , changeRangeOldEnd , changeRangeNewEnd , delta ) ;
@@ -531,32 +535,36 @@ module ts {
531
535
}
532
536
533
537
// Otherwise, the node is entirely before the change range. No need to do anything with it.
538
+ Debug . assert ( fullEnd < changeStart ) ;
534
539
}
535
540
536
541
function visitArray ( array : IncrementalNodeArray ) {
542
+ Debug . assert ( array . pos <= array . end ) ;
537
543
if ( array . pos > changeRangeOldEnd ) {
538
544
// Array is entirely after the change range. We need to move it, and move any of
539
545
// its children.
540
- moveElementEntirelyPastChangeRange ( array , delta , oldText , newText , aggressiveChecks ) ;
546
+ moveElementEntirelyPastChangeRange ( array , /*isArray:*/ true , delta , oldText , newText , aggressiveChecks ) ;
547
+ return ;
541
548
}
542
- else {
543
- // Check if the element intersects the change range. If it does, then it is not
544
- // reusable. Also, we'll need to recurse to see what constituent portions we may
545
- // be able to use.
546
- var fullEnd = array . end ;
547
- if ( fullEnd >= changeStart ) {
548
- array . intersectsChange = true ;
549
-
550
- // Adjust the pos or end (or both) of the intersecting array accordingly.
551
- adjustIntersectingElement ( array , changeStart , changeRangeOldEnd , changeRangeNewEnd , delta ) ;
552
- for ( var i = 0 , n = array . length ; i < n ; i ++ ) {
553
- visitNode ( array [ i ] ) ;
554
- }
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 ] ) ;
555
562
}
556
- // else {
557
- // Otherwise, the array is entirely before the change range. No need to do anything with it.
558
- // }
563
+ return ;
559
564
}
565
+
566
+ // Otherwise, the array is entirely before the change range. No need to do anything with it.
567
+ Debug . assert ( fullEnd < changeStart ) ;
560
568
}
561
569
}
562
570
@@ -842,7 +850,7 @@ module ts {
842
850
// Much of the time the parser will need the very next node in the array that
843
851
// we just returned a node from.So just simply check for that case and move
844
852
// forward in the array instead of searching for the node again.
845
- if ( current && current . end === position && currentArrayIndex < currentArray . length ) {
853
+ if ( current && current . end === position && currentArrayIndex < ( currentArray . length - 1 ) ) {
846
854
currentArrayIndex ++ ;
847
855
current = currentArray [ currentArrayIndex ] ;
848
856
}
@@ -878,6 +886,7 @@ module ts {
878
886
879
887
// Recurse into the source file to find the highest node at this position.
880
888
forEachChild ( sourceFile , visitNode , visitArray ) ;
889
+ return ;
881
890
882
891
function visitNode ( node : Node ) {
883
892
if ( position >= node . pos && position < node . end ) {
@@ -1649,8 +1658,8 @@ module ts {
1649
1658
return result ;
1650
1659
}
1651
1660
1652
- function parseListElement < T extends Node > ( kind : ParsingContext , parseElement : ( ) => T ) : T {
1653
- var node = currentNode ( kind ) ;
1661
+ function parseListElement < T extends Node > ( parsingContext : ParsingContext , parseElement : ( ) => T ) : T {
1662
+ var node = currentNode ( parsingContext ) ;
1654
1663
if ( node ) {
1655
1664
return < T > consumeNode ( node ) ;
1656
1665
}
@@ -1807,29 +1816,10 @@ module ts {
1807
1816
case SyntaxKind . InterfaceDeclaration :
1808
1817
case SyntaxKind . ModuleDeclaration :
1809
1818
case SyntaxKind . EnumDeclaration :
1810
-
1811
- // Keep in sync with isStatement:
1812
- case SyntaxKind . FunctionDeclaration :
1813
- case SyntaxKind . VariableStatement :
1814
- case SyntaxKind . Block :
1815
- case SyntaxKind . IfStatement :
1816
- case SyntaxKind . ExpressionStatement :
1817
- case SyntaxKind . ThrowStatement :
1818
- case SyntaxKind . ReturnStatement :
1819
- case SyntaxKind . SwitchStatement :
1820
- case SyntaxKind . BreakStatement :
1821
- case SyntaxKind . ContinueStatement :
1822
- case SyntaxKind . ForInStatement :
1823
- case SyntaxKind . ForStatement :
1824
- case SyntaxKind . WhileStatement :
1825
- case SyntaxKind . WithStatement :
1826
- case SyntaxKind . EmptyStatement :
1827
- case SyntaxKind . TryStatement :
1828
- case SyntaxKind . LabeledStatement :
1829
- case SyntaxKind . DoStatement :
1830
- case SyntaxKind . DebuggerStatement :
1831
1819
return true ;
1832
1820
}
1821
+
1822
+ return isReusableStatement ( node ) ;
1833
1823
}
1834
1824
1835
1825
return false ;
@@ -1935,9 +1925,13 @@ module ts {
1935
1925
}
1936
1926
1937
1927
function isReusableParameter ( node : Node ) {
1938
- // TODO: this most likely needs the same initializer check that
1939
- // isReusableVariableDeclaration has.
1940
- return node . kind === SyntaxKind . Parameter ;
1928
+ if ( node . kind !== SyntaxKind . Parameter ) {
1929
+ return false ;
1930
+ }
1931
+
1932
+ // See the comment in isReusableVariableDeclaration for why we do this.
1933
+ var parameter = < ParameterDeclaration > node ;
1934
+ return parameter . initializer === undefined ;
1941
1935
}
1942
1936
1943
1937
// Returns true if we should abort parsing.
0 commit comments