Debian Codegraph @

packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-in-function-param/exec.js

raw
1 class Foo {
2 static #x = 1;
3 static #m = function() { return this.#x; };
4 static #self = Foo;
5 static self = Foo;
6 static getSelf() { return this }
7
8 static test() {
9 const o = { Foo: Foo };
10 const deep = { very: { o } };
11 function fn() {
12 return o;
13 }
14 function fnDeep() {
15 return deep;
16 }
17
18 function f(o, r = o?.Foo.#m()) {
19 return r;
20 }
21
22 function g(o, r = o?.Foo.#self.getSelf().#m()) {
23 return r;
24 }
25
26 function h(fnDeep, r = fnDeep?.().very.o?.Foo?.#m()) {
27 return r;
28 }
29
30 function i(fn, r = fn?.().Foo.#self?.getSelf()?.self.#m()) {
31 return r;
32 }
33
34 function j(fn, r = (fn().Foo.#self.getSelf().self.#m)?.()) {
35 return r;
36 }
37
38 expect(f(o)).toBe(1);
39 expect(g(o)).toBe(1);
40 expect(h(fnDeep)).toBe(1);
41 expect(i(fn)).toBe(1);
42 expect(j(fn)).toBe(1);
43 }
44 }
45
46 Foo.test();