diff --git a/CHANGELOG.md b/CHANGELOG.md index 6366a4d92..9d7a2903d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ **Master** +- Preserve input maps when concatenating source maps. [Oskar Eichler](https://github.com/OskarEichler) + Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprockets/blob/master/UPGRADING.md # 4.4.1 diff --git a/README.md b/README.md index 958b44cd4..f39ddd91e 100644 --- a/README.md +++ b/README.md @@ -714,3 +714,5 @@ Please see the [CHANGELOG](https://github.com/rails/sprockets/tree/master/CHANGE ## License Sprockets is released under the [MIT License](MIT-LICENSE). + +Source map concatenation preserves both inputs so repeated concatenation retains the same line offsets. diff --git a/lib/sprockets/source_map_utils.rb b/lib/sprockets/source_map_utils.rb index b2ae018be..96604ef67 100644 --- a/lib/sprockets/source_map_utils.rb +++ b/lib/sprockets/source_map_utils.rb @@ -72,12 +72,16 @@ def format_source_map(map, input) # Returns a new source map hash. def concat_source_maps(a, b) return a || b unless a && b - a = make_index_map(a) + a = make_index_map(a).dup + a["sections"] = a["sections"].dup 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") + last_section = a["sections"].last.dup + last_section["map"] = last_section["map"].dup + a["sections"][-1] = last_section + last_line_count = last_section["map"].delete("x_sprockets_linecount") offset += last_line_count || 1 last_offset = a["sections"].last["offset"]["line"]