Skip to content
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
6 changes: 2 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,10 @@ namespace ts {
return _jsxNamespace;
}

function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationToken, ignoreDiagnostics?: boolean) {
function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationToken) {
// Ensure we have all the type information in place for this file so that all the
// emitter questions of this resolver will return the right information.
if (!ignoreDiagnostics) {
getDiagnostics(sourceFile, cancellationToken);
}
getDiagnostics(sourceFile, cancellationToken);
return emitResolver;
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ namespace ts {
// This is because in the -out scenario all files need to be emitted, and therefore all
// files need to be type checked. And the way to specify that all files need to be type
// checked is to not pass the file to getEmitResolver.
const emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out) ? undefined : sourceFile, cancellationToken, emitOnlyDtsFiles);
const emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out) ? undefined : sourceFile, cancellationToken);

performance.mark("beforeEmit");

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2892,7 +2892,7 @@ namespace ts {
// Should not be called directly. Should only be accessed through the Program instance.
/* @internal */ getDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[];
/* @internal */ getGlobalDiagnostics(): Diagnostic[];
/* @internal */ getEmitResolver(sourceFile?: SourceFile, cancellationToken?: CancellationToken, ignoreDiagnostics?: boolean): EmitResolver;
/* @internal */ getEmitResolver(sourceFile?: SourceFile, cancellationToken?: CancellationToken): EmitResolver;

/* @internal */ getNodeCount(): number;
/* @internal */ getIdentifierCount(): number;
Expand Down
7 changes: 0 additions & 7 deletions src/harness/unittests/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ namespace ts {
// 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
program = updateProgramFile(program, "/e.ts", "export function bar3() { }");
assertChanges(["/b.js", "/a.js", "/e.js"]);

// Cancel in the middle of affected files list after b.js emit
program = updateProgramFile(program, "/b.ts", "export class b { foo2() { c + 1; } }");
assertChanges(["/b.js", "/a.js"], 1);
// 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
program = updateProgramFile(program, "/e.ts", "export function bar5() { }");
assertChanges(["/b.js", "/a.js", "/e.js"]);
});
});

Expand Down
27 changes: 27 additions & 0 deletions src/harness/unittests/tscWatchMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,33 @@ namespace ts.tscWatch {
// This should be 0
host.checkTimeoutQueueLengthAndRun(0);
});

it("shouldnt report error about unused function incorrectly when file changes from global to module", () => {
const getFileContent = (asModule: boolean) => `
function one() {}
${asModule ? "export " : ""}function two() {
return function three() {
one();
}
}`;
const file: FileOrFolder = {
path: "/a/b/file.ts",
content: getFileContent(/*asModule*/ false)
};
const files = [file, libFile];
const host = createWatchedSystem(files);
const watch = createWatchOfFilesAndCompilerOptions([file.path], host, {
noUnusedLocals: true
});
checkProgramActualFiles(watch(), files.map(file => file.path));
checkOutputErrors(host, [], ExpectedOutputErrorsPosition.AfterCompilationStarting);

file.content = getFileContent(/*asModule*/ true);
host.reloadFS(files);
host.runQueuedTimeoutCallbacks();
checkProgramActualFiles(watch(), files.map(file => file.path));
checkOutputErrors(host, [], ExpectedOutputErrorsPosition.AfterFileChangeDetected);
});
});

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