Skip to content

Commit

Permalink
Fix: prefer-exponentiation-operator invalid autofix with await (#13924)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Dec 18, 2020
1 parent dc76911 commit ab240d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rules/prefer-exponentiation-operator.js
Expand Up @@ -30,6 +30,7 @@ function doesBaseNeedParens(base) {
astUtils.getPrecedence(base) <= PRECEDENCE_OF_EXPONENTIATION_EXPR ||

// An unary operator cannot be used immediately before an exponentiation expression
base.type === "AwaitExpression" ||
base.type === "UnaryExpression"
);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/prefer-exponentiation-operator.js
Expand Up @@ -218,6 +218,8 @@ ruleTester.run("prefer-exponentiation-operator", rule, {
invalid("Math.pow(a, -b)", "a**-b"),
invalid("Math.pow(-2, 3)", "(-2)**3"),
invalid("Math.pow(2, -3)", "2**-3"),
invalid("async () => Math.pow(await a, b)", "async () => (await a)**b"),
invalid("async () => Math.pow(a, await b)", "async () => a**await b"),

// base and exponent with a lower precedence
invalid("Math.pow(a * b, c)", "(a * b)**c"),
Expand Down

0 comments on commit ab240d4

Please sign in to comment.