Debian Codegraph @

packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/exec.js

raw
1 class Foo {
2 constructor() {
3 this.x = 1;
4 this.self = this;
5 }
6 m() { return this.x; };
7 getSelf() { return this }
8
9 test() {
10 const Foo = this;
11 const o = { Foo: Foo };
12 const fn = function () {
13 return o;
14 };
15
16 expect((Foo?.["m"])()).toEqual(1);
17 expect((Foo?.["m"])().toString).toEqual(1..toString);
18 expect((Foo?.["m"])().toString()).toEqual('1');
19
20 expect((o?.Foo.m)()).toEqual(1);
21 expect((o?.Foo.m)().toString).toEqual(1..toString);
22 expect((o?.Foo.m)().toString()).toEqual('1');
23
24 expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1);
25 expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1);
26
27 expect((((fn()?.Foo?.self.getSelf)())?.m)()).toEqual(1);
28 expect((((fn?.().Foo.self?.getSelf)())?.m)()).toEqual(1);
29 }
30
31 testNull() {
32 const o = null;
33
34 expect(() => { (o?.Foo.m)() }).toThrow();
35 expect(() => { (o?.Foo.m)().toString }).toThrow();
36 expect(() => { (o?.Foo.m)().toString() }).toThrow();
37
38 expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow();
39 expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow();
40
41 expect(() => (((fn()?.Foo?.self.getSelf)())?.m)()).toThrow();
42 expect(() => (((fn?.().Foo.self?.getSelf)())?.m)()).toThrow();
43 }
44 }
45
46 (new Foo).test();
47 (new Foo).testNull();