Skip to content

Commit 8349396

Browse files
committed
Merge branch 'master' into fix_lookup_regression_again_and_again
2 parents 40470ad + 4510149 commit 8349396

File tree

43 files changed

+10990
-10428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+10990
-10428
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13076,6 +13076,14 @@ namespace ts {
1307613076
const paramCount = targetRestType ? Math.min(targetCount - 1, sourceCount) :
1307713077
sourceRestType ? targetCount :
1307813078
Math.min(sourceCount, targetCount);
13079+
13080+
const sourceThisType = getThisTypeOfSignature(source);
13081+
if (sourceThisType) {
13082+
const targetThisType = getThisTypeOfSignature(target);
13083+
if (targetThisType) {
13084+
callback(sourceThisType, targetThisType);
13085+
}
13086+
}
1307913087
for (let i = 0; i < paramCount; i++) {
1308013088
callback(getTypeAtPosition(source, i), getTypeAtPosition(target, i));
1308113089
}

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ namespace ts {
12721272
if (!left || !right) return false;
12731273
for (const key in left) {
12741274
if (hasOwnProperty.call(left, key)) {
1275-
if (!hasOwnProperty.call(right, key) === undefined) return false;
1275+
if (!hasOwnProperty.call(right, key)) return false;
12761276
if (!equalityComparer(left[key], right[key])) return false;
12771277
}
12781278
}

src/compiler/tsbuild.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ namespace ts {
507507
const configFileCache = createConfigFileCache(host);
508508
let context = createBuildContext(defaultOptions);
509509
let timerToBuildInvalidatedProject: any;
510+
let reportFileChangeDetected = false;
510511

511512
const existingWatchersForWildcards = createMap<WildcardDirectoryWatcher>();
512513
return {
@@ -584,7 +585,7 @@ namespace ts {
584585
}
585586

586587
function invalidateProjectAndScheduleBuilds(resolved: ResolvedConfigFileName) {
587-
reportWatchStatus(Diagnostics.File_change_detected_Starting_incremental_compilation);
588+
reportFileChangeDetected = true;
588589
invalidateProject(resolved);
589590
scheduleBuildInvalidatedProject();
590591
}
@@ -817,6 +818,10 @@ namespace ts {
817818

818819
function buildInvalidatedProject() {
819820
timerToBuildInvalidatedProject = undefined;
821+
if (reportFileChangeDetected) {
822+
reportFileChangeDetected = false;
823+
reportWatchStatus(Diagnostics.File_change_detected_Starting_incremental_compilation);
824+
}
820825
const buildProject = context.getNextInvalidatedProject();
821826
buildSomeProjects(p => p === buildProject);
822827
if (context.hasPendingInvalidatedProjects()) {

src/lib/es5.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,16 @@ type Extract<T, U> = T extends U ? T : never;
13781378
*/
13791379
type NonNullable<T> = T extends null | undefined ? never : T;
13801380

1381+
/**
1382+
* Obtain the parameters of a function type in a tuple
1383+
*/
1384+
type Parameters<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never;
1385+
1386+
/**
1387+
* Obtain the parameters of a constructor function type in a tuple
1388+
*/
1389+
type ConstructorParameters<T extends new (...args: any[]) => any> = T extends new (...args: infer P) => any ? P : never;
1390+
13811391
/**
13821392
* Obtain the return type of a function type
13831393
*/

src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl

Lines changed: 10138 additions & 10138 deletions
Large diffs are not rendered by default.

src/services/codefixes/convertToAsyncFunction.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,18 @@ namespace ts.codefix {
4242

4343
function convertToAsyncFunction(changes: textChanges.ChangeTracker, sourceFile: SourceFile, position: number, checker: TypeChecker, context: CodeFixContextBase): void {
4444
// get the function declaration - returns a promise
45-
const functionToConvert: FunctionLikeDeclaration = getContainingFunction(getTokenAtPosition(sourceFile, position)) as FunctionLikeDeclaration;
45+
const tokenAtPosition = getTokenAtPosition(sourceFile, position);
46+
let functionToConvert: FunctionLikeDeclaration | undefined;
47+
48+
// if the parent of a FunctionLikeDeclaration is a variable declaration, the convertToAsync diagnostic will be reported on the variable name
49+
if (isIdentifier(tokenAtPosition) && isVariableDeclaration(tokenAtPosition.parent) &&
50+
tokenAtPosition.parent.initializer && isFunctionLikeDeclaration(tokenAtPosition.parent.initializer)) {
51+
functionToConvert = tokenAtPosition.parent.initializer;
52+
}
53+
else {
54+
functionToConvert = tryCast(getContainingFunction(getTokenAtPosition(sourceFile, position)), isFunctionLikeDeclaration);
55+
}
56+
4657
if (!functionToConvert) {
4758
return;
4859
}

src/services/suggestionDiagnostics.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace ts {
33
export function computeSuggestionDiagnostics(sourceFile: SourceFile, program: Program, cancellationToken: CancellationToken): DiagnosticWithLocation[] {
44
program.getSemanticDiagnostics(sourceFile, cancellationToken);
55
const diags: DiagnosticWithLocation[] = [];
6-
const checker = program.getDiagnosticsProducingTypeChecker();
6+
const checker = program.getTypeChecker();
77

88
if (sourceFile.commonJsModuleIndicator &&
99
(programContainsEs6Modules(program) || compilerOptionsIndicateEs6Modules(program.getCompilerOptions())) &&
@@ -115,11 +115,12 @@ namespace ts {
115115

116116
function addConvertToAsyncFunctionDiagnostics(node: FunctionLikeDeclaration, checker: TypeChecker, diags: DiagnosticWithLocation[]): void {
117117

118-
const functionType = node.type ? checker.getTypeFromTypeNode(node.type) : undefined;
119-
if (isAsyncFunction(node) || !node.body || !functionType) {
118+
if (isAsyncFunction(node) || !node.body) {
120119
return;
121120
}
122121

122+
const functionType = checker.getTypeAtLocation(node);
123+
123124
const callSignatures = checker.getSignaturesOfType(functionType, SignatureKind.Call);
124125
const returnType = callSignatures.length ? checker.getReturnTypeOfSignature(callSignatures[0]) : undefined;
125126

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"unittests/cancellableLanguageServiceOperations.ts",
4747
"unittests/commandLineParsing.ts",
4848
"unittests/compileOnSave.ts",
49+
"unittests/compilerCore.ts",
4950
"unittests/configurationExtension.ts",
5051
"unittests/convertCompilerOptionsFromJson.ts",
5152
"unittests/convertToAsyncFunction.ts",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace ts {
2+
describe("compilerCore", () => {
3+
describe("equalOwnProperties", () => {
4+
it("correctly equates objects", () => {
5+
assert.isTrue(equalOwnProperties({}, {}));
6+
assert.isTrue(equalOwnProperties({ a: 1 }, { a: 1 }));
7+
assert.isTrue(equalOwnProperties({ a: 1, b: 2 }, { b: 2, a: 1 }));
8+
});
9+
it("correctly identifies unmatched objects", () => {
10+
assert.isFalse(equalOwnProperties({}, { a: 1 }), "missing left property");
11+
assert.isFalse(equalOwnProperties({ a: 1 }, {}), "missing right property");
12+
assert.isFalse(equalOwnProperties({ a: 1 }, { a: 2 }), "differing property");
13+
});
14+
it("correctly identifies undefined vs hasOwnProperty", () => {
15+
assert.isFalse(equalOwnProperties({}, { a: undefined }), "missing left property");
16+
assert.isFalse(equalOwnProperties({ a: undefined }, {}), "missing right property");
17+
});
18+
it("truthiness", () => {
19+
const trythyTest = (l: any, r: any) => !!l === !!r;
20+
assert.isFalse(equalOwnProperties({}, { a: 1 }, trythyTest), "missing left truthy property");
21+
assert.isFalse(equalOwnProperties({}, { a: 0 }, trythyTest), "missing left falsey property");
22+
assert.isFalse(equalOwnProperties({ a: 1 }, {}, trythyTest), "missing right truthy property");
23+
assert.isFalse(equalOwnProperties({ a: 0 }, {}, trythyTest), "missing right falsey property");
24+
assert.isTrue(equalOwnProperties({ a: 1 }, { a: "foo" }, trythyTest), "valid equality");
25+
});
26+
it("all equal", () => {
27+
assert.isFalse(equalOwnProperties({}, { a: 1 }, () => true), "missing left property");
28+
assert.isFalse(equalOwnProperties({ a: 1 }, {}, () => true), "missing right property");
29+
assert.isTrue(equalOwnProperties({ a: 1 }, { a: 2 }, () => true), "valid equality");
30+
});
31+
});
32+
});
33+
}

src/testRunner/unittests/convertToAsyncFunction.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ interface String { charAt: any; }
319319
interface Array<T> {}`
320320
};
321321

322-
function testConvertToAsyncFunction(caption: string, text: string, baselineFolder: string, description: DiagnosticMessage, includeLib?: boolean) {
322+
function testConvertToAsyncFunction(caption: string, text: string, baselineFolder: string, diagnosticDescription: DiagnosticMessage, codeFixDescription: DiagnosticMessage, includeLib?: boolean) {
323323
const t = getTest(text);
324324
const selectionRange = t.ranges.get("selection")!;
325325
if (!selectionRange) {
@@ -361,12 +361,14 @@ interface Array<T> {}`
361361
};
362362

363363
const diagnostics = languageService.getSuggestionDiagnostics(f.path);
364-
const diagnostic = find(diagnostics, diagnostic => diagnostic.messageText === description.message);
365-
assert.isNotNull(diagnostic);
364+
const diagnostic = find(diagnostics, diagnostic => diagnostic.messageText === diagnosticDescription.message);
365+
assert.exists(diagnostic);
366+
assert.equal(diagnostic!.start, context.span.start);
367+
assert.equal(diagnostic!.length, context.span.length);
366368

367369
const actions = codefix.getFixes(context);
368-
const action = find(actions, action => action.description === description.message)!;
369-
assert.isNotNull(action);
370+
const action = find(actions, action => action.description === codeFixDescription.message)!;
371+
assert.exists(action);
370372

371373
const data: string[] = [];
372374
data.push(`// ==ORIGINAL==`);
@@ -423,6 +425,10 @@ interface Array<T> {}`
423425
_testConvertToAsyncFunction("convertToAsyncFunction_basic", `
424426
function [#|f|](): Promise<void>{
425427
return fetch('https://typescriptlang.org').then(result => { console.log(result) });
428+
}`);
429+
_testConvertToAsyncFunction("convertToAsyncFunction_basicNoReturnTypeAnnotation", `
430+
function [#|f|]() {
431+
return fetch('https://typescriptlang.org').then(result => { console.log(result) });
426432
}`);
427433
_testConvertToAsyncFunction("convertToAsyncFunction_basicWithComments", `
428434
function [#|f|](): Promise<void>{
@@ -436,6 +442,10 @@ function [#|f|](): Promise<void>{
436442
_testConvertToAsyncFunction("convertToAsyncFunction_ArrowFunction", `
437443
[#|():Promise<void> => {|]
438444
return fetch('https://typescriptlang.org').then(result => console.log(result));
445+
}`);
446+
_testConvertToAsyncFunction("convertToAsyncFunction_ArrowFunctionNoAnnotation", `
447+
[#|() => {|]
448+
return fetch('https://typescriptlang.org').then(result => console.log(result));
439449
}`);
440450
_testConvertToAsyncFunction("convertToAsyncFunction_Catch", `
441451
function [#|f|]():Promise<void> {
@@ -1178,11 +1188,17 @@ function [#|f|]() {
11781188
}
11791189
`);
11801190

1191+
_testConvertToAsyncFunction("convertToAsyncFunction_simpleFunctionExpression", `
1192+
const [#|foo|] = function () {
1193+
return fetch('https://typescriptlang.org').then(result => { console.log(result) });
1194+
}
1195+
`);
1196+
11811197

11821198
});
11831199

11841200
function _testConvertToAsyncFunction(caption: string, text: string) {
1185-
testConvertToAsyncFunction(caption, text, "convertToAsyncFunction", Diagnostics.Convert_to_async_function, /*includeLib*/ true);
1201+
testConvertToAsyncFunction(caption, text, "convertToAsyncFunction", Diagnostics.This_may_be_converted_to_an_async_function, Diagnostics.Convert_to_async_function, /*includeLib*/ true);
11861202
}
11871203

11881204
function _testConvertToAsyncFunctionFailed(caption: string, text: string) {

0 commit comments

Comments
 (0)