-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Deferred resolution of object literal members to support recursive types. #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f4d3c1c
deaf8e4
2105404
be08411
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1801,27 +1801,39 @@ module ts { | |
|
||
function resolveAnonymousTypeMembers(type: ObjectType) { | ||
var symbol = type.symbol; | ||
var members = emptySymbols; | ||
var callSignatures = emptyArray; | ||
var constructSignatures = emptyArray; | ||
if (symbol.flags & SymbolFlags.HasExports) { | ||
members = symbol.exports; | ||
} | ||
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method)) { | ||
callSignatures = getSignaturesOfSymbol(symbol); | ||
if (symbol.flags & SymbolFlags.TypeLiteral) { | ||
var members = symbol.members; | ||
var callSignatures = getSignaturesOfSymbol(members["__call"]); | ||
var constructSignatures = getSignaturesOfSymbol(members["__new"]); | ||
var stringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String); | ||
var numberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number); | ||
} | ||
if (symbol.flags & SymbolFlags.Class) { | ||
var classType = getDeclaredTypeOfClass(symbol); | ||
constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]); | ||
if (!constructSignatures.length) constructSignatures = getDefaultConstructSignatures(classType); | ||
if (classType.baseTypes.length) { | ||
var members = createSymbolTable(getNamedMembers(members)); | ||
addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol))); | ||
else { | ||
// Combinations of function, class, enum and module | ||
var members = emptySymbols; | ||
var callSignatures: Signature[] = emptyArray; | ||
var constructSignatures: Signature[] = emptyArray; | ||
if (symbol.flags & SymbolFlags.HasExports) { | ||
members = symbol.exports; | ||
} | ||
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method)) { | ||
callSignatures = getSignaturesOfSymbol(symbol); | ||
} | ||
if (symbol.flags & SymbolFlags.Class) { | ||
var classType = getDeclaredTypeOfClass(symbol); | ||
constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]); | ||
if (!constructSignatures.length) { | ||
constructSignatures = getDefaultConstructSignatures(classType); | ||
} | ||
if (classType.baseTypes.length) { | ||
members = createSymbolTable(getNamedMembers(members)); | ||
addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol))); | ||
} | ||
} | ||
var stringIndexType: Type = undefined; | ||
var numberIndexType: Type = (symbol.flags & SymbolFlags.Enum) ? stringType : undefined; | ||
} | ||
var numberIndexType = (symbol.flags & SymbolFlags.Enum) ? stringType : undefined; | ||
|
||
setObjectTypeMembers(type, members, callSignatures, constructSignatures, /* stringIndexType */ undefined, numberIndexType); | ||
setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stringIndexType looks like it might be undefined at this point, if you took the else path above. I would do stringIndexType || undefined just to make the intent clear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added (superfluous) assignment of undefined to make it clearer. |
||
} | ||
|
||
function resolveObjectTypeMembers(type: ObjectType): ResolvedObjectType { | ||
|
@@ -2276,13 +2288,8 @@ module ts { | |
function getTypeFromTypeLiteralNode(node: TypeLiteralNode): Type { | ||
var links = getNodeLinks(node); | ||
if (!links.resolvedType) { | ||
var symbol = node.symbol; | ||
var members = symbol.members; | ||
var callSignatures = getSignaturesOfSymbol(members["__call"]); | ||
var constructSignatures = getSignaturesOfSymbol(members["__new"]); | ||
var stringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String); | ||
var numberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number); | ||
links.resolvedType = createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); | ||
// Deferred resolution of members is handled by resolveObjectTypeMembers | ||
links.resolvedType = createObjectType(TypeFlags.Anonymous, node.symbol); | ||
} | ||
return links.resolvedType; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this down to where you use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used in both if statements below.