mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
use operator token when checking unary expressions in strict mode
This commit is contained in:
parent
8be8e1f5be
commit
ef6a87cdfb
@ -2174,10 +2174,10 @@ module ts {
|
||||
// The identifier eval or arguments may not appear as the LeftHandSideExpression of an
|
||||
// Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression
|
||||
// operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator
|
||||
if ((token === SyntaxKind.PlusPlusToken || token === SyntaxKind.MinusMinusToken) && isEvalOrArgumentsIdentifier(operand)) {
|
||||
if ((operator === SyntaxKind.PlusPlusToken || operator === SyntaxKind.MinusMinusToken) && isEvalOrArgumentsIdentifier(operand)) {
|
||||
reportInvalidUseInStrictMode(<Identifier>operand);
|
||||
}
|
||||
else if (token === SyntaxKind.DeleteKeyword && operand.kind === SyntaxKind.Identifier) {
|
||||
else if (operator === SyntaxKind.DeleteKeyword && operand.kind === SyntaxKind.Identifier) {
|
||||
// When a delete operator occurs within strict mode code, a SyntaxError is thrown if its
|
||||
// UnaryExpression is a direct reference to a variable, function argument, or function name
|
||||
grammarErrorOnNode(operand, Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode);
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
tests/cases/compiler/deleteOperatorInStrictMode.ts(3,8): error TS1102: 'delete' cannot be called on an identifier in strict mode.
|
||||
|
||||
|
||||
==== tests/cases/compiler/deleteOperatorInStrictMode.ts (1 errors) ====
|
||||
"use strict"
|
||||
var a;
|
||||
delete a;
|
||||
~
|
||||
!!! error TS1102: 'delete' cannot be called on an identifier in strict mode.
|
||||
@ -1,8 +1,11 @@
|
||||
tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode15.ts(2,8): error TS1102: 'delete' cannot be called on an identifier in strict mode.
|
||||
tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode15.ts(2,8): error TS2304: Cannot find name 'a'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode15.ts (1 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode15.ts (2 errors) ====
|
||||
"use strict";
|
||||
delete a;
|
||||
~
|
||||
!!! error TS1102: 'delete' cannot be called on an identifier in strict mode.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
@ -1,7 +0,0 @@
|
||||
//// [parserStrictMode15.ts]
|
||||
"use strict";
|
||||
delete a;
|
||||
|
||||
//// [parserStrictMode15.js]
|
||||
"use strict";
|
||||
delete a;
|
||||
@ -1,8 +1,11 @@
|
||||
tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts(2,3): error TS1100: Invalid use of 'eval' in strict mode.
|
||||
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.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts (1 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts (2 errors) ====
|
||||
"use strict";
|
||||
++eval;
|
||||
~~~~
|
||||
!!! error TS1100: Invalid use of 'eval' in strict mode.
|
||||
~~~~
|
||||
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
|
||||
@ -1,7 +0,0 @@
|
||||
//// [parserStrictMode7.ts]
|
||||
"use strict";
|
||||
++eval;
|
||||
|
||||
//// [parserStrictMode7.js]
|
||||
"use strict";
|
||||
++eval;
|
||||
@ -0,0 +1,62 @@
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(3,3): error TS1100: Invalid use of 'eval' in strict mode.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(4,3): error TS1100: Invalid use of 'eval' in strict mode.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(5,3): error TS1100: Invalid use of 'arguments' in strict mode.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(6,3): error TS1100: Invalid use of 'arguments' in strict mode.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(7,1): error TS1100: Invalid use of 'eval' in strict mode.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(8,1): error TS1100: Invalid use of 'eval' in strict mode.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(9,1): error TS1100: Invalid use of 'arguments' in strict mode.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(10,1): error TS1100: Invalid use of 'arguments' in strict mode.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(3,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(4,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(5,3): error TS2304: Cannot find name 'arguments'.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(6,3): error TS2304: Cannot find name 'arguments'.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(7,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(8,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(9,1): error TS2304: Cannot find name 'arguments'.
|
||||
tests/cases/compiler/unaryOperatorsInStrictMode.ts(10,1): error TS2304: Cannot find name 'arguments'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/unaryOperatorsInStrictMode.ts (16 errors) ====
|
||||
"use strict"
|
||||
|
||||
++eval;
|
||||
~~~~
|
||||
!!! error TS1100: Invalid use of 'eval' in strict mode.
|
||||
~~~~
|
||||
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
|
||||
--eval;
|
||||
~~~~
|
||||
!!! error TS1100: Invalid use of 'eval' in strict mode.
|
||||
~~~~
|
||||
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
|
||||
++arguments;
|
||||
~~~~~~~~~
|
||||
!!! error TS1100: Invalid use of 'arguments' in strict mode.
|
||||
~~~~~~~~~
|
||||
!!! error TS2304: Cannot find name 'arguments'.
|
||||
--arguments;
|
||||
~~~~~~~~~
|
||||
!!! error TS1100: Invalid use of 'arguments' in strict mode.
|
||||
~~~~~~~~~
|
||||
!!! error TS2304: Cannot find name 'arguments'.
|
||||
eval++;
|
||||
~~~~
|
||||
!!! error TS1100: Invalid use of 'eval' in strict mode.
|
||||
~~~~
|
||||
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
|
||||
eval--;
|
||||
~~~~
|
||||
!!! error TS1100: Invalid use of 'eval' in strict mode.
|
||||
~~~~
|
||||
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
|
||||
arguments++;
|
||||
~~~~~~~~~
|
||||
!!! error TS1100: Invalid use of 'arguments' in strict mode.
|
||||
~~~~~~~~~
|
||||
!!! error TS2304: Cannot find name 'arguments'.
|
||||
arguments--;
|
||||
~~~~~~~~~
|
||||
!!! error TS1100: Invalid use of 'arguments' in strict mode.
|
||||
~~~~~~~~~
|
||||
!!! error TS2304: Cannot find name 'arguments'.
|
||||
|
||||
3
tests/cases/compiler/deleteOperatorInStrictMode.ts
Normal file
3
tests/cases/compiler/deleteOperatorInStrictMode.ts
Normal file
@ -0,0 +1,3 @@
|
||||
"use strict"
|
||||
var a;
|
||||
delete a;
|
||||
10
tests/cases/compiler/unaryOperatorsInStrictMode.ts
Normal file
10
tests/cases/compiler/unaryOperatorsInStrictMode.ts
Normal file
@ -0,0 +1,10 @@
|
||||
"use strict"
|
||||
|
||||
++eval;
|
||||
--eval;
|
||||
++arguments;
|
||||
--arguments;
|
||||
eval++;
|
||||
eval--;
|
||||
arguments++;
|
||||
arguments--;
|
||||
Loading…
x
Reference in New Issue
Block a user