Skip to content

Commit

Permalink
fixed sourcemap file JSON error (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Dec 18, 2024
1 parent 499a642 commit 1c703aa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/converter/collect-source-maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions lib/platform/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1c703aa

Please sign in to comment.