@@ -736,6 +736,16 @@ module ts {
736736            return  parseSourceFile ( sourceFile . fileName ,  newText ,  sourceFile . languageVersion ,  /*syntaxCursor*/  undefined ,  /*setNodeParents*/  true ) 
737737        } 
738738
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+ 
739749        var  oldText  =  sourceFile . text ; 
740750        var  syntaxCursor  =  createSyntaxCursor ( sourceFile ) ; 
741751
@@ -774,7 +784,7 @@ module ts {
774784        // 
775785        // Also, mark any syntax elements that intersect the changed span.  We know, up front, 
776786        // that we cannot reuse these elements. 
777-         updateTokenPositionsAndMarkElements ( < IncrementalNode > < Node > sourceFile , 
787+         updateTokenPositionsAndMarkElements ( incrementalSourceFile , 
778788            changeRange . span . start ,  textSpanEnd ( changeRange . span ) ,  textSpanEnd ( textChangeRangeNewSpan ( changeRange ) ) ,  delta ,  oldText ,  newText ,  aggressiveChecks ) ; 
779789
780790        // Now that we've set up our internal incremental state just proceed and parse the 
@@ -815,6 +825,7 @@ module ts {
815825    } 
816826
817827    interface  IncrementalNode  extends  Node ,  IncrementalElement  { 
828+         hasBeenIncrementallyParsed : boolean 
818829    } 
819830
820831    interface  IncrementalNodeArray  extends  NodeArray < IncrementalNode > ,  IncrementalElement  { 
0 commit comments