mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
arguments should not be allowed in class static block (#48172)
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
This commit is contained in:
co-authored by
Nathan Shively-Sanders
Jake Bailey
parent
11e7932759
commit
e37ca49c70
+11
-21
@@ -30738,8 +30738,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
// To avoid that we will give an error to users if they use arguments objects in arrow function so that they
|
||||
// can explicitly bound arguments objects
|
||||
if (symbol === argumentsSymbol) {
|
||||
if (isInPropertyInitializerOrClassStaticBlock(node)) {
|
||||
error(node, Diagnostics.arguments_cannot_be_referenced_in_property_initializers);
|
||||
if (isInPropertyInitializerOrClassStaticBlock(node, /*ignoreArrowFunctions*/ true)) {
|
||||
error(node, Diagnostics.arguments_cannot_be_referenced_in_property_initializers_or_class_static_initialization_blocks);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34788,31 +34788,21 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
}
|
||||
|
||||
function isInPropertyInitializerOrClassStaticBlock(node: Node): boolean {
|
||||
function isInPropertyInitializerOrClassStaticBlock(node: Node, ignoreArrowFunctions?: boolean): boolean {
|
||||
return !!findAncestor(node, node => {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.ClassStaticBlockDeclaration:
|
||||
return true;
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
case SyntaxKind.TemplateSpan:
|
||||
case SyntaxKind.JsxExpression:
|
||||
case SyntaxKind.JsxAttribute:
|
||||
case SyntaxKind.JsxAttributes:
|
||||
case SyntaxKind.JsxSpreadAttribute:
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
case SyntaxKind.HeritageClause:
|
||||
return false;
|
||||
case SyntaxKind.TypeQuery:
|
||||
case SyntaxKind.JsxClosingElement: // already reported in JsxOpeningElement
|
||||
return "quit";
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
return isBlock(node.parent) && isClassStaticBlockDeclaration(node.parent.parent) ? true : "quit";
|
||||
return ignoreArrowFunctions ? false : "quit";
|
||||
case SyntaxKind.Block:
|
||||
return isFunctionLikeDeclaration(node.parent) && node.parent.kind !== SyntaxKind.ArrowFunction ? "quit" : false;
|
||||
default:
|
||||
return isExpressionNode(node) ? false : "quit";
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3767,7 +3767,7 @@
|
||||
"category": "Error",
|
||||
"code": 2814
|
||||
},
|
||||
"'arguments' cannot be referenced in property initializers.": {
|
||||
"'arguments' cannot be referenced in property initializers or class static initialization blocks.": {
|
||||
"category": "Error",
|
||||
"code": 2815
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user