vendor/sass/lib/sass/tree/visitors/check_nesting.rb in haml-3.1.8 vs vendor/sass/lib/sass/tree/visitors/check_nesting.rb in haml-3.2.0.alpha.2

- old
+ new

@@ -15,15 +15,15 @@ rescue Sass::SyntaxError => e e.modify_backtrace(:filename => node.filename, :line => node.line) raise e end - CONTROL_NODES = [Sass::Tree::EachNode, Sass::Tree::ForNode, Sass::Tree::IfNode, Sass::Tree::WhileNode] - SCRIPT_NODES = [Sass::Tree::ImportNode, Sass::Tree::MixinNode] + CONTROL_NODES + PARENT_CLASSES = [ Sass::Tree::EachNode, Sass::Tree::ForNode, Sass::Tree::IfNode, + Sass::Tree::ImportNode, Sass::Tree::MixinNode, Sass::Tree::WhileNode] def visit_children(parent) old_parent = @parent - @parent = parent unless is_any_of?(parent, SCRIPT_NODES) + @parent = parent unless is_any_of?(parent, PARENT_CLASSES) old_real_parent, @real_parent = @real_parent, parent super ensure @parent = old_parent @real_parent = old_real_parent @@ -46,37 +46,38 @@ def invalid_charset_parent?(parent, child) "@charset may only be used at the root of a document." unless parent.is_a?(Sass::Tree::RootNode) end - VALID_EXTEND_PARENTS = [Sass::Tree::RuleNode, Sass::Tree::MixinDefNode] + INVALID_EXTEND_PARENTS = [Sass::Tree::RuleNode, Sass::Tree::MixinDefNode] def invalid_extend_parent?(parent, child) - unless is_any_of?(parent, VALID_EXTEND_PARENTS) + unless is_any_of?(parent, INVALID_EXTEND_PARENTS) "Extend directives may only be used within rules." end end def invalid_function_parent?(parent, child) "Functions may only be defined at the root of a document." unless parent.is_a?(Sass::Tree::RootNode) end - VALID_FUNCTION_CHILDREN = [ - Sass::Tree::CommentNode, Sass::Tree::DebugNode, Sass::Tree::ReturnNode, - Sass::Tree::VariableNode, Sass::Tree::WarnNode - ] + CONTROL_NODES + INVALID_FUNCTION_CHILDREN = [ + Sass::Tree::CommentNode, Sass::Tree::DebugNode, Sass::Tree::EachNode, + Sass::Tree::ForNode, Sass::Tree::IfNode, Sass::Tree::ReturnNode, + Sass::Tree::VariableNode, Sass::Tree::WarnNode, Sass::Tree::WhileNode + ] def invalid_function_child?(parent, child) - unless is_any_of?(child, VALID_FUNCTION_CHILDREN) + unless is_any_of?(child, INVALID_FUNCTION_CHILDREN) "Functions can only contain variable declarations and control directives." end end - VALID_IMPORT_PARENTS = [ + INVALID_IMPORT_PARENTS = [ Sass::Tree::IfNode, Sass::Tree::ForNode, Sass::Tree::WhileNode, Sass::Tree::EachNode, Sass::Tree::MixinDefNode ] def invalid_import_parent?(parent, child) - if is_any_of?(@real_parent, VALID_IMPORT_PARENTS) + if is_any_of?(@real_parent, INVALID_IMPORT_PARENTS) return "Import directives may not be used within control directives or mixins." end return if parent.is_a?(Sass::Tree::RootNode) return "CSS import directives may only be used at the root of a document." if child.css_import? # If this is a nested @import, we need to make sure it doesn't have anything @@ -95,20 +96,20 @@ def invalid_mixindef_parent?(parent, child) "Mixins may only be defined at the root of a document." unless parent.is_a?(Sass::Tree::RootNode) end - VALID_PROP_CHILDREN = [Sass::Tree::CommentNode, Sass::Tree::PropNode, Sass::Tree::MixinNode] + CONTROL_NODES + INVALID_PROP_CHILDREN = [Sass::Tree::CommentNode, Sass::Tree::PropNode] def invalid_prop_child?(parent, child) - unless is_any_of?(child, VALID_PROP_CHILDREN) + unless is_any_of?(child, INVALID_PROP_CHILDREN) "Illegal nesting: Only properties may be nested beneath properties." end end - VALID_PROP_PARENTS = [Sass::Tree::RuleNode, Sass::Tree::PropNode, - Sass::Tree::MixinDefNode, Sass::Tree::DirectiveNode] + INVALID_PROP_PARENTS = [Sass::Tree::RuleNode, Sass::Tree::PropNode, + Sass::Tree::MixinDefNode, Sass::Tree::DirectiveNode] def invalid_prop_parent?(parent, child) - unless is_any_of?(parent, VALID_PROP_PARENTS) + unless is_any_of?(parent, INVALID_PROP_PARENTS) "Properties are only allowed within rules, directives, or other properties." + child.pseudo_class_selector_message end end def invalid_return_parent?(parent, child)