@@ -736,6 +736,16 @@ module ts {
736
736
return parseSourceFile ( sourceFile . fileName , newText , sourceFile . languageVersion , /*syntaxCursor*/ undefined , /*setNodeParents*/ true )
737
737
}
738
738
739
+ // Make sure we're not trying to incrementally update a source file more than once. Once
740
+ // we do an update the original source file is considered unusbale from that point onwards.
741
+ //
742
+ // This is because we do incremental parsing in-place. i.e. we take nodes from the old
743
+ // tree and give them new positions and parents. From that point on, trusting the old
744
+ // tree at all is not possible as far too much of it may violate invariants.
745
+ var incrementalSourceFile = < IncrementalNode > < Node > sourceFile ;
746
+ Debug . assert ( ! incrementalSourceFile . hasBeenIncrementallyParsed ) ;
747
+ incrementalSourceFile . hasBeenIncrementallyParsed = true ;
748
+
739
749
var oldText = sourceFile . text ;
740
750
var syntaxCursor = createSyntaxCursor ( sourceFile ) ;
741
751
@@ -774,7 +784,7 @@ module ts {
774
784
//
775
785
// Also, mark any syntax elements that intersect the changed span. We know, up front,
776
786
// that we cannot reuse these elements.
777
- updateTokenPositionsAndMarkElements ( < IncrementalNode > < Node > sourceFile ,
787
+ updateTokenPositionsAndMarkElements ( incrementalSourceFile ,
778
788
changeRange . span . start , textSpanEnd ( changeRange . span ) , textSpanEnd ( textChangeRangeNewSpan ( changeRange ) ) , delta , oldText , newText , aggressiveChecks ) ;
779
789
780
790
// Now that we've set up our internal incremental state just proceed and parse the
@@ -815,6 +825,7 @@ module ts {
815
825
}
816
826
817
827
interface IncrementalNode extends Node , IncrementalElement {
828
+ hasBeenIncrementallyParsed : boolean
818
829
}
819
830
820
831
interface IncrementalNodeArray extends NodeArray < IncrementalNode > , IncrementalElement {
0 commit comments