From b6511d3ed11b290f819ca2224dc1a6173d16ceea Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Mon, 21 Dec 2009 20:30:56 -0800 Subject: [PATCH] [Sass] Move detection of nodes only allowed at the root into Tree::Node. --- lib/sass/engine.rb | 11 ----------- lib/sass/tree/node.rb | 10 ++++++++-- lib/sass/tree/root_node.rb | 8 ++++++++ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/sass/engine.rb b/lib/sass/engine.rb index 50871b52..7d505139 100644 --- a/lib/sass/engine.rb +++ b/lib/sass/engine.rb @@ -298,17 +298,6 @@ END end def validate_and_append_child(parent, child, line, root) - unless root - case child - when Tree::MixinDefNode - raise SyntaxError.new("Mixins may only be defined at the root of a document.", - :line => line.index) - when Tree::ImportNode - raise SyntaxError.new("Import directives may only be used at the root of a document.", - :line => line.index) - end - end - case child when Array child.each {|c| validate_and_append_child(parent, c, line, root)} diff --git a/lib/sass/tree/node.rb b/lib/sass/tree/node.rb index c0fda6d1..eb66d39a 100644 --- a/lib/sass/tree/node.rb +++ b/lib/sass/tree/node.rb @@ -293,7 +293,8 @@ module Sass # Returns an error message if the given child node is invalid, # and false otherwise. # - # By default, all child nodes are valid. + # By default, all child nodes except those only allowed at root level + # ({Tree::MixinDefNode}, {Tree::ImportNode}) are valid. # This is expected to be overriden by subclasses # for which some children are invalid. # @@ -301,7 +302,12 @@ module Sass # @return [Boolean, String] Whether or not the child node is valid, # as well as the error message to display if it is invalid def invalid_child?(child) - false + case child + when Tree::MixinDefNode + "Mixins may only be defined at the root of a document." + when Tree::ImportNode + "Import directives may only be used at the root of a document." + end end end end diff --git a/lib/sass/tree/root_node.rb b/lib/sass/tree/root_node.rb index 7fafb246..73207d1f 100644 --- a/lib/sass/tree/root_node.rb +++ b/lib/sass/tree/root_node.rb @@ -70,6 +70,14 @@ module Sass return "" if result.empty? return result + "\n" end + + # Returns false, because all nodes are allowed at the root of the document + # (properties are detected elsewhere post-mixin-resolution). + # + # @see Node#invalid_child? + def invalid_child?(child) + false + end end end end