From 028484664d019153ed23791ffa88014890986a54 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 9 Dec 2015 15:53:39 -0800 Subject: [PATCH] most pr feedback --- src/compiler/checker.ts | 29 +++++++++++++--------------- src/compiler/diagnosticMessages.json | 4 ++-- src/compiler/types.ts | 2 +- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 45f4e43e424..35f92de8fbe 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5103,7 +5103,7 @@ namespace ts { const targetPredicate = target as PredicateType; if (sourcePredicate.predicate.kind !== targetPredicate.predicate.kind) { if (reportErrors) { - reportError(Diagnostics.A_this_based_type_guard_is_not_assignable_to_a_parameter_based_type_guard); + reportError(Diagnostics.A_this_based_type_guard_is_not_compatible_with_a_parameter_based_type_guard); reportError(Diagnostics.Type_predicate_0_is_not_assignable_to_1, typeToString(source), typeToString(target)); } return Ternary.False; @@ -6506,10 +6506,7 @@ namespace ts { function isAssignedInBinaryExpression(node: BinaryExpression) { if (node.operatorToken.kind >= SyntaxKind.FirstAssignment && node.operatorToken.kind <= SyntaxKind.LastAssignment) { - let n = node.left; - while (n.kind === SyntaxKind.ParenthesizedExpression) { - n = (n).expression; - } + const n = skipParenthesizedNodes(node.left); if (n.kind === SyntaxKind.Identifier && getResolvedSymbol(n) === symbol) { return true; } @@ -6844,13 +6841,6 @@ namespace ts { return type; } - function skipParenthesizedNodes(expression: Expression): Expression { - while (expression.kind === SyntaxKind.ParenthesizedExpression) { - expression = (expression as ParenthesizedExpression).expression; - } - return expression; - } - function getSymbolAtTypePredicatePosition(expr: Expression): Symbol { expr = skipParenthesizedNodes(expr); switch (expr.kind) { @@ -6897,6 +6887,13 @@ namespace ts { } } + function skipParenthesizedNodes(expression: Expression): Expression { + while (expression.kind === SyntaxKind.ParenthesizedExpression) { + expression = (expression as ParenthesizedExpression).expression; + } + return expression; + } + function checkIdentifier(node: Identifier): Type { const symbol = getResolvedSymbol(node); @@ -11085,7 +11082,7 @@ namespace ts { return -1; } - function isInLegalTypePredicatePosition(node: Node): boolean { + function isInLegalParameterTypePredicatePosition(node: Node): boolean { switch (node.parent.kind) { case SyntaxKind.ArrowFunction: case SyntaxKind.CallSignature: @@ -11100,7 +11097,7 @@ namespace ts { } function isInLegalThisTypePredicatePosition(node: Node): boolean { - if (isInLegalTypePredicatePosition(node)) { + if (isInLegalParameterTypePredicatePosition(node)) { return true; } switch (node.parent.kind) { @@ -14332,12 +14329,12 @@ namespace ts { } function checkTypePredicate(node: TypePredicateNode) { - if (node.parameterName.kind === SyntaxKind.Identifier && !isInLegalTypePredicatePosition(node)) { + if (node.parameterName.kind === SyntaxKind.Identifier && !isInLegalParameterTypePredicatePosition(node)) { error(node, Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods); } else if (node.parameterName.kind === SyntaxKind.ThisType) { if (!isInLegalThisTypePredicatePosition(node)) { - error(node, Diagnostics.A_this_based_type_predicate_is_only_allowed_in_class_or_interface_members_get_accessors_or_return_type_positions_for_functions_and_methods); + error(node, Diagnostics.A_this_based_type_predicate_is_only_allowed_within_a_class_or_interface_s_members_get_accessors_or_return_type_positions_for_functions_and_methods); } else { getTypeFromThisTypeNode(node.parameterName as ThisTypeNode); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 959363f148a..46983551338 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1647,11 +1647,11 @@ "category": "Error", "code": 2517 }, - "A 'this'-based type guard is not assignable to a parameter-based type guard": { + "A 'this'-based type guard is not compatible with a parameter-based type guard.": { "category": "Error", "code": 2518 }, - "A 'this'-based type predicate is only allowed in class or interface members, get accessors, or return type positions for functions and methods": { + "A 'this'-based type predicate is only allowed within a class or interface's members, get accessors, or return type positions for functions and methods.": { "category": "Error", "code": 2519 }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7b795846190..85ae020753f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2110,7 +2110,7 @@ namespace ts { ESSymbol = 0x01000000, // Type of symbol primitive introduced in ES6 ThisType = 0x02000000, // This type ObjectLiteralPatternWithComputedProperties = 0x04000000, // Object literal type implied by binding pattern has computed properties - PredicateType = 0x08000000, + PredicateType = 0x08000000, // Predicate types are also Boolean types, but should not be considered Intrinsics - there's no way to capture this with flags /* @internal */ Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null,