Skip to content

Commit c93f919

Browse files
committed
Merge branch 'master' into infer-from-usage/similarity-to-builtins
2 parents d347b08 + 5d36aab commit c93f919

File tree

6 files changed

+52
-8
lines changed

6 files changed

+52
-8
lines changed

src/compiler/watch.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ namespace ts {
372372
errorCount => result.onWatchStatusChange!(
373373
createCompilerDiagnostic(getWatchErrorSummaryDiagnosticMessage(errorCount), errorCount),
374374
newLine,
375-
compilerOptions
375+
compilerOptions,
376+
errorCount
376377
)
377378
);
378379
};
@@ -480,14 +481,14 @@ namespace ts {
480481
return createProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences);
481482
}
482483

483-
export type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void;
484+
export type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number) => void;
484485
/** Create the program with rootNames and options, if they are undefined, oldProgram and new configFile diagnostics create new program */
485486
export type CreateProgram<T extends BuilderProgram> = (rootNames: ReadonlyArray<string> | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: T, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>, projectReferences?: ReadonlyArray<ProjectReference> | undefined) => T;
486487

487488
/** Host that has watch functionality used in --watch mode */
488489
export interface WatchHost {
489490
/** If provided, called with Diagnostic message that informs about change in watch status */
490-
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void;
491+
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number): void;
491492

492493
/** Used to watch changes in source files, missing files needed to update the program or config file */
493494
watchFile(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher;

src/services/goToDefinition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ namespace ts.GoToDefinition {
241241
function getConstructSignatureDefinition(): DefinitionInfo[] | undefined {
242242
// Applicable only if we are in a new expression, or we are on a constructor declaration
243243
// and in either case the symbol has a construct signature definition, i.e. class
244-
if (symbol.flags & SymbolFlags.Class && (isNewExpressionTarget(node) || node.kind === SyntaxKind.ConstructorKeyword)) {
244+
if (symbol.flags & SymbolFlags.Class && !(symbol.flags & SymbolFlags.Function) && (isNewExpressionTarget(node) || node.kind === SyntaxKind.ConstructorKeyword)) {
245245
const cls = find(filteredDeclarations, isClassLike) || Debug.fail("Expected declaration to have at least one class-like declaration");
246246
return getSignatureDefinition(cls.members, /*selectConstructors*/ true);
247247
}

src/testRunner/unittests/tscWatch/watchApi.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,32 @@ namespace ts.tscWatch {
3737
checkProgramActualFiles(program, [mainFile.path, libFile.path, settingsJson.path]);
3838
});
3939
});
40+
41+
describe("unittests:: tsc-watch:: watchAPI:: tsc-watch expose error count to watch status reporter", () => {
42+
const projectRoot = "/user/username/projects/project";
43+
const configFileJson: any = {
44+
compilerOptions: { module: "commonjs" },
45+
files: ["index.ts"]
46+
};
47+
const config: File = {
48+
path: `${projectRoot}/tsconfig.json`,
49+
content: JSON.stringify(configFileJson)
50+
};
51+
const mainFile: File = {
52+
path: `${projectRoot}/index.ts`,
53+
content: "let compiler = new Compiler(); for (let i = 0; j < 5; i++) {}"
54+
};
55+
56+
it("verify that the error count is correctly passed down to the watch status reporter", () => {
57+
const files = [libFile, mainFile, config];
58+
const host = createWatchedSystem(files, { currentDirectory: projectRoot });
59+
let watchedErrorCount;
60+
const reportWatchStatus: WatchStatusReporter = (_, __, ___, errorCount) => {
61+
watchedErrorCount = errorCount;
62+
};
63+
const compilerHost = createWatchCompilerHostOfConfigFile(config.path, {}, host, /*createProgram*/ undefined, /*reportDiagnostic*/ undefined, reportWatchStatus);
64+
createWatchProgram(compilerHost);
65+
assert.equal(watchedErrorCount, 2, "The error count was expected to be 2 for the file change");
66+
});
67+
});
4068
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4491,13 +4491,13 @@ declare namespace ts {
44914491
createProgram?: CreateProgram<T>;
44924492
}
44934493
function createIncrementalProgram<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>({ rootNames, options, configFileParsingDiagnostics, projectReferences, host, createProgram }: IncrementalProgramOptions<T>): T;
4494-
type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void;
4494+
type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number) => void;
44954495
/** Create the program with rootNames and options, if they are undefined, oldProgram and new configFile diagnostics create new program */
44964496
type CreateProgram<T extends BuilderProgram> = (rootNames: ReadonlyArray<string> | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: T, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>, projectReferences?: ReadonlyArray<ProjectReference> | undefined) => T;
44974497
/** Host that has watch functionality used in --watch mode */
44984498
interface WatchHost {
44994499
/** If provided, called with Diagnostic message that informs about change in watch status */
4500-
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void;
4500+
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number): void;
45014501
/** Used to watch changes in source files, missing files needed to update the program or config file */
45024502
watchFile(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher;
45034503
/** Used to watch resolved module's failed lookup locations, config file specs, type roots where auto type reference directives are added */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4491,13 +4491,13 @@ declare namespace ts {
44914491
createProgram?: CreateProgram<T>;
44924492
}
44934493
function createIncrementalProgram<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>({ rootNames, options, configFileParsingDiagnostics, projectReferences, host, createProgram }: IncrementalProgramOptions<T>): T;
4494-
type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void;
4494+
type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number) => void;
44954495
/** Create the program with rootNames and options, if they are undefined, oldProgram and new configFile diagnostics create new program */
44964496
type CreateProgram<T extends BuilderProgram> = (rootNames: ReadonlyArray<string> | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: T, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>, projectReferences?: ReadonlyArray<ProjectReference> | undefined) => T;
44974497
/** Host that has watch functionality used in --watch mode */
44984498
interface WatchHost {
44994499
/** If provided, called with Diagnostic message that informs about change in watch status */
4500-
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void;
4500+
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number): void;
45014501
/** Used to watch changes in source files, missing files needed to update the program or config file */
45024502
watchFile(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher;
45034503
/** Used to watch resolved module's failed lookup locations, config file specs, type roots where auto type reference directives are added */
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="fourslash.ts" />
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @noEmit: true
5+
// @filename: gotoDefinitionConstructorFunction.js
6+
//// function /*end*/StringStreamm() {
7+
//// }
8+
//// StringStreamm.prototype = {
9+
//// };
10+
////
11+
//// function runMode () {
12+
//// new [|/*start*/StringStreamm|]()
13+
//// };
14+
15+
verify.goToDefinition('start', 'end')

0 commit comments

Comments
 (0)