sass-embedded 1.6.2 → 1.83.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -3
  3. data/exe/sass +13 -0
  4. data/ext/sass/Rakefile +352 -76
  5. data/ext/sass/embedded_sass_pb.rb +61 -0
  6. data/ext/sass/expand-archive.ps1 +1 -0
  7. data/ext/sass/package.json +1 -1
  8. data/lib/sass/calculation_value/calculation_operation.rb +49 -0
  9. data/lib/sass/calculation_value.rb +22 -0
  10. data/lib/sass/canonicalize_context.rb +25 -0
  11. data/lib/sass/compile_result.rb +3 -2
  12. data/lib/sass/compiler/channel.rb +68 -0
  13. data/lib/sass/compiler/connection.rb +89 -0
  14. data/lib/sass/compiler/dispatcher.rb +116 -0
  15. data/lib/sass/{embedded → compiler}/host/function_registry.rb +31 -34
  16. data/lib/sass/compiler/host/importer_registry.rb +141 -0
  17. data/lib/sass/compiler/host/logger_registry.rb +80 -0
  18. data/lib/sass/compiler/host/protofier.rb +360 -0
  19. data/lib/sass/compiler/host/structifier.rb +37 -0
  20. data/lib/sass/compiler/host.rb +226 -0
  21. data/lib/sass/{embedded → compiler}/varint.rb +9 -5
  22. data/lib/sass/compiler.rb +212 -0
  23. data/lib/sass/elf.rb +222 -0
  24. data/lib/sass/embedded/version.rb +2 -2
  25. data/lib/sass/embedded.rb +76 -204
  26. data/lib/sass/embedded_protocol.rb +10 -0
  27. data/lib/sass/exception.rb +74 -0
  28. data/lib/sass/fork_tracker.rb +51 -0
  29. data/lib/sass/logger/silent.rb +5 -3
  30. data/lib/sass/logger/source_location.rb +6 -5
  31. data/lib/sass/logger/source_span.rb +8 -7
  32. data/lib/sass/node_package_importer.rb +17 -0
  33. data/lib/sass/serializer.rb +30 -0
  34. data/lib/sass/value/argument_list.rb +13 -6
  35. data/lib/sass/value/boolean.rb +1 -1
  36. data/lib/sass/value/calculation.rb +90 -0
  37. data/lib/sass/value/color/channel.rb +79 -0
  38. data/lib/sass/value/color/conversions.rb +473 -0
  39. data/lib/sass/value/color/gamut_map_method/clip.rb +45 -0
  40. data/lib/sass/value/color/gamut_map_method/local_minde.rb +94 -0
  41. data/lib/sass/value/color/gamut_map_method.rb +45 -0
  42. data/lib/sass/value/color/interpolation_method.rb +51 -0
  43. data/lib/sass/value/color/space/a98_rgb.rb +57 -0
  44. data/lib/sass/value/color/space/display_p3.rb +57 -0
  45. data/lib/sass/value/color/space/hsl.rb +65 -0
  46. data/lib/sass/value/color/space/hwb.rb +70 -0
  47. data/lib/sass/value/color/space/lab.rb +77 -0
  48. data/lib/sass/value/color/space/lch.rb +53 -0
  49. data/lib/sass/value/color/space/lms.rb +129 -0
  50. data/lib/sass/value/color/space/oklab.rb +66 -0
  51. data/lib/sass/value/color/space/oklch.rb +54 -0
  52. data/lib/sass/value/color/space/prophoto_rgb.rb +59 -0
  53. data/lib/sass/value/color/space/rec2020.rb +69 -0
  54. data/lib/sass/value/color/space/rgb.rb +52 -0
  55. data/lib/sass/value/color/space/srgb.rb +140 -0
  56. data/lib/sass/value/color/space/srgb_linear.rb +72 -0
  57. data/lib/sass/value/color/space/utils.rb +86 -0
  58. data/lib/sass/value/color/space/xyz_d50.rb +100 -0
  59. data/lib/sass/value/color/space/xyz_d65.rb +57 -0
  60. data/lib/sass/value/color/space.rb +198 -0
  61. data/lib/sass/value/color.rb +538 -163
  62. data/lib/sass/value/function.rb +11 -16
  63. data/lib/sass/value/fuzzy_math.rb +24 -21
  64. data/lib/sass/value/list.rb +7 -7
  65. data/lib/sass/value/map.rb +6 -6
  66. data/lib/sass/value/mixin.rb +34 -0
  67. data/lib/sass/value/null.rb +1 -1
  68. data/lib/sass/value/number/unit.rb +7 -6
  69. data/lib/sass/value/number.rb +34 -26
  70. data/lib/sass/value/string.rb +9 -3
  71. data/lib/sass/value.rb +20 -16
  72. metadata +67 -103
  73. data/ext/sass/unzip.vbs +0 -13
  74. data/lib/sass/compile_error.rb +0 -28
  75. data/lib/sass/embedded/async.rb +0 -65
  76. data/lib/sass/embedded/channel.rb +0 -61
  77. data/lib/sass/embedded/compiler.rb +0 -60
  78. data/lib/sass/embedded/dispatcher.rb +0 -90
  79. data/lib/sass/embedded/host/importer_registry.rb +0 -107
  80. data/lib/sass/embedded/host/logger_registry.rb +0 -50
  81. data/lib/sass/embedded/host/value_protofier.rb +0 -241
  82. data/lib/sass/embedded/host.rb +0 -139
  83. data/lib/sass/embedded/protofier.rb +0 -78
  84. data/lib/sass/embedded/structifier.rb +0 -36
  85. data/lib/sass/script_error.rb +0 -6
