module Sprockets::SourceMapUtils

def concat_source_maps(a, b)

Returns a new source map hash.

b - Source map hash
a - Source map hash

map3 = concat_source_maps(map1, map2)
script3 = "#{script1}#{script2}"

Examples

maps for those files can be concatenated to map back to the originals.
For an example, if two js scripts are concatenated, the individual source

Public: Concatenate two source maps.
def concat_source_maps(a, b)
  return a || b unless a && b
  a = make_index_map(a)
  b = make_index_map(b)
  offset = 0
  if a["sections"].count != 0 && !a["sections"].last["map"]["mappings"].empty?
    last_line_count = a["sections"].last["map"].delete("x_sprockets_linecount")
    offset += last_line_count || 1
    last_offset = a["sections"].last["offset"]["line"]
    offset += last_offset
  end
  a["sections"] += b["sections"].map do |section|
    {
      "offset" => section["offset"].merge({ "line" => section["offset"]["line"] + offset }),
      "map"    => section["map"].merge({
        "sources" => section["map"]["sources"].map do |source|
          PathUtils.relative_path_from(a["file"], PathUtils.join(File.dirname(b["file"]), source))
        end
      })
    }
  end
  a
end