mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 12:03:44 -05:00
Add abstract properties and accessors
Almost all the infrastructure is in place, so I just allowed abstract properties+accessors and added an error when abstract accessors do not have the same abstractness specified.
This commit is contained in:
@@ -12051,6 +12051,9 @@ namespace ts {
|
||||
if (((node.flags & NodeFlags.AccessibilityModifier) !== (otherAccessor.flags & NodeFlags.AccessibilityModifier))) {
|
||||
error(node.name, Diagnostics.Getter_and_setter_accessors_do_not_agree_in_visibility);
|
||||
}
|
||||
if (((node.flags & NodeFlags.Abstract) !== (otherAccessor.flags & NodeFlags.Abstract))) {
|
||||
error(node.name, Diagnostics.Accessors_must_both_be_abstract_or_not_abstract);
|
||||
}
|
||||
|
||||
const currentAccessorType = getAnnotatedAccessorType(node);
|
||||
const otherAccessorType = getAnnotatedAccessorType(otherAccessor);
|
||||
@@ -16498,8 +16501,11 @@ namespace ts {
|
||||
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "abstract");
|
||||
}
|
||||
if (node.kind !== SyntaxKind.ClassDeclaration) {
|
||||
if (node.kind !== SyntaxKind.MethodDeclaration) {
|
||||
return grammarErrorOnNode(modifier, Diagnostics.abstract_modifier_can_only_appear_on_a_class_or_method_declaration);
|
||||
if (node.kind !== SyntaxKind.MethodDeclaration &&
|
||||
node.kind !== SyntaxKind.PropertyDeclaration &&
|
||||
node.kind !== SyntaxKind.GetAccessor &&
|
||||
node.kind !== SyntaxKind.SetAccessor) {
|
||||
return grammarErrorOnNode(modifier, Diagnostics.abstract_modifier_can_only_appear_on_a_class_method_or_property_declaration);
|
||||
}
|
||||
if (!(node.parent.kind === SyntaxKind.ClassDeclaration && node.parent.flags & NodeFlags.Abstract)) {
|
||||
return grammarErrorOnNode(modifier, Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class);
|
||||
@@ -16993,7 +16999,7 @@ namespace ts {
|
||||
else if (isInAmbientContext(accessor)) {
|
||||
return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
|
||||
}
|
||||
else if (accessor.body === undefined) {
|
||||
else if (accessor.body === undefined && !(accessor.flags & NodeFlags.Abstract)) {
|
||||
return grammarErrorAtPos(getSourceFileOfNode(accessor), accessor.end - 1, ";".length, Diagnostics._0_expected, "{");
|
||||
}
|
||||
else if (accessor.typeParameters) {
|
||||
|
||||
@@ -779,7 +779,7 @@
|
||||
"category": "Error",
|
||||
"code": 1241
|
||||
},
|
||||
"'abstract' modifier can only appear on a class or method declaration.": {
|
||||
"'abstract' modifier can only appear on a class, method, or property declaration.": {
|
||||
"category": "Error",
|
||||
"code": 1242
|
||||
},
|
||||
@@ -1843,6 +1843,10 @@
|
||||
"category": "Error",
|
||||
"code": 2675
|
||||
},
|
||||
"Accessors must both be abstract or not abstract.": {
|
||||
"category": "Error",
|
||||
"code": 2676
|
||||
},
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4000
|
||||
|
||||
Reference in New Issue
Block a user