Create typeof's string literal union type once

This changes the print order of string literal unions slightly. I think
this is because 'string', 'symbol', etc are added to a union very early
on in the creation of the checker.
This commit is contained in:
Nathan Shively-Sanders
2017-01-31 14:39:10 -08:00
parent 01bc4efc82
commit 2ce64f2bad
3 changed files with 10 additions and 7 deletions
+6 -3
View File
@@ -326,7 +326,6 @@ namespace ts {
"object": TypeFacts.TypeofEQObject,
"function": TypeFacts.TypeofEQFunction
});
const typeofNEFacts = createMapFromTemplate({
"string": TypeFacts.TypeofNEString,
"number": TypeFacts.TypeofNENumber,
@@ -336,7 +335,6 @@ namespace ts {
"object": TypeFacts.TypeofNEObject,
"function": TypeFacts.TypeofNEFunction
});
const typeofTypesByName = createMapFromTemplate<Type>({
"string": stringType,
"number": numberType,
@@ -344,6 +342,7 @@ namespace ts {
"symbol": esSymbolType,
"undefined": undefinedType
});
const typeofType = createTypeofType();
let jsxElementType: Type;
let _jsxNamespace: string;
@@ -1725,6 +1724,10 @@ namespace ts {
return type;
}
function createTypeofType() {
return getUnionType(arrayFromMap(typeofEQFacts.keys(), s => getLiteralTypeForText(TypeFlags.StringLiteral, s)));
}
// A reserved member name starts with two underscores, but the third character cannot be an underscore
// or the @ symbol. A third underscore indicates an escaped form of an identifer that started
// with at least two underscores. The @ character indicates that the name is denoted by a well known ES
@@ -14609,7 +14612,7 @@ namespace ts {
function checkTypeOfExpression(node: TypeOfExpression): Type {
checkExpression(node.expression);
return getUnionType(arrayFromMap(typeofEQFacts.keys(), s => getLiteralTypeForText(TypeFlags.StringLiteral, s)));
return typeofType;
}
function checkVoidExpression(node: VoidExpression): Type {