@@ -7943,18 +7943,6 @@ namespace ts {
7943
7943
return getFlowTypeOfReference(reference, autoType, initialType);
7944
7944
}
7945
7945
7946
- function isPossiblyAliasedThisProperty(declaration: BinaryExpression, kind = getAssignmentDeclarationKind(declaration)) {
7947
- if (kind === AssignmentDeclarationKind.ThisProperty) {
7948
- return true;
7949
- }
7950
- if (!isInJSFile(declaration) || kind !== AssignmentDeclarationKind.Property || !isIdentifier((declaration.left as AccessExpression).expression)) {
7951
- return false;
7952
- }
7953
- const name = ((declaration.left as AccessExpression).expression as Identifier).escapedText;
7954
- const symbol = resolveName(declaration.left, name, SymbolFlags.Value, undefined, undefined, /*isUse*/ true, /*excludeGlobals*/ true);
7955
- return isThisInitializedDeclaration(symbol?.valueDeclaration);
7956
- }
7957
-
7958
7946
function getWidenedTypeForAssignmentDeclaration(symbol: Symbol, resolvedSymbol?: Symbol) {
7959
7947
// function/class/{} initializers are themselves containers, so they won't merge in the same way as other initializers
7960
7948
const container = getAssignedExpandoInitializer(symbol.valueDeclaration);
@@ -23176,7 +23164,7 @@ namespace ts {
23176
23164
case AssignmentDeclarationKind.Prototype:
23177
23165
case AssignmentDeclarationKind.PrototypeProperty:
23178
23166
if (isPossiblyAliasedThisProperty(binaryExpression, kind)) {
23179
- // do nothing, fall through to ThisProperty case
23167
+ return getIsContextSensitiveOfThisProperty(binaryExpression, kind);
23180
23168
}
23181
23169
// If `binaryExpression.left` was assigned a symbol, then this is a new declaration; otherwise it is an assignment to an existing declaration.
23182
23170
// See `bindStaticPropertyAssignment` in `binder.ts`.
@@ -23210,27 +23198,9 @@ namespace ts {
23210
23198
}
23211
23199
return !isInJSFile(decl);
23212
23200
}
23213
- // fall through to ThisProperty for this-aliases
23214
23201
case AssignmentDeclarationKind.ModuleExports:
23215
23202
case AssignmentDeclarationKind.ThisProperty:
23216
- if (!binaryExpression.symbol) return true;
23217
- if (binaryExpression.symbol.valueDeclaration) {
23218
- const annotated = getEffectiveTypeAnnotationNode(binaryExpression.symbol.valueDeclaration);
23219
- if (annotated) {
23220
- const type = getTypeFromTypeNode(annotated);
23221
- if (type) {
23222
- return type;
23223
- }
23224
- }
23225
- }
23226
- if (kind === AssignmentDeclarationKind.ModuleExports) return false;
23227
- const thisAccess = cast(binaryExpression.left, isAccessExpression);
23228
- if (!isObjectLiteralMethod(getThisContainer(thisAccess.expression, /*includeArrowFunctions*/ false))) {
23229
- return false;
23230
- }
23231
- const thisType = checkThisExpression(thisAccess.expression);
23232
- const nameStr = getElementOrPropertyAccessName(thisAccess);
23233
- return nameStr !== undefined && thisType && getTypeOfPropertyOfContextualType(thisType, nameStr) || false;
23203
+ return getIsContextSensitiveOfThisProperty(binaryExpression, kind);
23234
23204
case AssignmentDeclarationKind.ObjectDefinePropertyValue:
23235
23205
case AssignmentDeclarationKind.ObjectDefinePropertyExports:
23236
23206
case AssignmentDeclarationKind.ObjectDefinePrototypeProperty:
@@ -23240,6 +23210,40 @@ namespace ts {
23240
23210
}
23241
23211
}
23242
23212
23213
+ function isPossiblyAliasedThisProperty(declaration: BinaryExpression, kind = getAssignmentDeclarationKind(declaration)) {
23214
+ if (kind === AssignmentDeclarationKind.ThisProperty) {
23215
+ return true;
23216
+ }
23217
+ if (!isInJSFile(declaration) || kind !== AssignmentDeclarationKind.Property || !isIdentifier((declaration.left as AccessExpression).expression)) {
23218
+ return false;
23219
+ }
23220
+ const name = ((declaration.left as AccessExpression).expression as Identifier).escapedText;
23221
+ const symbol = resolveName(declaration.left, name, SymbolFlags.Value, undefined, undefined, /*isUse*/ true, /*excludeGlobals*/ true);
23222
+ return isThisInitializedDeclaration(symbol?.valueDeclaration);
23223
+ }
23224
+
23225
+ function getIsContextSensitiveOfThisProperty(binaryExpression: BinaryExpression, kind: AssignmentDeclarationKind) {
23226
+ if (!binaryExpression.symbol) return true;
23227
+ if (binaryExpression.symbol.valueDeclaration) {
23228
+ const annotated = getEffectiveTypeAnnotationNode(binaryExpression.symbol.valueDeclaration);
23229
+ if (annotated) {
23230
+ const type = getTypeFromTypeNode(annotated);
23231
+ if (type) {
23232
+ return type;
23233
+ }
23234
+ }
23235
+ }
23236
+ if (kind === AssignmentDeclarationKind.ModuleExports) return false;
23237
+ const thisAccess = cast(binaryExpression.left, isAccessExpression);
23238
+ if (!isObjectLiteralMethod(getThisContainer(thisAccess.expression, /*includeArrowFunctions*/ false))) {
23239
+ return false;
23240
+ }
23241
+ const thisType = checkThisExpression(thisAccess.expression);
23242
+ const nameStr = getElementOrPropertyAccessName(thisAccess);
23243
+ return nameStr !== undefined && thisType && getTypeOfPropertyOfContextualType(thisType, nameStr) || false;
23244
+
23245
+ }
23246
+
23243
23247
function isCircularMappedProperty(symbol: Symbol) {
23244
23248
return !!(getCheckFlags(symbol) & CheckFlags.Mapped && !(<MappedSymbol>symbol).type && findResolutionCycleStartIndex(symbol, TypeSystemPropertyName.Type) >= 0);
23245
23249
}
0 commit comments