Skip to content

Regression from v0.1.10 - 'nested' vars not being processed #209

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

Closed
spacedawwwg opened this issue Mar 15, 2021 · 10 comments
Closed

Regression from v0.1.10 - 'nested' vars not being processed #209

spacedawwwg opened this issue Mar 15, 2021 · 10 comments

Comments

@spacedawwwg
Copy link

In v0.1.10, you could use nested vars that would be parsed before being set to a mixin, e.g:

:root {
  --original-var: 4px;
  --nested-var: calc(2 * var(--original-var));
}
.class-name {
  @mixin mixinName var(--nested-var);
}

nested var would be resolved in the mixin as calc(2 * 4px)

As of v2, this no longer works and is instead simply passed through as calc(2 * var(--original-var)) (i.e not resolving the original var)

@Scrum
Copy link
Owner

Scrum commented Mar 15, 2021

@spacedawwwg Thank, i'll check if it's a good catch.

@Scrum
Copy link
Owner

Scrum commented Mar 15, 2021

@spacedawwwg No, this is unfortunately not a catch, I created an example and it passes the tests. You can make adjustments to the test so that it fails, or create an example that clearly falls with your result.

https://github.com/Scrum/postcss-at-rules-variables/pull/210/files

@spacedawwwg
Copy link
Author

Oh, Ok - I only popped the example together based on my scenario but this is very weird then as I've had to revert back to back to v0.1.10 to get this working in my project. I wonder if it's 1) a config issue or 2) some kind of clash with another plugin

I'll do some more investigating and report back

@spacedawwwg
Copy link
Author

spacedawwwg commented Mar 16, 2021

I found the issue - It requires that any CSS vars used need to be included before they used now.

I wonder if this is a change in how PostCSS 8 works now?

@Scrum
Copy link
Owner

Scrum commented Mar 16, 2021

I wonder if this is a change in how PostCSS 8 works now?

I don't think my plugin and test uses PostCSS 8

@spacedawwwg
Copy link
Author

spacedawwwg commented Mar 16, 2021

@Scrum Sorry, I should have been more specific "included before they used" using the postcss-import plugin

Before hand the plugin used variables defined anywhere in the CSS (as if all the CSS had been previously parsed)

@Scrum
Copy link
Owner

Scrum commented Mar 17, 2021

I have created an example, please supplement it to reproduce your situation.

@spacedawwwg
Copy link
Author

@Scrum
Copy link
Owner

Scrum commented Mar 19, 2021

This is due to the fact that the ad comes after the definition. Postscss makes only one iteration from top to bottom, in your case you will have to do multiple iterations when declaring a new value.

It seems to me that it is not entirely correct to make definitions after the declaration.

Scrum added a commit that referenced this issue Mar 19, 2021
@Scrum
Copy link
Owner

Scrum commented Mar 19, 2021

now you can use the option declarationbywalk to find all declared variable declarations

@Scrum Scrum closed this as completed Mar 19, 2021
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

2 participants