Skip to content

Problems mixing-in rulesets defined using & combinator #1270

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
tcjr opened this issue Apr 15, 2013 · 6 comments
Closed

Problems mixing-in rulesets defined using & combinator #1270

tcjr opened this issue Apr 15, 2013 · 6 comments

Comments

@tcjr
Copy link

tcjr commented Apr 15, 2013

When I use the & combinator to define a ruleset like this:

.label {
  &-success {
    background-color: blue;
   }
}

This correctly creates css like this:

.label-success {
  background-color: blue;
}

However, when I try to add/mixin the label-success ruleset into another, like this:

.mySuccessLabel {
  .label-success;
}

It fails compilation with: "Name error: .label-success is undefined"

Here is the complete example showing the error:

.label {
  &-success {
    background-color: blue;
   }
}

.mySuccessLabel {
  .label-success;
}

I am using twitter bootstrap. They define labels and badges like above. https://github.com/twitter/bootstrap/blob/master/less/labels-badges.less#L52

@lukeapage
Copy link
Member

we had this bug before but I can't find it.

The answer was to use extends. These are in 1.4.0 beta.

It is unfortunately a limittation of the way mixins work that it would be difficult to compare to parts, e.g. &-success is evaluated after mixins are calculated.

@tcjr
Copy link
Author

tcjr commented Apr 15, 2013

I believe I found the issue you are talking about. Is it #1248 ?

In any event, I don't think the extend functionality, as currently implement, fixes this problem. Suppose we update the sample above to use extend, like so:

.label {
  &-success {
    background-color: blue;
   }
}
.mySuccessLabel:extend(.label-success) { }

This produces no rules for .mySuccessLabel.

Isn't this a bug? If not, then is there any workaround besides not using the & combinator in the original file?

@lukeapage
Copy link
Member

hrmm, your right.. I know why.. its because it treats it as

combinator .
element label
combinator blank
element -success

@ArturKwiatkowski
Copy link

I've run into that problem just recently while delivering more nested rules for bootstrap 3.0.0-wip (labels component), removed the short name combination in the end and im awaiting for merge. Removed because that &-name combination didnt work and i really want to use bootstrap classes as mixins in my Less mastersheet instead writing ton of classes in my html markup. Other thing im interested is a ability to make loops - can anyone point me anywhere if thats something that is/will be supported?

@lukeapage
Copy link
Member

@Fowowski #1267 (comment)

@lukeapage
Copy link
Member

duplicate of #1196

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants