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

Multiple ampersands do not produce a syntax error. #1901

Closed
knpwrs opened this issue Feb 27, 2014 · 3 comments
Closed

Multiple ampersands do not produce a syntax error. #1901

knpwrs opened this issue Feb 27, 2014 · 3 comments

Comments

@knpwrs
Copy link

knpwrs commented Feb 27, 2014

Tested in less.js 1.6.0.

The following code has very predictable output:

p {
  .foo {
    font-weight: bold;
    &.bar {
      color: red;
    }
  }
}

As such:

p .foo {
  font-weight: bold;
}
p .foo.bar {
  color: red;
}

Being the smartass I am, I then decided I wanted to know what would happen if I tried multiple ampersands:

p {
  .foo {
    font-weight: bold;
    &&.bar {
      color: red;
    }
  }
}

Produces the following css:

p .foo {
  font-weight: bold;
}
p .foop .foo.bar {
  color: red;
}

.foo and p were mashed together to make .foop. I don't know what else should happen -- a syntax error makes the most sense to me. You can also add more ampersands for even more hilarious results:

p {
  .foo {
    font-weight: bold;
    &&&&.bar {
      color: red;
    }
  }
}

Produces:

p .foo {
  font-weight: bold;
}
p .foop .foop .foop .foo.bar {
  color: red;
}

I therefore declare this the foop foop foop bug.

FWIW Sass (SCSS) produces a syntax error with the same code.

@lukeapage
Copy link
Member

In general, It is actually a feature, consider

.a {
    & + & {
    }
}

etc.

what is kind of a bug is that it joins together the p and the .foo

@seven-phases-max
Copy link
Member

what is kind of a bug is that it joins together the .p and the .foo

I don't think it's a bug either. && should join (unlike & &) see docs#40 for example.

@lukeapage
Copy link
Member

Yes, you are right people are using it to postfix everything.
I just think its nice that selectors stay selectors e.g. I might expect in
this example for the p tag to be moved to be p.foo.. anyway it can be
worked around and I agree thus should be closed.

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