Merge pull request #12565 from Microsoft/aozgaa/abstractAccessorImpl

Aozgaa/abstract accessor impl
This commit is contained in:
Arthur Ozga 2016-11-29 17:52:26 -06:00 committed by GitHub
commit 60c7340af6
5 changed files with 60 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,17 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(4,17): error TS1318: An abstract accessor cannot have an implementation.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(6,17): error TS1318: An abstract accessor cannot have an implementation.
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts (2 errors) ====
abstract class A {
abstract get a();
abstract get aa() { return 1; } // error
~~
!!! error TS1318: An abstract accessor cannot have an implementation.
abstract set b(x: string);
abstract set bb(x: string) {} // error
~~
!!! error TS1318: An abstract accessor cannot have an implementation.
}

View File

@ -0,0 +1,28 @@
//// [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,8 @@
// @target: es5
abstract class A {
abstract get a();
abstract get aa() { return 1; } // error
abstract set b(x: string);
abstract set bb(x: string) {} // error
}