dart-sass icon indicating copy to clipboard operation
dart-sass copied to clipboard

Improve error for declaration where a style rule is expected

Open nex3 opened this issue 5 years ago • 0 comments

Today, if a user uses a declaration in a context where only a style rule is valid (such as the top level of a style sheet, or within a top-level media query), Dart Sass produces a pretty opaque error. For example, this invalid stylesheet:

@media screen {
  a: b;
}

produces the error:

Error on line 2, column 7 of test.scss: expected "{".
  ╷
2 │   a: b;
  │       ^
  ╵

If we run into a situation where we fail to parse the children of a style rule in a case where only a style rule is allowed, we should rewind and try parsing a declaration instead. If that succeeds, we should throw a more specific error explaining that declarations aren't allowed there.

nex3 avatar Feb 26 '19 19:02 nex3