Skip to content

Commit

Permalink
Fix passing argument lists across compilations (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme authored Mar 11, 2025
1 parent f1ff432 commit 0378284
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 41 deletions.
52 changes: 29 additions & 23 deletions lib/sass/compiler/host/protofier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@ def to_proto(obj)
)
)
when Sass::Value::ArgumentList
EmbeddedProtocol::Value.new(
argument_list: EmbeddedProtocol::Value::ArgumentList.new(
id: obj.instance_variable_get(:@id),
contents: obj.to_a.map { |element| to_proto(element) },
keywords: obj.keywords.each_with_object({}) { |(key, value), hash| hash[key.to_s] = to_proto(value) },
separator: ListSeparator.to_proto(obj.separator)
if obj.instance_variable_get(:@environment) == @function_registry.environment
EmbeddedProtocol::Value.new(
argument_list: EmbeddedProtocol::Value::ArgumentList.new(
id: obj.instance_variable_get(:@id)
)
)
)
else
EmbeddedProtocol::Value.new(
argument_list: EmbeddedProtocol::Value::ArgumentList.new(
contents: obj.to_a.map { |element| to_proto(element) },
keywords: obj.keywords.each_with_object({}) { |(key, value), hash| hash[key.to_s] = to_proto(value) },
separator: ListSeparator.to_proto(obj.separator)
)
)
end
when Sass::Value::List
EmbeddedProtocol::Value.new(
list: EmbeddedProtocol::Value::List.new(
Expand Down Expand Up @@ -125,18 +132,18 @@ def from_proto(proto)
obj.has_alpha? ? obj.alpha : nil
)
when :argument_list
Sass::Value::ArgumentList.new(
obj.contents.map do |element|
from_proto(element)
end,
obj.keywords.to_enum.with_object({}) do |(key, value), hash|
hash[key.to_sym] = from_proto(value)
end,
ListSeparator.from_proto(obj.separator)
).instance_eval do
@id = obj.id
self
end
compiler_value(
Sass::Value::ArgumentList.new(
obj.contents.map do |element|
from_proto(element)
end,
obj.keywords.to_enum.with_object({}) do |(key, value), hash|
hash[key.to_sym] = from_proto(value)
end,
ListSeparator.from_proto(obj.separator)
),
obj.id
)
when :list
Sass::Value::List.new(
obj.contents.map do |element|
Expand All @@ -152,11 +159,11 @@ def from_proto(proto)
end
)
when :compiler_function
compiler_value(Sass::Value::Function, obj.id)
compiler_value(Sass::Value::Function.allocate, obj.id)
when :host_function
raise Sass::ScriptError, 'The compiler may not send Value.host_function to host'
when :compiler_mixin
compiler_value(Sass::Value::Mixin, obj.id)
compiler_value(Sass::Value::Mixin.allocate, obj.id)
when :calculation
Calculation.from_proto(obj)
when :singleton
Expand Down Expand Up @@ -185,8 +192,7 @@ def assert_compiler_value(value)
value
end

def compiler_value(klass, id)
value = klass.allocate
def compiler_value(value, id)
value.instance_variable_set(:@environment, @function_registry.environment)
value.instance_variable_set(:@id, id)
value
Expand Down
8 changes: 0 additions & 8 deletions lib/sass/value/argument_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class ArgumentList < List
def initialize(contents = [], keywords = {}, separator = ',')
super(contents, separator:)

@id = 0
@keywords_accessed = false
@keywords = keywords.freeze
end
Expand All @@ -25,13 +24,6 @@ def keywords
@keywords_accessed = true
@keywords
end

private

def initialize_dup(orig)
@id = 0
super
end
end
end
end
12 changes: 2 additions & 10 deletions spec/sass_proto_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@

RSpec.describe Sass do
def remote_eq(lhs, rhs)
to_host_value = lambda { |value|
if value.is_a?(Sass::Value::ArgumentList)
value.dup
else
value
end
}

result = nil
Sass.compile_string(
'$_: yield(lhs()==rhs());',
Expand All @@ -21,10 +13,10 @@ def remote_eq(lhs, rhs)
Sass::Value::Null::NULL
},
'lhs()' => lambda { |*|
to_host_value.call lhs
lhs
},
'rhs()' => lambda { |*|
to_host_value.call rhs
rhs
}
}
)
Expand Down

0 comments on commit 0378284

Please sign in to comment.