### Home Classes Methods

### In Files

- lib/sass/tree/visitors/check_nesting.rb

### Parent

Sass::Tree::Visitors::Base

### Methods

- ::new
- #invalid_charset_parent?
- #invalid_content_parent?
- #invalid_extend_parent?
- #invalid_function_child?
- #invalid_function_parent?
- #invalid_import_parent?
- #invalid_mixindef_parent?
- #invalid_prop_child?
- #invalid_prop_parent?
- #invalid_return_parent?
- #visit
- #visit_children
- #visit_import
- #visit_mixindef
- #visit_root

### Class/Module Index

Quicksearch

- Sass
- Sass::BaseEnvironment
- Sass::CSS
- Sass::CacheStores
- Sass::CacheStores::Base
- Sass::CacheStores::Chain
- Sass::CacheStores::Filesystem
- Sass::CacheStores::Memory
- Sass::CacheStores::Null
- Sass::Callbacks
- Sass::Callbacks::InstanceMethods
- Sass::Engine
- Sass::Engine::Line
- Sass::Environment
- Sass::Exec
- Sass::Exec::Base
- Sass::Exec::SassConvert
- Sass::Exec::SassScss
- Sass::Exec::SassScss::Sass::Plugin.compiler
- Sass::Features
- Sass::Importers
- Sass::Importers::Base
- Sass::Importers::Filesystem
- Sass::Logger
- Sass::Logger::Base
- Sass::Logger::LogLevel
- Sass::Logger::LogLevel::ClassMethods
- Sass::Media
- Sass::Media::Query
- Sass::Media::QueryList
- Sass::Plugin
- Sass::Plugin::Compiler
- Sass::Plugin::Configuration
- Sass::Plugin::MerbBootLoader
- Sass::Plugin::Rack
- Sass::Plugin::StalenessChecker
- Sass::ReadOnlyEnvironment
- Sass::Repl
- Sass::SCSS
- Sass::SCSS::CssParser
- Sass::SCSS::Parser
- Sass::SCSS::RX
- Sass::SCSS::ScriptLexer
- Sass::SCSS::ScriptParser
- Sass::SCSS::StaticParser
- Sass::Script
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Lexer
- Sass::Script::Parser
- Sass::Script::Tree
- Sass::Script::Tree::Funcall
- Sass::Script::Tree::Interpolation
- Sass::Script::Tree::ListLiteral
- Sass::Script::Tree::Literal
- Sass::Script::Tree::MapLiteral
- Sass::Script::Tree::Node
- Sass::Script::Tree::Operation
- Sass::Script::Tree::Selector
- Sass::Script::Tree::StringInterpolation
- Sass::Script::Tree::UnaryOperation
- Sass::Script::Tree::Variable
- Sass::Script::Value
- Sass::Script::Value::ArgList
- Sass::Script::Value::Base
- Sass::Script::Value::Bool
- Sass::Script::Value::Color
- Sass::Script::Value::Helpers
- Sass::Script::Value::List
- Sass::Script::Value::Map
- Sass::Script::Value::Null
- Sass::Script::Value::Number
- Sass::Script::Value::String
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::SemiGlobalEnvironment
- Sass::Shared
- Sass::Source
- Sass::Source::Map
- Sass::Source::Map::Mapping
- Sass::Source::Position
- Sass::Source::Range
- Sass::Stack
- Sass::Stack::Frame
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::AtRootNode
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ErrorNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::KeyframeRuleNode
- Sass::Tree::MediaNode
- Sass::Tree::MixinDefNode
- Sass::Tree::MixinNode
- Sass::Tree::Node
- Sass::Tree::PropNode
- Sass::Tree::ReturnNode
- Sass::Tree::RootNode
- Sass::Tree::RuleNode
- Sass::Tree::SupportsNode
- Sass::Tree::TraceNode
- Sass::Tree::VariableNode
- Sass::Tree::Visitors
- Sass::Tree::Visitors::Base
- Sass::Tree::Visitors::CheckNesting
- Sass::Tree::Visitors::Convert
- Sass::Tree::Visitors::Cssize
- Sass::Tree::Visitors::Cssize::Bubble
- Sass::Tree::Visitors::DeepCopy
- Sass::Tree::Visitors::Extend
- Sass::Tree::Visitors::Perform
- Sass::Tree::Visitors::SetOptions
- Sass::Tree::Visitors::ToCss
- Sass::Tree::WarnNode
- Sass::Tree::WhileNode
- Sass::UnitConversionError
- Sass::Util
- Sass::Util::CrossPlatformRandom
- Sass::Util::MultibyteStringScanner
- Sass::Util::NormalizedMap
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object
- OrderedHash

No matching classes.

# Sass::Tree::Visitors::CheckNesting

A visitor for checking that all nodes are properly nested.

### Constants

CONTROL_NODES
INVALID_IMPORT_PARENTS
SCRIPT_NODES
VALID_EXTEND_PARENTS
VALID_FUNCTION_CHILDREN
VALID_PROP_CHILDREN
VALID_PROP_PARENTS

### Public Class Methods

new() click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 5
    def initialize
      @parents = []
    end

### Protected Instance Methods

invalid_charset_parent?(parent, child) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 87
    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

invalid_content_parent?(parent, child) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 78
    def invalid_content_parent?(parent, child)
      if @current_mixin_def
        @current_mixin_def.has_content = true
        nil
      else
        "@content may only be used within a mixin."
      end
    end

invalid_extend_parent?(parent, child) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 92
    def invalid_extend_parent?(parent, child)
      unless is_any_of?(parent, VALID_EXTEND_PARENTS)
        return "Extend directives may only be used within rules."
      end
    end

invalid_function_child?(parent, child) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 128
    def invalid_function_child?(parent, child)
      unless is_any_of?(child, VALID_FUNCTION_CHILDREN)
        "Functions can only contain variable declarations and control directives."
      end
    end

invalid_function_parent?(parent, child) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 118
    def invalid_function_parent?(parent, child)
      unless (@parents.map {|p| p.class} & INVALID_IMPORT_PARENTS).empty?
        return "Functions may not be defined within control directives or other mixins."
      end
    end

invalid_import_parent?(parent, child) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 100
    def invalid_import_parent?(parent, child)
      unless (@parents.map {|p| p.class} & INVALID_IMPORT_PARENTS).empty?
        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?
    rescue Sass::SyntaxError => e
      e.modify_backtrace(:filename => child.imported_file.options[:filename])
      e.add_backtrace(:filename => child.filename, :line => child.line)
      raise e
    end

invalid_mixindef_parent?(parent, child) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 112
    def invalid_mixindef_parent?(parent, child)
      unless (@parents.map {|p| p.class} & INVALID_IMPORT_PARENTS).empty?
        return "Mixins may not be defined within control directives or other mixins."
      end
    end

invalid_prop_child?(parent, child) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 137
    def invalid_prop_child?(parent, child)
      unless is_any_of?(child, VALID_PROP_CHILDREN)
        "Illegal nesting: Only properties may be nested beneath properties."
      end
    end

invalid_prop_parent?(parent, child) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 145
    def invalid_prop_parent?(parent, child)
      unless is_any_of?(parent, VALID_PROP_PARENTS)
        "Properties are only allowed within rules, directives, mixin includes, or other properties." +
          child.pseudo_class_selector_message
      end
    end

invalid_return_parent?(parent, child) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 152
    def invalid_return_parent?(parent, child)
      "@return may only be used within a function." unless parent.is_a?(Sass::Tree::FunctionNode)
    end

visit(node) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 9
    def visit(node)
      if (error = @parent && (
          try_send(@parent.class.invalid_child_method_name, @parent, node) ||
          try_send(node.class.invalid_parent_method_name, @parent, node)))
        raise Sass::SyntaxError.new(error)
      end
      super
    rescue Sass::SyntaxError => e
      e.modify_backtrace(:filename => node.filename, :line => node.line)
      raise e
    end

visit_children(parent) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 24
    def visit_children(parent)
      old_parent = @parent

      # When checking a static tree, resolve at-roots to be sure they won't send
      # nodes where they don't belong.
      if parent.is_a?(Sass::Tree::AtRootNode) && parent.resolved_value
        old_parents = @parents
        @parents = @parents.reject {|p| parent.exclude_node?(p)}
        @parent = Sass::Util.enum_with_index(@parents.reverse).
          find {|p, i| !transparent_parent?(p, @parents[-i - 2])}.first

        begin
          return super
        ensure
          @parents = old_parents
          @parent = old_parent
        end
      end

      unless transparent_parent?(parent, old_parent)
        @parent = parent
      end

      @parents.push parent
      begin
        super
      ensure
        @parent = old_parent
        @parents.pop
      end
    end

visit_import(node) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 63
    def visit_import(node)
      yield
    rescue Sass::SyntaxError => e
      e.modify_backtrace(:filename => node.children.first.filename)
      e.add_backtrace(:filename => node.filename, :line => node.line)
      raise e
    end

visit_mixindef(node) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 71
    def visit_mixindef(node)
      @current_mixin_def, old_mixin_def = node, @current_mixin_def
      yield
    ensure
      @current_mixin_def = old_mixin_def
    end

visit_root(node) click to toggle source

    # File lib/sass/tree/visitors/check_nesting.rb, line 56
    def visit_root(node)
      yield
    rescue Sass::SyntaxError => e
      e.sass_template ||= node.template
      raise e
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.