-
Notifications
You must be signed in to change notification settings - Fork 33
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
base: master
Are you sure you want to change the base?
Conversation
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
For context, this is the discussion for the PostCSS change postcss/postcss#1703 |
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.