@@ -4,26 +4,21 @@ module Sass
4
4
  module Value
5
5
  # Sass's function type.
6
6
  #
7
- # @see https://sass-lang.com/documentation/js-api/classes/SassFunction
7
+ # @see https://sass-lang.com/documentation/js-api/classes/sassfunction/
8
8
  class Function
9
9
  include Value
10
10
 
11
- # @overload initialize(id)
12
- # @param id [Numeric]
13
- # @overload initialize(signature, callback)
14
- # @param signature [::String]
15
- # @param callback [Proc]
16
- def initialize(id_or_signature, callback = nil)
17
- if id_or_signature.is_a? Numeric
18
- @id = id_or_signature
19
- else
20
- @signature = id_or_signature
21
- @callback = callback
22
- end
11
+ # @param signature [::String]
12
+ # @param callback [Proc]
13
+ def initialize(signature, &callback)
14
+ raise Sass::ScriptError, 'no block given' unless signature.nil? || callback
15
+
16
+ @signature = signature.freeze
17
+ @callback = callback.freeze
23
18
  end
24
19
 
25
20
  # @return [Integer, nil]
26
- attr_reader :id
21
+ protected attr_reader :id
27
22
 
28
23
  # @return [::String, nil]
29
24
  attr_reader :signature
@@ -34,7 +29,7 @@ module Sass
34
29
  # @return [::Boolean]
35
30
  def ==(other)
36
31
  if id.nil?
37
- other.equal? self
32
+ other.equal?(self)
38
33
  else
39
34
  other.is_a?(Sass::Value::Function) && other.id == id
40
35
  end
@@ -42,7 +37,7 @@ module Sass
42
37
 
43
38
  # @return [Integer]
44
39
  def hash
45
- id.nil? ? signature.hash : id.hash
40
+ @hash ||= id.nil? ? signature.hash : id.hash
46
41
  end
47
42
 
48
43
  # @return [Function]
@@ -6,14 +6,27 @@ module Sass
6
6
  module FuzzyMath
7
7
  PRECISION = 10
8
8
 
9
- EPSILON = 10.pow(-PRECISION - 1)
9
+ EPSILON = 10**(-PRECISION - 1)
10
10
 
11
- INVERSE_EPSILON = 1 / EPSILON
11
+ INVERSE_EPSILON = 10**(PRECISION + 1)
12
12
 
13
13
  module_function
14
14
 
15
15
  def equals(number1, number2)
16
- (number1 - number2).abs < EPSILON
16
+ return true if number1 == number2
17
+
18
+ (number1 - number2).abs <= EPSILON &&
19
+ (number1 * INVERSE_EPSILON).round ==
20
+ (number2 * INVERSE_EPSILON).round
21
+ end
22
+
23
+ def equals_nilable(number1, number2)
24
+ return true if number1 == number2
25
+ return false if number1.nil? || number2.nil?
26
+
27
+ (number1 - number2).abs <= EPSILON &&
28
+ (number1 * INVERSE_EPSILON).round ==
29
+ (number2 * INVERSE_EPSILON).round
17
30
  end
