diff --git a/lib/sass/tree/attr_node.rb b/lib/sass/tree/attr_node.rb index 90127047..f89cb14f 100644 --- a/lib/sass/tree/attr_node.rb +++ b/lib/sass/tree/attr_node.rb @@ -40,5 +40,11 @@ module Sass::Tree def declaration ":#{name} #{value}" end + + def invalid_child?(child) + if !child.is_a?(AttrNode) + "Illegal nesting: Only attributes may be nested beneath attributes." + end + end end end diff --git a/lib/sass/tree/node.rb b/lib/sass/tree/node.rb index 4655a50f..82739efb 100644 --- a/lib/sass/tree/node.rb +++ b/lib/sass/tree/node.rb @@ -10,6 +10,9 @@ module Sass end def <<(child) + if msg = invalid_child?(child) + raise Sass::SyntaxError.new(msg, child.line) + end @children << child end @@ -24,6 +27,15 @@ module Sass end result[0...-1] end + + private + + # This method should be overridden by subclasses to return an error message + # if the given child node is invalid, + # and false or nil otherwise. + def invalid_child?(child) + false + end end end end diff --git a/test/sass/engine_test.rb b/test/sass/engine_test.rb index 454d04bd..cdf15b64 100644 --- a/test/sass/engine_test.rb +++ b/test/sass/engine_test.rb @@ -33,7 +33,8 @@ class SassEngineTest < Test::Unit::TestCase "a\n :b c" => "Illegal Indentation: Only two space characters are allowed as tabulation.", "a\n :b c\n !d = 3" => "Constants may only be declared at the root of a document.", "!a = 1b + 2c" => "Incompatible units: b and c", - "& a\n :b c" => "Base-level rules cannot contain the parent-selector-referencing character '&'" + "& a\n :b c" => "Base-level rules cannot contain the parent-selector-referencing character '&'", + "a\n :b\n c" => "Illegal nesting: Only attributes may be nested beneath attributes." } def test_basic_render