Skip to content

Commit a6d4f35

Browse files
committed
Refactor and move functions
1 parent 4650286 commit a6d4f35

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

src/compiler/checker.ts

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7943,18 +7943,6 @@ namespace ts {
79437943
return getFlowTypeOfReference(reference, autoType, initialType);
79447944
}
79457945

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-
79587946
function getWidenedTypeForAssignmentDeclaration(symbol: Symbol, resolvedSymbol?: Symbol) {
79597947
// function/class/{} initializers are themselves containers, so they won't merge in the same way as other initializers
79607948
const container = getAssignedExpandoInitializer(symbol.valueDeclaration);
@@ -23176,7 +23164,7 @@ namespace ts {
2317623164
case AssignmentDeclarationKind.Prototype:
2317723165
case AssignmentDeclarationKind.PrototypeProperty:
2317823166
if (isPossiblyAliasedThisProperty(binaryExpression, kind)) {
23179-
// do nothing, fall through to ThisProperty case
23167+
return getIsContextSensitiveOfThisProperty(binaryExpression, kind);
2318023168
}
2318123169
// If `binaryExpression.left` was assigned a symbol, then this is a new declaration; otherwise it is an assignment to an existing declaration.
2318223170
// See `bindStaticPropertyAssignment` in `binder.ts`.
@@ -23210,27 +23198,9 @@ namespace ts {
2321023198
}
2321123199
return !isInJSFile(decl);
2321223200
}
23213-
// fall through to ThisProperty for this-aliases
2321423201
case AssignmentDeclarationKind.ModuleExports:
2321523202
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);
2323423204
case AssignmentDeclarationKind.ObjectDefinePropertyValue:
2323523205
case AssignmentDeclarationKind.ObjectDefinePropertyExports:
2323623206
case AssignmentDeclarationKind.ObjectDefinePrototypeProperty:
@@ -23240,6 +23210,40 @@ namespace ts {
2324023210
}
2324123211
}
2324223212

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+
2324323247
function isCircularMappedProperty(symbol: Symbol) {
2324423248
return !!(getCheckFlags(symbol) & CheckFlags.Mapped && !(<MappedSymbol>symbol).type && findResolutionCycleStartIndex(symbol, TypeSystemPropertyName.Type) >= 0);
2324523249
}

0 commit comments

Comments
 (0)