Skip to content

Commit

Permalink
stop on invalid json
Browse files Browse the repository at this point in the history
  • Loading branch information
linoleum-js committed Mar 14, 2017
1 parent b1cdb14 commit 7b5c387
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 8 additions & 1 deletion index.js
Expand Up @@ -606,7 +606,14 @@ Browserify.prototype._recorder = function (opts) {
Browserify.prototype._json = function () {
return through.obj(function (row, enc, next) {
if (/\.json$/.test(row.file)) {
row.source = 'module.exports=' + sanitize(row.source);
var sanitizedString = sanitize(row.source);
try {
// check json validity
JSON.parse(sanitizedString);
row.source = 'module.exports=' + sanitizedString;
} catch (e) {
this.emit('error', syntaxError(e.message, row.file || row.id));
}
}
this.push(row);
next();
Expand Down
1 change: 0 additions & 1 deletion test/json.js
Expand Up @@ -48,7 +48,6 @@ test('invalid json', function (t) {
t.plan(1);
b.add(__dirname + '/json/invalid.js');
b.bundle(function (err, src) {
//console.log(src);
t.ok(err);
});
});

0 comments on commit 7b5c387

Please sign in to comment.