Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 6 additions & 2 deletions lib/sprockets/source_map_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down