From 881364117081d401ba4a2fd4cf7426781c5b3056 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Thu, 29 Dec 2016 16:06:56 -0500 Subject: [PATCH] include location info in stringified warnings --- src/Bundle.js | 9 ++++++++- src/utils/defaults.js | 9 +++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index f2f0dd2..520fa45 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -586,7 +586,14 @@ export default class Bundle { } warn ( warning ) { - warning.toString = () => warning.message || warning; + warning.toString = () => { + if ( warning.loc ) { + return `${warning.loc.file} (${warning.loc.line}:${warning.loc.column}) ${warning.message}`; + } + + return warning.message; + }; + this.onwarn( warning ); } } diff --git a/src/utils/defaults.js b/src/utils/defaults.js index 8db3c0b..c5dd054 100644 --- a/src/utils/defaults.js +++ b/src/utils/defaults.js @@ -45,9 +45,10 @@ export function resolveId ( importee, importer ) { export function makeOnwarn () { const warned = blank(); - return msg => { - if ( msg in warned ) return; - console.error( msg ); //eslint-disable-line no-console - warned[ msg ] = true; + return warning => { + const str = warning.toString(); + if ( str in warned ) return; + console.error( str ); //eslint-disable-line no-console + warned[ str ] = true; }; }