Skip to content

Commit 54399ab

Browse files
authored
Convert argument of SpreadElement correctly to assignable (babel#518) (babel#519)
1 parent 28985e7 commit 54399ab

4 files changed

Lines changed: 311 additions & 1 deletion

File tree

src/parser/lval.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ pp.toAssignable = function (node, isBinding, contextDescription) {
3636

3737
case "SpreadProperty":
3838
node.type = "RestProperty";
39+
const arg = node.argument;
40+
this.toAssignable(arg, isBinding, contextDescription);
3941
break;
4042

4143
case "ArrayExpression":
@@ -77,7 +79,11 @@ pp.toAssignableList = function (exprList, isBinding, contextDescription) {
7779
last.type = "RestElement";
7880
const arg = last.argument;
7981
this.toAssignable(arg, isBinding, contextDescription);
80-
if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern") {
82+
if (
83+
arg.type !== "Identifier" &&
84+
arg.type !== "MemberExpression" &&
85+
arg.type !== "ArrayPattern"
86+
) {
8187
this.unexpected(arg.start);
8288
}
8389
--end;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
({ x, ...{ y, z } } = o)
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
{
2+
"type": "File",
3+
"start": 0,
4+
"end": 24,
5+
"loc": {
6+
"start": {
7+
"line": 1,
8+
"column": 0
9+
},
10+
"end": {
11+
"line": 1,
12+
"column": 24
13+
}
14+
},
15+
"program": {
16+
"type": "Program",
17+
"start": 0,
18+
"end": 24,
19+
"loc": {
20+
"start": {
21+
"line": 1,
22+
"column": 0
23+
},
24+
"end": {
25+
"line": 1,
26+
"column": 24
27+
}
28+
},
29+
"sourceType": "script",
30+
"body": [
31+
{
32+
"type": "ExpressionStatement",
33+
"start": 0,
34+
"end": 24,
35+
"loc": {
36+
"start": {
37+
"line": 1,
38+
"column": 0
39+
},
40+
"end": {
41+
"line": 1,
42+
"column": 24
43+
}
44+
},
45+
"expression": {
46+
"type": "AssignmentExpression",
47+
"start": 1,
48+
"end": 23,
49+
"loc": {
50+
"start": {
51+
"line": 1,
52+
"column": 1
53+
},
54+
"end": {
55+
"line": 1,
56+
"column": 23
57+
}
58+
},
59+
"operator": "=",
60+
"left": {
61+
"type": "ObjectPattern",
62+
"start": 1,
63+
"end": 19,
64+
"loc": {
65+
"start": {
66+
"line": 1,
67+
"column": 1
68+
},
69+
"end": {
70+
"line": 1,
71+
"column": 19
72+
}
73+
},
74+
"properties": [
75+
{
76+
"type": "ObjectProperty",
77+
"start": 3,
78+
"end": 4,
79+
"loc": {
80+
"start": {
81+
"line": 1,
82+
"column": 3
83+
},
84+
"end": {
85+
"line": 1,
86+
"column": 4
87+
}
88+
},
89+
"method": false,
90+
"shorthand": true,
91+
"computed": false,
92+
"key": {
93+
"type": "Identifier",
94+
"start": 3,
95+
"end": 4,
96+
"loc": {
97+
"start": {
98+
"line": 1,
99+
"column": 3
100+
},
101+
"end": {
102+
"line": 1,
103+
"column": 4
104+
},
105+
"identifierName": "x"
106+
},
107+
"name": "x"
108+
},
109+
"value": {
110+
"type": "Identifier",
111+
"start": 3,
112+
"end": 4,
113+
"loc": {
114+
"start": {
115+
"line": 1,
116+
"column": 3
117+
},
118+
"end": {
119+
"line": 1,
120+
"column": 4
121+
},
122+
"identifierName": "x"
123+
},
124+
"name": "x"
125+
},
126+
"extra": {
127+
"shorthand": true
128+
}
129+
},
130+
{
131+
"type": "RestProperty",
132+
"start": 6,
133+
"end": 17,
134+
"loc": {
135+
"start": {
136+
"line": 1,
137+
"column": 6
138+
},
139+
"end": {
140+
"line": 1,
141+
"column": 17
142+
}
143+
},
144+
"argument": {
145+
"type": "ObjectPattern",
146+
"start": 9,
147+
"end": 17,
148+
"loc": {
149+
"start": {
150+
"line": 1,
151+
"column": 9
152+
},
153+
"end": {
154+
"line": 1,
155+
"column": 17
156+
}
157+
},
158+
"properties": [
159+
{
160+
"type": "ObjectProperty",
161+
"start": 11,
162+
"end": 12,
163+
"loc": {
164+
"start": {
165+
"line": 1,
166+
"column": 11
167+
},
168+
"end": {
169+
"line": 1,
170+
"column": 12
171+
}
172+
},
173+
"method": false,
174+
"shorthand": true,
175+
"computed": false,
176+
"key": {
177+
"type": "Identifier",
178+
"start": 11,
179+
"end": 12,
180+
"loc": {
181+
"start": {
182+
"line": 1,
183+
"column": 11
184+
},
185+
"end": {
186+
"line": 1,
187+
"column": 12
188+
},
189+
"identifierName": "y"
190+
},
191+
"name": "y"
192+
},
193+
"value": {
194+
"type": "Identifier",
195+
"start": 11,
196+
"end": 12,
197+
"loc": {
198+
"start": {
199+
"line": 1,
200+
"column": 11
201+
},
202+
"end": {
203+
"line": 1,
204+
"column": 12
205+
},
206+
"identifierName": "y"
207+
},
208+
"name": "y"
209+
},
210+
"extra": {
211+
"shorthand": true
212+
}
213+
},
214+
{
215+
"type": "ObjectProperty",
216+
"start": 14,
217+
"end": 15,
218+
"loc": {
219+
"start": {
220+
"line": 1,
221+
"column": 14
222+
},
223+
"end": {
224+
"line": 1,
225+
"column": 15
226+
}
227+
},
228+
"method": false,
229+
"shorthand": true,
230+
"computed": false,
231+
"key": {
232+
"type": "Identifier",
233+
"start": 14,
234+
"end": 15,
235+
"loc": {
236+
"start": {
237+
"line": 1,
238+
"column": 14
239+
},
240+
"end": {
241+
"line": 1,
242+
"column": 15
243+
},
244+
"identifierName": "z"
245+
},
246+
"name": "z"
247+
},
248+
"value": {
249+
"type": "Identifier",
250+
"start": 14,
251+
"end": 15,
252+
"loc": {
253+
"start": {
254+
"line": 1,
255+
"column": 14
256+
},
257+
"end": {
258+
"line": 1,
259+
"column": 15
260+
},
261+
"identifierName": "z"
262+
},
263+
"name": "z"
264+
},
265+
"extra": {
266+
"shorthand": true
267+
}
268+
}
269+
]
270+
}
271+
}
272+
]
273+
},
274+
"right": {
275+
"type": "Identifier",
276+
"start": 22,
277+
"end": 23,
278+
"loc": {
279+
"start": {
280+
"line": 1,
281+
"column": 22
282+
},
283+
"end": {
284+
"line": 1,
285+
"column": 23
286+
},
287+
"identifierName": "o"
288+
},
289+
"name": "o"
290+
},
291+
"extra": {
292+
"parenthesized": true,
293+
"parenStart": 0
294+
}
295+
}
296+
}
297+
],
298+
"directives": []
299+
}
300+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["objectRestSpread"]
3+
}

0 commit comments

Comments
 (0)