module Sprockets::SourceMapUtils
def concat_source_maps(a, b)
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, b = make_index_map(a), make_index_map(b) if a["sections"].count == 0 || a["sections"].last["map"]["mappings"].empty? offset = 0 else offset = a["sections"].last["map"]["mappings"].count(';') + a["sections"].last["offset"]["line"] + 1 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