18
31
 
19
32
  def less_than(number1, number2)
@@ -34,23 +47,14 @@ module Sass
34
47
 
35
48
  def integer?(number)
36
49
  return false unless number.finite?
37
- return true if number.integer?
38
50
 
39
- equals((number - 0.5).abs % 1, 0.5)
51
+ equals(number, number.round)
40
52
  end
41
53
 
42
54
  def to_i(number)
43
55
  integer?(number) ? number.round : nil
44
56
  end
45
57
 
46
- def round(number)
47
- if number.positive?
48
- less_than(number % 1, 0.5) ? number.floor : number.ceil
49
- else
50
- less_than_or_equals(number % 1, 0.5) ? number.floor : number.ceil
51
- end
52
- end
53
-
54
58
  def between(number, min, max)
55
59
  return min if equals(number, min)
56
60
  return max if equals(number, max)
@@ -63,16 +67,15 @@ module Sass
63
67
  result = between(number, min, max)
64
68
  return result unless result.nil?
65
69
 
66
- message = "#{number} must be between #{min} and #{max}."
67
- raise Sass::ScriptError, name.nil? ? message : "$#{name}: #{message}"
70
+ raise Sass::ScriptError.new("#{number} must be between #{min} and #{max}.", name)
71
+ end
72
+
73
+ def _clamp_like_css(number, lower_bound, upper_bound)
74
+ number.to_f.nan? ? lower_bound : number.clamp(lower_bound, upper_bound)
68
75
  end
69
76
 
70
- def hash(number)
71
- @hash ||= if number.finite?
72
- (number * INVERSE_EPSILON).round.hash
73
- else
74
- number.hash
75
- end
77
+ def _hash(number)
78
+ number&.finite? ? (number * INVERSE_EPSILON).round : number
76
79
  end
77
80
  end
78
81
 
@@ -4,7 +4,7 @@ module Sass
4
4
  module Value
5
5
  # Sass's list type.
6
6
  #
7
- # @see https://sass-lang.com/documentation/js-api/classes/SassList
7
+ # @see https://sass-lang.com/documentation/js-api/classes/sasslist/
8
8
  class List
9
9
  include Value
10
10
 
@@ -13,7 +13,7 @@ module Sass
13
13
  # @param bracketed [::Boolean]
14
14
  def initialize(contents = [], separator: ',', bracketed: false)
15
15
  if separator.nil? && contents.length > 1
16
- raise error 'A list with more than one element must have an explicit separator'
16
+ raise Sass::ScriptError, 'A list with more than one element must have an explicit separator'
17
17
  end
18
18
 
19
19
  @contents = contents.freeze
@@ -21,9 +21,6 @@ module Sass
21
21
  @bracketed = bracketed.freeze
22
22
  end
23
23
 
24
- # @return [Array<Value>]
25
- attr_reader :contents
26
-
27
24
  # @return [::String, nil]
28
25
  attr_reader :separator
29
26
 
@@ -35,7 +32,7 @@ module Sass
35
32
  # @return [::Boolean]
36
33
  def ==(other)
37
34
  (other.is_a?(Sass::Value::List) &&
38
- other.contents == contents &&
35
+ other.to_a == to_a &&
39
36
  other.separator == separator &&
40
37
  other.bracketed? == bracketed?) ||
41
38
  (to_a.empty? && other.is_a?(Sass::Value::Map) && other.to_a.empty?)
@@ -56,7 +53,10 @@ module Sass
56
53
  @hash ||= contents.hash
57
54
  end
58
55
 
59
- alias to_a contents
56
+ # @return [Array<Value>]
57
+ def to_a
58
+ @contents
59
+ end
60
60
 
61
61
  # @return [Map, nil]
62
62
  def to_map
@@ -4,7 +4,7 @@ module Sass
4
4
  module Value
5
5
  # Sass's map type.
6
6
  #
7
- # @see https://sass-lang.com/documentation/js-api/classes/SassMap
7
+ # @see https://sass-lang.com/documentation/js-api/classes/sassmap/
8
8
  class Map
9
9
  include Value
10
10
 
@@ -30,12 +30,12 @@ module Sass
30
30
  # @param index [Numeric, Value]
31
31
  # @return [List<(Value, Value)>, Value]
