1 | import { addHiddenProp } from "./utils";
|
2 | export function decorateMethodOrField(decoratorName, decorateFn, target, prop, descriptor) {
|
3 | if (descriptor) {
|
4 | return decorateMethod(decoratorName, decorateFn, prop, descriptor);
|
5 | }
|
6 | else {
|
7 | decorateField(decorateFn, target, prop);
|
8 | }
|
9 | }
|
10 | export function decorateMethod(decoratorName, decorateFn, prop, descriptor) {
|
11 | if (descriptor.get !== undefined) {
|
12 | return fail(decoratorName + " cannot be used with getters");
|
13 | }
|
14 |
|
15 |
|
16 | if (descriptor.value) {
|
17 |
|
18 | return {
|
19 | value: decorateFn(prop, descriptor.value),
|
20 | enumerable: false,
|
21 | configurable: true,
|
22 | writable: true,
|
23 | };
|
24 | }
|
25 |
|
26 | var initializer = descriptor.initializer;
|
27 | return {
|
28 | enumerable: false,
|
29 | configurable: true,
|
30 | writable: true,
|
31 | initializer: function () {
|
32 |
|
33 | return decorateFn(prop, initializer.call(this));
|
34 | },
|
35 | };
|
36 | }
|
37 | export function decorateField(decorateFn, target, prop) {
|
38 |
|
39 | Object.defineProperty(target, prop, {
|
40 | configurable: true,
|
41 | enumerable: false,
|
42 | get: function () {
|
43 | return undefined;
|
44 | },
|
45 | set: function (value) {
|
46 | addHiddenProp(this, prop, decorateFn(prop, value));
|
47 | },
|
48 | });
|
49 | }
|