Skip to content
This repository was archived by the owner on Apr 10, 2023. It is now read-only.

Commit 9939d0a

Browse files
committed
fix(binary operator precedences): 🐛
1 parent 2ccddf4 commit 9939d0a

File tree

18 files changed

+471
-56
lines changed

18 files changed

+471
-56
lines changed

lib/__tests__/fixtures/parse/003/output.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"right": {
5858
"type": "Literal",
5959
"value": "100%"
60-
}
60+
},
61+
"paren": true
6162
}
6263
},
6364
"right": {
@@ -91,7 +92,8 @@
9192
"right": {
9293
"type": "Literal",
9394
"value": "100%"
94-
}
95+
},
96+
"paren": true
9597
}
9698
},
9799
"right": {
@@ -125,7 +127,8 @@
125127
"right": {
126128
"type": "Literal",
127129
"value": "0"
128-
}
130+
},
131+
"paren": true
129132
}
130133
},
131134
"right": {
@@ -159,7 +162,8 @@
159162
"right": {
160163
"type": "Literal",
161164
"value": "0"
162-
}
165+
},
166+
"paren": true
163167
}
164168
},
165169
"right": {
@@ -169,4 +173,4 @@
169173
}
170174
}
171175
]
172-
}
176+
}

lib/__tests__/fixtures/parse/binary-expression-precedences-000/output.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
"right": {
3434
"type": "Literal",
3535
"value": 3
36-
}
36+
},
37+
"paren": true
3738
}
3839
},
3940
"right": {
4041
"type": "Literal",
4142
"value": 2
42-
}
43+
},
44+
"paren": true
4345
}
4446
},
4547
"right": {
@@ -49,4 +51,4 @@
4951
}
5052
}
5153
]
52-
}
54+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a || d && e ^ f & g === h < i << j + k % l ** !m++ ? b : c
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"type": "Program",
3+
"body": [
4+
{
5+
"type": "ConditionalExpression",
6+
"test": {
7+
"type": "LogicalExpression",
8+
"operator": "||",
9+
"left": {
10+
"type": "Identifier",
11+
"name": "a"
12+
},
13+
"right": {
14+
"type": "LogicalExpression",
15+
"operator": "&&",
16+
"left": {
17+
"type": "Identifier",
18+
"name": "d"
19+
},
20+
"right": {
21+
"type": "BinaryExpression",
22+
"operator": "^",
23+
"left": {
24+
"type": "Identifier",
25+
"name": "e"
26+
},
27+
"right": {
28+
"type": "BinaryExpression",
29+
"operator": "&",
30+
"left": {
31+
"type": "Identifier",
32+
"name": "f"
33+
},
34+
"right": {
35+
"type": "BinaryExpression",
36+
"operator": "===",
37+
"left": {
38+
"type": "Identifier",
39+
"name": "g"
40+
},
41+
"right": {
42+
"type": "BinaryExpression",
43+
"operator": "<",
44+
"left": {
45+
"type": "Identifier",
46+
"name": "h"
47+
},
48+
"right": {
49+
"type": "BinaryExpression",
50+
"operator": "<<",
51+
"left": {
52+
"type": "Identifier",
53+
"name": "i"
54+
},
55+
"right": {
56+
"type": "BinaryExpression",
57+
"operator": "+",
58+
"left": {
59+
"type": "Identifier",
60+
"name": "j"
61+
},
62+
"right": {
63+
"type": "BinaryExpression",
64+
"operator": "%",
65+
"left": {
66+
"type": "Identifier",
67+
"name": "k"
68+
},
69+
"right": {
70+
"type": "BinaryExpression",
71+
"operator": "**",
72+
"left": {
73+
"type": "Identifier",
74+
"name": "l"
75+
},
76+
"right": {
77+
"type": "UnaryExpression",
78+
"operator": "!",
79+
"argument": {
80+
"type": "UpdateExpression",
81+
"operator": "++",
82+
"argument": {
83+
"type": "Identifier",
84+
"name": "m"
85+
},
86+
"prefix": false
87+
}
88+
}
89+
}
90+
}
91+
}
92+
}
93+
}
94+
}
95+
}
96+
}
97+
}
98+
},
99+
"consequent": {
100+
"type": "Identifier",
101+
"name": "b"
102+
},
103+
"alternate": {
104+
"type": "Identifier",
105+
"name": "c"
106+
}
107+
}
108+
]
109+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a && b ** c
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"type": "Program",
3+
"body": [
4+
{
5+
"type": "ExpressionStatement",
6+
"expression": {
7+
"type": "LogicalExpression",
8+
"operator": "&&",
9+
"left": {
10+
"type": "Identifier",
11+
"name": "a"
12+
},
13+
"right": {
14+
"type": "BinaryExpression",
15+
"operator": "**",
16+
"left": {
17+
"type": "Identifier",
18+
"name": "b"
19+
},
20+
"right": {
21+
"type": "Identifier",
22+
"name": "c"
23+
}
24+
}
25+
}
26+
}
27+
]
28+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 + 2 + 3 + 4
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"type": "Program",
3+
"body": [
4+
{
5+
"type": "ExpressionStatement",
6+
"expression": {
7+
"type": "BinaryExpression",
8+
"operator": "+",
9+
"left": {
10+
"type": "BinaryExpression",
11+
"operator": "+",
12+
"left": {
13+
"type": "BinaryExpression",
14+
"operator": "+",
15+
"left": {
16+
"type": "Literal",
17+
"value": 1
18+
},
19+
"right": {
20+
"type": "Literal",
21+
"value": 2
22+
}
23+
},
24+
"right": {
25+
"type": "Literal",
26+
"value": 3
27+
}
28+
},
29+
"right": {
30+
"type": "Literal",
31+
"value": 4
32+
}
33+
}
34+
}
35+
]
36+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"type": "Program",
3+
"body": [
4+
{
5+
"type": "ExpressionStatement",
6+
"expression": {
7+
"type": "UnaryExpression",
8+
"operator": "!",
9+
"argument": {
10+
"type": "UpdateExpression",
11+
"operator": "++",
12+
"argument": {
13+
"type": "Identifier",
14+
"name": "a"
15+
},
16+
"prefix": false
17+
}
18+
}
19+
}
20+
]
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!a++

0 commit comments

Comments
 (0)