Skip to content

Commit

Permalink
Fix tsc --watch crash on module augmentations when module resolution …
Browse files Browse the repository at this point in the history
…changes (#39604)

* Add failing test

* Ensure source files are bound before analyzing them
  • Loading branch information
andrewbranch authored Jul 14, 2020
1 parent f68a839 commit 98ab3a7
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/compiler/builderState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ namespace ts {
const hasCalledUpdateShapeSignature = new Set<Path>();
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");
Expand Down
20 changes: 20 additions & 0 deletions src/testRunner/unittests/tscWatch/programUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Input::
//// [/a/b/f1.ts]
export {}
declare global {}

//// [/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; }

//// [/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

0 comments on commit 98ab3a7

Please sign in to comment.