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

Source Range of CommentNode after @if is incorrect #51

Open
@nex3

Description

@nex3

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions