Skip to content

Lists of maps with single item require trailing comma #1191

@loilo

Description

@loilo

I ran into a Sass compiler error recently with a combination of lists and maps.
What I have is a list containing a number of maps. This works without any problems until I only have a single map in that list.

At that point Sass requires a trailing comma after the list item, otherwise it will not be recognized as a map:

@use "sass:map";
@use "sass:list";

$list-of-maps: (
  (
    "key": "value"
  )
);

$list-item: list.nth($list-of-maps, 1);
$value: map.get($list-item, "key");

This produces the following error:

Error: $map: "key" "value" is not a map.

However, the code compiles correctly if a trailing comma is added after the list item:

@use "sass:map";
@use "sass:list";

$list-of-maps: (
  (
    "key": "value"
-  )
+  ),
);

$list-item: list.nth($list-of-maps, 1);
$value: map.get($list-item, "key");

I have created a minimal reproduction repo here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions