File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments