Fix crash in emitTokenWithComment (#36542)

This commit is contained in:
Ron Buckton
2020-01-31 10:41:09 -08:00
committed by GitHub
parent 80ad0de87e
commit 24d8f795b2
4 changed files with 39 additions and 3 deletions

View File

@@ -2744,11 +2744,11 @@ namespace ts {
const node = getParseTreeNode(contextNode);
const isSimilarNode = node && node.kind === contextNode.kind;
const startPos = pos;
if (isSimilarNode) {
pos = skipTrivia(currentSourceFile!.text, pos);
if (isSimilarNode && currentSourceFile) {
pos = skipTrivia(currentSourceFile.text, pos);
}
if (emitLeadingCommentsOfPosition && isSimilarNode && contextNode.pos !== startPos) {
const needsIndent = indentLeading && !positionsAreOnSameLine(startPos, pos, currentSourceFile!);
const needsIndent = indentLeading && currentSourceFile && !positionsAreOnSameLine(startPos, pos, currentSourceFile);
if (needsIndent) {
increaseIndent();
}