Skip to content

Commit 20563f1

Browse files
author
007lva
committed
Merge branch 'master' into chore/replace-Fixnum-and-Bignum-with-Integer
2 parents aabdf60 + 9f4b2f5 commit 20563f1

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket
55
## Master
66

77
- Fix for Ruby 2.7 keyword arguments warning in `base.rb`. [#660](https://github.com/rails/sprockets/pull/660)
8+
- Fix for when `x_sprockets_linecount` is missing from a source map.
89
- Remove remaining support for Ruby < 2.4.[#672](https://github.com/rails/sprockets/pull/672)
910

1011
## 4.0.0

UPGRADING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ If you wanted to specify additional assets to deliver that were not included by
5353
config.assets.precompile += ["marketing.css"]
5454
```
5555

56-
If you are using Sprockets 4, Rails changes it's default logic for determining top-level targets. It will now use _only_ a file at `./app/assets/config/manifest.js` for specifying top-level targets; this file may already exist in your Rails app (although Rails only starts automatically using it once you are using sprockets 4), if not you should create it.
56+
If you are using Sprockets 4, Rails changes its default logic for determining top-level targets. It will now use _only_ a file at `./app/assets/config/manifest.js` for specifying top-level targets; this file may already exist in your Rails app (although Rails only starts automatically using it once you are using sprockets 4), if not you should create it.
5757

5858
The `manifest.js` file is meant to specify which files to use as a top-level target using sprockets methods `link`, `link_directory`, and `link_tree`.
5959

lib/sprockets/source_map_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def concat_source_maps(a, b)
7878
offset = 0
7979
if a["sections"].count != 0 && !a["sections"].last["map"]["mappings"].empty?
8080
last_line_count = a["sections"].last["map"].delete("x_sprockets_linecount")
81-
offset += last_line_count
81+
offset += last_line_count || 1
8282

8383
last_offset = a["sections"].last["offset"]["line"]
8484
offset += last_offset

test/test_source_map_utils.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,51 @@ def test_concat_source_maps
177177
], Sprockets::SourceMapUtils.decode_source_map(combined)[:mappings]
178178
end
179179

180+
def test_concat_without_x_sprockets_linecount_works
181+
abc_mappings = [
182+
{ source: 'a.js', generated: [1, 0], original: [1, 0] },
183+
{ source: 'b.js', generated: [2, 0], original: [20, 0] },
184+
{ source: 'c.js', generated: [3, 0], original: [30, 0] }
185+
].freeze
186+
187+
d_mapping = [
188+
{ source: 'd.js', generated: [1, 0], original: [1, 0] }
189+
].freeze
190+
191+
abc_map = {
192+
"version" => 3,
193+
"file" => "a.js",
194+
"mappings" => Sprockets::SourceMapUtils.encode_vlq_mappings(abc_mappings),
195+
"sources" => ["a.js", "b.js", "c.js"],
196+
"names" => [],
197+
"x_sprockets_linecount" => 3
198+
}
199+
200+
d_map = {
201+
"version" => 3,
202+
"file" => "d.js",
203+
"mappings" => Sprockets::SourceMapUtils.encode_vlq_mappings(d_mapping),
204+
"sources" => ["d.js"],
205+
"names" => [],
206+
}
207+
208+
combined = Sprockets::SourceMapUtils.concat_source_maps(deep_dup(abc_map), deep_dup(d_map))
209+
assert_equal [
210+
{ source: 'a.js', generated: [1, 0], original: [1, 0] },
211+
{ source: 'b.js', generated: [2, 0], original: [20, 0] },
212+
{ source: 'c.js', generated: [3, 0], original: [30, 0] },
213+
{ source: 'd.js', generated: [4, 0], original: [1, 0] }
214+
], Sprockets::SourceMapUtils.decode_source_map(combined)[:mappings]
215+
216+
combined = Sprockets::SourceMapUtils.concat_source_maps(deep_dup(d_map), deep_dup(abc_map))
217+
assert_equal [
218+
{ source: 'd.js', generated: [1, 0], original: [1, 0] },
219+
{ source: 'a.js', generated: [2, 0], original: [1, 0] },
220+
{ source: 'b.js', generated: [3, 0], original: [20, 0] },
221+
{ source: 'c.js', generated: [4, 0], original: [30, 0] }
222+
], Sprockets::SourceMapUtils.decode_source_map(combined)[:mappings]
223+
end
224+
180225
def test_combine_source_maps_returns_original
181226
abc_mappings = [
182227
{ source: 'a.js', generated: [1, 0], original: [0, 0] },

0 commit comments

Comments
 (0)