Move assertions into the parsing layer.
This commit is contained in:
parent
a82c57c4b9
commit
1a17fd1daf
2 changed files with 15 additions and 18 deletions
|
@ -696,6 +696,21 @@ module ts {
|
|||
export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile {
|
||||
aggressiveChecks = aggressiveChecks || Debug.shouldAssert(AssertionLevel.Aggressive);
|
||||
|
||||
var oldText = sourceFile.text;
|
||||
if (textChangeRange) {
|
||||
Debug.assert((oldText.length - textChangeRange.span.length + textChangeRange.newLength) === newText.length);
|
||||
|
||||
if (Debug.shouldAssert(AssertionLevel.VeryAggressive)) {
|
||||
var oldTextPrefix = oldText.substr(0, textChangeRange.span.start);
|
||||
var newTextPrefix = newText.substr(0, textChangeRange.span.start);
|
||||
Debug.assert(oldTextPrefix === newTextPrefix);
|
||||
|
||||
var oldTextSuffix = oldText.substring(textSpanEnd(textChangeRange.span), oldText.length);
|
||||
var newTextSuffix = newText.substring(textSpanEnd(textChangeRangeNewSpan(textChangeRange)), newText.length);
|
||||
Debug.assert(oldTextSuffix === newTextSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
if (textChangeRangeIsUnchanged(textChangeRange)) {
|
||||
// if the text didn't change, then we can just return our current source file as-is.
|
||||
return sourceFile;
|
||||
|
@ -707,7 +722,6 @@ module ts {
|
|||
return parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion,/*syntaxCursor*/ undefined, /*setNodeParents*/ true)
|
||||
}
|
||||
|
||||
var oldText = sourceFile.text;
|
||||
var syntaxCursor = createSyntaxCursor(sourceFile);
|
||||
|
||||
// Make the actual change larger so that we know to reparse anything whose lookahead
|
||||
|
|
|
@ -1625,23 +1625,6 @@ module ts {
|
|||
export var disableIncrementalParsing = false;
|
||||
|
||||
export function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile {
|
||||
if (textChangeRange && Debug.shouldAssert(AssertionLevel.Normal)) {
|
||||
var oldText = sourceFile.scriptSnapshot;
|
||||
var newText = scriptSnapshot;
|
||||
|
||||
Debug.assert((oldText.getLength() - textChangeRange.span.length + textChangeRange.newLength) === newText.getLength());
|
||||
|
||||
if (Debug.shouldAssert(AssertionLevel.VeryAggressive)) {
|
||||
var oldTextPrefix = oldText.getText(0, textChangeRange.span.start);
|
||||
var newTextPrefix = newText.getText(0, textChangeRange.span.start);
|
||||
Debug.assert(oldTextPrefix === newTextPrefix);
|
||||
|
||||
var oldTextSuffix = oldText.getText(textSpanEnd(textChangeRange.span), oldText.getLength());
|
||||
var newTextSuffix = newText.getText(textSpanEnd(textChangeRangeNewSpan(textChangeRange)), newText.getLength());
|
||||
Debug.assert(oldTextSuffix === newTextSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
// If we were given a text change range, and our version or open-ness changed, then
|
||||
// incrementally parse this file.
|
||||
if (textChangeRange) {
|
||||
|
|
Loading…
Reference in a new issue