From 13685f85a5194a69f6661875d8e9102dec261c3c Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 12 Jul 2018 11:58:09 -0700 Subject: [PATCH 1/2] getContainingList: Handle TypeAliasDeclaration --- src/services/formatting/smartIndenter.ts | 3 ++- tests/cases/fourslash/codeFixUnusedIdentifier_all_delete.ts | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index b024d1f94d03a..004938e3a1e46 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -351,7 +351,8 @@ namespace ts.formatting { getListIfStartEndIsInListRange((node.parent).parameters, start, end); } case SyntaxKind.ClassDeclaration: - return getListIfStartEndIsInListRange((node.parent).typeParameters, node.getStart(sourceFile), end); + case SyntaxKind.TypeAliasDeclaration: + return getListIfStartEndIsInListRange((node.parent).typeParameters, node.getStart(sourceFile), end); case SyntaxKind.NewExpression: case SyntaxKind.CallExpression: { const start = node.getStart(sourceFile); diff --git a/tests/cases/fourslash/codeFixUnusedIdentifier_all_delete.ts b/tests/cases/fourslash/codeFixUnusedIdentifier_all_delete.ts index 5800fbcb1293b..2612ee3f08687 100644 --- a/tests/cases/fourslash/codeFixUnusedIdentifier_all_delete.ts +++ b/tests/cases/fourslash/codeFixUnusedIdentifier_all_delete.ts @@ -37,6 +37,8 @@ ////for (let i = 0, j = 0; ;) {} ////for (const x of []) {} ////for (const y in {}) {} +//// +////export type First = T; verify.codeFixAll({ fixId: "unusedIdentifier_delete", @@ -70,5 +72,7 @@ takesCb((x, y) => { y; }); } for (; ;) {} for (const {} of []) {} -for (const {} in {}) {}`, +for (const {} in {}) {} + +export type First = T;`, }); From b026e26445fc3c9346cd21cc39e409347498e49c Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 12 Jul 2018 12:33:56 -0700 Subject: [PATCH 2/2] Handle ClassExpression and InterfaceDeclaration --- src/services/formatting/smartIndenter.ts | 4 +++- tests/cases/fourslash/codeFixUnusedIdentifier_all_delete.ts | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 004938e3a1e46..c578c38cbc117 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -351,8 +351,10 @@ namespace ts.formatting { getListIfStartEndIsInListRange((node.parent).parameters, start, end); } case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + case SyntaxKind.InterfaceDeclaration: case SyntaxKind.TypeAliasDeclaration: - return getListIfStartEndIsInListRange((node.parent).typeParameters, node.getStart(sourceFile), end); + return getListIfStartEndIsInListRange((node.parent).typeParameters, node.getStart(sourceFile), end); case SyntaxKind.NewExpression: case SyntaxKind.CallExpression: { const start = node.getStart(sourceFile); diff --git a/tests/cases/fourslash/codeFixUnusedIdentifier_all_delete.ts b/tests/cases/fourslash/codeFixUnusedIdentifier_all_delete.ts index 2612ee3f08687..4b485fd403e0a 100644 --- a/tests/cases/fourslash/codeFixUnusedIdentifier_all_delete.ts +++ b/tests/cases/fourslash/codeFixUnusedIdentifier_all_delete.ts @@ -39,6 +39,8 @@ ////for (const y in {}) {} //// ////export type First = T; +////export interface ISecond { u: U; } +////export const cls = class { u: U; }; verify.codeFixAll({ fixId: "unusedIdentifier_delete", @@ -74,5 +76,7 @@ for (; ;) {} for (const {} of []) {} for (const {} in {}) {} -export type First = T;`, +export type First = T; +export interface ISecond { u: U; } +export const cls = class { u: U; };`, });