Add 'unknown' keyword to scanner/parser/emitter

This commit is contained in:
Anders Hejlsberg 2018-05-26 08:51:09 -07:00
parent 8b2149ecc8
commit 03f464f433
5 changed files with 43 additions and 31 deletions

View file

@ -2850,6 +2850,7 @@ namespace ts {
function parseNonArrayType(): TypeNode {
switch (token()) {
case SyntaxKind.AnyKeyword:
case SyntaxKind.UnknownKeyword:
case SyntaxKind.StringKeyword:
case SyntaxKind.NumberKeyword:
case SyntaxKind.SymbolKeyword:
@ -2907,6 +2908,7 @@ namespace ts {
function isStartOfType(inStartOfParameter?: boolean): boolean {
switch (token()) {
case SyntaxKind.AnyKeyword:
case SyntaxKind.UnknownKeyword:
case SyntaxKind.StringKeyword:
case SyntaxKind.NumberKeyword:
case SyntaxKind.BooleanKeyword:

View file

@ -124,6 +124,7 @@ namespace ts {
"typeof": SyntaxKind.TypeOfKeyword,
"undefined": SyntaxKind.UndefinedKeyword,
"unique": SyntaxKind.UniqueKeyword,
"unknown": SyntaxKind.UnknownKeyword,
"var": SyntaxKind.VarKeyword,
"void": SyntaxKind.VoidKeyword,
"while": SyntaxKind.WhileKeyword,

View file

@ -384,6 +384,7 @@ namespace ts {
case SyntaxKind.TypePredicate:
case SyntaxKind.TypeParameter:
case SyntaxKind.AnyKeyword:
case SyntaxKind.UnknownKeyword:
case SyntaxKind.BooleanKeyword:
case SyntaxKind.StringKeyword:
case SyntaxKind.NumberKeyword:
@ -1907,6 +1908,7 @@ namespace ts {
case SyntaxKind.MappedType:
case SyntaxKind.TypeLiteral:
case SyntaxKind.AnyKeyword:
case SyntaxKind.UnknownKeyword:
case SyntaxKind.ThisType:
break;

View file

@ -241,6 +241,7 @@ namespace ts {
TypeKeyword,
UndefinedKeyword,
UniqueKeyword,
UnknownKeyword,
FromKeyword,
GlobalKeyword,
OfKeyword, // LastKeyword and LastToken and LastContextualKeyword
@ -1068,6 +1069,7 @@ namespace ts {
export interface KeywordTypeNode extends TypeNode {
kind: SyntaxKind.AnyKeyword
| SyntaxKind.UnknownKeyword
| SyntaxKind.NumberKeyword
| SyntaxKind.ObjectKeyword
| SyntaxKind.BooleanKeyword
@ -3665,40 +3667,43 @@ namespace ts {
export const enum TypeFlags {
Any = 1 << 0,
String = 1 << 1,
Number = 1 << 2,
Boolean = 1 << 3,
Enum = 1 << 4,
StringLiteral = 1 << 5,
NumberLiteral = 1 << 6,
BooleanLiteral = 1 << 7,
EnumLiteral = 1 << 8, // Always combined with StringLiteral, NumberLiteral, or Union
ESSymbol = 1 << 9, // Type of symbol primitive introduced in ES6
UniqueESSymbol = 1 << 10, // unique symbol
Void = 1 << 11,
Undefined = 1 << 12,
Null = 1 << 13,
Never = 1 << 14, // Never type
TypeParameter = 1 << 15, // Type parameter
Object = 1 << 16, // Object type
Union = 1 << 17, // Union (T | U)
Intersection = 1 << 18, // Intersection (T & U)
Index = 1 << 19, // keyof T
IndexedAccess = 1 << 20, // T[K]
Conditional = 1 << 21, // T extends U ? X : Y
Substitution = 1 << 22, // Type parameter substitution
NonPrimitive = 1 << 23, // intrinsic object type
Unknown = 1 << 1,
String = 1 << 2,
Number = 1 << 3,
Boolean = 1 << 4,
Enum = 1 << 5,
StringLiteral = 1 << 6,
NumberLiteral = 1 << 7,
BooleanLiteral = 1 << 8,
EnumLiteral = 1 << 9, // Always combined with StringLiteral, NumberLiteral, or Union
ESSymbol = 1 << 10, // Type of symbol primitive introduced in ES6
UniqueESSymbol = 1 << 11, // unique symbol
Void = 1 << 12,
Undefined = 1 << 13,
Null = 1 << 14,
Never = 1 << 15, // Never type
TypeParameter = 1 << 16, // Type parameter
Object = 1 << 17, // Object type
Union = 1 << 18, // Union (T | U)
Intersection = 1 << 19, // Intersection (T & U)
Index = 1 << 20, // keyof T
IndexedAccess = 1 << 21, // T[K]
Conditional = 1 << 22, // T extends U ? X : Y
Substitution = 1 << 23, // Type parameter substitution
NonPrimitive = 1 << 24, // intrinsic object type
/* @internal */
FreshLiteral = 1 << 24, // Fresh literal or unique type
FreshLiteral = 1 << 25, // Fresh literal or unique type
/* @internal */
UnionOfUnitTypes = 1 << 25, // Type is union of unit types
UnionOfUnitTypes = 1 << 26, // Type is union of unit types
/* @internal */
ContainsWideningType = 1 << 26, // Type is or contains undefined or null widening type
ContainsWideningType = 1 << 27, // Type is or contains undefined or null widening type
/* @internal */
ContainsObjectLiteral = 1 << 27, // Type is or contains object literal type
ContainsObjectLiteral = 1 << 28, // Type is or contains object literal type
/* @internal */
ContainsAnyFunctionType = 1 << 28, // Type is or contains the anyFunctionType
ContainsAnyFunctionType = 1 << 29, // Type is or contains the anyFunctionType
/* @internal */
AnyOrUnknown = Any | Unknown,
/* @internal */
Nullable = Undefined | Null,
Literal = StringLiteral | NumberLiteral | BooleanLiteral,
@ -3710,7 +3715,7 @@ namespace ts {
DefinitelyFalsy = StringLiteral | NumberLiteral | BooleanLiteral | Void | Undefined | Null,
PossiblyFalsy = DefinitelyFalsy | String | Number | Boolean,
/* @internal */
Intrinsic = Any | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never | NonPrimitive,
Intrinsic = Any | Unknown | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never | NonPrimitive,
/* @internal */
Primitive = String | Number | Boolean | Enum | EnumLiteral | ESSymbol | Void | Undefined | Null | Literal | UniqueESSymbol,
StringLike = String | StringLiteral,
@ -3731,8 +3736,8 @@ namespace ts {
// 'Narrowable' types are types where narrowing actually narrows.
// This *should* be every type other than null, undefined, void, and never
Narrowable = Any | StructuredOrInstantiable | StringLike | NumberLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
NotUnionOrUnit = Any | ESSymbol | Object | NonPrimitive,
Narrowable = Any | Unknown | StructuredOrInstantiable | StringLike | NumberLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
NotUnionOrUnit = Any | Unknown | ESSymbol | Object | NonPrimitive,
/* @internal */
NotUnit = Any | String | Number | Boolean | Enum | ESSymbol | Void | Never | StructuredOrInstantiable,
/* @internal */

View file

@ -810,6 +810,7 @@ namespace ts {
switch (node.kind) {
case SyntaxKind.AnyKeyword:
case SyntaxKind.UnknownKeyword:
case SyntaxKind.NumberKeyword:
case SyntaxKind.StringKeyword:
case SyntaxKind.BooleanKeyword:
@ -5777,6 +5778,7 @@ namespace ts {
function isTypeNodeKind(kind: SyntaxKind) {
return (kind >= SyntaxKind.FirstTypeNode && kind <= SyntaxKind.LastTypeNode)
|| kind === SyntaxKind.AnyKeyword
|| kind === SyntaxKind.UnknownKeyword
|| kind === SyntaxKind.NumberKeyword
|| kind === SyntaxKind.ObjectKeyword
|| kind === SyntaxKind.BooleanKeyword