Skip to content

Commit 1a6d6ad

Browse files
committed
Merge branch 'release-2.7' of github.com:Microsoft/TypeScript into release-2.7
2 parents 7d946fb + 36eafce commit 1a6d6ad

File tree

13 files changed

+121
-53
lines changed

13 files changed

+121
-53
lines changed

src/compiler/checker.ts

Lines changed: 3 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

@@ -21031,6 +21029,7 @@ namespace ts {
2103121029
}
2103221030
break;
2103321031
case SyntaxKind.IndexSignature:
21032+
case SyntaxKind.SemicolonClassElement:
2103421033
// Can't be private
2103521034
break;
2103621035
default:

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/compiler/watch.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ namespace ts {
3131
};
3232
}
3333

34-
function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic) {
35-
if (system.clearScreen && diagnostic.code !== Diagnostics.Compilation_complete_Watching_for_file_changes.code) {
34+
function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic, options: CompilerOptions) {
35+
if (system.clearScreen &&
36+
diagnostic.code !== Diagnostics.Compilation_complete_Watching_for_file_changes.code &&
37+
!options.extendedDiagnostics &&
38+
!options.diagnostics) {
3639
system.clearScreen();
3740
}
3841
}
@@ -42,18 +45,18 @@ namespace ts {
4245
*/
4346
export function createWatchStatusReporter(system: System, pretty?: boolean): WatchStatusReporter {
4447
return pretty ?
45-
(diagnostic: Diagnostic, newLine: string) => {
46-
clearScreenIfNotWatchingForFileChanges(system, diagnostic);
47-
let output = `[${ formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey) }] `;
48-
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`;
49-
system.write(output);
50-
} :
51-
(diagnostic: Diagnostic, newLine: string) => {
52-
clearScreenIfNotWatchingForFileChanges(system, diagnostic);
53-
let output = new Date().toLocaleTimeString() + " - ";
54-
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`;
55-
system.write(output);
56-
};
48+
(diagnostic, newLine, options) => {
49+
clearScreenIfNotWatchingForFileChanges(system, diagnostic, options);
50+
let output = `[${formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey)}] `;
51+
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`;
52+
system.write(output);
53+
} :
54+
(diagnostic, newLine, options) => {
55+
clearScreenIfNotWatchingForFileChanges(system, diagnostic, options);
56+
let output = new Date().toLocaleTimeString() + " - ";
57+
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`;
58+
system.write(output);
59+
};
5760
}
5861

5962
/**
@@ -254,7 +257,7 @@ namespace ts {
254257

255258
namespace ts {
256259
export type DiagnosticReporter = (diagnostic: Diagnostic) => void;
257-
export type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string) => void;
260+
export type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void;
258261
export type CreateProgram<T extends BuilderProgram> = (rootNames: ReadonlyArray<string>, options: CompilerOptions, host?: CompilerHost, oldProgram?: T) => T;
259262
export interface WatchCompilerHost<T extends BuilderProgram> {
260263
/**
@@ -264,7 +267,7 @@ namespace ts {
264267
/** If provided, callback to invoke after every new program creation */
265268
afterProgramCreate?(program: T): void;
266269
/** If provided, called with Diagnostic message that informs about change in watch status */
267-
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string): void;
270+
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void;
268271

269272
// Only for testing
270273
/*@internal*/
@@ -725,7 +728,7 @@ namespace ts {
725728

726729
function reportWatchDiagnostic(message: DiagnosticMessage) {
727730
if (host.onWatchStatusChange) {
728-
host.onWatchStatusChange(createCompilerDiagnostic(message), newLine);
731+
host.onWatchStatusChange(createCompilerDiagnostic(message), newLine, compilerOptions);
729732
}
730733
}
731734

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: 57 additions & 20 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", () => {
@@ -2075,35 +2102,45 @@ declare module "fs" {
20752102
});
20762103

20772104
describe("tsc-watch console clearing", () => {
2078-
it("clears the console when it starts", () => {
2105+
function checkConsoleClearing(diagnostics: boolean, extendedDiagnostics: boolean) {
20792106
const file = {
20802107
path: "f.ts",
20812108
content: ""
20822109
};
2083-
const host = createWatchedSystem([file]);
2110+
const files = [file];
2111+
const host = createWatchedSystem(files);
2112+
let clearCount: number | undefined;
2113+
checkConsoleClears();
20842114

2085-
createWatchOfFilesAndCompilerOptions([file.path], host);
2086-
host.runQueuedTimeoutCallbacks();
2115+
createWatchOfFilesAndCompilerOptions([file.path], host, { diagnostics, extendedDiagnostics });
2116+
checkConsoleClears();
20872117

2088-
host.checkScreenClears(1);
2089-
});
2118+
file.content = "//";
2119+
host.reloadFS(files);
2120+
host.runQueuedTimeoutCallbacks();
20902121

2091-
it("clears the console on recompile", () => {
2092-
const file = {
2093-
path: "f.ts",
2094-
content: ""
2095-
};
2096-
const host = createWatchedSystem([file]);
2097-
createWatchOfFilesAndCompilerOptions([file.path], host);
2122+
checkConsoleClears();
20982123

2099-
const modifiedFile = {
2100-
...file,
2101-
content: "//"
2102-
};
2103-
host.reloadFS([modifiedFile]);
2104-
host.runQueuedTimeoutCallbacks();
2124+
function checkConsoleClears() {
2125+
if (clearCount === undefined) {
2126+
clearCount = 0;
2127+
}
2128+
else if (!diagnostics && !extendedDiagnostics) {
2129+
clearCount++;
2130+
}
2131+
host.checkScreenClears(clearCount);
2132+
return clearCount;
2133+
}
2134+
}
21052135

2106-
host.checkScreenClears(2);
2136+
it("without --diagnostics or --extendedDiagnostics", () => {
2137+
checkConsoleClearing(/*diagnostics*/ false, /*extendedDiagnostics*/ false);
2138+
});
2139+
it("with --diagnostics", () => {
2140+
checkConsoleClearing(/*diagnostics*/ true, /*extendedDiagnostics*/ false);
2141+
});
2142+
it("with --extendedDiagnostics", () => {
2143+
checkConsoleClearing(/*diagnostics*/ false, /*extendedDiagnostics*/ true);
21072144
});
21082145
});
21092146
}

src/services/completions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,8 @@ namespace ts.Completions {
19211921
return isDeclarationName(contextToken)
19221922
&& !isJsxAttribute(contextToken.parent)
19231923
// Don't block completions if we're in `class C /**/`, because we're *past* the end of the identifier and might want to complete `extends`.
1924-
&& !(isClassLike(contextToken.parent) && position > previousToken.end);
1924+
// If `contextToken !== previousToken`, this is `class C ex/**/`.
1925+
&& !(isClassLike(contextToken.parent) && (contextToken !== previousToken || position > previousToken.end));
19251926
}
19261927

19271928
function isFunctionLikeButNotConstructor(kind: SyntaxKind) {

tests/baselines/reference/api/typescript.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3976,7 +3976,7 @@ declare namespace ts {
39763976
}
39773977
declare namespace ts {
39783978
type DiagnosticReporter = (diagnostic: Diagnostic) => void;
3979-
type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string) => void;
3979+
type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void;
39803980
type CreateProgram<T extends BuilderProgram> = (rootNames: ReadonlyArray<string>, options: CompilerOptions, host?: CompilerHost, oldProgram?: T) => T;
39813981
interface WatchCompilerHost<T extends BuilderProgram> {
39823982
/**
@@ -3986,7 +3986,7 @@ declare namespace ts {
39863986
/** If provided, callback to invoke after every new program creation */
39873987
afterProgramCreate?(program: T): void;
39883988
/** If provided, called with Diagnostic message that informs about change in watch status */
3989-
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string): void;
3989+
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void;
39903990
useCaseSensitiveFileNames(): boolean;
39913991
getNewLine(): string;
39923992
getCurrentDirectory(): string;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [unusedSemicolonInClass.ts]
2+
class Unused {
3+
;
4+
}
5+
6+
7+
//// [unusedSemicolonInClass.js]
8+
var Unused = /** @class */ (function () {
9+
function Unused() {
10+
}
11+
;
12+
return Unused;
13+
}());
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/unusedSemicolonInClass.ts ===
2+
class Unused {
3+
>Unused : Symbol(Unused, Decl(unusedSemicolonInClass.ts, 0, 0))
4+
5+
;
6+
}
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/unusedSemicolonInClass.ts ===
2+
class Unused {
3+
>Unused : Unused
4+
5+
;
6+
}
7+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @noUnusedLocals: true
2+
class Unused {
3+
;
4+
}

tests/cases/fourslash/completionsKeywordsExtends.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// <reference path="fourslash.ts" />
22

33
////class C/*a*/ /*b*/ { }
4+
////class C e/*c*/ {}
45

56
// Tests that `isCompletionListBlocker` is true *at* the class name, but false *after* it.
67

@@ -9,3 +10,6 @@ verify.completionListIsEmpty();
910

1011
goTo.marker("b");
1112
verify.completionListContains("extends");
13+
14+
goTo.marker("c");
15+
verify.completionListContains("extends");

0 commit comments

Comments
 (0)