Debian Codegraph @

js/src/jit-test/tests/parser/arrow-rest.js

raw
1 // The parser should throw SyntaxError immediately if it finds "..." in a
2 // context where it's not allowed.
3
4 function testThrow(code, column) {
5 var caught = false;
6 try {
7 eval(code);
8 } catch (e) {
9 caught = true;
10 assertEq(e.columnNumber, column);
11 }
12 assertEq(caught, true,
13 "failed to throw evaluating <" + code + ">");
14 }
15
16 // expression statement
17
18 testThrow(`
19 ...a)=>
20 `, 1);
21
22 // default parameter
23
24 testThrow(`
25 function f(x=...a) =>
26 `, 14);
27
28 // rest parameter
29
30 testThrow(`
31 function f(... ...a) =>
32 `, 16);
33
34 // destructuring parameter
35
36 testThrow(`
37 ([... ...a)=>
38 `, 7);
39
40 testThrow(`
41 ({...a)=>
42 `, 7);
43
44 testThrow(`
45 function f([... ...a)=>
46 `, 17);
47
48 testThrow(`
49 function f({...a)=>
50 `, 17);
51
52 // arrow
53
54 testThrow(`
55 x => ...a)=>
56 `, 6);
57
58 // template literal
59
60 testThrow("`${ ...a)=>}`", 5);
61
62 // destructing assignment
63
64 testThrow(`
65 var [... ...a)=>
66 `, 10);
67
68 testThrow(`
69 var {...a)=>
70 `, 10);
71
72 // initializer
73
74 testThrow(`
75 var [a] = ...a)=>
76 `, 11);
77
78 testThrow(`
79 var {a:a} = ...a)=>
80 `, 13);
81
82 testThrow(`
83 var a = ...a)=>
84 `, 9);
85
86 // if statement
87
88 testThrow(`
89 if (...a) =>
90 `, 5);
91
92 // for statement
93
94 testThrow(`
95 for (...a)=>
96 `, 6);
97
98 testThrow(`
99 for (let a in ...a)=>
100 `, 15);
101
102 testThrow(`
103 for (let a of ...a)=>
104 `, 15);
105
106 testThrow(`
107 for (; ...a)=>
108 `, 8);
109
110 testThrow(`
111 for (;; ...a)=>
112 `, 9);
113
114 // case
115
116 testThrow(`
117 switch (x) { case ...a)=>
118 `, 19);
119
120 // return statement
121
122 testThrow(`
123 function f(x) { return ...a)=>
124 `, 24);
125
126 // yield expression
127
128 testThrow(`
129 function* f(x) { yield ...a)=>
130 `, 24);
131
132 // throw statement
133
134 testThrow(`
135 throw ...a) =>
136 `, 7);
137
138 // class
139
140 testThrow(`
141 class A extends ...a) =>
142 `, 17);
143
144 // conditional expression
145
146 testThrow(`
147 1 ? ...a) =>
148 `, 5);
149
150 testThrow(`
151 1 ? 2 : ...a) =>
152 `, 9);
153
154 // unary operators
155
156 testThrow(`
157 void ...a) =>
158 `, 6);
159
160 testThrow(`
161 typeof ...a) =>
162 `, 8);
163
164 testThrow(`
165 ++ ...a) =>
166 `, 4);
167
168 testThrow(`
169 delete ...a) =>
170 `, 8);
171
172 // new
173
174 testThrow(`
175 new ...a) =>
176 `, 5);
177
178 // member expression
179
180 testThrow(`
181 x[...a) =>
182 `, 3);
183
184 // array literal
185
186 testThrow(`
187 [... ...a) =>
188 `, 6);
189
190 // object literal
191
192 testThrow(`
193 ({[...a) =>
194 `, 4);
195
196 testThrow(`
197 ({x: ...a) =>
198 `, 6);
199
200 // assignment
201
202 testThrow(`
203 x = ...a) =>
204 `, 5);