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: preserve calc when extra parentheses are used #187

Merged
merged 2 commits into from May 5, 2023
Merged

fix: preserve calc when extra parentheses are used #187

merged 2 commits into from May 5, 2023

Conversation

tannerdolby
Copy link
Contributor

Fixes #181

This fix allows calc to be printed when calc((...)) is encountered. The bug occurred because the AST was 'type: 'ParenthesizedExpression' which didn't satisfy the shouldPrintCalc check in stringifier.js. The test I added piggy backs on the work started in #180. All the original tests pass with this addition, but I am new to the codebase so I very well could be missing some things.

cssnano/cssnano#1490 (comment)

TODOs:

  • remove the extra parentheses e.g. calc((var(--foo) / var(--bar)) should become calc(var(--foo) / var(--bar)
  • preserve the space between the division operator e.g. calc((var(--foo) / var(--bar)) should preserve the space if that is intended/expected behavior.

@ludofischer
Copy link
Collaborator

Good job! I think we're very close to being able to simplify the external parentheses completely. Regarding the second TODO, do you think there's a reason to preserve the space around the division operator?

@tannerdolby
Copy link
Contributor Author

tannerdolby commented May 5, 2023

@ludofischer Thank you! After implementing your suggested changes, it seems we're very close to completely fixing the bug. In regards to the second TODO, I don't think there is any reason to preserve the space around the division operator. Especially because that space isn't preserved in other tests within test/index.js so I think it makes sense to keep things as is.

@ludofischer ludofischer merged commit 18bb47b into postcss:master May 5, 2023
4 checks passed
@tannerdolby tannerdolby deleted the patch-181 branch May 5, 2023 18:26
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.

[Bug]: calc disappears if extra pair of parentheses around the argument
3 participants