Debian Codegraph @

packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-noDocumentAll/optional-chain-cast-to-boolean/exec.js

raw symbols SCIP
1 class C {
2 static #a = {
3 b: {
4 c: {
5 d: 2,
6 },
7 },
8 };
9 static testIf(o) {
10 if (o?.#a.b.c.d) {
11 return true;
12 }
13 return false;
14 }
15 static testConditional(o) {
16 return o?.#a.b?.c.d ? true : false;
17 }
18 static testLoop(o) {
19 while (o?.#a.b.c.d) {
20 for (; o?.#a.b.c?.d; ) {
21 let i = 0;
22 do {
23 i++;
24 if (i === 2) {
25 return true;
26 }
27 } while (o?.#a.b?.c.d);
28 }
29 }
30 return false;
31 }
32 static testNegate(o) {
33 return !!o?.#a.b?.c.d;
34 }
35 static testIfDeep(o) {
36 if (o.obj?.#a.b?.c.d) {
37 return true;
38 }
39 return false;
40 }
41 static testConditionalDeep(o) {
42 return o.obj?.#a.b?.c.d ? true : false;
43 }
44 static testLoopDeep(o) {
45 while (o.obj?.#a.b.c.d) {
46 for (; o.obj?.#a.b.c?.d; ) {
47 let i = 0;
48 do {
49 i++;
50 if (i === 2) {
51 return true;
52 }
53 } while (o.obj?.#a.b?.c.d);
54 }
55 }
56 return false;
57 }
58 static testNegateDeep(o) {
59 return !!o.obj?.#a.b?.c.d;
60 }
61
62 static testLogicalInIf(o) {
63 if (o?.#a.b?.c.d && o?.#a?.b.c.d) {
64 return true;
65 }
66 return false;
67 }
68
69 static testLogicalInReturn(o) {
70 return o?.#a.b?.c.d && o?.#a?.b.c.d;
71 }
72
73 static testNullishCoalescing(o) {
74 if (o?.#a.b?.c.non_existent ?? o?.#a.b?.c.d) {
75 return o?.#a.b?.c.non_existent ?? o?.#a.b?.c.d;
76 }
77 return o?.#a.b?.c.non_existent ?? o;
78 }
79
80 static test() {
81 const c = C;
82 expect(C.testIf(c)).toBe(true);
83 expect(C.testConditional(c)).toBe(true);
84 expect(C.testLoop(c)).toBe(true);
85 expect(C.testNegate(c)).toBe(true);
86
87 expect(C.testIfDeep({ obj: c })).toBe(true);
88 expect(C.testConditionalDeep({ obj: c })).toBe(true);
89 expect(C.testLoopDeep({ obj: c })).toBe(true);
90 expect(C.testNegateDeep({ obj: c })).toBe(true);
91
92 expect(C.testLogicalInIf(c)).toBe(true);
93 expect(C.testLogicalInReturn(c)).toBe(2);
94
95 expect(C.testNullishCoalescing(c)).toBe(2);
96 }
97
98 static testNullish() {
99 for (const n of [null, undefined]) {
100 expect(C.testIf(n)).toBe(false);
101 expect(C.testConditional(n)).toBe(false);
102 expect(C.testLoop(n)).toBe(false);
103 expect(C.testNegate(n)).toBe(false);
104
105 expect(C.testIfDeep({ obj: n })).toBe(false);
106 expect(C.testConditionalDeep({ obj: n })).toBe(false);
107 expect(C.testLoopDeep({ obj: n })).toBe(false);
108 expect(C.testNegateDeep({ obj: n })).toBe(false);
109
110 expect(C.testLogicalInIf(n)).toBe(false);
111 expect(C.testLogicalInReturn(n)).toBe(undefined);
112
113 expect(C.testNullishCoalescing(n)).toBe(n);
114 }
115 }
116 }
117
118 C.test();
119 C.testNullish();