-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
cache type for empty type literal #11934
Changes from 2 commits
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 |
---|---|---|
|
@@ -138,6 +138,11 @@ namespace ts { | |
const silentNeverType = createIntrinsicType(TypeFlags.Never, "never"); | ||
|
||
const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); | ||
|
||
const emptyTypeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral | SymbolFlags.Transient, "__type"); | ||
emptyTypeLiteralSymbol.members = createMap<Symbol>(); | ||
const cachedEmptyTypeLiteralType = createAnonymousType(emptyTypeLiteralSymbol, emptySymbols, emptyArray, emptyArray, undefined, undefined); | ||
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. For consistency with the other precanned types and symbols I would just name this |
||
|
||
const emptyGenericType = <GenericType><ObjectType>createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); | ||
emptyGenericType.instantiations = createMap<TypeReference>(); | ||
|
||
|
@@ -5696,10 +5701,15 @@ namespace ts { | |
const links = getNodeLinks(node); | ||
if (!links.resolvedType) { | ||
// Deferred resolution of members is handled by resolveObjectTypeMembers | ||
const type = createObjectType(ObjectFlags.Anonymous, node.symbol); | ||
type.aliasSymbol = aliasSymbol; | ||
type.aliasTypeArguments = aliasTypeArguments; | ||
links.resolvedType = type; | ||
if (isEmpty(node.symbol.members) && !aliasSymbol && !aliasTypeArguments) { | ||
links.resolvedType = cachedEmptyTypeLiteralType; | ||
} | ||
else { | ||
const type = createObjectType(ObjectFlags.Anonymous, node.symbol); | ||
type.aliasSymbol = aliasSymbol; | ||
type.aliasTypeArguments = aliasTypeArguments; | ||
links.resolvedType = type; | ||
} | ||
} | ||
return links.resolvedType; | ||
} | ||
|
@@ -6036,6 +6046,9 @@ namespace ts { | |
} | ||
|
||
function isSymbolInScopeOfMappedTypeParameter(symbol: Symbol, mapper: TypeMapper) { | ||
if (!(symbol.declarations && symbol.declarations.length)) { | ||
return false; | ||
} | ||
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. Change this to:
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. ✅ |
||
const mappedTypes = mapper.mappedTypes; | ||
// Starting with the parent of the symbol's declaration, check if the mapper maps any of | ||
// the type parameters introduced by enclosing declarations. We just pick the first | ||
|
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.
Why are you marking this as
SymbolFlags.Synthesized
? We use that flag for union and intersection properties. Also, I would use the name"__type"
, that's what we do in the binder.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.
the idea was to use this flag for marking anything what was not present in the original source code.
will change
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.
✅