Skip to content

Commit b4e664a

Browse files
Added check to only not allow private name method signatures in anything except classes.
Changes objects literal checking to not bail on first private name found in object literal.
1 parent b43d5ea commit b4e664a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/compiler/checker.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -32224,6 +32224,11 @@ namespace ts {
3222432224
if (hasSyntacticModifier(node, ModifierFlags.Abstract) && node.kind === SyntaxKind.MethodDeclaration && node.body) {
3222532225
error(node, Diagnostics.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, declarationNameToString(node.name));
3222632226
}
32227+
32228+
// Private named methods are only allowed in class declarations
32229+
if (isPrivateIdentifier(node.name) && !isClassDeclaration(node.parent)) {
32230+
error(node, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies);
32231+
}
3222732232
}
3222832233

3222932234
function checkConstructorDeclaration(node: ConstructorDeclaration) {
@@ -40007,7 +40012,7 @@ namespace ts {
4000740012
}
4000840013

4000940014
if (name.kind === SyntaxKind.PrivateIdentifier) {
40010-
return grammarErrorOnNode(name, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies);
40015+
grammarErrorOnNode(name, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies);
4001140016
}
4001240017

4001340018
// Modifiers are never allowed on properties except for 'async' on a method declaration

0 commit comments

Comments
 (0)