mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 11:35:42 -06:00
Merge branch 'master' into vfs
This commit is contained in:
commit
e2bbc3ee57
@ -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;
|
||||
}
|
||||
|
||||
@ -26601,7 +26599,7 @@ namespace ts {
|
||||
switch (name.parent.kind) {
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
return true;
|
||||
return isIdentifier(name);
|
||||
default:
|
||||
return isDeclarationName(name);
|
||||
}
|
||||
|
||||
@ -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");
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -31,8 +31,11 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
|
||||
function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic) {
|
||||
if (system.clearScreen && diagnostic.code !== Diagnostics.Compilation_complete_Watching_for_file_changes.code) {
|
||||
function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic, options: CompilerOptions) {
|
||||
if (system.clearScreen &&
|
||||
diagnostic.code !== Diagnostics.Compilation_complete_Watching_for_file_changes.code &&
|
||||
!options.extendedDiagnostics &&
|
||||
!options.diagnostics) {
|
||||
system.clearScreen();
|
||||
}
|
||||
}
|
||||
@ -42,18 +45,18 @@ namespace ts {
|
||||
*/
|
||||
export function createWatchStatusReporter(system: System, pretty?: boolean): WatchStatusReporter {
|
||||
return pretty ?
|
||||
(diagnostic: Diagnostic, newLine: string) => {
|
||||
clearScreenIfNotWatchingForFileChanges(system, diagnostic);
|
||||
let output = `[${ formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey) }] `;
|
||||
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`;
|
||||
system.write(output);
|
||||
} :
|
||||
(diagnostic: Diagnostic, newLine: string) => {
|
||||
clearScreenIfNotWatchingForFileChanges(system, diagnostic);
|
||||
let output = new Date().toLocaleTimeString() + " - ";
|
||||
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`;
|
||||
system.write(output);
|
||||
};
|
||||
(diagnostic, newLine, options) => {
|
||||
clearScreenIfNotWatchingForFileChanges(system, diagnostic, options);
|
||||
let output = `[${formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey)}] `;
|
||||
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`;
|
||||
system.write(output);
|
||||
} :
|
||||
(diagnostic, newLine, options) => {
|
||||
clearScreenIfNotWatchingForFileChanges(system, diagnostic, options);
|
||||
let output = new Date().toLocaleTimeString() + " - ";
|
||||
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`;
|
||||
system.write(output);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -254,7 +257,7 @@ namespace ts {
|
||||
|
||||
namespace ts {
|
||||
export type DiagnosticReporter = (diagnostic: Diagnostic) => void;
|
||||
export type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string) => void;
|
||||
export type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void;
|
||||
export type CreateProgram<T extends BuilderProgram> = (rootNames: ReadonlyArray<string>, options: CompilerOptions, host?: CompilerHost, oldProgram?: T) => T;
|
||||
export interface WatchCompilerHost<T extends BuilderProgram> {
|
||||
/**
|
||||
@ -264,7 +267,7 @@ namespace ts {
|
||||
/** If provided, callback to invoke after every new program creation */
|
||||
afterProgramCreate?(program: T): void;
|
||||
/** If provided, called with Diagnostic message that informs about change in watch status */
|
||||
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string): void;
|
||||
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void;
|
||||
|
||||
// Only for testing
|
||||
/*@internal*/
|
||||
@ -725,7 +728,7 @@ namespace ts {
|
||||
|
||||
function reportWatchDiagnostic(message: DiagnosticMessage) {
|
||||
if (host.onWatchStatusChange) {
|
||||
host.onWatchStatusChange(createCompilerDiagnostic(message), newLine);
|
||||
host.onWatchStatusChange(createCompilerDiagnostic(message), newLine, compilerOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2863,6 +2863,15 @@ Actual: ${stringify(fullActual)}`);
|
||||
}
|
||||
}
|
||||
|
||||
public verifyNoDocumentHighlights(startRange: Range) {
|
||||
this.goToRangeStart(startRange);
|
||||
const documentHighlights = this.getDocumentHighlightsAtCurrentPosition([this.activeFile.fileName]);
|
||||
const numHighlights = ts.length(documentHighlights);
|
||||
if (numHighlights > 0) {
|
||||
this.raiseError(`verifyNoDocumentHighlights failed - unexpectedly got ${numHighlights} highlights`);
|
||||
}
|
||||
}
|
||||
|
||||
private verifyDocumentHighlights(expectedRanges: Range[], fileNames: string[] = [this.activeFile.fileName]) {
|
||||
const documentHighlights = this.getDocumentHighlightsAtCurrentPosition(fileNames) || [];
|
||||
|
||||
@ -4271,6 +4280,10 @@ namespace FourSlashInterface {
|
||||
this.state.verifyDocumentHighlightsOf(startRange, ranges);
|
||||
}
|
||||
|
||||
public noDocumentHighlights(startRange: FourSlash.Range) {
|
||||
this.state.verifyNoDocumentHighlights(startRange);
|
||||
}
|
||||
|
||||
public completionEntryDetailIs(entryName: string, text: string, documentation?: string, kind?: string, tags?: ts.JSDocTagInfo[]) {
|
||||
this.state.verifyCompletionEntryDetails(entryName, text, documentation, kind, tags);
|
||||
}
|
||||
|
||||
@ -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"]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -63,7 +63,6 @@ namespace ts.projectSystem {
|
||||
// both files exist - expect no errors
|
||||
checkNumberOfProjects(projectService, { externalProjects: 1 });
|
||||
const diags3 = sendCompilerOptionsDiagnosticsRequest(session, { projectFileName }, /*seq*/ 2);
|
||||
console.log(diags3);
|
||||
checkDiagnosticsWithLinePos(diags3, []);
|
||||
});
|
||||
|
||||
|
||||
@ -766,6 +766,29 @@ 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 host = new fakes.FakeServerHost({ lib: true }, /*files*/ {
|
||||
"/a/b/file.ts": getFileContent(/*asModule*/ false)
|
||||
});
|
||||
const watch = createWatchOfFilesAndCompilerOptions(["/a/b/file.ts"], host, {
|
||||
noUnusedLocals: true
|
||||
});
|
||||
checkProgramActualFiles(watch(), ["/a/b/file.ts", fakes.FakeServerHost.libPath]);
|
||||
checkOutputErrors(host, [], ExpectedOutputErrorsPosition.AfterCompilationStarting);
|
||||
|
||||
host.writeFile("/a/b/file.ts", getFileContent(/*asModule*/ true));
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
checkProgramActualFiles(watch(), ["/a/b/file.ts", fakes.FakeServerHost.libPath]);
|
||||
checkOutputErrors(host, [], ExpectedOutputErrorsPosition.AfterFileChangeDetected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("emit once", () => {
|
||||
@ -1525,30 +1548,44 @@ namespace ts.tscWatch {
|
||||
.revoke();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("tsc-watch console clearing", () => {
|
||||
it("clears the console when it starts", () => {
|
||||
const host = new fakes.FakeServerHost({ lib: true }, /*files*/ {
|
||||
"/a/f.ts": "",
|
||||
describe("console clearing", () => {
|
||||
function checkConsoleClearing(diagnostics: boolean, extendedDiagnostics: boolean) {
|
||||
const host = new fakes.FakeServerHost({ lib: true }, /*files*/ {
|
||||
"/a/f.ts": ""
|
||||
});
|
||||
let clearCount: number | undefined;
|
||||
checkConsoleClears();
|
||||
|
||||
createWatchOfFilesAndCompilerOptions(["/a/f.ts"], host, { diagnostics, extendedDiagnostics });
|
||||
checkConsoleClears();
|
||||
|
||||
host.writeFile("/a/f.ts", "//");
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
|
||||
checkConsoleClears();
|
||||
|
||||
function checkConsoleClears() {
|
||||
if (clearCount === undefined) {
|
||||
clearCount = 0;
|
||||
}
|
||||
else if (!diagnostics && !extendedDiagnostics) {
|
||||
clearCount++;
|
||||
}
|
||||
host.checkScreenClears(clearCount);
|
||||
return clearCount;
|
||||
}
|
||||
}
|
||||
|
||||
it("without --diagnostics or --extendedDiagnostics", () => {
|
||||
checkConsoleClearing(/*diagnostics*/ false, /*extendedDiagnostics*/ false);
|
||||
});
|
||||
|
||||
createWatchOfFilesAndCompilerOptions(["/a/f.ts"], host);
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
|
||||
host.checkScreenClears(1);
|
||||
});
|
||||
|
||||
it("clears the console on recompile", () => {
|
||||
const host = new fakes.FakeServerHost({ lib: true }, /*files*/ {
|
||||
"/a/f.ts": "",
|
||||
it("with --diagnostics", () => {
|
||||
checkConsoleClearing(/*diagnostics*/ true, /*extendedDiagnostics*/ false);
|
||||
});
|
||||
it("with --extendedDiagnostics", () => {
|
||||
checkConsoleClearing(/*diagnostics*/ false, /*extendedDiagnostics*/ true);
|
||||
});
|
||||
createWatchOfFilesAndCompilerOptions(["/a/f.ts"], host);
|
||||
|
||||
host.vfs.writeFileSync("/a/f.ts", "//");
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
|
||||
host.checkScreenClears(2);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -1921,7 +1921,8 @@ namespace ts.Completions {
|
||||
return isDeclarationName(contextToken)
|
||||
&& !isJsxAttribute(contextToken.parent)
|
||||
// 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`.
|
||||
&& !(isClassLike(contextToken.parent) && position > previousToken.end);
|
||||
// If `contextToken !== previousToken`, this is `class C ex/**/`.
|
||||
&& !(isClassLike(contextToken.parent) && (contextToken !== previousToken || position > previousToken.end));
|
||||
}
|
||||
|
||||
function isFunctionLikeButNotConstructor(kind: SyntaxKind) {
|
||||
|
||||
@ -3978,7 +3978,7 @@ declare namespace ts {
|
||||
}
|
||||
declare namespace ts {
|
||||
type DiagnosticReporter = (diagnostic: Diagnostic) => void;
|
||||
type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string) => void;
|
||||
type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void;
|
||||
type CreateProgram<T extends BuilderProgram> = (rootNames: ReadonlyArray<string>, options: CompilerOptions, host?: CompilerHost, oldProgram?: T) => T;
|
||||
interface WatchCompilerHost<T extends BuilderProgram> {
|
||||
/**
|
||||
@ -3988,7 +3988,7 @@ declare namespace ts {
|
||||
/** If provided, callback to invoke after every new program creation */
|
||||
afterProgramCreate?(program: T): void;
|
||||
/** If provided, called with Diagnostic message that informs about change in watch status */
|
||||
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string): void;
|
||||
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void;
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
getNewLine(): string;
|
||||
getCurrentDirectory(): string;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////class C/*a*/ /*b*/ { }
|
||||
////class C e/*c*/ {}
|
||||
|
||||
// Tests that `isCompletionListBlocker` is true *at* the class name, but false *after* it.
|
||||
|
||||
@ -9,3 +10,6 @@ verify.completionListIsEmpty();
|
||||
|
||||
goTo.marker("b");
|
||||
verify.completionListContains("extends");
|
||||
|
||||
goTo.marker("c");
|
||||
verify.completionListContains("extends");
|
||||
|
||||
10
tests/cases/fourslash/documentHighlightInExport1.ts
Normal file
10
tests/cases/fourslash/documentHighlightInExport1.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
//// class [|C|] {}
|
||||
//// [|export|] { [|C|] [|as|] [|D|] };
|
||||
|
||||
const [classRange, exportKeywordRange, propertyNameRange, asKeywordRange, nameRange] = test.ranges();
|
||||
verify.noDocumentHighlights(exportKeywordRange);
|
||||
verify.documentHighlightsOf(propertyNameRange, [classRange, propertyNameRange, nameRange]);
|
||||
verify.noDocumentHighlights(asKeywordRange);
|
||||
verify.documentHighlightsOf(nameRange, [nameRange]);
|
||||
10
tests/cases/fourslash/findAllRefsInExport1.ts
Normal file
10
tests/cases/fourslash/findAllRefsInExport1.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
//// class C {}
|
||||
//// /*1*/export { C /*2*/as D };
|
||||
|
||||
goTo.marker("1");
|
||||
verify.noReferences();
|
||||
|
||||
goTo.marker("2");
|
||||
verify.noReferences();
|
||||
Loading…
x
Reference in New Issue
Block a user