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

Fix simplification of calc() expressions #3147

Closed
echocrow opened this issue Sep 14, 2021 · 1 comment
Closed

Fix simplification of calc() expressions #3147

echocrow opened this issue Sep 14, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@echocrow
Copy link

Dart Sass 1.40.0 introduced a new feature that simplifies calc() expressions. Unfortunately, at least part of that simplification logic seems to yield incorrect results.

Example input:

.example {
  opacity: calc(1 - (1 - var(--my-var, 0)));
}

Expected output:

.example {
  opacity: calc(1 - 1 + var(--my-var));
}
// or ideally:
.example {
  opacity: var(--my-var);
}

Actual output (as of v1.40.0 – v1.40.1):

.example {
  opacity: calc(1 - 1 - var(--my-var));
}

Seems like there is missing logic around resolving brackets () in the subtrahend (right-hand side of a substraction); here, + and - may need to be flipped.
For example, a - (b - c) can be simplified to a - b + c, but must not be simplified to a - b - c.

@nex3 nex3 transferred this issue from sass/dart-sass Sep 14, 2021
@nex3 nex3 self-assigned this Sep 14, 2021
@nex3 nex3 added the bug Something isn't working label Sep 14, 2021
nex3 added a commit that referenced this issue Sep 14, 2021
`a - (b - c)` should preserve the parentheses of the right-hand
operand, but we weren't doing so.

See #3147
nex3 added a commit that referenced this issue Sep 14, 2021
`a - (b - c)` and `a - (b + c)` should preserve the parentheses of the
right-hand operand, but we weren't doing so.

See #3147
nex3 added a commit to sass/sass-spec that referenced this issue Sep 14, 2021
nex3 added a commit to sass/dart-sass that referenced this issue Sep 14, 2021
nex3 added a commit that referenced this issue Sep 14, 2021
`a - (b - c)` and `a - (b + c)` should preserve the parentheses of the
right-hand operand, but we weren't doing so.

See #3147
nex3 added a commit to sass/sass-spec that referenced this issue Sep 14, 2021
nex3 added a commit to sass/dart-sass that referenced this issue Sep 14, 2021
@nex3 nex3 closed this as completed Sep 14, 2021
@nex3
Copy link
Contributor

nex3 commented Sep 14, 2021

Thanks for the report!

mirisuzanne pushed a commit that referenced this issue Feb 10, 2022
`a - (b - c)` and `a - (b + c)` should preserve the parentheses of the
right-hand operand, but we weren't doing so.

See #3147
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants