Skip to content

Instantly share code, notes, and snippets.

@peey peey/legacy-output.js
Last active Jul 24, 2017

Embed
What would you like to do?
// input
@decorator class Bizz {
@dec m1() {};
@bar @foo.bar(baz) m2() {};
@dec static 3 () {};
}
// output
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
var desc = {};
Object['ke' + 'ys'](descriptor).forEach(function (key) {
desc[key] = descriptor[key];
});
desc.enumerable = !!desc.enumerable;
desc.configurable = !!desc.configurable;
if ('value' in desc || desc.initializer) {
desc.writable = true;
}
desc = decorators.slice().reverse().reduce(function (desc, decorator) {
return decorator(target, property, desc) || desc;
}, desc);
if (context && desc.initializer !== void 0) {
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
desc.initializer = undefined;
}
if (desc.initializer === void 0) {
Object['define' + 'Property'](target, property, desc);
desc = null;
}
return desc;
}
let Bizz = (_dec = foo.bar(baz), decorator(_class = (_class2 = class Bizz {
m1() {}m2() {}static 3() {}
}, (_applyDecoratedDescriptor(_class2.prototype, "m1", [dec], Object.getOwnPropertyDescriptor(_class2.prototype, "m1"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "m2", [bar, _dec], Object.getOwnPropertyDescriptor(_class2.prototype, "m2"), _class2.prototype), _applyDecoratedDescriptor(_class2, 3, [dec], Object.getOwnPropertyDescriptor(_class2, 3), _class2)), _class2)) || _class);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.