Skip to content

Conversation

@exoticknight
Copy link
Contributor

Fixes #44269

@ghost
Copy link

ghost commented Jun 2, 2021

CLA assistant check
All CLA requirements met.

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Jun 2, 2021

const firstFunctionLikeContainerOrClassLikeContainer = findAncestor(node.parent, node => isClassLike(node) || isFunctionLike(node))!;
if (firstFunctionLikeContainerOrClassLikeContainer.kind === SyntaxKind.ClassExpression || firstFunctionLikeContainerOrClassLikeContainer.kind === SyntaxKind.ClassDeclaration) {
error(node, Diagnostics.arguments_is_not_allowed_in_class_field_initializer_or_static_initialization_block);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it should not execute the following two lines.

You should add

return errorType;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically there's an isInPropertyInitializer but the suggestions I've given seem cheaper.

"category": "Error",
"code": 2812
},
"'arguments' is not allowed in class field initializer or static initialization block.": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no static initialization block, right?

Suggested change
"'arguments' is not allowed in class field initializer or static initialization block.": {
"'arguments' cannot be referenced in property initializers.": {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, the error message is copied from Chrome. But Chrome does not support static initialization block either, that's strange.

}
}

const firstFunctionLikeContainerOrClassLikeContainer = findAncestor(node.parent, node => isClassLike(node) || isFunctionLike(node))!;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving this higher and reusing it for container

const firstFunctionLikeContainerOrClassLikeContainer = findAncestor(node.parent, node => isClassLike(node) || isFunctionLike(node))!;
const container = isClassLike(firstFunctionLikeContainerOrClassLikeContainer) ?
    findAncestor(firstFunctionLikeContainerOrClassLikeContainer.parent, isFunctionLike)! :
    firstFunctionLikeContainerOrClassLikeContainer;

@exoticknight
Copy link
Contributor Author

@DanielRosenwasser isInPropertyInitializer works well, thx for your review!

@exoticknight
Copy link
Contributor Author

only node14 failed,werid

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me -- what do you think @DanielRosenwasser ?

@exoticknight you can merge now from main to get diagnosticMessages up to date, or you can wait until @DanielRosenwasser signs off, it's up to you.

# Conflicts:
#	src/compiler/diagnosticMessages.json
@sandersn
Copy link
Member

I looked over the comment history and I think this is ready to go once CI finishes one more time.

@sandersn sandersn merged commit 9708022 into microsoft:main Jun 21, 2021
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Spec: 'arguments' is not allowed in class field initializer or static initialization block

5 participants