From b1bef15a1e05587f7b6a3471003ad2b773453b1f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 14 Mar 2016 15:11:27 -0700 Subject: [PATCH] Removing 'T?' type notation (use 'T | null | undefined' instead) --- src/compiler/checker.ts | 24 +----------------------- src/compiler/parser.ts | 23 ++++++----------------- src/compiler/types.ts | 9 +-------- 3 files changed, 8 insertions(+), 48 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 10e4d50d930..5360cb558f8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2414,7 +2414,6 @@ namespace ts { case SyntaxKind.UnionType: case SyntaxKind.IntersectionType: case SyntaxKind.ParenthesizedType: - case SyntaxKind.NullableType: return isDeclarationVisible(node.parent); // Default binding, import specifier and namespace import is visible @@ -4779,14 +4778,6 @@ namespace ts { return links.resolvedType; } - function getTypeFromNullableTypeNode(node: NullableTypeNode): Type { - const links = getNodeLinks(node); - if (!links.resolvedType) { - links.resolvedType = getNullableType(getTypeFromTypeNode(node.type)); - } - return links.resolvedType; - } - interface TypeSet extends Array { containsAny?: boolean; containsUndefined?: boolean; @@ -5029,8 +5020,6 @@ namespace ts { return getTypeFromUnionTypeNode(node); case SyntaxKind.IntersectionType: return getTypeFromIntersectionTypeNode(node); - case SyntaxKind.NullableType: - return getTypeFromNullableTypeNode(node); case SyntaxKind.ParenthesizedType: case SyntaxKind.JSDocNullableType: case SyntaxKind.JSDocNonNullableType: @@ -6546,16 +6535,6 @@ namespace ts { return getNullableKind(type) === TypeFlags.Nullable; } - function getNullableType(type: Type): Type { - if (!strictNullChecks) { - return type; - } - if (!type.nullableType) { - type.nullableType = isNullableType(type) ? type : getUnionType([type, undefinedType, nullType]); - } - return type.nullableType; - } - function addNullableKind(type: Type, kind: TypeFlags): Type { if ((getNullableKind(type) & kind) !== kind) { const types = [type]; @@ -15792,8 +15771,7 @@ namespace ts { case SyntaxKind.IntersectionType: return checkUnionOrIntersectionType(node); case SyntaxKind.ParenthesizedType: - case SyntaxKind.NullableType: - return checkSourceElement((node).type); + return checkSourceElement((node).type); case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); case SyntaxKind.Block: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0ff1dafc78b..a08c5755a3f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -127,8 +127,7 @@ namespace ts { case SyntaxKind.IntersectionType: return visitNodes(cbNodes, (node).types); case SyntaxKind.ParenthesizedType: - case SyntaxKind.NullableType: - return visitNode(cbNode, (node).type); + return visitNode(cbNode, (node).type); case SyntaxKind.ObjectBindingPattern: case SyntaxKind.ArrayBindingPattern: return visitNodes(cbNodes, (node).elements); @@ -2426,21 +2425,11 @@ namespace ts { function parseArrayTypeOrHigher(): TypeNode { let type = parseNonArrayType(); - while (!scanner.hasPrecedingLineBreak()) { - if (parseOptional(SyntaxKind.OpenBracketToken)) { - parseExpected(SyntaxKind.CloseBracketToken); - const node = createNode(SyntaxKind.ArrayType, type.pos); - node.elementType = type; - type = finishNode(node); - } - else if (parseOptional(SyntaxKind.QuestionToken)) { - const node = createNode(SyntaxKind.NullableType, type.pos); - node.type = type; - type = finishNode(node); - } - else { - break; - } + while (!scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) { + parseExpected(SyntaxKind.CloseBracketToken); + const node = createNode(SyntaxKind.ArrayType, type.pos); + node.elementType = type; + type = finishNode(node); } return type; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 12ff2673564..3c7a16da59f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -210,7 +210,6 @@ namespace ts { ParenthesizedType, ThisType, StringLiteralType, - NullableType, // Binding patterns ObjectBindingPattern, ArrayBindingPattern, @@ -357,7 +356,7 @@ namespace ts { FirstFutureReservedWord = ImplementsKeyword, LastFutureReservedWord = YieldKeyword, FirstTypeNode = TypePredicate, - LastTypeNode = NullableType, + LastTypeNode = StringLiteralType, FirstPunctuation = OpenBraceToken, LastPunctuation = CaretEqualsToken, FirstToken = Unknown, @@ -785,11 +784,6 @@ namespace ts { _stringLiteralTypeBrand: any; } - // @kind(SyntaxKind.NullableType) - export interface NullableTypeNode extends TypeNode { - type: TypeNode; - } - // @kind(SyntaxKind.StringLiteral) export interface StringLiteral extends LiteralExpression { _stringLiteralBrand: any; @@ -2152,7 +2146,6 @@ namespace ts { /* @internal */ id: number; // Unique ID symbol?: Symbol; // Symbol associated with type (if any) pattern?: DestructuringPattern; // Destructuring pattern represented by type (if any) - nullableType?: Type; // Cached nullable form of this type } /* @internal */