Skip to content

Commit

Permalink
Merge pull request #313 from mydea/fn/fix-source-map-lookup
Browse files Browse the repository at this point in the history
fix: Fix sourcemap file lookup
  • Loading branch information
ef4 committed Oct 31, 2023
2 parents 8e5decf + a31c803 commit 2e9bd88
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/get-sourcemap-content.js
Expand Up @@ -2,20 +2,24 @@

const fs = require('fs');
const path = require('path');
const srcURL = require('source-map-url');
const srcURL = require('./source-map-url');

module.exports = function getSourceMapContent(src, inFileDirname, relativePath, silent) {
let urls = [];
let matchedUrl;
srcURL.reset();
while ((matchedUrl = srcURL.getFrom(src)) !== null) {
urls.push(matchedUrl);
src = srcURL.removeFrom(src);
}
if (urls.length) {
for (let i = urls.length - 1; i >= 0; --i) {
let sourceMapPath = path.join(inFileDirname, urls[i]);
if (fs.existsSync(sourceMapPath)) {
return JSON.parse(fs.readFileSync(sourceMapPath));
try {
return JSON.parse(fs.readFileSync(sourceMapPath));
} catch (e) {
console.error('[ERROR] (broccoli-terser-sourcemap) failed to parse sourcemap file', sourceMapPath, e);
}
}
}
if (!silent) {
Expand Down
18 changes: 18 additions & 0 deletions lib/source-map-url.js
@@ -0,0 +1,18 @@
'use strict';

// Forked from https://github.com/lydell/source-map-url/blob/master/source-map-url.js
// We use a slightly adjusted regex here
const convertSourceMap = require('convert-source-map');

module.exports = {
regex: convertSourceMap.mapFileCommentRegex,

reset() {
this.regex = convertSourceMap.mapFileCommentRegex;
},

getFrom(code) {
const m = this.regex.exec(code);
return m ? m[1] || m[2] : null;
},
};
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -38,10 +38,10 @@
"dependencies": {
"async-promise-queue": "^1.0.5",
"broccoli-plugin": "^4.0.7",
"convert-source-map": "^2.0.0",
"debug": "^4.3.1",
"lodash.defaultsdeep": "^4.6.1",
"matcher-collection": "^2.0.1",
"source-map-url": "^0.4.1",
"symlink-or-copy": "^1.3.1",
"terser": "^5.7.0",
"walk-sync": "^2.2.0",
Expand Down
21 changes: 21 additions & 0 deletions test/__snapshots__/test.js.snap
Expand Up @@ -16,6 +16,7 @@ Object {
background: white;
}",
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}",
"with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}",
}
`;

Expand Down Expand Up @@ -65,6 +66,9 @@ function third(){
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}
//# sourceMappingURL=with-broken-sourcemap.map",
"with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}",
"with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}
//# sourceMappingURL=with-sourcemap-like-string.map",
"with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}",
}
`;

Expand Down Expand Up @@ -102,6 +106,9 @@ Object {
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}
//# sourceMappingURL=with-broken-sourcemap.map",
"with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}",
"with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}
//# sourceMappingURL=with-sourcemap-like-string.map",
"with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}",
}
`;

Expand Down Expand Up @@ -131,6 +138,9 @@ Object {
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}
//# sourceMappingURL=with-broken-sourcemap.map",
"with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}",
"with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}
//# sourceMappingURL=with-sourcemap-like-string.map",
"with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}",
}
`;

Expand Down Expand Up @@ -164,6 +174,9 @@ Object {
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}
//# sourceMappingURL=with-broken-sourcemap.map",
"with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}",
"with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}
//# sourceMappingURL=with-sourcemap-like-string.map",
"with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}",
}
`;

Expand All @@ -178,6 +191,7 @@ Object {
"no-upstream-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"no-upstream-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\",\\"boom\\",\\"somethingElse\\",\\"fourth\\",\\"third\\"],\\"mappings\\":\\"AACA,SAASA,gBAEP,MAAM,IAAIC,MADa,IAIzB,SAASC,OACP,MAAM,IAAID,MAAM,QAGlB,SAASE,gBACP,MAAM,IAAIF,MAAM,kBAMlB,SAASG,SACP,MAAM,IAAIH,MAAM,UAGlB,SAASI,QACP,MAAM,IAAIJ,MAAM\\",\\"file\\":\\"no-upstream-sourcemap.js\\"}",
"with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}",
"with-multi-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"/inner/first.js\\",\\"/inner/second.js\\",\\"/other/fourth.js\\",\\"/other/third.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\",\\"boom\\",\\"somethingElse\\",\\"fourth\\",\\"third\\"],\\"mappings\\":\\"AAAA,SAAAA,gBAEA,MAAA,IAAAC,MADA,IAIA,SAAAC,OACA,MAAA,IAAAD,MAAA,QCNA,SAAAE,gBACA,MAAA,IAAAF,MAAA,kBCEA,SAAAG,SACA,MAAA,IAAAH,MAAA,UCJA,SAAAI,QACA,MAAA,IAAAJ,MAAA\\",\\"file\\":\\"with-multi-sourcemap.js\\",\\"sourcesContent\\":[\\"function meaningOfLife() {\\\\n var thisIsALongLocal = 42;\\\\n throw new Error(thisIsALongLocal);\\\\n}\\\\n\\\\nfunction boom() {\\\\n throw new Error('boom');\\\\n}\\\\n\\",\\"function somethingElse() {\\\\n throw new Error(\\\\\\"somethign else\\\\\\");\\\\n}\\\\n\\",\\"\\\\n// Hello world\\\\n\\\\nfunction fourth(){\\\\n throw new Error('fourth');\\\\n}\\\\n\\",\\"function third(){\\\\n throw new Error(\\\\\\"oh no\\\\\\");\\\\n}\\\\n\\"]}",
"with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}",
"with-upstream-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"/inner/first.js\\",\\"/inner/second.js\\",\\"/other/fourth.js\\",\\"/other/third.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\",\\"boom\\",\\"somethingElse\\",\\"fourth\\",\\"third\\"],\\"mappings\\":\\"AAAA,SAAAA,gBAEA,MAAA,IAAAC,MADA,IAIA,SAAAC,OACA,MAAA,IAAAD,MAAA,QCNA,SAAAE,gBACA,MAAA,IAAAF,MAAA,kBCEA,SAAAG,SACA,MAAA,IAAAH,MAAA,UCJA,SAAAI,QACA,MAAA,IAAAJ,MAAA\\",\\"file\\":\\"with-upstream-sourcemap.js\\",\\"sourcesContent\\":[\\"function meaningOfLife() {\\\\n var thisIsALongLocal = 42;\\\\n throw new Error(thisIsALongLocal);\\\\n}\\\\n\\\\nfunction boom() {\\\\n throw new Error('boom');\\\\n}\\\\n\\",\\"function somethingElse() {\\\\n throw new Error(\\\\\\"somethign else\\\\\\");\\\\n}\\\\n\\",\\"\\\\n// Hello world\\\\n\\\\nfunction fourth(){\\\\n throw new Error('fourth');\\\\n}\\\\n\\",\\"function third(){\\\\n throw new Error(\\\\\\"oh no\\\\\\");\\\\n}\\\\n\\"]}",
},
"mjs": Object {
Expand All @@ -195,6 +209,8 @@ Object {
}",
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}
//# sourceMappingURL=/maps/with-broken-sourcemap.map",
"with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}
//# sourceMappingURL=/maps/with-sourcemap-like-string.map",
}
`;

