diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 37989c3433a..5b12e5ac215 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -618,5 +618,6 @@ namespace ts { JSX_attribute_expected: { code: 17003, category: DiagnosticCategory.Error, key: "JSX attribute expected." }, Cannot_use_JSX_unless_the_jsx_flag_is_provided: { code: 17004, category: DiagnosticCategory.Error, key: "Cannot use JSX unless the '--jsx' flag is provided." }, A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" }, + Left_hand_side_of_Asterisk_Asterisk_cannot_be_a_simple_unary_expression_Consider_parenthesize_the_expression: { code: 17006, category: DiagnosticCategory.Error, key: "Left hand side of '**' cannot be a simple unary expression. Consider parenthesize the expression." }, }; } \ No newline at end of file diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index c1657a81bab..34dd1ffa227 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1700,11 +1700,11 @@ "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead.": { "category": "Error", "code": 2652 - }, + }, "Non-abstract class expression does not implement inherited abstract member '{0}' from class '{1}'.": { "category": "Error", "code": 2653 - }, + }, "Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition.": { "category": "Error", "code": 2654 @@ -1712,11 +1712,11 @@ "Exported external package typings can only be in '.d.ts' files. Please contact the package author to update the package definition.": { "category": "Error", "code": 2655 - }, + }, "Exported external package typings file '{0}' is not a module. Please contact the package author to update the package definition.": { "category": "Error", "code": 2656 - }, + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 @@ -2466,5 +2466,9 @@ "A constructor cannot contain a 'super' call when its class extends 'null'": { "category": "Error", "code": 17005 + }, + "Left hand side of '**' cannot be a simple unary expression. Consider parenthesize the expression.": { + "category": "Error", + "code": 17006 } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 147dbfce9ef..8cbe82c7c01 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3191,34 +3191,36 @@ namespace ts { * Comment * @param node */ - function isIncrementExpression(node: UnaryExpression): node is IncrementExpression { - if (node.kind === SyntaxKind.DeleteExpression || node.kind === SyntaxKind.TypeOfExpression || - node.kind === SyntaxKind.VoidExpression || node.kind === SyntaxKind.TypeAssertionExpression || - node.kind === SyntaxKind.JsxExpression) { - return false; + function isIncrementExpression(): boolean{ + // TODO(yuisu): Comment why we have to do what are we doing here + switch (token) { + case SyntaxKind.PlusToken: + case SyntaxKind.MinusToken: + case SyntaxKind.TildeToken: + case SyntaxKind.ExclamationToken: + case SyntaxKind.DeleteKeyword: + case SyntaxKind.TypeOfKeyword: + case SyntaxKind.VoidKeyword: + case SyntaxKind.LessThanToken: + return false; + default: + return true; } - else if (node.kind === SyntaxKind.PrefixUnaryExpression && ((node).operator === SyntaxKind.PlusToken || - (node).operator === SyntaxKind.MinusToken || (node).operator === SyntaxKind.TildeToken || - (node).operator === SyntaxKind.ExclamationToken)) { - return false; - } - return true; } function parseUnaryExpressionOrHigher(): UnaryExpression | BinaryExpression { - let tryParseIncrementExpression = parseSimpleUnaryExpression(); + if (isIncrementExpression()) { + let incrementExpression = parseIncrementExpression(); + return token === SyntaxKind.AsteriskAsteriskToken ? + parseBinaryExpressionRest(getBinaryOperatorPrecedence(), incrementExpression) : + incrementExpression; + } + + let simpleUnaryExpression = parseSimpleUnaryExpression(); if (token === SyntaxKind.AsteriskAsteriskToken) { - if (isIncrementExpression(tryParseIncrementExpression)) { - return parseBinaryExpressionRest(getBinaryOperatorPrecedence(), tryParseIncrementExpression); - } - else { - parseErrorAtCurrentToken(Diagnostics.Only_incrementExpression_is_allowed_as_left_operand_of_Asterisk_Asterisk); - return tryParseIncrementExpression; - } - } - else { - return tryParseIncrementExpression; + parseErrorAtCurrentToken(Diagnostics.Left_hand_side_of_Asterisk_Asterisk_cannot_be_a_simple_unary_expression_Consider_parenthesize_the_expression) } + return simpleUnaryExpression; } /**