From 93f49f550438bcaaffaf076e51d619b637877afc Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Tue, 14 Jul 2020 12:31:12 -0700 Subject: [PATCH 1/2] Add failing test --- .../unittests/tscWatch/programUpdates.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/testRunner/unittests/tscWatch/programUpdates.ts b/src/testRunner/unittests/tscWatch/programUpdates.ts index 63888db6bf733..3faa145fe2cc6 100644 --- a/src/testRunner/unittests/tscWatch/programUpdates.ts +++ b/src/testRunner/unittests/tscWatch/programUpdates.ts @@ -481,6 +481,26 @@ export class A { changes: emptyArray }); + verifyTscWatch({ + scenario, + subScenario: "change module to none", + commandLineArgs: ["-w", "-p", configFilePath], + sys: () => { + const file1 = { + path: "/a/b/f1.ts", + content: "export {}\ndeclare global {}" + }; + return createWatchedSystem([file1, libFile, configFile]); + }, + changes: [{ + caption: "change `module` to 'none'", + timeouts: checkSingleTimeoutQueueLengthAndRun, + change: sys => { + sys.writeFile(configFilePath, JSON.stringify({ compilerOptions: { module: "none" } })); + } + }] + }); + it("correctly migrate files between projects", () => { const file1 = { path: "/a/b/f1.ts", From 01b6514b6c46b8246efe62c792ac7586ecece610 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Tue, 14 Jul 2020 13:29:05 -0700 Subject: [PATCH 2/2] Ensure source files are bound before analyzing them --- src/compiler/builderState.ts | 3 + .../programUpdates/change-module-to-none.js | 117 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 tests/baselines/reference/tscWatch/programUpdates/change-module-to-none.js diff --git a/src/compiler/builderState.ts b/src/compiler/builderState.ts index 1ad8c0aad1739..1c26513897aee 100644 --- a/src/compiler/builderState.ts +++ b/src/compiler/builderState.ts @@ -206,6 +206,9 @@ namespace ts { const hasCalledUpdateShapeSignature = new Set(); const useOldState = canReuseOldState(referencedMap, oldState); + // Ensure source files have parent pointers set + newProgram.getTypeChecker(); + // Create the reference map, and set the file infos for (const sourceFile of newProgram.getSourceFiles()) { const version = Debug.checkDefined(sourceFile.version, "Program intended to be used with Builder should have source files with versions set"); diff --git a/tests/baselines/reference/tscWatch/programUpdates/change-module-to-none.js b/tests/baselines/reference/tscWatch/programUpdates/change-module-to-none.js new file mode 100644 index 0000000000000..383baf1d6e5a0 --- /dev/null +++ b/tests/baselines/reference/tscWatch/programUpdates/change-module-to-none.js @@ -0,0 +1,117 @@ +Input:: +//// [/a/b/f1.ts] +export {} +declare global {} + +//// [/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; } + +//// [/a/b/tsconfig.json] +{} + + +/a/lib/tsc.js -w -p /a/b/tsconfig.json +Output:: +>> Screen clear +[12:00:15 AM] Starting compilation in watch mode... + + +[12:00:18 AM] Found 0 errors. Watching for file changes. + + + +Program root files: ["/a/b/f1.ts"] +Program options: {"watch":true,"project":"/a/b/tsconfig.json","configFilePath":"/a/b/tsconfig.json"} +Program files:: +/a/lib/lib.d.ts +/a/b/f1.ts + +Semantic diagnostics in builder refreshed for:: +/a/lib/lib.d.ts +/a/b/f1.ts + +WatchedFiles:: +/a/b/tsconfig.json: + {"fileName":"/a/b/tsconfig.json","pollingInterval":250} +/a/b/f1.ts: + {"fileName":"/a/b/f1.ts","pollingInterval":250} +/a/lib/lib.d.ts: + {"fileName":"/a/lib/lib.d.ts","pollingInterval":250} + +FsWatches:: + +FsWatchesRecursive:: +/a/b/node_modules/@types: + {"directoryName":"/a/b/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} +/a/b: + {"directoryName":"/a/b","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} + +exitCode:: ExitStatus.undefined + +//// [/a/b/f1.js] +"use strict"; +exports.__esModule = true; + + + +Change:: change `module` to 'none' + +Input:: +//// [/a/b/tsconfig.json] +{"compilerOptions":{"module":"none"}} + + +Output:: +>> Screen clear +[12:00:22 AM] File change detected. Starting incremental compilation... + + +a/b/f1.ts:1:1 - error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'. + +1 export {} +  ~~~~~~~~~ + + +[12:00:26 AM] Found 1 error. Watching for file changes. + + + +Program root files: ["/a/b/f1.ts"] +Program options: {"module":0,"watch":true,"project":"/a/b/tsconfig.json","configFilePath":"/a/b/tsconfig.json"} +Program files:: +/a/lib/lib.d.ts +/a/b/f1.ts + +Semantic diagnostics in builder refreshed for:: +/a/lib/lib.d.ts +/a/b/f1.ts + +WatchedFiles:: +/a/b/tsconfig.json: + {"fileName":"/a/b/tsconfig.json","pollingInterval":250} +/a/b/f1.ts: + {"fileName":"/a/b/f1.ts","pollingInterval":250} +/a/lib/lib.d.ts: + {"fileName":"/a/lib/lib.d.ts","pollingInterval":250} + +FsWatches:: + +FsWatchesRecursive:: +/a/b: + {"directoryName":"/a/b","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} +/a/b/node_modules/@types: + {"directoryName":"/a/b/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} + +exitCode:: ExitStatus.undefined + +//// [/a/b/f1.js] file written with same contents