Skip to content

Commit ea2021d

Browse files
Create fix for uninvoked decorators.
1 parent e5eccf0 commit ea2021d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Diff for: src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -3709,6 +3709,10 @@
37093709
"category": "Message",
37103710
"code": 90027
37113711
},
3712+
"Call decorator expression.": {
3713+
"category": "Message",
3714+
"code": 90028
3715+
},
37123716

37133717
"Convert function to an ES2015 class": {
37143718
"category": "Message",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* @internal */
2+
namespace ts.codefix {
3+
registerCodeFix({
4+
errorCodes: [Diagnostics._0_accepts_too_few_arguments_to_be_used_as_a_decorator_here_Did_you_mean_to_call_it_first_and_write_0.code],
5+
getCodeActions: (context: CodeFixContext) => {
6+
const sourceFile = context.sourceFile;
7+
const token = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false);
8+
const decorator = getAncestor(token, SyntaxKind.Decorator) as Decorator;
9+
Debug.assert(!!decorator, "Expected position to be owned by a decorator.");
10+
const replacement = createCall(decorator.expression, /*typeArguments*/ undefined, /*argumentsArray*/ undefined);
11+
const changeTracker = textChanges.ChangeTracker.fromContext(context);
12+
changeTracker.replaceNode(sourceFile, decorator.expression, replacement);
13+
14+
return [{
15+
description: getLocaleSpecificMessage(Diagnostics.Call_decorator_expression),
16+
changes: changeTracker.getChanges()
17+
}];
18+
}
19+
});
20+
}

Diff for: src/services/codefixes/fixes.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <reference path="addMissingInvocationForDecorator.ts" />
12
/// <reference path="correctQualifiedNameToIndexedAccessType.ts" />
23
/// <reference path="fixClassIncorrectlyImplementsInterface.ts" />
34
/// <reference path="fixAddMissingMember.ts" />

0 commit comments

Comments
 (0)