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

Commit 789014b

Browse files
committed
fix(ConditionalExpression): 🐛Fix parsed ConditionalExpression missing ExpressionStatement
1 parent 8162bd0 commit 789014b

File tree

5 files changed

+191
-113
lines changed

5 files changed

+191
-113
lines changed

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

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,88 +2,91 @@
22
"type": "Program",
33
"body": [
44
{
5-
"type": "ConditionalExpression",
6-
"test": {
7-
"type": "LogicalExpression",
8-
"operator": "||",
9-
"left": {
10-
"type": "Identifier",
11-
"name": "a"
12-
},
13-
"right": {
5+
"type": "ExpressionStatement",
6+
"expression": {
7+
"type": "ConditionalExpression",
8+
"test": {
149
"type": "LogicalExpression",
15-
"operator": "&&",
10+
"operator": "||",
1611
"left": {
1712
"type": "Identifier",
18-
"name": "d"
13+
"name": "a"
1914
},
2015
"right": {
21-
"type": "BinaryExpression",
22-
"operator": "^",
16+
"type": "LogicalExpression",
17+
"operator": "&&",
2318
"left": {
2419
"type": "Identifier",
25-
"name": "e"
20+
"name": "d"
2621
},
2722
"right": {
2823
"type": "BinaryExpression",
29-
"operator": "&",
24+
"operator": "^",
3025
"left": {
3126
"type": "Identifier",
32-
"name": "f"
27+
"name": "e"
3328
},
3429
"right": {
3530
"type": "BinaryExpression",
36-
"operator": "===",
31+
"operator": "&",
3732
"left": {
3833
"type": "Identifier",
39-
"name": "g"
34+
"name": "f"
4035
},
4136
"right": {
4237
"type": "BinaryExpression",
43-
"operator": "<",
38+
"operator": "===",
4439
"left": {
4540
"type": "Identifier",
46-
"name": "h"
41+
"name": "g"
4742
},
4843
"right": {
4944
"type": "BinaryExpression",
50-
"operator": "<<",
45+
"operator": "<",
5146
"left": {
5247
"type": "Identifier",
53-
"name": "i"
48+
"name": "h"
5449
},
5550
"right": {
5651
"type": "BinaryExpression",
57-
"operator": "+",
52+
"operator": "<<",
5853
"left": {
5954
"type": "Identifier",
60-
"name": "j"
55+
"name": "i"
6156
},
6257
"right": {
6358
"type": "BinaryExpression",
64-
"operator": "%",
59+
"operator": "+",
6560
"left": {
6661
"type": "Identifier",
67-
"name": "k"
62+
"name": "j"
6863
},
6964
"right": {
7065
"type": "BinaryExpression",
71-
"operator": "**",
66+
"operator": "%",
7267
"left": {
7368
"type": "Identifier",
74-
"name": "l"
69+
"name": "k"
7570
},
7671
"right": {
77-
"type": "UnaryExpression",
78-
"operator": "!",
79-
"argument": {
80-
"type": "UpdateExpression",
81-
"operator": "++",
72+
"type": "BinaryExpression",
73+
"operator": "**",
74+
"left": {
75+
"type": "Identifier",
76+
"name": "l"
77+
},
78+
"right": {
79+
"type": "UnaryExpression",
80+
"operator": "!",
8281
"argument": {
83-
"type": "Identifier",
84-
"name": "m"
85-
},
86-
"prefix": false
82+
"type": "UpdateExpression",
83+
"operator": "++",
84+
"argument": {
85+
"type": "Identifier",
86+
"name": "m"
87+
},
88+
"prefix": false
89+
}
8790
}
8891
}
8992
}
@@ -94,15 +97,15 @@
9497
}
9598
}
9699
}
100+
},
101+
"consequent": {
102+
"type": "Identifier",
103+
"name": "b"
104+
},
105+
"alternate": {
106+
"type": "Identifier",
107+
"name": "c"
97108
}
98-
},
99-
"consequent": {
100-
"type": "Identifier",
101-
"name": "b"
102-
},
103-
"alternate": {
104-
"type": "Identifier",
105-
"name": "c"
106109
}
107110
}
108111
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
url ? 'background-image:url(' + protocol + url + ');' : ''
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"type": "Program",
3+
"body": [
4+
{
5+
"type": "ExpressionStatement",
6+
"expression": {
7+
"type": "ConditionalExpression",
8+
"test": {
9+
"type": "Identifier",
10+
"name": "url"
11+
},
12+
"consequent": {
13+
"type": "BinaryExpression",
14+
"operator": "+",
15+
"left": {
16+
"type": "BinaryExpression",
17+
"operator": "+",
18+
"left": {
19+
"type": "BinaryExpression",
20+
"operator": "+",
21+
"left": {
22+
"type": "Literal",
23+
"value": "background-image:url("
24+
},
25+
"right": {
26+
"type": "Identifier",
27+
"name": "protocol"
28+
}
29+
},
30+
"right": {
31+
"type": "Identifier",
32+
"name": "url"
33+
}
34+
},
35+
"right": {
36+
"type": "Literal",
37+
"value": ");"
38+
}
39+
},
40+
"alternate": {
41+
"type": "Literal",
42+
"value": ""
43+
}
44+
}
45+
}
46+
]
47+
}

lib/__tests__/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('parse', async (t) => {
1717
onlyDirectories: true,
1818
})).filter((x) => {
1919
return true;
20-
return x === 'binary-expression-precedences-003';
20+
return x === 'conditional-expression-000';
2121
});
2222

2323
const tested = [];

0 commit comments

Comments
 (0)