Sha256: a361258bbf780549bdc9e54ce5fd82dcc2145192101ad41dbcf0e72d4fdf3dbe

Contents?: true

Size: 1.87 KB

Versions: 17

Compression:

Stored size: 1.87 KB

Contents

# Ignore documentation lints as these aren't original implementations.
# rubocop:disable Documentation

module Sass::Script
  # Since the Sass library is already loaded at this point.
  # Define the `node_name` and `visit_method` class methods for each Sass Script
  # parse tree node type so that our custom visitor can seamless traverse the
  # tree.
  #
  # This would be easier if we could just define an `inherited` callback, but
  # that won't work since the Sass library will have already been loaded before
  # this code gets loaded, so the `inherited` callback won't be fired.
  #
  # Thus we are left to manually define the methods for each type explicitly.
  {
    'Value' => %w[ArgList Bool Color List Map Null Number String],
    'Tree'  => %w[Funcall Interpolation ListLiteral Literal MapLiteral
                  Operation StringInterpolation UnaryOperation Variable],
  }.each do |namespace, types|
    types.each do |type|
      node_name = type.downcase

      eval <<-DECL
        class #{namespace}::#{type}
          def self.node_name
            :script_#{node_name}
          end

          def self.visit_method
            :visit_script_#{node_name}
          end
        end
      DECL
    end
  end

  class Value::Base
    attr_accessor :node_parent

    def children
      []
    end

    def line
      @line || (node_parent && node_parent.line)
    end

    def source_range
      @source_range || (node_parent && node_parent.source_range)
    end
  end

  # Contains extensions of Sass::Script::Tree::Nodes to add support for
  # accessing various parts of the parse tree not provided out-of-the-box.
  module Tree
    class Node
      attr_accessor :node_parent
    end

    class Literal
      # Literals wrap their underlying values. For sake of convenience, consider
      # the wrapped value a child of the Literal.
      def children
        [value]
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
scss-lint-0.28.0 lib/scss_lint/sass/script.rb
scss-lint-0.27.0 lib/scss_lint/sass/script.rb
scss-lint-0.26.2 lib/scss_lint/sass/script.rb
scss-lint-0.26.1 lib/scss_lint/sass/script.rb
scss-lint-0.26.0 lib/scss_lint/sass/script.rb
scss-lint-0.25.1 lib/scss_lint/sass/script.rb
scss-lint-0.25.0 lib/scss_lint/sass/script.rb
scss-lint-0.24.1 lib/scss_lint/sass/script.rb
scss-lint-0.24.0 lib/scss_lint/sass/script.rb
scss-lint-0.23.1 lib/scss_lint/sass/script.rb
scss-lint-0.23.0 lib/scss_lint/sass/script.rb
scss-lint-0.22.0 lib/scss_lint/sass/script.rb
scss-lint-0.21.0 lib/scss_lint/sass/script.rb
scss-lint-0.20.3 lib/scss_lint/sass/script.rb
scss-lint-0.20.2 lib/scss_lint/sass/script.rb
scss-lint-0.20.1 lib/scss_lint/sass/script.rb
scss-lint-0.20.0 lib/scss_lint/sass/script.rb