Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

some map keys become null when passed through custom functions #1102

@eoneill

Description

@eoneill

When a map is passed into a custom function, some keys mysteriously become null.

This is pretty edge case, but it happens (at least) when a / is in an unquoted key (e.g. a/b).

Here's a reproduction example of the issue.

var sass = require("node-sass");

var scss = [
  "$str: a/b;",
  "$map: (a/b: 1, 'c/d': 2, unquote('e/f'): 3);",

  // the `inspect` function doesn't show the full issue, so this will help better illustrate
  // you can basically ignore this bit :)
  "@mixin inspect($item) {",
  "  /* #{type-of($item)}: */",
  "  @if type-of($item) == map {",
  "    /* ( */",
  "    @each $key, $value in $item {",
  "      /*   #{nullish($key)}: #{nullish($value)} */",
  "    }",
  "    /* ) */",
  "  }",
  "  @else { /* #{nullish($item)} */ }",
  "}",

  // returns `null` as a string so it's visible in the output
  "@function nullish($value) {",
  "  @return if($value == null, 'null', $value);",
  "}",

  // without a custom function
  "/* -- without custom function -- */",
  "@include inspect($str);",
  "@include inspect($map);",

  // with a custom function
  "/* -- with custom function -- */",
  "@include inspect(fn($str));",
  "@include inspect(fn($map));"
].join("\n");

console.log(sass.renderSync({
  data: scss,
  functions: {
    // the simplest of custom functions...
    "fn($value)": function($value) {
      // don't do anything, just return the value
      return $value;
    }
  }
}).css.toString());

Here's the output:

/* -- without custom function -- */

/* string: */
/* a/b */

/* map: */
/* ( */
/*   a/b: 1 */
/*   c/d: 2 */
/*   e/f: 3 */
/* ) */


/* -- with custom function -- */

/* string: */
/* a/b */

/* map: */
/* ( */
/*   null: 1 */
/*   c/d: 2 */
/*   e/f: 3 */
/* ) */

Note that in the case we pass the value through the custom function, the expected a/b: 1 comes back as null: 1.

Also of potential interest is that a/b works fine passed through fn() when it's not a map key. And unquote('e/f') works fine as a key.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions