Browse Source

include location info in stringified warnings

gh-786
Rich-Harris 8 years ago
parent
commit
8813641170
  1. 9
      src/Bundle.js
  2. 9
      src/utils/defaults.js

9
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 );
}
}

9
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;
};
}

Loading…
Cancel
Save