Skip to content

Commit

Permalink
Merge branch 'master' into chore/replace-Fixnum-and-Bignum-with-Integer
Browse files Browse the repository at this point in the history
  • Loading branch information
007lva committed May 23, 2020
2 parents aabdf60 + 9f4b2f5 commit 20563f1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket
## Master

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

## 4.0.0
Expand Down
2 changes: 1 addition & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ If you wanted to specify additional assets to deliver that were not included by
config.assets.precompile += ["marketing.css"]
```

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.
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.

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`.

Expand Down
2 changes: 1 addition & 1 deletion lib/sprockets/source_map_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def concat_source_maps(a, 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
offset += last_line_count || 1

last_offset = a["sections"].last["offset"]["line"]
offset += last_offset
Expand Down
45 changes: 45 additions & 0 deletions test/test_source_map_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,51 @@ def test_concat_source_maps
], Sprockets::SourceMapUtils.decode_source_map(combined)[:mappings]
end

def test_concat_without_x_sprockets_linecount_works
abc_mappings = [
{ source: 'a.js', generated: [1, 0], original: [1, 0] },
{ source: 'b.js', generated: [2, 0], original: [20, 0] },
{ source: 'c.js', generated: [3, 0], original: [30, 0] }
].freeze

d_mapping = [
{ source: 'd.js', generated: [1, 0], original: [1, 0] }
].freeze

abc_map = {
"version" => 3,
"file" => "a.js",
"mappings" => Sprockets::SourceMapUtils.encode_vlq_mappings(abc_mappings),
"sources" => ["a.js", "b.js", "c.js"],
"names" => [],
"x_sprockets_linecount" => 3
}

d_map = {
"version" => 3,
"file" => "d.js",
"mappings" => Sprockets::SourceMapUtils.encode_vlq_mappings(d_mapping),
"sources" => ["d.js"],
"names" => [],
}

combined = Sprockets::SourceMapUtils.concat_source_maps(deep_dup(abc_map), deep_dup(d_map))
assert_equal [
{ source: 'a.js', generated: [1, 0], original: [1, 0] },
{ source: 'b.js', generated: [2, 0], original: [20, 0] },
{ source: 'c.js', generated: [3, 0], original: [30, 0] },
{ source: 'd.js', generated: [4, 0], original: [1, 0] }
], Sprockets::SourceMapUtils.decode_source_map(combined)[:mappings]

combined = Sprockets::SourceMapUtils.concat_source_maps(deep_dup(d_map), deep_dup(abc_map))
assert_equal [
{ source: 'd.js', generated: [1, 0], original: [1, 0] },
{ source: 'a.js', generated: [2, 0], original: [1, 0] },
{ source: 'b.js', generated: [3, 0], original: [20, 0] },
{ source: 'c.js', generated: [4, 0], original: [30, 0] }
], Sprockets::SourceMapUtils.decode_source_map(combined)[:mappings]
end

def test_combine_source_maps_returns_original
abc_mappings = [
{ source: 'a.js', generated: [1, 0], original: [0, 0] },
Expand Down

0 comments on commit 20563f1

Please sign in to comment.