css - 为什么我会收到语法错误 : SassError: expected "{"?

标签 css sass sass-loader dart-sass sass-maps

sass 给出的例子 map.set documentation不起作用,这是为什么?

@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)
我的 sass版本是 1.32.5 .
整个错误信息:
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
我希望 map 的设置不会引发错误。

最佳答案

问题 1 (如果您使用的是 map.set ,请跳到问题 2)
实际上,我正在使用 map-set一直以来,我都在想 map-setmap.set 相同,原来不是。
在 Sass 的文档中 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).


map.set 没有全局 map-set喜欢 map.merge 确实( map-merge )。
问题2
另外,我还以为 map.set就像 JavaScript 的 Map.prototype.set() ,您可以通过它设置 map ,如 map.set(key, value)不将其分配给变量将起作用。在 Sass 中,我必须这样做:
@use "sass:map";

$map: ();
$map: map.set($map, key, value);
为什么@debug “对我不起作用”
大多数情况下,我在 vue-cli 下使用 Sass环境。 Sass的@debug语法“从来没有”在视觉上有任何输出,结果它们实际上是输出的,我只需要向上滚动一点:
enter image description here

关于css - 为什么我会收到语法错误 : SassError: expected "{"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65911728/

相关文章:

jquery - 我如何使用 CSS 根据链接是否被访问来更改 jQuery 生成的类分配?

reactjs - 如何修复 antd babel import css 覆盖自定义 css?

javascript - 如何缩放像图像这样的元素?

网页包。 scss。 @extend后有重复的代码

css - 有没有办法将 clearfix hack 与 flexbox 一起使用?

html - 引导行中的左、中、右三个按钮

javascript - 有没有办法在 web pack 中使用 Dart Sass 命令行版本?

javascript - 带有 sourcemaps 和 url 语句的 Webpack sass 加载器

jquery - 选择 :after pseudo class/element

css - 我们能不能把简单的css语法写成.scss文件?