]>
Commit | Line | Data |
---|---|---|
eb39fafa | 1 | /** |
8f9d1d4d | 2 | * @fileoverview Disallow parenthesising higher precedence subexpressions. |
eb39fafa DC |
3 | * @author Michael Ficarra |
4 | */ | |
5 | ||
6 | "use strict"; | |
7 | ||
8 | //------------------------------------------------------------------------------ | |
9 | // Requirements | |
10 | //------------------------------------------------------------------------------ | |
11 | ||
12 | const rule = require("../../../lib/rules/no-extra-parens"), | |
13 | { RuleTester } = require("../../../lib/rule-tester"); | |
14 | ||
609c276f TL |
15 | //------------------------------------------------------------------------------ |
16 | // Helpers | |
17 | //------------------------------------------------------------------------------ | |
18 | ||
eb39fafa DC |
19 | /** |
20 | * Create error message object for failure cases | |
21 | * @param {string} code source code | |
22 | * @param {string} output fixed source code | |
23 | * @param {string} type node type | |
24 | * @param {int} line line number | |
25 | * @param {Object} config rule configuration | |
26 | * @returns {Object} result object | |
27 | * @private | |
28 | */ | |
29 | function invalid(code, output, type, line, config) { | |
30 | const result = { | |
31 | code, | |
32 | output, | |
33 | parserOptions: config && config.parserOptions || {}, | |
34 | errors: [ | |
35 | { | |
36 | messageId: "unexpected", | |
37 | type | |
38 | } | |
39 | ], | |
40 | options: config && config.options || [] | |
41 | }; | |
42 | ||
43 | if (line) { | |
44 | result.errors[0].line = line; | |
45 | } | |
46 | return result; | |
47 | } | |
48 | ||
609c276f TL |
49 | //------------------------------------------------------------------------------ |
50 | // Tests | |
51 | //------------------------------------------------------------------------------ | |
52 | ||
eb39fafa DC |
53 | const ruleTester = new RuleTester({ |
54 | parserOptions: { | |
609c276f | 55 | ecmaVersion: 2022, |
eb39fafa DC |
56 | ecmaFeatures: { |
57 | jsx: true | |
58 | } | |
59 | } | |
60 | }); | |
61 | ||
62 | ruleTester.run("no-extra-parens", rule, { | |
63 | valid: [ | |
64 | ||
65 | // all precedence boundaries | |
66 | "foo", | |
67 | "a = b, c = d", | |
68 | "a = b ? c : d", | |
69 | "a = (b, c)", | |
70 | "a || b ? c = d : e = f", | |
71 | "(a = b) ? (c, d) : (e, f)", | |
72 | "a && b || c && d", | |
73 | "(a ? b : c) || (d ? e : f)", | |
74 | "a | b && c | d", | |
75 | "(a || b) && (c || d)", | |
76 | "a ^ b | c ^ d", | |
77 | "(a && b) | (c && d)", | |
78 | "a & b ^ c & d", | |
79 | "(a | b) ^ (c | d)", | |
80 | "a == b & c != d", | |
81 | "(a ^ b) & (c ^ d)", | |
82 | "a < b === c in d", | |
83 | "(a & b) !== (c & d)", | |
84 | "a << b >= c >>> d", | |
85 | "(a == b) instanceof (c != d)", | |
86 | "a + b << c - d", | |
87 | "(a <= b) >> (c > d)", | |
88 | "a * b + c / d", | |
89 | "(a << b) - (c >> d)", | |
90 | "+a % !b", | |
91 | "(a + b) * (c - d)", | |
92 | "-void+delete~typeof!a", | |
93 | "!(a * b); typeof (a / b); +(a % b); delete (a * b); ~(a / b); void (a % b); -(a * b)", | |
94 | "a(b = c, (d, e))", | |
95 | "(++a)(b); (c++)(d);", | |
96 | "new (A())", | |
97 | "new (foo.Baz().foo)", | |
98 | "new (foo.baz.bar().foo.baz)", | |
99 | "new ({}.baz.bar.foo().baz)", | |
100 | "new (doSomething().baz.bar().foo)", | |
101 | "new ([][0].baz.foo().bar.foo)", | |
102 | "new (foo\n.baz\n.bar()\n.foo.baz)", | |
103 | "new A()()", | |
104 | "(new A)()", | |
105 | "(new (Foo || Bar))()", | |
106 | "(new new foo())()", | |
456be15e TL |
107 | "new (new A)()", |
108 | "new (new a.b)()", | |
eb39fafa DC |
109 | "new (new new foo())(bar)", |
110 | "(new foo).bar", | |
111 | "(new foo)[bar]", | |
112 | "(new foo).bar.baz", | |
113 | "(new foo.bar).baz", | |
114 | "(new foo).bar()", | |
115 | "(new foo.bar).baz()", | |
116 | "new (new foo).bar", | |
117 | "new (new foo.bar).baz", | |
118 | "(new new foo()).baz", | |
119 | "(2 + 3) ** 4", | |
120 | "2 ** (2 + 3)", | |
121 | "new (import(source))", | |
122 | "import((s,t))", | |
123 | ||
124 | // same precedence | |
125 | "a, b, c", | |
126 | "a = b = c", | |
127 | "a ? b ? c : d : e", | |
128 | "a ? b : c ? d : e", | |
129 | "a || b || c", | |
130 | "a || (b || c)", | |
131 | "a && b && c", | |
132 | "a && (b && c)", | |
133 | "a | b | c", | |
134 | "a | (b | c)", | |
135 | "a ^ b ^ c", | |
136 | "a ^ (b ^ c)", | |
137 | "a & b & c", | |
138 | "a & (b & c)", | |
139 | "a == b == c", | |
140 | "a == (b == c)", | |
141 | "a < b < c", | |
142 | "a < (b < c)", | |
143 | "a << b << c", | |
144 | "a << (b << c)", | |
145 | "a + b + c", | |
146 | "a + (b + c)", | |
147 | "a * b * c", | |
148 | "a * (b * c)", | |
149 | "!!a; typeof +b; void -c; ~delete d;", | |
150 | "a(b)", | |
151 | "a(b)(c)", | |
152 | "a((b, c))", | |
153 | "new new A", | |
154 | "2 ** 3 ** 4", | |
155 | "(2 ** 3) ** 4", | |
156 | ||
157 | // constructs that contain expressions | |
158 | "if(a);", | |
159 | "with(a){}", | |
160 | "switch(a){ case 0: break; }", | |
161 | "function a(){ return b; }", | |
162 | "var a = () => { return b; }", | |
163 | "throw a;", | |
164 | "while(a);", | |
165 | "do; while(a);", | |
166 | "for(;;);", | |
167 | "for(a in b);", | |
168 | "for(a in b, c);", | |
169 | "for(a of b);", | |
170 | "for (a of (b, c));", | |
171 | "var a = (b, c);", | |
172 | "[]", | |
173 | "[a, b]", | |
174 | "!{a}", | |
175 | "!{a: 0, b: 1}", | |
176 | "!{[a]:0}", | |
177 | "!{[(a, b)]:0}", | |
178 | "!{a, ...b}", | |
179 | "const {a} = {}", | |
180 | "const {a:b} = {}", | |
181 | "const {a:b=1} = {}", | |
182 | "const {[a]:b} = {}", | |
183 | "const {[a]:b=1} = {}", | |
184 | "const {[(a, b)]:c} = {}", | |
185 | "const {a, ...b} = {}", | |
186 | "class foo {}", | |
187 | "class foo { constructor(){} a(){} get b(){} set b(bar){} get c(){} set d(baz){} static e(){} }", | |
188 | "class foo { [a](){} get [b](){} set [b](bar){} get [c](){} set [d](baz){} static [e](){} }", | |
189 | "class foo { [(a,b)](){} }", | |
190 | "class foo { a(){} [b](){} c(){} [(d,e)](){} }", | |
191 | "class foo { [(a,b)](){} c(){} [d](){} e(){} }", | |
192 | "const foo = class { constructor(){} a(){} get b(){} set b(bar){} get c(){} set d(baz){} static e(){} }", | |
609c276f TL |
193 | "class foo { x; }", |
194 | "class foo { static x; }", | |
195 | "class foo { x = 1; }", | |
196 | "class foo { static x = 1; }", | |
197 | "class foo { #x; }", | |
198 | "class foo { static #x; }", | |
199 | "class foo { static #x = 1; }", | |
200 | "class foo { #x(){} get #y() {} set #y(value) {} static #z(){} static get #q() {} static set #q(value) {} }", | |
201 | "const foo = class { #x(){} get #y() {} set #y(value) {} static #z(){} static get #q() {} static set #q(value) {} }", | |
202 | "class foo { [(x, y)]; }", | |
203 | "class foo { static [(x, y)]; }", | |
204 | "class foo { [(x, y)] = 1; }", | |
205 | "class foo { static [(x, y)] = 1; }", | |
206 | "class foo { x = (y, z); }", | |
207 | "class foo { static x = (y, z); }", | |
208 | "class foo { #x = (y, z); }", | |
209 | "class foo { static #x = (y, z); }", | |
210 | "class foo { [(1, 2)] = (3, 4) }", | |
211 | "const foo = class { [(1, 2)] = (3, 4) }", | |
eb39fafa DC |
212 | |
213 | // ExpressionStatement restricted productions | |
214 | "({});", | |
215 | "(function(){});", | |
216 | "(let[a] = b);", | |
217 | "(function*(){});", | |
218 | "(class{});", | |
219 | ||
220 | // special cases | |
221 | "(0).a", | |
6f036462 TL |
222 | "(123).a", |
223 | "(08).a", | |
224 | "(09).a", | |
225 | "(018).a", | |
226 | "(012934).a", | |
227 | "(5_000).a", | |
228 | "(5_000_00).a", | |
eb39fafa DC |
229 | "(function(){ }())", |
230 | "({a: function(){}}.a());", | |
231 | "({a:0}.a ? b : c)", | |
232 | ||
233 | // RegExp literal is allowed to have parens (#1589) | |
234 | "var isA = (/^a$/).test('a');", | |
235 | "var regex = (/^a$/);", | |
236 | "function a(){ return (/^a$/); }", | |
237 | "function a(){ return (/^a$/).test('a'); }", | |
238 | "var isA = ((/^a$/)).test('a');", | |
239 | ||
240 | // IIFE is allowed to have parens in any position (#655) | |
241 | "var foo = (function() { return bar(); }())", | |
242 | "var o = { foo: (function() { return bar(); }()) };", | |
243 | "o.foo = (function(){ return bar(); }());", | |
244 | "(function(){ return bar(); }()), (function(){ return bar(); }())", | |
245 | ||
246 | // IIFE is allowed to have outer parens (#1004) | |
247 | "var foo = (function() { return bar(); })()", | |
248 | "var o = { foo: (function() { return bar(); })() };", | |
249 | "o.foo = (function(){ return bar(); })();", | |
250 | "(function(){ return bar(); })(), (function(){ return bar(); })()", | |
251 | "function foo() { return (function(){}()); }", | |
252 | ||
253 | // parens are required around yield | |
254 | "var foo = (function*() { if ((yield foo()) + 1) { return; } }())", | |
255 | ||
256 | // arrow functions have the precedence of an assignment expression | |
257 | "(() => 0)()", | |
258 | "(_ => 0)()", | |
259 | "_ => 0, _ => 1", | |
260 | "a = () => b = 0", | |
261 | "0 ? _ => 0 : _ => 0", | |
262 | "(_ => 0) || (_ => 0)", | |
263 | ||
264 | // Object literals as arrow function bodies need parentheses | |
265 | "x => ({foo: 1})", | |
266 | ||
267 | ||
268 | // Exponentiation operator `**` | |
269 | "1 + 2 ** 3", | |
270 | "1 - 2 ** 3", | |
271 | "2 ** -3", | |
272 | "(-2) ** 3", | |
273 | "(+2) ** 3", | |
274 | "+ (2 ** 3)", | |
275 | ||
276 | // https://github.com/eslint/eslint/issues/5789 | |
277 | "a => ({b: c}[d])", | |
278 | "a => ({b: c}.d())", | |
279 | "a => ({b: c}.d.e)", | |
280 | ||
281 | // "functions" enables reports for function nodes only | |
282 | { code: "(0)", options: ["functions"] }, | |
283 | { code: "((0))", options: ["functions"] }, | |
284 | { code: "a + (b * c)", options: ["functions"] }, | |
285 | { code: "a + ((b * c))", options: ["functions"] }, | |
286 | { code: "(a)(b)", options: ["functions"] }, | |
287 | { code: "((a))(b)", options: ["functions"] }, | |
288 | { code: "a, (b = c)", options: ["functions"] }, | |
289 | { code: "a, ((b = c))", options: ["functions"] }, | |
290 | { code: "for(a in (0));", options: ["functions"] }, | |
291 | { code: "for(a in ((0)));", options: ["functions"] }, | |
292 | { code: "var a = (b = c)", options: ["functions"] }, | |
293 | { code: "var a = ((b = c))", options: ["functions"] }, | |
294 | { code: "_ => (a = 0)", options: ["functions"] }, | |
295 | { code: "_ => ((a = 0))", options: ["functions"] }, | |
296 | ||
297 | // ["all", { conditionalAssign: false }] enables extra parens around conditional assignments | |
298 | { code: "while ((foo = bar())) {}", options: ["all", { conditionalAssign: false }] }, | |
299 | { code: "if ((foo = bar())) {}", options: ["all", { conditionalAssign: false }] }, | |
300 | { code: "do; while ((foo = bar()))", options: ["all", { conditionalAssign: false }] }, | |
301 | { code: "for (;(a = b););", options: ["all", { conditionalAssign: false }] }, | |
302 | { code: "var a = ((b = c)) ? foo : bar;", options: ["all", { conditionalAssign: false }] }, | |
303 | { code: "while (((foo = bar()))) {}", options: ["all", { conditionalAssign: false }] }, | |
304 | { code: "var a = (((b = c))) ? foo : bar;", options: ["all", { conditionalAssign: false }] }, | |
305 | ||
306 | // ["all", { nestedBinaryExpressions: false }] enables extra parens around conditional assignments | |
307 | { code: "a + (b * c)", options: ["all", { nestedBinaryExpressions: false }] }, | |
308 | { code: "(a * b) + c", options: ["all", { nestedBinaryExpressions: false }] }, | |
309 | { code: "(a * b) / c", options: ["all", { nestedBinaryExpressions: false }] }, | |
310 | { code: "a || (b && c)", options: ["all", { nestedBinaryExpressions: false }] }, | |
311 | { code: "a + ((b * c))", options: ["all", { nestedBinaryExpressions: false }] }, | |
312 | { code: "((a * b)) + c", options: ["all", { nestedBinaryExpressions: false }] }, | |
313 | { code: "((a * b)) / c", options: ["all", { nestedBinaryExpressions: false }] }, | |
314 | { code: "a || ((b && c))", options: ["all", { nestedBinaryExpressions: false }] }, | |
315 | ||
316 | // ["all", { returnAssign: false }] enables extra parens around expressions returned by return statements | |
317 | { code: "function a(b) { return b || c; }", options: ["all", { returnAssign: false }] }, | |
318 | { code: "function a(b) { return; }", options: ["all", { returnAssign: false }] }, | |
319 | { code: "function a(b) { return (b = 1); }", options: ["all", { returnAssign: false }] }, | |
320 | { code: "function a(b) { return (b = c) || (b = d); }", options: ["all", { returnAssign: false }] }, | |
321 | { code: "function a(b) { return c ? (d = b) : (e = b); }", options: ["all", { returnAssign: false }] }, | |
322 | { code: "b => b || c;", options: ["all", { returnAssign: false }] }, | |
323 | { code: "b => (b = 1);", options: ["all", { returnAssign: false }] }, | |
324 | { code: "b => (b = c) || (b = d);", options: ["all", { returnAssign: false }] }, | |
325 | { code: "b => c ? (d = b) : (e = b);", options: ["all", { returnAssign: false }] }, | |
326 | { code: "b => { return b || c };", options: ["all", { returnAssign: false }] }, | |
327 | { code: "b => { return (b = 1) };", options: ["all", { returnAssign: false }] }, | |
328 | { code: "b => { return (b = c) || (b = d) };", options: ["all", { returnAssign: false }] }, | |
329 | { code: "b => { return c ? (d = b) : (e = b) };", options: ["all", { returnAssign: false }] }, | |
330 | { code: "function a(b) { return ((b = 1)); }", options: ["all", { returnAssign: false }] }, | |
331 | { code: "b => ((b = 1));", options: ["all", { returnAssign: false }] }, | |
332 | ||
333 | // https://github.com/eslint/eslint/issues/3653 | |
334 | "(function(){}).foo(), 1, 2;", | |
335 | "(function(){}).foo++;", | |
336 | "(function(){}).foo() || bar;", | |
337 | "(function(){}).foo() + 1;", | |
338 | "(function(){}).foo() ? bar : baz;", | |
339 | "(function(){}).foo.bar();", | |
340 | "(function(){}.foo());", | |
341 | "(function(){}.foo.bar);", | |
342 | ||
343 | "(class{}).foo(), 1, 2;", | |
344 | "(class{}).foo++;", | |
345 | "(class{}).foo() || bar;", | |
346 | "(class{}).foo() + 1;", | |
347 | "(class{}).foo() ? bar : baz;", | |
348 | "(class{}).foo.bar();", | |
349 | "(class{}.foo());", | |
350 | "(class{}.foo.bar);", | |
351 | ||
352 | // https://github.com/eslint/eslint/issues/4608 | |
353 | "function *a() { yield b; }", | |
354 | "function *a() { yield yield; }", | |
355 | "function *a() { yield b, c; }", | |
356 | "function *a() { yield (b, c); }", | |
357 | "function *a() { yield b + c; }", | |
358 | "function *a() { (yield b) + c; }", | |
359 | ||
360 | // https://github.com/eslint/eslint/issues/4229 | |
361 | [ | |
362 | "function a() {", | |
363 | " return (", | |
364 | " b", | |
365 | " );", | |
366 | "}" | |
367 | ].join("\n"), | |
368 | [ | |
369 | "function a() {", | |
370 | " return (", | |
371 | " <JSX />", | |
372 | " );", | |
373 | "}" | |
374 | ].join("\n"), | |
375 | [ | |
376 | "function a() {", | |
377 | " return (", | |
378 | " <></>", | |
379 | " );", | |
380 | "}" | |
381 | ].join("\n"), | |
382 | [ | |
383 | "throw (", | |
384 | " a", | |
385 | ");" | |
386 | ].join("\n"), | |
387 | [ | |
388 | "function *a() {", | |
389 | " yield (", | |
390 | " b", | |
391 | " );", | |
392 | "}" | |
393 | ].join("\n"), | |
394 | ||
6f036462 TL |
395 | // linebreaks before postfix update operators are not allowed |
396 | "(a\n)++", | |
397 | "(a\n)--", | |
398 | "(a\n\n)++", | |
399 | "(a.b\n)--", | |
400 | "(a\n.b\n)++", | |
401 | "(a[\nb\n]\n)--", | |
402 | "(a[b]\n\n)++", | |
403 | ||
eb39fafa DC |
404 | // async/await |
405 | "async function a() { await (a + b) }", | |
406 | "async function a() { await (a + await b) }", | |
407 | "async function a() { (await a)() }", | |
408 | "async function a() { new (await a) }", | |
456be15e TL |
409 | "async function a() { await (a ** b) }", |
410 | "async function a() { (await a) ** b }", | |
411 | ||
eb39fafa DC |
412 | { code: "(foo instanceof bar) instanceof baz", options: ["all", { nestedBinaryExpressions: false }] }, |
413 | { code: "(foo in bar) in baz", options: ["all", { nestedBinaryExpressions: false }] }, | |
414 | { code: "(foo + bar) + baz", options: ["all", { nestedBinaryExpressions: false }] }, | |
415 | { code: "(foo && bar) && baz", options: ["all", { nestedBinaryExpressions: false }] }, | |
416 | { code: "foo instanceof (bar instanceof baz)", options: ["all", { nestedBinaryExpressions: false }] }, | |
417 | { code: "foo in (bar in baz)", options: ["all", { nestedBinaryExpressions: false }] }, | |
418 | { code: "foo + (bar + baz)", options: ["all", { nestedBinaryExpressions: false }] }, | |
419 | { code: "foo && (bar && baz)", options: ["all", { nestedBinaryExpressions: false }] }, | |
420 | { code: "((foo instanceof bar)) instanceof baz", options: ["all", { nestedBinaryExpressions: false }] }, | |
421 | { code: "((foo in bar)) in baz", options: ["all", { nestedBinaryExpressions: false }] }, | |
422 | ||
423 | // https://github.com/eslint/eslint/issues/9019 | |
424 | "(async function() {});", | |
425 | "(async function () { }());", | |
426 | ||
427 | // ["all", { ignoreJSX: "all" }] | |
428 | { code: "const Component = (<div />)", options: ["all", { ignoreJSX: "all" }] }, | |
429 | { code: "const Component = ((<div />))", options: ["all", { ignoreJSX: "all" }] }, | |
430 | { | |
431 | code: [ | |
432 | "const Component = (<>", | |
433 | " <p />", | |
434 | "</>);" | |
435 | ].join("\n"), | |
436 | options: ["all", { ignoreJSX: "all" }] | |
437 | }, | |
438 | { | |
439 | code: [ | |
440 | "const Component = ((<>", | |
441 | " <p />", | |
442 | "</>));" | |
443 | ].join("\n"), | |
444 | options: ["all", { ignoreJSX: "all" }] | |
445 | }, | |
446 | { | |
447 | code: [ | |
448 | "const Component = (<div>", | |
449 | " <p />", | |
450 | "</div>);" | |
451 | ].join("\n"), | |
452 | options: ["all", { ignoreJSX: "all" }] | |
453 | }, | |
454 | { | |
455 | code: [ | |
456 | "const Component = (", | |
457 | " <div />", | |
458 | ");" | |
459 | ].join("\n"), | |
460 | options: ["all", { ignoreJSX: "all" }] | |
461 | }, | |
462 | { | |
463 | code: [ | |
464 | "const Component =", | |
465 | " (<div />)" | |
466 | ].join("\n"), | |
467 | options: ["all", { ignoreJSX: "all" }] | |
468 | }, | |
469 | ||
470 | // ["all", { ignoreJSX: "single-line" }] | |
471 | { code: "const Component = (<div />);", options: ["all", { ignoreJSX: "single-line" }] }, | |
472 | { code: "const Component = ((<div />));", options: ["all", { ignoreJSX: "single-line" }] }, | |
473 | { | |
474 | code: [ | |
475 | "const Component = (", | |
476 | " <div />", | |
477 | ");" | |
478 | ].join("\n"), | |
479 | options: ["all", { ignoreJSX: "single-line" }] | |
480 | }, | |
481 | { | |
482 | code: [ | |
483 | "const Component =", | |
484 | "(<div />)" | |
485 | ].join("\n"), | |
486 | options: ["all", { ignoreJSX: "single-line" }] | |
487 | }, | |
488 | ||
489 | // ["all", { ignoreJSX: "multi-line" }] | |
490 | { | |
491 | code: [ | |
492 | "const Component = (", | |
493 | "<div>", | |
494 | " <p />", | |
495 | "</div>", | |
496 | ");" | |
497 | ].join("\n"), | |
498 | options: ["all", { ignoreJSX: "multi-line" }] | |
499 | }, | |
500 | { | |
501 | code: [ | |
502 | "const Component = ((", | |
503 | "<div>", | |
504 | " <p />", | |
505 | "</div>", | |
506 | "));" | |
507 | ].join("\n"), | |
508 | options: ["all", { ignoreJSX: "multi-line" }] | |
509 | }, | |
510 | { | |
511 | code: [ | |
512 | "const Component = (<div>", | |
513 | " <p />", | |
514 | "</div>);" | |
515 | ].join("\n"), | |
516 | options: ["all", { ignoreJSX: "multi-line" }] | |
517 | }, | |
518 | { | |
519 | code: [ | |
520 | "const Component =", | |
521 | "(<div>", | |
522 | " <p />", | |
523 | "</div>);" | |
524 | ].join("\n"), | |
525 | options: ["all", { ignoreJSX: "multi-line" }] | |
526 | }, | |
527 | { | |
528 | code: [ | |
529 | "const Component = (<div", | |
530 | " prop={true}", | |
531 | "/>)" | |
532 | ].join("\n"), | |
533 | options: ["all", { ignoreJSX: "multi-line" }] | |
534 | }, | |
535 | ||
536 | // ["all", { enforceForArrowConditionals: false }] | |
537 | { code: "var a = b => 1 ? 2 : 3", options: ["all", { enforceForArrowConditionals: false }] }, | |
538 | { code: "var a = (b) => (1 ? 2 : 3)", options: ["all", { enforceForArrowConditionals: false }] }, | |
539 | { code: "var a = (b) => ((1 ? 2 : 3))", options: ["all", { enforceForArrowConditionals: false }] }, | |
540 | ||
541 | // ["all", { enforceForSequenceExpressions: false }] | |
542 | { code: "(a, b)", options: ["all", { enforceForSequenceExpressions: false }] }, | |
543 | { code: "((a, b))", options: ["all", { enforceForSequenceExpressions: false }] }, | |
544 | { code: "(foo(), bar());", options: ["all", { enforceForSequenceExpressions: false }] }, | |
545 | { code: "((foo(), bar()));", options: ["all", { enforceForSequenceExpressions: false }] }, | |
546 | { code: "if((a, b)){}", options: ["all", { enforceForSequenceExpressions: false }] }, | |
547 | { code: "if(((a, b))){}", options: ["all", { enforceForSequenceExpressions: false }] }, | |
548 | { code: "while ((val = foo(), val < 10));", options: ["all", { enforceForSequenceExpressions: false }] }, | |
549 | ||
550 | // ["all", { enforceForNewInMemberExpressions: false }] | |
551 | { code: "(new foo()).bar", options: ["all", { enforceForNewInMemberExpressions: false }] }, | |
552 | { code: "(new foo())[bar]", options: ["all", { enforceForNewInMemberExpressions: false }] }, | |
553 | { code: "(new foo()).bar()", options: ["all", { enforceForNewInMemberExpressions: false }] }, | |
554 | { code: "(new foo(bar)).baz", options: ["all", { enforceForNewInMemberExpressions: false }] }, | |
555 | { code: "(new foo.bar()).baz", options: ["all", { enforceForNewInMemberExpressions: false }] }, | |
556 | { code: "(new foo.bar()).baz()", options: ["all", { enforceForNewInMemberExpressions: false }] }, | |
557 | { code: "((new foo.bar())).baz()", options: ["all", { enforceForNewInMemberExpressions: false }] }, | |
558 | ||
d3726936 TL |
559 | // ["all", { enforceForFunctionPrototypeMethods: false }] |
560 | { code: "var foo = (function(){}).call()", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
561 | { code: "var foo = (function(){}).apply()", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
562 | { code: "var foo = (function(){}.call())", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
563 | { code: "var foo = (function(){}.apply())", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
564 | { code: "var foo = (function(){}).call(arg)", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
565 | { code: "var foo = (function(){}.apply(arg))", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
566 | { code: "var foo = (function(){}['call']())", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
567 | { code: "var foo = (function(){})[`apply`]()", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
568 | { code: "var foo = ((function(){})).call()", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
569 | { code: "var foo = ((function(){}).apply())", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
570 | { code: "var foo = ((function(){}.call()))", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
571 | { code: "var foo = ((((function(){})).apply()))", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
572 | { code: "foo((function(){}).call().bar)", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
573 | { code: "foo = (function(){}).call()()", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
574 | { code: "foo = (function(){}.call())()", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
575 | { code: "var foo = { bar: (function(){}.call()) }", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
576 | { code: "var foo = { [(function(){}.call())]: bar }", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
577 | { code: "if((function(){}).call()){}", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
578 | { code: "while((function(){}.apply())){}", options: ["all", { enforceForFunctionPrototypeMethods: false }] }, | |
579 | ||
eb39fafa DC |
580 | "let a = [ ...b ]", |
581 | "let a = { ...b }", | |
582 | { | |
583 | code: "let a = { ...b }", | |
584 | parserOptions: { ecmaVersion: 2018 } | |
585 | }, | |
586 | "let a = [ ...(b, c) ]", | |
587 | "let a = { ...(b, c) }", | |
588 | { | |
589 | code: "let a = { ...(b, c) }", | |
590 | parserOptions: { ecmaVersion: 2018 } | |
591 | }, | |
592 | "var [x = (1, foo)] = bar", | |
593 | "class A extends B {}", | |
594 | "const A = class extends B {}", | |
595 | "class A extends (B=C) {}", | |
596 | "const A = class extends (B=C) {}", | |
597 | "class A extends (++foo) {}", | |
598 | "() => ({ foo: 1 })", | |
599 | "() => ({ foo: 1 }).foo", | |
600 | "() => ({ foo: 1 }.foo().bar).baz.qux()", | |
601 | "() => ({ foo: 1 }.foo().bar + baz)", | |
56c4a2cb DC |
602 | { |
603 | code: "export default (a, b)", | |
604 | parserOptions: { sourceType: "module" } | |
605 | }, | |
eb39fafa DC |
606 | { |
607 | code: "export default (function(){}).foo", | |
56c4a2cb | 608 | parserOptions: { sourceType: "module" } |
eb39fafa DC |
609 | }, |
610 | { | |
611 | code: "export default (class{}).foo", | |
56c4a2cb | 612 | parserOptions: { sourceType: "module" } |
eb39fafa DC |
613 | }, |
614 | "({}).hasOwnProperty.call(foo, bar)", | |
615 | "({}) ? foo() : bar()", | |
616 | "({}) + foo", | |
617 | "(function(){}) + foo", | |
618 | "(let)\nfoo", | |
619 | "(let[foo]) = 1", // setting the 'foo' property of the 'let' variable to 1 | |
620 | { | |
621 | code: "((function(){}).foo.bar)();", | |
622 | options: ["functions"] | |
623 | }, | |
624 | { | |
625 | code: "((function(){}).foo)();", | |
626 | options: ["functions"] | |
627 | }, | |
628 | "(let)[foo]", | |
456be15e TL |
629 | |
630 | // ForStatement#init expression cannot start with `let[`. It would be parsed as a `let` declaration with array pattern, or a syntax error. | |
631 | "for ((let[a]);;);", | |
632 | "for ((let)[a];;);", | |
633 | "for ((let[a] = 1);;);", | |
634 | "for ((let[a]) = 1;;);", | |
635 | "for ((let)[a] = 1;;);", | |
636 | "for ((let[a, b] = foo);;);", | |
637 | "for ((let[a].b = 1);;);", | |
638 | "for ((let[a].b) = 1;;);", | |
639 | "for ((let[a]).b = 1;;);", | |
640 | "for ((let)[a].b = 1;;);", | |
641 | "for ((let[a])();;);", | |
642 | "for ((let)[a]();;);", | |
643 | "for ((let[a]) + b;;);", | |
644 | ||
5422a9cc | 645 | // ForInStatement#left expression cannot start with `let[`. It would be parsed as a `let` declaration with array pattern, or a syntax error. |
eb39fafa DC |
646 | "for ((let[foo]) in bar);", |
647 | "for ((let)[foo] in bar);", | |
648 | "for ((let[foo].bar) in baz);", | |
5422a9cc TL |
649 | "for ((let[foo]).bar in baz);", |
650 | "for ((let)[foo].bar in baz);", | |
651 | ||
652 | // ForOfStatement#left expression cannot start with `let`. It's explicitly forbidden by the specification. | |
653 | "for ((let) of foo);", | |
654 | "for ((let).foo of bar);", | |
655 | "for ((let.foo) of bar);", | |
656 | "for ((let[foo]) of bar);", | |
657 | "for ((let)[foo] of bar);", | |
658 | "for ((let.foo.bar) of baz);", | |
659 | "for ((let.foo).bar of baz);", | |
660 | "for ((let).foo.bar of baz);", | |
661 | "for ((let[foo].bar) of baz);", | |
662 | "for ((let[foo]).bar of baz);", | |
663 | "for ((let)[foo].bar of baz);", | |
664 | "for ((let)().foo of bar);", | |
665 | "for ((let()).foo of bar);", | |
666 | "for ((let().foo) of bar);", | |
eb39fafa DC |
667 | |
668 | // https://github.com/eslint/eslint/issues/11706 (also in invalid[]) | |
669 | "for (let a = (b in c); ;);", | |
670 | "for (let a = (b && c in d); ;);", | |
671 | "for (let a = (b in c && d); ;);", | |
672 | "for (let a = (b => b in c); ;);", | |
673 | "for (let a = b => (b in c); ;);", | |
674 | "for (let a = (b in c in d); ;);", | |
675 | "for (let a = (b in c), d = (e in f); ;);", | |
676 | "for (let a = (b => c => b in c); ;);", | |
677 | "for (let a = (b && c && d in e); ;);", | |
678 | "for (let a = b && (c in d); ;);", | |
679 | "for (let a = (b in c) && (d in e); ;);", | |
680 | "for ((a in b); ;);", | |
681 | "for (a = (b in c); ;);", | |
682 | "for ((a in b && c in d && e in f); ;);", | |
683 | "for (let a = [] && (b in c); ;);", | |
684 | "for (let a = (b in [c]); ;);", | |
685 | "for (let a = b => (c in d); ;);", | |
686 | "for (let a = (b in c) ? d : e; ;);", | |
687 | "for (let a = (b in c ? d : e); ;);", | |
688 | "for (let a = b ? c : (d in e); ;);", | |
689 | "for (let a = (b in c), d = () => { for ((e in f);;); for ((g in h);;); }; ;); for((i in j); ;);", | |
690 | ||
691 | // https://github.com/eslint/eslint/issues/11706 regression tests (also in invalid[]) | |
692 | "for (let a = b; a; a); a; a;", | |
693 | "for (a; a; a); a; a;", | |
694 | "for (; a; a); a; a;", | |
d3726936 TL |
695 | "for (let a = (b && c) === d; ;);", |
696 | ||
6f036462 TL |
697 | "new (a()).b.c;", |
698 | "new (a().b).c;", | |
699 | "new (a().b.c);", | |
700 | "new (a().b().d);", | |
701 | "new a().b().d;", | |
702 | "new (a(b()).c)", | |
703 | "new (a.b()).c", | |
704 | ||
d3726936 TL |
705 | // Nullish coalescing |
706 | { code: "var v = (a ?? b) || c", parserOptions: { ecmaVersion: 2020 } }, | |
707 | { code: "var v = a ?? (b || c)", parserOptions: { ecmaVersion: 2020 } }, | |
708 | { code: "var v = (a ?? b) && c", parserOptions: { ecmaVersion: 2020 } }, | |
709 | { code: "var v = a ?? (b && c)", parserOptions: { ecmaVersion: 2020 } }, | |
710 | { code: "var v = (a || b) ?? c", parserOptions: { ecmaVersion: 2020 } }, | |
711 | { code: "var v = a || (b ?? c)", parserOptions: { ecmaVersion: 2020 } }, | |
712 | { code: "var v = (a && b) ?? c", parserOptions: { ecmaVersion: 2020 } }, | |
6f036462 TL |
713 | { code: "var v = a && (b ?? c)", parserOptions: { ecmaVersion: 2020 } }, |
714 | ||
715 | // Optional chaining | |
716 | { code: "var v = (obj?.aaa).bbb", parserOptions: { ecmaVersion: 2020 } }, | |
717 | { code: "var v = (obj?.aaa)()", parserOptions: { ecmaVersion: 2020 } }, | |
718 | { code: "var v = new (obj?.aaa)()", parserOptions: { ecmaVersion: 2020 } }, | |
719 | { code: "var v = new (obj?.aaa)", parserOptions: { ecmaVersion: 2020 } }, | |
720 | { code: "var v = (obj?.aaa)`template`", parserOptions: { ecmaVersion: 2020 } }, | |
721 | { code: "var v = (obj?.()).bbb", parserOptions: { ecmaVersion: 2020 } }, | |
722 | { code: "var v = (obj?.())()", parserOptions: { ecmaVersion: 2020 } }, | |
723 | { code: "var v = new (obj?.())()", parserOptions: { ecmaVersion: 2020 } }, | |
724 | { code: "var v = new (obj?.())", parserOptions: { ecmaVersion: 2020 } }, | |
725 | { code: "var v = (obj?.())`template`", parserOptions: { ecmaVersion: 2020 } }, | |
726 | { code: "(obj?.aaa).bbb = 0", parserOptions: { ecmaVersion: 2020 } }, | |
727 | { code: "var foo = (function(){})?.()", parserOptions: { ecmaVersion: 2020 } }, | |
728 | { code: "var foo = (function(){}?.())", parserOptions: { ecmaVersion: 2020 } }, | |
729 | { | |
730 | code: "var foo = (function(){})?.call()", | |
731 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
732 | parserOptions: { ecmaVersion: 2020 } | |
733 | }, | |
734 | { | |
735 | code: "var foo = (function(){}?.call())", | |
736 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
737 | parserOptions: { ecmaVersion: 2020 } | |
738 | } | |
eb39fafa DC |
739 | ], |
740 | ||
741 | invalid: [ | |
742 | invalid("(0)", "0", "Literal"), | |
743 | invalid("( 0 )", " 0 ", "Literal"), | |
744 | invalid("if((0));", "if(0);", "Literal"), | |
745 | invalid("if(( 0 ));", "if( 0 );", "Literal"), | |
746 | invalid("with((0)){}", "with(0){}", "Literal"), | |
747 | invalid("switch((0)){}", "switch(0){}", "Literal"), | |
748 | invalid("switch(0){ case (1): break; }", "switch(0){ case 1: break; }", "Literal"), | |
749 | invalid("for((0);;);", "for(0;;);", "Literal"), | |
750 | invalid("for(;(0););", "for(;0;);", "Literal"), | |
751 | invalid("for(;;(0));", "for(;;0);", "Literal"), | |
752 | invalid("throw(0)", "throw 0", "Literal"), | |
753 | invalid("while((0));", "while(0);", "Literal"), | |
754 | invalid("do; while((0))", "do; while(0)", "Literal"), | |
755 | invalid("for(a in (0));", "for(a in 0);", "Literal"), | |
756 | invalid("for(a of (0));", "for(a of 0);", "Literal", 1), | |
757 | invalid("const foo = {[(a)]:1}", "const foo = {[a]:1}", "Identifier", 1), | |
758 | invalid("const foo = {[(a=b)]:1}", "const foo = {[a=b]:1}", "AssignmentExpression", 1), | |
759 | invalid("const foo = {*[(Symbol.iterator)]() {}}", "const foo = {*[Symbol.iterator]() {}}", "MemberExpression", 1), | |
760 | invalid("const foo = { get [(a)]() {}}", "const foo = { get [a]() {}}", "Identifier", 1), | |
761 | invalid("const foo = {[(a+b)]:c, d}", "const foo = {[a+b]:c, d}", "BinaryExpression", 1), | |
762 | invalid("const foo = {a, [(b+c)]:d, e}", "const foo = {a, [b+c]:d, e}", "BinaryExpression", 1), | |
763 | invalid("const foo = {[(a+b)]:c, d:e}", "const foo = {[a+b]:c, d:e}", "BinaryExpression", 1), | |
764 | invalid("const foo = {a:b, [(c+d)]:e, f:g}", "const foo = {a:b, [c+d]:e, f:g}", "BinaryExpression", 1), | |
765 | invalid("const foo = {[(a+b)]:c, [d]:e}", "const foo = {[a+b]:c, [d]:e}", "BinaryExpression", 1), | |
766 | invalid("const foo = {[a]:b, [(c+d)]:e, [f]:g}", "const foo = {[a]:b, [c+d]:e, [f]:g}", "BinaryExpression", 1), | |
767 | invalid("const foo = {[(a+b)]:c, [(d,e)]:f}", "const foo = {[a+b]:c, [(d,e)]:f}", "BinaryExpression", 1), | |
768 | invalid("const foo = {[(a,b)]:c, [(d+e)]:f, [(g,h)]:e}", "const foo = {[(a,b)]:c, [d+e]:f, [(g,h)]:e}", "BinaryExpression", 1), | |
769 | invalid("const foo = {a, b:c, [(d+e)]:f, [(g,h)]:i, [j]:k}", "const foo = {a, b:c, [d+e]:f, [(g,h)]:i, [j]:k}", "BinaryExpression", 1), | |
770 | invalid("const foo = {[a+(b*c)]:d}", "const foo = {[a+b*c]:d}", "BinaryExpression", 1), | |
771 | invalid("const foo = {[(a, (b+c))]:d}", "const foo = {[(a, b+c)]:d}", "BinaryExpression", 1), | |
772 | invalid("const {[(a)]:b} = {}", "const {[a]:b} = {}", "Identifier", 1), | |
773 | invalid("const {[(a=b)]:c=1} = {}", "const {[a=b]:c=1} = {}", "AssignmentExpression", 1), | |
774 | invalid("const {[(a+b)]:c, d} = {}", "const {[a+b]:c, d} = {}", "BinaryExpression", 1), | |
775 | invalid("const {a, [(b+c)]:d, e} = {}", "const {a, [b+c]:d, e} = {}", "BinaryExpression", 1), | |
776 | invalid("const {[(a+b)]:c, d:e} = {}", "const {[a+b]:c, d:e} = {}", "BinaryExpression", 1), | |
777 | invalid("const {a:b, [(c+d)]:e, f:g} = {}", "const {a:b, [c+d]:e, f:g} = {}", "BinaryExpression", 1), | |
778 | invalid("const {[(a+b)]:c, [d]:e} = {}", "const {[a+b]:c, [d]:e} = {}", "BinaryExpression", 1), | |
779 | invalid("const {[a]:b, [(c+d)]:e, [f]:g} = {}", "const {[a]:b, [c+d]:e, [f]:g} = {}", "BinaryExpression", 1), | |
780 | invalid("const {[(a+b)]:c, [(d,e)]:f} = {}", "const {[a+b]:c, [(d,e)]:f} = {}", "BinaryExpression", 1), | |
781 | invalid("const {[(a,b)]:c, [(d+e)]:f, [(g,h)]:e} = {}", "const {[(a,b)]:c, [d+e]:f, [(g,h)]:e} = {}", "BinaryExpression", 1), | |
782 | invalid("const {a, b:c, [(d+e)]:f, [(g,h)]:i, [j]:k} = {}", "const {a, b:c, [d+e]:f, [(g,h)]:i, [j]:k} = {}", "BinaryExpression", 1), | |
783 | invalid("const {[a+(b*c)]:d} = {}", "const {[a+b*c]:d} = {}", "BinaryExpression", 1), | |
784 | invalid("const {[(a, (b+c))]:d} = {}", "const {[(a, b+c)]:d} = {}", "BinaryExpression", 1), | |
785 | invalid("class foo { [(a)](){} }", "class foo { [a](){} }", "Identifier"), | |
786 | invalid("class foo {*[(Symbol.iterator)]() {}}", "class foo {*[Symbol.iterator]() {}}", "MemberExpression"), | |
787 | invalid("class foo { get [(a)](){} }", "class foo { get [a](){} }", "Identifier"), | |
788 | invalid("class foo { set [(a)](bar){} }", "class foo { set [a](bar){} }", "Identifier"), | |
789 | invalid("class foo { static [(a)](bar){} }", "class foo { static [a](bar){} }", "Identifier"), | |
790 | invalid("class foo { [(a=b)](){} }", "class foo { [a=b](){} }", "AssignmentExpression"), | |
791 | invalid("class foo { constructor (){} [(a+b)](){} }", "class foo { constructor (){} [a+b](){} }", "BinaryExpression"), | |
792 | invalid("class foo { [(a+b)](){} constructor (){} }", "class foo { [a+b](){} constructor (){} }", "BinaryExpression"), | |
793 | invalid("class foo { [(a+b)](){} c(){} }", "class foo { [a+b](){} c(){} }", "BinaryExpression"), | |
794 | invalid("class foo { a(){} [(b+c)](){} d(){} }", "class foo { a(){} [b+c](){} d(){} }", "BinaryExpression"), | |
795 | invalid("class foo { [(a+b)](){} [c](){} }", "class foo { [a+b](){} [c](){} }", "BinaryExpression"), | |
796 | invalid("class foo { [a](){} [(b+c)](){} [d](){} }", "class foo { [a](){} [b+c](){} [d](){} }", "BinaryExpression"), | |
797 | invalid("class foo { [(a+b)](){} [(c,d)](){} }", "class foo { [a+b](){} [(c,d)](){} }", "BinaryExpression"), | |
798 | invalid("class foo { [(a,b)](){} [(c+d)](){} }", "class foo { [(a,b)](){} [c+d](){} }", "BinaryExpression"), | |
799 | invalid("class foo { [a+(b*c)](){} }", "class foo { [a+b*c](){} }", "BinaryExpression"), | |
800 | invalid("const foo = class { [(a)](){} }", "const foo = class { [a](){} }", "Identifier"), | |
609c276f TL |
801 | invalid("class foo { [(x)]; }", "class foo { [x]; }", "Identifier"), |
802 | invalid("class foo { static [(x)]; }", "class foo { static [x]; }", "Identifier"), | |
803 | invalid("class foo { [(x)] = 1; }", "class foo { [x] = 1; }", "Identifier"), | |
804 | invalid("class foo { static [(x)] = 1; }", "class foo { static [x] = 1; }", "Identifier"), | |
805 | invalid("const foo = class { [(x)]; }", "const foo = class { [x]; }", "Identifier"), | |
806 | invalid("class foo { [(x = y)]; }", "class foo { [x = y]; }", "AssignmentExpression"), | |
807 | invalid("class foo { [(x + y)]; }", "class foo { [x + y]; }", "BinaryExpression"), | |
808 | invalid("class foo { [(x ? y : z)]; }", "class foo { [x ? y : z]; }", "ConditionalExpression"), | |
809 | invalid("class foo { [((x, y))]; }", "class foo { [(x, y)]; }", "SequenceExpression"), | |
810 | invalid("class foo { x = (y); }", "class foo { x = y; }", "Identifier"), | |
811 | invalid("class foo { static x = (y); }", "class foo { static x = y; }", "Identifier"), | |
812 | invalid("class foo { #x = (y); }", "class foo { #x = y; }", "Identifier"), | |
813 | invalid("class foo { static #x = (y); }", "class foo { static #x = y; }", "Identifier"), | |
814 | invalid("const foo = class { x = (y); }", "const foo = class { x = y; }", "Identifier"), | |
815 | invalid("class foo { x = (() => {}); }", "class foo { x = () => {}; }", "ArrowFunctionExpression"), | |
816 | invalid("class foo { x = (y + z); }", "class foo { x = y + z; }", "BinaryExpression"), | |
817 | invalid("class foo { x = (y ? z : q); }", "class foo { x = y ? z : q; }", "ConditionalExpression"), | |
818 | invalid("class foo { x = ((y, z)); }", "class foo { x = (y, z); }", "SequenceExpression"), | |
819 | ||
820 | // | |
eb39fafa DC |
821 | invalid( |
822 | "var foo = (function*() { if ((yield foo())) { return; } }())", | |
823 | "var foo = (function*() { if (yield foo()) { return; } }())", | |
824 | "YieldExpression", | |
825 | 1 | |
826 | ), | |
827 | invalid("f((0))", "f(0)", "Literal"), | |
828 | invalid("f(0, (1))", "f(0, 1)", "Literal"), | |
829 | invalid("!(0)", "!0", "Literal"), | |
830 | invalid("a[(1)]", "a[1]", "Literal"), | |
831 | invalid("(a)(b)", "a(b)", "Identifier"), | |
832 | invalid("(async)", "async", "Identifier"), | |
833 | invalid("(a, b)", "a, b", "SequenceExpression"), | |
834 | invalid("var a = (b = c);", "var a = b = c;", "AssignmentExpression"), | |
835 | invalid("function f(){ return (a); }", "function f(){ return a; }", "Identifier"), | |
836 | invalid("[a, (b = c)]", "[a, b = c]", "AssignmentExpression"), | |
837 | invalid("!{a: (b = c)}", "!{a: b = c}", "AssignmentExpression"), | |
838 | invalid("typeof(0)", "typeof 0", "Literal"), | |
839 | invalid("typeof (0)", "typeof 0", "Literal"), | |
840 | invalid("typeof([])", "typeof[]", "ArrayExpression"), | |
841 | invalid("typeof ([])", "typeof []", "ArrayExpression"), | |
842 | invalid("typeof( 0)", "typeof 0", "Literal"), | |
843 | invalid("typeof(typeof 5)", "typeof typeof 5", "UnaryExpression"), | |
844 | invalid("typeof (typeof 5)", "typeof typeof 5", "UnaryExpression"), | |
845 | invalid("+(+foo)", "+ +foo", "UnaryExpression"), | |
846 | invalid("-(-foo)", "- -foo", "UnaryExpression"), | |
847 | invalid("+(-foo)", "+-foo", "UnaryExpression"), | |
848 | invalid("-(+foo)", "-+foo", "UnaryExpression"), | |
849 | invalid("-((bar+foo))", "-(bar+foo)", "BinaryExpression"), | |
850 | invalid("+((bar-foo))", "+(bar-foo)", "BinaryExpression"), | |
851 | invalid("++(foo)", "++foo", "Identifier"), | |
852 | invalid("--(foo)", "--foo", "Identifier"), | |
6f036462 TL |
853 | invalid("++\n(foo)", "++\nfoo", "Identifier"), |
854 | invalid("--\n(foo)", "--\nfoo", "Identifier"), | |
855 | invalid("++(\nfoo)", "++\nfoo", "Identifier"), | |
856 | invalid("--(\nfoo)", "--\nfoo", "Identifier"), | |
857 | invalid("(foo)++", "foo++", "Identifier"), | |
858 | invalid("(foo)--", "foo--", "Identifier"), | |
859 | invalid("((foo)\n)++", "(foo\n)++", "Identifier"), | |
860 | invalid("((foo\n))--", "(foo\n)--", "Identifier"), | |
861 | invalid("((foo\n)\n)++", "(foo\n\n)++", "Identifier"), | |
862 | invalid("(a\n.b)--", "a\n.b--", "MemberExpression"), | |
863 | invalid("(a.\nb)++", "a.\nb++", "MemberExpression"), | |
864 | invalid("(a\n[\nb\n])--", "a\n[\nb\n]--", "MemberExpression"), | |
eb39fafa DC |
865 | invalid("(a || b) ? c : d", "a || b ? c : d", "LogicalExpression"), |
866 | invalid("a ? (b = c) : d", "a ? b = c : d", "AssignmentExpression"), | |
867 | invalid("a ? b : (c = d)", "a ? b : c = d", "AssignmentExpression"), | |
868 | invalid("(c = d) ? (b) : c", "(c = d) ? b : c", "Identifier", null, { options: ["all", { conditionalAssign: false }] }), | |
869 | invalid("(c = d) ? b : (c)", "(c = d) ? b : c", "Identifier", null, { options: ["all", { conditionalAssign: false }] }), | |
870 | invalid("f((a = b))", "f(a = b)", "AssignmentExpression"), | |
871 | invalid("a, (b = c)", "a, b = c", "AssignmentExpression"), | |
872 | invalid("a = (b * c)", "a = b * c", "BinaryExpression"), | |
873 | invalid("a + (b * c)", "a + b * c", "BinaryExpression"), | |
874 | invalid("(a * b) + c", "a * b + c", "BinaryExpression"), | |
875 | invalid("(a * b) / c", "a * b / c", "BinaryExpression"), | |
876 | invalid("(2) ** 3 ** 4", "2 ** 3 ** 4", "Literal", null), | |
877 | invalid("2 ** (3 ** 4)", "2 ** 3 ** 4", "BinaryExpression", null), | |
878 | invalid("(2 ** 3)", "2 ** 3", "BinaryExpression", null), | |
879 | invalid("(2 ** 3) + 1", "2 ** 3 + 1", "BinaryExpression", null), | |
880 | invalid("1 - (2 ** 3)", "1 - 2 ** 3", "BinaryExpression", null), | |
881 | invalid("-((2 ** 3))", "-(2 ** 3)", "BinaryExpression", null), | |
882 | invalid("typeof ((a ** b));", "typeof (a ** b);", "BinaryExpression", null), | |
883 | invalid("((-2)) ** 3", "(-2) ** 3", "UnaryExpression", null), | |
884 | ||
885 | invalid("a = (b * c)", "a = b * c", "BinaryExpression", null, { options: ["all", { nestedBinaryExpressions: false }] }), | |
886 | invalid("(b * c)", "b * c", "BinaryExpression", null, { options: ["all", { nestedBinaryExpressions: false }] }), | |
887 | ||
888 | invalid("a = (b = c)", "a = b = c", "AssignmentExpression"), | |
889 | invalid("(a).b", "a.b", "Identifier"), | |
890 | invalid("(0)[a]", "0[a]", "Literal"), | |
891 | invalid("(0.0).a", "0.0.a", "Literal"), | |
6f036462 TL |
892 | invalid("(123.4).a", "123.4.a", "Literal"), |
893 | invalid("(0.0_0).a", "0.0_0.a", "Literal"), | |
eb39fafa | 894 | invalid("(0xBEEF).a", "0xBEEF.a", "Literal"), |
6f036462 | 895 | invalid("(0xBE_EF).a", "0xBE_EF.a", "Literal"), |
eb39fafa DC |
896 | invalid("(1e6).a", "1e6.a", "Literal"), |
897 | invalid("(0123).a", "0123.a", "Literal"), | |
6f036462 TL |
898 | invalid("(08.1).a", "08.1.a", "Literal"), |
899 | invalid("(09.).a", "09..a", "Literal"), | |
eb39fafa DC |
900 | invalid("a[(function() {})]", "a[function() {}]", "FunctionExpression"), |
901 | invalid("new (function(){})", "new function(){}", "FunctionExpression"), | |
902 | invalid("new (\nfunction(){}\n)", "new \nfunction(){}\n", "FunctionExpression", 1), | |
903 | invalid("((function foo() {return 1;}))()", "(function foo() {return 1;})()", "FunctionExpression"), | |
904 | invalid("((function(){ return bar(); })())", "(function(){ return bar(); })()", "CallExpression"), | |
905 | invalid("(foo()).bar", "foo().bar", "CallExpression"), | |
906 | invalid("(foo.bar()).baz", "foo.bar().baz", "CallExpression"), | |
907 | invalid("(foo\n.bar())\n.baz", "foo\n.bar()\n.baz", "CallExpression"), | |
908 | invalid("(new foo()).bar", "new foo().bar", "NewExpression"), | |
909 | invalid("(new foo())[bar]", "new foo()[bar]", "NewExpression"), | |
910 | invalid("(new foo()).bar()", "new foo().bar()", "NewExpression"), | |
911 | invalid("(new foo(bar)).baz", "new foo(bar).baz", "NewExpression"), | |
912 | invalid("(new foo.bar()).baz", "new foo.bar().baz", "NewExpression"), | |
913 | invalid("(new foo.bar()).baz()", "new foo.bar().baz()", "NewExpression"), | |
6f036462 | 914 | invalid("new a[(b()).c]", "new a[b().c]", "CallExpression"), |
eb39fafa DC |
915 | |
916 | invalid("(a)()", "a()", "Identifier"), | |
917 | invalid("(a.b)()", "a.b()", "MemberExpression"), | |
918 | invalid("(a())()", "a()()", "CallExpression"), | |
919 | invalid("(a.b())()", "a.b()()", "CallExpression"), | |
920 | invalid("(a().b)()", "a().b()", "MemberExpression"), | |
921 | invalid("(a().b.c)()", "a().b.c()", "MemberExpression"), | |
922 | invalid("new (A)", "new A", "Identifier"), | |
923 | invalid("(new A())()", "new A()()", "NewExpression"), | |
924 | invalid("(new A(1))()", "new A(1)()", "NewExpression"), | |
925 | invalid("((new A))()", "(new A)()", "NewExpression"), | |
926 | invalid("new (foo\n.baz\n.bar\n.foo.baz)", "new foo\n.baz\n.bar\n.foo.baz", "MemberExpression"), | |
927 | invalid("new (foo.baz.bar.baz)", "new foo.baz.bar.baz", "MemberExpression"), | |
6f036462 TL |
928 | invalid("new ((a.b())).c", "new (a.b()).c", "CallExpression"), |
929 | invalid("new ((a().b)).c", "new (a().b).c", "MemberExpression"), | |
930 | invalid("new ((a().b().d))", "new (a().b().d)", "MemberExpression"), | |
931 | invalid("new ((a())).b.d", "new (a()).b.d", "CallExpression"), | |
932 | invalid("new (a.b).d;", "new a.b.d;", "MemberExpression"), | |
456be15e TL |
933 | invalid("new (new A())();", "new new A()();", "NewExpression"), |
934 | invalid("new (new A());", "new new A();", "NewExpression"), | |
935 | invalid("new (new A);", "new new A;", "NewExpression"), | |
936 | invalid("new (new a.b);", "new new a.b;", "NewExpression"), | |
6f036462 TL |
937 | invalid("(a().b).d;", "a().b.d;", "MemberExpression"), |
938 | invalid("(a.b()).d;", "a.b().d;", "CallExpression"), | |
939 | invalid("(a.b).d;", "a.b.d;", "MemberExpression"), | |
eb39fafa DC |
940 | |
941 | invalid("0, (_ => 0)", "0, _ => 0", "ArrowFunctionExpression", 1), | |
942 | invalid("(_ => 0), 0", "_ => 0, 0", "ArrowFunctionExpression", 1), | |
943 | invalid("a = (_ => 0)", "a = _ => 0", "ArrowFunctionExpression", 1), | |
944 | invalid("_ => (a = 0)", "_ => a = 0", "AssignmentExpression", 1), | |
945 | invalid("x => (({}))", "x => ({})", "ObjectExpression", 1), | |
946 | ||
947 | invalid("new (function(){})", "new function(){}", "FunctionExpression", null, { options: ["functions"] }), | |
948 | invalid("new (\nfunction(){}\n)", "new \nfunction(){}\n", "FunctionExpression", 1, { options: ["functions"] }), | |
949 | invalid("((function foo() {return 1;}))()", "(function foo() {return 1;})()", "FunctionExpression", null, { options: ["functions"] }), | |
950 | invalid("a[(function() {})]", "a[function() {}]", "FunctionExpression", null, { options: ["functions"] }), | |
951 | invalid("0, (_ => 0)", "0, _ => 0", "ArrowFunctionExpression", 1, { options: ["functions"] }), | |
952 | invalid("(_ => 0), 0", "_ => 0, 0", "ArrowFunctionExpression", 1, { options: ["functions"] }), | |
953 | invalid("a = (_ => 0)", "a = _ => 0", "ArrowFunctionExpression", 1, { options: ["functions"] }), | |
954 | ||
955 | ||
956 | invalid("while ((foo = bar())) {}", "while (foo = bar()) {}", "AssignmentExpression"), | |
957 | invalid("while ((foo = bar())) {}", "while (foo = bar()) {}", "AssignmentExpression", 1, { options: ["all", { conditionalAssign: true }] }), | |
958 | invalid("if ((foo = bar())) {}", "if (foo = bar()) {}", "AssignmentExpression"), | |
959 | invalid("do; while ((foo = bar()))", "do; while (foo = bar())", "AssignmentExpression"), | |
960 | invalid("for (;(a = b););", "for (;a = b;);", "AssignmentExpression"), | |
961 | ||
962 | // https://github.com/eslint/eslint/issues/3653 | |
963 | invalid("((function(){})).foo();", "(function(){}).foo();", "FunctionExpression"), | |
964 | invalid("((function(){}).foo());", "(function(){}).foo();", "CallExpression"), | |
965 | invalid("((function(){}).foo);", "(function(){}).foo;", "MemberExpression"), | |
966 | invalid("0, (function(){}).foo();", "0, function(){}.foo();", "FunctionExpression"), | |
967 | invalid("void (function(){}).foo();", "void function(){}.foo();", "FunctionExpression"), | |
968 | invalid("++(function(){}).foo;", "++function(){}.foo;", "FunctionExpression"), | |
969 | invalid("bar || (function(){}).foo();", "bar || function(){}.foo();", "FunctionExpression"), | |
970 | invalid("1 + (function(){}).foo();", "1 + function(){}.foo();", "FunctionExpression"), | |
971 | invalid("bar ? (function(){}).foo() : baz;", "bar ? function(){}.foo() : baz;", "FunctionExpression"), | |
972 | invalid("bar ? baz : (function(){}).foo();", "bar ? baz : function(){}.foo();", "FunctionExpression"), | |
973 | invalid("bar((function(){}).foo(), 0);", "bar(function(){}.foo(), 0);", "FunctionExpression"), | |
974 | invalid("bar[(function(){}).foo()];", "bar[function(){}.foo()];", "FunctionExpression"), | |
975 | invalid("var bar = (function(){}).foo();", "var bar = function(){}.foo();", "FunctionExpression"), | |
976 | ||
977 | invalid("((class{})).foo();", "(class{}).foo();", "ClassExpression", null), | |
978 | invalid("((class{}).foo());", "(class{}).foo();", "CallExpression", null), | |
979 | invalid("((class{}).foo);", "(class{}).foo;", "MemberExpression", null), | |
980 | invalid("0, (class{}).foo();", "0, class{}.foo();", "ClassExpression", null), | |
981 | invalid("void (class{}).foo();", "void class{}.foo();", "ClassExpression", null), | |
982 | invalid("++(class{}).foo;", "++class{}.foo;", "ClassExpression", null), | |
983 | invalid("bar || (class{}).foo();", "bar || class{}.foo();", "ClassExpression", null), | |
984 | invalid("1 + (class{}).foo();", "1 + class{}.foo();", "ClassExpression", null), | |
985 | invalid("bar ? (class{}).foo() : baz;", "bar ? class{}.foo() : baz;", "ClassExpression", null), | |
986 | invalid("bar ? baz : (class{}).foo();", "bar ? baz : class{}.foo();", "ClassExpression", null), | |
987 | invalid("bar((class{}).foo(), 0);", "bar(class{}.foo(), 0);", "ClassExpression", null), | |
988 | invalid("bar[(class{}).foo()];", "bar[class{}.foo()];", "ClassExpression", null), | |
989 | invalid("var bar = (class{}).foo();", "var bar = class{}.foo();", "ClassExpression", null), | |
990 | invalid("var foo = ((bar, baz));", "var foo = (bar, baz);", "SequenceExpression", null), | |
991 | ||
992 | // https://github.com/eslint/eslint/issues/4608 | |
993 | invalid("function *a() { yield (b); }", "function *a() { yield b; }", "Identifier", null), | |
994 | invalid("function *a() { (yield b), c; }", "function *a() { yield b, c; }", "YieldExpression", null), | |
995 | invalid("function *a() { yield ((b, c)); }", "function *a() { yield (b, c); }", "SequenceExpression", null), | |
996 | invalid("function *a() { yield (b + c); }", "function *a() { yield b + c; }", "BinaryExpression", null), | |
997 | ||
998 | // https://github.com/eslint/eslint/issues/4229 | |
999 | invalid([ | |
1000 | "function a() {", | |
1001 | " return (b);", | |
1002 | "}" | |
1003 | ].join("\n"), [ | |
1004 | "function a() {", | |
1005 | " return b;", | |
1006 | "}" | |
1007 | ].join("\n"), "Identifier"), | |
1008 | invalid([ | |
1009 | "function a() {", | |
1010 | " return", | |
1011 | " (b);", | |
1012 | "}" | |
1013 | ].join("\n"), [ | |
1014 | "function a() {", | |
1015 | " return", | |
1016 | " b;", | |
1017 | "}" | |
1018 | ].join("\n"), "Identifier"), | |
1019 | invalid([ | |
1020 | "function a() {", | |
1021 | " return ((", | |
1022 | " b", | |
1023 | " ));", | |
1024 | "}" | |
1025 | ].join("\n"), [ | |
1026 | "function a() {", | |
1027 | " return (", | |
1028 | " b", | |
1029 | " );", | |
1030 | "}" | |
1031 | ].join("\n"), "Identifier"), | |
1032 | invalid([ | |
1033 | "function a() {", | |
1034 | " return (<JSX />);", | |
1035 | "}" | |
1036 | ].join("\n"), [ | |
1037 | "function a() {", | |
1038 | " return <JSX />;", | |
1039 | "}" | |
1040 | ].join("\n"), "JSXElement", null), | |
1041 | invalid([ | |
1042 | "function a() {", | |
1043 | " return", | |
1044 | " (<JSX />);", | |
1045 | "}" | |
1046 | ].join("\n"), [ | |
1047 | "function a() {", | |
1048 | " return", | |
1049 | " <JSX />;", | |
1050 | "}" | |
1051 | ].join("\n"), "JSXElement", null), | |
1052 | invalid([ | |
1053 | "function a() {", | |
1054 | " return ((", | |
1055 | " <JSX />", | |
1056 | " ));", | |
1057 | "}" | |
1058 | ].join("\n"), [ | |
1059 | "function a() {", | |
1060 | " return (", | |
1061 | " <JSX />", | |
1062 | " );", | |
1063 | "}" | |
1064 | ].join("\n"), "JSXElement", null), | |
1065 | invalid([ | |
1066 | "function a() {", | |
1067 | " return ((", | |
1068 | " <></>", | |
1069 | " ));", | |
1070 | "}" | |
1071 | ].join("\n"), [ | |
1072 | "function a() {", | |
1073 | " return (", | |
1074 | " <></>", | |
1075 | " );", | |
1076 | "}" | |
1077 | ].join("\n"), "JSXFragment", null), | |
1078 | invalid("throw (a);", "throw a;", "Identifier"), | |
1079 | invalid([ | |
1080 | "throw ((", | |
1081 | " a", | |
1082 | "));" | |
1083 | ].join("\n"), [ | |
1084 | "throw (", | |
1085 | " a", | |
1086 | ");" | |
1087 | ].join("\n"), "Identifier"), | |
1088 | invalid([ | |
1089 | "function *a() {", | |
1090 | " yield (b);", | |
1091 | "}" | |
1092 | ].join("\n"), [ | |
1093 | "function *a() {", | |
1094 | " yield b;", | |
1095 | "}" | |
1096 | ].join("\n"), "Identifier", null), | |
1097 | invalid([ | |
1098 | "function *a() {", | |
1099 | " yield", | |
1100 | " (b);", | |
1101 | "}" | |
1102 | ].join("\n"), [ | |
1103 | "function *a() {", | |
1104 | " yield", | |
1105 | " b;", | |
1106 | "}" | |
1107 | ].join("\n"), "Identifier", null), | |
1108 | invalid([ | |
1109 | "function *a() {", | |
1110 | " yield ((", | |
1111 | " b", | |
1112 | " ));", | |
1113 | "}" | |
1114 | ].join("\n"), [ | |
1115 | "function *a() {", | |
1116 | " yield (", | |
1117 | " b", | |
1118 | " );", | |
1119 | "}" | |
1120 | ].join("\n"), "Identifier", null), | |
1121 | ||
1122 | // returnAssign option | |
1123 | { | |
1124 | code: "function a(b) { return (b || c); }", | |
1125 | output: "function a(b) { return b || c; }", | |
1126 | options: ["all", { returnAssign: false }], | |
1127 | errors: [ | |
1128 | { | |
1129 | messageId: "unexpected", | |
1130 | type: "LogicalExpression" | |
1131 | } | |
1132 | ] | |
1133 | }, | |
1134 | { | |
1135 | code: "function a(b) { return ((b = c) || (d = e)); }", | |
1136 | output: "function a(b) { return (b = c) || (d = e); }", | |
1137 | errors: [ | |
1138 | { | |
1139 | messageId: "unexpected", | |
1140 | type: "LogicalExpression" | |
1141 | } | |
1142 | ] | |
1143 | }, | |
1144 | { | |
1145 | code: "function a(b) { return (b = 1); }", | |
1146 | output: "function a(b) { return b = 1; }", | |
1147 | errors: [ | |
1148 | { | |
1149 | messageId: "unexpected", | |
1150 | type: "AssignmentExpression" | |
1151 | } | |
1152 | ] | |
1153 | }, | |
1154 | { | |
1155 | code: "function a(b) { return c ? (d = b) : (e = b); }", | |
1156 | output: "function a(b) { return c ? d = b : e = b; }", | |
1157 | errors: [ | |
1158 | { | |
1159 | messageId: "unexpected", | |
1160 | type: "AssignmentExpression" | |
1161 | }, | |
1162 | { | |
1163 | messageId: "unexpected", | |
1164 | type: "AssignmentExpression" | |
1165 | } | |
1166 | ] | |
1167 | }, | |
1168 | { | |
1169 | code: "b => (b || c);", | |
1170 | output: "b => b || c;", | |
1171 | options: ["all", { returnAssign: false }], | |
1172 | ||
1173 | errors: [ | |
1174 | { | |
1175 | messageId: "unexpected", | |
1176 | type: "LogicalExpression" | |
1177 | } | |
1178 | ] | |
1179 | }, | |
1180 | { | |
1181 | code: "b => ((b = c) || (d = e));", | |
1182 | output: "b => (b = c) || (d = e);", | |
1183 | errors: [ | |
1184 | { | |
1185 | messageId: "unexpected", | |
1186 | type: "LogicalExpression" | |
1187 | } | |
1188 | ] | |
1189 | }, | |
1190 | { | |
1191 | code: "b => (b = 1);", | |
1192 | output: "b => b = 1;", | |
1193 | errors: [ | |
1194 | { | |
1195 | messageId: "unexpected", | |
1196 | type: "AssignmentExpression" | |
1197 | } | |
1198 | ] | |
1199 | }, | |
1200 | { | |
1201 | code: "b => c ? (d = b) : (e = b);", | |
1202 | output: "b => c ? d = b : e = b;", | |
1203 | errors: [ | |
1204 | { | |
1205 | messageId: "unexpected", | |
1206 | type: "AssignmentExpression" | |
1207 | }, | |
1208 | { | |
1209 | messageId: "unexpected", | |
1210 | type: "AssignmentExpression" | |
1211 | } | |
1212 | ] | |
1213 | }, | |
1214 | { | |
1215 | code: "b => { return (b || c); }", | |
1216 | output: "b => { return b || c; }", | |
1217 | options: ["all", { returnAssign: false }], | |
1218 | errors: [ | |
1219 | { | |
1220 | messageId: "unexpected", | |
1221 | type: "LogicalExpression" | |
1222 | } | |
1223 | ] | |
1224 | }, | |
1225 | { | |
1226 | code: "b => { return ((b = c) || (d = e)) };", | |
1227 | output: "b => { return (b = c) || (d = e) };", | |
1228 | errors: [ | |
1229 | { | |
1230 | messageId: "unexpected", | |
1231 | type: "LogicalExpression" | |
1232 | } | |
1233 | ] | |
1234 | }, | |
1235 | { | |
1236 | code: "b => { return (b = 1) };", | |
1237 | output: "b => { return b = 1 };", | |
1238 | errors: [ | |
1239 | { | |
1240 | messageId: "unexpected", | |
1241 | type: "AssignmentExpression" | |
1242 | } | |
1243 | ] | |
1244 | }, | |
1245 | { | |
1246 | code: "b => { return c ? (d = b) : (e = b); }", | |
1247 | output: "b => { return c ? d = b : e = b; }", | |
1248 | errors: [ | |
1249 | { | |
1250 | messageId: "unexpected", | |
1251 | type: "AssignmentExpression" | |
1252 | }, | |
1253 | { | |
1254 | messageId: "unexpected", | |
1255 | type: "AssignmentExpression" | |
1256 | } | |
1257 | ] | |
1258 | }, | |
1259 | ||
1260 | // async/await | |
1261 | { | |
1262 | code: "async function a() { (await a) + (await b); }", | |
1263 | output: "async function a() { await a + await b; }", | |
1264 | errors: [ | |
1265 | { | |
1266 | messageId: "unexpected", | |
1267 | type: "AwaitExpression" | |
1268 | }, | |
1269 | { | |
1270 | messageId: "unexpected", | |
1271 | type: "AwaitExpression" | |
1272 | } | |
1273 | ] | |
1274 | }, | |
1275 | invalid("async function a() { await (a); }", "async function a() { await a; }", "Identifier", null), | |
1276 | invalid("async function a() { await (a()); }", "async function a() { await a(); }", "CallExpression", null), | |
1277 | invalid("async function a() { await (+a); }", "async function a() { await +a; }", "UnaryExpression", null), | |
1278 | invalid("async function a() { +(await a); }", "async function a() { +await a; }", "AwaitExpression", null), | |
1279 | invalid("async function a() { await ((a,b)); }", "async function a() { await (a,b); }", "SequenceExpression", null), | |
456be15e TL |
1280 | invalid("async function a() { a ** (await b); }", "async function a() { a ** await b; }", "AwaitExpression", null), |
1281 | ||
eb39fafa DC |
1282 | invalid("(foo) instanceof bar", "foo instanceof bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }), |
1283 | invalid("(foo) in bar", "foo in bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }), | |
1284 | invalid("(foo) + bar", "foo + bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }), | |
1285 | invalid("(foo) && bar", "foo && bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }), | |
1286 | invalid("foo instanceof (bar)", "foo instanceof bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }), | |
1287 | invalid("foo in (bar)", "foo in bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }), | |
1288 | invalid("foo + (bar)", "foo + bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }), | |
1289 | invalid("foo && (bar)", "foo && bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }), | |
1290 | ||
1291 | // ["all", { ignoreJSX: "multi-line" }] | |
1292 | invalid("const Component = (<div />);", "const Component = <div />;", "JSXElement", 1, { | |
1293 | options: ["all", { ignoreJSX: "multi-line" }] | |
1294 | }), | |
1295 | invalid([ | |
1296 | "const Component = (", | |
1297 | " <div />", | |
1298 | ");" | |
1299 | ].join("\n"), "const Component = \n <div />\n;", "JSXElement", 1, { | |
1300 | options: ["all", { ignoreJSX: "multi-line" }] | |
1301 | }), | |
1302 | invalid([ | |
1303 | "const Component = (", | |
1304 | " <></>", | |
1305 | ");" | |
1306 | ].join("\n"), "const Component = \n <></>\n;", "JSXFragment", 1, { | |
1307 | options: ["all", { ignoreJSX: "multi-line" }] | |
1308 | }), | |
1309 | ||
1310 | // ["all", { ignoreJSX: "single-line" }] | |
1311 | invalid([ | |
1312 | "const Component = (", | |
1313 | "<div>", | |
1314 | " <p />", | |
1315 | "</div>", | |
1316 | ");" | |
1317 | ].join("\n"), "const Component = \n<div>\n <p />\n</div>\n;", "JSXElement", 1, { | |
1318 | options: ["all", { ignoreJSX: "single-line" }] | |
1319 | }), | |
1320 | invalid([ | |
1321 | "const Component = (<div>", | |
1322 | " <p />", | |
1323 | "</div>);" | |
1324 | ].join("\n"), "const Component = <div>\n <p />\n</div>;", "JSXElement", 1, { | |
1325 | options: ["all", { ignoreJSX: "single-line" }] | |
1326 | }), | |
1327 | invalid([ | |
1328 | "const Component = (<div", | |
1329 | " prop={true}", | |
1330 | "/>)" | |
1331 | ].join("\n"), "const Component = <div\n prop={true}\n/>", "JSXElement", 1, { | |
1332 | options: ["all", { ignoreJSX: "single-line" }] | |
1333 | }), | |
1334 | ||
1335 | // ["all", { ignoreJSX: "none" }] default, same as unspecified | |
1336 | invalid("const Component = (<div />);", "const Component = <div />;", "JSXElement", 1, { | |
1337 | options: ["all", { ignoreJSX: "none" }] | |
1338 | }), | |
1339 | invalid([ | |
1340 | "const Component = (<div>", | |
1341 | "<p />", | |
1342 | "</div>)" | |
1343 | ].join("\n"), "const Component = <div>\n<p />\n</div>", "JSXElement", 1, { | |
1344 | options: ["all", { ignoreJSX: "none" }] | |
1345 | }), | |
1346 | ||
1347 | // ["all", { enforceForArrowConditionals: true }] | |
1348 | { | |
1349 | code: "var a = (b) => (1 ? 2 : 3)", | |
1350 | output: "var a = (b) => 1 ? 2 : 3", | |
1351 | options: ["all", { enforceForArrowConditionals: true }], | |
1352 | errors: [ | |
1353 | { | |
1354 | messageId: "unexpected" | |
1355 | } | |
1356 | ] | |
1357 | }, | |
1358 | { | |
1359 | code: "var a = (b) => ((1 ? 2 : 3))", | |
1360 | output: "var a = (b) => (1 ? 2 : 3)", | |
1361 | options: ["all", { enforceForArrowConditionals: true }], | |
1362 | errors: [ | |
1363 | { | |
1364 | messageId: "unexpected" | |
1365 | } | |
1366 | ] | |
1367 | }, | |
1368 | ||
1369 | // ["all", { enforceForSequenceExpressions: true }] | |
1370 | { | |
1371 | code: "(a, b)", | |
1372 | output: "a, b", | |
1373 | options: ["all"], | |
1374 | errors: [ | |
1375 | { | |
1376 | messageId: "unexpected", | |
1377 | type: "SequenceExpression" | |
1378 | } | |
1379 | ] | |
1380 | }, | |
1381 | { | |
1382 | code: "(a, b)", | |
1383 | output: "a, b", | |
1384 | options: ["all", {}], | |
1385 | errors: [ | |
1386 | { | |
1387 | messageId: "unexpected", | |
1388 | type: "SequenceExpression" | |
1389 | } | |
1390 | ] | |
1391 | }, | |
1392 | { | |
1393 | code: "(a, b)", | |
1394 | output: "a, b", | |
1395 | options: ["all", { enforceForSequenceExpressions: true }], | |
1396 | errors: [ | |
1397 | { | |
1398 | messageId: "unexpected", | |
1399 | type: "SequenceExpression" | |
1400 | } | |
1401 | ] | |
1402 | }, | |
1403 | { | |
1404 | code: "(foo(), bar());", | |
1405 | output: "foo(), bar();", | |
1406 | options: ["all", { enforceForSequenceExpressions: true }], | |
1407 | errors: [ | |
1408 | { | |
1409 | messageId: "unexpected", | |
1410 | type: "SequenceExpression" | |
1411 | } | |
1412 | ] | |
1413 | }, | |
1414 | { | |
1415 | code: "if((a, b)){}", | |
1416 | output: "if(a, b){}", | |
1417 | options: ["all", { enforceForSequenceExpressions: true }], | |
1418 | errors: [ | |
1419 | { | |
1420 | messageId: "unexpected", | |
1421 | type: "SequenceExpression" | |
1422 | } | |
1423 | ] | |
1424 | }, | |
1425 | { | |
1426 | code: "while ((val = foo(), val < 10));", | |
1427 | output: "while (val = foo(), val < 10);", | |
1428 | options: ["all", { enforceForSequenceExpressions: true }], | |
1429 | errors: [ | |
1430 | { | |
1431 | messageId: "unexpected", | |
1432 | type: "SequenceExpression" | |
1433 | } | |
1434 | ] | |
1435 | }, | |
1436 | ||
1437 | // ["all", { enforceForNewInMemberExpressions: true }] | |
1438 | { | |
1439 | code: "(new foo()).bar", | |
1440 | output: "new foo().bar", | |
1441 | options: ["all"], | |
1442 | errors: [ | |
1443 | { | |
1444 | messageId: "unexpected", | |
1445 | type: "NewExpression" | |
1446 | } | |
1447 | ] | |
1448 | }, | |
1449 | { | |
1450 | code: "(new foo()).bar", | |
1451 | output: "new foo().bar", | |
1452 | options: ["all", {}], | |
1453 | errors: [ | |
1454 | { | |
1455 | messageId: "unexpected", | |
1456 | type: "NewExpression" | |
1457 | } | |
1458 | ] | |
1459 | }, | |
1460 | { | |
1461 | code: "(new foo()).bar", | |
1462 | output: "new foo().bar", | |
1463 | options: ["all", { enforceForNewInMemberExpressions: true }], | |
1464 | errors: [ | |
1465 | { | |
1466 | messageId: "unexpected", | |
1467 | type: "NewExpression" | |
1468 | } | |
1469 | ] | |
1470 | }, | |
1471 | { | |
1472 | code: "(new foo())[bar]", | |
1473 | output: "new foo()[bar]", | |
1474 | options: ["all", { enforceForNewInMemberExpressions: true }], | |
1475 | errors: [ | |
1476 | { | |
1477 | messageId: "unexpected", | |
1478 | type: "NewExpression" | |
1479 | } | |
1480 | ] | |
1481 | }, | |
1482 | { | |
1483 | code: "(new foo.bar()).baz", | |
1484 | output: "new foo.bar().baz", | |
1485 | options: ["all", { enforceForNewInMemberExpressions: true }], | |
1486 | errors: [ | |
1487 | { | |
1488 | messageId: "unexpected", | |
1489 | type: "NewExpression" | |
1490 | } | |
1491 | ] | |
1492 | }, | |
1493 | ||
d3726936 TL |
1494 | // enforceForFunctionPrototypeMethods |
1495 | { | |
1496 | code: "var foo = (function(){}).call()", | |
1497 | output: "var foo = function(){}.call()", | |
1498 | options: ["all"], | |
1499 | errors: [ | |
1500 | { | |
1501 | messageId: "unexpected", | |
1502 | type: "FunctionExpression" | |
1503 | } | |
1504 | ] | |
1505 | }, | |
1506 | { | |
1507 | code: "var foo = (function(){}.apply())", | |
1508 | output: "var foo = function(){}.apply()", | |
1509 | options: ["all"], | |
1510 | errors: [ | |
1511 | { | |
1512 | messageId: "unexpected", | |
1513 | type: "CallExpression" | |
1514 | } | |
1515 | ] | |
1516 | }, | |
1517 | { | |
1518 | code: "var foo = (function(){}).apply()", | |
1519 | output: "var foo = function(){}.apply()", | |
1520 | options: ["all", {}], | |
1521 | errors: [ | |
1522 | { | |
1523 | messageId: "unexpected", | |
1524 | type: "FunctionExpression" | |
1525 | } | |
1526 | ] | |
1527 | }, | |
1528 | { | |
1529 | code: "var foo = (function(){}.call())", | |
1530 | output: "var foo = function(){}.call()", | |
1531 | options: ["all", {}], | |
1532 | errors: [ | |
1533 | { | |
1534 | messageId: "unexpected", | |
1535 | type: "CallExpression" | |
1536 | } | |
1537 | ] | |
1538 | }, | |
1539 | { | |
1540 | code: "var foo = (function(){}).call()", | |
1541 | output: "var foo = function(){}.call()", | |
1542 | options: ["all", { enforceForFunctionPrototypeMethods: true }], | |
1543 | errors: [ | |
1544 | { | |
1545 | messageId: "unexpected", | |
1546 | type: "FunctionExpression" | |
1547 | } | |
1548 | ] | |
1549 | }, | |
1550 | { | |
1551 | code: "var foo = (function(){}).apply()", | |
1552 | output: "var foo = function(){}.apply()", | |
1553 | options: ["all", { enforceForFunctionPrototypeMethods: true }], | |
1554 | errors: [ | |
1555 | { | |
1556 | messageId: "unexpected", | |
1557 | type: "FunctionExpression" | |
1558 | } | |
1559 | ] | |
1560 | }, | |
1561 | { | |
1562 | code: "var foo = (function(){}.call())", | |
1563 | output: "var foo = function(){}.call()", | |
1564 | options: ["all", { enforceForFunctionPrototypeMethods: true }], | |
1565 | errors: [ | |
1566 | { | |
1567 | messageId: "unexpected", | |
1568 | type: "CallExpression" | |
1569 | } | |
1570 | ] | |
1571 | }, | |
1572 | { | |
1573 | code: "var foo = (function(){}.apply())", | |
1574 | output: "var foo = function(){}.apply()", | |
1575 | options: ["all", { enforceForFunctionPrototypeMethods: true }], | |
1576 | errors: [ | |
1577 | { | |
1578 | messageId: "unexpected", | |
1579 | type: "CallExpression" | |
1580 | } | |
1581 | ] | |
1582 | }, | |
1583 | { | |
1584 | code: "var foo = (function(){}.call)()", // removing these parens does not cause any conflicts with wrap-iife | |
1585 | output: "var foo = function(){}.call()", | |
1586 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1587 | errors: [ | |
1588 | { | |
1589 | messageId: "unexpected", | |
1590 | type: "MemberExpression" | |
1591 | } | |
1592 | ] | |
1593 | }, | |
1594 | { | |
1595 | code: "var foo = (function(){}.apply)()", // removing these parens does not cause any conflicts with wrap-iife | |
1596 | output: "var foo = function(){}.apply()", | |
1597 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1598 | errors: [ | |
1599 | { | |
1600 | messageId: "unexpected", | |
1601 | type: "MemberExpression" | |
1602 | } | |
1603 | ] | |
1604 | }, | |
1605 | { | |
1606 | code: "var foo = (function(){}).call", | |
1607 | output: "var foo = function(){}.call", | |
1608 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1609 | errors: [ | |
1610 | { | |
1611 | messageId: "unexpected", | |
1612 | type: "FunctionExpression" | |
1613 | } | |
1614 | ] | |
1615 | }, | |
1616 | { | |
1617 | code: "var foo = (function(){}.call)", | |
1618 | output: "var foo = function(){}.call", | |
1619 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1620 | errors: [ | |
1621 | { | |
1622 | messageId: "unexpected", | |
1623 | type: "MemberExpression" | |
1624 | } | |
1625 | ] | |
1626 | }, | |
1627 | { | |
1628 | code: "var foo = new (function(){}).call()", | |
1629 | output: "var foo = new function(){}.call()", | |
1630 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1631 | errors: [ | |
1632 | { | |
1633 | messageId: "unexpected", | |
1634 | type: "FunctionExpression" | |
1635 | } | |
1636 | ] | |
1637 | }, | |
1638 | { | |
1639 | code: "var foo = (new function(){}.call())", | |
1640 | output: "var foo = new function(){}.call()", | |
1641 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1642 | errors: [ | |
1643 | { | |
1644 | messageId: "unexpected", | |
1645 | type: "NewExpression" | |
1646 | } | |
1647 | ] | |
1648 | }, | |
1649 | { | |
1650 | code: "var foo = (function(){})[call]()", | |
1651 | output: "var foo = function(){}[call]()", | |
1652 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1653 | errors: [ | |
1654 | { | |
1655 | messageId: "unexpected", | |
1656 | type: "FunctionExpression" | |
1657 | } | |
1658 | ] | |
1659 | }, | |
1660 | { | |
1661 | code: "var foo = (function(){}[apply]())", | |
1662 | output: "var foo = function(){}[apply]()", | |
1663 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1664 | errors: [ | |
1665 | { | |
1666 | messageId: "unexpected", | |
1667 | type: "CallExpression" | |
1668 | } | |
1669 | ] | |
1670 | }, | |
1671 | { | |
1672 | code: "var foo = (function(){}).bar()", | |
1673 | output: "var foo = function(){}.bar()", | |
1674 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1675 | errors: [ | |
1676 | { | |
1677 | messageId: "unexpected", | |
1678 | type: "FunctionExpression" | |
1679 | } | |
1680 | ] | |
1681 | }, | |
1682 | { | |
1683 | code: "var foo = (function(){}.bar())", | |
1684 | output: "var foo = function(){}.bar()", | |
1685 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1686 | errors: [ | |
1687 | { | |
1688 | messageId: "unexpected", | |
1689 | type: "CallExpression" | |
1690 | } | |
1691 | ] | |
1692 | }, | |
1693 | { | |
1694 | code: "var foo = (function(){}).call.call()", | |
1695 | output: "var foo = function(){}.call.call()", | |
1696 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1697 | errors: [ | |
1698 | { | |
1699 | messageId: "unexpected", | |
1700 | type: "FunctionExpression" | |
1701 | } | |
1702 | ] | |
1703 | }, | |
1704 | { | |
1705 | code: "var foo = (function(){}.call.call())", | |
1706 | output: "var foo = function(){}.call.call()", | |
1707 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1708 | errors: [ | |
1709 | { | |
1710 | messageId: "unexpected", | |
1711 | type: "CallExpression" | |
1712 | } | |
1713 | ] | |
1714 | }, | |
1715 | { | |
1716 | code: "var foo = (call())", | |
1717 | output: "var foo = call()", | |
1718 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1719 | errors: [ | |
1720 | { | |
1721 | messageId: "unexpected", | |
1722 | type: "CallExpression" | |
1723 | } | |
1724 | ] | |
1725 | }, | |
1726 | { | |
1727 | code: "var foo = (apply())", | |
1728 | output: "var foo = apply()", | |
1729 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1730 | errors: [ | |
1731 | { | |
1732 | messageId: "unexpected", | |
1733 | type: "CallExpression" | |
1734 | } | |
1735 | ] | |
1736 | }, | |
1737 | { | |
1738 | code: "var foo = (bar).call()", | |
1739 | output: "var foo = bar.call()", | |
1740 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1741 | errors: [ | |
1742 | { | |
1743 | messageId: "unexpected", | |
1744 | type: "Identifier" | |
1745 | } | |
1746 | ] | |
1747 | }, | |
1748 | { | |
1749 | code: "var foo = (bar.call())", | |
1750 | output: "var foo = bar.call()", | |
1751 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1752 | errors: [ | |
1753 | { | |
1754 | messageId: "unexpected", | |
1755 | type: "CallExpression" | |
1756 | } | |
1757 | ] | |
1758 | }, | |
1759 | { | |
1760 | code: "((() => {}).call())", | |
1761 | output: "(() => {}).call()", | |
1762 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1763 | errors: [ | |
1764 | { | |
1765 | messageId: "unexpected", | |
1766 | type: "CallExpression" | |
1767 | } | |
1768 | ] | |
1769 | }, | |
1770 | { | |
1771 | code: "var foo = function(){}.call((a.b))", | |
1772 | output: "var foo = function(){}.call(a.b)", | |
1773 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1774 | errors: [ | |
1775 | { | |
1776 | messageId: "unexpected", | |
1777 | type: "MemberExpression" | |
1778 | } | |
1779 | ] | |
1780 | }, | |
1781 | { | |
1782 | code: "var foo = function(){}.call((a).b)", | |
1783 | output: "var foo = function(){}.call(a.b)", | |
1784 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1785 | errors: [ | |
1786 | { | |
1787 | messageId: "unexpected", | |
1788 | type: "Identifier" | |
1789 | } | |
1790 | ] | |
1791 | }, | |
1792 | { | |
1793 | code: "var foo = function(){}[('call')]()", | |
1794 | output: "var foo = function(){}['call']()", | |
1795 | options: ["all", { enforceForFunctionPrototypeMethods: false }], | |
1796 | errors: [ | |
1797 | { | |
1798 | messageId: "unexpected", | |
1799 | type: "Literal" | |
1800 | } | |
1801 | ] | |
1802 | }, | |
1803 | ||
eb39fafa DC |
1804 | // https://github.com/eslint/eslint/issues/8175 |
1805 | invalid( | |
1806 | "let a = [...(b)]", | |
1807 | "let a = [...b]", | |
1808 | "Identifier", | |
1809 | 1 | |
1810 | ), | |
1811 | invalid( | |
1812 | "let a = {...(b)}", | |
1813 | "let a = {...b}", | |
1814 | "Identifier", | |
1815 | 1 | |
1816 | ), | |
1817 | invalid( | |
1818 | "let a = {...(b)}", | |
1819 | "let a = {...b}", | |
1820 | "Identifier", | |
1821 | 1, | |
1822 | { parserOptions: { ecmaVersion: 2018 } } | |
1823 | ), | |
1824 | invalid( | |
1825 | "let a = [...((b, c))]", | |
1826 | "let a = [...(b, c)]", | |
1827 | "SequenceExpression", | |
1828 | 1 | |
1829 | ), | |
1830 | invalid( | |
1831 | "let a = {...((b, c))}", | |
1832 | "let a = {...(b, c)}", | |
1833 | "SequenceExpression", | |
1834 | 1 | |
1835 | ), | |
1836 | invalid( | |
1837 | "let a = {...((b, c))}", | |
1838 | "let a = {...(b, c)}", | |
1839 | "SequenceExpression", | |
1840 | 1, | |
1841 | { parserOptions: { ecmaVersion: 2018 } } | |
1842 | ), | |
1843 | invalid( | |
1844 | "class A extends (B) {}", | |
1845 | "class A extends B {}", | |
1846 | "Identifier", | |
1847 | 1 | |
1848 | ), | |
1849 | invalid( | |
1850 | "const A = class extends (B) {}", | |
1851 | "const A = class extends B {}", | |
1852 | "Identifier", | |
1853 | 1 | |
1854 | ), | |
1855 | invalid( | |
1856 | "class A extends ((B=C)) {}", | |
1857 | "class A extends (B=C) {}", | |
1858 | "AssignmentExpression", | |
1859 | 1 | |
1860 | ), | |
1861 | invalid( | |
1862 | "const A = class extends ((B=C)) {}", | |
1863 | "const A = class extends (B=C) {}", | |
1864 | "AssignmentExpression", | |
1865 | 1 | |
1866 | ), | |
1867 | invalid( | |
1868 | "class A extends ((++foo)) {}", | |
1869 | "class A extends (++foo) {}", | |
1870 | "UpdateExpression", | |
1871 | 1 | |
1872 | ), | |
56c4a2cb DC |
1873 | invalid( |
1874 | "export default ((a, b))", | |
1875 | "export default (a, b)", | |
1876 | "SequenceExpression", | |
1877 | 1, | |
1878 | { parserOptions: { sourceType: "module" } } | |
1879 | ), | |
1880 | invalid( | |
1881 | "export default (() => {})", | |
1882 | "export default () => {}", | |
1883 | "ArrowFunctionExpression", | |
1884 | 1, | |
1885 | { parserOptions: { sourceType: "module" } } | |
1886 | ), | |
1887 | invalid( | |
1888 | "export default ((a, b) => a + b)", | |
1889 | "export default (a, b) => a + b", | |
1890 | "ArrowFunctionExpression", | |
1891 | 1, | |
1892 | { parserOptions: { sourceType: "module" } } | |
1893 | ), | |
1894 | invalid( | |
1895 | "export default (a => a)", | |
1896 | "export default a => a", | |
1897 | "ArrowFunctionExpression", | |
1898 | 1, | |
1899 | { parserOptions: { sourceType: "module" } } | |
1900 | ), | |
1901 | invalid( | |
1902 | "export default (a = b)", | |
1903 | "export default a = b", | |
1904 | "AssignmentExpression", | |
1905 | 1, | |
1906 | { parserOptions: { sourceType: "module" } } | |
1907 | ), | |
1908 | invalid( | |
1909 | "export default (a ? b : c)", | |
1910 | "export default a ? b : c", | |
1911 | "ConditionalExpression", | |
1912 | 1, | |
1913 | { parserOptions: { sourceType: "module" } } | |
1914 | ), | |
1915 | invalid( | |
1916 | "export default (a)", | |
1917 | "export default a", | |
1918 | "Identifier", | |
1919 | 1, | |
1920 | { parserOptions: { sourceType: "module" } } | |
1921 | ), | |
eb39fafa DC |
1922 | invalid( |
1923 | "for (foo of(bar));", | |
1924 | "for (foo of bar);", | |
1925 | "Identifier", | |
1926 | 1 | |
1927 | ), | |
1928 | invalid( | |
1929 | "for ((foo) of bar);", | |
1930 | "for (foo of bar);", | |
1931 | "Identifier", | |
1932 | 1 | |
1933 | ), | |
5422a9cc TL |
1934 | invalid( |
1935 | "for (foo of (baz = bar));", | |
1936 | "for (foo of baz = bar);", | |
1937 | "AssignmentExpression", | |
1938 | 1 | |
1939 | ), | |
1940 | invalid( | |
1941 | "function* f() { for (foo of (yield bar)); }", | |
1942 | "function* f() { for (foo of yield bar); }", | |
1943 | "YieldExpression", | |
1944 | 1 | |
1945 | ), | |
eb39fafa DC |
1946 | invalid( |
1947 | "for (foo of ((bar, baz)));", | |
1948 | "for (foo of (bar, baz));", | |
1949 | "SequenceExpression", | |
1950 | 1 | |
1951 | ), | |
1952 | invalid( | |
1953 | "for ((foo)in bar);", | |
1954 | "for (foo in bar);", | |
1955 | "Identifier", | |
1956 | 1 | |
1957 | ), | |
1958 | invalid( | |
1959 | "for ((foo['bar'])of baz);", | |
1960 | "for (foo['bar']of baz);", | |
1961 | "MemberExpression", | |
1962 | 1 | |
1963 | ), | |
1964 | invalid( | |
1965 | "() => (({ foo: 1 }).foo)", | |
1966 | "() => ({ foo: 1 }).foo", | |
1967 | "MemberExpression", | |
1968 | 1 | |
1969 | ), | |
1970 | invalid( | |
1971 | "(let).foo", | |
1972 | "let.foo", | |
1973 | "Identifier", | |
1974 | 1 | |
1975 | ), | |
456be15e TL |
1976 | |
1977 | // ForStatement#init expression cannot start with `let[`, but it can start with `let` if it isn't followed by `[` | |
1978 | invalid( | |
1979 | "for ((let);;);", | |
1980 | "for (let;;);", | |
1981 | "Identifier", | |
1982 | 1 | |
1983 | ), | |
1984 | invalid( | |
1985 | "for ((let = 1);;);", | |
1986 | "for (let = 1;;);", | |
1987 | "AssignmentExpression", | |
1988 | 1 | |
1989 | ), | |
1990 | invalid( | |
1991 | "for ((let) = 1;;);", | |
1992 | "for (let = 1;;);", | |
1993 | "Identifier", | |
1994 | 1 | |
1995 | ), | |
1996 | invalid( | |
1997 | "for ((let = []);;);", | |
1998 | "for (let = [];;);", | |
1999 | "AssignmentExpression", | |
2000 | 1 | |
2001 | ), | |
2002 | invalid( | |
2003 | "for ((let) = [];;);", | |
2004 | "for (let = [];;);", | |
2005 | "Identifier", | |
2006 | 1 | |
2007 | ), | |
2008 | invalid( | |
2009 | "for ((let());;);", | |
2010 | "for (let();;);", | |
2011 | "CallExpression", | |
2012 | 1 | |
2013 | ), | |
2014 | invalid( | |
2015 | "for ((let([]));;);", | |
2016 | "for (let([]);;);", | |
2017 | "CallExpression", | |
2018 | 1 | |
2019 | ), | |
2020 | invalid( | |
2021 | "for ((let())[a];;);", | |
2022 | "for (let()[a];;);", | |
2023 | "CallExpression", | |
2024 | 1 | |
2025 | ), | |
2026 | invalid( | |
2027 | "for ((let`[]`);;);", | |
2028 | "for (let`[]`;;);", | |
2029 | "TaggedTemplateExpression", | |
2030 | 1 | |
2031 | ), | |
2032 | invalid( | |
2033 | "for ((let.a);;);", | |
2034 | "for (let.a;;);", | |
2035 | "MemberExpression", | |
2036 | 1 | |
2037 | ), | |
2038 | invalid( | |
2039 | "for ((let).a;;);", | |
2040 | "for (let.a;;);", | |
2041 | "Identifier", | |
2042 | 1 | |
2043 | ), | |
2044 | invalid( | |
2045 | "for ((let).a = 1;;);", | |
2046 | "for (let.a = 1;;);", | |
2047 | "Identifier", | |
2048 | 1 | |
2049 | ), | |
2050 | invalid( | |
2051 | "for ((let).a[b];;);", | |
2052 | "for (let.a[b];;);", | |
2053 | "Identifier", | |
2054 | 1 | |
2055 | ), | |
2056 | invalid( | |
2057 | "for ((let.a)[b];;);", | |
2058 | "for (let.a[b];;);", | |
2059 | "MemberExpression", | |
2060 | 1 | |
2061 | ), | |
2062 | invalid( | |
2063 | "for ((let.a[b]);;);", | |
2064 | "for (let.a[b];;);", | |
2065 | "MemberExpression", | |
2066 | 1 | |
2067 | ), | |
2068 | invalid( | |
2069 | "for ((let);[];);", | |
2070 | "for (let;[];);", | |
2071 | "Identifier", | |
2072 | 1 | |
2073 | ), | |
2074 | invalid( | |
2075 | "for (((let[a]));;);", | |
2076 | "for ((let[a]);;);", | |
2077 | "MemberExpression", | |
2078 | 1 | |
2079 | ), | |
2080 | invalid( | |
2081 | "for (((let))[a];;);", | |
2082 | "for ((let)[a];;);", | |
2083 | "Identifier", | |
2084 | 1 | |
2085 | ), | |
2086 | invalid( | |
2087 | "for (((let[a])).b;;);", | |
2088 | "for ((let[a]).b;;);", | |
2089 | "MemberExpression", | |
2090 | 1 | |
2091 | ), | |
2092 | invalid( | |
2093 | "for (((let))[a].b;;);", | |
2094 | "for ((let)[a].b;;);", | |
2095 | "Identifier", | |
2096 | 1 | |
2097 | ), | |
2098 | invalid( | |
2099 | "for (((let)[a]).b;;);", | |
2100 | "for ((let)[a].b;;);", | |
2101 | "MemberExpression", | |
2102 | 1 | |
2103 | ), | |
2104 | invalid( | |
2105 | "for (((let[a]) = b);;);", | |
2106 | "for ((let[a]) = b;;);", | |
2107 | "AssignmentExpression", | |
2108 | 1 | |
2109 | ), | |
2110 | invalid( | |
2111 | "for (((let)[a]) = b;;);", | |
2112 | "for ((let)[a] = b;;);", | |
2113 | "MemberExpression", | |
2114 | 1 | |
2115 | ), | |
2116 | invalid( | |
2117 | "for (((let)[a] = b);;);", | |
2118 | "for ((let)[a] = b;;);", | |
2119 | "AssignmentExpression", | |
2120 | 1 | |
2121 | ), | |
2122 | invalid( | |
2123 | "for ((Let[a]);;);", | |
2124 | "for (Let[a];;);", | |
2125 | "MemberExpression", | |
2126 | 1 | |
2127 | ), | |
2128 | invalid( | |
2129 | "for ((lett)[a];;);", | |
2130 | "for (lett[a];;);", | |
2131 | "Identifier", | |
2132 | 1 | |
2133 | ), | |
2134 | ||
5422a9cc TL |
2135 | // ForInStatement#left expression cannot start with `let[`, but it can start with `let` if it isn't followed by `[` |
2136 | invalid( | |
2137 | "for ((let) in foo);", | |
2138 | "for (let in foo);", | |
2139 | "Identifier", | |
2140 | 1 | |
2141 | ), | |
2142 | invalid( | |
2143 | "for ((let())[a] in foo);", | |
2144 | "for (let()[a] in foo);", | |
2145 | "CallExpression", | |
2146 | 1 | |
2147 | ), | |
2148 | invalid( | |
2149 | "for ((let.a) in foo);", | |
2150 | "for (let.a in foo);", | |
2151 | "MemberExpression", | |
2152 | 1 | |
2153 | ), | |
2154 | invalid( | |
2155 | "for ((let).a in foo);", | |
2156 | "for (let.a in foo);", | |
2157 | "Identifier", | |
2158 | 1 | |
2159 | ), | |
2160 | invalid( | |
2161 | "for ((let).a.b in foo);", | |
2162 | "for (let.a.b in foo);", | |
2163 | "Identifier", | |
2164 | 1 | |
2165 | ), | |
2166 | invalid( | |
2167 | "for ((let).a[b] in foo);", | |
2168 | "for (let.a[b] in foo);", | |
2169 | "Identifier", | |
2170 | 1 | |
2171 | ), | |
2172 | invalid( | |
2173 | "for ((let.a)[b] in foo);", | |
2174 | "for (let.a[b] in foo);", | |
2175 | "MemberExpression", | |
2176 | 1 | |
2177 | ), | |
2178 | invalid( | |
2179 | "for ((let.a[b]) in foo);", | |
2180 | "for (let.a[b] in foo);", | |
2181 | "MemberExpression", | |
2182 | 1 | |
2183 | ), | |
2184 | invalid( | |
2185 | "for (((let[a])) in foo);", | |
2186 | "for ((let[a]) in foo);", | |
2187 | "MemberExpression", | |
2188 | 1 | |
2189 | ), | |
2190 | invalid( | |
2191 | "for (((let))[a] in foo);", | |
2192 | "for ((let)[a] in foo);", | |
2193 | "Identifier", | |
2194 | 1 | |
2195 | ), | |
2196 | invalid( | |
2197 | "for (((let[a])).b in foo);", | |
2198 | "for ((let[a]).b in foo);", | |
2199 | "MemberExpression", | |
2200 | 1 | |
2201 | ), | |
2202 | invalid( | |
2203 | "for (((let))[a].b in foo);", | |
2204 | "for ((let)[a].b in foo);", | |
2205 | "Identifier", | |
2206 | 1 | |
2207 | ), | |
2208 | invalid( | |
2209 | "for (((let)[a]).b in foo);", | |
2210 | "for ((let)[a].b in foo);", | |
2211 | "MemberExpression", | |
2212 | 1 | |
2213 | ), | |
2214 | invalid( | |
2215 | "for (((let[a]).b) in foo);", | |
2216 | "for ((let[a]).b in foo);", | |
2217 | "MemberExpression", | |
2218 | 1 | |
2219 | ), | |
2220 | invalid( | |
2221 | "for ((Let[a]) in foo);", | |
2222 | "for (Let[a] in foo);", | |
2223 | "MemberExpression", | |
2224 | 1 | |
2225 | ), | |
2226 | invalid( | |
2227 | "for ((lett)[a] in foo);", | |
2228 | "for (lett[a] in foo);", | |
2229 | "Identifier", | |
2230 | 1 | |
2231 | ), | |
2232 | ||
2233 | // ForOfStatement#left expression cannot start with `let` | |
2234 | invalid( | |
2235 | "for (((let)) of foo);", | |
2236 | "for ((let) of foo);", | |
2237 | "Identifier", | |
2238 | 1 | |
2239 | ), | |
eb39fafa | 2240 | invalid( |
5422a9cc TL |
2241 | "for (((let)).a of foo);", |
2242 | "for ((let).a of foo);", | |
2243 | "Identifier", | |
2244 | 1 | |
2245 | ), | |
2246 | invalid( | |
2247 | "for (((let))[a] of foo);", | |
2248 | "for ((let)[a] of foo);", | |
2249 | "Identifier", | |
2250 | 1 | |
2251 | ), | |
2252 | invalid( | |
2253 | "for (((let).a) of foo);", | |
2254 | "for ((let).a of foo);", | |
2255 | "MemberExpression", | |
2256 | 1 | |
2257 | ), | |
2258 | invalid( | |
2259 | "for (((let[a]).b) of foo);", | |
2260 | "for ((let[a]).b of foo);", | |
2261 | "MemberExpression", | |
2262 | 1 | |
2263 | ), | |
2264 | invalid( | |
2265 | "for (((let).a).b of foo);", | |
2266 | "for ((let).a.b of foo);", | |
2267 | "MemberExpression", | |
2268 | 1 | |
2269 | ), | |
2270 | invalid( | |
2271 | "for (((let).a.b) of foo);", | |
2272 | "for ((let).a.b of foo);", | |
eb39fafa DC |
2273 | "MemberExpression", |
2274 | 1 | |
2275 | ), | |
2276 | invalid( | |
5422a9cc TL |
2277 | "for (((let.a).b) of foo);", |
2278 | "for ((let.a).b of foo);", | |
2279 | "MemberExpression", | |
2280 | 1 | |
2281 | ), | |
2282 | invalid( | |
2283 | "for (((let()).a) of foo);", | |
2284 | "for ((let()).a of foo);", | |
2285 | "MemberExpression", | |
2286 | 1 | |
2287 | ), | |
2288 | invalid( | |
2289 | "for ((Let) of foo);", | |
2290 | "for (Let of foo);", | |
2291 | "Identifier", | |
2292 | 1 | |
2293 | ), | |
2294 | invalid( | |
2295 | "for ((lett) of foo);", | |
2296 | "for (lett of foo);", | |
eb39fafa DC |
2297 | "Identifier", |
2298 | 1 | |
2299 | ), | |
5422a9cc | 2300 | |
eb39fafa DC |
2301 | invalid("for (a in (b, c));", "for (a in b, c);", "SequenceExpression", null), |
2302 | invalid( | |
2303 | "(let)", | |
2304 | "let", | |
2305 | "Identifier", | |
2306 | 1 | |
2307 | ), | |
2308 | invalid( | |
2309 | "((let))", | |
2310 | "(let)", | |
2311 | "Identifier", | |
2312 | 1 | |
2313 | ), | |
2314 | invalid("let s = `${(v)}`", "let s = `${v}`", "Identifier"), | |
2315 | invalid("let s = `${(a, b)}`", "let s = `${a, b}`", "SequenceExpression"), | |
2316 | invalid("function foo(a = (b)) {}", "function foo(a = b) {}", "Identifier"), | |
2317 | invalid("const bar = (a = (b)) => a", "const bar = (a = b) => a", "Identifier"), | |
2318 | invalid("const [a = (b)] = []", "const [a = b] = []", "Identifier"), | |
2319 | invalid("const {a = (b)} = {}", "const {a = b} = {}", "Identifier"), | |
2320 | ||
2321 | // LHS of assignments/Assignment targets | |
2322 | invalid("(a) = b", "a = b", "Identifier"), | |
2323 | invalid("(a.b) = c", "a.b = c", "MemberExpression"), | |
2324 | invalid("(a) += b", "a += b", "Identifier"), | |
2325 | invalid("(a.b) >>= c", "a.b >>= c", "MemberExpression"), | |
2326 | invalid("[(a) = b] = []", "[a = b] = []", "Identifier"), | |
2327 | invalid("[(a.b) = c] = []", "[a.b = c] = []", "MemberExpression"), | |
2328 | invalid("({ a: (b) = c } = {})", "({ a: b = c } = {})", "Identifier"), | |
2329 | invalid("({ a: (b.c) = d } = {})", "({ a: b.c = d } = {})", "MemberExpression"), | |
2330 | invalid("[(a)] = []", "[a] = []", "Identifier"), | |
2331 | invalid("[(a.b)] = []", "[a.b] = []", "MemberExpression"), | |
2332 | invalid("[,(a),,] = []", "[,a,,] = []", "Identifier"), | |
2333 | invalid("[...(a)] = []", "[...a] = []", "Identifier"), | |
2334 | invalid("[...(a.b)] = []", "[...a.b] = []", "MemberExpression"), | |
2335 | invalid("({ a: (b) } = {})", "({ a: b } = {})", "Identifier"), | |
2336 | invalid("({ a: (b.c) } = {})", "({ a: b.c } = {})", "MemberExpression"), | |
8f9d1d4d DC |
2337 | invalid("({ ...(a) } = {})", "({ ...a } = {})", "Identifier"), |
2338 | invalid("({ ...(a.b) } = {})", "({ ...a.b } = {})", "MemberExpression"), | |
eb39fafa DC |
2339 | |
2340 | // https://github.com/eslint/eslint/issues/11706 (also in valid[]) | |
2341 | { | |
2342 | code: "for ((a = (b in c)); ;);", | |
2343 | output: "for ((a = b in c); ;);", | |
2344 | errors: [ | |
2345 | { | |
2346 | messageId: "unexpected" | |
2347 | } | |
2348 | ] | |
2349 | }, | |
2350 | { | |
2351 | code: "for (let a = ((b in c) && (d in e)); ;);", | |
2352 | output: "for (let a = (b in c && d in e); ;);", | |
2353 | errors: Array(2).fill( | |
2354 | { | |
2355 | messageId: "unexpected" | |
2356 | } | |
2357 | ) | |
2358 | }, | |
2359 | { | |
2360 | code: "for (let a = ((b in c) in d); ;);", | |
2361 | output: "for (let a = (b in c in d); ;);", | |
2362 | errors: [ | |
2363 | { | |
2364 | messageId: "unexpected" | |
2365 | } | |
2366 | ] | |
2367 | }, | |
2368 | { | |
2369 | code: "for (let a = (b && (c in d)), e = (f in g); ;);", | |
2370 | output: "for (let a = (b && c in d), e = (f in g); ;);", | |
2371 | errors: [ | |
2372 | { | |
2373 | messageId: "unexpected" | |
2374 | } | |
2375 | ] | |
2376 | }, | |
2377 | { | |
2378 | code: "for (let a = (b + c), d = (e in f); ;);", | |
2379 | output: "for (let a = b + c, d = (e in f); ;);", | |
2380 | errors: [ | |
2381 | { | |
2382 | messageId: "unexpected" | |
2383 | } | |
2384 | ] | |
2385 | }, | |
2386 | { | |
2387 | code: "for (let a = [(b in c)]; ;);", | |
2388 | output: "for (let a = [b in c]; ;);", | |
2389 | errors: [ | |
2390 | { | |
2391 | messageId: "unexpected" | |
2392 | } | |
2393 | ] | |
2394 | }, | |
2395 | { | |
2396 | code: "for (let a = [b, (c in d)]; ;);", | |
2397 | output: "for (let a = [b, c in d]; ;);", | |
2398 | errors: [ | |
2399 | { | |
2400 | messageId: "unexpected" | |
2401 | } | |
2402 | ] | |
2403 | }, | |
2404 | { | |
2405 | code: "for (let a = ([b in c]); ;);", | |
2406 | output: "for (let a = [b in c]; ;);", | |
2407 | errors: [ | |
2408 | { | |
2409 | messageId: "unexpected" | |
2410 | } | |
2411 | ] | |
2412 | }, | |
2413 | { | |
2414 | code: "for (let a = ([b, c in d]); ;);", | |
2415 | output: "for (let a = [b, c in d]; ;);", | |
2416 | errors: [ | |
2417 | { | |
2418 | messageId: "unexpected" | |
2419 | } | |
2420 | ] | |
2421 | }, | |
2422 | { | |
2423 | code: "for ((a = [b in c]); ;);", | |
2424 | output: "for (a = [b in c]; ;);", | |
2425 | errors: [ | |
2426 | { | |
2427 | messageId: "unexpected" | |
2428 | } | |
2429 | ] | |
2430 | }, | |
2431 | { | |
2432 | code: "for (let a = [b && (c in d)]; ;);", | |
2433 | output: "for (let a = [b && c in d]; ;);", | |
2434 | errors: [ | |
2435 | { | |
2436 | messageId: "unexpected" | |
2437 | } | |
2438 | ] | |
2439 | }, | |
2440 | { | |
2441 | code: "for (let a = [(b && c in d)]; ;);", | |
2442 | output: "for (let a = [b && c in d]; ;);", | |
2443 | errors: [ | |
2444 | { | |
2445 | messageId: "unexpected" | |
2446 | } | |
2447 | ] | |
2448 | }, | |
2449 | { | |
2450 | code: "for (let a = ([b && c in d]); ;);", | |
2451 | output: "for (let a = [b && c in d]; ;);", | |
2452 | errors: [ | |
2453 | { | |
2454 | messageId: "unexpected" | |
2455 | } | |
2456 | ] | |
2457 | }, | |
2458 | { | |
2459 | code: "for ((a = [b && c in d]); ;);", | |
2460 | output: "for (a = [b && c in d]; ;);", | |
2461 | errors: [ | |
2462 | { | |
2463 | messageId: "unexpected" | |
2464 | } | |
2465 | ] | |
2466 | }, | |
2467 | { | |
2468 | code: "for ([(a in b)]; ;);", | |
2469 | output: "for ([a in b]; ;);", | |
2470 | errors: [ | |
2471 | { | |
2472 | messageId: "unexpected" | |
2473 | } | |
2474 | ] | |
2475 | }, | |
2476 | { | |
2477 | code: "for (([a in b]); ;);", | |
2478 | output: "for ([a in b]; ;);", | |
2479 | errors: [ | |
2480 | { | |
2481 | messageId: "unexpected" | |
2482 | } | |
2483 | ] | |
2484 | }, | |
2485 | { | |
2486 | code: "for (let a = [(b in c)], d = (e in f); ;);", | |
2487 | output: "for (let a = [b in c], d = (e in f); ;);", | |
2488 | errors: [ | |
2489 | { | |
2490 | messageId: "unexpected" | |
2491 | } | |
2492 | ] | |
2493 | }, | |
2494 | { | |
2495 | code: "for (let [a = (b in c)] = []; ;);", | |
2496 | output: "for (let [a = b in c] = []; ;);", | |
2497 | errors: [ | |
2498 | { | |
2499 | messageId: "unexpected" | |
2500 | } | |
2501 | ] | |
2502 | }, | |
2503 | { | |
2504 | code: "for (let [a = b && (c in d)] = []; ;);", | |
2505 | output: "for (let [a = b && c in d] = []; ;);", | |
2506 | errors: [ | |
2507 | { | |
2508 | messageId: "unexpected" | |
2509 | } | |
2510 | ] | |
2511 | }, | |
2512 | { | |
2513 | code: "for (let a = () => { (b in c) }; ;);", | |
2514 | output: "for (let a = () => { b in c }; ;);", | |
2515 | errors: [ | |
2516 | { | |
2517 | messageId: "unexpected" | |
2518 | } | |
2519 | ] | |
2520 | }, | |
2521 | { | |
2522 | code: "for (let a = () => { a && (b in c) }; ;);", | |
2523 | output: "for (let a = () => { a && b in c }; ;);", | |
2524 | errors: [ | |
2525 | { | |
2526 | messageId: "unexpected" | |
2527 | } | |
2528 | ] | |
2529 | }, | |
2530 | { | |
2531 | code: "for (let a = function () { (b in c) }; ;);", | |
2532 | output: "for (let a = function () { b in c }; ;);", | |
2533 | errors: [ | |
2534 | { | |
2535 | messageId: "unexpected" | |
2536 | } | |
2537 | ] | |
2538 | }, | |
2539 | { | |
2540 | code: "for (let a = { a: (b in c) }; ;);", | |
2541 | output: "for (let a = { a: b in c }; ;);", | |
2542 | errors: [ | |
2543 | { | |
2544 | messageId: "unexpected" | |
2545 | } | |
2546 | ] | |
2547 | }, | |
2548 | { | |
2549 | code: "for (let a = { a: b && (c in d) }; ;);", | |
2550 | output: "for (let a = { a: b && c in d }; ;);", | |
2551 | errors: [ | |
2552 | { | |
2553 | messageId: "unexpected" | |
2554 | } | |
2555 | ] | |
2556 | }, | |
2557 | { | |
2558 | code: "for (let { a = (b in c) } = {}; ;);", | |
2559 | output: "for (let { a = b in c } = {}; ;);", | |
2560 | errors: [ | |
2561 | { | |
2562 | messageId: "unexpected" | |
2563 | } | |
2564 | ] | |
2565 | }, | |
2566 | { | |
2567 | code: "for (let { a = b && (c in d) } = {}; ;);", | |
2568 | output: "for (let { a = b && c in d } = {}; ;);", | |
2569 | errors: [ | |
2570 | { | |
2571 | messageId: "unexpected" | |
2572 | } | |
2573 | ] | |
2574 | }, | |
2575 | { | |
2576 | code: "for (let { a: { b = c && (d in e) } } = {}; ;);", | |
2577 | output: "for (let { a: { b = c && d in e } } = {}; ;);", | |
2578 | errors: [ | |
2579 | { | |
2580 | messageId: "unexpected" | |
2581 | } | |
2582 | ] | |
2583 | }, | |
2584 | { | |
2585 | code: "for (let a = `${(a in b)}`; ;);", | |
2586 | output: "for (let a = `${a in b}`; ;);", | |
2587 | errors: [ | |
2588 | { | |
2589 | messageId: "unexpected" | |
2590 | } | |
2591 | ] | |
2592 | }, | |
2593 | { | |
2594 | code: "for (let a = `${a && (b in c)}`; ;);", | |
2595 | output: "for (let a = `${a && b in c}`; ;);", | |
2596 | errors: [ | |
2597 | { | |
2598 | messageId: "unexpected" | |
2599 | } | |
2600 | ] | |
2601 | }, | |
2602 | { | |
2603 | code: "for (let a = (b = (c in d)) => {}; ;);", | |
2604 | output: "for (let a = (b = c in d) => {}; ;);", | |
2605 | errors: [ | |
2606 | { | |
2607 | messageId: "unexpected" | |
2608 | } | |
2609 | ] | |
2610 | }, | |
2611 | { | |
2612 | code: "for (let a = (b = c && (d in e)) => {}; ;);", | |
2613 | output: "for (let a = (b = c && d in e) => {}; ;);", | |
2614 | errors: [ | |
2615 | { | |
2616 | messageId: "unexpected" | |
2617 | } | |
2618 | ] | |
2619 | }, | |
2620 | { | |
2621 | code: "for (let a = (b, c = d && (e in f)) => {}; ;);", | |
2622 | output: "for (let a = (b, c = d && e in f) => {}; ;);", | |
2623 | errors: [ | |
2624 | { | |
2625 | messageId: "unexpected" | |
2626 | } | |
2627 | ] | |
2628 | }, | |
2629 | { | |
2630 | code: "for (let a = function (b = c && (d in e)) {}; ;);", | |
2631 | output: "for (let a = function (b = c && d in e) {}; ;);", | |
2632 | errors: [ | |
2633 | { | |
2634 | messageId: "unexpected" | |
2635 | } | |
2636 | ] | |
2637 | }, | |
2638 | { | |
2639 | code: "for (let a = function (b, c = d && (e in f)) {}; ;);", | |
2640 | output: "for (let a = function (b, c = d && e in f) {}; ;);", | |
2641 | errors: [ | |
2642 | { | |
2643 | messageId: "unexpected" | |
2644 | } | |
2645 | ] | |
2646 | }, | |
2647 | { | |
2648 | code: "for (let a = b((c in d)); ;);", | |
2649 | output: "for (let a = b(c in d); ;);", | |
2650 | errors: [ | |
2651 | { | |
2652 | messageId: "unexpected" | |
2653 | } | |
2654 | ] | |
2655 | }, | |
2656 | { | |
2657 | code: "for (let a = b(c, (d in e)); ;);", | |
2658 | output: "for (let a = b(c, d in e); ;);", | |
2659 | errors: [ | |
2660 | { | |
2661 | messageId: "unexpected" | |
2662 | } | |
2663 | ] | |
2664 | }, | |
2665 | { | |
2666 | code: "for (let a = b(c && (d in e)); ;);", | |
2667 | output: "for (let a = b(c && d in e); ;);", | |
2668 | errors: [ | |
2669 | { | |
2670 | messageId: "unexpected" | |
2671 | } | |
2672 | ] | |
2673 | }, | |
2674 | { | |
2675 | code: "for (let a = b(c, d && (e in f)); ;);", | |
2676 | output: "for (let a = b(c, d && e in f); ;);", | |
2677 | errors: [ | |
2678 | { | |
2679 | messageId: "unexpected" | |
2680 | } | |
2681 | ] | |
2682 | }, | |
2683 | { | |
2684 | code: "for (let a = new b((c in d)); ;);", | |
2685 | output: "for (let a = new b(c in d); ;);", | |
2686 | errors: [ | |
2687 | { | |
2688 | messageId: "unexpected" | |
2689 | } | |
2690 | ] | |
2691 | }, | |
2692 | { | |
2693 | code: "for (let a = new b(c, (d in e)); ;);", | |
2694 | output: "for (let a = new b(c, d in e); ;);", | |
2695 | errors: [ | |
2696 | { | |
2697 | messageId: "unexpected" | |
2698 | } | |
2699 | ] | |
2700 | }, | |
2701 | { | |
2702 | code: "for (let a = new b(c && (d in e)); ;);", | |
2703 | output: "for (let a = new b(c && d in e); ;);", | |
2704 | errors: [ | |
2705 | { | |
2706 | messageId: "unexpected" | |
2707 | } | |
2708 | ] | |
2709 | }, | |
2710 | { | |
2711 | code: "for (let a = new b(c, d && (e in f)); ;);", | |
2712 | output: "for (let a = new b(c, d && e in f); ;);", | |
2713 | errors: [ | |
2714 | { | |
2715 | messageId: "unexpected" | |
2716 | } | |
2717 | ] | |
2718 | }, | |
2719 | { | |
2720 | code: "for (let a = b[(c in d)]; ;);", | |
2721 | output: "for (let a = b[c in d]; ;);", | |
2722 | errors: [ | |
2723 | { | |
2724 | messageId: "unexpected" | |
2725 | } | |
2726 | ] | |
2727 | }, | |
2728 | { | |
2729 | code: "for (let a = b[c && (d in e)]; ;);", | |
2730 | output: "for (let a = b[c && d in e]; ;);", | |
2731 | errors: [ | |
2732 | { | |
2733 | messageId: "unexpected" | |
2734 | } | |
2735 | ] | |
2736 | }, | |
2737 | { | |
2738 | code: "for (let a = b ? (c in d) : e; ;);", | |
2739 | output: "for (let a = b ? c in d : e; ;);", | |
2740 | errors: [ | |
2741 | { | |
2742 | messageId: "unexpected" | |
2743 | } | |
2744 | ] | |
2745 | }, | |
2746 | { | |
2747 | code: "for (let a = b ? c && (d in e) : f; ;);", | |
2748 | output: "for (let a = b ? c && d in e : f; ;);", | |
2749 | errors: [ | |
2750 | { | |
2751 | messageId: "unexpected" | |
2752 | } | |
2753 | ] | |
2754 | }, | |
2755 | { | |
2756 | code: "for (a ? b && (c in d) : e; ;);", | |
2757 | output: "for (a ? b && c in d : e; ;);", | |
2758 | errors: [ | |
2759 | { | |
2760 | messageId: "unexpected" | |
2761 | } | |
2762 | ] | |
2763 | }, | |
2764 | { | |
2765 | code: "for (let a = ((b in c)); ;);", | |
2766 | output: "for (let a = (b in c); ;);", | |
2767 | errors: [ | |
2768 | { | |
2769 | messageId: "unexpected" | |
2770 | } | |
2771 | ] | |
2772 | }, | |
2773 | { | |
2774 | code: "for (((a in b)); ;);", | |
2775 | output: "for ((a in b); ;);", | |
2776 | errors: [ | |
2777 | { | |
2778 | messageId: "unexpected" | |
2779 | } | |
2780 | ] | |
2781 | }, | |
2782 | { | |
2783 | code: "for (((a && b in c && d)); ;);", | |
2784 | output: "for ((a && b in c && d); ;);", | |
2785 | errors: [ | |
2786 | { | |
2787 | messageId: "unexpected" | |
2788 | } | |
2789 | ] | |
2790 | }, | |
2791 | { | |
2792 | code: "for (let a = (!(b in c)); ;);", | |
2793 | output: "for (let a = !(b in c); ;);", | |
2794 | errors: [ | |
2795 | { | |
2796 | messageId: "unexpected" | |
2797 | } | |
2798 | ] | |
2799 | }, | |
2800 | { | |
2801 | code: "for (let a = (!(b && c in d)); ;);", | |
2802 | output: "for (let a = !(b && c in d); ;);", | |
2803 | errors: [ | |
2804 | { | |
2805 | messageId: "unexpected" | |
2806 | } | |
2807 | ] | |
2808 | }, | |
2809 | { | |
2810 | code: "for (let a = !((b in c) && (d in e)); ;);", | |
2811 | output: "for (let a = !(b in c && d in e); ;);", | |
2812 | errors: Array(2).fill( | |
2813 | { | |
2814 | messageId: "unexpected" | |
2815 | } | |
2816 | ) | |
2817 | }, | |
2818 | { | |
2819 | code: "for (let a = (x && (b in c)), d = () => { for ((e in f); ;); for ((g in h); ;); }; ;); for((i in j); ;);", | |
2820 | output: "for (let a = (x && b in c), d = () => { for ((e in f); ;); for ((g in h); ;); }; ;); for((i in j); ;);", | |
2821 | errors: [ | |
2822 | { | |
2823 | messageId: "unexpected" | |
2824 | } | |
2825 | ] | |
2826 | }, | |
2827 | { | |
2828 | code: "for (let a = (b in c), d = () => { for ((x && (e in f)); ;); for ((g in h); ;); }; ;); for((i in j); ;);", | |
2829 | output: "for (let a = (b in c), d = () => { for ((x && e in f); ;); for ((g in h); ;); }; ;); for((i in j); ;);", | |
2830 | errors: [ | |
2831 | { | |
2832 | messageId: "unexpected" | |
2833 | } | |
2834 | ] | |
2835 | }, | |
2836 | { | |
2837 | code: "for (let a = (b in c), d = () => { for ((e in f); ;); for ((x && (g in h)); ;); }; ;); for((i in j); ;);", | |
2838 | output: "for (let a = (b in c), d = () => { for ((e in f); ;); for ((x && g in h); ;); }; ;); for((i in j); ;);", | |
2839 | errors: [ | |
2840 | { | |
2841 | messageId: "unexpected" | |
2842 | } | |
2843 | ] | |
2844 | }, | |
2845 | { | |
2846 | code: "for (let a = (b in c), d = () => { for ((e in f); ;); for ((g in h); ;); }; ;); for((x && (i in j)); ;);", | |
2847 | output: "for (let a = (b in c), d = () => { for ((e in f); ;); for ((g in h); ;); }; ;); for((x && i in j); ;);", | |
2848 | errors: [ | |
2849 | { | |
2850 | messageId: "unexpected" | |
2851 | } | |
2852 | ] | |
2853 | }, | |
2854 | { | |
2855 | code: "for (let a = (x && (b in c)), d = () => { for ((e in f); ;); for ((y && (g in h)); ;); }; ;); for((i in j); ;);", | |
2856 | output: "for (let a = (x && b in c), d = () => { for ((e in f); ;); for ((y && g in h); ;); }; ;); for((i in j); ;);", | |
2857 | errors: Array(2).fill( | |
2858 | { | |
2859 | messageId: "unexpected" | |
2860 | } | |
2861 | ) | |
2862 | }, | |
2863 | { | |
2864 | code: "for (let a = (x && (b in c)), d = () => { for ((y && (e in f)); ;); for ((z && (g in h)); ;); }; ;); for((w && (i in j)); ;);", | |
2865 | output: "for (let a = (x && b in c), d = () => { for ((y && e in f); ;); for ((z && g in h); ;); }; ;); for((w && i in j); ;);", | |
2866 | errors: Array(4).fill( | |
2867 | { | |
2868 | messageId: "unexpected" | |
2869 | } | |
2870 | ) | |
2871 | }, | |
2872 | ||
2873 | // https://github.com/eslint/eslint/issues/11706 regression tests (also in valid[]) | |
2874 | { | |
2875 | code: "for (let a = (b); a > (b); a = (b)) a = (b); a = (b);", | |
2876 | output: "for (let a = b; a > b; a = b) a = b; a = b;", | |
2877 | errors: Array(5).fill( | |
2878 | { | |
2879 | messageId: "unexpected" | |
2880 | } | |
2881 | ) | |
2882 | }, | |
2883 | { | |
2884 | code: "for ((a = b); (a > b); (a = b)) (a = b); (a = b);", | |
2885 | output: "for (a = b; a > b; a = b) a = b; a = b;", | |
2886 | errors: Array(5).fill( | |
2887 | { | |
2888 | messageId: "unexpected" | |
2889 | } | |
2890 | ) | |
2891 | }, | |
2892 | { | |
2893 | code: "for (let a = b; a > (b); a = (b)) a = (b); a = (b);", | |
2894 | output: "for (let a = b; a > b; a = b) a = b; a = b;", | |
2895 | errors: Array(4).fill( | |
2896 | { | |
2897 | messageId: "unexpected" | |
2898 | } | |
2899 | ) | |
2900 | }, | |
2901 | { | |
2902 | code: "for (let a = b; (a > b); (a = b)) (a = b); (a = b);", | |
2903 | output: "for (let a = b; a > b; a = b) a = b; a = b;", | |
2904 | errors: Array(4).fill( | |
2905 | { | |
2906 | messageId: "unexpected" | |
2907 | } | |
2908 | ) | |
2909 | }, | |
2910 | { | |
2911 | code: "for (; a > (b); a = (b)) a = (b); a = (b);", | |
2912 | output: "for (; a > b; a = b) a = b; a = b;", | |
2913 | errors: Array(4).fill( | |
2914 | { | |
2915 | messageId: "unexpected" | |
2916 | } | |
2917 | ) | |
2918 | }, | |
2919 | { | |
2920 | code: "for (; (a > b); (a = b)) (a = b); (a = b);", | |
2921 | output: "for (; a > b; a = b) a = b; a = b;", | |
2922 | errors: Array(4).fill( | |
2923 | { | |
2924 | messageId: "unexpected" | |
2925 | } | |
2926 | ) | |
2927 | }, | |
2928 | { | |
2929 | code: "for (let a = (b); a = (b in c); a = (b in c)) a = (b in c); a = (b in c);", | |
2930 | output: "for (let a = b; a = b in c; a = b in c) a = b in c; a = b in c;", | |
2931 | errors: Array(5).fill( | |
2932 | { | |
2933 | messageId: "unexpected" | |
2934 | } | |
2935 | ) | |
2936 | }, | |
2937 | { | |
2938 | code: "for (let a = (b); (a in b); (a in b)) (a in b); (a in b);", | |
2939 | output: "for (let a = b; a in b; a in b) a in b; a in b;", | |
2940 | errors: Array(5).fill( | |
2941 | { | |
2942 | messageId: "unexpected" | |
2943 | } | |
2944 | ) | |
2945 | }, | |
2946 | { | |
2947 | code: "for (let a = b; a = (b in c); a = (b in c)) a = (b in c); a = (b in c);", | |
2948 | output: "for (let a = b; a = b in c; a = b in c) a = b in c; a = b in c;", | |
2949 | errors: Array(4).fill( | |
2950 | { | |
2951 | messageId: "unexpected" | |
2952 | } | |
2953 | ) | |
2954 | }, | |
2955 | { | |
2956 | code: "for (let a = b; (a in b); (a in b)) (a in b); (a in b);", | |
2957 | output: "for (let a = b; a in b; a in b) a in b; a in b;", | |
2958 | errors: Array(4).fill( | |
2959 | { | |
2960 | messageId: "unexpected" | |
2961 | } | |
2962 | ) | |
2963 | }, | |
2964 | { | |
2965 | code: "for (; a = (b in c); a = (b in c)) a = (b in c); a = (b in c);", | |
2966 | output: "for (; a = b in c; a = b in c) a = b in c; a = b in c;", | |
2967 | errors: Array(4).fill( | |
2968 | { | |
2969 | messageId: "unexpected" | |
2970 | } | |
2971 | ) | |
2972 | }, | |
2973 | { | |
2974 | code: "for (; (a in b); (a in b)) (a in b); (a in b);", | |
2975 | output: "for (; a in b; a in b) a in b; a in b;", | |
2976 | errors: Array(4).fill( | |
2977 | { | |
2978 | messageId: "unexpected" | |
2979 | } | |
2980 | ) | |
2981 | }, | |
2982 | { | |
2983 | code: "for (let a = (b + c), d = () => { for ((e + f); ;); for ((g + h); ;); }; ;); for((i + j); ;);", | |
2984 | output: "for (let a = b + c, d = () => { for (e + f; ;); for (g + h; ;); }; ;); for(i + j; ;);", | |
2985 | errors: Array(4).fill( | |
2986 | { | |
2987 | messageId: "unexpected" | |
2988 | } | |
2989 | ) | |
2990 | }, | |
2991 | ||
2992 | // import expressions | |
2993 | invalid( | |
2994 | "import((source))", | |
2995 | "import(source)", | |
2996 | "Identifier", | |
2997 | 1, | |
2998 | { parserOptions: { ecmaVersion: 2020 } } | |
2999 | ), | |
3000 | invalid( | |
3001 | "import((source = 'foo.js'))", | |
3002 | "import(source = 'foo.js')", | |
3003 | "AssignmentExpression", | |
3004 | 1, | |
3005 | { parserOptions: { ecmaVersion: 2020 } } | |
3006 | ), | |
3007 | invalid( | |
3008 | "import(((s,t)))", | |
3009 | "import((s,t))", | |
3010 | "SequenceExpression", | |
3011 | 1, | |
3012 | { parserOptions: { ecmaVersion: 2020 } } | |
3013 | ), | |
3014 | ||
3015 | // https://github.com/eslint/eslint/issues/12127 | |
3016 | { | |
3017 | code: "[1, ((2, 3))];", | |
3018 | output: "[1, (2, 3)];", | |
3019 | errors: [{ messageId: "unexpected" }] | |
3020 | }, | |
3021 | { | |
3022 | code: "const foo = () => ((bar, baz));", | |
3023 | output: "const foo = () => (bar, baz);", | |
3024 | errors: [{ messageId: "unexpected" }] | |
3025 | }, | |
3026 | { | |
3027 | code: "foo = ((bar, baz));", | |
3028 | output: "foo = (bar, baz);", | |
3029 | errors: [{ messageId: "unexpected" }] | |
3030 | }, | |
3031 | { | |
3032 | code: "foo + ((bar + baz));", | |
3033 | output: "foo + (bar + baz);", | |
3034 | errors: [{ messageId: "unexpected" }] | |
3035 | }, | |
3036 | { | |
3037 | code: "((foo + bar)) + baz;", | |
3038 | output: "(foo + bar) + baz;", | |
3039 | errors: [{ messageId: "unexpected" }] | |
3040 | }, | |
3041 | { | |
3042 | code: "foo * ((bar + baz));", | |
3043 | output: "foo * (bar + baz);", | |
3044 | errors: [{ messageId: "unexpected" }] | |
3045 | }, | |
3046 | { | |
3047 | code: "((foo + bar)) * baz;", | |
3048 | output: "(foo + bar) * baz;", | |
3049 | errors: [{ messageId: "unexpected" }] | |
3050 | }, | |
3051 | { | |
3052 | code: "new A(((foo, bar)))", | |
3053 | output: "new A((foo, bar))", | |
3054 | errors: [{ messageId: "unexpected" }] | |
3055 | }, | |
3056 | { | |
3057 | code: "class A{ [((foo, bar))]() {} }", | |
3058 | output: "class A{ [(foo, bar)]() {} }", | |
3059 | errors: [{ messageId: "unexpected" }] | |
3060 | }, | |
3061 | { | |
3062 | code: "new ((A, B))()", | |
3063 | output: "new (A, B)()", | |
3064 | errors: [{ messageId: "unexpected" }] | |
3065 | }, | |
3066 | { | |
3067 | code: "((foo, bar)) ? bar : baz;", | |
3068 | output: "(foo, bar) ? bar : baz;", | |
3069 | errors: [{ messageId: "unexpected" }] | |
3070 | }, | |
3071 | { | |
3072 | code: "((f ? o : o)) ? bar : baz;", | |
3073 | output: "(f ? o : o) ? bar : baz;", | |
3074 | errors: [{ messageId: "unexpected" }] | |
3075 | }, | |
3076 | { | |
3077 | code: "((f = oo)) ? bar : baz;", | |
3078 | output: "(f = oo) ? bar : baz;", | |
3079 | errors: [{ messageId: "unexpected" }] | |
3080 | }, | |
3081 | { | |
3082 | code: "foo ? ((bar, baz)) : baz;", | |
3083 | output: "foo ? (bar, baz) : baz;", | |
3084 | errors: [{ messageId: "unexpected" }] | |
3085 | }, | |
3086 | { | |
3087 | code: "foo ? bar : ((bar, baz));", | |
3088 | output: "foo ? bar : (bar, baz);", | |
3089 | errors: [{ messageId: "unexpected" }] | |
3090 | }, | |
3091 | { | |
3092 | code: "function foo(bar = ((baz1, baz2))) {}", | |
3093 | output: "function foo(bar = (baz1, baz2)) {}", | |
3094 | errors: [{ messageId: "unexpected" }] | |
3095 | }, | |
3096 | { | |
3097 | code: "var foo = { bar: ((baz1, baz2)) };", | |
3098 | output: "var foo = { bar: (baz1, baz2) };", | |
3099 | errors: [{ messageId: "unexpected" }] | |
3100 | }, | |
3101 | { | |
3102 | code: "var foo = { [((bar1, bar2))]: baz };", | |
3103 | output: "var foo = { [(bar1, bar2)]: baz };", | |
3104 | errors: [{ messageId: "unexpected" }] | |
3105 | }, | |
3106 | ||
3107 | // adjacent tokens tests for division operator, comments and regular expressions | |
3108 | invalid("a+/**/(/**/b)", "a+/**//**/b", "Identifier"), | |
3109 | invalid("a+/**/(//\nb)", "a+/**///\nb", "Identifier"), | |
3110 | invalid("a in(/**/b)", "a in/**/b", "Identifier"), | |
3111 | invalid("a in(//\nb)", "a in//\nb", "Identifier"), | |
3112 | invalid("a+(/**/b)", "a+/**/b", "Identifier"), | |
3113 | invalid("a+/**/(b)", "a+/**/b", "Identifier"), | |
3114 | invalid("a+(//\nb)", "a+//\nb", "Identifier"), | |
3115 | invalid("a+//\n(b)", "a+//\nb", "Identifier"), | |
3116 | invalid("a+(/^b$/)", "a+/^b$/", "Literal"), | |
3117 | invalid("a/(/**/b)", "a/ /**/b", "Identifier"), | |
3118 | invalid("a/(//\nb)", "a/ //\nb", "Identifier"), | |
d3726936 TL |
3119 | invalid("a/(/^b$/)", "a/ /^b$/", "Literal"), |
3120 | ||
3121 | ||
3122 | // Nullish coalescing | |
3123 | { | |
3124 | code: "var v = ((a ?? b)) || c", | |
3125 | output: "var v = (a ?? b) || c", | |
3126 | parserOptions: { ecmaVersion: 2020 }, | |
3127 | errors: [{ messageId: "unexpected" }] | |
3128 | }, | |
3129 | { | |
3130 | code: "var v = a ?? ((b || c))", | |
3131 | output: "var v = a ?? (b || c)", | |
3132 | parserOptions: { ecmaVersion: 2020 }, | |
3133 | errors: [{ messageId: "unexpected" }] | |
3134 | }, | |
3135 | { | |
3136 | code: "var v = ((a ?? b)) && c", | |
3137 | output: "var v = (a ?? b) && c", | |
3138 | parserOptions: { ecmaVersion: 2020 }, | |
3139 | errors: [{ messageId: "unexpected" }] | |
3140 | }, | |
3141 | { | |
3142 | code: "var v = a ?? ((b && c))", | |
3143 | output: "var v = a ?? (b && c)", | |
3144 | parserOptions: { ecmaVersion: 2020 }, | |
3145 | errors: [{ messageId: "unexpected" }] | |
3146 | }, | |
3147 | { | |
3148 | code: "var v = ((a || b)) ?? c", | |
3149 | output: "var v = (a || b) ?? c", | |
3150 | parserOptions: { ecmaVersion: 2020 }, | |
3151 | errors: [{ messageId: "unexpected" }] | |
3152 | }, | |
3153 | { | |
3154 | code: "var v = a || ((b ?? c))", | |
3155 | output: "var v = a || (b ?? c)", | |
3156 | parserOptions: { ecmaVersion: 2020 }, | |
3157 | errors: [{ messageId: "unexpected" }] | |
3158 | }, | |
3159 | { | |
3160 | code: "var v = ((a && b)) ?? c", | |
3161 | output: "var v = (a && b) ?? c", | |
3162 | parserOptions: { ecmaVersion: 2020 }, | |
3163 | errors: [{ messageId: "unexpected" }] | |
3164 | }, | |
3165 | { | |
3166 | code: "var v = a && ((b ?? c))", | |
3167 | output: "var v = a && (b ?? c)", | |
3168 | parserOptions: { ecmaVersion: 2020 }, | |
3169 | errors: [{ messageId: "unexpected" }] | |
3170 | }, | |
3171 | { | |
3172 | code: "var v = (a ?? b) ? b : c", | |
3173 | output: "var v = a ?? b ? b : c", | |
3174 | parserOptions: { ecmaVersion: 2020 }, | |
3175 | errors: [{ messageId: "unexpected" }] | |
3176 | }, | |
3177 | { | |
3178 | code: "var v = (a | b) ?? c | d", | |
3179 | output: "var v = a | b ?? c | d", | |
3180 | parserOptions: { ecmaVersion: 2020 }, | |
3181 | errors: [{ messageId: "unexpected" }] | |
3182 | }, | |
3183 | { | |
3184 | code: "var v = a | b ?? (c | d)", | |
3185 | output: "var v = a | b ?? c | d", | |
3186 | parserOptions: { ecmaVersion: 2020 }, | |
3187 | errors: [{ messageId: "unexpected" }] | |
6f036462 TL |
3188 | }, |
3189 | ||
3190 | // Optional chaining | |
3191 | { | |
3192 | code: "var v = (obj?.aaa)?.aaa", | |
3193 | output: "var v = obj?.aaa?.aaa", | |
3194 | parserOptions: { ecmaVersion: 2020 }, | |
3195 | errors: [{ messageId: "unexpected" }] | |
3196 | }, | |
3197 | { | |
3198 | code: "var v = (obj.aaa)?.aaa", | |
3199 | output: "var v = obj.aaa?.aaa", | |
3200 | parserOptions: { ecmaVersion: 2020 }, | |
3201 | errors: [{ messageId: "unexpected" }] | |
3202 | }, | |
3203 | { | |
3204 | code: "var foo = (function(){})?.call()", | |
3205 | output: "var foo = function(){}?.call()", | |
3206 | options: ["all", { enforceForFunctionPrototypeMethods: true }], | |
3207 | parserOptions: { ecmaVersion: 2020 }, | |
3208 | errors: [{ messageId: "unexpected" }] | |
3209 | }, | |
3210 | { | |
3211 | code: "var foo = (function(){}?.call())", | |
3212 | output: "var foo = function(){}?.call()", | |
3213 | options: ["all", { enforceForFunctionPrototypeMethods: true }], | |
3214 | parserOptions: { ecmaVersion: 2020 }, | |
3215 | errors: [{ messageId: "unexpected" }] | |
d3726936 | 3216 | } |
eb39fafa DC |
3217 | ] |
3218 | }); |