packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/set-only-getter/exec.js
raw| 1 | class Cl { |
| 2 | #privateField = 0; |
| 3 | counter = 0; |
| 4 | |
| 5 | get #privateFieldValue() { |
| 6 | return this.#privateField; |
| 7 | } |
| 8 | |
| 9 | get self() { |
| 10 | this.counter++; |
| 11 | return this; |
| 12 | } |
| 13 | |
| 14 | constructor() { |
| 15 | expect(() => this.self.#privateFieldValue = 1).toThrow(TypeError); |
| 16 | expect(this.counter).toBe(1); |
| 17 | expect(() => ([this.self.#privateFieldValue] = [1])).toThrow(TypeError); |
| 18 | expect(this.counter).toBe(2); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | const cl = new Cl(); |