@@ -67,6 +67,7 @@ module ts {
6767 var stringType = createIntrinsicType(TypeFlags.String, "string");
6868 var numberType = createIntrinsicType(TypeFlags.Number, "number");
6969 var booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean");
70+ var esSymbolType = createIntrinsicType(TypeFlags.ESSymbol, "symbol");
7071 var voidType = createIntrinsicType(TypeFlags.Void, "void");
7172 var undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefinedOrNull, "undefined");
7273 var nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefinedOrNull, "null");
@@ -123,6 +124,10 @@ module ts {
123124 "boolean": {
124125 type: booleanType,
125126 flags: TypeFlags.Boolean
127+ },
128+ "symbol": {
129+ type: esSymbolType,
130+ flags: TypeFlags.ESSymbol
126131 }
127132 };
128133
@@ -3191,6 +3196,8 @@ module ts {
31913196 return numberType;
31923197 case SyntaxKind.BooleanKeyword:
31933198 return booleanType;
3199+ case SyntaxKind.SymbolKeyword:
3200+ return esSymbolType;
31943201 case SyntaxKind.VoidKeyword:
31953202 return voidType;
31963203 case SyntaxKind.StringLiteral:
@@ -5492,7 +5499,7 @@ module ts {
54925499 function isNumericComputedName(name: ComputedPropertyName): boolean {
54935500 // It seems odd to consider an expression of type Any to result in a numeric name,
54945501 // but this behavior is consistent with checkIndexedAccess
5495- return isTypeOfKind(checkComputedPropertyName(name), TypeFlags.Any | TypeFlags.NumberLike, /*includeESSymbols*/ false );
5502+ return isTypeOfKind(checkComputedPropertyName(name), TypeFlags.Any | TypeFlags.NumberLike);
54965503 }
54975504
54985505 function isNumericLiteralName(name: string) {
@@ -5527,7 +5534,7 @@ module ts {
55275534
55285535 // This will allow types number, string, Symbol or any. It will also allow enums, the unknown
55295536 // type, and any union of these types (like string | number).
5530- if (!isTypeOfKind(links.resolvedType, TypeFlags.Any | TypeFlags.NumberLike | TypeFlags.StringLike, /*includeESSymbols*/ true )) {
5537+ if (!isTypeOfKind(links.resolvedType, TypeFlags.Any | TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol )) {
55315538 error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_Symbol_or_any);
55325539 }
55335540 }
@@ -5792,10 +5799,10 @@ module ts {
57925799 }
57935800
57945801 // Check for compatible indexer types.
5795- if (isTypeOfKind(indexType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike, /*includeESSymbols*/ true )) {
5802+ if (isTypeOfKind(indexType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol )) {
57965803
57975804 // Try to use a number indexer.
5798- if (isTypeOfKind(indexType, TypeFlags.Any | TypeFlags.NumberLike, /*includeESSymbols*/ false )) {
5805+ if (isTypeOfKind(indexType, TypeFlags.Any | TypeFlags.NumberLike)) {
57995806 var numberIndexType = getIndexTypeOfType(objectType, IndexKind.Number);
58005807 if (numberIndexType) {
58015808 return numberIndexType;
@@ -6733,7 +6740,7 @@ module ts {
67336740 }
67346741
67356742 function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage): boolean {
6736- if (!isTypeOfKind(type, TypeFlags.Any | TypeFlags.NumberLike, /*includeESSymbols*/ false )) {
6743+ if (!isTypeOfKind(type, TypeFlags.Any | TypeFlags.NumberLike)) {
67376744 error(operand, diagnostic);
67386745 return false;
67396746 }
@@ -6884,29 +6891,20 @@ module ts {
68846891 return numberType;
68856892 }
68866893
6887- // Return true if type has the given flags, or is a union type composed of types that all have those flags
6888- // If include includeESSymbols is true, then check if the type (or union constituents) is an ESSymbol
6889- // if it does not match the kind. This is necessary because ESSymbol has no corresponding flag.
6890- function isTypeOfKind(type: Type, kind: TypeFlags, includeESSymbols: boolean): boolean {
6894+ // Return true if type has the given flags, or is a union type composed of types that all have those flags.
6895+ function isTypeOfKind(type: Type, kind: TypeFlags): boolean {
68916896 if (type.flags & kind) {
68926897 return true;
68936898 }
68946899 if (type.flags & TypeFlags.Union) {
68956900 var types = (<UnionType>type).types;
68966901 for (var i = 0; i < types.length; i++) {
6897- if (types[i].flags & kind) {
6898- continue;
6899- }
6900- if (includeESSymbols && types[i] === globalESSymbolType) {
6901- continue;
6902+ if (!(types[i].flags & kind)) {
6903+ return false;
69026904 }
6903- return false;
69046905 }
69056906 return true;
69066907 }
6907- if (includeESSymbols) {
6908- return type === globalESSymbolType;
6909- }
69106908 return false;
69116909 }
69126910
@@ -6924,11 +6922,7 @@ module ts {
69246922 // and the right operand to be of type Any or a subtype of the 'Function' interface type.
69256923 // The result is always of the Boolean primitive type.
69266924 // NOTE: do not raise error if leftType is unknown as related error was already reported
6927- //
6928- // The reason for globalESSymbolType !== unknownType is that if the type is unknownType, we don't want to error.
6929- // If the globalESSymbolType is also unknownType, then by including globalESSymbolType, we will error
6930- // on unknownType, because transitively, type will be the same as globalESSymbolType.
6931- if (isTypeOfKind(leftType, TypeFlags.Primitive, /*includeESSymbols*/ globalESSymbolType !== unknownType)) {
6925+ if (isTypeOfKind(leftType, TypeFlags.Primitive)) {
69326926 error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
69336927 }
69346928 // NOTE: do not raise error if right is unknown as related error was already reported
@@ -6943,10 +6937,10 @@ module ts {
69436937 // The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type,
69446938 // and the right operand to be of type Any, an object type, or a type parameter type.
69456939 // The result is always of the Boolean primitive type.
6946- if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike, /*includeESSymbols*/ true )) {
6940+ if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol )) {
69476941 error(node.left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number);
69486942 }
6949- if (!isTypeOfKind(rightType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter, /*includeESSymbols*/ false )) {
6943+ if (!isTypeOfKind(rightType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) {
69506944 error(node.right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
69516945 }
69526946 return booleanType;
@@ -7107,12 +7101,12 @@ module ts {
71077101 if (rightType.flags & (TypeFlags.Undefined | TypeFlags.Null)) rightType = leftType;
71087102
71097103 var resultType: Type;
7110- if (isTypeOfKind(leftType, TypeFlags.NumberLike, /*includeESSymbols*/ false ) && isTypeOfKind(rightType, TypeFlags.NumberLike, /*includeESSymbols*/ false )) {
7104+ if (isTypeOfKind(leftType, TypeFlags.NumberLike) && isTypeOfKind(rightType, TypeFlags.NumberLike)) {
71117105 // Operands of an enum type are treated as having the primitive type Number.
71127106 // If both operands are of the Number primitive type, the result is of the Number primitive type.
71137107 resultType = numberType;
71147108 }
7115- else if (isTypeOfKind(leftType, TypeFlags.StringLike, /*includeESSymbols*/ false ) || isTypeOfKind(rightType, TypeFlags.StringLike, /*includeESSymbols*/ false )) {
7109+ else if (isTypeOfKind(leftType, TypeFlags.StringLike) || isTypeOfKind(rightType, TypeFlags.StringLike)) {
71167110 // If one or both operands are of the String primitive type, the result is of the String primitive type.
71177111 resultType = stringType;
71187112 }
@@ -8478,7 +8472,7 @@ module ts {
84788472 // and Expr must be an expression of type Any, an object type, or a type parameter type.
84798473 var varExpr = <Expression>node.initializer;
84808474 var exprType = checkExpression(varExpr);
8481- if (!isTypeOfKind(exprType, TypeFlags.Any | TypeFlags.StringLike, /*includeESSymbols*/ true )) {
8475+ if (!isTypeOfKind(exprType, TypeFlags.Any | TypeFlags.StringLike)) {
84828476 error(varExpr, Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any);
84838477 }
84848478 else {
@@ -8490,7 +8484,7 @@ module ts {
84908484 var exprType = checkExpression(node.expression);
84918485 // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved
84928486 // in this case error about missing name is already reported - do not report extra one
8493- if (!isTypeOfKind(exprType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter, /*includeESSymbols*/ false )) {
8487+ if (!isTypeOfKind(exprType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) {
84948488 error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter);
84958489 }
84968490
0 commit comments