diff --git a/packages/babel-core/src/config/option-manager.js b/packages/babel-core/src/config/option-manager.js index 6cd3845f57..05859e29cb 100644 --- a/packages/babel-core/src/config/option-manager.js +++ b/packages/babel-core/src/config/option-manager.js @@ -9,7 +9,6 @@ import merge from "../helpers/merge"; import removed from "./removed"; import buildConfigChain from "./build-config-chain"; import path from "path"; -import * as util from "../util"; type PluginObject = { pre?: Function; @@ -373,7 +372,12 @@ export default class OptionManager { this.mergeOptions(config); } } catch (e) { - e.message = util.message(opts, e.message); + // There are a few case where thrown errors will try to annotate themselves multiple times, so + // to keep things simple we just bail out if re-wrapping the message. + if (!/^\[BABEL\]/.test(e.message)) { + e.message = `[BABEL] ${opts.filename || "unknown"}: ${e.message}`; + } + throw e; } diff --git a/packages/babel-core/src/transformation/file/index.js b/packages/babel-core/src/transformation/file/index.js index d47702ca45..d07b7c64da 100644 --- a/packages/babel-core/src/transformation/file/index.js +++ b/packages/babel-core/src/transformation/file/index.js @@ -11,9 +11,9 @@ import codeFrame from "babel-code-frame"; import traverse from "babel-traverse"; import Store from "../store"; import { parse } from "babylon"; -import * as util from "../../util"; import path from "path"; import * as t from "babel-types"; +import buildDebug from "debug"; import resolve from "../../helpers/resolve"; import OptionManager from "../../config/option-manager"; @@ -21,6 +21,12 @@ import OptionManager from "../../config/option-manager"; import blockHoistPlugin from "../internal-plugins/block-hoist"; import shadowFunctionsPlugin from "../internal-plugins/shadow-functions"; +const babelDebug = buildDebug("babel:file"); + +export function debug(opts: Object, msg: string) { + babelDebug(`${opts.filename || "unknown"}: ${msg}`); +} + const shebangRegex = /^#!.*/; const INTERNAL_PLUGINS = new OptionManager().init({ @@ -362,9 +368,9 @@ export default class File extends Store { } } - util.debug(this.opts, "Parse start"); + debug(this.opts, "Parse start"); const ast = parseCode(code, parserOpts || this.parserOpts); - util.debug(this.opts, "Parse stop"); + debug(this.opts, "Parse stop"); return ast; } @@ -382,9 +388,9 @@ export default class File extends Store { } addAst(ast) { - util.debug(this.opts, "Start set AST"); + debug(this.opts, "Start set AST"); this._addAst(ast); - util.debug(this.opts, "End set AST"); + debug(this.opts, "End set AST"); } transform(): BabelFileResult { @@ -408,13 +414,13 @@ export default class File extends Store { if (fn) fn.call(pass, this); } - util.debug(this.opts, "Start transform traverse"); + debug(this.opts, "Start transform traverse"); // merge all plugin visitors into a single visitor const visitor = traverse.visitors.merge(visitors, passes, this.opts.wrapPluginVisitorMethod); traverse(this.ast, visitor, this.scope); - util.debug(this.opts, "End transform traverse"); + debug(this.opts, "End transform traverse"); for (const [ plugin, pass ] of passPairs) { const fn = plugin.post; @@ -543,14 +549,14 @@ export default class File extends Store { } } - util.debug(this.opts, "Generation start"); + debug(this.opts, "Generation start"); const _result = gen(ast, opts.generatorOpts ? Object.assign(opts, opts.generatorOpts) : opts, this.code); result.code = _result.code; result.map = _result.map; - util.debug(this.opts, "Generation end"); + debug(this.opts, "Generation end"); if (this.shebang) { // add back shebang diff --git a/packages/babel-core/src/util.js b/packages/babel-core/src/util.js deleted file mode 100644 index 3caa4be75e..0000000000 --- a/packages/babel-core/src/util.js +++ /dev/null @@ -1,17 +0,0 @@ -import buildDebug from "debug"; - -export { inherits, inspect } from "util"; - -const debugBabel = buildDebug("babel"); - -export function debug(opts: Object, msg: string) { - debugBabel(message(opts, msg)); -} - -export function message(opts: Object, msg: string) { - // There are a few case where throws errors will try to annotate themselves multiple times, so - // to keep things simple we just bail out if re-wrapping the message. - if (/^\[BABEL\]/.test(msg)) return msg; - - return `[BABEL] ${opts.filename || "unknown"}: ${msg}`; -}