Last active
July 24, 2017 17:41
-
-
Save peey/de84842230a1dcae327f40dc6c1cdb9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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