32
32
  def at(index)
33
- if index.is_a? Numeric
33
+ if index.is_a?(Numeric)
34
34
  index = index.floor
35
- index = to_a.length + index if index.negative?
36
- return nil if index.negative? || index >= to_a.length
35
+ index = to_a_length + index if index.negative?
36
+ return nil if index.negative? || index >= to_a_length
37
37
 
38
- to_a[index]
38
+ Sass::Value::List.new(contents.to_a[index], separator: ' ')
39
39
  else
40
40
  contents[index]
41
41
  end
@@ -48,7 +48,7 @@ module Sass
48
48
 
49
49
  # @return [Array<List<(Value, Value)>>]
50
50
  def to_a
51
- contents.to_a.map { |entry| Sass::Value::List.new(entry, separator: ' ') }
51
+ contents.map { |key, value| Sass::Value::List.new([key, value], separator: ' ') }
52
52
  end
53
53
 
54
54
  # @return [Map]
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ module Value
5
+ # Sass's mixin type.
6
+ #
7
+ # @see https://sass-lang.com/documentation/js-api/classes/sassmixin/
8
+ class Mixin
9
+ include Value
10
+
11
+ class << self
12
+ private :new
13
+ end
14
+
15
+ # @return [Integer]
16
+ protected attr_reader :id
17
+
18
+ # @return [::Boolean]
19
+ def ==(other)
20
+ other.is_a?(Sass::Value::Mixin) && other.id == id
21
+ end
22
+
23
+ # @return [Integer]
24
+ def hash
25
+ @hash ||= id.hash
26
+ end
27
+
28
+ # @return [Mixin]
29
+ def assert_mixin(_name = nil)
30
+ self
31
+ end
32
+ end
33
+ end
34
+ end
@@ -4,7 +4,7 @@ module Sass
4
4
  module Value
5
5
  # Sass's null type.
6
6
  #
7
- # @see https://sass-lang.com/documentation/js-api/modules#sassNull
7
+ # @see https://sass-lang.com/documentation/js-api/variables/sassnull/
8
8
  class Null
9
9
  include Value
10
10
 
@@ -88,12 +88,12 @@ module Sass
88
88
  'deg' => Rational(Math::PI, 180),
89
89
  'grad' => Rational(Math::PI, 200),
90
90
  'rad' => Rational(1),
91
- 'turn' => Rational(2 * Math::PI)
91
+ 'turn' => Rational(Math::PI * 2)
92
92
  },
93
93
  'turn' => {
94
94
  'deg' => Rational(1, 360),
95
95
  'grad' => Rational(1, 400),
96
- 'rad' => Rational(1, 2 * Math::PI),
96
+ 'rad' => Rational(1, Math::PI * 2),
97
97
  'turn' => Rational(1)
98
98
  },
99
99
 
@@ -141,10 +141,11 @@ module Sass
141
141
  'pixel density': %w[dpi dpcm dppx]
142
142
  }.freeze
143
143
 
144
- TYPES_BY_UNIT = UNITS_BY_TYPE.invert
145
- .to_a
146
- .flat_map { |pair| pair[0].map { |key| [key, pair[1]] } }
147
- .to_h
144
+ TYPES_BY_UNIT = UNITS_BY_TYPE.each_with_object({}) do |(key, values), hash|
145
+ values.each do |value|
146
+ hash[value] = key
147
+ end
148
+ end
148
149
 
149
150
  module_function
150
151
 
@@ -6,9 +6,10 @@ module Sass
6
6
  module Value
7
7
  # Sass's number type.
8
8
  #
9
- # @see https://sass-lang.com/documentation/js-api/classes/SassNumber
9
+ # @see https://sass-lang.com/documentation/js-api/classes/sassnumber/
10
10
  class Number
11
11
  include Value
12
+ include CalculationValue
12
13
 
13
14
  # @param value [Numeric]
14
15
  # @param unit [::String, Hash]
@@ -24,12 +25,16 @@ module Sass
24
25
  denominator_units = []
25
26
  when ::Hash
26
27
  numerator_units = unit.fetch(:numerator_units, [])
27
- raise error "invalid numerator_units #{numerator_units.inspect}" unless numerator_units.is_a? Array
28
+ unless numerator_units.is_a?(Array)
29
+ raise Sass::ScriptError, "invalid numerator_units #{numerator_units.inspect}"
30
+ end
28
31
 
