importsNotUsedAsValue affects semantic diagnostics (#36001)

* importsNotUsedAsValue affects semantic diagnostics

* add tests
This commit is contained in:
Klaus Meinhardt 2020-01-16 00:08:17 +01:00 committed by Sheetal Nandi
parent 81a942e7b9
commit f220e62ce7
3 changed files with 279 additions and 0 deletions

View file

@ -480,6 +480,7 @@ namespace ts {
error: importsNotUsedAsValues.Error
}),
affectsEmit: true,
affectsSemanticDiagnostics: true,
category: Diagnostics.Advanced_Options,
description: Diagnostics.Specify_emit_Slashchecking_behavior_for_imports_that_are_only_used_for_types
},

View file

@ -1121,6 +1121,45 @@ foo().hello`
]
});
verifyTscWatch({
scenario,
subScenario: "updates errors and emit when importsNotUsedAsValues changes",
commandLineArgs: ["-w"],
sys: () => {
const aFile: File = {
path: `${projectRoot}/a.ts`,
content: `export class C {}`
};
const bFile: File = {
path: `${projectRoot}/b.ts`,
content: `import {C} from './a';
export function f(p: C) { return p; }`
};
const config: File = {
path: `${projectRoot}/tsconfig.json`,
content: JSON.stringify({ compilerOptions: {} })
};
return createWatchedSystem([aFile, bFile, config, libFile], { currentDirectory: projectRoot });
},
changes: [
sys => {
sys.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify({ compilerOptions: { importsNotUsedAsValues: "remove" } }));
sys.runQueuedTimeoutCallbacks();
return 'Set to "remove"';
},
sys => {
sys.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify({ compilerOptions: { importsNotUsedAsValues: "error" } }));
sys.runQueuedTimeoutCallbacks();
return 'Set to "error"';
},
sys => {
sys.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify({ compilerOptions: { importsNotUsedAsValues: "preserve" } }));
sys.runQueuedTimeoutCallbacks();
return 'Set to "preserve"';
},
]
});
verifyTscWatch({
scenario,
subScenario: "updates errors when ambient modules of program changes",

View file

@ -0,0 +1,239 @@
/a/lib/tsc.js -w
//// [/user/username/projects/myproject/a.ts]
export class C {}
//// [/user/username/projects/myproject/b.ts]
import {C} from './a';
export function f(p: C) { return p; }
//// [/user/username/projects/myproject/tsconfig.json]
{"compilerOptions":{}}
//// [/a/lib/lib.d.ts]
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
//// [/user/username/projects/myproject/a.js]
"use strict";
exports.__esModule = true;
var C = /** @class */ (function () {
function C() {
}
return C;
}());
exports.C = C;
//// [/user/username/projects/myproject/b.js]
"use strict";
exports.__esModule = true;
function f(p) { return p; }
exports.f = f;
Output::
>> Screen clear
12:00:23 AM - Starting compilation in watch mode...
12:00:28 AM - Found 0 errors. Watching for file changes.
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
Program options: {"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts
Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts
WatchedFiles::
/user/username/projects/myproject/tsconfig.json:
{"pollingInterval":250}
/user/username/projects/myproject/a.ts:
{"pollingInterval":250}
/user/username/projects/myproject/b.ts:
{"pollingInterval":250}
/a/lib/lib.d.ts:
{"pollingInterval":250}
FsWatches::
FsWatchesRecursive::
/user/username/projects/myproject/node_modules/@types:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/user/username/projects/myproject:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
exitCode:: ExitStatus.undefined
Change:: Set to "remove"
//// [/user/username/projects/myproject/tsconfig.json]
{"compilerOptions":{"importsNotUsedAsValues":"remove"}}
//// [/user/username/projects/myproject/a.js] file written with same contents
//// [/user/username/projects/myproject/b.js] file written with same contents
Output::
>> Screen clear
12:00:32 AM - File change detected. Starting incremental compilation...
12:00:39 AM - Found 0 errors. Watching for file changes.
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
Program options: {"importsNotUsedAsValues":0,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts
Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts
WatchedFiles::
/user/username/projects/myproject/tsconfig.json:
{"pollingInterval":250}
/user/username/projects/myproject/a.ts:
{"pollingInterval":250}
/user/username/projects/myproject/b.ts:
{"pollingInterval":250}
/a/lib/lib.d.ts:
{"pollingInterval":250}
FsWatches::
FsWatchesRecursive::
/user/username/projects/myproject/node_modules/@types:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/user/username/projects/myproject:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
exitCode:: ExitStatus.undefined
Change:: Set to "error"
//// [/user/username/projects/myproject/tsconfig.json]
{"compilerOptions":{"importsNotUsedAsValues":"error"}}
//// [/user/username/projects/myproject/a.js] file written with same contents
//// [/user/username/projects/myproject/b.js]
"use strict";
exports.__esModule = true;
require("./a");
function f(p) { return p; }
exports.f = f;
Output::
>> Screen clear
12:00:43 AM - File change detected. Starting incremental compilation...
b.ts(1,1): error TS1371: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
12:00:50 AM - Found 1 error. Watching for file changes.
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
Program options: {"importsNotUsedAsValues":2,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts
Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts
WatchedFiles::
/user/username/projects/myproject/tsconfig.json:
{"pollingInterval":250}
/user/username/projects/myproject/a.ts:
{"pollingInterval":250}
/user/username/projects/myproject/b.ts:
{"pollingInterval":250}
/a/lib/lib.d.ts:
{"pollingInterval":250}
FsWatches::
FsWatchesRecursive::
/user/username/projects/myproject/node_modules/@types:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/user/username/projects/myproject:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
exitCode:: ExitStatus.undefined
Change:: Set to "preserve"
//// [/user/username/projects/myproject/tsconfig.json]
{"compilerOptions":{"importsNotUsedAsValues":"preserve"}}
//// [/user/username/projects/myproject/a.js] file written with same contents
//// [/user/username/projects/myproject/b.js] file written with same contents
Output::
>> Screen clear
12:00:54 AM - File change detected. Starting incremental compilation...
12:01:01 AM - Found 0 errors. Watching for file changes.
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
Program options: {"importsNotUsedAsValues":1,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts
Semantic diagnostics in builder refreshed for::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.ts
/user/username/projects/myproject/b.ts
WatchedFiles::
/user/username/projects/myproject/tsconfig.json:
{"pollingInterval":250}
/user/username/projects/myproject/a.ts:
{"pollingInterval":250}
/user/username/projects/myproject/b.ts:
{"pollingInterval":250}
/a/lib/lib.d.ts:
{"pollingInterval":250}
FsWatches::
FsWatchesRecursive::
/user/username/projects/myproject/node_modules/@types:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/user/username/projects/myproject:
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
exitCode:: ExitStatus.undefined