Debian Codegraph @

packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/private-with-initializers/exec.js

raw symbols SCIP
1 function dec(fn, context) {
2 context.addInitializer(function() {
3 this[context.name + 'Context'] = context;
4 });
5
6 return function () {
7 return fn.call(this) + 1;
8 }
9 }
10
11 class Foo {
12 value = 1;
13
14 @dec
15 #a() {
16 return this.value;
17 }
18
19 callA() {
20 return this.#a();
21 }
22 }
23
24 let foo = new Foo();
25
26 const aContext = foo['#aContext'];
27
28 // First call gets the method, second call calls the method with correct `this`
29 expect(aContext.access.get.call(foo).call(foo)).toBe(2);
30 expect(foo.callA()).toBe(2);
31 foo.value = 123;
32 expect(aContext.access.get.call(foo).call(foo)).toBe(124);
33 expect(foo.callA()).toBe(124);
34
35 expect(aContext.name).toBe('#a');
36 expect(aContext.kind).toBe('method');
37 expect(aContext.isStatic).toBe(false);
38 expect(aContext.isPrivate).toBe(true);
39 expect(typeof aContext.addInitializer).toBe('function');
40 expect(typeof aContext.setMetadata).toBe('function');
41 expect(typeof aContext.getMetadata).toBe('function');