29
32
  denominator_units = unit.fetch(:denominator_units, [])
30
- raise error "invalid denominator_units #{denominator_units.inspect}" unless denominator_units.is_a? Array
33
+ unless denominator_units.is_a?(Array)
34
+ raise Sass::ScriptError, "invalid denominator_units #{denominator_units.inspect}"
35
+ end
31
36
  else
32
- raise error "invalid unit #{unit.inspect}"
37
+ raise Sass::ScriptError, "invalid unit #{unit.inspect}"
33
38
  end
34
39
 
35
40
  unless denominator_units.empty? && numerator_units.empty?
@@ -58,8 +63,8 @@ module Sass
58
63
  end
59
64
 
60
65
  @value = value.freeze
61
- @numerator_units = numerator_units.freeze
62
- @denominator_units = denominator_units.freeze
66
+ @numerator_units = numerator_units.each(&:freeze).freeze
67
+ @denominator_units = denominator_units.each(&:freeze).freeze
63
68
  end
64
69
 
65
70
  # @return [Numeric]
@@ -70,7 +75,7 @@ module Sass
70
75
 
71
76
  # @return [::Boolean]
72
77
  def ==(other)
73
- return false unless other.is_a? Sass::Value::Number
78
+ return false unless other.is_a?(Sass::Value::Number)
74
79
 
75
80
  return false if numerator_units.length != other.numerator_units.length ||
76
81
  denominator_units.length != other.denominator_units.length
@@ -94,7 +99,7 @@ module Sass
94
99
 
95
100
  # @return [Integer]
96
101
  def hash
97
- @hash ||= FuzzyMath.hash(canonical_units_value)
102
+ @hash ||= FuzzyMath._hash(canonical_units_value).hash
98
103
  end
99
104
 
100
105
  # @return [::Boolean]
@@ -105,7 +110,7 @@ module Sass
105
110
  # @return [Number]
106
111
  # @raise [ScriptError]
107
112
  def assert_unitless(name = nil)
108
- raise error "Expected #{self} to have no units", name unless unitless?
113
+ raise Sass::ScriptError.new("Expected #{self} to have no units", name) unless unitless?
109
114
 
110
115
  self
111
116
  end
@@ -125,7 +130,7 @@ module Sass
125
130
  # @return [Number]
126
131
  # @raise [ScriptError]
127
132
  def assert_unit(unit, name = nil)
128
- raise error "Expected #{self} to have unit #{unit.inspect}", name unless unit?(unit)
133
+ raise Sass::ScriptError.new("Expected #{self} to have unit #{unit.inspect}", name) unless unit?(unit)
129
134
 
130
135
  self
131
136
  end
@@ -138,7 +143,7 @@ module Sass
138
143
  # @return [Integer]
139
144
  # @raise [ScriptError]
140
145
  def assert_integer(name = nil)
141
- raise error "#{self} is not an integer", name unless integer?
146
+ raise Sass::ScriptError.new("#{self} is not an integer", name) unless integer?
142
147
 
143
148
  to_i
144
149
  end
@@ -178,7 +183,7 @@ module Sass
178
183
  def convert_value(new_numerator_units, new_denominator_units, name = nil)
179
184
  coerce_or_convert_value(new_numerator_units, new_denominator_units,
180
185
  coerce_unitless: false,
181
- name: name)
186
+ name:)
182
187
  end
183
188
 
184
189
  # @param other [Number]
@@ -195,9 +200,9 @@ module Sass
195
200
  def convert_value_to_match(other, name = nil, other_name = nil)
196
201
  coerce_or_convert_value(other.numerator_units, other.denominator_units,
197
202
  coerce_unitless: false,
198
- name: name,
199
- other: other,
200
- other_name: other_name)
203
+ name:,
204
+ other:,
205
+ other_name:)
201
206
  end
202
207
 
203
208
  # @param new_numerator_units [Array<::String>]
@@ -216,7 +221,7 @@ module Sass
216
221
  def coerce_value(new_numerator_units, new_denominator_units, name = nil)
217
222
  coerce_or_convert_value(new_numerator_units, new_denominator_units,
218
223
  coerce_unitless: true,
219
- name: name)
224
+ name:)
220
225
  end
221
226
 
222
227
  # @param unit [::String]
