Skip to content

Commit 8ec36e9

Browse files
committed
Add asserts upstream from microsoft#20809
1 parent cae4bc5 commit 8ec36e9

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/compiler/utilities.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,22 @@ namespace ts {
681681
return getSpanOfTokenAtPosition(sourceFile, node.pos);
682682
}
683683

684-
const pos = nodeIsMissing(errorNode)
684+
const isMissing = nodeIsMissing(errorNode);
685+
const pos = isMissing
685686
? errorNode.pos
686687
: skipTrivia(sourceFile.text, errorNode.pos);
687688

689+
// These asserts should all be satisfied for a properly constructed `errorNode`.
690+
// Upstream from https://github.com/Microsoft/TypeScript/issues/20809.
691+
if (isMissing) {
692+
Debug.assert(pos === errorNode.pos);
693+
Debug.assert(pos === errorNode.end);
694+
}
695+
else {
696+
Debug.assert(pos >= errorNode.pos);
697+
Debug.assert(pos <= errorNode.end);
698+
}
699+
688700
return createTextSpanFromBounds(pos, errorNode.end);
689701
}
690702

src/services/refactors/extractSymbol.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,15 @@ namespace ts.refactor.extractSymbol {
335335
Continue = 1 << 1,
336336
Return = 1 << 2
337337
}
338+
339+
// This assert is upstream from https://github.com/Microsoft/TypeScript/issues/20809.
340+
// We believe it's true because the node is from the (unmodified) tree.
341+
Debug.assert(nodeToCheck.pos <= nodeToCheck.end);
342+
343+
// This assert is upstream from https://github.com/Microsoft/TypeScript/issues/20809.
344+
// For understanding how skipTrivia functioned:
345+
Debug.assert(!positionIsSynthesized(nodeToCheck.pos));
346+
338347
if (!isStatement(nodeToCheck) && !(isExpressionNode(nodeToCheck) && isExtractableExpression(nodeToCheck))) {
339348
return [createDiagnosticForNode(nodeToCheck, Messages.statementOrExpressionExpected)];
340349
}

0 commit comments

Comments
 (0)