Skip to content

Commit

Permalink
Implement code review suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdotdesign committed Nov 11, 2024
1 parent ecc10b7 commit 00a22f3
Showing 1 changed file with 35 additions and 38 deletions.
73 changes: 35 additions & 38 deletions src/utils/source_map_generator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ module Mint
def initialize(unsorted : Deque(Mapping), @generated)
# We sort the mappings into lines.
unsorted.each do |item|
mappings[item[1][0]] ||= [] of Mapping
mappings[item[1][0]] << item
(mappings[item[1][0]] ||= [] of Mapping) << item
end
end

Expand All @@ -49,53 +48,51 @@ module Mint

generated_mappings =
(0..generated.lines.size).map do |line_index|
if items = mappings[line_index]?
items.reduce({[] of String, 0}) do |(memo, last), item|
column =
item[1][1]
next "" unless items = mappings[line_index]?

segment =
VLQ.encode(column - last)
items.reduce({[] of String, 0}) do |(memo, last), item|
column =
item[1][1]

if node = item[0]
# TODO: After the refactor of location remove
# this temporary variable.
location =
node.location
segment =
VLQ.encode(column - last)

source_line =
location.start[0] - 1
if node = item[0]
# TODO: After the refactor of location remove
# this temporary variable.
location =
node.location

source_column =
location.start[1]
source_line =
location.start[0] - 1

source_index =
get_source_index(node.file)
source_column =
location.start[1]

# The order is significant.
segment += VLQ.encode(source_index - last_index)
segment += VLQ.encode(source_line - last_line)
segment += VLQ.encode(source_column - last_column)
source_index =
get_source_index(node.file)

if name = item[2]
source_name_index =
get_source_name_index(name)
# The order is significant.
segment += VLQ.encode(source_index - last_index)
segment += VLQ.encode(source_line - last_line)
segment += VLQ.encode(source_column - last_column)

segment += VLQ.encode(source_name_index - last_name_index)
last_name_index = source_name_index
end
if name = item[2]
source_name_index =
get_source_name_index(name)

last_column = source_column
last_index = source_index
last_line = source_line
segment += VLQ.encode(source_name_index - last_name_index)
last_name_index = source_name_index
end

memo << segment
{memo, column}
end[0].join(",")
else
""
end
last_column = source_column
last_index = source_index
last_line = source_line
end

memo << segment
{memo, column}
end.first.join(",")
end.join(";")

{
Expand Down

0 comments on commit 00a22f3

Please sign in to comment.