Skip to content

issue with variable scope in namespaces #719

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
nlac opened this issue Mar 16, 2012 · 5 comments
Closed

issue with variable scope in namespaces #719

nlac opened this issue Mar 16, 2012 · 5 comments

Comments

@nlac
Copy link

nlac commented Mar 16, 2012

Hello,
please check the following code compiled flawlessly by less.js:

/* mixin library uses a variable from the "caller" namespace #skin */
#lib {
  //@w : @size;
  .rect() {
    width:2*@size;
    height:@size;
  }
}

/* "caller" namespace uses the mixins from #lib in its mixins */
#skin {
 @size : 100px;
  .panel() {
    #lib > .rect();
  }
}

/* constructing actual html class */
div.intro {
  #skin > .panel();
}

The issue: if i remove the comment before the @w : @size; the compilation fails.

Is there a particular reason why? Why the mixin body can see the @size variable and the variable defining rule can't, in the #lib namespace?

Regards, nlac

@nlac
Copy link
Author

nlac commented Mar 23, 2012

Hi,
#lib is a namespace (go to http://lesscss.org and study the section "Namespaces"), just like the #skin, and it is intended to be a namespace - #lib may contain other rules. I want that rules to see variables, classes, mixins from #skin, that's what i'm doing.

@nlac
Copy link
Author

nlac commented Mar 23, 2012

which part shouldn't work? which part doesn't work in the correct way? how is it connected to the theory that "namespaces are still rules"? How your comments lead closer or even connected to the solution or at least the explanation of the issue?

@nlac
Copy link
Author

nlac commented Mar 24, 2012

My problem is, this one is the 7th comment and i (and people who also interest how scopes work in deep) didn't get any closer to the solution.

The original scope issue exposed in this ticket as a reminder, is:

why the compilation fails if i remove the comment in the 2nd line, while the .rect() mixin can flawlessly see the @size variable in the actual context?
It is NOT about how someone define a namespace in his head or how not.

I'm waiting for some people who can see the problem exposed.

@souldreamer
Copy link

It's because #lib doesn't know what @size is. #lib > .rect()'s code is pasted into #skin and tied to the @size var in #skin (because that's where the mix-in is instantiated), but @w isn't (as it has no ties to @size, and can't be computed so the parser has no idea what to do with it). Then #panel pastes the code for #skin > .panel() which is already tied to #skin's @size variable (i.e. setting @size in div.intro will do nothing).

@nlac
Copy link
Author

nlac commented Mar 26, 2012

Thanks souldreamer, that's clear and makes sense.

actually i wanted to customize semantic.gs a bit to be able to define more than one grid system (embedding the gs lib into a namespace with all its vars and mixins, @gridsystem-width would be the @w in the purified example etc.).

Thinking over your explanation i understand that the above example is not an issue and have to work around some other way. I close the issue.

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