From 61c7d374f3bc732e7d05644078ff526f48287728 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 22 Dec 2015 11:28:49 -0500 Subject: [PATCH 1/2] squelch duplicate warnings per-bundle (#362) --- src/Bundle.js | 4 ++-- src/utils/defaults.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index dabbde2..c099301 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -6,7 +6,7 @@ import Module from './Module.js'; import ExternalModule from './ExternalModule.js'; import finalisers from './finalisers/index.js'; import ensureArray from './utils/ensureArray.js'; -import { load, onwarn, resolveId } from './utils/defaults.js'; +import { load, makeOnwarn, resolveId } from './utils/defaults.js'; import getExportMode from './utils/getExportMode.js'; import getIndentString from './utils/getIndentString.js'; import { unixizePath } from './utils/normalizePlatform.js'; @@ -49,7 +49,7 @@ export default class Bundle { this.assumedGlobals = blank(); this.external = options.external || []; - this.onwarn = options.onwarn || onwarn; + this.onwarn = options.onwarn || makeOnwarn(); // TODO strictly speaking, this only applies with non-ES6, non-default-only bundles [ 'module', 'exports' ].forEach( global => this.assumedGlobals[ global ] = true ); diff --git a/src/utils/defaults.js b/src/utils/defaults.js index 9deea1f..bf26801 100644 --- a/src/utils/defaults.js +++ b/src/utils/defaults.js @@ -1,5 +1,6 @@ import { isFile, readFileSync } from './fs.js'; import { dirname, isAbsolute, resolve } from './path.js'; +import { blank } from './object.js'; export function load ( id ) { return readFileSync( id, 'utf-8' ); @@ -27,6 +28,13 @@ export function resolveId ( importee, importer ) { return addJsExtensionIfNecessary( resolve( dirname( importer ), importee ) ); } -export function onwarn ( msg ) { - console.error( msg ); //eslint-disable-line no-console + +export function makeOnwarn ( msg ) { + let warned = blank(); + + return msg => { + if ( msg in warned ) return; + console.error( msg ); //eslint-disable-line no-console + warned[ msg ] = true; + }; } From 1dc76ca715e2df8adc9cb97adaf3dfd67284d7b7 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 22 Dec 2015 11:47:42 -0500 Subject: [PATCH 2/2] linting --- src/utils/defaults.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/defaults.js b/src/utils/defaults.js index bf26801..4753d1b 100644 --- a/src/utils/defaults.js +++ b/src/utils/defaults.js @@ -29,7 +29,7 @@ export function resolveId ( importee, importer ) { } -export function makeOnwarn ( msg ) { +export function makeOnwarn () { let warned = blank(); return msg => {