Skip to content

Commit

Permalink
💅
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Aug 1, 2023
1 parent e125765 commit 9a3f15a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/slim/embedded/minify/javascript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def remove_comments!(line)
escaped_backslash = true
next char
elsif char == "\\"
if ["'", '"'].include?(next_char(line, index)) && inside_char == next_char(line, index)
escaped = true unless escaped_backslash
if ["'", '"'].include?(next_char(line, index)) && inside_char == next_char(line, index) && !escaped_backslash
escaped = true
end
escaped_backslash = false
next char
Expand Down
13 changes: 7 additions & 6 deletions lib/slim/embedded/minify/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def remaining_string_range(line, index)
end

def prev_char(line, index)
line.last[index - 1] if index > 0
line.last[index - 1] if index.positive?
end

def next_char(line, index)
Expand All @@ -92,29 +92,30 @@ def stripped_quotes(line)
inside_char = nil
escaped = false
escaped_backslash = false
line.last.chars.each_with_index.map do |char, index|
line.last.chars.each_with_index.filter_map do |char, index|
if ["'", '"'].include?(char) && inside_char.nil?
inside_char = char
next
elsif char == "\\" && next_char(line, index) == "\\" && inside_char
escaped_backslash = true
next
elsif char == "\\"
if ["'", '"'].include?(next_char(line, index)) && inside_char == next_char(line, index)
escaped = true unless escaped_backslash
if ["'",
'"'].include?(next_char(line, index)) && inside_char == next_char(line, index) && !escaped_backslash
escaped = true
end
escaped_backslash = false
next
elsif char == inside_char && !inside_char.nil?
inside_char = nil if !escaped
inside_char = nil unless escaped
escaped = false
next
elsif inside_char
next
else
char
end
end.compact.join
end.join
end

def empty_line?(line)
Expand Down

0 comments on commit 9a3f15a

Please sign in to comment.