Skip to content

Commit f96c04c

Browse files
authored
Merge pull request #21522 from Microsoft/alwaysGetDiagnosticsWhenEmitting
Always get diagnostics when emitting irrespective of whether its declaration only emit
2 parents d0ab164 + 11214b9 commit f96c04c

5 files changed

Lines changed: 31 additions & 13 deletions

File tree

src/compiler/checker.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,12 +749,10 @@ namespace ts {
749749
return _jsxNamespace;
750750
}
751751

752-
function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationToken, ignoreDiagnostics?: boolean) {
752+
function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationToken) {
753753
// Ensure we have all the type information in place for this file so that all the
754754
// emitter questions of this resolver will return the right information.
755-
if (!ignoreDiagnostics) {
756-
getDiagnostics(sourceFile, cancellationToken);
757-
}
755+
getDiagnostics(sourceFile, cancellationToken);
758756
return emitResolver;
759757
}
760758

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ namespace ts {
11791179
// This is because in the -out scenario all files need to be emitted, and therefore all
11801180
// files need to be type checked. And the way to specify that all files need to be type
11811181
// checked is to not pass the file to getEmitResolver.
1182-
const emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out) ? undefined : sourceFile, cancellationToken, emitOnlyDtsFiles);
1182+
const emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out) ? undefined : sourceFile, cancellationToken);
11831183

11841184
performance.mark("beforeEmit");
11851185

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2892,7 +2892,7 @@ namespace ts {
28922892
// Should not be called directly. Should only be accessed through the Program instance.
28932893
/* @internal */ getDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[];
28942894
/* @internal */ getGlobalDiagnostics(): Diagnostic[];
2895-
/* @internal */ getEmitResolver(sourceFile?: SourceFile, cancellationToken?: CancellationToken, ignoreDiagnostics?: boolean): EmitResolver;
2895+
/* @internal */ getEmitResolver(sourceFile?: SourceFile, cancellationToken?: CancellationToken): EmitResolver;
28962896

28972897
/* @internal */ getNodeCount(): number;
28982898
/* @internal */ getIdentifierCount(): number;

src/harness/unittests/builder.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ namespace ts {
7070
// Change e.ts and verify previously b.js as well as a.js get emitted again since previous change was consumed completely but not d.ts
7171
program = updateProgramFile(program, "/e.ts", "export function bar3() { }");
7272
assertChanges(["/b.js", "/a.js", "/e.js"]);
73-
74-
// Cancel in the middle of affected files list after b.js emit
75-
program = updateProgramFile(program, "/b.ts", "export class b { foo2() { c + 1; } }");
76-
assertChanges(["/b.js", "/a.js"], 1);
77-
// Change e.ts and verify previously b.js as well as a.js get emitted again since previous change was consumed completely but not d.ts
78-
program = updateProgramFile(program, "/e.ts", "export function bar5() { }");
79-
assertChanges(["/b.js", "/a.js", "/e.js"]);
8073
});
8174
});
8275

src/harness/unittests/tscWatchMode.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,33 @@ namespace ts.tscWatch {
10861086
// This should be 0
10871087
host.checkTimeoutQueueLengthAndRun(0);
10881088
});
1089+
1090+
it("shouldnt report error about unused function incorrectly when file changes from global to module", () => {
1091+
const getFileContent = (asModule: boolean) => `
1092+
function one() {}
1093+
${asModule ? "export " : ""}function two() {
1094+
return function three() {
1095+
one();
1096+
}
1097+
}`;
1098+
const file: FileOrFolder = {
1099+
path: "/a/b/file.ts",
1100+
content: getFileContent(/*asModule*/ false)
1101+
};
1102+
const files = [file, libFile];
1103+
const host = createWatchedSystem(files);
1104+
const watch = createWatchOfFilesAndCompilerOptions([file.path], host, {
1105+
noUnusedLocals: true
1106+
});
1107+
checkProgramActualFiles(watch(), files.map(file => file.path));
1108+
checkOutputErrors(host, [], ExpectedOutputErrorsPosition.AfterCompilationStarting);
1109+
1110+
file.content = getFileContent(/*asModule*/ true);
1111+
host.reloadFS(files);
1112+
host.runQueuedTimeoutCallbacks();
1113+
checkProgramActualFiles(watch(), files.map(file => file.path));
1114+
checkOutputErrors(host, [], ExpectedOutputErrorsPosition.AfterFileChangeDetected);
1115+
});
10891116
});
10901117

10911118
describe("tsc-watch emit with outFile or out setting", () => {

0 commit comments

Comments
 (0)