Debian Codegraph @

packages/babel-plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-expression-member-call/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(((Foo?.["m"]))()).toEqual(1);
21 expect(((Foo?.["m"]))().toString).toEqual(1..toString);
22 expect(((Foo?.["m"]))().toString()).toEqual('1');
23
24 expect((o?.Foo.m)()).toEqual(1);
25 expect((o?.Foo.m)().toString).toEqual(1..toString);
26 expect((o?.Foo.m)().toString()).toEqual('1');
27
28 expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1);
29 expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1);
30
31 expect((((fn()?.Foo?.self.getSelf)())?.m)()).toEqual(1);
32 expect((((fn?.().Foo.self?.getSelf)())?.m)()).toEqual(1);
33 }
34
35 testNull() {
36 const o = null;
37
38 expect(() => { (o?.Foo.m)() }).toThrow();
39 expect(() => { (o?.Foo.m)().toString }).toThrow();
40 expect(() => { (o?.Foo.m)().toString() }).toThrow();
41
42 expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow();
43 expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow();
44
45 expect(() => (((fn()?.Foo?.self.getSelf)())?.m)()).toThrow();
46 expect(() => (((fn?.().Foo.self?.getSelf)())?.m)()).toThrow();
47 }
48 }
49
50 (new Foo).test();
51 (new Foo).testNull();