sass-embedded 1.74.1-riscv64-linux-gnu
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +48 -0
- data/exe/sass +21 -0
- data/ext/sass/cli.rb +12 -0
- data/ext/sass/dart-sass/sass +20 -0
- data/ext/sass/dart-sass/src/LICENSE +1687 -0
- data/ext/sass/dart-sass/src/dart +0 -0
- data/ext/sass/dart-sass/src/sass.snapshot +0 -0
- data/ext/sass/embedded_sass_pb.rb +63 -0
- data/lib/sass/calculation_value/calculation_operation.rb +49 -0
- data/lib/sass/calculation_value.rb +22 -0
- data/lib/sass/canonicalize_context.rb +21 -0
- data/lib/sass/compile_result.rb +24 -0
- data/lib/sass/compiler/channel.rb +68 -0
- data/lib/sass/compiler/connection.rb +92 -0
- data/lib/sass/compiler/dispatcher.rb +115 -0
- data/lib/sass/compiler/host/function_registry.rb +87 -0
- data/lib/sass/compiler/host/importer_registry.rb +137 -0
- data/lib/sass/compiler/host/logger_registry.rb +55 -0
- data/lib/sass/compiler/host/protofier.rb +390 -0
- data/lib/sass/compiler/host/structifier.rb +37 -0
- data/lib/sass/compiler/host.rb +226 -0
- data/lib/sass/compiler/varint.rb +39 -0
- data/lib/sass/compiler.rb +212 -0
- data/lib/sass/elf.rb +276 -0
- data/lib/sass/embedded/version.rb +7 -0
- data/lib/sass/embedded.rb +107 -0
- data/lib/sass/embedded_protocol.rb +10 -0
- data/lib/sass/exception.rb +69 -0
- data/lib/sass/fork_tracker.rb +51 -0
- data/lib/sass/logger/silent.rb +28 -0
- data/lib/sass/logger/source_location.rb +22 -0
- data/lib/sass/logger/source_span.rb +28 -0
- data/lib/sass/node_package_importer.rb +17 -0
- data/lib/sass/serializer.rb +36 -0
- data/lib/sass/value/argument_list.rb +37 -0
- data/lib/sass/value/boolean.rb +52 -0
- data/lib/sass/value/calculation.rb +90 -0
- data/lib/sass/value/color.rb +253 -0
- data/lib/sass/value/function.rb +51 -0
- data/lib/sass/value/fuzzy_math.rb +80 -0
- data/lib/sass/value/list.rb +79 -0
- data/lib/sass/value/map.rb +71 -0
- data/lib/sass/value/mixin.rb +36 -0
- data/lib/sass/value/null.rb +48 -0
- data/lib/sass/value/number/unit.rb +186 -0
- data/lib/sass/value/number.rb +366 -0
- data/lib/sass/value/string.rb +61 -0
- data/lib/sass/value.rb +136 -0
- data/lib/sass-embedded.rb +4 -0
- metadata +120 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
class Compiler
|
5
|
+
class Host
|
6
|
+
# The {ImporterRegistry} class.
|
7
|
+
#
|
8
|
+
# It stores importers and handles import requests.
|
9
|
+
class ImporterRegistry
|
10
|
+
attr_reader :importers
|
11
|
+
|
12
|
+
def initialize(importers, load_paths, alert_color:)
|
13
|
+
@id = 0
|
14
|
+
@importers_by_id = {}.compare_by_identity
|
15
|
+
@importers = importers
|
16
|
+
.map { |importer| register(importer) }
|
17
|
+
.concat(
|
18
|
+
load_paths.map do |load_path|
|
19
|
+
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
20
|
+
path: File.absolute_path(load_path)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
)
|
24
|
+
|
25
|
+
@highlight = alert_color
|
26
|
+
end
|
27
|
+
|
28
|
+
def register(importer)
|
29
|
+
if importer.is_a?(Sass::NodePackageImporter)
|
30
|
+
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
31
|
+
node_package_importer: EmbeddedProtocol::NodePackageImporter.new(
|
32
|
+
entry_point_directory: importer.instance_eval { @entry_point_directory }
|
33
|
+
)
|
34
|
+
)
|
35
|
+
else
|
36
|
+
importer = Structifier.to_struct(importer, :canonicalize, :load, :non_canonical_scheme, :find_file_url)
|
37
|
+
|
38
|
+
is_importer = importer.respond_to?(:canonicalize) && importer.respond_to?(:load)
|
39
|
+
is_file_importer = importer.respond_to?(:find_file_url)
|
40
|
+
|
41
|
+
raise ArgumentError, 'importer must be an Importer or a FileImporter' if is_importer == is_file_importer
|
42
|
+
|
43
|
+
id = @id
|
44
|
+
@id = id.next
|
45
|
+
|
46
|
+
@importers_by_id[id] = importer
|
47
|
+
if is_importer
|
48
|
+
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
49
|
+
importer_id: id,
|
50
|
+
non_canonical_scheme: if importer.respond_to?(:non_canonical_scheme)
|
51
|
+
non_canonical_scheme = importer.non_canonical_scheme
|
52
|
+
if non_canonical_scheme.is_a?(String)
|
53
|
+
[non_canonical_scheme]
|
54
|
+
else
|
55
|
+
non_canonical_scheme || []
|
56
|
+
end
|
57
|
+
else
|
58
|
+
[]
|
59
|
+
end
|
60
|
+
)
|
61
|
+
else
|
62
|
+
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
63
|
+
file_importer_id: id
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def canonicalize(canonicalize_request)
|
70
|
+
importer = @importers_by_id[canonicalize_request.importer_id]
|
71
|
+
url = importer.canonicalize(canonicalize_request.url,
|
72
|
+
CanonicalizeContext.new(canonicalize_request))&.to_s
|
73
|
+
|
74
|
+
EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
75
|
+
id: canonicalize_request.id,
|
76
|
+
url:
|
77
|
+
)
|
78
|
+
rescue StandardError => e
|
79
|
+
EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
80
|
+
id: canonicalize_request.id,
|
81
|
+
error: e.full_message(highlight: @highlight, order: :top)
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
def import(import_request)
|
86
|
+
importer = @importers_by_id[import_request.importer_id]
|
87
|
+
importer_result = Structifier.to_struct importer.load(import_request.url), :contents, :syntax, :source_map_url
|
88
|
+
|
89
|
+
EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
90
|
+
id: import_request.id,
|
91
|
+
success: EmbeddedProtocol::InboundMessage::ImportResponse::ImportSuccess.new(
|
92
|
+
contents: importer_result.contents.to_str,
|
93
|
+
syntax: syntax_to_proto(importer_result.syntax),
|
94
|
+
source_map_url: (importer_result.source_map_url&.to_s if importer_result.respond_to?(:source_map_url))
|
95
|
+
)
|
96
|
+
)
|
97
|
+
rescue StandardError => e
|
98
|
+
EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
99
|
+
id: import_request.id,
|
100
|
+
error: e.full_message(highlight: @highlight, order: :top)
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
def file_import(file_import_request)
|
105
|
+
importer = @importers_by_id[file_import_request.importer_id]
|
106
|
+
file_url = importer.find_file_url(file_import_request.url,
|
107
|
+
CanonicalizeContext.new(file_import_request))&.to_s
|
108
|
+
|
109
|
+
EmbeddedProtocol::InboundMessage::FileImportResponse.new(
|
110
|
+
id: file_import_request.id,
|
111
|
+
file_url:
|
112
|
+
)
|
113
|
+
rescue StandardError => e
|
114
|
+
EmbeddedProtocol::InboundMessage::FileImportResponse.new(
|
115
|
+
id: file_import_request.id,
|
116
|
+
error: e.full_message(highlight: @highlight, order: :top)
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
def syntax_to_proto(syntax)
|
121
|
+
case syntax&.to_sym
|
122
|
+
when :scss
|
123
|
+
EmbeddedProtocol::Syntax::SCSS
|
124
|
+
when :indented
|
125
|
+
EmbeddedProtocol::Syntax::INDENTED
|
126
|
+
when :css
|
127
|
+
EmbeddedProtocol::Syntax::CSS
|
128
|
+
else
|
129
|
+
raise ArgumentError, 'syntax must be one of :scss, :indented, :css'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
private_constant :ImporterRegistry
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
class Compiler
|
5
|
+
class Host
|
6
|
+
# The {LoggerRegistry} class.
|
7
|
+
#
|
8
|
+
# It stores logger and handles log events.
|
9
|
+
class LoggerRegistry
|
10
|
+
def initialize(logger)
|
11
|
+
logger = Structifier.to_struct(logger, :debug, :warn)
|
12
|
+
|
13
|
+
if logger.respond_to?(:debug)
|
14
|
+
define_singleton_method(:debug) do |event|
|
15
|
+
logger.debug(event.message,
|
16
|
+
span: event.span.nil? ? nil : Logger::SourceSpan.new(event.span))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if logger.respond_to?(:warn) # rubocop:disable Style/GuardClause
|
21
|
+
define_singleton_method(:warn) do |event|
|
22
|
+
logger.warn(event.message,
|
23
|
+
deprecation: event.type == :DEPRECATION_WARNING,
|
24
|
+
span: event.span.nil? ? nil : Logger::SourceSpan.new(event.span),
|
25
|
+
stack: event.stack_trace)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def log(event)
|
31
|
+
case event.type
|
32
|
+
when :DEBUG
|
33
|
+
debug(event)
|
34
|
+
when :DEPRECATION_WARNING, :WARNING
|
35
|
+
warn(event)
|
36
|
+
else
|
37
|
+
raise ArgumentError, "Unknown LogEvent.type #{event.type}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def debug(event)
|
44
|
+
Kernel.warn(event.formatted)
|
45
|
+
end
|
46
|
+
|
47
|
+
def warn(event)
|
48
|
+
Kernel.warn(event.formatted)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private_constant :LoggerRegistry
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,390 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
class Compiler
|
5
|
+
class Host
|
6
|
+
# The {Protofier} class.
|
7
|
+
#
|
8
|
+
# It converts Pure Ruby types and Protobuf Ruby types.
|
9
|
+
class Protofier
|
10
|
+
def initialize(function_registry)
|
11
|
+
@function_registry = function_registry
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_proto(obj)
|
15
|
+
case obj
|
16
|
+
when Sass::Value::String
|
17
|
+
EmbeddedProtocol::Value.new(
|
18
|
+
string: EmbeddedProtocol::Value::String.new(
|
19
|
+
text: obj.text.to_str,
|
20
|
+
quoted: obj.quoted?
|
21
|
+
)
|
22
|
+
)
|
23
|
+
when Sass::Value::Number
|
24
|
+
EmbeddedProtocol::Value.new(
|
25
|
+
number: Number.to_proto(obj)
|
26
|
+
)
|
27
|
+
when Sass::Value::Color
|
28
|
+
if obj.instance_eval { !defined?(@hue) }
|
29
|
+
EmbeddedProtocol::Value.new(
|
30
|
+
rgb_color: EmbeddedProtocol::Value::RgbColor.new(
|
31
|
+
red: obj.red,
|
32
|
+
green: obj.green,
|
33
|
+
blue: obj.blue,
|
34
|
+
alpha: obj.alpha.to_f
|
35
|
+
)
|
36
|
+
)
|
37
|
+
elsif obj.instance_eval { !defined?(@saturation) }
|
38
|
+
EmbeddedProtocol::Value.new(
|
39
|
+
hwb_color: EmbeddedProtocol::Value::HwbColor.new(
|
40
|
+
hue: obj.hue.to_f,
|
41
|
+
whiteness: obj.whiteness.to_f,
|
42
|
+
blackness: obj.blackness.to_f,
|
43
|
+
alpha: obj.alpha.to_f
|
44
|
+
)
|
45
|
+
)
|
46
|
+
else
|
47
|
+
EmbeddedProtocol::Value.new(
|
48
|
+
hsl_color: EmbeddedProtocol::Value::HslColor.new(
|
49
|
+
hue: obj.hue.to_f,
|
50
|
+
saturation: obj.saturation.to_f,
|
51
|
+
lightness: obj.lightness.to_f,
|
52
|
+
alpha: obj.alpha.to_f
|
53
|
+
)
|
54
|
+
)
|
55
|
+
end
|
56
|
+
when Sass::Value::ArgumentList
|
57
|
+
EmbeddedProtocol::Value.new(
|
58
|
+
argument_list: EmbeddedProtocol::Value::ArgumentList.new(
|
59
|
+
id: obj.instance_eval { @id },
|
60
|
+
contents: obj.to_a.map { |element| to_proto(element) },
|
61
|
+
keywords: obj.keywords.to_h { |key, value| [key.to_s, to_proto(value)] },
|
62
|
+
separator: ListSeparator.to_proto(obj.separator)
|
63
|
+
)
|
64
|
+
)
|
65
|
+
when Sass::Value::List
|
66
|
+
EmbeddedProtocol::Value.new(
|
67
|
+
list: EmbeddedProtocol::Value::List.new(
|
68
|
+
contents: obj.to_a.map { |element| to_proto(element) },
|
69
|
+
separator: ListSeparator.to_proto(obj.separator),
|
70
|
+
has_brackets: obj.bracketed?
|
71
|
+
)
|
72
|
+
)
|
73
|
+
when Sass::Value::Map
|
74
|
+
EmbeddedProtocol::Value.new(
|
75
|
+
map: EmbeddedProtocol::Value::Map.new(
|
76
|
+
entries: obj.contents.map do |key, value|
|
77
|
+
EmbeddedProtocol::Value::Map::Entry.new(
|
78
|
+
key: to_proto(key),
|
79
|
+
value: to_proto(value)
|
80
|
+
)
|
81
|
+
end
|
82
|
+
)
|
83
|
+
)
|
84
|
+
when Sass::Value::Function
|
85
|
+
if obj.instance_eval { @id }
|
86
|
+
EmbeddedProtocol::Value.new(
|
87
|
+
compiler_function: EmbeddedProtocol::Value::CompilerFunction.new(
|
88
|
+
id: obj.instance_eval { @id }
|
89
|
+
)
|
90
|
+
)
|
91
|
+
else
|
92
|
+
EmbeddedProtocol::Value.new(
|
93
|
+
host_function: EmbeddedProtocol::Value::HostFunction.new(
|
94
|
+
id: @function_registry.register(obj.callback),
|
95
|
+
signature: obj.signature
|
96
|
+
)
|
97
|
+
)
|
98
|
+
end
|
99
|
+
when Sass::Value::Mixin
|
100
|
+
EmbeddedProtocol::Value.new(
|
101
|
+
compiler_mixin: EmbeddedProtocol::Value::CompilerMixin.new(
|
102
|
+
id: obj.instance_eval { @id }
|
103
|
+
)
|
104
|
+
)
|
105
|
+
when Sass::Value::Calculation
|
106
|
+
EmbeddedProtocol::Value.new(
|
107
|
+
calculation: Calculation.to_proto(obj)
|
108
|
+
)
|
109
|
+
when Sass::Value::Boolean
|
110
|
+
EmbeddedProtocol::Value.new(
|
111
|
+
singleton: obj.value ? :TRUE : :FALSE
|
112
|
+
)
|
113
|
+
when Sass::Value::Null
|
114
|
+
EmbeddedProtocol::Value.new(
|
115
|
+
singleton: :NULL
|
116
|
+
)
|
117
|
+
else
|
118
|
+
raise Sass::ScriptError, "Unknown Sass::Value #{obj}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def from_proto(proto)
|
123
|
+
oneof = proto.value
|
124
|
+
obj = proto.public_send(oneof)
|
125
|
+
case oneof
|
126
|
+
when :string
|
127
|
+
Sass::Value::String.new(
|
128
|
+
obj.text,
|
129
|
+
quoted: obj.quoted
|
130
|
+
)
|
131
|
+
when :number
|
132
|
+
Number.from_proto(obj)
|
133
|
+
when :rgb_color
|
134
|
+
Sass::Value::Color.new(
|
135
|
+
red: obj.red,
|
136
|
+
green: obj.green,
|
137
|
+
blue: obj.blue,
|
138
|
+
alpha: obj.alpha
|
139
|
+
)
|
140
|
+
when :hsl_color
|
141
|
+
Sass::Value::Color.new(
|
142
|
+
hue: obj.hue,
|
143
|
+
saturation: obj.saturation,
|
144
|
+
lightness: obj.lightness,
|
145
|
+
alpha: obj.alpha
|
146
|
+
)
|
147
|
+
when :hwb_color
|
148
|
+
Sass::Value::Color.new(
|
149
|
+
hue: obj.hue,
|
150
|
+
whiteness: obj.whiteness,
|
151
|
+
blackness: obj.blackness,
|
152
|
+
alpha: obj.alpha
|
153
|
+
)
|
154
|
+
when :argument_list
|
155
|
+
Sass::Value::ArgumentList.new(
|
156
|
+
obj.contents.map do |element|
|
157
|
+
from_proto(element)
|
158
|
+
end,
|
159
|
+
obj.keywords.entries.to_h do |key, value|
|
160
|
+
[key.to_sym, from_proto(value)]
|
161
|
+
end,
|
162
|
+
ListSeparator.from_proto(obj.separator)
|
163
|
+
).instance_eval do
|
164
|
+
@id = obj.id
|
165
|
+
self
|
166
|
+
end
|
167
|
+
when :list
|
168
|
+
Sass::Value::List.new(
|
169
|
+
obj.contents.map do |element|
|
170
|
+
from_proto(element)
|
171
|
+
end,
|
172
|
+
separator: ListSeparator.from_proto(obj.separator),
|
173
|
+
bracketed: obj.has_brackets
|
174
|
+
)
|
175
|
+
when :map
|
176
|
+
Sass::Value::Map.new(
|
177
|
+
obj.entries.to_h do |entry|
|
178
|
+
[from_proto(entry.key), from_proto(entry.value)]
|
179
|
+
end
|
180
|
+
)
|
181
|
+
when :compiler_function
|
182
|
+
Sass::Value::Function.new(nil).instance_eval do
|
183
|
+
@id = obj.id
|
184
|
+
self
|
185
|
+
end
|
186
|
+
when :host_function
|
187
|
+
raise Sass::ScriptError, 'The compiler may not send Value.host_function to host'
|
188
|
+
when :compiler_mixin
|
189
|
+
Sass::Value::Mixin.send(:new).instance_eval do
|
190
|
+
@id = obj.id
|
191
|
+
self
|
192
|
+
end
|
193
|
+
when :calculation
|
194
|
+
Calculation.from_proto(obj)
|
195
|
+
when :singleton
|
196
|
+
case obj
|
197
|
+
when :TRUE
|
198
|
+
Sass::Value::Boolean::TRUE
|
199
|
+
when :FALSE
|
200
|
+
Sass::Value::Boolean::FALSE
|
201
|
+
when :NULL
|
202
|
+
Sass::Value::Null::NULL
|
203
|
+
else
|
204
|
+
raise Sass::ScriptError, "Unknown Value.singleton #{obj}"
|
205
|
+
end
|
206
|
+
else
|
207
|
+
raise Sass::ScriptError, "Unknown Value.value #{obj}"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# The {Number} Protofier.
|
212
|
+
module Number
|
213
|
+
module_function
|
214
|
+
|
215
|
+
def to_proto(obj)
|
216
|
+
EmbeddedProtocol::Value::Number.new(
|
217
|
+
value: obj.value.to_f,
|
218
|
+
numerators: obj.numerator_units,
|
219
|
+
denominators: obj.denominator_units
|
220
|
+
)
|
221
|
+
end
|
222
|
+
|
223
|
+
def from_proto(obj)
|
224
|
+
Sass::Value::Number.new(
|
225
|
+
obj.value, {
|
226
|
+
numerator_units: obj.numerators.to_a,
|
227
|
+
denominator_units: obj.denominators.to_a
|
228
|
+
}
|
229
|
+
)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
private_constant :Number
|
234
|
+
|
235
|
+
# The {Calculation} Protofier.
|
236
|
+
module Calculation
|
237
|
+
module_function
|
238
|
+
|
239
|
+
def to_proto(obj)
|
240
|
+
EmbeddedProtocol::Value::Calculation.new(
|
241
|
+
name: obj.name,
|
242
|
+
arguments: obj.arguments.map { |argument| CalculationValue.to_proto(argument) }
|
243
|
+
)
|
244
|
+
end
|
245
|
+
|
246
|
+
def from_proto(obj)
|
247
|
+
Sass::Value::Calculation.send(
|
248
|
+
:new,
|
249
|
+
obj.name,
|
250
|
+
obj.arguments.map { |argument| CalculationValue.from_proto(argument) }
|
251
|
+
)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
private_constant :Calculation
|
256
|
+
|
257
|
+
# The {CalculationValue} Protofier.
|
258
|
+
module CalculationValue
|
259
|
+
module_function
|
260
|
+
|
261
|
+
def to_proto(value)
|
262
|
+
case value
|
263
|
+
when Sass::Value::Number
|
264
|
+
EmbeddedProtocol::Value::Calculation::CalculationValue.new(
|
265
|
+
number: Number.to_proto(value)
|
266
|
+
)
|
267
|
+
when Sass::Value::Calculation
|
268
|
+
EmbeddedProtocol::Value::Calculation::CalculationValue.new(
|
269
|
+
calculation: Calculation.to_proto(value)
|
270
|
+
)
|
271
|
+
when Sass::Value::String
|
272
|
+
EmbeddedProtocol::Value::Calculation::CalculationValue.new(
|
273
|
+
string: value.text
|
274
|
+
)
|
275
|
+
when Sass::CalculationValue::CalculationOperation
|
276
|
+
EmbeddedProtocol::Value::Calculation::CalculationValue.new(
|
277
|
+
operation: EmbeddedProtocol::Value::Calculation::CalculationOperation.new(
|
278
|
+
operator: CalculationOperator.to_proto(value.operator),
|
279
|
+
left: to_proto(value.left),
|
280
|
+
right: to_proto(value.right)
|
281
|
+
)
|
282
|
+
)
|
283
|
+
else
|
284
|
+
raise Sass::ScriptError, "Unknown CalculationValue #{value}"
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def from_proto(value)
|
289
|
+
oneof = value.value
|
290
|
+
obj = value.public_send(oneof)
|
291
|
+
case oneof
|
292
|
+
when :number
|
293
|
+
Number.from_proto(obj)
|
294
|
+
when :calculation
|
295
|
+
Calculation.from_proto(obj)
|
296
|
+
when :string
|
297
|
+
Sass::Value::String.new(obj, quoted: false)
|
298
|
+
when :operation
|
299
|
+
Sass::CalculationValue::CalculationOperation.new(
|
300
|
+
CalculationOperator.from_proto(obj.operator),
|
301
|
+
from_proto(obj.left),
|
302
|
+
from_proto(obj.right)
|
303
|
+
)
|
304
|
+
else
|
305
|
+
raise Sass::ScriptError, "Unknown CalculationValue #{value}"
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
private_constant :CalculationValue
|
311
|
+
|
312
|
+
# The {CalculationOperator} Protofier.
|
313
|
+
module CalculationOperator
|
314
|
+
module_function
|
315
|
+
|
316
|
+
def to_proto(operator)
|
317
|
+
case operator
|
318
|
+
when '+'
|
319
|
+
:PLUS
|
320
|
+
when '-'
|
321
|
+
:MINUS
|
322
|
+
when '*'
|
323
|
+
:TIMES
|
324
|
+
when '/'
|
325
|
+
:DIVIDE
|
326
|
+
else
|
327
|
+
raise Sass::ScriptError, "Unknown CalculationOperator #{separator}"
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
def from_proto(operator)
|
332
|
+
case operator
|
333
|
+
when :PLUS
|
334
|
+
'+'
|
335
|
+
when :MINUS
|
336
|
+
'-'
|
337
|
+
when :TIMES
|
338
|
+
'*'
|
339
|
+
when :DIVIDE
|
340
|
+
'/'
|
341
|
+
else
|
342
|
+
raise Sass::ScriptError, "Unknown CalculationOperator #{separator}"
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
private_constant :CalculationOperator
|
348
|
+
|
349
|
+
# The {ListSeparator} Protofier.
|
350
|
+
module ListSeparator
|
351
|
+
module_function
|
352
|
+
|
353
|
+
def to_proto(separator)
|
354
|
+
case separator
|
355
|
+
when ','
|
356
|
+
:COMMA
|
357
|
+
when ' '
|
358
|
+
:SPACE
|
359
|
+
when '/'
|
360
|
+
:SLASH
|
361
|
+
when nil
|
362
|
+
:UNDECIDED
|
363
|
+
else
|
364
|
+
raise Sass::ScriptError, "Unknown ListSeparator #{separator}"
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
def from_proto(separator)
|
369
|
+
case separator
|
370
|
+
when :COMMA
|
371
|
+
','
|
372
|
+
when :SPACE
|
373
|
+
' '
|
374
|
+
when :SLASH
|
375
|
+
'/'
|
376
|
+
when :UNDECIDED
|
377
|
+
nil
|
378
|
+
else
|
379
|
+
raise Sass::ScriptError, "Unknown ListSeparator #{separator}"
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
private_constant :ListSeparator
|
385
|
+
end
|
386
|
+
|
387
|
+
private_constant :Protofier
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
class Compiler
|
5
|
+
class Host
|
6
|
+
# The {Structifier} module.
|
7
|
+
#
|
8
|
+
# It converts {::Hash} to {Struct}-like objects.
|
9
|
+
module Structifier
|
10
|
+
module_function
|
11
|
+
|
12
|
+
def to_struct(obj, *symbols)
|
13
|
+
return obj unless obj.is_a?(Hash)
|
14
|
+
|
15
|
+
struct = Object.new
|
16
|
+
symbols.each do |key|
|
17
|
+
next unless obj.key?(key)
|
18
|
+
|
19
|
+
value = obj[key]
|
20
|
+
if value.respond_to?(:call)
|
21
|
+
struct.define_singleton_method key do |*args, **kwargs|
|
22
|
+
value.call(*args, **kwargs)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
struct.define_singleton_method key do
|
26
|
+
value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
struct
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private_constant :Structifier
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|