Skip to content

Commit 2e9bd88

Browse files
authored
Merge pull request #313 from mydea/fn/fix-source-map-lookup
fix: Fix sourcemap file lookup
2 parents 8e5decf + a31c803 commit 2e9bd88

File tree

6 files changed

+72
-5
lines changed

6 files changed

+72
-5
lines changed

lib/get-sourcemap-content.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22

33
const fs = require('fs');
44
const path = require('path');
5-
const srcURL = require('source-map-url');
5+
const srcURL = require('./source-map-url');
66

77
module.exports = function getSourceMapContent(src, inFileDirname, relativePath, silent) {
88
let urls = [];
99
let matchedUrl;
10+
srcURL.reset();
1011
while ((matchedUrl = srcURL.getFrom(src)) !== null) {
1112
urls.push(matchedUrl);
12-
src = srcURL.removeFrom(src);
1313
}
1414
if (urls.length) {
1515
for (let i = urls.length - 1; i >= 0; --i) {
1616
let sourceMapPath = path.join(inFileDirname, urls[i]);
1717
if (fs.existsSync(sourceMapPath)) {
18-
return JSON.parse(fs.readFileSync(sourceMapPath));
18+
try {
19+
return JSON.parse(fs.readFileSync(sourceMapPath));
20+
} catch (e) {
21+
console.error('[ERROR] (broccoli-terser-sourcemap) failed to parse sourcemap file', sourceMapPath, e);
22+
}
1923
}
2024
}
2125
if (!silent) {

lib/source-map-url.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
// Forked from https://github.com/lydell/source-map-url/blob/master/source-map-url.js
4+
// We use a slightly adjusted regex here
5+
const convertSourceMap = require('convert-source-map');
6+
7+
module.exports = {
8+
regex: convertSourceMap.mapFileCommentRegex,
9+
10+
reset() {
11+
this.regex = convertSourceMap.mapFileCommentRegex;
12+
},
13+
14+
getFrom(code) {
15+
const m = this.regex.exec(code);
16+
return m ? m[1] || m[2] : null;
17+
},
18+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
"dependencies": {
3939
"async-promise-queue": "^1.0.5",
4040
"broccoli-plugin": "^4.0.7",
41+
"convert-source-map": "^2.0.0",
4142
"debug": "^4.3.1",
4243
"lodash.defaultsdeep": "^4.6.1",
4344
"matcher-collection": "^2.0.1",
44-
"source-map-url": "^0.4.1",
4545
"symlink-or-copy": "^1.3.1",
4646
"terser": "^5.7.0",
4747
"walk-sync": "^2.2.0",

test/__snapshots__/test.js.snap

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Object {
1616
background: white;
1717
}",
1818
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}",
19+
"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)}",
1920
}
2021
`;
2122

@@ -65,6 +66,9 @@ function third(){
6566
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}
6667
//# sourceMappingURL=with-broken-sourcemap.map",
6768
"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\\"}",
69+
"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)}
70+
//# sourceMappingURL=with-sourcemap-like-string.map",
71+
"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\\"}",
6872
}
6973
`;
7074

@@ -102,6 +106,9 @@ Object {
102106
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}
103107
//# sourceMappingURL=with-broken-sourcemap.map",
104108
"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\\"}",
109+
"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)}
110+
//# sourceMappingURL=with-sourcemap-like-string.map",
111+
"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\\"}",
105112
}
106113
`;
107114

@@ -131,6 +138,9 @@ Object {
131138
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}
132139
//# sourceMappingURL=with-broken-sourcemap.map",
133140
"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\\"}",
141+
"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)}
142+
//# sourceMappingURL=with-sourcemap-like-string.map",
143+
"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\\"}",
134144
}
135145
`;
136146

@@ -164,6 +174,9 @@ Object {
164174
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}
165175
//# sourceMappingURL=with-broken-sourcemap.map",
166176
"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\\"}",
177+
"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)}
178+
//# sourceMappingURL=with-sourcemap-like-string.map",
179+
"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\\"}",
167180
}
168181
`;
169182

@@ -178,6 +191,7 @@ Object {
178191
"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\\"}",
179192
"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\\"}",
180193
"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\\"]}",
194+
"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\\"}",
181195
"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\\"]}",
182196
},
183197
"mjs": Object {
@@ -195,6 +209,8 @@ Object {
195209
}",
196210
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}
197211
//# sourceMappingURL=/maps/with-broken-sourcemap.map",
212+
"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)}
213+
//# sourceMappingURL=/maps/with-sourcemap-like-string.map",
198214
}
199215
`;
200216

@@ -219,6 +235,8 @@ Object {
219235
}",
220236
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}",
221237
"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\\"}",
238+
"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)}",
239+
"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\\"}",
222240
}
223241
`;
224242

@@ -248,5 +266,8 @@ Object {
248266
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}
249267
//# sourceMappingURL=https://example.com/with-broken-sourcemap.map",
250268
"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\\"}",
269+
"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)}
270+
//# sourceMappingURL=https://example.com/with-sourcemap-like-string.map",
271+
"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\\"}",
251272
}
252273
`;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function createURL(base64, sourcemapArg, enableUnicodeArg) {
2+
var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
3+
var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg;
4+
var source = decodeBase64(base64, enableUnicode);
5+
var start = source.indexOf('\n', 10) + 1;
6+
var body = source.substring(start) + (sourcemap ? '\/\/# sourceMappingURL=' + sourcemap : '');
7+
var blob = new Blob([body], { type: 'application/javascript' });
8+
return URL.createObjectURL(blob);
9+
}
10+
11+
function createURL2(base64, sourcemapArg, enableUnicodeArg) {
12+
var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
13+
var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg;
14+
var source = decodeBase64(base64, enableUnicode);
15+
var start = source.indexOf('\n', 10) + 1;
16+
var body = source.substring(start) + (sourcemap ? '//# sourceMappingURL=' + sourcemap : '');
17+
var blob = new Blob([body], { type: 'application/javascript' });
18+
return URL.createObjectURL(blob);
19+
}

0 commit comments

Comments
 (0)