Skip to content
This repository has been archived by the owner on Apr 4, 2019. It is now read-only.

Source Range of CommentNode after @if is incorrect #51

Open
nex3 opened this issue Apr 11, 2018 · 0 comments
Open

Source Range of CommentNode after @if is incorrect #51

nex3 opened this issue Apr 11, 2018 · 0 comments
Labels
bug Something isn't working

Comments

@nex3
Copy link
Contributor

nex3 commented Apr 11, 2018

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
       end

Pass 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.

@nex3 nex3 added the bug Something isn't working label Apr 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant