sass / dart-sass

The reference implementation of Sass, written in Dart.
https://sass-lang.com/dart-sass
MIT License
3.9k stars 352 forks source link

FileSpan is not defined when using @warn with a custom logger. #2155

Closed Subash closed 8 months ago

Subash commented 8 months ago

I am using the sass.compile API with a custom logger, and it seems that FileSpan is not provided when using the @warn statement. I also checked with the @debug statement, and it appears that FileSpan is provided when the @debug statement is used with a custom logger.

I explored the source code for both statements and found some differences, but I couldn't figure out an elegant way to include FileSpan when calling warn.

Link to the source for @warn Link to the source for @debug

Here is a script to reproduce the issue.

const sass = require('sass');

sass.compileString('@warn hello;\n@debug world;', {
  logger: {
    warn: (...args) => console.log(...args), // span is undefined
    debug: (...args) => console.log(...args) // span is defined
  }
});
nex3 commented 8 months ago

This is intentional. Per the spec, warnings for @warn only include a stack trace, not a span. This is for a combination of two reasons:

  1. When a span is passed to @warn, it's generally expected to be displayed to the user as an indication of a place the stylesheet is doing something it shouldn't (such as $foo && $bar).
  2. The @warn rule is usually called from a function or a mixin, or possibly a nested series of functions or mixins. This means that the @warn rule itself is not usually the place where the user's stylesheet is doing something wrong, and so isn't useful to show in a span.