Debian Codegraph @

packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/private/exec.js

raw symbols SCIP
1 function dec(value, context) {
2 context.addInitializer(function() {
3 this[context.name + '_' + context.kind + 'Context'] = context;
4 });
5
6 if (context.kind === 'getter') {
7 return function () {
8 return value.call(this) + 1;
9 }
10 } else {
11 return function (v) {
12 return value.call(this, v + 1);
13 }
14 }
15 }
16
17 class Foo {
18 value = 1;
19
20 @dec
21 get #a() {
22 return this.value;
23 }
24
25 @dec
26 set #a(v) {
27 this.value = v;
28 }
29
30 getA() {
31 return this.#a;
32 }
33
34 setA(v) {
35 this.#a = v;
36 }
37 }
38
39 let foo = new Foo();
40
41 const a_getterContext = foo['#a_getterContext'];
42 const a_setterContext = foo['#a_setterContext'];
43
44 expect(a_getterContext.access.get.call(foo)).toBe(2);
45 expect(foo.getA()).toBe(2);
46 a_setterContext.access.set.call(foo, 123);
47 expect(a_getterContext.access.get.call(foo)).toBe(125);
48 expect(foo.getA()).toBe(125);
49 foo.setA(456);
50 expect(a_getterContext.access.get.call(foo)).toBe(458);
51 expect(foo.getA()).toBe(458);
52
53 expect(a_getterContext.name).toBe('#a');
54 expect(a_getterContext.kind).toBe('getter');
55 expect(a_getterContext.isStatic).toBe(false);
56 expect(a_getterContext.isPrivate).toBe(true);
57 expect(typeof a_getterContext.addInitializer).toBe('function');
58 expect(typeof a_getterContext.setMetadata).toBe('function');
59 expect(typeof a_getterContext.getMetadata).toBe('function');
60
61 expect(a_setterContext.name).toBe('#a');
62 expect(a_setterContext.kind).toBe('setter');
63 expect(a_setterContext.isStatic).toBe(false);
64 expect(a_setterContext.isPrivate).toBe(true);
65 expect(typeof a_setterContext.addInitializer).toBe('function');
66 expect(typeof a_setterContext.setMetadata).toBe('function');
67 expect(typeof a_setterContext.getMetadata).toBe('function');