@@ -239,9 +244,9 @@ module Sass
239
244
  def coerce_value_to_match(other, name = nil, other_name = nil)
240
245
  coerce_or_convert_value(other.numerator_units, other.denominator_units,
241
246
  coerce_unitless: true,
242
- name: name,
243
- other: other,
244
- other_name: other_name)
247
+ name:,
248
+ other:,
249
+ other_name:)
245
250
  end
246
251
 
247
252
  # @return [Number]
@@ -249,7 +254,7 @@ module Sass
249
254
  self
250
255
  end
251
256
 
252
- protected
257
+ private
253
258
 
254
259
  def single_unit?
255
260
  numerator_units.length == 1 && denominator_units.empty?
@@ -271,7 +276,8 @@ module Sass
271
276
  other: nil,
272
277
  other_name: nil)
273
278
  if other && (other.numerator_units != new_denominator_units && other.denominator_units != new_denominator_units)
274
- raise error "Expect #{other} to have units #{unit_string(new_numerator_units, new_denominator_units).inspect}"
279
+ raise Sass::ScriptError, "Expect #{other} to have units #{unit_string(new_numerator_units,
280
+ new_denominator_units).inspect}"
275
281
  end
276
282
 
277
283
  return value if numerator_units == new_numerator_units && denominator_units == new_denominator_units
@@ -284,23 +290,25 @@ module Sass
284
290
 
285
291
  compatibility_error = lambda {
286
292
  unless other.nil?
287
- message = +"#{self} and"
293
+ message = "#{self} and"
288
294
  message << " $#{other_name}:" unless other_name.nil?
289
295
  message << " #{other} have incompatible units"
290
296
  message << " (one has units and the other doesn't)" if unitless? || other_unitless
291
- return error message, name
297
+ return Sass::ScriptError.new(message, name)
292
298
  end
293
299
 
294
- return error "Expected #{self} to have no units", name unless other_unitless
300
+ return Sass::ScriptError.new("Expected #{self} to have no units", name) unless other_unitless
295
301
 
296
302
  if new_numerator_units.length == 1 && new_denominator_units.empty?
297
303
  type = Unit::TYPES_BY_UNIT[new_numerator_units.first]
298
- return error "Expected #{self} to have a #{type} unit (#{Unit::UNITS_BY_TYPE[type].join(', ')})", name
304
+ return Sass::ScriptError.new(
305
+ "Expected #{self} to have a #{type} unit (#{Unit::UNITS_BY_TYPE[type].join(', ')})", name
306
+ )
299
307
  end
300
308
 
301
309
  unit_length = new_numerator_units.length + new_denominator_units.length
302
310
  units = unit_string(new_numerator_units, new_denominator_units)
303
- error "Expected #{self} to have unit#{unit_length > 1 ? 's' : ''} #{units}", name
311
+ Sass::ScriptError.new("Expected #{self} to have unit#{unit_length > 1 ? 's' : ''} #{units}", name)
304
312
  }
305
313
 
306
314
  result = value
@@ -4,9 +4,10 @@ module Sass
4
4
  module Value
5
5
  # Sass's string type.
6
6
  #
7
- # @see https://sass-lang.com/documentation/js-api/classes/SassString
7
+ # @see https://sass-lang.com/documentation/js-api/classes/sassstring/
8
8
  class String
9
9
  include Value
10
+ include CalculationValue
10
11
 
11
12
  # @param text [::String]
12
13
  # @param quoted [::Boolean]
@@ -42,14 +43,19 @@ module Sass
42
43
  # @return [Integer]
43
44
  def sass_index_to_string_index(sass_index, name = nil)
44
45
  index = sass_index.assert_number(name).assert_integer(name)
45
- raise error('String index may not be 0', name) if index.zero?
46
+ raise Sass::ScriptError.new('String index may not be 0', name) if index.zero?
46
47
 
47
48
  if index.abs > text.length
48
- raise error("Invalid index #{sass_index} for a string with #{text.length} characters", name)
49
+ raise Sass::ScriptError.new("Invalid index #{sass_index} for a string with #{text.length} characters", name)
49
50
  end
50
51
 
51
52
  index.negative? ? text.length + index : index - 1
52
53
  end
54
+
55
+ # @return [::String]
56
+ def to_s
57
+ @quoted ? Serializer.serialize_quoted_string(@text) : Serializer.serialize_unquoted_string(@text)
58
+ end
53
59
  end
