@@ -25080,12 +25080,11 @@ namespace ts {
25080
25080
switch (kind) {
25081
25081
case AssignmentDeclarationKind.None:
25082
25082
return getTypeOfExpression(binaryExpression.left);
25083
+ case AssignmentDeclarationKind.ThisProperty:
25084
+ return getContextualTypeForThisPropertyAssignment(binaryExpression);
25083
25085
case AssignmentDeclarationKind.Property:
25084
- case AssignmentDeclarationKind.ExportsProperty:
25085
- case AssignmentDeclarationKind.Prototype:
25086
- case AssignmentDeclarationKind.PrototypeProperty:
25087
25086
if (isPossiblyAliasedThisProperty(binaryExpression, kind)) {
25088
- return getContextualTypeForThisPropertyAssignment(binaryExpression, kind );
25087
+ return getContextualTypeForThisPropertyAssignment(binaryExpression);
25089
25088
}
25090
25089
// If `binaryExpression.left` was assigned a symbol, then this is a new declaration; otherwise it is an assignment to an existing declaration.
25091
25090
// See `bindStaticPropertyAssignment` in `binder.ts`.
@@ -25118,9 +25117,15 @@ namespace ts {
25118
25117
}
25119
25118
return isInJSFile(decl) ? undefined : getTypeOfExpression(binaryExpression.left);
25120
25119
}
25120
+ case AssignmentDeclarationKind.ExportsProperty:
25121
+ case AssignmentDeclarationKind.Prototype:
25122
+ case AssignmentDeclarationKind.PrototypeProperty:
25123
+ let valueDeclaration = binaryExpression.left.symbol?.valueDeclaration;
25124
+ // falls through
25121
25125
case AssignmentDeclarationKind.ModuleExports:
25122
- case AssignmentDeclarationKind.ThisProperty:
25123
- return getContextualTypeForThisPropertyAssignment(binaryExpression, kind);
25126
+ valueDeclaration ||= binaryExpression.symbol?.valueDeclaration;
25127
+ const annotated = valueDeclaration && getEffectiveTypeAnnotationNode(valueDeclaration);
25128
+ return annotated ? getTypeFromTypeNode(annotated) : undefined;
25124
25129
case AssignmentDeclarationKind.ObjectDefinePropertyValue:
25125
25130
case AssignmentDeclarationKind.ObjectDefinePropertyExports:
25126
25131
case AssignmentDeclarationKind.ObjectDefinePrototypeProperty:
@@ -25142,7 +25147,7 @@ namespace ts {
25142
25147
return isThisInitializedDeclaration(symbol?.valueDeclaration);
25143
25148
}
25144
25149
25145
- function getContextualTypeForThisPropertyAssignment(binaryExpression: BinaryExpression, kind: AssignmentDeclarationKind ): Type | undefined {
25150
+ function getContextualTypeForThisPropertyAssignment(binaryExpression: BinaryExpression): Type | undefined {
25146
25151
if (!binaryExpression.symbol) return getTypeOfExpression(binaryExpression.left);
25147
25152
if (binaryExpression.symbol.valueDeclaration) {
25148
25153
const annotated = getEffectiveTypeAnnotationNode(binaryExpression.symbol.valueDeclaration);
@@ -25153,7 +25158,6 @@ namespace ts {
25153
25158
}
25154
25159
}
25155
25160
}
25156
- if (kind === AssignmentDeclarationKind.ModuleExports) return undefined;
25157
25161
const thisAccess = cast(binaryExpression.left, isAccessExpression);
25158
25162
if (!isObjectLiteralMethod(getThisContainer(thisAccess.expression, /*includeArrowFunctions*/ false))) {
25159
25163
return undefined;
@@ -38874,10 +38878,10 @@ namespace ts {
38874
38878
38875
38879
switch (location.kind) {
38876
38880
case SyntaxKind.SourceFile:
38877
- if (!isExternalOrCommonJsModule (<SourceFile>location)) break;
38881
+ if (!isExternalModule (<SourceFile>location)) break;
38878
38882
// falls through
38879
38883
case SyntaxKind.ModuleDeclaration:
38880
- copySymbols (getSymbolOfNode(location as ModuleDeclaration | SourceFile).exports!, meaning & SymbolFlags.ModuleMember);
38884
+ copyLocallyVisibleExportSymbols (getSymbolOfNode(location as ModuleDeclaration | SourceFile).exports!, meaning & SymbolFlags.ModuleMember);
38881
38885
break;
38882
38886
case SyntaxKind.EnumDeclaration:
38883
38887
copySymbols(getSymbolOfNode(location as EnumDeclaration).exports!, meaning & SymbolFlags.EnumMember);
@@ -38946,6 +38950,17 @@ namespace ts {
38946
38950
});
38947
38951
}
38948
38952
}
38953
+
38954
+ function copyLocallyVisibleExportSymbols(source: SymbolTable, meaning: SymbolFlags): void {
38955
+ if (meaning) {
38956
+ source.forEach(symbol => {
38957
+ // Similar condition as in `resolveNameHelper`
38958
+ if (!getDeclarationOfKind(symbol, SyntaxKind.ExportSpecifier) && !getDeclarationOfKind(symbol, SyntaxKind.NamespaceExport)) {
38959
+ copySymbol(symbol, meaning);
38960
+ }
38961
+ });
38962
+ }
38963
+ }
38949
38964
}
38950
38965
38951
38966
function isTypeDeclarationName(name: Node): boolean {
0 commit comments