Skip to content

Commit 555c128

Browse files
authored
Fix: false positive with await and ** in no-extra-parens (fixes #12739) (#13923)
1 parent d93c935 commit 555c128

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/rules/no-extra-parens.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ module.exports = {
511511

512512
if (!shouldSkipLeft && hasExcessParens(node.left)) {
513513
if (
514-
!(node.left.type === "UnaryExpression" && isExponentiation) &&
514+
!(["AwaitExpression", "UnaryExpression"].includes(node.left.type) && isExponentiation) &&
515515
!astUtils.isMixedLogicalAndCoalesceExpressions(node.left, node) &&
516516
(leftPrecedence > prec || (leftPrecedence === prec && !isExponentiation)) ||
517517
isParenthesisedTwice(node.left)

tests/lib/rules/no-extra-parens.js

+5
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ ruleTester.run("no-extra-parens", rule, {
377377
"async function a() { await (a + await b) }",
378378
"async function a() { (await a)() }",
379379
"async function a() { new (await a) }",
380+
"async function a() { await (a ** b) }",
381+
"async function a() { (await a) ** b }",
382+
380383
{ code: "(foo instanceof bar) instanceof baz", options: ["all", { nestedBinaryExpressions: false }] },
381384
{ code: "(foo in bar) in baz", options: ["all", { nestedBinaryExpressions: false }] },
382385
{ code: "(foo + bar) + baz", options: ["all", { nestedBinaryExpressions: false }] },
@@ -1187,6 +1190,8 @@ ruleTester.run("no-extra-parens", rule, {
11871190
invalid("async function a() { await (+a); }", "async function a() { await +a; }", "UnaryExpression", null),
11881191
invalid("async function a() { +(await a); }", "async function a() { +await a; }", "AwaitExpression", null),
11891192
invalid("async function a() { await ((a,b)); }", "async function a() { await (a,b); }", "SequenceExpression", null),
1193+
invalid("async function a() { a ** (await b); }", "async function a() { a ** await b; }", "AwaitExpression", null),
1194+
11901195
invalid("(foo) instanceof bar", "foo instanceof bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }),
11911196
invalid("(foo) in bar", "foo in bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }),
11921197
invalid("(foo) + bar", "foo + bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }),

0 commit comments

Comments
 (0)