Report a semantic error for an arrow function with a "this" parameter.

Fixes #9744.
This commit is contained in:
Matt McCutchen
2018-07-23 10:42:56 -04:00
parent 93722c8942
commit f72193eedc
8 changed files with 171 additions and 119 deletions

View File

@@ -21857,6 +21857,9 @@ namespace ts {
if (func.kind === SyntaxKind.Constructor || func.kind === SyntaxKind.ConstructSignature || func.kind === SyntaxKind.ConstructorType) {
error(node, Diagnostics.A_constructor_cannot_have_a_this_parameter);
}
if (func.kind === SyntaxKind.ArrowFunction) {
error(node, Diagnostics.An_arrow_function_cannot_have_a_this_parameter);
}
}
// Only check rest parameter type if it's not a binding pattern. Since binding patterns are

View File

@@ -2417,6 +2417,10 @@
"category": "Error",
"code": 2729
},
"An arrow function cannot have a 'this' parameter.": {
"category": "Error",
"code": 2730
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",

View File

@@ -3537,8 +3537,9 @@ namespace ts {
}
// If we had "(" followed by something that's not an identifier,
// then this definitely doesn't look like a lambda.
if (!isIdentifier()) {
// then this definitely doesn't look like a lambda. "this" is not
// valid, but we want to parse it and then give a semantic error.
if (!isIdentifier() && second !== SyntaxKind.ThisKeyword) {
return Tristate.False;
}