2 * @fileoverview Disallow parenthesesisng higher precedence subexpressions.
3 * @author Michael Ficarra
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/no-extra-parens"),
13 { RuleTester
} = require("../../../lib/rule-tester");
16 * Create error message object for failure cases
17 * @param {string} code source code
18 * @param {string} output fixed source code
19 * @param {string} type node type
20 * @param {int} line line number
21 * @param {Object} config rule configuration
22 * @returns {Object} result object
25 function invalid(code
, output
, type
, line
, config
) {
29 parserOptions
: config
&& config
.parserOptions
|| {},
32 messageId
: "unexpected",
36 options
: config
&& config
.options
|| []
40 result
.errors
[0].line
= line
;
45 const ruleTester
= new RuleTester({
54 ruleTester
.run("no-extra-parens", rule
, {
57 // all precedence boundaries
62 "a || b ? c = d : e = f",
63 "(a = b) ? (c, d) : (e, f)",
65 "(a ? b : c) || (d ? e : f)",
67 "(a || b) && (c || d)",
69 "(a && b) | (c && d)",
75 "(a & b) !== (c & d)",
77 "(a == b) instanceof (c != d)",
79 "(a <= b) >> (c > d)",
81 "(a << b) - (c >> d)",
84 "-void+delete~typeof!a",
85 "!(a * b); typeof (a / b); +(a % b); delete (a * b); ~(a / b); void (a % b); -(a * b)",
87 "(++a)(b); (c++)(d);",
89 "new (foo.Baz().foo)",
90 "new (foo.baz.bar().foo.baz)",
91 "new ({}.baz.bar.foo().baz)",
92 "new (doSomething().baz.bar().foo)",
93 "new ([][0].baz.foo().bar.foo)",
94 "new (foo\n.baz\n.bar()\n.foo.baz)",
97 "(new (Foo || Bar))()",
101 "new (new new foo())(bar)",
107 "(new foo.bar).baz()",
109 "new (new foo.bar).baz",
110 "(new new foo()).baz",
113 "new (import(source))",
141 "!!a; typeof +b; void -c; ~delete d;",
149 // constructs that contain expressions
152 "switch(a){ case 0: break; }",
153 "function a(){ return b; }",
154 "var a = () => { return b; }",
162 "for (a of (b, c));",
173 "const {a:b=1} = {}",
174 "const {[a]:b} = {}",
175 "const {[a]:b=1} = {}",
176 "const {[(a, b)]:c} = {}",
177 "const {a, ...b} = {}",
179 "class foo { constructor(){} a(){} get b(){} set b(bar){} get c(){} set d(baz){} static e(){} }",
180 "class foo { [a](){} get [b](){} set [b](bar){} get [c](){} set [d](baz){} static [e](){} }",
181 "class foo { [(a,b)](){} }",
182 "class foo { a(){} [b](){} c(){} [(d,e)](){} }",
183 "class foo { [(a,b)](){} c(){} [d](){} e(){} }",
184 "const foo = class { constructor(){} a(){} get b(){} set b(bar){} get c(){} set d(baz){} static e(){} }",
186 // ExpressionStatement restricted productions
203 "({a: function(){}}.a());",
206 // RegExp literal is allowed to have parens (#1589)
207 "var isA = (/^a$/).test('a');",
208 "var regex = (/^a$/);",
209 "function a(){ return (/^a$/); }",
210 "function a(){ return (/^a$/).test('a'); }",
211 "var isA = ((/^a$/)).test('a');",
213 // IIFE is allowed to have parens in any position (#655)
214 "var foo = (function() { return bar(); }())",
215 "var o = { foo: (function() { return bar(); }()) };",
216 "o.foo = (function(){ return bar(); }());",
217 "(function(){ return bar(); }()), (function(){ return bar(); }())",
219 // IIFE is allowed to have outer parens (#1004)
220 "var foo = (function() { return bar(); })()",
221 "var o = { foo: (function() { return bar(); })() };",
222 "o.foo = (function(){ return bar(); })();",
223 "(function(){ return bar(); })(), (function(){ return bar(); })()",
224 "function foo() { return (function(){}()); }",
226 // parens are required around yield
227 "var foo = (function*() { if ((yield foo()) + 1) { return; } }())",
229 // arrow functions have the precedence of an assignment expression
234 "0 ? _ => 0 : _ => 0",
235 "(_ => 0) || (_ => 0)",
237 // Object literals as arrow function bodies need parentheses
241 // Exponentiation operator `**`
249 // https://github.com/eslint/eslint/issues/5789
254 // "functions" enables reports for function nodes only
255 { code
: "(0)", options
: ["functions"] },
256 { code
: "((0))", options
: ["functions"] },
257 { code
: "a + (b * c)", options
: ["functions"] },
258 { code
: "a + ((b * c))", options
: ["functions"] },
259 { code
: "(a)(b)", options
: ["functions"] },
260 { code
: "((a))(b)", options
: ["functions"] },
261 { code
: "a, (b = c)", options
: ["functions"] },
262 { code
: "a, ((b = c))", options
: ["functions"] },
263 { code
: "for(a in (0));", options
: ["functions"] },
264 { code
: "for(a in ((0)));", options
: ["functions"] },
265 { code
: "var a = (b = c)", options
: ["functions"] },
266 { code
: "var a = ((b = c))", options
: ["functions"] },
267 { code
: "_ => (a = 0)", options
: ["functions"] },
268 { code
: "_ => ((a = 0))", options
: ["functions"] },
270 // ["all", { conditionalAssign: false }] enables extra parens around conditional assignments
271 { code
: "while ((foo = bar())) {}", options
: ["all", { conditionalAssign
: false }] },
272 { code
: "if ((foo = bar())) {}", options
: ["all", { conditionalAssign
: false }] },
273 { code
: "do; while ((foo = bar()))", options
: ["all", { conditionalAssign
: false }] },
274 { code
: "for (;(a = b););", options
: ["all", { conditionalAssign
: false }] },
275 { code
: "var a = ((b = c)) ? foo : bar;", options
: ["all", { conditionalAssign
: false }] },
276 { code
: "while (((foo = bar()))) {}", options
: ["all", { conditionalAssign
: false }] },
277 { code
: "var a = (((b = c))) ? foo : bar;", options
: ["all", { conditionalAssign
: false }] },
279 // ["all", { nestedBinaryExpressions: false }] enables extra parens around conditional assignments
280 { code
: "a + (b * c)", options
: ["all", { nestedBinaryExpressions
: false }] },
281 { code
: "(a * b) + c", options
: ["all", { nestedBinaryExpressions
: false }] },
282 { code
: "(a * b) / c", options
: ["all", { nestedBinaryExpressions
: false }] },
283 { code
: "a || (b && c)", options
: ["all", { nestedBinaryExpressions
: false }] },
284 { code
: "a + ((b * c))", options
: ["all", { nestedBinaryExpressions
: false }] },
285 { code
: "((a * b)) + c", options
: ["all", { nestedBinaryExpressions
: false }] },
286 { code
: "((a * b)) / c", options
: ["all", { nestedBinaryExpressions
: false }] },
287 { code
: "a || ((b && c))", options
: ["all", { nestedBinaryExpressions
: false }] },
289 // ["all", { returnAssign: false }] enables extra parens around expressions returned by return statements
290 { code
: "function a(b) { return b || c; }", options
: ["all", { returnAssign
: false }] },
291 { code
: "function a(b) { return; }", options
: ["all", { returnAssign
: false }] },
292 { code
: "function a(b) { return (b = 1); }", options
: ["all", { returnAssign
: false }] },
293 { code
: "function a(b) { return (b = c) || (b = d); }", options
: ["all", { returnAssign
: false }] },
294 { code
: "function a(b) { return c ? (d = b) : (e = b); }", options
: ["all", { returnAssign
: false }] },
295 { code
: "b => b || c;", options
: ["all", { returnAssign
: false }] },
296 { code
: "b => (b = 1);", options
: ["all", { returnAssign
: false }] },
297 { code
: "b => (b = c) || (b = d);", options
: ["all", { returnAssign
: false }] },
298 { code
: "b => c ? (d = b) : (e = b);", options
: ["all", { returnAssign
: false }] },
299 { code
: "b => { return b || c };", options
: ["all", { returnAssign
: false }] },
300 { code
: "b => { return (b = 1) };", options
: ["all", { returnAssign
: false }] },
301 { code
: "b => { return (b = c) || (b = d) };", options
: ["all", { returnAssign
: false }] },
302 { code
: "b => { return c ? (d = b) : (e = b) };", options
: ["all", { returnAssign
: false }] },
303 { code
: "function a(b) { return ((b = 1)); }", options
: ["all", { returnAssign
: false }] },
304 { code
: "b => ((b = 1));", options
: ["all", { returnAssign
: false }] },
306 // https://github.com/eslint/eslint/issues/3653
307 "(function(){}).foo(), 1, 2;",
308 "(function(){}).foo++;",
309 "(function(){}).foo() || bar;",
310 "(function(){}).foo() + 1;",
311 "(function(){}).foo() ? bar : baz;",
312 "(function(){}).foo.bar();",
313 "(function(){}.foo());",
314 "(function(){}.foo.bar);",
316 "(class{}).foo(), 1, 2;",
318 "(class{}).foo() || bar;",
319 "(class{}).foo() + 1;",
320 "(class{}).foo() ? bar : baz;",
321 "(class{}).foo.bar();",
323 "(class{}.foo.bar);",
325 // https://github.com/eslint/eslint/issues/4608
326 "function *a() { yield b; }",
327 "function *a() { yield yield; }",
328 "function *a() { yield b, c; }",
329 "function *a() { yield (b, c); }",
330 "function *a() { yield b + c; }",
331 "function *a() { (yield b) + c; }",
333 // https://github.com/eslint/eslint/issues/4229
368 // linebreaks before postfix update operators are not allowed
378 "async function a() { await (a + b) }",
379 "async function a() { await (a + await b) }",
380 "async function a() { (await a)() }",
381 "async function a() { new (await a) }",
382 "async function a() { await (a ** b) }",
383 "async function a() { (await a) ** b }",
385 { code
: "(foo instanceof bar) instanceof baz", options
: ["all", { nestedBinaryExpressions
: false }] },
386 { code
: "(foo in bar) in baz", options
: ["all", { nestedBinaryExpressions
: false }] },
387 { code
: "(foo + bar) + baz", options
: ["all", { nestedBinaryExpressions
: false }] },
388 { code
: "(foo && bar) && baz", options
: ["all", { nestedBinaryExpressions
: false }] },
389 { code
: "foo instanceof (bar instanceof baz)", options
: ["all", { nestedBinaryExpressions
: false }] },
390 { code
: "foo in (bar in baz)", options
: ["all", { nestedBinaryExpressions
: false }] },
391 { code
: "foo + (bar + baz)", options
: ["all", { nestedBinaryExpressions
: false }] },
392 { code
: "foo && (bar && baz)", options
: ["all", { nestedBinaryExpressions
: false }] },
393 { code
: "((foo instanceof bar)) instanceof baz", options
: ["all", { nestedBinaryExpressions
: false }] },
394 { code
: "((foo in bar)) in baz", options
: ["all", { nestedBinaryExpressions
: false }] },
396 // https://github.com/eslint/eslint/issues/9019
397 "(async function() {});",
398 "(async function () { }());",
400 // ["all", { ignoreJSX: "all" }]
401 { code
: "const Component = (<div />)", options
: ["all", { ignoreJSX
: "all" }] },
402 { code
: "const Component = ((<div />))", options
: ["all", { ignoreJSX
: "all" }] },
405 "const Component = (<>",
409 options
: ["all", { ignoreJSX
: "all" }]
413 "const Component = ((<>",
417 options
: ["all", { ignoreJSX
: "all" }]
421 "const Component = (<div>",
425 options
: ["all", { ignoreJSX
: "all" }]
429 "const Component = (",
433 options
: ["all", { ignoreJSX
: "all" }]
440 options
: ["all", { ignoreJSX
: "all" }]
443 // ["all", { ignoreJSX: "single-line" }]
444 { code
: "const Component = (<div />);", options
: ["all", { ignoreJSX
: "single-line" }] },
445 { code
: "const Component = ((<div />));", options
: ["all", { ignoreJSX
: "single-line" }] },
448 "const Component = (",
452 options
: ["all", { ignoreJSX
: "single-line" }]
459 options
: ["all", { ignoreJSX
: "single-line" }]
462 // ["all", { ignoreJSX: "multi-line" }]
465 "const Component = (",
471 options
: ["all", { ignoreJSX
: "multi-line" }]
475 "const Component = ((",
481 options
: ["all", { ignoreJSX
: "multi-line" }]
485 "const Component = (<div>",
489 options
: ["all", { ignoreJSX
: "multi-line" }]
498 options
: ["all", { ignoreJSX
: "multi-line" }]
502 "const Component = (<div",
506 options
: ["all", { ignoreJSX
: "multi-line" }]
509 // ["all", { enforceForArrowConditionals: false }]
510 { code
: "var a = b => 1 ? 2 : 3", options
: ["all", { enforceForArrowConditionals
: false }] },
511 { code
: "var a = (b) => (1 ? 2 : 3)", options
: ["all", { enforceForArrowConditionals
: false }] },
512 { code
: "var a = (b) => ((1 ? 2 : 3))", options
: ["all", { enforceForArrowConditionals
: false }] },
514 // ["all", { enforceForSequenceExpressions: false }]
515 { code
: "(a, b)", options
: ["all", { enforceForSequenceExpressions
: false }] },
516 { code
: "((a, b))", options
: ["all", { enforceForSequenceExpressions
: false }] },
517 { code
: "(foo(), bar());", options
: ["all", { enforceForSequenceExpressions
: false }] },
518 { code
: "((foo(), bar()));", options
: ["all", { enforceForSequenceExpressions
: false }] },
519 { code
: "if((a, b)){}", options
: ["all", { enforceForSequenceExpressions
: false }] },
520 { code
: "if(((a, b))){}", options
: ["all", { enforceForSequenceExpressions
: false }] },
521 { code
: "while ((val = foo(), val < 10));", options
: ["all", { enforceForSequenceExpressions
: false }] },
523 // ["all", { enforceForNewInMemberExpressions: false }]
524 { code
: "(new foo()).bar", options
: ["all", { enforceForNewInMemberExpressions
: false }] },
525 { code
: "(new foo())[bar]", options
: ["all", { enforceForNewInMemberExpressions
: false }] },
526 { code
: "(new foo()).bar()", options
: ["all", { enforceForNewInMemberExpressions
: false }] },
527 { code
: "(new foo(bar)).baz", options
: ["all", { enforceForNewInMemberExpressions
: false }] },
528 { code
: "(new foo.bar()).baz", options
: ["all", { enforceForNewInMemberExpressions
: false }] },
529 { code
: "(new foo.bar()).baz()", options
: ["all", { enforceForNewInMemberExpressions
: false }] },
530 { code
: "((new foo.bar())).baz()", options
: ["all", { enforceForNewInMemberExpressions
: false }] },
532 // ["all", { enforceForFunctionPrototypeMethods: false }]
533 { code
: "var foo = (function(){}).call()", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
534 { code
: "var foo = (function(){}).apply()", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
535 { code
: "var foo = (function(){}.call())", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
536 { code
: "var foo = (function(){}.apply())", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
537 { code
: "var foo = (function(){}).call(arg)", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
538 { code
: "var foo = (function(){}.apply(arg))", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
539 { code
: "var foo = (function(){}['call']())", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
540 { code
: "var foo = (function(){})[`apply`]()", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
541 { code
: "var foo = ((function(){})).call()", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
542 { code
: "var foo = ((function(){}).apply())", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
543 { code
: "var foo = ((function(){}.call()))", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
544 { code
: "var foo = ((((function(){})).apply()))", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
545 { code
: "foo((function(){}).call().bar)", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
546 { code
: "foo = (function(){}).call()()", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
547 { code
: "foo = (function(){}.call())()", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
548 { code
: "var foo = { bar: (function(){}.call()) }", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
549 { code
: "var foo = { [(function(){}.call())]: bar }", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
550 { code
: "if((function(){}).call()){}", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
551 { code
: "while((function(){}.apply())){}", options
: ["all", { enforceForFunctionPrototypeMethods
: false }] },
556 code
: "let a = { ...b }",
557 parserOptions
: { ecmaVersion
: 2018 }
559 "let a = [ ...(b, c) ]",
560 "let a = { ...(b, c) }",
562 code
: "let a = { ...(b, c) }",
563 parserOptions
: { ecmaVersion
: 2018 }
565 "var [x = (1, foo)] = bar",
566 "class A extends B {}",
567 "const A = class extends B {}",
568 "class A extends (B=C) {}",
569 "const A = class extends (B=C) {}",
570 "class A extends (++foo) {}",
571 "() => ({ foo: 1 })",
572 "() => ({ foo: 1 }).foo",
573 "() => ({ foo: 1 }.foo().bar).baz.qux()",
574 "() => ({ foo: 1 }.foo().bar + baz)",
576 code
: "export default (a, b)",
577 parserOptions
: { sourceType
: "module" }
580 code
: "export default (function(){}).foo",
581 parserOptions
: { sourceType
: "module" }
584 code
: "export default (class{}).foo",
585 parserOptions
: { sourceType
: "module" }
587 "({}).hasOwnProperty.call(foo, bar)",
588 "({}) ? foo() : bar()",
590 "(function(){}) + foo",
592 "(let[foo]) = 1", // setting the 'foo' property of the 'let' variable to 1
594 code
: "((function(){}).foo.bar)();",
595 options
: ["functions"]
598 code
: "((function(){}).foo)();",
599 options
: ["functions"]
603 // ForStatement#init expression cannot start with `let[`. It would be parsed as a `let` declaration with array pattern, or a syntax error.
606 "for ((let[a] = 1);;);",
607 "for ((let[a]) = 1;;);",
608 "for ((let)[a] = 1;;);",
609 "for ((let[a, b] = foo);;);",
610 "for ((let[a].b = 1);;);",
611 "for ((let[a].b) = 1;;);",
612 "for ((let[a]).b = 1;;);",
613 "for ((let)[a].b = 1;;);",
614 "for ((let[a])();;);",
615 "for ((let)[a]();;);",
616 "for ((let[a]) + b;;);",
618 // ForInStatement#left expression cannot start with `let[`. It would be parsed as a `let` declaration with array pattern, or a syntax error.
619 "for ((let[foo]) in bar);",
620 "for ((let)[foo] in bar);",
621 "for ((let[foo].bar) in baz);",
622 "for ((let[foo]).bar in baz);",
623 "for ((let)[foo].bar in baz);",
625 // ForOfStatement#left expression cannot start with `let`. It's explicitly forbidden by the specification.
626 "for ((let) of foo);",
627 "for ((let).foo of bar);",
628 "for ((let.foo) of bar);",
629 "for ((let[foo]) of bar);",
630 "for ((let)[foo] of bar);",
631 "for ((let.foo.bar) of baz);",
632 "for ((let.foo).bar of baz);",
633 "for ((let).foo.bar of baz);",
634 "for ((let[foo].bar) of baz);",
635 "for ((let[foo]).bar of baz);",
636 "for ((let)[foo].bar of baz);",
637 "for ((let)().foo of bar);",
638 "for ((let()).foo of bar);",
639 "for ((let().foo) of bar);",
641 // https://github.com/eslint/eslint/issues/11706 (also in invalid[])
642 "for (let a = (b in c); ;);",
643 "for (let a = (b && c in d); ;);",
644 "for (let a = (b in c && d); ;);",
645 "for (let a = (b => b in c); ;);",
646 "for (let a = b => (b in c); ;);",
647 "for (let a = (b in c in d); ;);",
648 "for (let a = (b in c), d = (e in f); ;);",
649 "for (let a = (b => c => b in c); ;);",
650 "for (let a = (b && c && d in e); ;);",
651 "for (let a = b && (c in d); ;);",
652 "for (let a = (b in c) && (d in e); ;);",
653 "for ((a in b); ;);",
654 "for (a = (b in c); ;);",
655 "for ((a in b && c in d && e in f); ;);",
656 "for (let a = [] && (b in c); ;);",
657 "for (let a = (b in [c]); ;);",
658 "for (let a = b => (c in d); ;);",
659 "for (let a = (b in c) ? d : e; ;);",
660 "for (let a = (b in c ? d : e); ;);",
661 "for (let a = b ? c : (d in e); ;);",
662 "for (let a = (b in c), d = () => { for ((e in f);;); for ((g in h);;); }; ;); for((i in j); ;);",
664 // https://github.com/eslint/eslint/issues/11706 regression tests (also in invalid[])
665 "for (let a = b; a; a); a; a;",
666 "for (a; a; a); a; a;",
667 "for (; a; a); a; a;",
668 "for (let a = (b && c) === d; ;);",
678 // Nullish coalescing
679 { code
: "var v = (a ?? b) || c", parserOptions
: { ecmaVersion
: 2020 } },
680 { code
: "var v = a ?? (b || c)", parserOptions
: { ecmaVersion
: 2020 } },
681 { code
: "var v = (a ?? b) && c", parserOptions
: { ecmaVersion
: 2020 } },
682 { code
: "var v = a ?? (b && c)", parserOptions
: { ecmaVersion
: 2020 } },
683 { code
: "var v = (a || b) ?? c", parserOptions
: { ecmaVersion
: 2020 } },
684 { code
: "var v = a || (b ?? c)", parserOptions
: { ecmaVersion
: 2020 } },
685 { code
: "var v = (a && b) ?? c", parserOptions
: { ecmaVersion
: 2020 } },
686 { code
: "var v = a && (b ?? c)", parserOptions
: { ecmaVersion
: 2020 } },
689 { code
: "var v = (obj?.aaa).bbb", parserOptions
: { ecmaVersion
: 2020 } },
690 { code
: "var v = (obj?.aaa)()", parserOptions
: { ecmaVersion
: 2020 } },
691 { code
: "var v = new (obj?.aaa)()", parserOptions
: { ecmaVersion
: 2020 } },
692 { code
: "var v = new (obj?.aaa)", parserOptions
: { ecmaVersion
: 2020 } },
693 { code
: "var v = (obj?.aaa)`template`", parserOptions
: { ecmaVersion
: 2020 } },
694 { code
: "var v = (obj?.()).bbb", parserOptions
: { ecmaVersion
: 2020 } },
695 { code
: "var v = (obj?.())()", parserOptions
: { ecmaVersion
: 2020 } },
696 { code
: "var v = new (obj?.())()", parserOptions
: { ecmaVersion
: 2020 } },
697 { code
: "var v = new (obj?.())", parserOptions
: { ecmaVersion
: 2020 } },
698 { code
: "var v = (obj?.())`template`", parserOptions
: { ecmaVersion
: 2020 } },
699 { code
: "(obj?.aaa).bbb = 0", parserOptions
: { ecmaVersion
: 2020 } },
700 { code
: "var foo = (function(){})?.()", parserOptions
: { ecmaVersion
: 2020 } },
701 { code
: "var foo = (function(){}?.())", parserOptions
: { ecmaVersion
: 2020 } },
703 code
: "var foo = (function(){})?.call()",
704 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
705 parserOptions
: { ecmaVersion
: 2020 }
708 code
: "var foo = (function(){}?.call())",
709 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
710 parserOptions
: { ecmaVersion
: 2020 }
715 invalid("(0)", "0", "Literal"),
716 invalid("( 0 )", " 0 ", "Literal"),
717 invalid("if((0));", "if(0);", "Literal"),
718 invalid("if(( 0 ));", "if( 0 );", "Literal"),
719 invalid("with((0)){}", "with(0){}", "Literal"),
720 invalid("switch((0)){}", "switch(0){}", "Literal"),
721 invalid("switch(0){ case (1): break; }", "switch(0){ case 1: break; }", "Literal"),
722 invalid("for((0);;);", "for(0;;);", "Literal"),
723 invalid("for(;(0););", "for(;0;);", "Literal"),
724 invalid("for(;;(0));", "for(;;0);", "Literal"),
725 invalid("throw(0)", "throw 0", "Literal"),
726 invalid("while((0));", "while(0);", "Literal"),
727 invalid("do; while((0))", "do; while(0)", "Literal"),
728 invalid("for(a in (0));", "for(a in 0);", "Literal"),
729 invalid("for(a of (0));", "for(a of 0);", "Literal", 1),
730 invalid("const foo = {[(a)]:1}", "const foo = {[a]:1}", "Identifier", 1),
731 invalid("const foo = {[(a=b)]:1}", "const foo = {[a=b]:1}", "AssignmentExpression", 1),
732 invalid("const foo = {*[(Symbol.iterator)]() {}}", "const foo = {*[Symbol.iterator]() {}}", "MemberExpression", 1),
733 invalid("const foo = { get [(a)]() {}}", "const foo = { get [a]() {}}", "Identifier", 1),
734 invalid("const foo = {[(a+b)]:c, d}", "const foo = {[a+b]:c, d}", "BinaryExpression", 1),
735 invalid("const foo = {a, [(b+c)]:d, e}", "const foo = {a, [b+c]:d, e}", "BinaryExpression", 1),
736 invalid("const foo = {[(a+b)]:c, d:e}", "const foo = {[a+b]:c, d:e}", "BinaryExpression", 1),
737 invalid("const foo = {a:b, [(c+d)]:e, f:g}", "const foo = {a:b, [c+d]:e, f:g}", "BinaryExpression", 1),
738 invalid("const foo = {[(a+b)]:c, [d]:e}", "const foo = {[a+b]:c, [d]:e}", "BinaryExpression", 1),
739 invalid("const foo = {[a]:b, [(c+d)]:e, [f]:g}", "const foo = {[a]:b, [c+d]:e, [f]:g}", "BinaryExpression", 1),
740 invalid("const foo = {[(a+b)]:c, [(d,e)]:f}", "const foo = {[a+b]:c, [(d,e)]:f}", "BinaryExpression", 1),
741 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),
742 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),
743 invalid("const foo = {[a+(b*c)]:d}", "const foo = {[a+b*c]:d}", "BinaryExpression", 1),
744 invalid("const foo = {[(a, (b+c))]:d}", "const foo = {[(a, b+c)]:d}", "BinaryExpression", 1),
745 invalid("const {[(a)]:b} = {}", "const {[a]:b} = {}", "Identifier", 1),
746 invalid("const {[(a=b)]:c=1} = {}", "const {[a=b]:c=1} = {}", "AssignmentExpression", 1),
747 invalid("const {[(a+b)]:c, d} = {}", "const {[a+b]:c, d} = {}", "BinaryExpression", 1),
748 invalid("const {a, [(b+c)]:d, e} = {}", "const {a, [b+c]:d, e} = {}", "BinaryExpression", 1),
749 invalid("const {[(a+b)]:c, d:e} = {}", "const {[a+b]:c, d:e} = {}", "BinaryExpression", 1),
750 invalid("const {a:b, [(c+d)]:e, f:g} = {}", "const {a:b, [c+d]:e, f:g} = {}", "BinaryExpression", 1),
751 invalid("const {[(a+b)]:c, [d]:e} = {}", "const {[a+b]:c, [d]:e} = {}", "BinaryExpression", 1),
752 invalid("const {[a]:b, [(c+d)]:e, [f]:g} = {}", "const {[a]:b, [c+d]:e, [f]:g} = {}", "BinaryExpression", 1),
753 invalid("const {[(a+b)]:c, [(d,e)]:f} = {}", "const {[a+b]:c, [(d,e)]:f} = {}", "BinaryExpression", 1),
754 invalid("const {[(a,b)]:c, [(d+e)]:f, [(g,h)]:e} = {}", "const {[(a,b)]:c, [d+e]:f, [(g,h)]:e} = {}", "BinaryExpression", 1),
755 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),
756 invalid("const {[a+(b*c)]:d} = {}", "const {[a+b*c]:d} = {}", "BinaryExpression", 1),
757 invalid("const {[(a, (b+c))]:d} = {}", "const {[(a, b+c)]:d} = {}", "BinaryExpression", 1),
758 invalid("class foo { [(a)](){} }", "class foo { [a](){} }", "Identifier"),
759 invalid("class foo {*[(Symbol.iterator)]() {}}", "class foo {*[Symbol.iterator]() {}}", "MemberExpression"),
760 invalid("class foo { get [(a)](){} }", "class foo { get [a](){} }", "Identifier"),
761 invalid("class foo { set [(a)](bar){} }", "class foo { set [a](bar){} }", "Identifier"),
762 invalid("class foo { static [(a)](bar){} }", "class foo { static [a](bar){} }", "Identifier"),
763 invalid("class foo { [(a=b)](){} }", "class foo { [a=b](){} }", "AssignmentExpression"),
764 invalid("class foo { constructor (){} [(a+b)](){} }", "class foo { constructor (){} [a+b](){} }", "BinaryExpression"),
765 invalid("class foo { [(a+b)](){} constructor (){} }", "class foo { [a+b](){} constructor (){} }", "BinaryExpression"),
766 invalid("class foo { [(a+b)](){} c(){} }", "class foo { [a+b](){} c(){} }", "BinaryExpression"),
767 invalid("class foo { a(){} [(b+c)](){} d(){} }", "class foo { a(){} [b+c](){} d(){} }", "BinaryExpression"),
768 invalid("class foo { [(a+b)](){} [c](){} }", "class foo { [a+b](){} [c](){} }", "BinaryExpression"),
769 invalid("class foo { [a](){} [(b+c)](){} [d](){} }", "class foo { [a](){} [b+c](){} [d](){} }", "BinaryExpression"),
770 invalid("class foo { [(a+b)](){} [(c,d)](){} }", "class foo { [a+b](){} [(c,d)](){} }", "BinaryExpression"),
771 invalid("class foo { [(a,b)](){} [(c+d)](){} }", "class foo { [(a,b)](){} [c+d](){} }", "BinaryExpression"),
772 invalid("class foo { [a+(b*c)](){} }", "class foo { [a+b*c](){} }", "BinaryExpression"),
773 invalid("const foo = class { [(a)](){} }", "const foo = class { [a](){} }", "Identifier"),
775 "var foo = (function*() { if ((yield foo())) { return; } }())",
776 "var foo = (function*() { if (yield foo()) { return; } }())",
780 invalid("f((0))", "f(0)", "Literal"),
781 invalid("f(0, (1))", "f(0, 1)", "Literal"),
782 invalid("!(0)", "!0", "Literal"),
783 invalid("a[(1)]", "a[1]", "Literal"),
784 invalid("(a)(b)", "a(b)", "Identifier"),
785 invalid("(async)", "async", "Identifier"),
786 invalid("(a, b)", "a, b", "SequenceExpression"),
787 invalid("var a = (b = c);", "var a = b = c;", "AssignmentExpression"),
788 invalid("function f(){ return (a); }", "function f(){ return a; }", "Identifier"),
789 invalid("[a, (b = c)]", "[a, b = c]", "AssignmentExpression"),
790 invalid("!{a: (b = c)}", "!{a: b = c}", "AssignmentExpression"),
791 invalid("typeof(0)", "typeof 0", "Literal"),
792 invalid("typeof (0)", "typeof 0", "Literal"),
793 invalid("typeof([])", "typeof[]", "ArrayExpression"),
794 invalid("typeof ([])", "typeof []", "ArrayExpression"),
795 invalid("typeof( 0)", "typeof 0", "Literal"),
796 invalid("typeof(typeof 5)", "typeof typeof 5", "UnaryExpression"),
797 invalid("typeof (typeof 5)", "typeof typeof 5", "UnaryExpression"),
798 invalid("+(+foo)", "+ +foo", "UnaryExpression"),
799 invalid("-(-foo)", "- -foo", "UnaryExpression"),
800 invalid("+(-foo)", "+-foo", "UnaryExpression"),
801 invalid("-(+foo)", "-+foo", "UnaryExpression"),
802 invalid("-((bar+foo))", "-(bar+foo)", "BinaryExpression"),
803 invalid("+((bar-foo))", "+(bar-foo)", "BinaryExpression"),
804 invalid("++(foo)", "++foo", "Identifier"),
805 invalid("--(foo)", "--foo", "Identifier"),
806 invalid("++\n(foo)", "++\nfoo", "Identifier"),
807 invalid("--\n(foo)", "--\nfoo", "Identifier"),
808 invalid("++(\nfoo)", "++\nfoo", "Identifier"),
809 invalid("--(\nfoo)", "--\nfoo", "Identifier"),
810 invalid("(foo)++", "foo++", "Identifier"),
811 invalid("(foo)--", "foo--", "Identifier"),
812 invalid("((foo)\n)++", "(foo\n)++", "Identifier"),
813 invalid("((foo\n))--", "(foo\n)--", "Identifier"),
814 invalid("((foo\n)\n)++", "(foo\n\n)++", "Identifier"),
815 invalid("(a\n.b)--", "a\n.b--", "MemberExpression"),
816 invalid("(a.\nb)++", "a.\nb++", "MemberExpression"),
817 invalid("(a\n[\nb\n])--", "a\n[\nb\n]--", "MemberExpression"),
818 invalid("(a || b) ? c : d", "a || b ? c : d", "LogicalExpression"),
819 invalid("a ? (b = c) : d", "a ? b = c : d", "AssignmentExpression"),
820 invalid("a ? b : (c = d)", "a ? b : c = d", "AssignmentExpression"),
821 invalid("(c = d) ? (b) : c", "(c = d) ? b : c", "Identifier", null, { options
: ["all", { conditionalAssign
: false }] }),
822 invalid("(c = d) ? b : (c)", "(c = d) ? b : c", "Identifier", null, { options
: ["all", { conditionalAssign
: false }] }),
823 invalid("f((a = b))", "f(a = b)", "AssignmentExpression"),
824 invalid("a, (b = c)", "a, b = c", "AssignmentExpression"),
825 invalid("a = (b * c)", "a = b * c", "BinaryExpression"),
826 invalid("a + (b * c)", "a + b * c", "BinaryExpression"),
827 invalid("(a * b) + c", "a * b + c", "BinaryExpression"),
828 invalid("(a * b) / c", "a * b / c", "BinaryExpression"),
829 invalid("(2) ** 3 ** 4", "2 ** 3 ** 4", "Literal", null),
830 invalid("2 ** (3 ** 4)", "2 ** 3 ** 4", "BinaryExpression", null),
831 invalid("(2 ** 3)", "2 ** 3", "BinaryExpression", null),
832 invalid("(2 ** 3) + 1", "2 ** 3 + 1", "BinaryExpression", null),
833 invalid("1 - (2 ** 3)", "1 - 2 ** 3", "BinaryExpression", null),
834 invalid("-((2 ** 3))", "-(2 ** 3)", "BinaryExpression", null),
835 invalid("typeof ((a ** b));", "typeof (a ** b);", "BinaryExpression", null),
836 invalid("((-2)) ** 3", "(-2) ** 3", "UnaryExpression", null),
838 invalid("a = (b * c)", "a = b * c", "BinaryExpression", null, { options
: ["all", { nestedBinaryExpressions
: false }] }),
839 invalid("(b * c)", "b * c", "BinaryExpression", null, { options
: ["all", { nestedBinaryExpressions
: false }] }),
841 invalid("a = (b = c)", "a = b = c", "AssignmentExpression"),
842 invalid("(a).b", "a.b", "Identifier"),
843 invalid("(0)[a]", "0[a]", "Literal"),
844 invalid("(0.0).a", "0.0.a", "Literal"),
845 invalid("(123.4).a", "123.4.a", "Literal"),
846 invalid("(0.0_0).a", "0.0_0.a", "Literal"),
847 invalid("(0xBEEF).a", "0xBEEF.a", "Literal"),
848 invalid("(0xBE_EF).a", "0xBE_EF.a", "Literal"),
849 invalid("(1e6).a", "1e6.a", "Literal"),
850 invalid("(0123).a", "0123.a", "Literal"),
851 invalid("(08.1).a", "08.1.a", "Literal"),
852 invalid("(09.).a", "09..a", "Literal"),
853 invalid("a[(function() {})]", "a[function() {}]", "FunctionExpression"),
854 invalid("new (function(){})", "new function(){}", "FunctionExpression"),
855 invalid("new (\nfunction(){}\n)", "new \nfunction(){}\n", "FunctionExpression", 1),
856 invalid("((function foo() {return 1;}))()", "(function foo() {return 1;})()", "FunctionExpression"),
857 invalid("((function(){ return bar(); })())", "(function(){ return bar(); })()", "CallExpression"),
858 invalid("(foo()).bar", "foo().bar", "CallExpression"),
859 invalid("(foo.bar()).baz", "foo.bar().baz", "CallExpression"),
860 invalid("(foo\n.bar())\n.baz", "foo\n.bar()\n.baz", "CallExpression"),
861 invalid("(new foo()).bar", "new foo().bar", "NewExpression"),
862 invalid("(new foo())[bar]", "new foo()[bar]", "NewExpression"),
863 invalid("(new foo()).bar()", "new foo().bar()", "NewExpression"),
864 invalid("(new foo(bar)).baz", "new foo(bar).baz", "NewExpression"),
865 invalid("(new foo.bar()).baz", "new foo.bar().baz", "NewExpression"),
866 invalid("(new foo.bar()).baz()", "new foo.bar().baz()", "NewExpression"),
867 invalid("new a[(b()).c]", "new a[b().c]", "CallExpression"),
869 invalid("(a)()", "a()", "Identifier"),
870 invalid("(a.b)()", "a.b()", "MemberExpression"),
871 invalid("(a())()", "a()()", "CallExpression"),
872 invalid("(a.b())()", "a.b()()", "CallExpression"),
873 invalid("(a().b)()", "a().b()", "MemberExpression"),
874 invalid("(a().b.c)()", "a().b.c()", "MemberExpression"),
875 invalid("new (A)", "new A", "Identifier"),
876 invalid("(new A())()", "new A()()", "NewExpression"),
877 invalid("(new A(1))()", "new A(1)()", "NewExpression"),
878 invalid("((new A))()", "(new A)()", "NewExpression"),
879 invalid("new (foo\n.baz\n.bar\n.foo.baz)", "new foo\n.baz\n.bar\n.foo.baz", "MemberExpression"),
880 invalid("new (foo.baz.bar.baz)", "new foo.baz.bar.baz", "MemberExpression"),
881 invalid("new ((a.b())).c", "new (a.b()).c", "CallExpression"),
882 invalid("new ((a().b)).c", "new (a().b).c", "MemberExpression"),
883 invalid("new ((a().b().d))", "new (a().b().d)", "MemberExpression"),
884 invalid("new ((a())).b.d", "new (a()).b.d", "CallExpression"),
885 invalid("new (a.b).d;", "new a.b.d;", "MemberExpression"),
886 invalid("new (new A())();", "new new A()();", "NewExpression"),
887 invalid("new (new A());", "new new A();", "NewExpression"),
888 invalid("new (new A);", "new new A;", "NewExpression"),
889 invalid("new (new a.b);", "new new a.b;", "NewExpression"),
890 invalid("(a().b).d;", "a().b.d;", "MemberExpression"),
891 invalid("(a.b()).d;", "a.b().d;", "CallExpression"),
892 invalid("(a.b).d;", "a.b.d;", "MemberExpression"),
894 invalid("0, (_ => 0)", "0, _ => 0", "ArrowFunctionExpression", 1),
895 invalid("(_ => 0), 0", "_ => 0, 0", "ArrowFunctionExpression", 1),
896 invalid("a = (_ => 0)", "a = _ => 0", "ArrowFunctionExpression", 1),
897 invalid("_ => (a = 0)", "_ => a = 0", "AssignmentExpression", 1),
898 invalid("x => (({}))", "x => ({})", "ObjectExpression", 1),
900 invalid("new (function(){})", "new function(){}", "FunctionExpression", null, { options
: ["functions"] }),
901 invalid("new (\nfunction(){}\n)", "new \nfunction(){}\n", "FunctionExpression", 1, { options
: ["functions"] }),
902 invalid("((function foo() {return 1;}))()", "(function foo() {return 1;})()", "FunctionExpression", null, { options
: ["functions"] }),
903 invalid("a[(function() {})]", "a[function() {}]", "FunctionExpression", null, { options
: ["functions"] }),
904 invalid("0, (_ => 0)", "0, _ => 0", "ArrowFunctionExpression", 1, { options
: ["functions"] }),
905 invalid("(_ => 0), 0", "_ => 0, 0", "ArrowFunctionExpression", 1, { options
: ["functions"] }),
906 invalid("a = (_ => 0)", "a = _ => 0", "ArrowFunctionExpression", 1, { options
: ["functions"] }),
909 invalid("while ((foo = bar())) {}", "while (foo = bar()) {}", "AssignmentExpression"),
910 invalid("while ((foo = bar())) {}", "while (foo = bar()) {}", "AssignmentExpression", 1, { options
: ["all", { conditionalAssign
: true }] }),
911 invalid("if ((foo = bar())) {}", "if (foo = bar()) {}", "AssignmentExpression"),
912 invalid("do; while ((foo = bar()))", "do; while (foo = bar())", "AssignmentExpression"),
913 invalid("for (;(a = b););", "for (;a = b;);", "AssignmentExpression"),
915 // https://github.com/eslint/eslint/issues/3653
916 invalid("((function(){})).foo();", "(function(){}).foo();", "FunctionExpression"),
917 invalid("((function(){}).foo());", "(function(){}).foo();", "CallExpression"),
918 invalid("((function(){}).foo);", "(function(){}).foo;", "MemberExpression"),
919 invalid("0, (function(){}).foo();", "0, function(){}.foo();", "FunctionExpression"),
920 invalid("void (function(){}).foo();", "void function(){}.foo();", "FunctionExpression"),
921 invalid("++(function(){}).foo;", "++function(){}.foo;", "FunctionExpression"),
922 invalid("bar || (function(){}).foo();", "bar || function(){}.foo();", "FunctionExpression"),
923 invalid("1 + (function(){}).foo();", "1 + function(){}.foo();", "FunctionExpression"),
924 invalid("bar ? (function(){}).foo() : baz;", "bar ? function(){}.foo() : baz;", "FunctionExpression"),
925 invalid("bar ? baz : (function(){}).foo();", "bar ? baz : function(){}.foo();", "FunctionExpression"),
926 invalid("bar((function(){}).foo(), 0);", "bar(function(){}.foo(), 0);", "FunctionExpression"),
927 invalid("bar[(function(){}).foo()];", "bar[function(){}.foo()];", "FunctionExpression"),
928 invalid("var bar = (function(){}).foo();", "var bar = function(){}.foo();", "FunctionExpression"),
930 invalid("((class{})).foo();", "(class{}).foo();", "ClassExpression", null),
931 invalid("((class{}).foo());", "(class{}).foo();", "CallExpression", null),
932 invalid("((class{}).foo);", "(class{}).foo;", "MemberExpression", null),
933 invalid("0, (class{}).foo();", "0, class{}.foo();", "ClassExpression", null),
934 invalid("void (class{}).foo();", "void class{}.foo();", "ClassExpression", null),
935 invalid("++(class{}).foo;", "++class{}.foo;", "ClassExpression", null),
936 invalid("bar || (class{}).foo();", "bar || class{}.foo();", "ClassExpression", null),
937 invalid("1 + (class{}).foo();", "1 + class{}.foo();", "ClassExpression", null),
938 invalid("bar ? (class{}).foo() : baz;", "bar ? class{}.foo() : baz;", "ClassExpression", null),
939 invalid("bar ? baz : (class{}).foo();", "bar ? baz : class{}.foo();", "ClassExpression", null),
940 invalid("bar((class{}).foo(), 0);", "bar(class{}.foo(), 0);", "ClassExpression", null),
941 invalid("bar[(class{}).foo()];", "bar[class{}.foo()];", "ClassExpression", null),
942 invalid("var bar = (class{}).foo();", "var bar = class{}.foo();", "ClassExpression", null),
943 invalid("var foo = ((bar, baz));", "var foo = (bar, baz);", "SequenceExpression", null),
945 // https://github.com/eslint/eslint/issues/4608
946 invalid("function *a() { yield (b); }", "function *a() { yield b; }", "Identifier", null),
947 invalid("function *a() { (yield b), c; }", "function *a() { yield b, c; }", "YieldExpression", null),
948 invalid("function *a() { yield ((b, c)); }", "function *a() { yield (b, c); }", "SequenceExpression", null),
949 invalid("function *a() { yield (b + c); }", "function *a() { yield b + c; }", "BinaryExpression", null),
951 // https://github.com/eslint/eslint/issues/4229
960 ].join("\n"), "Identifier"),
971 ].join("\n"), "Identifier"),
984 ].join("\n"), "Identifier"),
987 " return (<JSX />);",
993 ].join("\n"), "JSXElement", null),
1004 ].join("\n"), "JSXElement", null),
1017 ].join("\n"), "JSXElement", null),
1030 ].join("\n"), "JSXFragment", null),
1031 invalid("throw (a);", "throw a;", "Identifier"),
1040 ].join("\n"), "Identifier"),
1049 ].join("\n"), "Identifier", null),
1060 ].join("\n"), "Identifier", null),
1073 ].join("\n"), "Identifier", null),
1075 // returnAssign option
1077 code
: "function a(b) { return (b || c); }",
1078 output
: "function a(b) { return b || c; }",
1079 options
: ["all", { returnAssign
: false }],
1082 messageId
: "unexpected",
1083 type
: "LogicalExpression"
1088 code
: "function a(b) { return ((b = c) || (d = e)); }",
1089 output
: "function a(b) { return (b = c) || (d = e); }",
1092 messageId
: "unexpected",
1093 type
: "LogicalExpression"
1098 code
: "function a(b) { return (b = 1); }",
1099 output
: "function a(b) { return b = 1; }",
1102 messageId
: "unexpected",
1103 type
: "AssignmentExpression"
1108 code
: "function a(b) { return c ? (d = b) : (e = b); }",
1109 output
: "function a(b) { return c ? d = b : e = b; }",
1112 messageId
: "unexpected",
1113 type
: "AssignmentExpression"
1116 messageId
: "unexpected",
1117 type
: "AssignmentExpression"
1122 code
: "b => (b || c);",
1123 output
: "b => b || c;",
1124 options
: ["all", { returnAssign
: false }],
1128 messageId
: "unexpected",
1129 type
: "LogicalExpression"
1134 code
: "b => ((b = c) || (d = e));",
1135 output
: "b => (b = c) || (d = e);",
1138 messageId
: "unexpected",
1139 type
: "LogicalExpression"
1144 code
: "b => (b = 1);",
1145 output
: "b => b = 1;",
1148 messageId
: "unexpected",
1149 type
: "AssignmentExpression"
1154 code
: "b => c ? (d = b) : (e = b);",
1155 output
: "b => c ? d = b : e = b;",
1158 messageId
: "unexpected",
1159 type
: "AssignmentExpression"
1162 messageId
: "unexpected",
1163 type
: "AssignmentExpression"
1168 code
: "b => { return (b || c); }",
1169 output
: "b => { return b || c; }",
1170 options
: ["all", { returnAssign
: false }],
1173 messageId
: "unexpected",
1174 type
: "LogicalExpression"
1179 code
: "b => { return ((b = c) || (d = e)) };",
1180 output
: "b => { return (b = c) || (d = e) };",
1183 messageId
: "unexpected",
1184 type
: "LogicalExpression"
1189 code
: "b => { return (b = 1) };",
1190 output
: "b => { return b = 1 };",
1193 messageId
: "unexpected",
1194 type
: "AssignmentExpression"
1199 code
: "b => { return c ? (d = b) : (e = b); }",
1200 output
: "b => { return c ? d = b : e = b; }",
1203 messageId
: "unexpected",
1204 type
: "AssignmentExpression"
1207 messageId
: "unexpected",
1208 type
: "AssignmentExpression"
1215 code
: "async function a() { (await a) + (await b); }",
1216 output
: "async function a() { await a + await b; }",
1219 messageId
: "unexpected",
1220 type
: "AwaitExpression"
1223 messageId
: "unexpected",
1224 type
: "AwaitExpression"
1228 invalid("async function a() { await (a); }", "async function a() { await a; }", "Identifier", null),
1229 invalid("async function a() { await (a()); }", "async function a() { await a(); }", "CallExpression", null),
1230 invalid("async function a() { await (+a); }", "async function a() { await +a; }", "UnaryExpression", null),
1231 invalid("async function a() { +(await a); }", "async function a() { +await a; }", "AwaitExpression", null),
1232 invalid("async function a() { await ((a,b)); }", "async function a() { await (a,b); }", "SequenceExpression", null),
1233 invalid("async function a() { a ** (await b); }", "async function a() { a ** await b; }", "AwaitExpression", null),
1235 invalid("(foo) instanceof bar", "foo instanceof bar", "Identifier", 1, { options
: ["all", { nestedBinaryExpressions
: false }] }),
1236 invalid("(foo) in bar", "foo in bar", "Identifier", 1, { options
: ["all", { nestedBinaryExpressions
: false }] }),
1237 invalid("(foo) + bar", "foo + bar", "Identifier", 1, { options
: ["all", { nestedBinaryExpressions
: false }] }),
1238 invalid("(foo) && bar", "foo && bar", "Identifier", 1, { options
: ["all", { nestedBinaryExpressions
: false }] }),
1239 invalid("foo instanceof (bar)", "foo instanceof bar", "Identifier", 1, { options
: ["all", { nestedBinaryExpressions
: false }] }),
1240 invalid("foo in (bar)", "foo in bar", "Identifier", 1, { options
: ["all", { nestedBinaryExpressions
: false }] }),
1241 invalid("foo + (bar)", "foo + bar", "Identifier", 1, { options
: ["all", { nestedBinaryExpressions
: false }] }),
1242 invalid("foo && (bar)", "foo && bar", "Identifier", 1, { options
: ["all", { nestedBinaryExpressions
: false }] }),
1244 // ["all", { ignoreJSX: "multi-line" }]
1245 invalid("const Component = (<div />);", "const Component = <div />;", "JSXElement", 1, {
1246 options
: ["all", { ignoreJSX
: "multi-line" }]
1249 "const Component = (",
1252 ].join("\n"), "const Component = \n <div />\n;", "JSXElement", 1, {
1253 options
: ["all", { ignoreJSX
: "multi-line" }]
1256 "const Component = (",
1259 ].join("\n"), "const Component = \n <></>\n;", "JSXFragment", 1, {
1260 options
: ["all", { ignoreJSX
: "multi-line" }]
1263 // ["all", { ignoreJSX: "single-line" }]
1265 "const Component = (",
1270 ].join("\n"), "const Component = \n<div>\n <p />\n</div>\n;", "JSXElement", 1, {
1271 options
: ["all", { ignoreJSX
: "single-line" }]
1274 "const Component = (<div>",
1277 ].join("\n"), "const Component = <div>\n <p />\n</div>;", "JSXElement", 1, {
1278 options
: ["all", { ignoreJSX
: "single-line" }]
1281 "const Component = (<div",
1284 ].join("\n"), "const Component = <div\n prop={true}\n/>", "JSXElement", 1, {
1285 options
: ["all", { ignoreJSX
: "single-line" }]
1288 // ["all", { ignoreJSX: "none" }] default, same as unspecified
1289 invalid("const Component = (<div />);", "const Component = <div />;", "JSXElement", 1, {
1290 options
: ["all", { ignoreJSX
: "none" }]
1293 "const Component = (<div>",
1296 ].join("\n"), "const Component = <div>\n<p />\n</div>", "JSXElement", 1, {
1297 options
: ["all", { ignoreJSX
: "none" }]
1300 // ["all", { enforceForArrowConditionals: true }]
1302 code
: "var a = (b) => (1 ? 2 : 3)",
1303 output
: "var a = (b) => 1 ? 2 : 3",
1304 options
: ["all", { enforceForArrowConditionals
: true }],
1307 messageId
: "unexpected"
1312 code
: "var a = (b) => ((1 ? 2 : 3))",
1313 output
: "var a = (b) => (1 ? 2 : 3)",
1314 options
: ["all", { enforceForArrowConditionals
: true }],
1317 messageId
: "unexpected"
1322 // ["all", { enforceForSequenceExpressions: true }]
1329 messageId
: "unexpected",
1330 type
: "SequenceExpression"
1337 options
: ["all", {}],
1340 messageId
: "unexpected",
1341 type
: "SequenceExpression"
1348 options
: ["all", { enforceForSequenceExpressions
: true }],
1351 messageId
: "unexpected",
1352 type
: "SequenceExpression"
1357 code
: "(foo(), bar());",
1358 output
: "foo(), bar();",
1359 options
: ["all", { enforceForSequenceExpressions
: true }],
1362 messageId
: "unexpected",
1363 type
: "SequenceExpression"
1368 code
: "if((a, b)){}",
1369 output
: "if(a, b){}",
1370 options
: ["all", { enforceForSequenceExpressions
: true }],
1373 messageId
: "unexpected",
1374 type
: "SequenceExpression"
1379 code
: "while ((val = foo(), val < 10));",
1380 output
: "while (val = foo(), val < 10);",
1381 options
: ["all", { enforceForSequenceExpressions
: true }],
1384 messageId
: "unexpected",
1385 type
: "SequenceExpression"
1390 // ["all", { enforceForNewInMemberExpressions: true }]
1392 code
: "(new foo()).bar",
1393 output
: "new foo().bar",
1397 messageId
: "unexpected",
1398 type
: "NewExpression"
1403 code
: "(new foo()).bar",
1404 output
: "new foo().bar",
1405 options
: ["all", {}],
1408 messageId
: "unexpected",
1409 type
: "NewExpression"
1414 code
: "(new foo()).bar",
1415 output
: "new foo().bar",
1416 options
: ["all", { enforceForNewInMemberExpressions
: true }],
1419 messageId
: "unexpected",
1420 type
: "NewExpression"
1425 code
: "(new foo())[bar]",
1426 output
: "new foo()[bar]",
1427 options
: ["all", { enforceForNewInMemberExpressions
: true }],
1430 messageId
: "unexpected",
1431 type
: "NewExpression"
1436 code
: "(new foo.bar()).baz",
1437 output
: "new foo.bar().baz",
1438 options
: ["all", { enforceForNewInMemberExpressions
: true }],
1441 messageId
: "unexpected",
1442 type
: "NewExpression"
1447 // enforceForFunctionPrototypeMethods
1449 code
: "var foo = (function(){}).call()",
1450 output
: "var foo = function(){}.call()",
1454 messageId
: "unexpected",
1455 type
: "FunctionExpression"
1460 code
: "var foo = (function(){}.apply())",
1461 output
: "var foo = function(){}.apply()",
1465 messageId
: "unexpected",
1466 type
: "CallExpression"
1471 code
: "var foo = (function(){}).apply()",
1472 output
: "var foo = function(){}.apply()",
1473 options
: ["all", {}],
1476 messageId
: "unexpected",
1477 type
: "FunctionExpression"
1482 code
: "var foo = (function(){}.call())",
1483 output
: "var foo = function(){}.call()",
1484 options
: ["all", {}],
1487 messageId
: "unexpected",
1488 type
: "CallExpression"
1493 code
: "var foo = (function(){}).call()",
1494 output
: "var foo = function(){}.call()",
1495 options
: ["all", { enforceForFunctionPrototypeMethods
: true }],
1498 messageId
: "unexpected",
1499 type
: "FunctionExpression"
1504 code
: "var foo = (function(){}).apply()",
1505 output
: "var foo = function(){}.apply()",
1506 options
: ["all", { enforceForFunctionPrototypeMethods
: true }],
1509 messageId
: "unexpected",
1510 type
: "FunctionExpression"
1515 code
: "var foo = (function(){}.call())",
1516 output
: "var foo = function(){}.call()",
1517 options
: ["all", { enforceForFunctionPrototypeMethods
: true }],
1520 messageId
: "unexpected",
1521 type
: "CallExpression"
1526 code
: "var foo = (function(){}.apply())",
1527 output
: "var foo = function(){}.apply()",
1528 options
: ["all", { enforceForFunctionPrototypeMethods
: true }],
1531 messageId
: "unexpected",
1532 type
: "CallExpression"
1537 code
: "var foo = (function(){}.call)()", // removing these parens does not cause any conflicts with wrap-iife
1538 output
: "var foo = function(){}.call()",
1539 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1542 messageId
: "unexpected",
1543 type
: "MemberExpression"
1548 code
: "var foo = (function(){}.apply)()", // removing these parens does not cause any conflicts with wrap-iife
1549 output
: "var foo = function(){}.apply()",
1550 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1553 messageId
: "unexpected",
1554 type
: "MemberExpression"
1559 code
: "var foo = (function(){}).call",
1560 output
: "var foo = function(){}.call",
1561 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1564 messageId
: "unexpected",
1565 type
: "FunctionExpression"
1570 code
: "var foo = (function(){}.call)",
1571 output
: "var foo = function(){}.call",
1572 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1575 messageId
: "unexpected",
1576 type
: "MemberExpression"
1581 code
: "var foo = new (function(){}).call()",
1582 output
: "var foo = new function(){}.call()",
1583 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1586 messageId
: "unexpected",
1587 type
: "FunctionExpression"
1592 code
: "var foo = (new function(){}.call())",
1593 output
: "var foo = new function(){}.call()",
1594 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1597 messageId
: "unexpected",
1598 type
: "NewExpression"
1603 code
: "var foo = (function(){})[call]()",
1604 output
: "var foo = function(){}[call]()",
1605 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1608 messageId
: "unexpected",
1609 type
: "FunctionExpression"
1614 code
: "var foo = (function(){}[apply]())",
1615 output
: "var foo = function(){}[apply]()",
1616 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1619 messageId
: "unexpected",
1620 type
: "CallExpression"
1625 code
: "var foo = (function(){}).bar()",
1626 output
: "var foo = function(){}.bar()",
1627 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1630 messageId
: "unexpected",
1631 type
: "FunctionExpression"
1636 code
: "var foo = (function(){}.bar())",
1637 output
: "var foo = function(){}.bar()",
1638 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1641 messageId
: "unexpected",
1642 type
: "CallExpression"
1647 code
: "var foo = (function(){}).call.call()",
1648 output
: "var foo = function(){}.call.call()",
1649 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1652 messageId
: "unexpected",
1653 type
: "FunctionExpression"
1658 code
: "var foo = (function(){}.call.call())",
1659 output
: "var foo = function(){}.call.call()",
1660 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1663 messageId
: "unexpected",
1664 type
: "CallExpression"
1669 code
: "var foo = (call())",
1670 output
: "var foo = call()",
1671 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1674 messageId
: "unexpected",
1675 type
: "CallExpression"
1680 code
: "var foo = (apply())",
1681 output
: "var foo = apply()",
1682 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1685 messageId
: "unexpected",
1686 type
: "CallExpression"
1691 code
: "var foo = (bar).call()",
1692 output
: "var foo = bar.call()",
1693 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1696 messageId
: "unexpected",
1702 code
: "var foo = (bar.call())",
1703 output
: "var foo = bar.call()",
1704 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1707 messageId
: "unexpected",
1708 type
: "CallExpression"
1713 code
: "((() => {}).call())",
1714 output
: "(() => {}).call()",
1715 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1718 messageId
: "unexpected",
1719 type
: "CallExpression"
1724 code
: "var foo = function(){}.call((a.b))",
1725 output
: "var foo = function(){}.call(a.b)",
1726 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1729 messageId
: "unexpected",
1730 type
: "MemberExpression"
1735 code
: "var foo = function(){}.call((a).b)",
1736 output
: "var foo = function(){}.call(a.b)",
1737 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1740 messageId
: "unexpected",
1746 code
: "var foo = function(){}[('call')]()",
1747 output
: "var foo = function(){}['call']()",
1748 options
: ["all", { enforceForFunctionPrototypeMethods
: false }],
1751 messageId
: "unexpected",
1757 // https://github.com/eslint/eslint/issues/8175
1775 { parserOptions
: { ecmaVersion
: 2018 } }
1778 "let a = [...((b, c))]",
1779 "let a = [...(b, c)]",
1780 "SequenceExpression",
1784 "let a = {...((b, c))}",
1785 "let a = {...(b, c)}",
1786 "SequenceExpression",
1790 "let a = {...((b, c))}",
1791 "let a = {...(b, c)}",
1792 "SequenceExpression",
1794 { parserOptions
: { ecmaVersion
: 2018 } }
1797 "class A extends (B) {}",
1798 "class A extends B {}",
1803 "const A = class extends (B) {}",
1804 "const A = class extends B {}",
1809 "class A extends ((B=C)) {}",
1810 "class A extends (B=C) {}",
1811 "AssignmentExpression",
1815 "const A = class extends ((B=C)) {}",
1816 "const A = class extends (B=C) {}",
1817 "AssignmentExpression",
1821 "class A extends ((++foo)) {}",
1822 "class A extends (++foo) {}",
1827 "export default ((a, b))",
1828 "export default (a, b)",
1829 "SequenceExpression",
1831 { parserOptions
: { sourceType
: "module" } }
1834 "export default (() => {})",
1835 "export default () => {}",
1836 "ArrowFunctionExpression",
1838 { parserOptions
: { sourceType
: "module" } }
1841 "export default ((a, b) => a + b)",
1842 "export default (a, b) => a + b",
1843 "ArrowFunctionExpression",
1845 { parserOptions
: { sourceType
: "module" } }
1848 "export default (a => a)",
1849 "export default a => a",
1850 "ArrowFunctionExpression",
1852 { parserOptions
: { sourceType
: "module" } }
1855 "export default (a = b)",
1856 "export default a = b",
1857 "AssignmentExpression",
1859 { parserOptions
: { sourceType
: "module" } }
1862 "export default (a ? b : c)",
1863 "export default a ? b : c",
1864 "ConditionalExpression",
1866 { parserOptions
: { sourceType
: "module" } }
1869 "export default (a)",
1873 { parserOptions
: { sourceType
: "module" } }
1876 "for (foo of(bar));",
1877 "for (foo of bar);",
1882 "for ((foo) of bar);",
1883 "for (foo of bar);",
1888 "for (foo of (baz = bar));",
1889 "for (foo of baz = bar);",
1890 "AssignmentExpression",
1894 "function* f() { for (foo of (yield bar)); }",
1895 "function* f() { for (foo of yield bar); }",
1900 "for (foo of ((bar, baz)));",
1901 "for (foo of (bar, baz));",
1902 "SequenceExpression",
1906 "for ((foo)in bar);",
1907 "for (foo in bar);",
1912 "for ((foo['bar'])of baz);",
1913 "for (foo['bar']of baz);",
1918 "() => (({ foo: 1 }).foo)",
1919 "() => ({ foo: 1 }).foo",
1930 // ForStatement#init expression cannot start with `let[`, but it can start with `let` if it isn't followed by `[`
1938 "for ((let = 1);;);",
1940 "AssignmentExpression",
1944 "for ((let) = 1;;);",
1950 "for ((let = []);;);",
1951 "for (let = [];;);",
1952 "AssignmentExpression",
1956 "for ((let) = [];;);",
1957 "for (let = [];;);",
1968 "for ((let([]));;);",
1974 "for ((let())[a];;);",
1975 "for (let()[a];;);",
1980 "for ((let`[]`);;);",
1982 "TaggedTemplateExpression",
1998 "for ((let).a = 1;;);",
1999 "for (let.a = 1;;);",
2004 "for ((let).a[b];;);",
2005 "for (let.a[b];;);",
2010 "for ((let.a)[b];;);",
2011 "for (let.a[b];;);",
2016 "for ((let.a[b]);;);",
2017 "for (let.a[b];;);",
2028 "for (((let[a]));;);",
2029 "for ((let[a]);;);",
2034 "for (((let))[a];;);",
2035 "for ((let)[a];;);",
2040 "for (((let[a])).b;;);",
2041 "for ((let[a]).b;;);",
2046 "for (((let))[a].b;;);",
2047 "for ((let)[a].b;;);",
2052 "for (((let)[a]).b;;);",
2053 "for ((let)[a].b;;);",
2058 "for (((let[a]) = b);;);",
2059 "for ((let[a]) = b;;);",
2060 "AssignmentExpression",
2064 "for (((let)[a]) = b;;);",
2065 "for ((let)[a] = b;;);",
2070 "for (((let)[a] = b);;);",
2071 "for ((let)[a] = b;;);",
2072 "AssignmentExpression",
2076 "for ((Let[a]);;);",
2082 "for ((lett)[a];;);",
2088 // ForInStatement#left expression cannot start with `let[`, but it can start with `let` if it isn't followed by `[`
2090 "for ((let) in foo);",
2091 "for (let in foo);",
2096 "for ((let())[a] in foo);",
2097 "for (let()[a] in foo);",
2102 "for ((let.a) in foo);",
2103 "for (let.a in foo);",
2108 "for ((let).a in foo);",
2109 "for (let.a in foo);",
2114 "for ((let).a.b in foo);",
2115 "for (let.a.b in foo);",
2120 "for ((let).a[b] in foo);",
2121 "for (let.a[b] in foo);",
2126 "for ((let.a)[b] in foo);",
2127 "for (let.a[b] in foo);",
2132 "for ((let.a[b]) in foo);",
2133 "for (let.a[b] in foo);",
2138 "for (((let[a])) in foo);",
2139 "for ((let[a]) in foo);",
2144 "for (((let))[a] in foo);",
2145 "for ((let)[a] in foo);",
2150 "for (((let[a])).b in foo);",
2151 "for ((let[a]).b in foo);",
2156 "for (((let))[a].b in foo);",
2157 "for ((let)[a].b in foo);",
2162 "for (((let)[a]).b in foo);",
2163 "for ((let)[a].b in foo);",
2168 "for (((let[a]).b) in foo);",
2169 "for ((let[a]).b in foo);",
2174 "for ((Let[a]) in foo);",
2175 "for (Let[a] in foo);",
2180 "for ((lett)[a] in foo);",
2181 "for (lett[a] in foo);",
2186 // ForOfStatement#left expression cannot start with `let`
2188 "for (((let)) of foo);",
2189 "for ((let) of foo);",
2194 "for (((let)).a of foo);",
2195 "for ((let).a of foo);",
2200 "for (((let))[a] of foo);",
2201 "for ((let)[a] of foo);",
2206 "for (((let).a) of foo);",
2207 "for ((let).a of foo);",
2212 "for (((let[a]).b) of foo);",
2213 "for ((let[a]).b of foo);",
2218 "for (((let).a).b of foo);",
2219 "for ((let).a.b of foo);",
2224 "for (((let).a.b) of foo);",
2225 "for ((let).a.b of foo);",
2230 "for (((let.a).b) of foo);",
2231 "for ((let.a).b of foo);",
2236 "for (((let()).a) of foo);",
2237 "for ((let()).a of foo);",
2242 "for ((Let) of foo);",
2243 "for (Let of foo);",
2248 "for ((lett) of foo);",
2249 "for (lett of foo);",
2254 invalid("for (a in (b, c));", "for (a in b, c);", "SequenceExpression", null),
2267 invalid("let s = `${(v)}`", "let s = `${v}`", "Identifier"),
2268 invalid("let s = `${(a, b)}`", "let s = `${a, b}`", "SequenceExpression"),
2269 invalid("function foo(a = (b)) {}", "function foo(a = b) {}", "Identifier"),
2270 invalid("const bar = (a = (b)) => a", "const bar = (a = b) => a", "Identifier"),
2271 invalid("const [a = (b)] = []", "const [a = b] = []", "Identifier"),
2272 invalid("const {a = (b)} = {}", "const {a = b} = {}", "Identifier"),
2274 // LHS of assignments/Assignment targets
2275 invalid("(a) = b", "a = b", "Identifier"),
2276 invalid("(a.b) = c", "a.b = c", "MemberExpression"),
2277 invalid("(a) += b", "a += b", "Identifier"),
2278 invalid("(a.b) >>= c", "a.b >>= c", "MemberExpression"),
2279 invalid("[(a) = b] = []", "[a = b] = []", "Identifier"),
2280 invalid("[(a.b) = c] = []", "[a.b = c] = []", "MemberExpression"),
2281 invalid("({ a: (b) = c } = {})", "({ a: b = c } = {})", "Identifier"),
2282 invalid("({ a: (b.c) = d } = {})", "({ a: b.c = d } = {})", "MemberExpression"),
2283 invalid("[(a)] = []", "[a] = []", "Identifier"),
2284 invalid("[(a.b)] = []", "[a.b] = []", "MemberExpression"),
2285 invalid("[,(a),,] = []", "[,a,,] = []", "Identifier"),
2286 invalid("[...(a)] = []", "[...a] = []", "Identifier"),
2287 invalid("[...(a.b)] = []", "[...a.b] = []", "MemberExpression"),
2288 invalid("({ a: (b) } = {})", "({ a: b } = {})", "Identifier"),
2289 invalid("({ a: (b.c) } = {})", "({ a: b.c } = {})", "MemberExpression"),
2292 * TODO: Add these tests for RestElement's parenthesized arguments in object patterns when that becomes supported by Espree.
2294 * invalid("({ ...(a) } = {})", "({ ...a } = {})", "Identifier"),
2295 * invalid("({ ...(a.b) } = {})", "({ ...a.b } = {})", "MemberExpression")
2298 // https://github.com/eslint/eslint/issues/11706 (also in valid[])
2300 code
: "for ((a = (b in c)); ;);",
2301 output
: "for ((a = b in c); ;);",
2304 messageId
: "unexpected"
2309 code
: "for (let a = ((b in c) && (d in e)); ;);",
2310 output
: "for (let a = (b in c && d in e); ;);",
2311 errors
: Array(2).fill(
2313 messageId
: "unexpected"
2318 code
: "for (let a = ((b in c) in d); ;);",
2319 output
: "for (let a = (b in c in d); ;);",
2322 messageId
: "unexpected"
2327 code
: "for (let a = (b && (c in d)), e = (f in g); ;);",
2328 output
: "for (let a = (b && c in d), e = (f in g); ;);",
2331 messageId
: "unexpected"
2336 code
: "for (let a = (b + c), d = (e in f); ;);",
2337 output
: "for (let a = b + c, d = (e in f); ;);",
2340 messageId
: "unexpected"
2345 code
: "for (let a = [(b in c)]; ;);",
2346 output
: "for (let a = [b in c]; ;);",
2349 messageId
: "unexpected"
2354 code
: "for (let a = [b, (c in d)]; ;);",
2355 output
: "for (let a = [b, c in d]; ;);",
2358 messageId
: "unexpected"
2363 code
: "for (let a = ([b in c]); ;);",
2364 output
: "for (let a = [b in c]; ;);",
2367 messageId
: "unexpected"
2372 code
: "for (let a = ([b, c in d]); ;);",
2373 output
: "for (let a = [b, c in d]; ;);",
2376 messageId
: "unexpected"
2381 code
: "for ((a = [b in c]); ;);",
2382 output
: "for (a = [b in c]; ;);",
2385 messageId
: "unexpected"
2390 code
: "for (let a = [b && (c in d)]; ;);",
2391 output
: "for (let a = [b && c in d]; ;);",
2394 messageId
: "unexpected"
2399 code
: "for (let a = [(b && c in d)]; ;);",
2400 output
: "for (let a = [b && c in d]; ;);",
2403 messageId
: "unexpected"
2408 code
: "for (let a = ([b && c in d]); ;);",
2409 output
: "for (let a = [b && c in d]; ;);",
2412 messageId
: "unexpected"
2417 code
: "for ((a = [b && c in d]); ;);",
2418 output
: "for (a = [b && c in d]; ;);",
2421 messageId
: "unexpected"
2426 code
: "for ([(a in b)]; ;);",
2427 output
: "for ([a in b]; ;);",
2430 messageId
: "unexpected"
2435 code
: "for (([a in b]); ;);",
2436 output
: "for ([a in b]; ;);",
2439 messageId
: "unexpected"
2444 code
: "for (let a = [(b in c)], d = (e in f); ;);",
2445 output
: "for (let a = [b in c], d = (e in f); ;);",
2448 messageId
: "unexpected"
2453 code
: "for (let [a = (b in c)] = []; ;);",
2454 output
: "for (let [a = b in c] = []; ;);",
2457 messageId
: "unexpected"
2462 code
: "for (let [a = b && (c in d)] = []; ;);",
2463 output
: "for (let [a = b && c in d] = []; ;);",
2466 messageId
: "unexpected"
2471 code
: "for (let a = () => { (b in c) }; ;);",
2472 output
: "for (let a = () => { b in c }; ;);",
2475 messageId
: "unexpected"
2480 code
: "for (let a = () => { a && (b in c) }; ;);",
2481 output
: "for (let a = () => { a && b in c }; ;);",
2484 messageId
: "unexpected"
2489 code
: "for (let a = function () { (b in c) }; ;);",
2490 output
: "for (let a = function () { b in c }; ;);",
2493 messageId
: "unexpected"
2498 code
: "for (let a = { a: (b in c) }; ;);",
2499 output
: "for (let a = { a: b in c }; ;);",
2502 messageId
: "unexpected"
2507 code
: "for (let a = { a: b && (c in d) }; ;);",
2508 output
: "for (let a = { a: b && c in d }; ;);",
2511 messageId
: "unexpected"
2516 code
: "for (let { a = (b in c) } = {}; ;);",
2517 output
: "for (let { a = b in c } = {}; ;);",
2520 messageId
: "unexpected"
2525 code
: "for (let { a = b && (c in d) } = {}; ;);",
2526 output
: "for (let { a = b && c in d } = {}; ;);",
2529 messageId
: "unexpected"
2534 code
: "for (let { a: { b = c && (d in e) } } = {}; ;);",
2535 output
: "for (let { a: { b = c && d in e } } = {}; ;);",
2538 messageId
: "unexpected"
2543 code
: "for (let a = `${(a in b)}`; ;);",
2544 output
: "for (let a = `${a in b}`; ;);",
2547 messageId
: "unexpected"
2552 code
: "for (let a = `${a && (b in c)}`; ;);",
2553 output
: "for (let a = `${a && b in c}`; ;);",
2556 messageId
: "unexpected"
2561 code
: "for (let a = (b = (c in d)) => {}; ;);",
2562 output
: "for (let a = (b = c in d) => {}; ;);",
2565 messageId
: "unexpected"
2570 code
: "for (let a = (b = c && (d in e)) => {}; ;);",
2571 output
: "for (let a = (b = c && d in e) => {}; ;);",
2574 messageId
: "unexpected"
2579 code
: "for (let a = (b, c = d && (e in f)) => {}; ;);",
2580 output
: "for (let a = (b, c = d && e in f) => {}; ;);",
2583 messageId
: "unexpected"
2588 code
: "for (let a = function (b = c && (d in e)) {}; ;);",
2589 output
: "for (let a = function (b = c && d in e) {}; ;);",
2592 messageId
: "unexpected"
2597 code
: "for (let a = function (b, c = d && (e in f)) {}; ;);",
2598 output
: "for (let a = function (b, c = d && e in f) {}; ;);",
2601 messageId
: "unexpected"
2606 code
: "for (let a = b((c in d)); ;);",
2607 output
: "for (let a = b(c in d); ;);",
2610 messageId
: "unexpected"
2615 code
: "for (let a = b(c, (d in e)); ;);",
2616 output
: "for (let a = b(c, d in e); ;);",
2619 messageId
: "unexpected"
2624 code
: "for (let a = b(c && (d in e)); ;);",
2625 output
: "for (let a = b(c && d in e); ;);",
2628 messageId
: "unexpected"
2633 code
: "for (let a = b(c, d && (e in f)); ;);",
2634 output
: "for (let a = b(c, d && e in f); ;);",
2637 messageId
: "unexpected"
2642 code
: "for (let a = new b((c in d)); ;);",
2643 output
: "for (let a = new b(c in d); ;);",
2646 messageId
: "unexpected"
2651 code
: "for (let a = new b(c, (d in e)); ;);",
2652 output
: "for (let a = new b(c, d in e); ;);",
2655 messageId
: "unexpected"
2660 code
: "for (let a = new b(c && (d in e)); ;);",
2661 output
: "for (let a = new b(c && d in e); ;);",
2664 messageId
: "unexpected"
2669 code
: "for (let a = new b(c, d && (e in f)); ;);",
2670 output
: "for (let a = new b(c, d && e in f); ;);",
2673 messageId
: "unexpected"
2678 code
: "for (let a = b[(c in d)]; ;);",
2679 output
: "for (let a = b[c in d]; ;);",
2682 messageId
: "unexpected"
2687 code
: "for (let a = b[c && (d in e)]; ;);",
2688 output
: "for (let a = b[c && d in e]; ;);",
2691 messageId
: "unexpected"
2696 code
: "for (let a = b ? (c in d) : e; ;);",
2697 output
: "for (let a = b ? c in d : e; ;);",
2700 messageId
: "unexpected"
2705 code
: "for (let a = b ? c && (d in e) : f; ;);",
2706 output
: "for (let a = b ? c && d in e : f; ;);",
2709 messageId
: "unexpected"
2714 code
: "for (a ? b && (c in d) : e; ;);",
2715 output
: "for (a ? b && c in d : e; ;);",
2718 messageId
: "unexpected"
2723 code
: "for (let a = ((b in c)); ;);",
2724 output
: "for (let a = (b in c); ;);",
2727 messageId
: "unexpected"
2732 code
: "for (((a in b)); ;);",
2733 output
: "for ((a in b); ;);",
2736 messageId
: "unexpected"
2741 code
: "for (((a && b in c && d)); ;);",
2742 output
: "for ((a && b in c && d); ;);",
2745 messageId
: "unexpected"
2750 code
: "for (let a = (!(b in c)); ;);",
2751 output
: "for (let a = !(b in c); ;);",
2754 messageId
: "unexpected"
2759 code
: "for (let a = (!(b && c in d)); ;);",
2760 output
: "for (let a = !(b && c in d); ;);",
2763 messageId
: "unexpected"
2768 code
: "for (let a = !((b in c) && (d in e)); ;);",
2769 output
: "for (let a = !(b in c && d in e); ;);",
2770 errors
: Array(2).fill(
2772 messageId
: "unexpected"
2777 code
: "for (let a = (x && (b in c)), d = () => { for ((e in f); ;); for ((g in h); ;); }; ;); for((i in j); ;);",
2778 output
: "for (let a = (x && b in c), d = () => { for ((e in f); ;); for ((g in h); ;); }; ;); for((i in j); ;);",
2781 messageId
: "unexpected"
2786 code
: "for (let a = (b in c), d = () => { for ((x && (e in f)); ;); for ((g in h); ;); }; ;); for((i in j); ;);",
2787 output
: "for (let a = (b in c), d = () => { for ((x && e in f); ;); for ((g in h); ;); }; ;); for((i in j); ;);",
2790 messageId
: "unexpected"
2795 code
: "for (let a = (b in c), d = () => { for ((e in f); ;); for ((x && (g in h)); ;); }; ;); for((i in j); ;);",
2796 output
: "for (let a = (b in c), d = () => { for ((e in f); ;); for ((x && g in h); ;); }; ;); for((i in j); ;);",
2799 messageId
: "unexpected"
2804 code
: "for (let a = (b in c), d = () => { for ((e in f); ;); for ((g in h); ;); }; ;); for((x && (i in j)); ;);",
2805 output
: "for (let a = (b in c), d = () => { for ((e in f); ;); for ((g in h); ;); }; ;); for((x && i in j); ;);",
2808 messageId
: "unexpected"
2813 code
: "for (let a = (x && (b in c)), d = () => { for ((e in f); ;); for ((y && (g in h)); ;); }; ;); for((i in j); ;);",
2814 output
: "for (let a = (x && b in c), d = () => { for ((e in f); ;); for ((y && g in h); ;); }; ;); for((i in j); ;);",
2815 errors
: Array(2).fill(
2817 messageId
: "unexpected"
2822 code
: "for (let a = (x && (b in c)), d = () => { for ((y && (e in f)); ;); for ((z && (g in h)); ;); }; ;); for((w && (i in j)); ;);",
2823 output
: "for (let a = (x && b in c), d = () => { for ((y && e in f); ;); for ((z && g in h); ;); }; ;); for((w && i in j); ;);",
2824 errors
: Array(4).fill(
2826 messageId
: "unexpected"
2831 // https://github.com/eslint/eslint/issues/11706 regression tests (also in valid[])
2833 code
: "for (let a = (b); a > (b); a = (b)) a = (b); a = (b);",
2834 output
: "for (let a = b; a > b; a = b) a = b; a = b;",
2835 errors
: Array(5).fill(
2837 messageId
: "unexpected"
2842 code
: "for ((a = b); (a > b); (a = b)) (a = b); (a = b);",
2843 output
: "for (a = b; a > b; a = b) a = b; a = b;",
2844 errors
: Array(5).fill(
2846 messageId
: "unexpected"
2851 code
: "for (let a = b; a > (b); a = (b)) a = (b); a = (b);",
2852 output
: "for (let a = b; a > b; a = b) a = b; a = b;",
2853 errors
: Array(4).fill(
2855 messageId
: "unexpected"
2860 code
: "for (let a = b; (a > b); (a = b)) (a = b); (a = b);",
2861 output
: "for (let a = b; a > b; a = b) a = b; a = b;",
2862 errors
: Array(4).fill(
2864 messageId
: "unexpected"
2869 code
: "for (; a > (b); a = (b)) a = (b); a = (b);",
2870 output
: "for (; a > b; a = b) a = b; a = b;",
2871 errors
: Array(4).fill(
2873 messageId
: "unexpected"
2878 code
: "for (; (a > b); (a = b)) (a = b); (a = b);",
2879 output
: "for (; a > b; a = b) a = b; a = b;",
2880 errors
: Array(4).fill(
2882 messageId
: "unexpected"
2887 code
: "for (let a = (b); a = (b in c); a = (b in c)) a = (b in c); a = (b in c);",
2888 output
: "for (let a = b; a = b in c; a = b in c) a = b in c; a = b in c;",
2889 errors
: Array(5).fill(
2891 messageId
: "unexpected"
2896 code
: "for (let a = (b); (a in b); (a in b)) (a in b); (a in b);",
2897 output
: "for (let a = b; a in b; a in b) a in b; a in b;",
2898 errors
: Array(5).fill(
2900 messageId
: "unexpected"
2905 code
: "for (let a = b; a = (b in c); a = (b in c)) a = (b in c); a = (b in c);",
2906 output
: "for (let a = b; a = b in c; a = b in c) a = b in c; a = b in c;",
2907 errors
: Array(4).fill(
2909 messageId
: "unexpected"
2914 code
: "for (let a = b; (a in b); (a in b)) (a in b); (a in b);",
2915 output
: "for (let a = b; a in b; a in b) a in b; a in b;",
2916 errors
: Array(4).fill(
2918 messageId
: "unexpected"
2923 code
: "for (; a = (b in c); a = (b in c)) a = (b in c); a = (b in c);",
2924 output
: "for (; a = b in c; a = b in c) a = b in c; a = b in c;",
2925 errors
: Array(4).fill(
2927 messageId
: "unexpected"
2932 code
: "for (; (a in b); (a in b)) (a in b); (a in b);",
2933 output
: "for (; a in b; a in b) a in b; a in b;",
2934 errors
: Array(4).fill(
2936 messageId
: "unexpected"
2941 code
: "for (let a = (b + c), d = () => { for ((e + f); ;); for ((g + h); ;); }; ;); for((i + j); ;);",
2942 output
: "for (let a = b + c, d = () => { for (e + f; ;); for (g + h; ;); }; ;); for(i + j; ;);",
2943 errors
: Array(4).fill(
2945 messageId
: "unexpected"
2950 // import expressions
2956 { parserOptions
: { ecmaVersion
: 2020 } }
2959 "import((source = 'foo.js'))",
2960 "import(source = 'foo.js')",
2961 "AssignmentExpression",
2963 { parserOptions
: { ecmaVersion
: 2020 } }
2968 "SequenceExpression",
2970 { parserOptions
: { ecmaVersion
: 2020 } }
2973 // https://github.com/eslint/eslint/issues/12127
2975 code
: "[1, ((2, 3))];",
2976 output
: "[1, (2, 3)];",
2977 errors
: [{ messageId
: "unexpected" }]
2980 code
: "const foo = () => ((bar, baz));",
2981 output
: "const foo = () => (bar, baz);",
2982 errors
: [{ messageId
: "unexpected" }]
2985 code
: "foo = ((bar, baz));",
2986 output
: "foo = (bar, baz);",
2987 errors
: [{ messageId
: "unexpected" }]
2990 code
: "foo + ((bar + baz));",
2991 output
: "foo + (bar + baz);",
2992 errors
: [{ messageId
: "unexpected" }]
2995 code
: "((foo + bar)) + baz;",
2996 output
: "(foo + bar) + baz;",
2997 errors
: [{ messageId
: "unexpected" }]
3000 code
: "foo * ((bar + baz));",
3001 output
: "foo * (bar + baz);",
3002 errors
: [{ messageId
: "unexpected" }]
3005 code
: "((foo + bar)) * baz;",
3006 output
: "(foo + bar) * baz;",
3007 errors
: [{ messageId
: "unexpected" }]
3010 code
: "new A(((foo, bar)))",
3011 output
: "new A((foo, bar))",
3012 errors
: [{ messageId
: "unexpected" }]
3015 code
: "class A{ [((foo, bar))]() {} }",
3016 output
: "class A{ [(foo, bar)]() {} }",
3017 errors
: [{ messageId
: "unexpected" }]
3020 code
: "new ((A, B))()",
3021 output
: "new (A, B)()",
3022 errors
: [{ messageId
: "unexpected" }]
3025 code
: "((foo, bar)) ? bar : baz;",
3026 output
: "(foo, bar) ? bar : baz;",
3027 errors
: [{ messageId
: "unexpected" }]
3030 code
: "((f ? o : o)) ? bar : baz;",
3031 output
: "(f ? o : o) ? bar : baz;",
3032 errors
: [{ messageId
: "unexpected" }]
3035 code
: "((f = oo)) ? bar : baz;",
3036 output
: "(f = oo) ? bar : baz;",
3037 errors
: [{ messageId
: "unexpected" }]
3040 code
: "foo ? ((bar, baz)) : baz;",
3041 output
: "foo ? (bar, baz) : baz;",
3042 errors
: [{ messageId
: "unexpected" }]
3045 code
: "foo ? bar : ((bar, baz));",
3046 output
: "foo ? bar : (bar, baz);",
3047 errors
: [{ messageId
: "unexpected" }]
3050 code
: "function foo(bar = ((baz1, baz2))) {}",
3051 output
: "function foo(bar = (baz1, baz2)) {}",
3052 errors
: [{ messageId
: "unexpected" }]
3055 code
: "var foo = { bar: ((baz1, baz2)) };",
3056 output
: "var foo = { bar: (baz1, baz2) };",
3057 errors
: [{ messageId
: "unexpected" }]
3060 code
: "var foo = { [((bar1, bar2))]: baz };",
3061 output
: "var foo = { [(bar1, bar2)]: baz };",
3062 errors
: [{ messageId
: "unexpected" }]
3065 // adjacent tokens tests for division operator, comments and regular expressions
3066 invalid("a+/**/(/**/b)", "a+/**//**/b", "Identifier"),
3067 invalid("a+/**/(//\nb)", "a+/**///\nb", "Identifier"),
3068 invalid("a in(/**/b)", "a in/**/b", "Identifier"),
3069 invalid("a in(//\nb)", "a in//\nb", "Identifier"),
3070 invalid("a+(/**/b)", "a+/**/b", "Identifier"),
3071 invalid("a+/**/(b)", "a+/**/b", "Identifier"),
3072 invalid("a+(//\nb)", "a+//\nb", "Identifier"),
3073 invalid("a+//\n(b)", "a+//\nb", "Identifier"),
3074 invalid("a+(/^b$/)", "a+/^b$/", "Literal"),
3075 invalid("a/(/**/b)", "a/ /**/b", "Identifier"),
3076 invalid("a/(//\nb)", "a/ //\nb", "Identifier"),
3077 invalid("a/(/^b$/)", "a/ /^b$/", "Literal"),
3080 // Nullish coalescing
3082 code
: "var v = ((a ?? b)) || c",
3083 output
: "var v = (a ?? b) || c",
3084 parserOptions
: { ecmaVersion
: 2020 },
3085 errors
: [{ messageId
: "unexpected" }]
3088 code
: "var v = a ?? ((b || c))",
3089 output
: "var v = a ?? (b || c)",
3090 parserOptions
: { ecmaVersion
: 2020 },
3091 errors
: [{ messageId
: "unexpected" }]
3094 code
: "var v = ((a ?? b)) && c",
3095 output
: "var v = (a ?? b) && c",
3096 parserOptions
: { ecmaVersion
: 2020 },
3097 errors
: [{ messageId
: "unexpected" }]
3100 code
: "var v = a ?? ((b && c))",
3101 output
: "var v = a ?? (b && c)",
3102 parserOptions
: { ecmaVersion
: 2020 },
3103 errors
: [{ messageId
: "unexpected" }]
3106 code
: "var v = ((a || b)) ?? c",
3107 output
: "var v = (a || b) ?? c",
3108 parserOptions
: { ecmaVersion
: 2020 },
3109 errors
: [{ messageId
: "unexpected" }]
3112 code
: "var v = a || ((b ?? c))",
3113 output
: "var v = a || (b ?? c)",
3114 parserOptions
: { ecmaVersion
: 2020 },
3115 errors
: [{ messageId
: "unexpected" }]
3118 code
: "var v = ((a && b)) ?? c",
3119 output
: "var v = (a && b) ?? c",
3120 parserOptions
: { ecmaVersion
: 2020 },
3121 errors
: [{ messageId
: "unexpected" }]
3124 code
: "var v = a && ((b ?? c))",
3125 output
: "var v = a && (b ?? c)",
3126 parserOptions
: { ecmaVersion
: 2020 },
3127 errors
: [{ messageId
: "unexpected" }]
3130 code
: "var v = (a ?? b) ? b : c",
3131 output
: "var v = a ?? b ? b : c",
3132 parserOptions
: { ecmaVersion
: 2020 },
3133 errors
: [{ messageId
: "unexpected" }]
3136 code
: "var v = (a | b) ?? c | d",
3137 output
: "var v = a | b ?? c | d",
3138 parserOptions
: { ecmaVersion
: 2020 },
3139 errors
: [{ messageId
: "unexpected" }]
3142 code
: "var v = a | b ?? (c | d)",
3143 output
: "var v = a | b ?? c | d",
3144 parserOptions
: { ecmaVersion
: 2020 },
3145 errors
: [{ messageId
: "unexpected" }]
3148 // Optional chaining
3150 code
: "var v = (obj?.aaa)?.aaa",
3151 output
: "var v = obj?.aaa?.aaa",
3152 parserOptions
: { ecmaVersion
: 2020 },
3153 errors
: [{ messageId
: "unexpected" }]
3156 code
: "var v = (obj.aaa)?.aaa",
3157 output
: "var v = obj.aaa?.aaa",
3158 parserOptions
: { ecmaVersion
: 2020 },
3159 errors
: [{ messageId
: "unexpected" }]
3162 code
: "var foo = (function(){})?.call()",
3163 output
: "var foo = function(){}?.call()",
3164 options
: ["all", { enforceForFunctionPrototypeMethods
: true }],
3165 parserOptions
: { ecmaVersion
: 2020 },
3166 errors
: [{ messageId
: "unexpected" }]
3169 code
: "var foo = (function(){}?.call())",
3170 output
: "var foo = function(){}?.call()",
3171 options
: ["all", { enforceForFunctionPrototypeMethods
: true }],
3172 parserOptions
: { ecmaVersion
: 2020 },
3173 errors
: [{ messageId
: "unexpected" }]