@@ -336,11 +336,16 @@ module ts {
336
336
}
337
337
338
338
function fixupParentReferences ( sourceFile : SourceFile ) {
339
- // normally parent references are set during binding.
340
- // however here SourceFile data is used only for syntactic features so running the whole binding process is an overhead.
341
- // walk over the nodes and set parent references
339
+ // normally parent references are set during binding. However, for clients that only need
340
+ // a syntax tree, and no semantic features, then the binding process is an unnecessary
341
+ // overhead. This functions allows us to set all the parents, without all the expense of
342
+ // binding.
343
+
342
344
var parent : Node = sourceFile ;
343
- function walk ( n : Node ) : void {
345
+ forEachChild ( sourceFile , visitNode ) ;
346
+ return ;
347
+
348
+ function visitNode ( n : Node ) : void {
344
349
// walk down setting parents that differ from the parent we think it should be. This
345
350
// allows us to quickly bail out of setting parents for subtrees during incremental
346
351
// parsing
@@ -349,12 +354,10 @@ module ts {
349
354
350
355
var saveParent = parent ;
351
356
parent = n ;
352
- forEachChild ( n , walk ) ;
357
+ forEachChild ( n , visitNode ) ;
353
358
parent = saveParent ;
354
359
}
355
360
}
356
-
357
- forEachChild ( sourceFile , walk ) ;
358
361
}
359
362
360
363
function shouldCheckNode ( node : Node ) {
@@ -721,7 +724,7 @@ module ts {
721
724
if ( sourceFile . statements . length === 0 ) {
722
725
// If we don't have any statements in the current source file, then there's no real
723
726
// way to incrementally parse. So just do a full parse instead.
724
- return parseSourceFile ( sourceFile . fileName , newText , sourceFile . languageVersion , /*syntaxCursor*/ undefined , /*setNodeParents*/ true )
727
+ return parseSourceFile ( sourceFile . fileName , newText , sourceFile . languageVersion , /*syntaxCursor*/ undefined , /*setNodeParents*/ true )
725
728
}
726
729
727
730
var oldText = sourceFile . text ;
@@ -744,8 +747,8 @@ module ts {
744
747
var delta = textChangeRangeNewSpan ( changeRange ) . length - changeRange . span . length ;
745
748
746
749
// If we added or removed characters during the edit, then we need to go and adjust all
747
- // the nodes after the edit. Those nodes may move forward down (if we inserted chars)
748
- // or they may move backward (if we deleted chars).
750
+ // the nodes after the edit. Those nodes may move forward (if we inserted chars) or they
751
+ // may move backward (if we deleted chars).
749
752
//
750
753
// Doing this helps us out in two ways. First, it means that any nodes/tokens we want
751
754
// to reuse are already at the appropriate position in the new text. That way when we
@@ -1045,6 +1048,7 @@ module ts {
1045
1048
fixupParentReferences ( sourceFile ) ;
1046
1049
}
1047
1050
1051
+ syntaxCursor = undefined ;
1048
1052
return sourceFile ;
1049
1053
1050
1054
function setContextFlag ( val : Boolean , flag : ParserContextFlags ) {
0 commit comments