@@ -5111,7 +5111,7 @@ namespace ts {
51115111 * to "this" in its body, if all base types are interfaces,
51125112 * and if none of the base interfaces have a "this" type.
51135113 */
5114- function isInterfaceFreeOfThisReference (symbol: Symbol): boolean {
5114+ function isThislessInterface (symbol: Symbol): boolean {
51155115 for (const declaration of symbol.declarations) {
51165116 if (declaration.kind === SyntaxKind.InterfaceDeclaration) {
51175117 if (declaration.flags & NodeFlags.ContainsThis) {
@@ -5145,7 +5145,7 @@ namespace ts {
51455145 // property types inferred from initializers and method return types inferred from return statements are very hard
51465146 // to exhaustively analyze). We give interfaces a "this" type if we can't definitely determine that they are free of
51475147 // "this" references.
5148- if (outerTypeParameters || localTypeParameters || kind === ObjectFlags.Class || !isInterfaceFreeOfThisReference (symbol)) {
5148+ if (outerTypeParameters || localTypeParameters || kind === ObjectFlags.Class || !isThislessInterface (symbol)) {
51495149 type.objectFlags |= ObjectFlags.Reference;
51505150 type.typeParameters = concatenate(outerTypeParameters, localTypeParameters);
51515151 type.outerTypeParameters = outerTypeParameters;
@@ -5327,17 +5327,12 @@ namespace ts {
53275327 return undefined;
53285328 }
53295329
5330- /** A type reference is free of this references if each type argument is free of this references. */
5331- function isTypeReferenceFreeOfThisReference(node: TypeReferenceNode): boolean {
5332- return !node.typeArguments || node.typeArguments.every(isTypeFreeOfThisReference);
5333- }
5334-
53355330 /**
53365331 * A type is free of this references if it's the any, string, number, boolean, symbol, or void keyword, a string
53375332 * literal type, an array with an element type that is free of this references, or a type reference that is
53385333 * free of this references.
53395334 */
5340- function isTypeFreeOfThisReference (node: TypeNode): boolean {
5335+ function isThislessType (node: TypeNode): boolean {
53415336 switch (node.kind) {
53425337 case SyntaxKind.AnyKeyword:
53435338 case SyntaxKind.StringKeyword:
@@ -5352,37 +5347,37 @@ namespace ts {
53525347 case SyntaxKind.LiteralType:
53535348 return true;
53545349 case SyntaxKind.ArrayType:
5355- return isTypeFreeOfThisReference ((<ArrayTypeNode>node).elementType);
5350+ return isThislessType ((<ArrayTypeNode>node).elementType);
53565351 case SyntaxKind.TypeReference:
5357- return isTypeReferenceFreeOfThisReference(< TypeReferenceNode> node);
5352+ return !(node as TypeReferenceNode).typeArguments || ( node as TypeReferenceNode).typeArguments.every(isThislessType );
53585353 }
53595354 return false;
53605355 }
53615356
5362- /** A type parameter is this-free if its contraint is this-free , or if it has no constraint. */
5363- function isTypeParameterFreeOfThisReference (node: TypeParameterDeclaration) {
5364- return !node.constraint || isTypeFreeOfThisReference (node.constraint);
5357+ /** A type parameter is thisless if its contraint is thisless , or if it has no constraint. */
5358+ function isThislessTypeParameter (node: TypeParameterDeclaration) {
5359+ return !node.constraint || isThislessType (node.constraint);
53655360 }
53665361
53675362 /**
53685363 * A variable-like declaration is free of this references if it has a type annotation
5369- * that is this-free , or if it has no type annotation and no initializer (and is thus of type any).
5364+ * that is thisless , or if it has no type annotation and no initializer (and is thus of type any).
53705365 */
5371- function isVariableLikeDeclarationFreeOfThisReference (node: VariableLikeDeclaration): boolean {
5366+ function isThislessVariableLikeDeclaration (node: VariableLikeDeclaration): boolean {
53725367 const typeNode = getEffectiveTypeAnnotationNode(node);
5373- return typeNode ? isTypeFreeOfThisReference (typeNode) : !node.initializer;
5368+ return typeNode ? isThislessType (typeNode) : !node.initializer;
53745369 }
53755370
53765371 /**
53775372 * A function-like declaration is considered free of `this` references if it has a return type
5378- * annotation that is free of this references and if each parameter is this-free and if
5379- * each type parameter (if present) is this-free .
5373+ * annotation that is free of this references and if each parameter is thisless and if
5374+ * each type parameter (if present) is thisless .
53805375 */
5381- function isFunctionLikeDeclarationFreeOfThisReference (node: FunctionLikeDeclaration): boolean {
5376+ function isThislessFunctionLikeDeclaration (node: FunctionLikeDeclaration): boolean {
53825377 const returnType = getEffectiveReturnTypeNode(node);
5383- return (node.kind === SyntaxKind.Constructor || (returnType && isTypeFreeOfThisReference (returnType))) &&
5384- node.parameters.every(isVariableLikeDeclarationFreeOfThisReference ) &&
5385- (!node.typeParameters || node.typeParameters.every(isTypeParameterFreeOfThisReference ));
5378+ return (node.kind === SyntaxKind.Constructor || (returnType && isThislessType (returnType))) &&
5379+ node.parameters.every(isThislessVariableLikeDeclaration ) &&
5380+ (!node.typeParameters || node.typeParameters.every(isThislessTypeParameter ));
53865381 }
53875382
53885383 /**
@@ -5392,18 +5387,18 @@ namespace ts {
53925387 * inferred from their initializers and function members with inferred return types are conservatively
53935388 * assumed not to be free of "this" references.
53945389 */
5395- function isFreeOfThisReference (symbol: Symbol): boolean {
5390+ function isThisless (symbol: Symbol): boolean {
53965391 if (symbol.declarations && symbol.declarations.length === 1) {
53975392 const declaration = symbol.declarations[0];
53985393 if (declaration) {
53995394 switch (declaration.kind) {
54005395 case SyntaxKind.PropertyDeclaration:
54015396 case SyntaxKind.PropertySignature:
5402- return isVariableLikeDeclarationFreeOfThisReference (<VariableLikeDeclaration>declaration);
5397+ return isThislessVariableLikeDeclaration (<VariableLikeDeclaration>declaration);
54035398 case SyntaxKind.MethodDeclaration:
54045399 case SyntaxKind.MethodSignature:
54055400 case SyntaxKind.Constructor:
5406- return isFunctionLikeDeclarationFreeOfThisReference (<FunctionLikeDeclaration>declaration);
5401+ return isThislessFunctionLikeDeclaration (<FunctionLikeDeclaration>declaration);
54075402 }
54085403 }
54095404 }
@@ -5415,7 +5410,7 @@ namespace ts {
54155410 function createInstantiatedSymbolTable(symbols: Symbol[], mapper: TypeMapper, mappingThisOnly: boolean): SymbolTable {
54165411 const result = createSymbolTable();
54175412 for (const symbol of symbols) {
5418- result.set(symbol.escapedName, mappingThisOnly && isFreeOfThisReference (symbol) ? symbol : instantiateSymbol(symbol, mapper));
5413+ result.set(symbol.escapedName, mappingThisOnly && isThisless (symbol) ? symbol : instantiateSymbol(symbol, mapper));
54195414 }
54205415 return result;
54215416 }
0 commit comments