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

Custom visitor transformation doesn't get minified #554

Open
webschik opened this issue Aug 1, 2023 · 4 comments
Open

Custom visitor transformation doesn't get minified #554

webschik opened this issue Aug 1, 2023 · 4 comments

Comments

@webschik
Copy link

webschik commented Aug 1, 2023

Hi,

First of all, thank you for the amazing tool!

During my attempt to implement a customer visitor to inline "static" CSS variables, similar to the behaviour of postcss-custom-properties plugin, I found that the result of custom visitor doesn't get minified correctly:

Input

.foo {
  width: calc(20 * var(--grid));
}
// visitor
{
  Variable(variable) {
    if (variable.name.ident === '--grid') {
      return {type: 'length', value: {unit: 'rem', value: 0.25}}
    }
  }
}

Actual output

.foo{width:calc(20*.25rem)}

Expected output

.foo{width:5rem}

Playground link

@webschik
Copy link
Author

webschik commented Aug 1, 2023

Btw, I found another issue related to the value replacement, please check this example.

Maybe it's not a bug, but may incorrect understanding of how the transformation should work...
Please, help me to figure our what goes wrong, when you have time.

@devongovett
Copy link
Member

calc simplification happens during the initial parse phase, which is before custom visitors run. Currently there is not an additional simplification pass done after transforms, resulting in the output you see here.

@webschik
Copy link
Author

Thanks @devongovett!
Is this behavior strictly defined and won't change in the future?
And could you please check the 2nd issue, this example, as well?

@robertmoura
Copy link

robertmoura commented Sep 5, 2023

I ran into that second bug as well. I've created an issue here: #579

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

No branches or pull requests

3 participants