diff --git a/packages/json/src/index.js b/packages/json/src/index.js index 63e37c280..9dd8d81db 100755 --- a/packages/json/src/index.js +++ b/packages/json/src/index.js @@ -24,8 +24,7 @@ export default function json(options = {}) { }; } catch (err) { const message = 'Could not parse JSON file'; - const position = parseInt(/[\d]/.exec(err.message)[0], 10); - this.warn({ message, id, position }); + this.warn({ message, id, cause: err }); return null; } } diff --git a/packages/json/test/test.js b/packages/json/test/test.js index 95ce01d33..e9e003500 100755 --- a/packages/json/test/test.js +++ b/packages/json/test/test.js @@ -81,11 +81,11 @@ test('handles garbage', async (t) => { onwarn: (warning) => warns.push(warning) }).catch(() => {}); - const [{ message, id, position, plugin }] = warns; + const [{ message, id, cause, plugin }] = warns; t.is(warns.length, 1); t.is(plugin, 'json'); - t.is(position, 1); + t.instanceOf(cause, SyntaxError); t.is(message, 'Could not parse JSON file'); t.regex(id, /(.*)bad.json$/); });