mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 11:35:42 -06:00
abstract accessors can't have implementations
This commit is contained in:
parent
1418fd170d
commit
3cd1731628
@ -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
|
||||
|
||||
22
tests/baselines/reference/classAbstractAccessor.errors.txt
Normal file
22
tests/baselines/reference/classAbstractAccessor.errors.txt
Normal 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.
|
||||
}
|
||||
|
||||
27
tests/baselines/reference/classAbstractAccessor.js
Normal file
27
tests/baselines/reference/classAbstractAccessor.js
Normal 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;
|
||||
}());
|
||||
@ -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
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user