Permalink
Browse files

Nice error tracing for @content chains.

  • Loading branch information...
1 parent 720a944 commit cffb94d72366b20cc63d4c9caf37ccc702e851a9 @nex3 nex3 committed Sep 14, 2011
Showing with 43 additions and 1 deletion.
  1. +7 −1 lib/sass/tree/visitors/perform.rb
  2. +36 −0 test/sass/engine_test.rb
@@ -218,7 +218,13 @@ def visit_mixin(node)
def visit_content(node)
raise Sass::SyntaxError.new("No @content passed.") unless content = @environment.content
- with_environment(@environment.caller) {content.map {|c| visit(c.dup)}}
+ trace_node = Sass::Tree::TraceNode.from_node('@content', node)
+ with_environment(@environment.caller) {trace_node.children = content.map {|c| visit(c.dup)}}
+ trace_node
+ rescue Sass::SyntaxError => e
+ e.modify_backtrace(:mixin => '@content', :line => node.line)
+ e.add_backtrace(:line => node.line)
+ raise e
end
# Runs any SassScript that may be embedded in a property.
View
@@ -2612,6 +2612,42 @@ def test_content_not_seen_through_mixin
assert_equal(7, e.sass_line)
end
+ def test_content_backtrace_for_perform
+ render(<<SASS)
+=foo
+ @content
+
+a
+ +foo
+ b: 1em + 2px
+SASS
+ assert(false, "Expected exception")
+ rescue Sass::SyntaxError => e
+ assert_equal([
+ {:mixin => '@content', :line => 6, :filename => 'test_content_backtrace_for_perform_inline.sass'},
+ {:mixin => 'foo', :line => 2, :filename => 'test_content_backtrace_for_perform_inline.sass'},
+ {:line => 5, :filename => 'test_content_backtrace_for_perform_inline.sass'},
+ ], e.sass_backtrace)
+ end
+
+ def test_content_backtrace_for_cssize
+ render(<<SASS)
+=foo
+ @content
+
+a
+ +foo
+ @extend foo bar baz
+SASS
+ assert(false, "Expected exception")
+ rescue Sass::SyntaxError => e
+ assert_equal([
+ {:mixin => '@content', :line => 6, :filename => 'test_content_backtrace_for_cssize_inline.sass'},
+ {:mixin => 'foo', :line => 2, :filename => 'test_content_backtrace_for_cssize_inline.sass'},
+ {:line => 5, :filename => 'test_content_backtrace_for_cssize_inline.sass'},
+ ], e.sass_backtrace)
+ end
+
private
def assert_hash_has(hash, expected)

0 comments on commit cffb94d

Please sign in to comment.