Skip to content

Commit

Permalink
[FIX] bundle/Builder: Correct bundling of resources with empty source…
Browse files Browse the repository at this point in the history
… map

If a resource features an empty source map (which is not the same as
having no source map), the bundle's source map generation needs to
handle this differently from cases where mappings exist.

It must not prefix the empty mapping with a string "AAAA,"
since the danglíng comma will result in a corrupt source map.

However, it should still add the mapping for the first line/column
"AAAA". Otherwise the source map of the preceding module in the bundle
would be applied.

Resolves the root cause of SAP/openui5#4035
DINC0139775
  • Loading branch information
RandomByte committed May 13, 2024
1 parent b7fd89c commit 1228db7
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/lbt/bundle/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,13 @@ class BundleBuilder {
// If first column of the first line is not already mapped, add a mapping for the same reason as above.
// This is typical for transpiled code, where there is a bunch of generated code at the beginning that
// can't be mapped to the original source
map.mappings = "AAAA," + map.mappings;
if (map.mappings) {
map.mappings = "AAAA," + map.mappings;
} else {
// If there are no existing mappings (e.g. if the file is empty or only comments),
// make sure to still define a single mapping
map.mappings = "AAAA";
}
}

map.sourceRoot = path.posix.relative(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*!
* Some fancy copyright
*/

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*!
* Some fancy copyright
*/

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*!
* Some fancy copyright
*/

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*!
* ${copyright}
*/

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/fixtures/library.d-minified/main/src/library/d/empty.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/fixtures/library.d/main/src/library/d/empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*!
* ${copyright}
*/
4 changes: 2 additions & 2 deletions test/lib/tasks/bundlers/generateLibraryPreload.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test.serial("integration: build library.d with library preload", async (t) => {
assert.directoryDeepEqual(destPath, expectedPath);

// Check for all file contents
t.is(expectedFiles.length, 7, "7 files are expected");
t.is(expectedFiles.length, 8, "8 files are expected");
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
Expand Down Expand Up @@ -105,7 +105,7 @@ test.serial("integration: build library.d-minified with library preload", async
assert.directoryDeepEqual(destPath, expectedPath);

// Check for all file contents
t.is(expectedFiles.length, 9, "9 files are expected");
t.is(expectedFiles.length, 11, "11 files are expected");
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
Expand Down

0 comments on commit 1228db7

Please sign in to comment.