Expand All @@ -219,6 +235,8 @@ Object {
}",
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}",
"with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}",
"with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}",
"with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}",
}
`;

Expand Down Expand Up @@ -248,5 +266,8 @@ Object {
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}
//# sourceMappingURL=https://example.com/with-broken-sourcemap.map",
"with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}",
"with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}
//# sourceMappingURL=https://example.com/with-sourcemap-like-string.map",
"with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}",
}
`;
19 changes: 19 additions & 0 deletions test/fixtures/with-sourcemap-like-string.js
@@ -0,0 +1,19 @@
function createURL(base64, sourcemapArg, enableUnicodeArg) {
var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg;
var source = decodeBase64(base64, enableUnicode);
var start = source.indexOf('\n', 10) + 1;
var body = source.substring(start) + (sourcemap ? '\/\/# sourceMappingURL=' + sourcemap : '');
var blob = new Blob([body], { type: 'application/javascript' });
return URL.createObjectURL(blob);
}

function createURL2(base64, sourcemapArg, enableUnicodeArg) {
var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg;
var source = decodeBase64(base64, enableUnicode);
var start = source.indexOf('\n', 10) + 1;
var body = source.substring(start) + (sourcemap ? '//# sourceMappingURL=' + sourcemap : '');
var blob = new Blob([body], { type: 'application/javascript' });
return URL.createObjectURL(blob);
}

0 comments on commit 2e9bd88

Please sign in to comment.