mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Bind non-expando property assignments at top-level (#26908)
* Bind non-expando property assignments at toplevel Previously, only property assignments with expando initialisers were bound in top-level statements. Now, all property assignments are bound. This requires a matching change in the checker to make sure that these assignments remain context sensitive if their valueDeclaration is a 'real' declaration (ie a non assignment-declaration). * Add baselines for new test
This commit is contained in:
committed by
GitHub
parent
6e318890fe
commit
ff05082e45
@@ -2512,11 +2512,10 @@ namespace ts {
|
||||
|
||||
function bindPropertyAssignment(name: EntityNameExpression, propertyAccess: PropertyAccessEntityNameExpression, isPrototypeProperty: boolean) {
|
||||
let namespaceSymbol = lookupSymbolForPropertyAccess(name);
|
||||
const isToplevelNamespaceableInitializer = isBinaryExpression(propertyAccess.parent)
|
||||
? getParentOfBinaryExpression(propertyAccess.parent).parent.kind === SyntaxKind.SourceFile &&
|
||||
!!getJavascriptInitializer(getInitializerOfBinaryExpression(propertyAccess.parent), isPrototypeAccess(propertyAccess.parent.left))
|
||||
const isToplevel = isBinaryExpression(propertyAccess.parent)
|
||||
? getParentOfBinaryExpression(propertyAccess.parent).parent.kind === SyntaxKind.SourceFile
|
||||
: propertyAccess.parent.parent.kind === SyntaxKind.SourceFile;
|
||||
if (!isPrototypeProperty && (!namespaceSymbol || !(namespaceSymbol.flags & SymbolFlags.Namespace)) && isToplevelNamespaceableInitializer) {
|
||||
if (!isPrototypeProperty && (!namespaceSymbol || !(namespaceSymbol.flags & SymbolFlags.Namespace)) && isToplevel) {
|
||||
// make symbols or add declarations for intermediate containers
|
||||
const flags = SymbolFlags.Module | SymbolFlags.JSContainer;
|
||||
const excludeFlags = SymbolFlags.ValueModuleExcludes & ~SymbolFlags.JSContainer;
|
||||
@@ -2573,7 +2572,7 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function getParentOfBinaryExpression(expr: BinaryExpression) {
|
||||
function getParentOfBinaryExpression(expr: Node) {
|
||||
while (isBinaryExpression(expr.parent)) {
|
||||
expr = expr.parent;
|
||||
}
|
||||
|
||||
@@ -16189,7 +16189,7 @@ namespace ts {
|
||||
else if (isIdentifier(lhs.expression)) {
|
||||
const id = lhs.expression;
|
||||
const parentSymbol = resolveName(id, id.escapedText, SymbolFlags.Value, undefined, id.escapedText, /*isUse*/ true);
|
||||
if (parentSymbol && isFunctionSymbol(parentSymbol)) {
|
||||
if (parentSymbol) {
|
||||
const annotated = getEffectiveTypeAnnotationNode(parentSymbol.valueDeclaration);
|
||||
if (annotated) {
|
||||
const type = getTypeOfPropertyOfContextualType(getTypeFromTypeNode(annotated), lhs.name.escapedText);
|
||||
|
||||
Reference in New Issue
Block a user