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

Interpolation mangles up lists #639

Closed
SanderElias opened this issue Nov 12, 2014 · 7 comments · Fixed by #779
Closed

Interpolation mangles up lists #639

SanderElias opened this issue Nov 12, 2014 · 7 comments · Fixed by #779

Comments

@SanderElias
Copy link

I had a strange bug, and tracked it down to LibSass.

map-keys($primary-color-palette) result:
'50', '100', '200', '300', '400', '500', '600', '700', '800', '900', 'A100', 'A200', 'A400', 'A700'

"#{map-values($primary-color-palette)}" result:
"5','10','20','30','40','50','60','70','80','90','A10','A20','A40','A700"

see it in Sassmeister

@lunelson
Copy link

This is not to do with map-keys(), rather it's a problem with interpolating a list to a string. So the title of this issue and the test do not point to the real problem—I suggest you edit it and reference a better test.

For your use-case, you could in the meantime use a loop to build the right string for you, e.g.

$color-names: map-keys($primary-color-palette);
$length: length($color-names);
$string: '';
@for $n from 1 through $length {
  $name: nth($color-names, $n);
  $string: $string + if($n == $length, '#{$name}', '#{$name}, ');
}
.out {
  content: $string;
}

@SanderElias
Copy link
Author

@lunelson Thanks you for the workaround.

I updated the issue's title, but I think the example still holds. If you have an suggestion on how to better demonstrate the issue, I will adapt it

@SanderElias SanderElias changed the title map-keys mangling up content when using interpolation Interpolation mangles up map-keys result Nov 16, 2014
@xzyfer xzyfer changed the title Interpolation mangles up map-keys result Interpolation mangles up lists Nov 16, 2014
@xzyfer
Copy link
Contributor

xzyfer commented Nov 16, 2014

A simplified test case FTR

foo {
  foo: #{"foo", "bar", "baz"};
}

@lunelson
Copy link

As of today, I'm still seeing problems with lists of quoted items. The following is a bit elaborate but please bear with me, it's just to show that what's at issue is a list of explicitly quoted strings:

$contexts: (
  mobile-l: (min-width: 20em),
  tablet-s: (min-width: 30em),
  tablet-l: (min-width: 48em),
  desktop-s: (min-width: 64em),
  desktop-m: (min-width: 80em)
) !default;


$quoted-context-keys: ();
@each $key in map-keys($contexts) {
  $quoted-context-keys: append($quoted-context-keys, quote($key), 'comma');
}

.test {
  output: map-keys($contexts);
  output: $quoted-context-keys;
  output: #{$quoted-context-keys};
  output: "[#{$quoted-context-keys}]";
  output: "#{$quoted-context-keys}";
  output: "["#{$quoted-context-keys}"]";
  output: '#{$quoted-context-keys}';
  output: "['#{$quoted-context-keys}']";
}

in ruby sass 3.4.9 produces

.test {
  output: mobile-l, tablet-s, tablet-l, desktop-s, desktop-m;
  output: "mobile-l", "tablet-s", "tablet-l", "desktop-s", "desktop-m";
  output: mobile-l, tablet-s, tablet-l, desktop-s, desktop-m;
  output: "[mobile-l, tablet-s, tablet-l, desktop-s, desktop-m]";
  output: "mobile-l, tablet-s, tablet-l, desktop-s, desktop-m";
  output: "["mobile-l, tablet-s, tablet-l, desktop-s, desktop-m"]";
  output: "mobile-l, tablet-s, tablet-l, desktop-s, desktop-m";
  output: "['mobile-l, tablet-s, tablet-l, desktop-s, desktop-m']"; }

but in sassc: 3.1.0-2-g2033 / libsass: 3.1.0-76-g71448, produces

.test {
  output: mobile-l, tablet-s, tablet-l, desktop-s, desktop-m;
  output: "mobile-l", "tablet-s", "tablet-l", "desktop-s", "desktop-m";
  output: mobile-l", "tablet-s", "tablet-l", "desktop-s", "desktop-m;
  output: "[mobile-l", "tablet-s", "tablet-l", "desktop-s", "desktop-m]";
  output: "mobile-l", "tablet-s", "tablet-l", "desktop-s", "desktop-m";
  output: "["mobile-l", "tablet-s", "tablet-l", "desktop-s", "desktop-m"]";
  output: 'mobile-l", "tablet-s", "tablet-l", "desktop-s", "desktop-m';
  output: "['mobile-l", "tablet-s", "tablet-l", "desktop-s", "desktop-m']"; }

note different results with single and double quoting, etc.

@xzyfer
Copy link
Contributor

xzyfer commented Feb 2, 2015

Thanks for this @lunelson . This appears to be a different issue than the one originally reported.

Could you please create a new issue and spec?

@lunelson
Copy link

lunelson commented Feb 2, 2015

Sure thing

@mgreter
Copy link
Contributor

mgreter commented Mar 2, 2015

This should be solved by #910!

@mgreter mgreter reopened this Mar 2, 2015
@mgreter mgreter closed this as completed Mar 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants