• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* @internal */
2namespace ts.codefix {
3    const fixId = "addMissingInvocationForDecorator";
4    const 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    registerCodeFix({
6        errorCodes,
7        getCodeActions: (context) => {
8            const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start));
9            return [createCodeFixAction(fixId, changes, Diagnostics.Call_decorator_expression, fixId, Diagnostics.Add_to_all_uncalled_decorators)];
10        },
11        fixIds: [fixId],
12        getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag.start)),
13    });
14
15    function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number) {
16        const token = getTokenAtPosition(sourceFile, pos);
17        const decorator = findAncestor(token, isDecorator)!;
18        Debug.assert(!!decorator, "Expected position to be owned by a decorator.");
19        const replacement = factory.createCallExpression(decorator.expression, /*typeArguments*/ undefined, /*argumentsArray*/ undefined);
20        changeTracker.replaceNode(sourceFile, decorator.expression, replacement);
21    }
22}
23