-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Ruleset variables aren't overridden within the same scope #2212
Comments
May be related to #1316? |
UPDATE: I found I could get the desired output with a slight modification of the example. But, I can't pretend to understand why it works this way, and I'm hoping there's a different / better solution. Here's the modified source:
Outputs:
|
Yes, this is related to #1316, though not really the same. Basically in this example the
resuting in:
resulting in:
which already looks like a |
P.S. and |
@seven-phases-max I do not think your latest example is a bug. Variables values are usually taken from declaration scope. Caller scope is searched only if the declaration scope does not contain the value. Lazy loading (as I understand it) means that the expression will be evaluated at the latest possible occasion, so the following will compile without errors: .parent() {
.sub() {var-in-sub: @var} // var is undefined in caller
}
.output {
@var: green;
.parent();
var-in-output: @var; // lazy loading kick in - uses local value
.sub();
} results in:
IMO, if we would fix this, using mixins would become too error prone. You would have to be super careful about local variable names. You would have to remember "internal" variables used define third party mixins just so you name your own differently and do not override them. |
Interesting. As I played with it more, it started to seem like the mixin behavior was consistent, but it just felt disjointed operating next to detached rulesets. Detached rulesets look very much like variably-assigned mixins in their syntax, but their behavior is quite different from mixins and other variables. It's fine if it's by design, but hopefully you can see why side-by-side, it can get confusing fast. Basically, I was trying a variety of things to do one thing, which was extending a ruleset in some fashion, and I ran into some unexpected behaviors. |
I'm somewhat agreed. Which means then that all results above are not a bug too (since all these examples are equal in scope handling). Getting back to the original @matthew-dean example, probably what was confusing there is that one may think of two In that sense I guess to get the desired result it's possible to rewrite the original example to something like this:
Though this is not something I would want to use in a practical project. (Too tricky, I believe there much more simple ways, though I need to think of it more to come up with a better method :) |
Oh. #library and #library are not the same namespace? Huh. So.... ohhhhhhhh.... So each .rules() was calling its local @rules ruleset. But when I re-evaluated the scope, I imported the foreign @rules, which THEN overrode the local @rules. Ohhhhh...... Now that makes sense.
I'm hoping there are too. I'm literally just trying to support overriding and extending rulesets from a base Less library, which would allow really granular replacement of a library's components. Basically it's one piece that would help support "theming" of a library. |
Probably I'd started with something in this direction: |
Oh, right, accessing namespaced variables. Yes, that comment is exactly the thrust of where I'm headed. It's funny, there's probably about 4 or 5 solutions in the works for what I'm trying to do, but it hasn't gotten there yet. It's also too bad that when we use the word "namespace", we don't actually treat it as a common combined namespace (same scope for variables in those namespaces). Or, if that would cause problems, some way to force namespace combining or define a namespace that is auto-confined. Like I said, there are a lot of ways to get there (such as expanding ":extend" to detached rulesets). Maybe we could sort / evaluate them in terms of priority? |
Should this be closed because it's not actually the "same scope" according to how Less.js has defined it? The code is actually working as designed, albeit different from the goals I wanted. But that can be addressed in other namespacing- / extend- related discussions. |
I guess we could. If nobody minds. |
Nope. Closing. |
I'm still trying to find a way to "extend" rulesets. I thought I had a way, but then ran into this issue: I can't both use a mixin to call the ruleset AND allow overriding the ruleset variable. Here's a simplified test case:
Expected output:
Actual output:
Can someone explain the discrepancy? Is this a known bug or expected scoping behavior?
The text was updated successfully, but these errors were encountered: