Skip to content

Commit a280777

Browse files
committed
deleteDeclaration: don't crash on the top node.
A misbehaved client can sometimes cause the server to reach `deleteDeclaration` with the SourceFile, and it will crash due to no `node.parent`. I couldn't find a good way to create a test for it, but I could trigger it manually by having a file with just a `,`, and sending an explicit `getCodeFixes` command to the server with `errorCodes: [6133]`. I can only guess some scenario in which Emacs or other editors could lead to that, but it's easy to just avoid the crash instead. (Doing the default of deleting the whole thing -- not really important since it's a broken client situation anyway--?) Fixes microsoft#33726
1 parent ccdd688 commit a280777

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/services/textChanges.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,10 @@ namespace ts.textChanges {
13611361
break;
13621362

13631363
default:
1364-
if (isImportClause(node.parent) && node.parent.name === node) {
1364+
if (node.parent === node) {
1365+
// a misbehaving client can reach here with the SourceFile node
1366+
deleteNode(changes, sourceFile, node);
1367+
} else if (isImportClause(node.parent) && node.parent.name === node) {
13651368
deleteDefaultImport(changes, sourceFile, node.parent);
13661369
}
13671370
else if (isCallExpression(node.parent) && contains(node.parent.arguments, node)) {

0 commit comments

Comments
 (0)