terrazzoapp / terrazzo

Use DTCG tokens JSON to generate code for web, mobile, native apps, and more
https://terrazzo.app
MIT License
148 stars 26 forks source link

Failing nested aliases type validation #309

Open nclsndr opened 1 week ago

nclsndr commented 1 week ago

The tokens parser is capable of catching type mismatches for scalar types but ignore the composites.

parse([{
  src: JSON.stringify({
    color: {
      $type: 'color',
      blue: {
        $value: '#10109A',
      },
    },
    dimension: {
      base: {
        $type: 'dimension',
        $value: '{color.blue}', // should be dimension: caught by parser ✅
      },
    },
    border: {
      base: {
        $type: 'border',
        $value: '{dimension.base}', // should be border: caught by parser ✅
      },
      nested: {
        $type: 'border',
        $value: {
          color: '{color.blue}',
          width: '{color.blue}', // should be dimension: silently failing ❌
          style: 'solid',
        },
      },
    },
  })
}])

I think that's not much of a deal, yet I preferred to report it while looking into it.

— The only solution I found on my end was to manually declare the mapping.

drwpow commented 1 week ago

Ah that’s a great catch, thank you! Worth fixing for sure. I like your mapping approach; great suggestion.