question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bad substitution if using color keywords as map keys

See original GitHub issue

If you use color keywords, such as white oder black, and use them to build classes dynamically, sass-loader substitutes them with color hashes. This only happens when using webpack with -p.

$testMap: (
    white: (color: white)
);

@each $key in map-keys($testMap) {
    .test-btn-#{$key} {
        $colors: map_get($testMap, $key);

        color: map-get($colors, color);
    }
}

actual result:

.test-btn-#fff{
    color:#fff
}

expected result:

.test-btn-white {
    color: white; // or #fff because of -p
}

Versions:

    ...
    "node-sass": "^4.5.1",
    "sass-loader": "^6.0.3",
    ...

Using single curly quote fixes it, thought.

$testMap: (
    'white': (color: white)
);

Not sure if this is an actual issue or intended as it is, because sass documentation says:

Both the keys and values in maps can be any SassScript object.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:10
  • Comments:19 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
xzyfercommented, Jun 29, 2017

Hallo, I’m the maintainer of LibSass and Node Sass.

This is actually a Sass feature. When CSS colors are unquoted they’re treated as Color objects, not Strings as you might expect. This is why you can do things like color math on them.

A feature of Color objects is that when they’re output in compressed mode, Sass tries to output the shortest representation i.e. #fff is more “compressed” than white.

If you want CSS color names to act like strings you should quote them.

1reaction
alexander-akaitcommented, Jun 12, 2017

@michael-ciniawsky I also think so, but the problem should be reported in any case

Read more comments on GitHub >

github_iconTop Results From Across the Web

bash : Bad Substitution - Stack Overflow
So if you chmod +x your_script_file.sh and then run it with ./your_script_file.sh , or if you run it with bash your_script_file.sh , it...
Read more >
Script to display all terminal colors - command line - Ask Ubuntu
Xdefaults . However when I try to use these, I always get error: Bad Substitution . Does anyone have a working script that...
Read more >
Bad substitution error in zsh shell - Unix & Linux Stack Exchange
zsh has different parameter substitution than Bash, which is documented in man zshexpn . ... will loop over the keys of the array...
Read more >
The Coot User Manual - MRC Laboratory of Molecular Biology
This state file contains information about the screen centre, the clipping, colour map rotation size, the symmetry radius, and other molecule related parameters ......
Read more >
Bash Reference Manual - GNU.org
A sequence of characters treated as a unit by the shell. Words may not include unquoted metacharacters . Next: Shell Builtin Commands, Previous: ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found