Skip to content

Commit e2bbc3e

Browse files
committed
Merge branch 'master' into vfs
2 parents 3de9630 + 1fb3593 commit e2bbc3e

13 files changed

Lines changed: 121 additions & 53 deletions

File tree

src/compiler/checker.ts

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

@@ -26601,7 +26599,7 @@ namespace ts {
2660126599
switch (name.parent.kind) {
2660226600
case SyntaxKind.ImportSpecifier:
2660326601
case SyntaxKind.ExportSpecifier:
26604-
return true;
26602+
return isIdentifier(name);
2660526603
default:
2660626604
return isDeclarationName(name);
2660726605
}

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/fourslash.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,6 +2863,15 @@ Actual: ${stringify(fullActual)}`);
28632863
}
28642864
}
28652865

2866+
public verifyNoDocumentHighlights(startRange: Range) {
2867+
this.goToRangeStart(startRange);
2868+
const documentHighlights = this.getDocumentHighlightsAtCurrentPosition([this.activeFile.fileName]);
2869+
const numHighlights = ts.length(documentHighlights);
2870+
if (numHighlights > 0) {
2871+
this.raiseError(`verifyNoDocumentHighlights failed - unexpectedly got ${numHighlights} highlights`);
2872+
}
2873+
}
2874+
28662875
private verifyDocumentHighlights(expectedRanges: Range[], fileNames: string[] = [this.activeFile.fileName]) {
28672876
const documentHighlights = this.getDocumentHighlightsAtCurrentPosition(fileNames) || [];
28682877

@@ -4271,6 +4280,10 @@ namespace FourSlashInterface {
42714280
this.state.verifyDocumentHighlightsOf(startRange, ranges);
42724281
}
42734282

4283+
public noDocumentHighlights(startRange: FourSlash.Range) {
4284+
this.state.verifyNoDocumentHighlights(startRange);
4285+
}
4286+
42744287
public completionEntryDetailIs(entryName: string, text: string, documentation?: string, kind?: string, tags?: ts.JSDocTagInfo[]) {
42754288
this.state.verifyCompletionEntryDetails(entryName, text, documentation, kind, tags);
42764289
}

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/projectErrors.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ namespace ts.projectSystem {
6363
// both files exist - expect no errors
6464
checkNumberOfProjects(projectService, { externalProjects: 1 });
6565
const diags3 = sendCompilerOptionsDiagnosticsRequest(session, { projectFileName }, /*seq*/ 2);
66-
console.log(diags3);
6766
checkDiagnosticsWithLinePos(diags3, []);
6867
});
6968

src/harness/unittests/tscWatchMode.ts

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,29 @@ namespace ts.tscWatch {
766766
// This should be 0
767767
host.checkTimeoutQueueLengthAndRun(0);
768768
});
769+
770+
it("shouldnt report error about unused function incorrectly when file changes from global to module", () => {
771+
const getFileContent = (asModule: boolean) => `
772+
function one() {}
773+
${asModule ? "export " : ""}function two() {
774+
return function three() {
775+
one();
776+
}
777+
}`;
778+
const host = new fakes.FakeServerHost({ lib: true }, /*files*/ {
779+
"/a/b/file.ts": getFileContent(/*asModule*/ false)
780+
});
781+
const watch = createWatchOfFilesAndCompilerOptions(["/a/b/file.ts"], host, {
782+
noUnusedLocals: true
783+
});
784+
checkProgramActualFiles(watch(), ["/a/b/file.ts", fakes.FakeServerHost.libPath]);
785+
checkOutputErrors(host, [], ExpectedOutputErrorsPosition.AfterCompilationStarting);
786+
787+
host.writeFile("/a/b/file.ts", getFileContent(/*asModule*/ true));
788+
host.runQueuedTimeoutCallbacks();
789+
checkProgramActualFiles(watch(), ["/a/b/file.ts", fakes.FakeServerHost.libPath]);
790+
checkOutputErrors(host, [], ExpectedOutputErrorsPosition.AfterFileChangeDetected);
791+
});
769792
});
770793

771794
describe("emit once", () => {
@@ -1525,30 +1548,44 @@ namespace ts.tscWatch {
15251548
.revoke();
15261549
});
15271550
});
1528-
});
15291551

1530-
describe("tsc-watch console clearing", () => {
1531-
it("clears the console when it starts", () => {
1532-
const host = new fakes.FakeServerHost({ lib: true }, /*files*/ {
1533-
"/a/f.ts": "",
1534-
});
1552+
describe("console clearing", () => {
1553+
function checkConsoleClearing(diagnostics: boolean, extendedDiagnostics: boolean) {
1554+
const host = new fakes.FakeServerHost({ lib: true }, /*files*/ {
1555+
"/a/f.ts": ""
1556+
});
1557+
let clearCount: number | undefined;
1558+
checkConsoleClears();
15351559

1536-
createWatchOfFilesAndCompilerOptions(["/a/f.ts"], host);
1537-
host.runQueuedTimeoutCallbacks();
1560+
createWatchOfFilesAndCompilerOptions(["/a/f.ts"], host, { diagnostics, extendedDiagnostics });
1561+
checkConsoleClears();
15381562

1539-
host.checkScreenClears(1);
1540-
});
1563+
host.writeFile("/a/f.ts", "//");
1564+
host.runQueuedTimeoutCallbacks();
15411565

1542-
it("clears the console on recompile", () => {
1543-
const host = new fakes.FakeServerHost({ lib: true }, /*files*/ {
1544-
"/a/f.ts": "",
1545-
});
1546-
createWatchOfFilesAndCompilerOptions(["/a/f.ts"], host);
1566+
checkConsoleClears();
15471567

1548-
host.vfs.writeFileSync("/a/f.ts", "//");
1549-
host.runQueuedTimeoutCallbacks();
1568+
function checkConsoleClears() {
1569+
if (clearCount === undefined) {
1570+
clearCount = 0;
1571+
}
1572+
else if (!diagnostics && !extendedDiagnostics) {
1573+
clearCount++;
1574+
}
1575+
host.checkScreenClears(clearCount);
1576+
return clearCount;
1577+
}
1578+
}
15501579

1551-
host.checkScreenClears(2);
1580+
it("without --diagnostics or --extendedDiagnostics", () => {
1581+
checkConsoleClearing(/*diagnostics*/ false, /*extendedDiagnostics*/ false);
1582+
});
1583+
it("with --diagnostics", () => {
1584+
checkConsoleClearing(/*diagnostics*/ true, /*extendedDiagnostics*/ false);
1585+
});
1586+
it("with --extendedDiagnostics", () => {
1587+
checkConsoleClearing(/*diagnostics*/ false, /*extendedDiagnostics*/ true);
1588+
});
15521589
});
15531590
});
15541591
}

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
@@ -3978,7 +3978,7 @@ declare namespace ts {
39783978
}
39793979
declare namespace ts {
39803980
type DiagnosticReporter = (diagnostic: Diagnostic) => void;
3981-
type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string) => void;
3981+
type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void;
39823982
type CreateProgram<T extends BuilderProgram> = (rootNames: ReadonlyArray<string>, options: CompilerOptions, host?: CompilerHost, oldProgram?: T) => T;
39833983
interface WatchCompilerHost<T extends BuilderProgram> {
39843984
/**
@@ -3988,7 +3988,7 @@ declare namespace ts {
39883988
/** If provided, callback to invoke after every new program creation */
39893989
afterProgramCreate?(program: T): void;
39903990
/** If provided, called with Diagnostic message that informs about change in watch status */
3991-
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string): void;
3991+
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void;
39923992
useCaseSensitiveFileNames(): boolean;
39933993
getNewLine(): string;
39943994
getCurrentDirectory(): string;

0 commit comments

Comments
 (0)