Skip to content

Commit fbd7c13

Browse files
authoredJan 27, 2017
Update: ensure operator-assignment handles exponentiation operators (#7970)
1 parent c5066ce commit fbd7c13

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
 

‎lib/rules/operator-assignment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function isCommutativeOperatorWithShorthand(operator) {
2727
* a shorthand form.
2828
*/
2929
function isNonCommutativeOperatorWithShorthand(operator) {
30-
return ["+", "-", "/", "%", "<<", ">>", ">>>"].indexOf(operator) >= 0;
30+
return ["+", "-", "/", "%", "<<", ">>", ">>>", "**"].indexOf(operator) >= 0;
3131
}
3232

3333
//------------------------------------------------------------------------------

‎tests/lib/rules/operator-assignment.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const rule = require("../../../lib/rules/operator-assignment"),
1616
// Tests
1717
//------------------------------------------------------------------------------
1818

19-
const ruleTester = new RuleTester();
19+
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 7 } });
2020

2121
const EXPECTED_OPERATOR_ASSIGNMENT = [{ message: "Assignment can be replaced with operator assignment.", type: "AssignmentExpression" }];
2222
const UNEXPECTED_OPERATOR_ASSIGNMENT = [{ message: "Unexpected operator assignment shorthand.", type: "AssignmentExpression" }];
@@ -40,6 +40,7 @@ ruleTester.run("operator-assignment", rule, {
4040
"x >>= x >> y",
4141
"x >>>= y",
4242
"x &= y",
43+
"x **= y",
4344
"x ^= y ^ z",
4445
"x |= x | y",
4546
"x = x && y",
@@ -66,6 +67,11 @@ ruleTester.run("operator-assignment", rule, {
6667
code: "x = x + y",
6768
options: ["never"]
6869
},
70+
{
71+
code: "x = x ** y",
72+
options: ["never"]
73+
},
74+
"x = y ** x",
6975
"x = x < y",
7076
"x = x > y",
7177
"x = x <= y",
@@ -184,6 +190,15 @@ ruleTester.run("operator-assignment", rule, {
184190
output: "(foo.bar) = (foo.bar) ^ ((((((((((((((((baz))))))))))))))))",
185191
options: ["never"],
186192
errors: UNEXPECTED_OPERATOR_ASSIGNMENT
193+
}, {
194+
code: "foo = foo ** bar",
195+
output: "foo **= bar",
196+
errors: EXPECTED_OPERATOR_ASSIGNMENT
197+
}, {
198+
code: "foo **= bar",
199+
output: "foo = foo ** bar",
200+
options: ["never"],
201+
errors: UNEXPECTED_OPERATOR_ASSIGNMENT
187202
}]
188203

189204
});

0 commit comments

Comments
 (0)