• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* @internal */
2namespace ts.codefix {
3    const fixID = "fixEnableJsxFlag";
4    const errorCodes = [Diagnostics.Cannot_use_JSX_unless_the_jsx_flag_is_provided.code];
5    registerCodeFix({
6        errorCodes,
7        getCodeActions: context => {
8            const { configFile } = context.program.getCompilerOptions();
9            if (configFile === undefined) {
10                return undefined;
11            }
12
13            const changes = textChanges.ChangeTracker.with(context, changeTracker =>
14                doChange(changeTracker, configFile)
15            );
16            return [
17                createCodeFixActionWithoutFixAll(fixID, changes, Diagnostics.Enable_the_jsx_flag_in_your_configuration_file)
18            ];
19        },
20        fixIds: [fixID],
21        getAllCodeActions: context =>
22            codeFixAll(context, errorCodes, changes => {
23                const { configFile } = context.program.getCompilerOptions();
24                if (configFile === undefined) {
25                    return undefined;
26                }
27
28                doChange(changes, configFile);
29            })
30    });
31
32    function doChange(changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile) {
33        setJsonCompilerOptionValue(changeTracker, configFile, "jsx", factory.createStringLiteral("react"));
34    }
35}
36