Skip to content

Commit 7753efa

Browse files
Improve error message TS1210 (#44892)
1 parent cce2e92 commit 7753efa

10 files changed

+110
-110
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,7 @@ namespace ts {
22942294
// Provide specialized messages to help the user understand why we think they're in
22952295
// strict mode.
22962296
if (getContainingClass(node)) {
2297-
return Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode;
2297+
return Diagnostics.Code_contained_in_a_class_is_evaluated_in_JavaScript_s_strict_mode_which_does_not_allow_this_use_of_0_For_more_information_see_https_Colon_Slash_Slashdeveloper_mozilla_org_Slashen_US_Slashdocs_SlashWeb_SlashJavaScript_SlashReference_SlashStrict_mode;
22982298
}
22992299

23002300
if (file.externalModuleIndicator) {

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@
663663
"category": "Error",
664664
"code": 1208
665665
},
666-
"Invalid use of '{0}'. Class definitions are automatically in strict mode.": {
666+
"Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of '{0}'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.": {
667667
"category": "Error",
668668
"code": 1210
669669
},

tests/baselines/reference/classStaticBlock6.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(8,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
2-
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(9,13): error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode.
1+
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(8,13): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
2+
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(9,13): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'eval'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
33
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(13,9): error TS18037: Await expression cannot be used inside a class static block.
44
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(13,14): error TS1109: Expression expected.
55
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(17,9): error TS2662: Cannot find name 'arguments'. Did you mean the static member 'C.arguments'?
@@ -25,10 +25,10 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(55,13): er
2525
let await = 1;
2626
let arguments = 1;
2727
~~~~~~~~~
28-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
28+
!!! error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
2929
let eval = 1;
3030
~~~~
31-
!!! error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode.
31+
!!! error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'eval'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
3232
}
3333

3434
static {

tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt

Lines changed: 48 additions & 48 deletions
Large diffs are not rendered by default.

tests/baselines/reference/collisionArgumentsClassMethod.errors.txt

Lines changed: 40 additions & 40 deletions
Large diffs are not rendered by default.

tests/baselines/reference/emitArrowFunctionWhenUsingArguments12.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments12.ts(2,7): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
1+
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments12.ts(2,7): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
22
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments12.ts(3,23): error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
33

44

55
==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments12.ts (2 errors) ====
66
class C {
77
f(arguments) {
88
~~~~~~~~~
9-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
9+
!!! error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
1010
var a = () => arguments;
1111
~~~~~~~~~
1212
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments12_ES6.ts(2,7): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
1+
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments12_ES6.ts(2,7): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
22

33

44
==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments12_ES6.ts (1 errors) ====
55
class C {
66
f(arguments) {
77
~~~~~~~~~
8-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
8+
!!! error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
99
var a = () => arguments;
1010
}
1111
}

tests/baselines/reference/jsFileCompilationBindStrictModeErrors.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tests/cases/compiler/a.js(10,10): error TS1100: Invalid use of 'eval' in strict
77
tests/cases/compiler/a.js(12,10): error TS1100: Invalid use of 'arguments' in strict mode.
88
tests/cases/compiler/a.js(15,1): error TS1101: 'with' statements are not allowed in strict mode.
99
tests/cases/compiler/a.js(15,1): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
10-
tests/cases/compiler/b.js(3,7): error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode.
10+
tests/cases/compiler/b.js(3,7): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'eval'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
1111
tests/cases/compiler/b.js(6,13): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode.
1212
tests/cases/compiler/c.js(1,12): error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
1313
tests/cases/compiler/c.js(2,5): error TS1215: Invalid use of 'eval'. Modules are automatically in strict mode.
@@ -57,7 +57,7 @@ tests/cases/compiler/d.js(2,11): error TS1005: ',' expected.
5757
class c {
5858
a(eval) { //error
5959
~~~~
60-
!!! error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode.
60+
!!! error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'eval'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
6161
}
6262
method() {
6363
var let = 10; // error

tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(4,16): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
2-
tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(5,17): error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode.
3-
tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
1+
tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(4,16): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
2+
tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(5,17): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'eval'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
3+
tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
44
tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS2322: Type 'string' is not assignable to type 'IArguments'.
55

66

@@ -10,13 +10,13 @@ tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeBy
1010
public implements() { }
1111
public foo(arguments: any) { }
1212
~~~~~~~~~
13-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
13+
!!! error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
1414
private bar(eval:any) {
1515
~~~~
16-
!!! error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode.
16+
!!! error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'eval'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
1717
arguments = "hello";
1818
~~~~~~~~~
19-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
19+
!!! error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
2020
~~~~~~~~~
2121
!!! error TS2322: Type 'string' is not assignable to type 'IArguments'.
2222
}

tests/baselines/reference/parserRealSource11.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(504,58): error
113113
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(506,22): error TS2304: Cannot find name 'NodeType'.
114114
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(507,58): error TS2304: Cannot find name 'TokenID'.
115115
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(518,32): error TS2304: Cannot find name 'NodeType'.
116-
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(520,29): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
116+
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(520,29): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
117117
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(525,27): error TS2304: Cannot find name 'Signature'.
118118
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(527,36): error TS2304: Cannot find name 'TypeFlow'.
119119
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(528,34): error TS2304: Cannot find name 'NodeType'.
@@ -241,7 +241,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(959,27): error
241241
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(961,25): error TS2304: Cannot find name 'IHashTable'.
242242
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(963,27): error TS2304: Cannot find name 'Signature'.
243243
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(981,27): error TS2304: Cannot find name 'Type'.
244-
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(985,29): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
244+
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(985,29): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
245245
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1004,44): error TS2304: Cannot find name 'hasFlag'.
246246
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1004,67): error TS2304: Cannot find name 'FncFlags'.
247247
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1005,57): error TS2304: Cannot find name 'FncFlags'.
@@ -1263,7 +1263,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error
12631263
public target: AST,
12641264
public arguments: ASTList) {
12651265
~~~~~~~~~
1266-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
1266+
!!! error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
12671267
super(nodeType);
12681268
this.minChar = this.target.minChar;
12691269
}
@@ -1984,7 +1984,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error
19841984
constructor (public name: Identifier, public bod: ASTList, public isConstructor: boolean,
19851985
public arguments: ASTList, public vars: ASTList, public scopes: ASTList, public statics: ASTList,
19861986
~~~~~~~~~
1987-
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
1987+
!!! error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
19881988
nodeType: number) {
19891989

19901990
super(nodeType);

0 commit comments

Comments
 (0)