From 1228db78e7e655cea58c20517662b08dd09db87b Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Fri, 10 May 2024 14:40:00 +0200 Subject: [PATCH] [FIX] bundle/Builder: Correct bundling of resources with empty source map MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 https://github.com/SAP/openui5/issues/4035 DINC0139775 --- lib/lbt/bundle/Builder.js | 8 +++++++- .../dest-deps/resources/library/d/empty-dbg.js | 3 +++ .../application.a/dest-deps/resources/library/d/empty.js | 5 +++++ .../dest-deps/resources/library/d/empty.js.map | 1 + .../dest-depself/resources/library/d/empty-dbg.js | 3 +++ .../dest-depself/resources/library/d/empty.js | 5 +++++ .../dest-depself/resources/library/d/empty.js.map | 1 + .../preload/resources/library/d/empty.js | 5 +++++ .../preload/resources/library/d/empty.js.map | 1 + .../preload/resources/library/d/library-preload.js | 6 ++++++ .../preload/resources/library/d/library-preload.js.map | 2 +- .../build/library.d/dest/resources/library/d/empty-dbg.js | 3 +++ .../build/library.d/dest/resources/library/d/empty.js | 5 +++++ .../build/library.d/dest/resources/library/d/empty.js.map | 1 + .../build/library.d/preload/resources/library/d/empty.js | 3 +++ .../preload/resources/library/d/library-preload.js | 5 +++++ .../preload/resources/library/d/library-preload.js.map | 2 +- .../library.d-minified/main/src/library/d/empty.js | 5 +++++ .../library.d-minified/main/src/library/d/empty.js.map | 1 + test/fixtures/library.d/main/src/library/d/empty.js | 3 +++ .../tasks/bundlers/generateLibraryPreload.integration.js | 4 ++-- 21 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 test/expected/build/application.a/dest-deps/resources/library/d/empty-dbg.js create mode 100644 test/expected/build/application.a/dest-deps/resources/library/d/empty.js create mode 100644 test/expected/build/application.a/dest-deps/resources/library/d/empty.js.map create mode 100644 test/expected/build/application.a/dest-depself/resources/library/d/empty-dbg.js create mode 100644 test/expected/build/application.a/dest-depself/resources/library/d/empty.js create mode 100644 test/expected/build/application.a/dest-depself/resources/library/d/empty.js.map create mode 100644 test/expected/build/library.d-minified/preload/resources/library/d/empty.js create mode 100644 test/expected/build/library.d-minified/preload/resources/library/d/empty.js.map create mode 100644 test/expected/build/library.d/dest/resources/library/d/empty-dbg.js create mode 100644 test/expected/build/library.d/dest/resources/library/d/empty.js create mode 100644 test/expected/build/library.d/dest/resources/library/d/empty.js.map create mode 100644 test/expected/build/library.d/preload/resources/library/d/empty.js create mode 100644 test/fixtures/library.d-minified/main/src/library/d/empty.js create mode 100644 test/fixtures/library.d-minified/main/src/library/d/empty.js.map create mode 100644 test/fixtures/library.d/main/src/library/d/empty.js diff --git a/lib/lbt/bundle/Builder.js b/lib/lbt/bundle/Builder.js index 71a839fb9..3fc71dbcc 100644 --- a/lib/lbt/bundle/Builder.js +++ b/lib/lbt/bundle/Builder.js @@ -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( diff --git a/test/expected/build/application.a/dest-deps/resources/library/d/empty-dbg.js b/test/expected/build/application.a/dest-deps/resources/library/d/empty-dbg.js new file mode 100644 index 000000000..c82b694dc --- /dev/null +++ b/test/expected/build/application.a/dest-deps/resources/library/d/empty-dbg.js @@ -0,0 +1,3 @@ +/*! + * Some fancy copyright + */ diff --git a/test/expected/build/application.a/dest-deps/resources/library/d/empty.js b/test/expected/build/application.a/dest-deps/resources/library/d/empty.js new file mode 100644 index 000000000..8af07c600 --- /dev/null +++ b/test/expected/build/application.a/dest-deps/resources/library/d/empty.js @@ -0,0 +1,5 @@ +/*! + * Some fancy copyright + */ + +//# sourceMappingURL=empty.js.map \ No newline at end of file diff --git a/test/expected/build/application.a/dest-deps/resources/library/d/empty.js.map b/test/expected/build/application.a/dest-deps/resources/library/d/empty.js.map new file mode 100644 index 000000000..767ef9fbd --- /dev/null +++ b/test/expected/build/application.a/dest-deps/resources/library/d/empty.js.map @@ -0,0 +1 @@ +{"version":3,"file":"empty.js","names":[],"sources":[],"mappings":"","ignoreList":[]} \ No newline at end of file diff --git a/test/expected/build/application.a/dest-depself/resources/library/d/empty-dbg.js b/test/expected/build/application.a/dest-depself/resources/library/d/empty-dbg.js new file mode 100644 index 000000000..c82b694dc --- /dev/null +++ b/test/expected/build/application.a/dest-depself/resources/library/d/empty-dbg.js @@ -0,0 +1,3 @@ +/*! + * Some fancy copyright + */ diff --git a/test/expected/build/application.a/dest-depself/resources/library/d/empty.js b/test/expected/build/application.a/dest-depself/resources/library/d/empty.js new file mode 100644 index 000000000..8af07c600 --- /dev/null +++ b/test/expected/build/application.a/dest-depself/resources/library/d/empty.js @@ -0,0 +1,5 @@ +/*! + * Some fancy copyright + */ + +//# sourceMappingURL=empty.js.map \ No newline at end of file diff --git a/test/expected/build/application.a/dest-depself/resources/library/d/empty.js.map b/test/expected/build/application.a/dest-depself/resources/library/d/empty.js.map new file mode 100644 index 000000000..767ef9fbd --- /dev/null +++ b/test/expected/build/application.a/dest-depself/resources/library/d/empty.js.map @@ -0,0 +1 @@ +{"version":3,"file":"empty.js","names":[],"sources":[],"mappings":"","ignoreList":[]} \ No newline at end of file diff --git a/test/expected/build/library.d-minified/preload/resources/library/d/empty.js b/test/expected/build/library.d-minified/preload/resources/library/d/empty.js new file mode 100644 index 000000000..8af07c600 --- /dev/null +++ b/test/expected/build/library.d-minified/preload/resources/library/d/empty.js @@ -0,0 +1,5 @@ +/*! + * Some fancy copyright + */ + +//# sourceMappingURL=empty.js.map \ No newline at end of file diff --git a/test/expected/build/library.d-minified/preload/resources/library/d/empty.js.map b/test/expected/build/library.d-minified/preload/resources/library/d/empty.js.map new file mode 100644 index 000000000..767ef9fbd --- /dev/null +++ b/test/expected/build/library.d-minified/preload/resources/library/d/empty.js.map @@ -0,0 +1 @@ +{"version":3,"file":"empty.js","names":[],"sources":[],"mappings":"","ignoreList":[]} \ No newline at end of file diff --git a/test/expected/build/library.d-minified/preload/resources/library/d/library-preload.js b/test/expected/build/library.d-minified/preload/resources/library/d/library-preload.js index 730758d70..916914b98 100644 --- a/test/expected/build/library.d-minified/preload/resources/library/d/library-preload.js +++ b/test/expected/build/library.d-minified/preload/resources/library/d/library-preload.js @@ -1,5 +1,11 @@ //@ui5-bundle library/d/library-preload.js sap.ui.require.preload({ + "library/d/empty.js":function(){ +/*! + * Some fancy copyright + */ + +}, "library/d/legacy.js":'/*!\n * Some fancy copyright\n */\nvar topLevelVar="Old World";console.log("Hello "+topLevelVar);\n', "library/d/manifest.json":'{"_version":"1.21.0","sap.app":{"id":"library.d","type":"library","embeds":[],"applicationVersion":{"version":"1.0.0"},"title":"Library D","description":"Library D","resources":"resources.json","offline":true},"sap.ui":{"technology":"UI5","supportedThemes":[]},"sap.ui5":{"dependencies":{"minUI5Version":"1.0","libs":{}},"library":{"i18n":false}}}', "library/d/some.js":function(){ diff --git a/test/expected/build/library.d-minified/preload/resources/library/d/library-preload.js.map b/test/expected/build/library.d-minified/preload/resources/library/d/library-preload.js.map index 1eabfb66d..2fd326774 100644 --- a/test/expected/build/library.d-minified/preload/resources/library/d/library-preload.js.map +++ b/test/expected/build/library.d-minified/preload/resources/library/d/library-preload.js.map @@ -1 +1 @@ -{"version":3,"file":"library-preload.js","sections":[{"offset":{"line":1,"column":0},"map":{"version":3,"names":[],"sources":["library-preload.js?bundle-code-0"],"mappings":"AAAA;AACA","sourcesContent":["sap.ui.require.preload({\n"],"sourceRoot":""}},{"offset":{"line":5,"column":0},"map":{"version":3,"file":"some.js","names":["someNonUglifiedVariable","console","log"],"sources":["some-dbg.js"],"mappings":"AAAA;;;CAGA,WACC,IAAIA,EAA0B,QAC9BC,QAAQC,IAAI,SAAWF,EACvB,EAHD","sourceRoot":""}}]} \ No newline at end of file +{"version":3,"file":"library-preload.js","sections":[{"offset":{"line":1,"column":0},"map":{"version":3,"names":[],"sources":["library-preload.js?bundle-code-0"],"mappings":"AAAA;AACA","sourcesContent":["sap.ui.require.preload({\n"],"sourceRoot":""}},{"offset":{"line":3,"column":0},"map":{"version":3,"file":"empty.js","names":[],"sources":[],"mappings":"AAAA","ignoreList":[],"sourceRoot":""}},{"offset":{"line":11,"column":0},"map":{"version":3,"file":"some.js","names":["someNonUglifiedVariable","console","log"],"sources":["some-dbg.js"],"mappings":"AAAA;;;CAGA,WACC,IAAIA,EAA0B,QAC9BC,QAAQC,IAAI,SAAWF,EACvB,EAHD","sourceRoot":""}}]} \ No newline at end of file diff --git a/test/expected/build/library.d/dest/resources/library/d/empty-dbg.js b/test/expected/build/library.d/dest/resources/library/d/empty-dbg.js new file mode 100644 index 000000000..c82b694dc --- /dev/null +++ b/test/expected/build/library.d/dest/resources/library/d/empty-dbg.js @@ -0,0 +1,3 @@ +/*! + * Some fancy copyright + */ diff --git a/test/expected/build/library.d/dest/resources/library/d/empty.js b/test/expected/build/library.d/dest/resources/library/d/empty.js new file mode 100644 index 000000000..8af07c600 --- /dev/null +++ b/test/expected/build/library.d/dest/resources/library/d/empty.js @@ -0,0 +1,5 @@ +/*! + * Some fancy copyright + */ + +//# sourceMappingURL=empty.js.map \ No newline at end of file diff --git a/test/expected/build/library.d/dest/resources/library/d/empty.js.map b/test/expected/build/library.d/dest/resources/library/d/empty.js.map new file mode 100644 index 000000000..767ef9fbd --- /dev/null +++ b/test/expected/build/library.d/dest/resources/library/d/empty.js.map @@ -0,0 +1 @@ +{"version":3,"file":"empty.js","names":[],"sources":[],"mappings":"","ignoreList":[]} \ No newline at end of file diff --git a/test/expected/build/library.d/preload/resources/library/d/empty.js b/test/expected/build/library.d/preload/resources/library/d/empty.js new file mode 100644 index 000000000..117426a83 --- /dev/null +++ b/test/expected/build/library.d/preload/resources/library/d/empty.js @@ -0,0 +1,3 @@ +/*! + * ${copyright} + */ diff --git a/test/expected/build/library.d/preload/resources/library/d/library-preload.js b/test/expected/build/library.d/preload/resources/library/d/library-preload.js index 587515c70..4099e45b7 100644 --- a/test/expected/build/library.d/preload/resources/library/d/library-preload.js +++ b/test/expected/build/library.d/preload/resources/library/d/library-preload.js @@ -31,6 +31,11 @@ sap.ui.predefine("library/d/some", ["./library"], (_library) => { console.log('Hello ' + someNonUglifiedVariable); }); sap.ui.require.preload({ + "library/d/empty.js":function(){ +/*! + * ${copyright} + */ +}, "library/d/legacy.js":'/*!\n * ${copyright}\n */\nvar topLevelVar = "Old World";\nconsole.log(\'Hello \' + topLevelVar);\n' }); //# sourceMappingURL=library-preload.js.map diff --git a/test/expected/build/library.d/preload/resources/library/d/library-preload.js.map b/test/expected/build/library.d/preload/resources/library/d/library-preload.js.map index 8356c9adf..8e99bab16 100644 --- a/test/expected/build/library.d/preload/resources/library/d/library-preload.js.map +++ b/test/expected/build/library.d/preload/resources/library/d/library-preload.js.map @@ -1 +1 @@ -{"version":3,"file":"library-preload.js","sections":[{"offset":{"line":1,"column":0},"map":{"version":3,"names":[],"sources":["library.js"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourceRoot":""}},{"offset":{"line":24,"column":0},"map":{"version":3,"names":[],"sources":["some.js"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourceRoot":""}},{"offset":{"line":32,"column":0},"map":{"version":3,"names":[],"sources":["library-preload.js?bundle-code-0"],"mappings":"AAAA;AACA","sourcesContent":["sap.ui.require.preload({\n"],"sourceRoot":""}}]} \ No newline at end of file +{"version":3,"file":"library-preload.js","sections":[{"offset":{"line":1,"column":0},"map":{"version":3,"names":[],"sources":["library.js"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourceRoot":""}},{"offset":{"line":24,"column":0},"map":{"version":3,"names":[],"sources":["some.js"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourceRoot":""}},{"offset":{"line":32,"column":0},"map":{"version":3,"names":[],"sources":["library-preload.js?bundle-code-0"],"mappings":"AAAA;AACA","sourcesContent":["sap.ui.require.preload({\n"],"sourceRoot":""}},{"offset":{"line":34,"column":0},"map":{"version":3,"names":[],"sources":["empty.js"],"mappings":"AAAA;AACA;AACA;AACA","sourceRoot":""}}]} \ No newline at end of file diff --git a/test/fixtures/library.d-minified/main/src/library/d/empty.js b/test/fixtures/library.d-minified/main/src/library/d/empty.js new file mode 100644 index 000000000..8af07c600 --- /dev/null +++ b/test/fixtures/library.d-minified/main/src/library/d/empty.js @@ -0,0 +1,5 @@ +/*! + * Some fancy copyright + */ + +//# sourceMappingURL=empty.js.map \ No newline at end of file diff --git a/test/fixtures/library.d-minified/main/src/library/d/empty.js.map b/test/fixtures/library.d-minified/main/src/library/d/empty.js.map new file mode 100644 index 000000000..767ef9fbd --- /dev/null +++ b/test/fixtures/library.d-minified/main/src/library/d/empty.js.map @@ -0,0 +1 @@ +{"version":3,"file":"empty.js","names":[],"sources":[],"mappings":"","ignoreList":[]} \ No newline at end of file diff --git a/test/fixtures/library.d/main/src/library/d/empty.js b/test/fixtures/library.d/main/src/library/d/empty.js new file mode 100644 index 000000000..117426a83 --- /dev/null +++ b/test/fixtures/library.d/main/src/library/d/empty.js @@ -0,0 +1,3 @@ +/*! + * ${copyright} + */ diff --git a/test/lib/tasks/bundlers/generateLibraryPreload.integration.js b/test/lib/tasks/bundlers/generateLibraryPreload.integration.js index 76394a1e4..873902922 100644 --- a/test/lib/tasks/bundlers/generateLibraryPreload.integration.js +++ b/test/lib/tasks/bundlers/generateLibraryPreload.integration.js @@ -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); @@ -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);