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

Extend statement with & selector causes crash #1519

Closed
bassplayer7 opened this issue Sep 2, 2015 · 10 comments
Closed

Extend statement with & selector causes crash #1519

bassplayer7 opened this issue Sep 2, 2015 · 10 comments

Comments

@bassplayer7
Copy link

I have this situation in one of my SCSS stylesheets which I'm compiling with libsass (with CodeKit 2):
controls_scss-river_valley_woodworks-___sites_river_valley_woodworks

At the time of writing, I didn't put it together that @extend & will always extend the current selector and as such doesn't make sense. However, CodeKit crashed with that and I'm guessing that it threw an unrecoverable exception. I suppose it is conceivable that others would make the same mistake that I did, and it would be nice to have an error saying that the "current select cannot be extended". Obviously, had it compiled or told me, I would have immediately realized the error of my thought at that moment.

@mgreter mgreter added this to the 3.3 milestone Sep 2, 2015
@mgreter mgreter self-assigned this Sep 2, 2015
@mgreter
Copy link
Contributor

mgreter commented Sep 2, 2015

I can confirm that this segfaults. Fix seems simple as we just need to error when we extend '&'

Can't extend &: can't extend parent selectors

@bassplayer7 thanks for the report! I just don't understand why quite a few people actually like to post pictures of code instead of just pasting the code (it keeps us from transcribing the test case) 😕

foo {
  @extend &;
}

@bassplayer7
Copy link
Author

@mgreter, I'm sorry about that. I absolutely should have included the code: I'm not sure why it didn't cross my mind.


Here's where it happened to me, in case it affects your error message:

.column {
  & {
    width: 31%;
    margin: 1rem 1.5%;
    display: inline-block;
    vertical-align: top;

    &-half {
      @extend &;
    }
  }
}

That was perhaps what made me miss the error of my way originally is that it was not extending a parent selector. I was trying to extend .column, but would have extended .column-half unintentionally. I'm not sure if that would impact the error message.

Thanks for working on this! I appreciate libsass very much.

@mgreter
Copy link
Contributor

mgreter commented Sep 2, 2015

Not sure if you expect this to compile, but ruby sass gives this error (and libsass segfaults):

Error: Can't extend &: can't extend parent selectors
        on line 9 of foo.scss
  Use --trace for backtrace.

So we need add this check to libsass, but the given code is not valid sass ...

@bassplayer7
Copy link
Author

Ok. Great. Right, I didn't expect the SCSS to compile, I was just commenting on the error message. And, & could, and often would be a parent selector, so that message would make sense. Again, I really appreciate your work on that.

@mgreter
Copy link
Contributor

mgreter commented Sep 2, 2015

Ah, I guess I got you now. The error seems to repeat what you tried to extend. Ie. @extend &.xyz will lead to Can't extend &.xyz.

@mgreter
Copy link
Contributor

mgreter commented Sep 3, 2015

Fix was merged and will be in 3.3

@xzyfer
Copy link
Contributor

xzyfer commented Jan 12, 2016

Spec added and activated in sass/sass-spec#689

@brookjordan
Copy link

Why not allow extending of parent selectors?
I was hoping this would work — I'm using B__E--M and would love for modifiers to be able to extend their parent without having to type the full parent selector out.

@xzyfer
Copy link
Contributor

xzyfer commented Apr 4, 2016

@brookjordan LibSass just implements the Sass language. Questions and suggestions about the language should be raised with Sass - https://github.com/sass/sass

@brookjordan
Copy link

Oops, sorry. Thanks @xzyfer !

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

4 participants