@@ -278,7 +278,13 @@ module ts {
278278 child ( ( < TypeAssertion > node ) . operand ) ;
279279 case SyntaxKind . ParenExpression :
280280 return child ( ( < ParenExpression > node ) . expression ) ;
281- case SyntaxKind . PrefixOperator :
281+ case SyntaxKind . DeleteExpression :
282+ return child ( ( < DeleteExpression > node ) . expression ) ;
283+ case SyntaxKind . TypeOfExpression :
284+ return child ( ( < TypeOfExpression > node ) . expression ) ;
285+ case SyntaxKind . VoidExpression :
286+ return child ( ( < VoidExpression > node ) . expression ) ;
287+ case SyntaxKind . PrefixUnaryExpression :
282288 case SyntaxKind . PostfixOperator :
283289 return child ( ( < UnaryExpression > node ) . operand ) ;
284290 case SyntaxKind . BinaryExpression :
@@ -518,7 +524,10 @@ module ts {
518524 case SyntaxKind . ParenExpression :
519525 case SyntaxKind . FunctionExpression :
520526 case SyntaxKind . ArrowFunction :
521- case SyntaxKind . PrefixOperator :
527+ case SyntaxKind . VoidExpression :
528+ case SyntaxKind . DeleteExpression :
529+ case SyntaxKind . TypeOfExpression :
530+ case SyntaxKind . PrefixUnaryExpression :
522531 case SyntaxKind . PostfixOperator :
523532 case SyntaxKind . BinaryExpression :
524533 case SyntaxKind . ConditionalExpression :
@@ -1659,7 +1668,7 @@ module ts {
16591668 // <T extends "">
16601669 //
16611670 // We do *not* want to consume the > as we're consuming the expression for "".
1662- node . expression = parseUnaryExpression ( ) ;
1671+ node . expression = parseUnaryExpressionOrHigher ( ) ;
16631672 }
16641673 }
16651674
@@ -2532,7 +2541,7 @@ module ts {
25322541 }
25332542
25342543 function parseBinaryExpressionOrHigher ( precedence : number ) : Expression {
2535- var leftOperand = parseUnaryExpression ( ) ;
2544+ var leftOperand = parseUnaryExpressionOrHigher ( ) ;
25362545 return parseBinaryExpressionRest ( precedence , leftOperand ) ;
25372546 }
25382547
@@ -2611,21 +2620,33 @@ module ts {
26112620 return finishNode ( node ) ;
26122621 }
26132622
2614- function parseUnaryExpression ( ) : Expression {
2623+ function parseUnaryExpressionOrHigher ( ) : Expression {
26152624 var pos = getNodePos ( ) ;
26162625 switch ( token ) {
26172626 case SyntaxKind . PlusToken :
26182627 case SyntaxKind . MinusToken :
26192628 case SyntaxKind . TildeToken :
26202629 case SyntaxKind . ExclamationToken :
2621- case SyntaxKind . DeleteKeyword :
2622- case SyntaxKind . TypeOfKeyword :
2623- case SyntaxKind . VoidKeyword :
26242630 case SyntaxKind . PlusPlusToken :
26252631 case SyntaxKind . MinusMinusToken :
26262632 var operator = token ;
26272633 nextToken ( ) ;
2628- return makeUnaryExpression ( SyntaxKind . PrefixOperator , pos , operator , parseUnaryExpression ( ) ) ;
2634+ return makeUnaryExpression ( SyntaxKind . PrefixUnaryExpression , pos , operator , parseUnaryExpressionOrHigher ( ) ) ;
2635+ case SyntaxKind . DeleteKeyword :
2636+ var node = < DeleteExpression > createNode ( SyntaxKind . DeleteExpression ) ;
2637+ nextToken ( ) ;
2638+ node . expression = parseUnaryExpressionOrHigher ( ) ;
2639+ return finishNode ( node ) ;
2640+ case SyntaxKind . TypeOfKeyword :
2641+ var node = < TypeOfExpression > createNode ( SyntaxKind . TypeOfExpression ) ;
2642+ nextToken ( ) ;
2643+ node . expression = parseUnaryExpressionOrHigher ( ) ;
2644+ return finishNode ( node ) ;
2645+ case SyntaxKind . VoidKeyword :
2646+ var node = < VoidExpression > createNode ( SyntaxKind . VoidExpression ) ;
2647+ nextToken ( ) ;
2648+ node . expression = parseUnaryExpressionOrHigher ( ) ;
2649+ return finishNode ( node ) ;
26292650 case SyntaxKind . LessThanToken :
26302651 return parseTypeAssertion ( ) ;
26312652 }
@@ -2659,7 +2680,7 @@ module ts {
26592680 parseExpected ( SyntaxKind . LessThanToken ) ;
26602681 node . type = parseType ( ) ;
26612682 parseExpected ( SyntaxKind . GreaterThanToken ) ;
2662- node . operand = parseUnaryExpression ( ) ;
2683+ node . operand = parseUnaryExpressionOrHigher ( ) ;
26632684 return finishNode ( node ) ;
26642685 }
26652686
@@ -4073,6 +4094,7 @@ module ts {
40734094 case SyntaxKind . ClassDeclaration : return checkClassDeclaration ( < ClassDeclaration > node ) ;
40744095 case SyntaxKind . ComputedPropertyName : return checkComputedPropertyName ( < ComputedPropertyName > node ) ;
40754096 case SyntaxKind . Constructor : return checkConstructor ( < ConstructorDeclaration > node ) ;
4097+ case SyntaxKind . DeleteExpression : return checkDeleteExpression ( < DeleteExpression > node ) ;
40764098 case SyntaxKind . ExportAssignment : return checkExportAssignment ( < ExportAssignment > node ) ;
40774099 case SyntaxKind . ForInStatement : return checkForInStatement ( < ForInStatement > node ) ;
40784100 case SyntaxKind . ForStatement : return checkForStatement ( < ForStatement > node ) ;
@@ -4089,7 +4111,7 @@ module ts {
40894111 case SyntaxKind . NumericLiteral : return checkNumericLiteral ( < LiteralExpression > node ) ;
40904112 case SyntaxKind . Parameter : return checkParameter ( < ParameterDeclaration > node ) ;
40914113 case SyntaxKind . PostfixOperator : return checkPostfixOperator ( < UnaryExpression > node ) ;
4092- case SyntaxKind . PrefixOperator : return checkPrefixOperator ( < UnaryExpression > node ) ;
4114+ case SyntaxKind . PrefixUnaryExpression : return checkPrefixOperator ( < UnaryExpression > node ) ;
40934115 case SyntaxKind . Property : return checkProperty ( < PropertyDeclaration > node ) ;
40944116 case SyntaxKind . PropertyAssignment : return checkPropertyAssignment ( < PropertyDeclaration > node ) ;
40954117 case SyntaxKind . ReturnStatement : return checkReturnStatement ( < ReturnStatement > node ) ;
@@ -4355,6 +4377,19 @@ module ts {
43554377 }
43564378 }
43574379
4380+ function checkDeleteExpression ( node : DeleteExpression ) {
4381+ if ( node . parserContextFlags & ParserContextFlags . StrictMode ) {
4382+ // The identifier eval or arguments may not appear as the LeftHandSideExpression of an
4383+ // Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression
4384+ // operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator
4385+ if ( node . expression . kind === SyntaxKind . Identifier ) {
4386+ // When a delete operator occurs within strict mode code, a SyntaxError is thrown if its
4387+ // UnaryExpression is a direct reference to a variable, function argument, or function name
4388+ return grammarErrorOnNode ( node . expression , Diagnostics . delete_cannot_be_called_on_an_identifier_in_strict_mode ) ;
4389+ }
4390+ }
4391+ }
4392+
43584393 function checkEnumDeclaration ( enumDecl : EnumDeclaration ) : boolean {
43594394 var enumIsConst = ( enumDecl . flags & NodeFlags . Const ) !== 0 ;
43604395
@@ -4396,7 +4431,7 @@ module ts {
43964431 return / ^ [ 0 - 9 ] + ( [ e E ] \+ ? [ 0 - 9 ] + ) ? $ / . test ( literalExpression . text ) ;
43974432 }
43984433
4399- if ( expression . kind === SyntaxKind . PrefixOperator ) {
4434+ if ( expression . kind === SyntaxKind . PrefixUnaryExpression ) {
44004435 var unaryExpression = < UnaryExpression > expression ;
44014436 if ( unaryExpression . operator === SyntaxKind . PlusToken || unaryExpression . operator === SyntaxKind . MinusToken ) {
44024437 expression = unaryExpression . operand ;
@@ -4872,11 +4907,6 @@ module ts {
48724907 if ( ( node . operator === SyntaxKind . PlusPlusToken || node . operator === SyntaxKind . MinusMinusToken ) && isEvalOrArgumentsIdentifier ( node . operand ) ) {
48734908 return reportInvalidUseInStrictMode ( < Identifier > node . operand ) ;
48744909 }
4875- else if ( node . operator === SyntaxKind . DeleteKeyword && node . operand . kind === SyntaxKind . Identifier ) {
4876- // When a delete operator occurs within strict mode code, a SyntaxError is thrown if its
4877- // UnaryExpression is a direct reference to a variable, function argument, or function name
4878- return grammarErrorOnNode ( node . operand , Diagnostics . delete_cannot_be_called_on_an_identifier_in_strict_mode ) ;
4879- }
48804910 }
48814911 }
48824912
0 commit comments