Skip to content

Improve error message TS1210 #44892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@ namespace ts {
// Provide specialized messages to help the user understand why we think they're in
// strict mode.
if (getContainingClass(node)) {
return Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode;
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;
}

if (file.externalModuleIndicator) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@
"category": "Error",
"code": 1208
},
"Invalid use of '{0}'. Class definitions are automatically in strict mode.": {
"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.": {
"category": "Error",
"code": 1210
},
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/classStaticBlock6.errors.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(8,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(9,13): error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode.
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.
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.
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(13,9): error TS18037: Await expression cannot be used inside a class static block.
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(13,14): error TS1109: Expression expected.
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(17,9): error TS2662: Cannot find name 'arguments'. Did you mean the static member 'C.arguments'?
Expand All @@ -25,10 +25,10 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(55,13): er
let await = 1;
let arguments = 1;
~~~~~~~~~
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
!!! 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.
let eval = 1;
~~~~
!!! error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode.
!!! 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.
}

static {
Expand Down

Large diffs are not rendered by default.

80 changes: 40 additions & 40 deletions tests/baselines/reference/collisionArgumentsClassMethod.errors.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments12.ts(2,7): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
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.
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.


==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments12.ts (2 errors) ====
class C {
f(arguments) {
~~~~~~~~~
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
!!! 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.
var a = () => arguments;
~~~~~~~~~
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments12_ES6.ts(2,7): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
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.


==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments12_ES6.ts (1 errors) ====
class C {
f(arguments) {
~~~~~~~~~
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
!!! 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.
var a = () => arguments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tests/cases/compiler/a.js(10,10): error TS1100: Invalid use of 'eval' in strict
tests/cases/compiler/a.js(12,10): error TS1100: Invalid use of 'arguments' in strict mode.
tests/cases/compiler/a.js(15,1): error TS1101: 'with' statements are not allowed in strict mode.
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'.
tests/cases/compiler/b.js(3,7): error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode.
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.
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.
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.
tests/cases/compiler/c.js(2,5): error TS1215: Invalid use of 'eval'. Modules are automatically in strict mode.
Expand Down Expand Up @@ -57,7 +57,7 @@ tests/cases/compiler/d.js(2,11): error TS1005: ',' expected.
class c {
a(eval) { //error
~~~~
!!! error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode.
!!! 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.
}
method() {
var let = 10; // error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(4,16): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(5,17): error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode.
tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
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.
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.
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.
tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS2322: Type 'string' is not assignable to type 'IArguments'.


Expand All @@ -10,13 +10,13 @@ tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeBy
public implements() { }
public foo(arguments: any) { }
~~~~~~~~~
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
!!! 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.
private bar(eval:any) {
~~~~
!!! error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode.
!!! 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.
arguments = "hello";
~~~~~~~~~
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
!!! 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.
~~~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'IArguments'.
}
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/parserRealSource11.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(504,58): error
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(506,22): error TS2304: Cannot find name 'NodeType'.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(507,58): error TS2304: Cannot find name 'TokenID'.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(518,32): error TS2304: Cannot find name 'NodeType'.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(520,29): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
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.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(525,27): error TS2304: Cannot find name 'Signature'.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(527,36): error TS2304: Cannot find name 'TypeFlow'.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(528,34): error TS2304: Cannot find name 'NodeType'.
Expand Down Expand Up @@ -241,7 +241,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(959,27): error
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(961,25): error TS2304: Cannot find name 'IHashTable'.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(963,27): error TS2304: Cannot find name 'Signature'.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(981,27): error TS2304: Cannot find name 'Type'.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(985,29): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
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.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1004,44): error TS2304: Cannot find name 'hasFlag'.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1004,67): error TS2304: Cannot find name 'FncFlags'.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1005,57): error TS2304: Cannot find name 'FncFlags'.
Expand Down Expand Up @@ -1263,7 +1263,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error
public target: AST,
public arguments: ASTList) {
~~~~~~~~~
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
!!! 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.
super(nodeType);
this.minChar = this.target.minChar;
}
Expand Down Expand Up @@ -1984,7 +1984,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error
constructor (public name: Identifier, public bod: ASTList, public isConstructor: boolean,
public arguments: ASTList, public vars: ASTList, public scopes: ASTList, public statics: ASTList,
~~~~~~~~~
!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode.
!!! 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.
nodeType: number) {

super(nodeType);
Expand Down