Debian Codegraph @

packages/babel-plugin-proposal-class-properties/test/fixtures/private/reevaluated/exec.js

raw
1 function classFactory() {
2 return class Foo {
3 #foo = "foo";
4 static #bar = "bar";
5
6 instance() {
7 return this.#foo;
8 }
9
10 static() {
11 return Foo.#bar;
12 }
13
14 static instance(inst) {
15 return inst.#foo;
16 }
17
18 static static() {
19 return Foo.#bar;
20 }
21 };
22 }
23
24 const Foo1 = classFactory();
25 const Foo2 = classFactory();
26
27 const f1 = new Foo1();
28 const f2 = new Foo2();
29
30 expect(f1.instance()).toBe("foo");
31 expect(f1.static()).toBe("bar");
32 expect(f2.instance()).toBe("foo");
33 expect(f2.static()).toBe("bar");
34
35 expect(Foo1.instance(f1)).toBe("foo");
36 expect(Foo1.static()).toBe("bar");
37 expect(Foo2.instance(f2)).toBe("foo");
38 expect(Foo2.static()).toBe("bar");
39
40 expect(() => {
41 f1.instance.call(f2), undefined;
42 }).toThrow();
43 expect(() => {
44 f2.instance.call(f1), undefined;
45 }).toThrow();
46 expect(() => {
47 Foo1.instance(f2), undefined;
48 }).toThrow();
49 expect(() => {
50 Foo2.instance(f1), undefined;
51 }).toThrow();