Wrap modulo operation in parens inside additive operation (#4413)
This commit is contained in:
1 parent
c77f1e5987
commit
bafa76f613
4 files changed
+28
No files matched your search
@@ -298,6 +298,10 @@ const equalityOperators = {
|
||||
"===": true,
|
||||
"!==": true
|
||||
};
|
||||
const additiveOperators = {
|
||||
"+": true,
|
||||
"-": true
|
||||
};
|
||||
const multiplicativeOperators = {
|
||||
"*": true,
|
||||
"/": true,
|
||||
@@ -311,6 +315,11 @@ const bitshiftOperators = {
|
||||
|
||||
function shouldFlatten(parentOp, nodeOp) {
|
||||
if (getPrecedence(nodeOp) !== getPrecedence(parentOp)) {
|
||||
// x + y % z --> (x + y) % z
|
||||
if (nodeOp === "%" && !additiveOperators[parentOp]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -259,6 +259,10 @@ function needsParens(path, options) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pp < np && no === "%") {
|
||||
return !util.shouldFlatten(po, no);
|
||||
}
|
||||
|
||||
// Add parenthesis when working with binary operators
|
||||
// It's not stricly needed but helps with code understanding
|
||||
if (util.isBitwiseOperator(po)) {
|
||||
|
||||
@@ -14,6 +14,11 @@ mantissa = ((b[2] & 0x7f) << 16) | (b[1] << 8) | b[0];
|
||||
2 / 3 * 10 / 2 + 2;
|
||||
const rotateX = ((RANGE / rect.height) * refY - RANGE / 2) * getXMultiplication(rect.width);
|
||||
const rotateY = ((RANGE / rect.width) * refX - RANGE / 2) * getYMultiplication(rect.width);
|
||||
|
||||
a % 10 - 5;
|
||||
a * b % 10;
|
||||
a % 10 > 5;
|
||||
a % 10 == 0;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
const result = (a + b) >>> 1;
|
||||
var sizeIndex = ((index - 1) >>> level) & MASK;
|
||||
@@ -32,4 +37,9 @@ const rotateX =
|
||||
const rotateY =
|
||||
((RANGE / rect.width) * refX - RANGE / 2) * getYMultiplication(rect.width);
|
||||
|
||||
(a % 10) - 5;
|
||||
(a * b) % 10;
|
||||
a % 10 > 5;
|
||||
a % 10 == 0;
|
||||
|
||||
`;
|
||||
@@ -11,3 +11,8 @@ mantissa = ((b[2] & 0x7f) << 16) | (b[1] << 8) | b[0];
|
||||
2 / 3 * 10 / 2 + 2;
|
||||
const rotateX = ((RANGE / rect.height) * refY - RANGE / 2) * getXMultiplication(rect.width);
|
||||
const rotateY = ((RANGE / rect.width) * refX - RANGE / 2) * getYMultiplication(rect.width);
|
||||
|
||||
a % 10 - 5;
|
||||
a * b % 10;
|
||||
a % 10 > 5;
|
||||
a % 10 == 0;
|
||||
Reference in new issue
Block a user