diff --git a/lib/sassc/embedded.rb b/lib/sassc/embedded.rb index 45f1479..f89d7c4 100644 --- a/lib/sassc/embedded.rb +++ b/lib/sassc/embedded.rb @@ -139,8 +139,6 @@ class FunctionsHandler remove_method(:setup) if public_method_defined?(:setup, false) def setup(_native_options, functions: Script::Functions) - @callbacks = {} - functions_wrapper = Class.new do attr_accessor :options @@ -148,7 +146,7 @@ def setup(_native_options, functions: Script::Functions) end.new functions_wrapper.options = @options - Script.custom_functions(functions:).each do |custom_function| + Script.custom_functions(functions:).map.with_object({}) do |custom_function, callbacks| callback = lambda do |native_argument_list| function_arguments = arguments_from_native_list(native_argument_list) begin @@ -162,10 +160,8 @@ def setup(_native_options, functions: Script::Functions) raise e end - @callbacks[Script.formatted_function_name(custom_function, functions:)] = callback + callbacks[Script.formatted_function_name(custom_function, functions:)] = callback end - - @callbacks end private @@ -375,8 +371,7 @@ def import_to_native(import, parent_dir, from_import, canonicalize) canonical_url = Uri.path_to_file_url(File.absolute_path(import.path, parent_dir)) @importer_results[canonical_url] = if import.source.is_a?(Hash) { - contents: import.source[:contents], - syntax: import.source[:syntax], + **import.source, source_map_url: canonical_url } else @@ -500,7 +495,7 @@ def self.from_native(value, options) ) when ::Sass::Value::Map ::SassC::Script::Value::Map.new( - value.contents.to_a.to_h { |k, v| [from_native(k, options), from_native(v, options)] } + value.contents.map.with_object({}) { |(k, v), h| h[from_native(k, options)] = from_native(v, options) } ) when ::Sass::Value::Number ::SassC::Script::Value::Number.new( @@ -563,7 +558,7 @@ def self.to_native(value) ) when ::SassC::Script::Value::Map ::Sass::Value::Map.new( - value.value.to_a.to_h { |k, v| [to_native(k), to_native(v)] } + value.value.map.with_object({}) { |(k, v), h| h[to_native(k)] = to_native(v) } ) when ::SassC::Script::Value::Number ::Sass::Value::Number.new( @@ -629,8 +624,8 @@ def parse(...) decode_uri_hash_with_preserve_escaped = if unescaped.nil? || unescaped.empty? decode_uri_hash else - decode_uri_hash.to_h do |key, value| - [key, unescaped.include?(value) ? key : value] + decode_uri_hash.map.with_object({}) do |(key, value), hash| + hash[key] = unescaped.include?(value) ? key : value end.freeze end