Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: prefer-exponentiation-operator invalid autofix with await #13924

Merged
merged 1 commit into from Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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