diff --git a/CHANGELOG.md b/CHANGELOG.md index ac28141c..439e04c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +- 2.11.5 + - fixed sourcemap file JSON error (#97) + - 2.11.4 - fixed encoded source url issue - fixed filter for encoded url diff --git a/lib/converter/collect-source-maps.js b/lib/converter/collect-source-maps.js index b9ce1a44..28a8eef2 100644 --- a/lib/converter/collect-source-maps.js +++ b/lib/converter/collect-source-maps.js @@ -17,7 +17,7 @@ const loadSourceMap = async (url = '') => { Util.logDebug(EC.red(`failed to load sourcemap ${p}`)); return; } - return JSON.parse(content); + return Util.jsonParse(content); } const [err, res] = await Util.request(url); @@ -31,7 +31,7 @@ const loadSourceMap = async (url = '') => { // could be string not json, if Content-Type is application/octet-stream if (typeof content === 'string') { - return JSON.parse(content); + return Util.jsonParse(content); } return content; diff --git a/lib/platform/share.js b/lib/platform/share.js index a0e17611..ef5fb6e4 100644 --- a/lib/platform/share.js +++ b/lib/platform/share.js @@ -402,6 +402,30 @@ const Util = { return string.charAt(0).toUpperCase() + string.slice(1); }, + jsonParse: function(str) { + + if (typeof str !== 'string') { + return null; + } + + if (!str) { + return null; + } + + let json = null; + + // remove BOM \ufeff + // str = str.replace(/^\uFEFF/, ''); + + try { + json = JSON.parse(str); + } catch (e) { + // console.log(e); + } + + return json; + }, + // ============================================================================= // formatter