Skip to content

Commit ef6a87c

Browse files
committed
use operator token when checking unary expressions in strict mode
1 parent 8be8e1f commit ef6a87c

9 files changed

+94
-18
lines changed

src/compiler/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,10 +2174,10 @@ module ts {
21742174
// The identifier eval or arguments may not appear as the LeftHandSideExpression of an
21752175
// Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression
21762176
// operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator
2177-
if ((token === SyntaxKind.PlusPlusToken || token === SyntaxKind.MinusMinusToken) && isEvalOrArgumentsIdentifier(operand)) {
2177+
if ((operator === SyntaxKind.PlusPlusToken || operator === SyntaxKind.MinusMinusToken) && isEvalOrArgumentsIdentifier(operand)) {
21782178
reportInvalidUseInStrictMode(<Identifier>operand);
21792179
}
2180-
else if (token === SyntaxKind.DeleteKeyword && operand.kind === SyntaxKind.Identifier) {
2180+
else if (operator === SyntaxKind.DeleteKeyword && operand.kind === SyntaxKind.Identifier) {
21812181
// When a delete operator occurs within strict mode code, a SyntaxError is thrown if its
21822182
// UnaryExpression is a direct reference to a variable, function argument, or function name
21832183
grammarErrorOnNode(operand, Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/compiler/deleteOperatorInStrictMode.ts(3,8): error TS1102: 'delete' cannot be called on an identifier in strict mode.
2+
3+
4+
==== tests/cases/compiler/deleteOperatorInStrictMode.ts (1 errors) ====
5+
"use strict"
6+
var a;
7+
delete a;
8+
~
9+
!!! error TS1102: 'delete' cannot be called on an identifier in strict mode.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode15.ts(2,8): error TS1102: 'delete' cannot be called on an identifier in strict mode.
12
tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode15.ts(2,8): error TS2304: Cannot find name 'a'.
23

34

4-
==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode15.ts (1 errors) ====
5+
==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode15.ts (2 errors) ====
56
"use strict";
67
delete a;
78
~
9+
!!! error TS1102: 'delete' cannot be called on an identifier in strict mode.
10+
~
811
!!! error TS2304: Cannot find name 'a'.

tests/baselines/reference/parserStrictMode15.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts(2,3): error TS1100: Invalid use of 'eval' in strict mode.
12
tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts(2,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
23

34

4-
==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts (1 errors) ====
5+
==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts (2 errors) ====
56
"use strict";
67
++eval;
78
~~~~
9+
!!! error TS1100: Invalid use of 'eval' in strict mode.
10+
~~~~
811
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.

tests/baselines/reference/parserStrictMode7.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(3,3): error TS1100: Invalid use of 'eval' in strict mode.
2+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(4,3): error TS1100: Invalid use of 'eval' in strict mode.
3+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(5,3): error TS1100: Invalid use of 'arguments' in strict mode.
4+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(6,3): error TS1100: Invalid use of 'arguments' in strict mode.
5+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(7,1): error TS1100: Invalid use of 'eval' in strict mode.
6+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(8,1): error TS1100: Invalid use of 'eval' in strict mode.
7+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(9,1): error TS1100: Invalid use of 'arguments' in strict mode.
8+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(10,1): error TS1100: Invalid use of 'arguments' in strict mode.
9+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(3,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
10+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(4,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
11+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(5,3): error TS2304: Cannot find name 'arguments'.
12+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(6,3): error TS2304: Cannot find name 'arguments'.
13+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(7,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
14+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(8,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
15+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(9,1): error TS2304: Cannot find name 'arguments'.
16+
tests/cases/compiler/unaryOperatorsInStrictMode.ts(10,1): error TS2304: Cannot find name 'arguments'.
17+
18+
19+
==== tests/cases/compiler/unaryOperatorsInStrictMode.ts (16 errors) ====
20+
"use strict"
21+
22+
++eval;
23+
~~~~
24+
!!! error TS1100: Invalid use of 'eval' in strict mode.
25+
~~~~
26+
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
27+
--eval;
28+
~~~~
29+
!!! error TS1100: Invalid use of 'eval' in strict mode.
30+
~~~~
31+
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
32+
++arguments;
33+
~~~~~~~~~
34+
!!! error TS1100: Invalid use of 'arguments' in strict mode.
35+
~~~~~~~~~
36+
!!! error TS2304: Cannot find name 'arguments'.
37+
--arguments;
38+
~~~~~~~~~
39+
!!! error TS1100: Invalid use of 'arguments' in strict mode.
40+
~~~~~~~~~
41+
!!! error TS2304: Cannot find name 'arguments'.
42+
eval++;
43+
~~~~
44+
!!! error TS1100: Invalid use of 'eval' in strict mode.
45+
~~~~
46+
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
47+
eval--;
48+
~~~~
49+
!!! error TS1100: Invalid use of 'eval' in strict mode.
50+
~~~~
51+
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
52+
arguments++;
53+
~~~~~~~~~
54+
!!! error TS1100: Invalid use of 'arguments' in strict mode.
55+
~~~~~~~~~
56+
!!! error TS2304: Cannot find name 'arguments'.
57+
arguments--;
58+
~~~~~~~~~
59+
!!! error TS1100: Invalid use of 'arguments' in strict mode.
60+
~~~~~~~~~
61+
!!! error TS2304: Cannot find name 'arguments'.
62+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"use strict"
2+
var a;
3+
delete a;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict"
2+
3+
++eval;
4+
--eval;
5+
++arguments;
6+
--arguments;
7+
eval++;
8+
eval--;
9+
arguments++;
10+
arguments--;

0 commit comments

Comments
 (0)