From 90667e104df18bce0e0457d90393b54f2b9a9730 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 13 May 2019 12:42:33 -0700 Subject: [PATCH 1/3] Remove this-parameter filtering in statement completion --- src/compiler/checker.ts | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 64834befee1c8..b730f382db3dd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20386,25 +20386,7 @@ namespace ts { } function isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode | QualifiedName, type: Type, property: Symbol): boolean { - return isValidPropertyAccessWithType(node, node.kind === SyntaxKind.PropertyAccessExpression && node.expression.kind === SyntaxKind.SuperKeyword, property.escapedName, type) - && (!(property.flags & SymbolFlags.Method) || isValidMethodAccess(property, type)); - } - function isValidMethodAccess(method: Symbol, actualThisType: Type): boolean { - const propType = getTypeOfPropertyOfType(actualThisType, method.escapedName)!; - const signatures = getSignaturesOfType(getNonNullableType(propType), SignatureKind.Call); - Debug.assert(signatures.length !== 0); - return signatures.some(sig => { - const signatureThisType = getThisTypeOfSignature(sig); - return !signatureThisType || isTypeAssignableTo(actualThisType, getInstantiatedSignatureThisType(sig, signatureThisType, actualThisType)); - }); - } - function getInstantiatedSignatureThisType(sig: Signature, signatureThisType: Type, actualThisType: Type): Type { - if (!sig.typeParameters) { - return signatureThisType; - } - const context = createInferenceContext(sig.typeParameters, sig, InferenceFlags.None); - inferTypes(context.inferences, actualThisType, signatureThisType); - return instantiateType(signatureThisType, createSignatureTypeMapper(sig, getInferredTypes(context))); + return isValidPropertyAccessWithType(node, node.kind === SyntaxKind.PropertyAccessExpression && node.expression.kind === SyntaxKind.SuperKeyword, property.escapedName, type); } function isValidPropertyAccessWithType( From a65f35b5fb4c1bc0d56724258a051b7e6f85bfce Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 13 May 2019 12:42:44 -0700 Subject: [PATCH 2/3] Remove fourslash test --- .../completionsMethodWithThisParameter.ts | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 tests/cases/fourslash/completionsMethodWithThisParameter.ts diff --git a/tests/cases/fourslash/completionsMethodWithThisParameter.ts b/tests/cases/fourslash/completionsMethodWithThisParameter.ts deleted file mode 100644 index d746f3626dc08..0000000000000 --- a/tests/cases/fourslash/completionsMethodWithThisParameter.ts +++ /dev/null @@ -1,20 +0,0 @@ -/// - -////class A { -//// value: T; // Make the type parameter actually matter -//// ms(this: A) {} -//// mo(this: A<{}>) {} -//// mt(this: A) {} -//// mp

(this: A

) {} -//// mps

(this: A

) {} -////} -//// -////const s = new A(); -////const n = new A(); -////s./*s*/; -////n./*n*/; - -verify.completions( - { marker: "s", exact: ["value", "ms", "mo", "mt", "mp", "mps"] }, - { marker: "n", exact: ["value", "mo", "mt", "mp"] }, -); From d2923460e967d9bd58057ce1570e24e62c08c62b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 13 May 2019 16:34:09 -0700 Subject: [PATCH 3/3] Add comment providing context on the change --- src/compiler/checker.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b730f382db3dd..cdd873cd0bc0f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20387,6 +20387,7 @@ namespace ts { function isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode | QualifiedName, type: Type, property: Symbol): boolean { return isValidPropertyAccessWithType(node, node.kind === SyntaxKind.PropertyAccessExpression && node.expression.kind === SyntaxKind.SuperKeyword, property.escapedName, type); + // Previously we validated the 'this' type of methods but this adversely affected performance. See #31377 for more context. } function isValidPropertyAccessWithType(