-
Notifications
You must be signed in to change notification settings - Fork 14
Added support for static private fields accessors and methods. #50
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
Changes from 11 commits
5ebb3d6
7006c09
b876613
31a8c00
5a27a32
d2ab6fc
23f6c67
374e6f3
62b4f2f
b2a692d
363041e
64757e0
68a7f80
7e7b0b1
2834737
82de139
0b337f1
3d1c6e8
c497b48
f1c911b
5dbb110
0cf834c
6cd87d0
652199a
a8742e3
09a5aae
497e47f
7751ecb
8a81a67
15e69ac
3e05aa6
1f6a8d7
e234f0c
38fdce9
ca8d9e4
9862b03
f0a72e2
408c804
25375a2
612a96e
7394efc
ba56fca
f918bd9
f7cd702
4d50624
294cc48
027bdb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,6 +240,7 @@ namespace ts { | |
| SetAccessor = 2, | ||
| PropertyAssignment = 4, | ||
| Method = 8, | ||
| PrivateStatic = 16, | ||
| GetOrSetAccessor = GetAccessor | SetAccessor, | ||
| PropertyAssignmentOrMethod = PropertyAssignment | Method, | ||
| } | ||
|
|
@@ -32131,29 +32132,32 @@ namespace ts { | |
| const isStatic = hasSyntacticModifier(member, ModifierFlags.Static); | ||
| const name = member.name; | ||
| if (!name) { | ||
| return; | ||
| continue; | ||
| } | ||
| const isPrivate = isPrivateIdentifier(name); | ||
| const isPrivateStatic = isPrivate && isStatic ? DeclarationMeaning.PrivateStatic : 0; | ||
| const names = | ||
| isPrivateIdentifier(name) ? privateIdentifiers : | ||
| isPrivate ? privateIdentifiers : | ||
| isStatic ? staticNames : | ||
| instanceNames; | ||
|
|
||
| const memberName = name && getPropertyNameForPropertyNameNode(name); | ||
| if (memberName) { | ||
| switch (member.kind) { | ||
| case SyntaxKind.GetAccessor: | ||
| addName(names, name, memberName, DeclarationMeaning.GetAccessor); | ||
| addName(names, name, memberName, DeclarationMeaning.GetAccessor | isPrivateStatic); | ||
| break; | ||
|
|
||
| case SyntaxKind.SetAccessor: | ||
| addName(names, name, memberName, DeclarationMeaning.SetAccessor); | ||
| addName(names, name, memberName, DeclarationMeaning.SetAccessor | isPrivateStatic); | ||
| break; | ||
|
|
||
| case SyntaxKind.PropertyDeclaration: | ||
| addName(names, name, memberName, DeclarationMeaning.GetOrSetAccessor); | ||
| addName(names, name, memberName, DeclarationMeaning.GetOrSetAccessor | isPrivateStatic); | ||
| break; | ||
|
|
||
| case SyntaxKind.MethodDeclaration: | ||
| addName(names, name, memberName, DeclarationMeaning.Method); | ||
| addName(names, name, memberName, DeclarationMeaning.Method | isPrivateStatic); | ||
| break; | ||
| } | ||
| } | ||
|
|
@@ -32163,16 +32167,25 @@ namespace ts { | |
| function addName(names: UnderscoreEscapedMap<DeclarationMeaning>, location: Node, name: __String, meaning: DeclarationMeaning) { | ||
| const prev = names.get(name); | ||
| if (prev) { | ||
| if (prev & DeclarationMeaning.Method) { | ||
| if (meaning !== DeclarationMeaning.Method) { | ||
| error(location, Diagnostics.Duplicate_identifier_0, getTextOfNode(location)); | ||
| } | ||
| } | ||
| else if (prev & meaning) { | ||
| error(location, Diagnostics.Duplicate_identifier_0, getTextOfNode(location)); | ||
| // For private identifiers, do not allow mixing of static and instance members with the same name | ||
| if ((prev & DeclarationMeaning.PrivateStatic) !== (meaning & DeclarationMeaning.PrivateStatic)) { | ||
| error(location, Diagnostics.Duplicate_identifier_0_Static_and_instance_elements_cannot_share_the_same_private_name, getTextOfNode(location)); | ||
| } | ||
| else { | ||
| names.set(name, prev | meaning); | ||
| const prevIsMethod = !!(prev & DeclarationMeaning.Method); | ||
| const isMethod = !!(meaning & DeclarationMeaning.Method); | ||
| if (prevIsMethod || isMethod) { | ||
| if (prevIsMethod !== isMethod) { | ||
| error(location, Diagnostics.Duplicate_identifier_0, getTextOfNode(location)); | ||
| } | ||
| // If this is a method/method duplication is might be an overload, so this will be handled when overloads are considered | ||
| } | ||
| else if (prev & meaning & ~DeclarationMeaning.PrivateStatic) { | ||
| error(location, Diagnostics.Duplicate_identifier_0, getTextOfNode(location)); | ||
| } | ||
| else { | ||
| names.set(name, prev | meaning); | ||
| } | ||
| } | ||
| } | ||
| else { | ||
|
|
@@ -32296,6 +32309,9 @@ namespace ts { | |
| getNodeLinks(lexicalScope).flags |= NodeCheckFlags.ContainsClassWithPrivateIdentifiers; | ||
| } | ||
| } | ||
| if (isPrivateIdentifier(node.name) && hasStaticModifier(node) && node.initializer && languageVersion === ScriptTarget.ESNext && !compilerOptions.useDefineForClassFields) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line will need to be updated to use
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. After we get that in we should do a merge and do a sweep for |
||
| error(node.initializer, Diagnostics.Static_fields_with_private_names_can_t_have_initializers_when_the_useDefineForClassFields_flag_is_not_specified_with_a_target_of_esnext_Consider_adding_the_useDefineForClassFields_flag); | ||
| } | ||
| } | ||
|
|
||
| function checkPropertySignature(node: PropertySignature) { | ||
|
|
@@ -36030,6 +36046,9 @@ namespace ts { | |
| } | ||
|
|
||
| function checkClassDeclaration(node: ClassDeclaration) { | ||
| if (some(node.decorators) && some(node.members, p => hasStaticModifier(p) && isPrivateIdentifierClassElementDeclaration(p))) { | ||
| grammarErrorOnNode(node.decorators[0], Diagnostics.Class_decorators_can_t_be_used_with_static_private_identifier_Consider_removing_the_experimental_decorator); | ||
| } | ||
| if (!node.name && !hasSyntacticModifier(node, ModifierFlags.Default)) { | ||
| grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); | ||
| } | ||
|
|
@@ -39586,9 +39605,6 @@ namespace ts { | |
| else if (flags & ModifierFlags.Abstract) { | ||
| return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "abstract"); | ||
| } | ||
| else if (isPrivateIdentifierClassElementDeclaration(node)) { | ||
| return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_a_private_identifier, "static"); | ||
| } | ||
| flags |= ModifierFlags.Static; | ||
| lastStatic = modifier; | ||
| break; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.