oddbird / accoutrement

Combined Sass Accoutrement tools, with option for individual module imports
MIT License
37 stars 6 forks source link

bug: get-token() errors when getting 2nd+ level submap, and null mode enabled #61

Closed johncrim closed 3 years ago

johncrim commented 3 years ago

Using dart-sass, this fails:

// file: submap-null-setting.scss
@use './node_modules/accoutrement/sass' as a with (
  $handle-missing-keys: 'null'
);

$map: (
  'bar': (
    'foo': (
      'three': 'four'
    ),
  )
);

// Works
@debug a.get-token($map, 'bar->foo->three');

// Errors
$barfoo: a.get-token($map, 'bar->foo');
@debug $barfoo;

then:

❯ sass submap-null-setting.scss
submap-null-setting.scss:26 Debug: four
Error: ("three": "four") isn't a valid CSS value.
   ╷
64 │   $string: if((type-of($string) == 'string'), $string, '#{$string}');
   │                                                           ^^^^^^^
   ╵
  node_modules\accoutrement\sass\core\_strings.scss 64:59  -a-str-replace()
  node_modules\accoutrement\sass\core\_parser.scss 225:14  -a-replace()
  node_modules\accoutrement\sass\core\_parser.scss 108:14  -a-parse()
  node_modules\accoutrement\sass\core\_parser.scss 51:11   -a-get()
  node_modules\accoutrement\sass\core\_api.scss 339:9      get-token()
  submap-null-setting.scss 28:10                           root stylesheet

This is a very similar bug in cause to the one I fixed in PR 60, in that both are caused by weak contracts (variable named $string can be a map, and isn't documented as such) and by map interpolation erroring in dart-sass. However, the behavior is different, so I filed a separate bug. It also was probably added when adding the $handle-missing-keys support.

I have a unit test and I think a fix for this already.

mirisuzanne commented 3 years ago

Released: https://github.com/oddbird/accoutrement/releases/tag/v3.0.0

Thanks again!