spanForElement method

FileSpan spanForElement(
  1. int index
)

Returns the FileSpan covering the element of the interpolation at index.

Unlike contents[index].span, which only covers the text of the expression itself, this typically covers the entire #{} that surrounds the expression. However, this is not a strong guarantee—there are cases where interpolations are constructed when the source uses Sass expressions directly where this may return the same value as contents[index].span.

For string elements, this is the span that covers the entire text of the string, including the quote for text at the beginning or end of quoted strings. Note that the quote is never included for expressions.

Implementation

FileSpan spanForElement(int index) => switch (contents[index]) {
      String() => span.file.span(
          (index == 0 ? span.start : spans[index - 1]!.end).offset,
          (index == spans.length ? span.end : spans[index + 1]!.start)
              .offset),
      _ => spans[index]!
    };