Source Range of CommentNode after @if is incorrect
Opened this issue · 0 comments
nex3 commented
From sass/sass#2284:
Take the following SCSS:
div { top: 0; /* x16 */ @if (1 + 1 == 2) { width: 7; } /* x40 */ }I patched scss so that CommentNode source_range is printed in
process_comment
:$ git diff diff --git i/lib/sass/scss/parser.rb w/lib/sass/scss/parser.rb index 172d364d..d1529d2a 100644 --- i/lib/sass/scss/parser.rb +++ w/lib/sass/scss/parser.rb @@ -191,6 +191,7 @@ module Sass end start_pos = Sass::Source::Position.new(line, offset) comment = node(Sass::Tree::CommentNode.new(value, type), start_pos) + $stderr.puts "SOURCE_POS #{source_position.inspect} / RANGE #{comment.source_range.inspect}" node << comment endPass the SCSS file through
scss
:
ruby -I ./lib ./bin/scss -C --trace in.scss out.css
You get:
SOURCE_POS 2:20 / RANGE (2:11 to 2:20 in ../scss-lint/issue-887-2.scss) SOURCE_POS 3:12 / RANGE (3:35 to 3:12 in ../scss-lint/issue-887-2.scss)
So the second comment runs along line 3, from offset 35 to offset 12???
Where 12 comes from is very curious to me. If you add or remove space from the body of the comment, or even the whitespace before the comment, like any of:
{ width: 7; } /* x40 */ { width: 7; } /* x40 */ { width: 7; } /* x40 */then that "offset" changes, always to be the length from
}
to the newline.