postcss / postcss-calc

PostCSS plugin to reduce calc()
MIT License
212 stars 34 forks source link

wrong/insufficient reduction #122

Closed csr632 closed 3 years ago

csr632 commented 3 years ago

These test cases fail with postcss-calc@7.0.4:


test(
  'should reduce additions and subtractions (6)',
  testValue,
  'calc(1px - (2em + 4vh + 3%))',
  'calc(1px - 2em - 4vh - 3%)',
// actual: calc(1px - 2em + 4vh - 3%)
);

test(
  'should reduce additions and subtractions (7)',
  testValue,
  'calc(0px - (24px - (var(--a) - var(--b)) / 2 + var(--c)))',
  'calc(-24px + var(--a)/2 - var(--b)/2 - var(--c))',
// actual: calc(0px - 24px - (var(--a) - var(--b))/2 - var(--c))
);

test(
  'should reduce additions and subtractions (8)',
  testValue,
  'calc(1px + (2em + (3vh + 4px)))',
  'calc(5px + 2em + 3vh)',
// actual: calc(1px + 2em + 3vh + 4px)
);

test(
  'should reduce additions and subtractions (9)',
  testValue,
  'calc(1px - (2em + 4px - 6vh) / 2)',
  'calc(-1px - 1em + 3vh)',
// actual: calc(1px - (2em + 4px - 6vh)/2)
);

test(
  'should reduce multiplication before reducing additions',
  testValue,
  'calc(((var(--a) + 4px) * 2) * 2 + 4px)',
  'calc(var(--a)*2*2 + 20px)',
// actual: calc((var(--a) + 4px)*2*2 + 4px)
);

test(
  'should reduce division before reducing additions',
  testValue,
  'calc(((var(--a) + 4px) / 2) / 2 + 4px)',
  'calc(var(--a)/2/2 + 5px)',
// actual: calc((var(--a) + 4px)/2/2 + 4px)
);
alexander-akait commented 3 years ago

Do you fix it in https://github.com/postcss/postcss-calc/pull/121?

csr632 commented 3 years ago

Do you fix it in #121?

Yes, I try to demonstrate the issue here :)