Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment interpolations have wrong source_range #1868

Closed
srawlins opened this issue Oct 26, 2015 · 2 comments
Closed

Comment interpolations have wrong source_range #1868

srawlins opened this issue Oct 26, 2015 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@srawlins
Copy link

When visiting a Sass tree with a visitor (and expanding to visit things like comments, script interpolations and script funcalls), Sass::Script::Tree::Interpolation nodes (and nodes within) have wrong #source_range. It appears to not understand when comments are on their own lines, maybe? Here's a recreate script:

require 'sass'

class InterpolationVisitor < Sass::Tree::Visitors::Base
  def visit_comment(node)
    puts "Comment at:       #{node.source_range.inspect}"
    yield
  end

  def visit_script_funcall(node)
    puts "Funcall at:       #{node.source_range.inspect}"
    yield
  end

  def visit_script_interpolation(node)
    puts "Interpolation at: #{node.source_range.inspect}"
    yield
  end
end

module Sass::Tree
  class CommentNode
    def children
      super + value.select { |item| item.is_a?(::Sass::Script::Tree::Node) }
    end
  end
end

module Sass::Script
  class Tree::Funcall
    def self.visit_method; :visit_script_funcall; end
  end

  class Tree::Interpolation
    def self.visit_method; :visit_script_interpolation; end
  end

  class Tree::Variable
    def self.visit_method; :visit_script_variable; end
  end
end

sass = <<SASS
$color: purple;
/* \#{hue($color)} */

$color: purple;
/* \#{hue($color)} */
SASS

puts sass
tree = Sass::Engine.new(sass, {syntax: :scss}).to_tree
InterpolationVisitor.new().send(:visit, tree)

This produces:

Comment at:       nil
Interpolation at: (2:15 to 2:29)
Funcall at:       (2:17 to 2:28)
Comment at:       nil
Interpolation at: (5:53 to 5:67)
Funcall at:       (5:55 to 5:66)

which is definitely way wrong.

@srawlins
Copy link
Author

It's probably not high priority to fix internal, undocumented API bugs (this is for sds/scss-lint#568), so I'd be happy to contribute a fix. I'll probably need a hint though.

@chriseppstein
Copy link

@srawlins This appears to be an oversight. We just didn't think that comment nodes were important from a source-mapping perspective or we missed it.

We just don't pass a source range when we make a Sass::Tree::CommentNode:

Hopefully that's enough to get you going on a patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants