Skip to content

Conversation

@jasminexie
Copy link
Contributor

This PR should fix #88, where a division expression subtracted from zero is incorrectly reduced. Apparently reducer.js does not reduce division expressions if the denominator cannot be reduced to a value, so similar multiplication tests pass while division did not.

Copy link
Collaborator

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need more tests

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests when 0 is other value

@jasminexie
Copy link
Contributor Author

jasminexie commented Oct 1, 2019

The changes I made affected only the '0 - something => -something' case, so correct me if I'm wrong please but I don't see a point of adding tests when 0 is another value. Tests like value - unreducable division expression should already be covered by value - expression and division expression tests. I have add another one if you think it hasn't been sufficiently tested.

The '0 - something => -something' case currently has the following tests:

  • 0 - value
  • 0 - calc expression
  • 0 - unreducable division expression (in this PR)

I've added the cases:

  • 0 - unreducable addition/subtraction expression
  • 0 - unreducable multiplication expression

To test the actual code I changed, the expressions on the right side should not be reducable, and they should preserve the node. One example is calc( 0 - (100vw - 10px) * 2px ). If any of these expressions are reducable, the test would implicitly fall back to the 0 - value state, which already has a test case. I've edited the PR, please tell me what you think.

@alexander-akait
Copy link
Collaborator

/cc @ben-eb can you look on this?

@ben-eb
Copy link
Member

ben-eb commented Oct 1, 2019

I don't have much to add really, I wasn't involved with the more recent refactoring. Thanks for the contribution, @jasminexie 😃

@alexander-akait alexander-akait merged commit 6260789 into postcss:master Oct 1, 2019
@alexander-akait
Copy link
Collaborator

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect calc reduction of 0 - (A - B) / C

3 participants