Scrum/postcss-at-rules-variables

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

spacedawwwg opened this issue · 10 comments

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 commented

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

Scrum commented

@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

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

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 commented

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

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

@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 commented

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

Scrum commented

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 commented

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