Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in v7.0.2 when combing calc with CSS Custom Properties #103

Closed
wessberg opened this issue Mar 9, 2020 · 4 comments
Closed

Regression in v7.0.2 when combing calc with CSS Custom Properties #103

wessberg opened this issue Mar 9, 2020 · 4 comments
Labels

Comments

@wessberg
Copy link

wessberg commented Mar 9, 2020

Consider the following CSS:

:host {
    --a: calc(2 * var(--b) - (1 * var(--b)));
}

With postcss-calc v7.0.1, the value of --a will be unchanged which, since var(--b is a dynamic value that may change.

However, in v7.0.2, it will turn into:

:host {
    --a: 1;
}

This is untentional since it discards the var(--b) expressions entirely from the resulting property value.
This error can be reproduced here when checking the postcss-calc checkbox in the left-hand menu.

@Semigradsky Semigradsky added the bug label Mar 9, 2020
@while0pass
Copy link

After transition from v7.0.0 to v7.0.[12], postcss-calc got a regression bug. Now I get the following error, though it has never been raised before:

:root {
  /* ... */
  --main-gap-mobile: calc((100vw - var(--main-width-mobile)) / 2);
}
JisonParserError in plugin "gulp-postcss"
Message:
    Parse error on line 1:
- calc((100v...
--^
Expecting "ADD", "SUB", "LENGTH", "ANGLE", "TIME", "FREQ", "RES", "UNKNOWN_DIMENSION", "EMS", "EXS", "CHS", "REMS", "VHS", "VWS", "VMINS", "VMAXS", "PERCENTAGE", "NUMBER", "dimension", got unexpected "CALC"
Details:
    hash: [object Object]
    fileName: ./src/styles/main.css
    domainEmitter: [object Object]
    domain: [object Object]
    domainThrown: false

Stack:
JisonParserError: Parse error on line 1:
- calc((100v...
--^
Expecting "ADD", "SUB", "LENGTH", "ANGLE", "TIME", "FREQ", "RES", "UNKNOWN_DIMENSION", "EMS", "EXS", "CHS", "REMS", "VHS", "VWS", "VMINS", "VMAXS", "PERCENTAGE", "NUMBER", "dimension", got unexpected "CALC"
    at Parser.parseError (./node_modules/postcss-calc/dist/parser.js:1200:15)
    at Parser.parse (./node_modules/postcss-calc/dist/parser.js:1716:30)
    at ./node_modules/postcss-calc/dist/lib/transform.js:33:30
    at walk (./node_modules/postcss-calc/node_modules/postcss-value-parser/lib/walk.js:7:16)
    at ValueParser.walk (./node_modules/postcss-calc/node_modules/postcss-value-parser/lib/index.js:18:3)
    at transformValue (./node_modules/postcss-calc/dist/lib/transform.js:24:50)
    at _default (./node_modules/postcss-calc/dist/lib/transform.js:66:100)
    at ./node_modules/postcss-calc/dist/index.js:27:32
    at ./node_modules/postcss-import/node_modules/postcss/lib/container.js:144:26
    at Rule.each (./node_modules/postcss-import/node_modules/postcss/lib/container.js:110:22)```

@hanse
Copy link

hanse commented Apr 16, 2020

We're using create-react-app and experienced similar regressions with v7.0.2.

Our CSS

.event::before {
  left: calc(
    var(--icon-size) / 2 - var(--border-width) / 2
  );
}

used to compile to (v7.0.1)

.event:before {
  left: 11px;
  left: calc(
    var(--icon-size) / 2 - var(--border-width) / 2
  );
}

but with v7.0.2 it compiles to:

.event:before {
  left: 11px;
  left: calc(
    var(--icon-size) - var(--border-width)
  );
}

(the / 2 division is gone)

@vishaltelangre
Copy link

I experienced a similar issue. My postcss-calc version is 7.0.2 as well.

It seems to be completely overlooking the subtraction and division operations.

transform: translateZ(calc(0px - var(--thickness) / 2));
/* compiles to */
transform: translateZ(calc(var(--thickness) / 2));

/* Similarly, */
transform: translateX(calc(var(--width) / 2 - var(--thickness) / 2 - var(--pagesOffset)));
/* compiles to */
transform: translateX(calc(var(--width) - var(--thickness) - var(--pagesOffset)));

As a workaround, I used multiplication which seems to work as intended.

transform: translateZ(calc(0px - var(--thickness) / 2));
/* I rewritten this to */
transform: translateZ(calc((var(--thickness) / 2) * -1));

/* Also, I changed manually */
transform: translateX(calc(var(--width) / 2 - var(--thickness) / 2 - var(--pagesOffset)));
/* to */
transform: translateX(calc((0.5 * var(--width)) - (0.5 * var(--thickness)) - var(--pagesOffset)));

@ludofischer
Copy link
Collaborator

All the examples produce the expected output in 8.2. This was probably a duplicate of #107 fixed in 7.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants