mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 01:34:55 -06:00
Create fix for uninvoked decorators.
This commit is contained in:
parent
e5eccf0a22
commit
ea2021dd3e
@ -3709,6 +3709,10 @@
|
||||
"category": "Message",
|
||||
"code": 90027
|
||||
},
|
||||
"Call decorator expression.": {
|
||||
"category": "Message",
|
||||
"code": 90028
|
||||
},
|
||||
|
||||
"Convert function to an ES2015 class": {
|
||||
"category": "Message",
|
||||
|
||||
20
src/services/codefixes/addMissingInvocationForDecorator.ts
Normal file
20
src/services/codefixes/addMissingInvocationForDecorator.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/* @internal */
|
||||
namespace ts.codefix {
|
||||
registerCodeFix({
|
||||
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],
|
||||
getCodeActions: (context: CodeFixContext) => {
|
||||
const sourceFile = context.sourceFile;
|
||||
const token = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false);
|
||||
const decorator = getAncestor(token, SyntaxKind.Decorator) as Decorator;
|
||||
Debug.assert(!!decorator, "Expected position to be owned by a decorator.");
|
||||
const replacement = createCall(decorator.expression, /*typeArguments*/ undefined, /*argumentsArray*/ undefined);
|
||||
const changeTracker = textChanges.ChangeTracker.fromContext(context);
|
||||
changeTracker.replaceNode(sourceFile, decorator.expression, replacement);
|
||||
|
||||
return [{
|
||||
description: getLocaleSpecificMessage(Diagnostics.Call_decorator_expression),
|
||||
changes: changeTracker.getChanges()
|
||||
}];
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
/// <reference path="addMissingInvocationForDecorator.ts" />
|
||||
/// <reference path="correctQualifiedNameToIndexedAccessType.ts" />
|
||||
/// <reference path="fixClassIncorrectlyImplementsInterface.ts" />
|
||||
/// <reference path="fixAddMissingMember.ts" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user