mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Merge pull request #12565 from Microsoft/aozgaa/abstractAccessorImpl
Aozgaa/abstract accessor impl
This commit is contained in:
commit
60c7340af6
@ -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);
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
17
tests/baselines/reference/classAbstractAccessor.errors.txt
Normal file
17
tests/baselines/reference/classAbstractAccessor.errors.txt
Normal 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.
|
||||
}
|
||||
|
||||
28
tests/baselines/reference/classAbstractAccessor.js
Normal file
28
tests/baselines/reference/classAbstractAccessor.js
Normal 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;
|
||||
}());
|
||||
@ -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
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user