Skip to content

Commit 0378284

Browse files
authored
Fix passing argument lists across compilations (#298)
1 parent f1ff432 commit 0378284

File tree

3 files changed

+31
-41
lines changed

3 files changed

+31
-41
lines changed

lib/sass/compiler/host/protofier.rb

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,21 @@ def to_proto(obj)
3535
)
3636
)
3737
when Sass::Value::ArgumentList
38-
EmbeddedProtocol::Value.new(
39-
argument_list: EmbeddedProtocol::Value::ArgumentList.new(
40-
id: obj.instance_variable_get(:@id),
41-
contents: obj.to_a.map { |element| to_proto(element) },
42-
keywords: obj.keywords.each_with_object({}) { |(key, value), hash| hash[key.to_s] = to_proto(value) },
43-
separator: ListSeparator.to_proto(obj.separator)
38+
if obj.instance_variable_get(:@environment) == @function_registry.environment
39+
EmbeddedProtocol::Value.new(
40+
argument_list: EmbeddedProtocol::Value::ArgumentList.new(
41+
id: obj.instance_variable_get(:@id)
42+
)
4443
)
45-
)
44+
else
45+
EmbeddedProtocol::Value.new(
46+
argument_list: EmbeddedProtocol::Value::ArgumentList.new(
47+
contents: obj.to_a.map { |element| to_proto(element) },
48+
keywords: obj.keywords.each_with_object({}) { |(key, value), hash| hash[key.to_s] = to_proto(value) },
49+
separator: ListSeparator.to_proto(obj.separator)
50+
)
51+
)
52+
end
4653
when Sass::Value::List
4754
EmbeddedProtocol::Value.new(
4855
list: EmbeddedProtocol::Value::List.new(
@@ -125,18 +132,18 @@ def from_proto(proto)
125132
obj.has_alpha? ? obj.alpha : nil
126133
)
127134
when :argument_list
128-
Sass::Value::ArgumentList.new(
129-
obj.contents.map do |element|
130-
from_proto(element)
131-
end,
132-
obj.keywords.to_enum.with_object({}) do |(key, value), hash|
133-
hash[key.to_sym] = from_proto(value)
134-
end,
135-
ListSeparator.from_proto(obj.separator)
136-
).instance_eval do
137-
@id = obj.id
138-
self
139-
end
135+
compiler_value(
136+
Sass::Value::ArgumentList.new(
137+
obj.contents.map do |element|
138+
from_proto(element)
139+
end,
140+
obj.keywords.to_enum.with_object({}) do |(key, value), hash|
141+
hash[key.to_sym] = from_proto(value)
142+
end,
143+
ListSeparator.from_proto(obj.separator)
144+
),
145+
obj.id
146+
)
140147
when :list
141148
Sass::Value::List.new(
142149
obj.contents.map do |element|
@@ -152,11 +159,11 @@ def from_proto(proto)
152159
end
153160
)
154161
when :compiler_function
155-
compiler_value(Sass::Value::Function, obj.id)
162+
compiler_value(Sass::Value::Function.allocate, obj.id)
156163
when :host_function
157164
raise Sass::ScriptError, 'The compiler may not send Value.host_function to host'
158165
when :compiler_mixin
159-
compiler_value(Sass::Value::Mixin, obj.id)
166+
compiler_value(Sass::Value::Mixin.allocate, obj.id)
160167
when :calculation
161168
Calculation.from_proto(obj)
162169
when :singleton
@@ -185,8 +192,7 @@ def assert_compiler_value(value)
185192
value
186193
end
187194

188-
def compiler_value(klass, id)
189-
value = klass.allocate
195+
def compiler_value(value, id)
190196
value.instance_variable_set(:@environment, @function_registry.environment)
191197
value.instance_variable_set(:@id, id)
192198
value

lib/sass/value/argument_list.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class ArgumentList < List
1515
def initialize(contents = [], keywords = {}, separator = ',')
1616
super(contents, separator:)
1717

18-
@id = 0
1918
@keywords_accessed = false
2019
@keywords = keywords.freeze
2120
end
@@ -25,13 +24,6 @@ def keywords
2524
@keywords_accessed = true
2625
@keywords
2726
end
28-
29-
private
30-
31-
def initialize_dup(orig)
32-
@id = 0
33-
super
34-
end
3527
end
3628
end
3729
end

spec/sass_proto_spec.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44

55
RSpec.describe Sass do
66
def remote_eq(lhs, rhs)
7-
to_host_value = lambda { |value|
8-
if value.is_a?(Sass::Value::ArgumentList)
9-
value.dup
10-
else
11-
value
12-
end
13-
}
14-
157
result = nil
168
Sass.compile_string(
179
'$_: yield(lhs()==rhs());',
@@ -21,10 +13,10 @@ def remote_eq(lhs, rhs)
2113
Sass::Value::Null::NULL
2214
},
2315
'lhs()' => lambda { |*|
24-
to_host_value.call lhs
16+
lhs
2517
},
2618
'rhs()' => lambda { |*|
27-
to_host_value.call rhs
19+
rhs
2820
}
2921
}
3022
)

0 commit comments

Comments
 (0)