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

Add spans to the Selector AST

Open nex3 opened this issue 3 years ago • 2 comments

Currently the selector AST used by Sass and exposed by sass_api doesn't expose source span information. This information is tricky to determine, because selectors are interpolated in the source file. However, it should be possible to map the source spans from the parsed string back to the original file by tracking where the source offsets of the interpolated sections begin and end, and thereby get accurate spans for the selectors.

This would allow us to improve a number of error/deprecation messages, and make the Kythe indexer implementation cleaner.

nex3 avatar Aug 18 '22 22:08 nex3

Even without taking interpolation into account, complex and compound selectors won't have a single span as source (due to the nesting features, and mixins might even make them combine simple selectors from different files). Note that the &-suffix feature also means that even simple selectors could have multiple source spans.

stof avatar Sep 03 '22 01:09 stof

For nested selectors, we'd generally fall back to using the innermost span when necessary. You're right that that does increase the complexity of the translation, though.

nex3 avatar Sep 06 '22 22:09 nex3