The example given by the sass map.set
documentation doesn't work, why is that?
@use "sass:map";
$font-weights: (
'regular': 400,
'medium': 500,
'bold': 700
);
map.set($font-weights, 'extra-bold', 900);
// ("regular": 400, "medium": 500, "bold": 700, "extra-bold": 900)
map.set($font-weights, 'bold', 900);
// ("regular": 400, "medium": 500, "bold": 900)
My sass
version is 1.32.5
.
The entire error message:
Syntax Error: SassError: expected "{".
╷
9 │ map.set($font-weights, 'extra-bold', 900);
│ ^
╵
src\assets\styles\variables.scss 9:42 @import
src\assets\styles\main.scss 4:9 root stylesheet
I expect the map to be set without throwing errors.
When you attempt to assign a value to pass, or when you attempt to define a new function called pass, you’ll get a SyntaxError and see the "invalid syntax" message again. It might be a little harder to solve this type of invalid syntax in Python code because the code looks fine from the outside.
You might run into invalid syntax in Python when you’re defining or calling functions. For example, you’ll see a SyntaxError if you use a semicolon instead of a colon at the end of a function definition: >>>. >>> def fun(); File "<stdin>", line 1 def fun(); ^ SyntaxError: invalid syntax.
A SyntaxError comes from language issues in code that the interpreter actually tried to evaluate. I know you mention that it's pointing to "env", but that pointer isn't always correct. So check the code that you wrote after this comment.
Messing up with the syntax will prevent from execution. The following example shows an executable function without errors. Function calling has to have the required cautions to prevent bugs. The following error is caused by the argument provided which is not defined in the declaration. There are many syntax errors in python that are frustrating.
If an error in your code is still occurring, you might do the same stupid mistake as I did.
Just assign the return value to some variable.
map.set
actually returns a new map with updated values and it is not assigned to a variable, so the following code will throw the error SassError: expected "{".
:
@using 'sass:map';
$test: (
foo: 23,
bar: ()
);
map.set($test, bar, baz, 5);
... because on line 8 (map.set($test, bar, baz, 5);
) set function will return new map ((foo: 23, bar: (baz: 5))
) and it is not valid sass syntax, so the situation will be the same as you will write the following code:
@using 'sass:map';
$test: (
foo: 23,
bar: ()
);
(foo: 23, bar: (baz: 5));
Problem 1 (If you are using map.set
, please skip to problem 2)
Actually, I was using map-set
the whole time, I thought map-set
is the same as map.set
, turned out it's not.
In Sass's doc Built-In Modules:
Before the Sass module system was introduced, all Sass functions were globally available at all times. Many functions still have global aliases (these are listed in their documentation). The Sass team discourages their use and will eventually deprecate them, but for now, they remain available for compatibility with older Sass versions and with LibSass (which doesn’t support the module system yet).
And map.set
doesn't have a global map-set
like map.merge
does (map-merge
).
Problem 2
Also, I thought map.set
would act like JavaScript's Map.prototype.set()
, by which you set a map like map.set(key, value)
without assigning it to a variable will work. In Sass, I had to do:
@use "sass:map";
$map: ();
$map: map.set($map, key, value);
Why @debug
"didn't work" for me
Mostly I'm using Sass under the vue-cli
environment. Sass's @debug
syntax "never had" any output visually, it turned out they're actually outputted, I just have to scroll up a bit:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With