54
60
  end
55
61
  end
data/lib/sass/value.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'script_error'
4
-
5
3
  module Sass
6
4
  # The abstract base class of Sass's value types.
7
5
  #
8
- # @see https://sass-lang.com/documentation/js-api/classes/Value
6
+ # @see https://sass-lang.com/documentation/js-api/classes/value/
9
7
  module Value
10
8
  # @return [::String, nil]
11
9
  def separator
@@ -57,52 +55,59 @@ module Sass
57
55
  # @return [Boolean]
58
56
  # @raise [ScriptError]
59
57
  def assert_boolean(name = nil)
60
- raise error("#{self} is not a boolean", name)
58
+ raise Sass::ScriptError.new("#{self} is not a boolean", name)
61
59
  end
62
60
 
61
+ # @return [Calculation]
63
62
  # @raise [ScriptError]
64
63
  def assert_calculation(name = nil)
65
- raise error("#{self} is not a calculation", name)
64
+ raise Sass::ScriptError.new("#{self} is not a calculation", name)
66
65
  end
67
66
 
68
67
  # @return [Color]
69
68
  # @raise [ScriptError]
70
69
  def assert_color(name = nil)
71
- raise error("#{self} is not a color", name)
70
+ raise Sass::ScriptError.new("#{self} is not a color", name)
72
71
  end
73
72
 
74
73
  # @return [Function]
75
74
  # @raise [ScriptError]
76
75
  def assert_function(name = nil)
77
- raise error("#{self} is not a function", name)
76
+ raise Sass::ScriptError.new("#{self} is not a function", name)
78
77
  end
79
78
 
80
79
  # @return [Map]
81
80
  # @raise [ScriptError]
82
81
  def assert_map(name = nil)
83
- raise error("#{self} is not a map", name)
82
+ raise Sass::ScriptError.new("#{self} is not a map", name)
83
+ end
84
+
85
+ # @return [Mixin]
86
+ # @raise [ScriptError]
87
+ def assert_mixin(name = nil)
88
+ raise Sass::ScriptError.new("#{self} is not a mixin", name)
84
89
  end
85
90
 
86
91
  # @return [Number]
87
92
  # @raise [ScriptError]
88
93
  def assert_number(name = nil)
89
- raise error("#{self} is not a number", name)
94
+ raise Sass::ScriptError.new("#{self} is not a number", name)
90
95
  end
91
96
 
92
97
  # @return [String]
93
98
  # @raise [ScriptError]
94
99
  def assert_string(name = nil)
95
- raise error("#{self} is not a string", name)
100
+ raise Sass::ScriptError.new("#{self} is not a string", name)
96
101
  end
97
102
 
98
103
  # @param sass_index [Number]
99
104
  # @return [Integer]
100
105
  def sass_index_to_array_index(sass_index, name = nil)
101
106
  index = sass_index.assert_number(name).assert_integer(name)
102
- raise error('List index may not be 0', name) if index.zero?
107
+ raise Sass::ScriptError.new('List index may not be 0', name) if index.zero?
103
108
 
104
109
  if index.abs > to_a_length
105
- raise error("Invalid index #{sass_index} for a list with #{to_a_length} elements", name)
110
+ raise Sass::ScriptError.new("Invalid index #{sass_index} for a list with #{to_a_length} elements", name)
106
111
  end
107
112
 
108
113
  index.negative? ? to_a_length + index : index - 1
@@ -113,20 +118,19 @@ module Sass
113
118
  def to_a_length
114
119
  1
115
120
  end
116
-
117
- def error(message, name = nil)
118
- Sass::ScriptError.new name.nil? ? message : "$#{name}: #{message}"
119
- end
120
121
  end
121
122
  end
122
123
 
124
+ require_relative 'calculation_value'
123
125
  require_relative 'value/list'
124
126
  require_relative 'value/argument_list'
125
127
  require_relative 'value/boolean'
128
+ require_relative 'value/calculation'
126
129
  require_relative 'value/color'
127
130
  require_relative 'value/function'
128
131
  require_relative 'value/fuzzy_math'
129
132
  require_relative 'value/map'
133
+ require_relative 'value/mixin'
130
134
  require_relative 'value/null'
131
135
  require_relative 'value/number'
132
136
  require_relative 'value/string'