Add asserts upstream from #20809

This commit is contained in:
Andrew Casey
2018-01-23 17:18:47 -08:00
parent cae4bc5e83
commit 8ec36e988d
2 changed files with 22 additions and 1 deletions

View File

@@ -681,10 +681,22 @@ namespace ts {
return getSpanOfTokenAtPosition(sourceFile, node.pos);
}
const pos = nodeIsMissing(errorNode)
const isMissing = nodeIsMissing(errorNode);
const pos = isMissing
? errorNode.pos
: skipTrivia(sourceFile.text, errorNode.pos);
// These asserts should all be satisfied for a properly constructed `errorNode`.
// Upstream from https://github.com/Microsoft/TypeScript/issues/20809.
if (isMissing) {
Debug.assert(pos === errorNode.pos);
Debug.assert(pos === errorNode.end);
}
else {
Debug.assert(pos >= errorNode.pos);
Debug.assert(pos <= errorNode.end);
}
return createTextSpanFromBounds(pos, errorNode.end);
}

View File

@@ -335,6 +335,15 @@ namespace ts.refactor.extractSymbol {
Continue = 1 << 1,
Return = 1 << 2
}
// This assert is upstream from https://github.com/Microsoft/TypeScript/issues/20809.
// We believe it's true because the node is from the (unmodified) tree.
Debug.assert(nodeToCheck.pos <= nodeToCheck.end);
// This assert is upstream from https://github.com/Microsoft/TypeScript/issues/20809.
// For understanding how skipTrivia functioned:
Debug.assert(!positionIsSynthesized(nodeToCheck.pos));
if (!isStatement(nodeToCheck) && !(isExpressionNode(nodeToCheck) && isExtractableExpression(nodeToCheck))) {
return [createDiagnosticForNode(nodeToCheck, Messages.statementOrExpressionExpected)];
}