Take a look at this Babel test:
function decorate(el) {
el.descriptor.value.decorated = true;
return el;
}
class A {
@decorate
method() {
return 1;
}
method() {
return 2;
}
}
expect(new A().method.decorated).toBe(true);
expect(new A().method()).toBe(2);
Per the current spec, if an element is overwritten by an element with the same name, the value is replaced but the old decorators are kept.
I find it very confusing that the method passed to the decorator isthe second one and not the first one, I think it would be better to throw.
The same motivation doesn't apply to the following example example, but I think it should also throw to avoid refactoring hazards.
class A {
method() {
return 1;
}
@decorate
method() {
return 2;
}
}