Merge pull request #6129 from pimterry/decorator-overload-msg

Improve decorator on overload error message
This commit is contained in:
Daniel Rosenwasser 2015-12-21 13:30:46 -08:00
commit ee50adbc85
5 changed files with 48 additions and 1 deletions

View File

@ -15563,7 +15563,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);

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

View File

@ -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() { }
}

View File

@ -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;
}());

View File

@ -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() { }
}