Skip to content

Commit

Permalink
Support first class mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Sep 29, 2023
1 parent f073652 commit 77274ac
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/sass/value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ def assert_map(name = nil)
raise Sass::ScriptError.new("#{self} is not a map", name)
end

# @return [Mixin]
# @raise [ScriptError]
def assert_mixin(name = nil)
raise Sass::ScriptError.new("#{self} is not a mixin", name)
end

# @return [Number]
# @raise [ScriptError]
def assert_number(name = nil)
Expand Down
2 changes: 0 additions & 2 deletions lib/sass/value/function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module Value
class Function
include Value

# @overload initialize(id)
# @param id [Numeric]
# @overload initialize(signature, callback)
# @param signature [::String]
# @param callback [Proc]
Expand Down
39 changes: 39 additions & 0 deletions lib/sass/value/mixin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

module Sass
module Value
# Sass's mixin type.
#
# @see https://sass-lang.com/documentation/js-api/classes/sassmixin/
class Mixin
include Value

# @!visibility private
def initialize(id)
@id = id
end

# @return [Integer, nil]
attr_reader :id

# @return [::Boolean]
def ==(other)
if id.nil?
other.equal? self
else
other.is_a?(Sass::Value::Mixin) && other.id == id
end
end

# @return [Integer]
def hash
id.hash
end

# @return [Mixin]
def assert_mixin(_name = nil)
self
end
end
end
end

0 comments on commit 77274ac

Please sign in to comment.