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

Dynamically generated mixins suddenly can be used as mixins #1837

Closed
SomMeri opened this issue Jan 29, 2014 · 4 comments
Closed

Dynamically generated mixins suddenly can be used as mixins #1837

SomMeri opened this issue Jan 29, 2014 · 4 comments

Comments

@SomMeri
Copy link
Member

SomMeri commented Jan 29, 2014

E.g. this:

.@{fa-css-prefix} { display: inline-block; }
.@{fa-css-prefix}-2x { font-size: 2em; }

.my-class {
  .my-icon;
  .my-icon-2x;
}

@fa-css-prefix: my-icon;

compiles into:

.my-icon {
  display: inline-block;
}
.my-icon-2x {
  font-size: 2em;
}
.my-class {
  display: inline-block;
  font-size: 2em;
}

Was this intentional and do we know how variables scoping works? This works now and people seem to be discovering it. I did not dug into how exactly the feature works, is there anyone who knows?

Related to #1399 and #1836 .

@seven-phases-max
Copy link
Member

Not quite suddenly :) It was in #1624 PR.

do we know how variables scoping works?

Yes. It's all is almost as usual except the #1399 (comment) first example (note that the third example "experiment" was not included in the PR). In summary: mixins are evaluated before variables so "dynamically generated class" is not available as mixin in the scope of its definition (hence it can't re-define itself by redefining an interpolated variable).

I'm not sure, maybe we could close #1399 and open a new issue dedicated to further improvements? (#1399 has too many examples to comment: some of them are implemented in #1624, some do not apply at all, some are more about "selector interpolation" rather than using those as mixins and others need more decisions/discussions).

@SomMeri
Copy link
Member Author

SomMeri commented Jan 29, 2014

@seven-phases-max So, the order is somewhat like this:
1.) match mixins calls with mixins,
2.) replace variables by their values,
3.) evaluate guards and replace mixins?

Another question: Dynamic mixin has to be defined before being used. Was that intentional? Following throws compile error:

.my-class {
  .my-icon;
}

.@{fa-css-prefix} { 
  display: inline-block; 
}

@fa-css-prefix: my-icon;

@seven-phases-max
Copy link
Member

So, the order is somewhat like this:

It's even more nuclear. Variables are replaced with their values after mixins of the same scope are expanded/replaced. It's not in #1624 code, it's just how mixin expansion is made in general, e.g.:

@var: 1;

.test {
    var: @var;
    .mixin() {@var: 2;}
    .mixin();
}

Dynamic mixin has to be defined before being used. Was that intentional?

No. The #1624 actually does not change any mixin/variable evaluation/scope stuff, it's just expands @{var} to its value, that's it (but the value itself is set elsewhere so if variable is not evaluated yet the mixin match fails because @{var}'s value could be just "@var" yet). I think the PR diff. can put some light on how it works: lines 37-39 is just what it does, nothing else.

@SomMeri
Copy link
Member Author

SomMeri commented Jan 30, 2014

@seven-phases-max Thanks for the answer. I will play with the feature once I will have some free time. I have none right now :(

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