Sha256: fe78377253381e6a1d6cfca0e5e93cff7573d8e833563fd3012fc8297557f190

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 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 Selector 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

1 entries across 1 versions & 1 rubygems

Version Path
scss-lint-0.29.0 lib/scss_lint/sass/script.rb