Debian Codegraph @

packages/babel-plugin-proposal-decorators/test/fixtures/legacy-class-static-methods/mutate-descriptor/exec.js

raw
1 function dec(target, name, descriptor) {
2 expect(target).toBeTruthy();
3 expect(typeof name).toBe("string");
4 expect(typeof descriptor).toBe("object");
5
6 target.decoratedProps = (target.decoratedProps || []).concat([name]);
7
8 let value = descriptor.value;
9 Object.assign(descriptor, {
10 enumerable: name.indexOf("enum") !== -1,
11 configurable: name.indexOf("conf") !== -1,
12 writable: name.indexOf("write") !== -1,
13 value: function(...args) {
14 return "__" + value.apply(this, args) + "__";
15 },
16 });
17 }
18
19 class Example {
20 @dec
21 static enumconfwrite(){
22 return 1;
23 }
24
25 @dec
26 static enumconf(){
27 return 2;
28 }
29
30 @dec
31 static enumwrite(){
32 return 3;
33 }
34
35 @dec
36 static enum(){
37 return 4;
38 }
39
40 @dec
41 static confwrite(){
42 return 5;
43 }
44
45 @dec
46 static conf(){
47 return 6;
48 }
49
50 @dec
51 static write(){
52 return 7;
53 }
54
55 @dec
56 static _(){
57 return 8;
58 }
59 }
60
61 expect(Example).toHaveProperty("decoratedProps");
62 expect(Example.decoratedProps).toEqual([
63 "enumconfwrite",
64 "enumconf",
65 "enumwrite",
66 "enum",
67 "confwrite",
68 "conf",
69 "write",
70 "_",
71 ]);
72
73 const descs = Object.getOwnPropertyDescriptors(Example);
74
75 expect(descs.enumconfwrite.enumerable).toBeTruthy();
76 expect(descs.enumconfwrite.writable).toBeTruthy();
77 expect(descs.enumconfwrite.configurable).toBeTruthy();
78 expect(Example.enumconfwrite()).toBe("__1__");
79
80 expect(descs.enumconf.enumerable).toBeTruthy();
81 expect(descs.enumconf.writable).toBe(false);
82 expect(descs.enumconf.configurable).toBeTruthy();
83 expect(Example.enumconf()).toBe("__2__");
84
85 expect(descs.enumwrite.enumerable).toBeTruthy();
86 expect(descs.enumwrite.writable).toBeTruthy();
87 expect(descs.enumwrite.configurable).toBe(false);
88 expect(Example.enumwrite()).toBe("__3__");
89
90 expect(descs.enum.enumerable).toBeTruthy();
91 expect(descs.enum.writable).toBe(false);
92 expect(descs.enum.configurable).toBe(false);
93 expect(Example.enum()).toBe("__4__");
94
95 expect(descs.confwrite.enumerable).toBe(false);
96 expect(descs.confwrite.writable).toBeTruthy();
97 expect(descs.confwrite.configurable).toBeTruthy();
98 expect(Example.confwrite()).toBe("__5__");
99
100 expect(descs.conf.enumerable).toBe(false);
101 expect(descs.conf.writable).toBe(false);
102 expect(descs.conf.configurable).toBeTruthy();
103 expect(Example.conf()).toBe("__6__");
104
105 expect(descs.write.enumerable).toBe(false);
106 expect(descs.write.writable).toBeTruthy();
107 expect(descs.write.configurable).toBe(false);
108 expect(Example.write()).toBe("__7__");
109
110 expect(descs._.enumerable).toBe(false);
111 expect(descs._.writable).toBe(false);
112 expect(descs._.configurable).toBe(false);
113 expect(Example._()).toBe("__8__");