Improve decorator on overload error message (fixes #6064)

This commit is contained in:
Tim Perry
2015-12-17 11:56:02 +01:00
parent 55d4f0f7e4
commit 411e90df44
5 changed files with 48 additions and 1 deletions
+6 -1
View File
@@ -15544,7 +15544,12 @@ namespace ts {
return false;
}
if (!nodeCanBeDecorated(node)) {
return grammarErrorOnFirstToken(node, Diagnostics.Decorators_are_not_valid_here);
if (node.kind === SyntaxKind.MethodDeclaration && !ts.nodeIsPresent((<MethodDeclaration>node).body)) {
return grammarErrorOnFirstToken(node, Diagnostics.A_decorator_can_only_decorate_a_method_implementation_not_an_overload);
}
else {
return grammarErrorOnFirstToken(node, Diagnostics.Decorators_are_not_valid_here);
}
}
else if (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor) {
const accessors = getAllAccessorDeclarations((<ClassDeclaration>node.parent).members, <AccessorDeclaration>node);
+4
View File
@@ -795,6 +795,10 @@
"category": "Error",
"code": 1248
},
"A decorator can only decorate a method implementation, not an overload.": {
"category": "Error",
"code": 1249
},
"'with' statements are not allowed in an async function block.": {
"category": "Error",
"code": 1300
@@ -0,0 +1,13 @@
tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload1.ts(4,5): error TS1249: A decorator can only decorate a method implementation, not an overload.
==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload1.ts (1 errors) ====
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
class C {
@dec
~
!!! error TS1249: A decorator can only decorate a method implementation, not an overload.
method()
method() { }
}
@@ -0,0 +1,16 @@
//// [decoratorOnClassMethodOverload1.ts]
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
class C {
@dec
method()
method() { }
}
//// [decoratorOnClassMethodOverload1.js]
var C = (function () {
function C() {
}
C.prototype.method = function () { };
return C;
}());
@@ -0,0 +1,9 @@
// @target: ES5
// @experimentaldecorators: true
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
class C {
@dec
method()
method() { }
}