Skip to content

Commit c452094

Browse files
committed
converter: simplify replace_mixins
1 parent 5d3c30a commit c452094

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tasks/converter/less_conversion.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,16 @@ def extract_mixins_from_selectors(file, selectors_to_mixins)
424424
# #scope > .mixin() -> @include scope-mixin()
425425
# &:extend(.mixin all) -> @include mixin()
426426
def replace_mixins(less, mixin_names)
427-
mixin_pattern = /(\s+)(([#|\.][\w-]+\s*>\s*)*)\.([\w-]+\(.*\))(?!\s\{)/
428-
429-
less = less.gsub(mixin_pattern) do |match|
430-
matches = match.scan(mixin_pattern).flatten
431-
scope = matches[1] && matches[1] != '' ? matches[1].scan(/[\w-]+/).join('-') + '-' : ''
432-
mixin_name = match.scan(/\.([\w-]+)\(.*\)\s?\{?/).first
433-
if mixin_name && mixin_names.include?("#{scope}#{mixin_name.first}")
434-
"#{matches.first}@include #{scope}#{matches.last.gsub(/;\s*\$/, ', $').sub(/;\)$/, ')').sub(/\(\)$/, '')}"
427+
mixin_pattern = /(?<=^|\s)((?:[#|\.][\w-]+\s*>\s*)*)\.([\w-]+)\((.*)\)(?!\s\{)/
428+
429+
less = less.gsub(mixin_pattern) do |_|
430+
scope, name, args = $1, $2, $3
431+
scope = scope.scan(/[\w-]+/).join('-') + '-' unless scope.empty?
432+
args = "(#{args.tr(';', ',')})" unless args.empty?
433+
if name && mixin_names.include?("#{scope}#{name}")
434+
"@include #{scope}#{name}#{args}"
435435
else
436-
"#{matches.first}@extend .#{scope}#{matches.last.gsub(/\(\)/, '')}"
436+
"@extend .#{scope}#{name}"
437437
end
438438
end
439439

0 commit comments

Comments
 (0)