@@ -683,24 +683,12 @@ module ts {
683
683
}
684
684
}
685
685
686
-
687
- // Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter
688
- // indicates what changed between the 'text' that this SourceFile has and the 'newText'.
689
- // The SourceFile will be created with the compiler attempting to reuse as many nodes from
690
- // this file as possible.
691
- //
692
- // Note: this function mutates nodes from this SourceFile. That means any existing nodes
693
- // from this SourceFile that are being held onto may change as a result (including
694
- // becoming detached from any SourceFile). It is recommended that this SourceFile not
695
- // be used once 'update' is called on it.
696
- export function updateSourceFile ( sourceFile : SourceFile , newText : string , textChangeRange : TextChangeRange , aggressiveChecks ?: boolean ) : SourceFile {
697
- aggressiveChecks = aggressiveChecks || Debug . shouldAssert ( AssertionLevel . Aggressive ) ;
698
-
686
+ function checkChangeRange ( sourceFile : SourceFile , newText : string , textChangeRange : TextChangeRange , aggressiveChecks : boolean ) {
699
687
var oldText = sourceFile . text ;
700
688
if ( textChangeRange ) {
701
689
Debug . assert ( ( oldText . length - textChangeRange . span . length + textChangeRange . newLength ) === newText . length ) ;
702
690
703
- if ( Debug . shouldAssert ( AssertionLevel . VeryAggressive ) ) {
691
+ if ( aggressiveChecks || Debug . shouldAssert ( AssertionLevel . VeryAggressive ) ) {
704
692
var oldTextPrefix = oldText . substr ( 0 , textChangeRange . span . start ) ;
705
693
var newTextPrefix = newText . substr ( 0 , textChangeRange . span . start ) ;
706
694
Debug . assert ( oldTextPrefix === newTextPrefix ) ;
@@ -710,7 +698,21 @@ module ts {
710
698
Debug . assert ( oldTextSuffix === newTextSuffix ) ;
711
699
}
712
700
}
8000
code>
701
+ }
713
702
703
+ // Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter
704
+ // indicates what changed between the 'text' that this SourceFile has and the 'newText'.
705
+ // The SourceFile will be created with the compiler attempting to reuse as many nodes from
706
+ // this file as possible.
707
+ //
708
+ // Note: this function mutates nodes from this SourceFile. That means any existing nodes
709
+ // from this SourceFile that are being held onto may change as a result (including
710
+ // becoming detached from any SourceFile). It is recommended that this SourceFile not
711
+ // be used once 'update' is called on it.
712
+ export function updateSourceFile ( sourceFile : SourceFile , newText : string , textChangeRange : TextChangeRange , aggressiveChecks ?: boolean ) : SourceFile {
713
+ aggressiveChecks = aggressiveChecks || Debug . shouldAssert ( AssertionLevel . Aggressive ) ;
714
+
715
+ checkChangeRange ( sourceFile , newText , textChangeRange , aggressiveChecks ) ;
714
716
if ( textChangeRangeIsUnchanged ( textChangeRange ) ) {
715
717
// if the text didn't change, then we can just return our current source file as-is.
716
718
return sourceFile ;
@@ -722,11 +724,13 @@ module ts {
722
724
return parseSourceFile ( sourceFile . fileName , newText , sourceFile . languageVersion , /*syntaxCursor*/ undefined , /*setNodeParents*/ true )
723
725
}
724
726
727
+ var oldText = sourceFile . text ;
725
728
var syntaxCursor = createSyntaxCursor ( sourceFile ) ;
726
729
727
730
// Make the actual change larger so that we know to reparse anything whose lookahead
728
731
// might have intersected the change.
729
732
var changeRange = extendToAffectedRange ( sourceFile , textChangeRange ) ;
733
+ checkChangeRange ( sourceFile , newText , changeRange , aggressiveChecks ) ;
730
734
731
735
// Ensure that extending the affected range only moved the start of the change range
732
736
// earlier in the file.
0 commit comments