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: remove comments before parsing calc value #171

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ludofischer
Copy link
Collaborator

Since 8.4.6, PostCSS stopped removing comments in declarations,
because it sometimes produced the wrong CSS.
postcss-calc can remove the comments safely because it only
modifies the contents of function nodes.

Since 8.4.6, PostCSS stopped removing comments in declarations,
because it sometimes produced the wrong CSS.
postcss-calc can remove the comments safely because it only
modifies the contents of function nodes.
for (const node of nodes) {
if (node.type !== 'comment') {
if (node.type === 'function') {
node.nodes = removeComments(node.nodes);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suppose there is no risk of stack overflow as people won't nest function that deeply.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can remove useful comments...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The issue PostCSS had was with comments that replaced spaces:

margin: 10px/* comment */20px;

that would become

margin:10px20px;

I've had a look at postcss-discard-comment, and interestingly because it looks at node.raws, it would repair the CSS value that PostCSS parssed incorrectly! It's also true that discard-comments does not remove !important comments, so maybe to get comment removal right we would end up duplicating too much logic from postcss-discard-comments

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't mind this improvement, just weird regression and parsing... Let's merge

@ludofischer ludofischer marked this pull request as ready for review February 5, 2022 19:02
@ludofischer
Copy link
Collaborator Author

For context, this is the discussion for the PostCSS change postcss/postcss#1703

@ludofischer ludofischer marked this pull request as draft February 5, 2022 19:31
@ludofischer ludofischer mentioned this pull request Feb 5, 2022
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.

None yet

2 participants