Skip to content

Color names in JSON keys are interpreted as color objects by SASS #41

Closed
@BigglesZX

Description

@BigglesZX

First off, thanks for a really useful loader!

I came across an issue this morning where if I use CSS color names as my JSON keys, e.g.

{
  "colors": {
    "fg": {
      "default": "#2c2c2c",
      "pink": "#ffabab"
    }
}

...and then use map-deep-get (source) to extract the values, like this:

.button {
    background: map-deep-get($colors, 'fg', 'pink');
}

...that despite my quoting the keys in the latter fragment, I found that CSS color names (e.g. pink) don't work (returning nothing), while custom names (e.g. default) do. What I think is happening is that when sass-vars-loader converts my JSON, the color names in my JSON file become unquoted and are then interpreted as colour objects by SASS. So when I use map-deep-get to look up the colour, it returns nothing (because my string lookup doesn't match the color object) and so that property doesn't get written into my CSS.

I found I could fix the issue by double-quoting the names in m JSON, e.g.

{
  "colors": {
    "fg": {
      "'default'": "#2c2c2c",
      "'pink'": "#ffabab"
    }
}

Is it possible to force sass-vars-loader to quote all keys when it creates maps from JSON? Either way, I thought I had better report this in case anyone else has the same issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions