abstract accessors can't have implementations

This commit is contained in:
Arthur Ozga 2016-11-29 15:59:28 -06:00
parent 1418fd170d
commit 3cd1731628
5 changed files with 62 additions and 0 deletions

View File

@ -21239,6 +21239,9 @@ namespace ts {
else if (accessor.body === undefined && !(getModifierFlags(accessor) & ModifierFlags.Abstract)) {
return grammarErrorAtPos(getSourceFileOfNode(accessor), accessor.end - 1, ";".length, Diagnostics._0_expected, "{");
}
else if (accessor.body && getModifierFlags(accessor) & ModifierFlags.Abstract) {
return grammarErrorOnNode(accessor, Diagnostics.An_abstract_accessor_cannot_have_an_implementation);
}
else if (accessor.typeParameters) {
return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_have_type_parameters);
}

View File

@ -851,6 +851,10 @@
"category": "Error",
"code": 1317
},
"An abstract accessor cannot have an implementation.": {
"category": "Error",
"code": 1318
},
"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300

View File

@ -0,0 +1,22 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(2,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(3,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(4,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(5,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts (4 errors) ====
abstract class A {
abstract get a();
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
abstract get aa() { return 1; } // error
~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
abstract set b(x: string);
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
abstract set bb(x: string) {} // error
~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
}

View File

@ -0,0 +1,27 @@
//// [classAbstractAccessor.ts]
abstract class A {
abstract get a();
abstract get aa() { return 1; } // error
abstract set b(x: string);
abstract set bb(x: string) {} // error
}
//// [classAbstractAccessor.js]
var A = (function () {
function A() {
}
Object.defineProperty(A.prototype, "aa", {
get: function () { return 1; } // error
,
enumerable: true,
configurable: true
});
Object.defineProperty(A.prototype, "bb", {
set: function (x) { } // error
,
enumerable: true,
configurable: true
});
return A;
}());

View File

@ -0,0 +1,6 @@
abstract class A {
abstract get a();
abstract get aa() { return 1; } // error
abstract set b(x: string);
abstract set bb(x: string) {} // error
}