From 2e6abdc08cf2fdc8539a4ab3b2a8e7eed9a64e1f Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Sat, 4 Jan 2020 15:21:19 +0100 Subject: [PATCH 1/2] importsNotUsedAsValue affects semantic diagnostics --- src/compiler/commandLineParser.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 8fd84130cbc47..69871c2e5b0fe 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -480,6 +480,7 @@ namespace ts { error: ImportsNotUsedAsValue.Error }), affectsEmit: true, + affectsSemanticDiagnostics: true, category: Diagnostics.Advanced_Options, description: Diagnostics.Specify_emit_Slashchecking_behavior_for_imports_that_are_only_used_for_types }, From 3f5e4cedb1aa661584c10b21bdc4f09358004426 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Sun, 12 Jan 2020 16:57:39 +0100 Subject: [PATCH 2/2] add tests --- .../unittests/tscWatch/programUpdates.ts | 39 +++ ...mit-when-importsNotUsedAsValues-changes.js | 239 ++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100644 tests/baselines/reference/tscWatch/programUpdates/updates-errors-and-emit-when-importsNotUsedAsValues-changes.js diff --git a/src/testRunner/unittests/tscWatch/programUpdates.ts b/src/testRunner/unittests/tscWatch/programUpdates.ts index a8539eff38bbc..ede0927aa1967 100644 --- a/src/testRunner/unittests/tscWatch/programUpdates.ts +++ b/src/testRunner/unittests/tscWatch/programUpdates.ts @@ -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", diff --git a/tests/baselines/reference/tscWatch/programUpdates/updates-errors-and-emit-when-importsNotUsedAsValues-changes.js b/tests/baselines/reference/tscWatch/programUpdates/updates-errors-and-emit-when-importsNotUsedAsValues-changes.js new file mode 100644 index 0000000000000..f4d689a0a5ba6 --- /dev/null +++ b/tests/baselines/reference/tscWatch/programUpdates/updates-errors-and-emit-when-importsNotUsedAsValues-changes.js @@ -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] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { 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