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

@supports fails when passing variables #2452

Closed
jhpratt opened this issue Jul 30, 2017 · 11 comments
Closed

@supports fails when passing variables #2452

jhpratt opened this issue Jul 30, 2017 · 11 comments

Comments

@jhpratt
Copy link

jhpratt commented Jul 30, 2017

input.scss

@mixin supports($prop, $val) {
  @supports ($prop: $val) {
    $prop: $val;
  }
}

div {
  @include supports(display, flow-root);
}

Actual results

node-sass 4.5.3 (via gulp)

Error: Invalid CSS after "  @supports (": expected "}", was "$prop: $val) {"
        on line 2 of css/all.scss
>>   @supports ($prop: $val) {
   ------------^

Expected result

ruby sass 3.5.1

@supports (display: flow-root) {
  div {
    display: flow-root; } }

Spec sass/sass-spec#1219

@nschonni
Copy link
Collaborator

Trying with Ruby 3.4.21 on sassmeister doesn't output anything.

To find the version of node-sass installed with gulp-sass, try npm ls node-sass

@jhpratt
Copy link
Author

jhpratt commented Jul 31, 2017

@nschonni node-sass is 4.5.3.

@nschonni
Copy link
Collaborator

Can you also confirm the Ruby Sass version as well, since I didn't get any output when trying on Sassmeister.

@jhpratt
Copy link
Author

jhpratt commented Jul 31, 2017

Just running sass --version, which is what I think you want, gives 3.5.1, which is the current release.

@nschonni
Copy link
Collaborator

I'm not 💯 that the variables in the support query is supported, but using the @supports without the mixin works in both Ruby and Node so I'll update the title

div {
  @supports(display: flow-root) {
    display: flow-root;
  }
}

@nschonni nschonni changed the title @supports fails ("invalid CSS"), but works with regular SASS compilation @supports fails when passing variables Jul 31, 2017
@jhpratt
Copy link
Author

jhpratt commented Jul 31, 2017

Ah, gotcha. It works using regular compilation, that's why I couldn't figure out why it wasn't working. Thanks for figuring that out! Hopefully this can be resolved at some point.

@meduzen
Copy link

meduzen commented Oct 10, 2017

I encountered this blocking situation while writing a @mixin. I have a @supports declaration with logic. Basically, and a bit shortened, what I’d like to do is this, which seems impossible at the moment:

@each $offset, $val in $offsets {
  @supports(#{$prop}-#{$offset}: unquote('max(0px)')) {
    #{$prop}-#{$offset}: unquote('max(constant(safe-area-inset#{$offset}), #{$value})');
  }
}

@hitautodestruct
Copy link

This issue is occurring for me on node-sass v4.7.2 any ideas if this will be fixed?

@xzyfer
Copy link
Contributor

xzyfer commented Feb 21, 2018

The issue here is that Sass does not support $variables as the prop in @supports.

$prop: display;
$val: flow-root;

div {
  @supports ($prop: $val) {
    $prop: $val;
  }
}

The following works as expected.

$val: flow-root;

div {
  @supports (display: $val) {
    display: $val;
  }
}

There are a couple things here:

  • Dart and Ruby produce no output (@nex3 can you please comment on whether this is intended?)
  • LibSass throws an error (it should either do nothing, or do something, but not error)

@nex3
Copy link
Contributor

nex3 commented Mar 2, 2018

@xzyfer The Dart/Ruby output is intended. The issue isn't that @supports ($prop: $val) doesn't work (it does); the issue is that the $prop: $val; in the body is a variable assignment, not a property declaration. If you wrote instead

$prop: display;
$val: flow-root;

div {
  @supports ($prop: $val) {
    #{$prop}: $val;
  }
}

Ruby and Dart Sass will both produce

@supports (display: flow-root) {
  div {
    display: flow-root;
  }
}

@xzyfer
Copy link
Contributor

xzyfer commented Mar 5, 2018

@nex3 thanks for clearing that up. Makes total sense.

xzyfer added a commit to xzyfer/sass-spec that referenced this issue Mar 5, 2018
@xzyfer xzyfer self-assigned this Mar 5, 2018
xzyfer added a commit to xzyfer/libsass that referenced this issue Mar 5, 2018
Emulate the parse behaviour of `@media` query declarations.

Fixes sass#2452
xzyfer added a commit to sass/sass-spec that referenced this issue Mar 5, 2018
xzyfer added a commit that referenced this issue Mar 5, 2018
Emulate the parse behaviour of `@media` query declarations.

Fixes #2452
xzyfer added a commit to xzyfer/sass-spec that referenced this issue Mar 6, 2018
xzyfer added a commit to xzyfer/sass-spec that referenced this issue Mar 6, 2018
xzyfer added a commit to sass/sass-spec that referenced this issue Mar 6, 2018
mgreter pushed a commit that referenced this issue Mar 9, 2018
Emulate the parse behaviour of `@media` query declarations.

Fixes #2452
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

6 participants