mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
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]`. Do three things to improve this: 1. `textChanges.ts`: if we get here with the root node, delete it instead of failing. 2. `fixUnusedIdentifier.ts`: check that we don't `delete` a node that is the whole source file, so the error is more focused (should have more similar failure stacks). 3. `session.ts`: when there was any failure in `getCodeFixes`, check if the input had a diag code that does not appear in the requested text range, and throw an error saying that the failure is probably a result of a bad request. Closes #33726 (probably not fixing it, but making it easier to find the cause)
This commit is contained in:
@@ -1363,7 +1363,11 @@ namespace ts.textChanges {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (isImportClause(node.parent) && node.parent.name === node) {
|
||||
if (!node.parent) {
|
||||
// a misbehaving client can reach here with the SourceFile node
|
||||
deleteNode(changes, sourceFile, node);
|
||||
}
|
||||
else if (isImportClause(node.parent) && node.parent.name === node) {
|
||||
deleteDefaultImport(changes, sourceFile, node.parent);
|
||||
}
|
||||
else if (isCallExpression(node.parent) && contains(node.parent.arguments, node)) {
|
||||
|
||||
Reference in New Issue
Block a user