From b070fd91fd3c9e9aa32535f5bc4548f6de7ad520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Fri, 29 Sep 2023 09:17:57 -0700 Subject: [PATCH] Support first class mixins --- lib/sass/value.rb | 6 ++++++ lib/sass/value/function.rb | 2 -- lib/sass/value/mixin.rb | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 lib/sass/value/mixin.rb diff --git a/lib/sass/value.rb b/lib/sass/value.rb index 24909366..82928db5 100644 --- a/lib/sass/value.rb +++ b/lib/sass/value.rb @@ -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) diff --git a/lib/sass/value/function.rb b/lib/sass/value/function.rb index 3d412c92..8873d6a7 100644 --- a/lib/sass/value/function.rb +++ b/lib/sass/value/function.rb @@ -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] diff --git a/lib/sass/value/mixin.rb b/lib/sass/value/mixin.rb new file mode 100644 index 00000000..1626f36a --- /dev/null +++ b/lib/sass/value/mixin.rb @@ -0,0 +1,35 @@ +# 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] + attr_reader :id + + # @return [::Boolean] + def ==(other) + other.is_a?(Sass::Value::Mixin) && other.id == id + end + + # @return [Integer] + def hash + id.hash + end + + # @return [Mixin] + def assert_mixin(_name = nil) + self + end + end + end +end