diff --git a/lib/sass/embedded/host/value_protofier.rb b/lib/sass/embedded/host/value_protofier.rb index 2efdc0b1..7e454df4 100644 --- a/lib/sass/embedded/host/value_protofier.rb +++ b/lib/sass/embedded/host/value_protofier.rb @@ -96,6 +96,12 @@ def to_proto(obj) ) ) end + when Sass::Value::Mixin + EmbeddedProtocol::Value.new( + compiler_mixin: EmbeddedProtocol::Value::CompilerMixin.new( + id: obj.id + ) + ) when Sass::Value::Calculation EmbeddedProtocol::Value.new( calculation: Calculation.to_proto(obj) @@ -176,6 +182,8 @@ def from_proto(proto) Sass::Value::Function.new(obj.id) when :host_function raise Sass::ScriptError, 'The compiler may not send Value.host_function to host' + when :compiler_mixin + Sass::Value::Mixin.new(obj.id) when :calculation Calculation.from_proto(obj) when :singleton diff --git a/lib/sass/value.rb b/lib/sass/value.rb index 24909366..3b686298 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) @@ -132,6 +138,7 @@ def to_a_length require_relative 'value/function' require_relative 'value/fuzzy_math' require_relative 'value/map' +require_relative 'value/mixin' require_relative 'value/null' require_relative 'value/number' require_relative 'value/string' diff --git a/lib/sass/value/mixin.rb b/lib/sass/value/mixin.rb new file mode 100644 index 00000000..1175b58a --- /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 + @hash ||= id.hash + end + + # @return [Mixin] + def assert_mixin(_name = nil) + self + end + end + end +end