Skip to content

Commit

Permalink
fix: incorrect reduction of subtraction from zero (postcss#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasminexie committed Sep 28, 2019
1 parent 29ff26e commit 5338ae3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ test(
'calc(-1px + -1em)',
);

test(
'should reduce substracted division expression from zero',
testValue,
'calc( 0 - (100vw - 10px) / 2 )',
'calc((-100vw - -10px)/2)',
);

test(
'should reduce nested expression',
testValue,
Expand Down
8 changes: 6 additions & 2 deletions src/lib/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ function flipValue(node) {
if (isValueType(node.type)) {
node.value = -node.value;
} else if (node.type === 'MathExpression') {
node.left = flipValue(node.left);
node.right = flipValue(node.right);
if (node.operator === '*' || node.operator === '/') {
node.left = flipValue(node.left);
} else {
node.left = flipValue(node.left);
node.right = flipValue(node.right);
}
}

return node;
Expand Down

0 comments on commit 5338ae3

Please sign in to comment.