-
Notifications
You must be signed in to change notification settings - Fork 116
Closed
Labels
Description
While playing with decorators I found a little usability problem. I initially wrote this decorator:
function add(value) {
return function decorator(element) {
const { initializer } = element;
element.initializer = function() {
return initializer.call(this) + value;
};
};
}
class Foo {
@add(2) num = 3;
}When run, it throws Cannot read property "kind" of undefined.. It was my fault (I forgot to write return element; at the end of the decorator function), but it has been quite hard to spot.
I propose two ways of improving this:
- If the decorator function returns
undefined, throw an error. (After step 3.d of https://tc39.github.io/proposal-decorators/#sec-decorate-element) - If the decorator function returns
undefined, default toelementObject. This make it possible to just mutate the descriptor without returning it.
Reactions are currently unavailable