Skip to content

Fix tsc --watch crash on module augmentations when module resolution changes #39604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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