@@ -173,6 +173,7 @@ def convert_to_scss(file)
173173 file = replace_calculation_semantics ( file )
174174 file = replace_file_imports ( file )
175175 file = wrap_at_groups_with_at_root ( file )
176+ file = replace_division ( file )
176177 file
177178 end
178179
@@ -182,6 +183,26 @@ def wrap_at_groups_with_at_root(file)
182183 }
183184 end
184185
186+ # The `/` operator is not supported in dart-sass 1.33+, but
187+ # sassc/libass do not support its replacement, `math.div()`.
188+ def replace_division ( less )
189+ re = /(?<!\w )\( \s *([^(]+?)\s +\/ \s +([^)]+?)\s *\) /
190+ return less if less !~ re
191+ # In the future, we could publish a sassc compatible build to gems
192+ # and a dart-sass compatible build to npm, or we could develop a
193+ # dart-sass wrapper gem of the kind envisioned by DHH
194+ # https://discuss.rubyonrails.org/t/transition-to-the-sass-npm-gem/76566/7
195+ # For now, stick to libsass compatible output.
196+ dart_sass = false
197+ if dart_sass
198+ # use dart-sass's math.div() global function
199+ "@use \" sass:math\" ;\n " + less . gsub ( re , 'math.div(\1, \2)' )
200+ else # sassc / libsass
201+ # multiply by the reciprocal
202+ less . gsub re { "(#{ $1} * #{ 1 / $2. to_f } )" }
203+ end
204+ end
205+
185206 def sass_fn_exists ( fn )
186207 %Q{(#{ fn } ("") != unquote('#{ fn } ("")'))}
187208 end
0 commit comments