Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

Sass - map.remove() function throwing error

Sass throws the following error when trying to compile the below code...what am I doing wrong?

Dart Sass failed with this error: Error: expected "{".
   ?
13 │ map.remove($map-1, "1");
   │                       ^
   ?
// Modules
@include "sass:map";

$map-1: (
    "1": (
        "color": red,
    ),
    "2": (
        "color": orange,
    ),
);

map.remove($map-1, "1");
question from:https://stackoverflow.com/questions/65886588/sass-map-remove-function-throwing-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Sass-modules are imported with @use, not included (@include), unlike mixins.

When "removing" a variable from a map, the original map does not get altered, therefor the altered map has to be redeclared. For example:

Dart Sass:

@use "sass:map";

$map: (
  'foo': bar,
  'faz': foobar,
);

$nMap: map.remove($map, 'faz');

@debug $map; //("foo": bar, "faz": foobar)
@debug $nMap; //("foo": bar)

Node Sass & Dart Sass (currently):

$map: (
  'foo': bar,
  'faz': foobar,
);

$nMap: map-remove($map, 'faz');

@debug $map; //("foo": bar, "faz": foobar)
@debug $nMap; //("foo": bar)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...