Skip to content

Commit c3b653c

Browse files
authored
Fix error for top level binary expr (#107)
1 parent 6a5e46a commit c3b653c

File tree

3 files changed

+152
-1
lines changed

3 files changed

+152
-1
lines changed

src/parser/convert.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ export function convertProgramNode(
161161
node.type !== "JSONLiteral" &&
162162
node.type !== "JSONUnaryExpression" &&
163163
node.type !== "JSONIdentifier" &&
164-
node.type !== "JSONTemplateLiteral"
164+
node.type !== "JSONTemplateLiteral" &&
165+
node.type !== "JSONBinaryExpression"
165166
) {
166167
return throwUnexpectedNodeError(node, tokens)
167168
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
42 + 1
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"type": "Program",
3+
"body": [
4+
{
5+
"type": "JSONExpressionStatement",
6+
"expression": {
7+
"type": "JSONBinaryExpression",
8+
"left": {
9+
"type": "JSONLiteral",
10+
"value": 42,
11+
"raw": "42",
12+
"range": [
13+
0,
14+
2
15+
],
16+
"loc": {
17+
"start": {
18+
"line": 1,
19+
"column": 0
20+
},
21+
"end": {
22+
"line": 1,
23+
"column": 2
24+
}
25+
}
26+
},
27+
"operator": "+",
28+
"right": {
29+
"type": "JSONLiteral",
30+
"value": 1,
31+
"raw": "1",
32+
"range": [
33+
5,
34+
6
35+
],
36+
"loc": {
37+
"start": {
38+
"line": 1,
39+
"column": 5
40+
},
41+
"end": {
42+
"line": 1,
43+
"column": 6
44+
}
45+
}
46+
},
47+
"range": [
48+
0,
49+
6
50+
],
51+
"loc": {
52+
"start": {
53+
"line": 1,
54+
"column": 0
55+
},
56+
"end": {
57+
"line": 1,
58+
"column": 6
59+
}
60+
}
61+
},
62+
"range": [
63+
0,
64+
6
65+
],
66+
"loc": {
67+
"start": {
68+
"line": 1,
69+
"column": 0
70+
},
71+
"end": {
72+
"line": 1,
73+
"column": 6
74+
}
75+
}
76+
}
77+
],
78+
"comments": [],
79+
"tokens": [
80+
{
81+
"type": "Numeric",
82+
"value": "42",
83+
"range": [
84+
0,
85+
2
86+
],
87+
"loc": {
88+
"start": {
89+
"line": 1,
90+
"column": 0
91+
},
92+
"end": {
93+
"line": 1,
94+
"column": 2
95+
}
96+
}
97+
},
98+
{
99+
"type": "Punctuator",
100+
"value": "+",
101+
"range": [
102+
3,
103+
4
104+
],
105+
"loc": {
106+
"start": {
107+
"line": 1,
108+
"column": 3
109+
},
110+
"end": {
111+
"line": 1,
112+
"column": 4
113+
}
114+
}
115+
},
116+
{
117+
"type": "Numeric",
118+
"value": "1",
119+
"range": [
120+
5,
121+
6
122+
],
123+
"loc": {
124+
"start": {
125+
"line": 1,
126+
"column": 5
127+
},
128+
"end": {
129+
"line": 1,
130+
"column": 6
131+
}
132+
}
133+
}
134+
],
135+
"range": [
136+
0,
137+
6
138+
],
139+
"loc": {
140+
"start": {
141+
"line": 1,
142+
"column": 0
143+
},
144+
"end": {
145+
"line": 1,
146+
"column": 6
147+
}
148+
}
149+
}

0 commit comments

Comments
 (0)