Skip to content

Commit a6c42a6

Browse files
author
Andy
authored
Remove unused properties from interface Refactor (microsoft#21286)
1 parent 98dfb7c commit a6c42a6

8 files changed

+34
-80
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3897,10 +3897,6 @@
38973897
"category": "Message",
38983898
"code": 95002
38993899
},
3900-
"Extract symbol": {
3901-
"category": "Message",
3902-
"code": 95003
3903-
},
39043900
"Extract to {0} in {1}": {
39053901
"category": "Message",
39063902
"code": 95004

src/services/refactorProvider.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
/* @internal */
22
namespace ts {
33
export interface Refactor {
4-
/** An unique code associated with each refactor */
5-
name: string;
6-
7-
/** Description of the refactor to display in the UI of the editor */
8-
description: string;
9-
104
/** Compute the associated code actions */
115
getEditsForAction(context: RefactorContext, actionName: string): RefactorEditInfo | undefined;
126

@@ -27,8 +21,9 @@ namespace ts {
2721
// e.g. nonSuggestableRefactors[refactorCode] -> the refactor you want
2822
const refactors: Map<Refactor> = createMap<Refactor>();
2923

30-
export function registerRefactor(refactor: Refactor) {
31-
refactors.set(refactor.name, refactor);
24+
/** @param name An unique code associated with each refactor. Does not have to be human-readable. */
25+
export function registerRefactor(name: string, refactor: Refactor) {
26+
refactors.set(name, refactor);
3227
}
3328

3429
export function getApplicableRefactors(context: RefactorContext): ApplicableRefactorInfo[] {

src/services/refactors/annotateWithTypeFromJSDoc.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
/* @internal */
22
namespace ts.refactor.annotateWithTypeFromJSDoc {
3+
const refactorName = "Annotate with type from JSDoc";
34
const actionName = "annotate";
5+
const description = Diagnostics.Annotate_with_type_from_JSDoc.message;
6+
registerRefactor(refactorName, { getEditsForAction, getAvailableActions });
47

5-
const annotateTypeFromJSDoc: Refactor = {
6-
name: "Annotate with type from JSDoc",
7-
description: Diagnostics.Annotate_with_type_from_JSDoc.message,
8-
getEditsForAction,
9-
getAvailableActions
10-
};
118
type DeclarationWithType =
129
| FunctionLikeDeclaration
1310
| VariableDeclaration
1411
| ParameterDeclaration
1512
| PropertySignature
1613
| PropertyDeclaration;
1714

18-
registerRefactor(annotateTypeFromJSDoc);
19-
2015
function getAvailableActions(context: RefactorContext): ApplicableRefactorInfo[] | undefined {
2116
if (isInJavaScriptFile(context.file)) {
2217
return undefined;
@@ -25,11 +20,11 @@ namespace ts.refactor.annotateWithTypeFromJSDoc {
2520
const node = getTokenAtPosition(context.file, context.startPosition, /*includeJsDocComment*/ false);
2621
if (hasUsableJSDoc(findAncestor(node, isDeclarationWithType))) {
2722
return [{
28-
name: annotateTypeFromJSDoc.name,
29-
description: annotateTypeFromJSDoc.description,
23+
name: refactorName,
24+
description,
3025
actions: [
3126
{
32-
description: annotateTypeFromJSDoc.description,
27+
description,
3328
name: actionName
3429
}
3530
]

src/services/refactors/convertFunctionToEs6Class.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
/* @internal */
22

33
namespace ts.refactor.convertFunctionToES6Class {
4+
const refactorName = "Convert to ES2015 class";
45
const actionName = "convert";
5-
6-
const convertFunctionToES6Class: Refactor = {
7-
name: "Convert to ES2015 class",
8-
description: Diagnostics.Convert_function_to_an_ES2015_class.message,
9-
getEditsForAction,
10-
getAvailableActions
11-
};
12-
13-
registerRefactor(convertFunctionToES6Class);
6+
const description = Diagnostics.Convert_function_to_an_ES2015_class.message;
7+
registerRefactor(refactorName, { getEditsForAction, getAvailableActions });
148

159
function getAvailableActions(context: RefactorContext): ApplicableRefactorInfo[] | undefined {
1610
if (!isInJavaScriptFile(context.file)) {
@@ -29,11 +23,11 @@ namespace ts.refactor.convertFunctionToES6Class {
2923
if ((symbol.flags & SymbolFlags.Function) && symbol.members && (symbol.members.size > 0)) {
3024
return [
3125
{
32-
name: convertFunctionToES6Class.name,
33-
description: convertFunctionToES6Class.description,
26+
name: refactorName,
27+
description,
3428
actions: [
3529
{
36-
description: convertFunctionToES6Class.description,
30+
description,
3731
name: actionName
3832
}
3933
]

src/services/refactors/convertToEs6Module.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
/* @internal */
22
namespace ts.refactor {
33
const actionName = "Convert to ES6 module";
4-
5-
const convertToEs6Module: Refactor = {
6-
name: actionName,
7-
description: getLocaleSpecificMessage(Diagnostics.Convert_to_ES6_module),
8-
getEditsForAction,
9-
getAvailableActions,
10-
};
11-
12-
registerRefactor(convertToEs6Module);
4+
const description = getLocaleSpecificMessage(Diagnostics.Convert_to_ES6_module);
5+
registerRefactor(actionName, { getEditsForAction, getAvailableActions });
136

147
function getAvailableActions(context: RefactorContext): ApplicableRefactorInfo[] | undefined {
158
const { file, startPosition } = context;
@@ -20,11 +13,11 @@ namespace ts.refactor {
2013
const node = getTokenAtPosition(file, startPosition, /*includeJsDocComment*/ false);
2114
return !isAtTriggerLocation(file, node) ? undefined : [
2215
{
23-
name: convertToEs6Module.name,
24-
description: convertToEs6Module.description,
16+
name: actionName,
17+
description,
2518
actions: [
2619
{
27-
description: convertToEs6Module.description,
20+
description,
2821
name: actionName,
2922
},
3023
],

src/services/refactors/extractSymbol.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33

44
/* @internal */
55
namespace ts.refactor.extractSymbol {
6-
const extractSymbol: Refactor = {
7-
name: "Extract Symbol",
8-
description: getLocaleSpecificMessage(Diagnostics.Extract_symbol),
9-
getAvailableActions,
10-
getEditsForAction,
11-
};
12-
13-
registerRefactor(extractSymbol);
6+
const refactorName = "Extract Symbol";
7+
registerRefactor(refactorName, { getAvailableActions, getEditsForAction });
148

159
/**
1610
* Compute the associated code actions
@@ -77,15 +71,15 @@ namespace ts.refactor.extractSymbol {
7771

7872
if (functionActions.length) {
7973
infos.push({
80-
name: extractSymbol.name,
74+
name: refactorName,
8175
description: getLocaleSpecificMessage(Diagnostics.Extract_function),
8276
actions: functionActions
8377
});
8478
}
8579

8680
if (constantActions.length) {
8781
infos.push({
88-
name: extractSymbol.name,
82+
name: refactorName,
8983
description: getLocaleSpecificMessage(Diagnostics.Extract_constant),
9084
actions: constantActions
9185
});

src/services/refactors/installTypesForPackage.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
/* @internal */
22
namespace ts.refactor.installTypesForPackage {
3+
const refactorName = "Install missing types package";
34
const actionName = "install";
4-
5-
const installTypesForPackage: Refactor = {
6-
name: "Install missing types package",
7-
description: "Install missing types package",
8-
getEditsForAction,
9-
getAvailableActions,
10-
};
11-
12-
registerRefactor(installTypesForPackage);
5+
const description = "Install missing types package";
6+
registerRefactor(refactorName, { getEditsForAction, getAvailableActions });
137

148
function getAvailableActions(context: RefactorContext): ApplicableRefactorInfo[] | undefined {
159
if (getStrictOptionValue(context.program.getCompilerOptions(), "noImplicitAny")) {
@@ -20,8 +14,8 @@ namespace ts.refactor.installTypesForPackage {
2014
const action = getAction(context);
2115
return action && [
2216
{
23-
name: installTypesForPackage.name,
24-
description: installTypesForPackage.description,
17+
name: refactorName,
18+
description,
2519
actions: [
2620
{
2721
description: action.description,

src/services/refactors/useDefaultImport.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
/* @internal */
22
namespace ts.refactor.installTypesForPackage {
33
const actionName = "Convert to default import";
4-
5-
const useDefaultImport: Refactor = {
6-
name: actionName,
7-
description: getLocaleSpecificMessage(Diagnostics.Convert_to_default_import),
8-
getEditsForAction,
9-
getAvailableActions,
10-
};
11-
12-
registerRefactor(useDefaultImport);
4+
const description = getLocaleSpecificMessage(Diagnostics.Convert_to_default_import);
5+
registerRefactor(actionName, { getEditsForAction, getAvailableActions });
136

147
function getAvailableActions(context: RefactorContext): ApplicableRefactorInfo[] | undefined {
158
const { file, startPosition, program } = context;
@@ -31,11 +24,11 @@ namespace ts.refactor.installTypesForPackage {
3124

3225
return [
3326
{
34-
name: useDefaultImport.name,
35-
description: useDefaultImport.description,
27+
name: actionName,
28+
description,
3629
actions: [
3730
{
38-
description: useDefaultImport.description,
31+
description,
3932
name: actionName,
4033
},
4134
],

0 commit comments

Comments
 (0)