Debian Codegraph @

packages/babel-plugin-transform-block-scoping/test/fixtures/const-violations/assignment-expression/exec.js

raw symbols SCIP
1 const state1 = {};
2 expect(function() {
3 const a = 3;
4 let b = 1;
5 state1.getA = () => a;
6 state1.getB = () => b;
7
8 a += b++;
9 }).toThrow('"a" is read-only');
10 expect(state1.getA()).toBe(3); // Assignment did not succeed
11 expect(state1.getB()).toBe(2); // `b++` was evaluated before error thrown
12
13 const state2 = {};
14 expect(function() {
15 const a = {
16 valueOf() {
17 state2.valueOfIsCalled = true;
18 }
19 };
20 state2.a = a;
21 state2.getA = () => a;
22 state2.getB = () => b;
23
24 let b = 1;
25 a += b++;
26 }).toThrow('"a" is read-only');
27 expect(state2.getA()).toBe(state2.a); // Assignment did not succeed
28 expect(state2.getB()).toBe(2); // `b++` was evaluated before error thrown
29 expect(state2.valueOfIsCalled).toBe(true); // `a` was read before error thrown
30
31 const state3 = {};
32 expect(function() {
33 const a = 32;
34 let b = 1;
35 state3.getA = () => a;
36 state3.getB = () => b;
37
38 a >>>= ++b;
39 }).toThrow('"a" is read-only');
40 expect(state3.getA()).toBe(32); // Assignment did not succeed
41 expect(state3.getB()).toBe(2); // `++b` was evaluated before error thrown
42
43 const state4 = {};
44 expect(function() {
45 const a = 1;
46 let b = 1;
47 state4.getA = () => a;
48 state4.getB = () => b;
49
50 a &&= ++b;
51 }).toThrow('"a" is read-only');
52 expect(state4.getA()).toBe(1); // Assignment did not succeed
53 expect(state4.getB()).toBe(2); // `++b` was evaluated before error thrown
54
55 {
56 const a = 1;
57 let b = 1;
58 a ||= ++b;
59
60 expect(a).toBe(1); // Assignment not made
61 expect(b).toBe(1); // `++b` was not evaluated
62 }