style-dictionary icon indicating copy to clipboard operation
style-dictionary copied to clipboard

Format scss/map-deep fails if value is string or null

Open supermueller opened this issue 2 years ago • 0 comments

If the token file contains values that are null or strings then (under some circumstances) the parsing fails (error message: TypeError: Cannot read property 'hasOwnProperty' of null).

spike.js

const StyleDictionary = require('style-dictionary')

const StyleDictionaryExtended = StyleDictionary.extend({
    "source": ["./spike.tokens.json"],
    "platforms": {
      "scss": {
        "transformGroup": "scss",
        "files": [{
          "destination": "spike.variables.scss",
          "format": "scss/map-deep"
        }]
      }
    }
  }
)

StyleDictionaryExtended.buildAllPlatforms()

spike.tokens.js

{
  "color": {
    "primary": {
      "brand orange": {
        "type": "color",
        "value": "orange"
      },
      "brand blue": {
        "type": "color",
        "value": "blue"
      },
      "description": null
    }
  }
}

I do have a solution for this and will create a pull request for it.

supermueller avatar Jun 23 '22 15:06 supermueller