Sha256: 640543aa87f61994a1ca8cbfacfeef7722de3be6a5dbcf5a0a494dbf0c1003bc

Contents?: true

Size: 1.64 KB

Versions: 6

Compression:

Stored size: 1.64 KB

Contents

module Sass::Script::Value
  # A SassScript object representing a `false` value that came from a call to
  # `index()`. It will print deprecation warnings if it's used with `==`.
  class DeprecatedFalse < Bool
    def self.new(environment)
      obj = allocate
      obj.send(:initialize, environment)
      obj
    end

    def initialize(environment)
      @value = false
      @global_env = environment.global_env
      if (frame = environment.stack.frames.last)
        @filename = frame.filename
        @line = frame.line
      end
    end

    def eq(other)
      if other.value == false && !warned?
        self.warned = true
        Sass::Util.sass_warn <<WARNING + @global_env.stack.to_s.gsub(/^/, '        ')
DEPRECATION WARNING: The return value of index() will change from "false" to
"null" in future versions of Sass. For compatibility, avoid using "== false" on
the return value. For example, instead of "@if index(...) == false", just write
"@if index(...)".
WARNING
      end
      Bool.new(other.value == false)
    end

    def neq(other)
      if other.value.nil? && !warned?
        self.warned = true
        Sass::Util.sass_warn <<WARNING + @global_env.stack.to_s.gsub(/^/, '        ')
DEPRECATION WARNING: The return value of index() will change from "false" to
"null" in future versions of Sass. For compatibility, avoid using "!= null" on
the return value.
WARNING
      end
      Bool.new(other.value != false)
    end

    private

    def warned?
      @global_env.deprecated_false_warning_given.include?([@filename, @line])
    end

    def warned=(value)
      @global_env.deprecated_false_warning_given << [@filename, @line]
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sass-3.3.3 lib/sass/script/value/deprecated_false.rb
sass-3.3.2 lib/sass/script/value/deprecated_false.rb
sass-3.3.1 lib/sass/script/value/deprecated_false.rb
sass-3.3.0 lib/sass/script/value/deprecated_false.rb
sass-3.3.0.rc.6 lib/sass/script/value/deprecated_false.rb
sass-3.3.0.rc.5 lib/sass/script/value/deprecated_false.rb