diff --git a/package.json b/package.json index b4ebcee5a0..673ada54f5 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "eslint": "^3.9.0", "eslint-config-babel": "^6.0.0", "eslint-plugin-flowtype": "^2.20.0", - "flow-bin": "^0.34.0", + "flow-bin": "^0.41.0", "gulp": "^3.9.0", "gulp-babel": "^6.0.0", "gulp-newer": "^1.0.0", diff --git a/packages/babel-core/src/transformation/file/options/build-config-chain.js b/packages/babel-core/src/config/build-config-chain.js similarity index 97% rename from packages/babel-core/src/transformation/file/options/build-config-chain.js rename to packages/babel-core/src/config/build-config-chain.js index df05a06443..a8659f0960 100644 --- a/packages/babel-core/src/transformation/file/options/build-config-chain.js +++ b/packages/babel-core/src/config/build-config-chain.js @@ -1,5 +1,5 @@ -import * as babel from "../../../index"; -import resolve from "../../../helpers/resolve"; +import * as babel from "../index"; +import resolve from "./helpers/resolve"; import json5 from "json5"; import path from "path"; import fs from "fs"; @@ -28,6 +28,7 @@ export default function buildConfigChain(opts: Object = {}) { try { builder.mergeConfig({ + type: "arguments", options: opts, alias: "base", dirname: process.cwd(), @@ -185,6 +186,7 @@ class ConfigChainBuilder { if (lines.length) { this.mergeConfig({ + type: "options", options: { ignore: lines }, alias: loc, dirname: path.dirname(loc), @@ -231,6 +233,7 @@ class ConfigChainBuilder { } this.mergeConfig({ + type: "options", options, alias: loc, dirname: path.dirname(loc), @@ -240,6 +243,7 @@ class ConfigChainBuilder { } mergeConfig({ + type, options, alias, loc, @@ -266,6 +270,7 @@ class ConfigChainBuilder { delete options.env; this.mergeConfig({ + type, options: envOpts, alias: `${alias}.env.${envKey}`, dirname: dirname, @@ -273,6 +278,7 @@ class ConfigChainBuilder { } this.configs.push({ + type, options, alias, loc, diff --git a/packages/babel-core/src/helpers/environment.js b/packages/babel-core/src/config/helpers/environment.js similarity index 100% rename from packages/babel-core/src/helpers/environment.js rename to packages/babel-core/src/config/helpers/environment.js diff --git a/packages/babel-core/src/helpers/get-possible-plugin-names.js b/packages/babel-core/src/config/helpers/get-possible-plugin-names.js similarity index 100% rename from packages/babel-core/src/helpers/get-possible-plugin-names.js rename to packages/babel-core/src/config/helpers/get-possible-plugin-names.js diff --git a/packages/babel-core/src/helpers/get-possible-preset-names.js b/packages/babel-core/src/config/helpers/get-possible-preset-names.js similarity index 100% rename from packages/babel-core/src/helpers/get-possible-preset-names.js rename to packages/babel-core/src/config/helpers/get-possible-preset-names.js diff --git a/packages/babel-core/src/helpers/merge.js b/packages/babel-core/src/config/helpers/merge.js similarity index 100% rename from packages/babel-core/src/helpers/merge.js rename to packages/babel-core/src/config/helpers/merge.js diff --git a/packages/babel-core/src/helpers/resolve-from-possible-names.js b/packages/babel-core/src/config/helpers/resolve-from-possible-names.js similarity index 100% rename from packages/babel-core/src/helpers/resolve-from-possible-names.js rename to packages/babel-core/src/config/helpers/resolve-from-possible-names.js diff --git a/packages/babel-core/src/helpers/resolve-plugin.js b/packages/babel-core/src/config/helpers/resolve-plugin.js similarity index 100% rename from packages/babel-core/src/helpers/resolve-plugin.js rename to packages/babel-core/src/config/helpers/resolve-plugin.js diff --git a/packages/babel-core/src/helpers/resolve-preset.js b/packages/babel-core/src/config/helpers/resolve-preset.js similarity index 100% rename from packages/babel-core/src/helpers/resolve-preset.js rename to packages/babel-core/src/config/helpers/resolve-preset.js diff --git a/packages/babel-core/src/helpers/resolve.js b/packages/babel-core/src/config/helpers/resolve.js similarity index 100% rename from packages/babel-core/src/helpers/resolve.js rename to packages/babel-core/src/config/helpers/resolve.js diff --git a/packages/babel-core/src/config/index.js b/packages/babel-core/src/config/index.js new file mode 100644 index 0000000000..3c8f49a157 --- /dev/null +++ b/packages/babel-core/src/config/index.js @@ -0,0 +1,30 @@ +import type Plugin from "./plugin"; +import OptionManager from "./option-manager"; + +export type ResolvedConfig = { + options: Object, + passes: Array>, +}; + +/** + * Standard API for loading Babel configuration data. Not for public consumption. + */ +export default function loadConfig(opts: Object): ResolvedConfig|null { + const mergedOpts = new OptionManager().init(opts); + if (!mergedOpts) return null; + + let passes = []; + if (mergedOpts.plugins) { + passes.push(mergedOpts.plugins); + } + + // With "passPerPreset" enabled there may still be presets in the options. + if (mergedOpts.presets) { + passes = passes.concat(mergedOpts.presets.map((preset) => preset.plugins).filter(Boolean)); + } + + return { + options: mergedOpts, + passes, + }; +} diff --git a/packages/babel-core/src/transformation/file/options/option-manager.js b/packages/babel-core/src/config/option-manager.js similarity index 77% rename from packages/babel-core/src/transformation/file/options/option-manager.js rename to packages/babel-core/src/config/option-manager.js index df43555c5f..cb501f00b8 100644 --- a/packages/babel-core/src/transformation/file/options/option-manager.js +++ b/packages/babel-core/src/config/option-manager.js @@ -1,15 +1,15 @@ -import * as context from "../../../index"; -import Plugin from "../../plugin"; +import * as context from "../index"; +import Plugin from "./plugin"; import * as messages from "babel-messages"; -import resolvePlugin from "../../../helpers/resolve-plugin"; -import resolvePreset from "../../../helpers/resolve-preset"; +import resolve from "./helpers/resolve"; +import resolvePlugin from "./helpers/resolve-plugin"; +import resolvePreset from "./helpers/resolve-preset"; import defaults from "lodash/defaults"; import cloneDeepWith from "lodash/cloneDeepWith"; -import merge from "../../../helpers/merge"; +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; @@ -25,6 +25,7 @@ type PluginObject = { }; type MergeOptions = { + type: "arguments"|"options"|"preset", options?: Object, extending?: Object, alias: string, @@ -188,6 +189,7 @@ export default class OptionManager { */ mergeOptions({ + type, options: rawOpts, extending: extendingOpts, alias, @@ -213,6 +215,23 @@ export default class OptionManager { dirname = dirname || process.cwd(); loc = loc || alias; + if (type !== "arguments") { + if (opts.filename !== undefined) { + throw new Error(`${alias}.filename is only allowed as a root argument`); + } + + if (opts.babelrc !== undefined) { + throw new Error(`${alias}.babelrc is only allowed as a root argument`); + } + } + + if (type === "preset") { + if (opts.only !== undefined) throw new Error(`${alias}.only is not supported in a preset`); + if (opts.ignore !== undefined) throw new Error(`${alias}.ignore is not supported in a preset`); + if (opts.extends !== undefined) throw new Error(`${alias}.extends is not supported in a preset`); + if (opts.env !== undefined) throw new Error(`${alias}.env is not supported in a preset`); + } + if (opts.sourceMap !== undefined) { if (opts.sourceMaps !== undefined) { throw new Error(`Both ${alias}.sourceMap and .sourceMaps have been set`); @@ -236,6 +255,26 @@ export default class OptionManager { } } + if (opts.parserOpts && typeof opts.parserOpts.parser === "string") { + const parser = resolve(opts.parserOpts.parser, dirname); + if (parser) { + opts.parserOpts.parser = require(parser).parse; + } else { + throw new Error(`Couldn't find parser ${opts.parserOpts.parser} with "parse" method ` + + `relative to directory ${dirname}`); + } + } + + if (opts.generatorOpts && typeof opts.generatorOpts.generator === "string") { + const generator = resolve(opts.generatorOpts.generator, dirname); + if (generator) { + opts.generatorOpts.generator = require(generator).print; + } else { + throw new Error(`Couldn't find generator ${opts.generatorOpts.generator} with "print" method ` + + `relative to directory ${dirname}`); + } + } + // resolve plugins if (opts.plugins) { if (!Array.isArray(rawOpts.plugins)) throw new Error(`${alias}.plugins should be an array`); @@ -247,23 +286,22 @@ export default class OptionManager { if (opts.presets) { if (!Array.isArray(rawOpts.presets)) throw new Error(`${alias}.presets should be an array`); - // If we're in the "pass per preset" mode, we resolve the presets - // and keep them for further execution to calculate the options. - if (opts.passPerPreset) { - opts.presets = this.resolvePresets(opts.presets, dirname, (preset, presetLoc) => { - this.mergeOptions({ - options: preset, - extending: preset, - alias: presetLoc, - loc: presetLoc, - dirname: dirname, - }); + opts.presets = this.resolvePresets(opts.presets, dirname, (preset, presetLoc) => { + this.mergeOptions({ + type: "preset", + options: preset, + + // For `passPerPreset` we merge child options back into the preset object instead of the root. + extending: opts.passPerPreset ? preset : null, + alias: presetLoc, + loc: presetLoc, + dirname: dirname, }); - } else { - // Otherwise, just merge presets options into the main options. - this.mergePresets(opts.presets, dirname); - delete opts.presets; - } + }); + + // If not passPerPreset, the plugins have all been merged into the parent config so the presets + // list is not needed. + if (!opts.passPerPreset) delete opts.presets; } // Merge them into current extending options in case of top-level @@ -276,21 +314,6 @@ export default class OptionManager { } } - /** - * Merges all presets into the main options in case we are not in the - * "pass per preset" mode. Otherwise, options are calculated per preset. - */ - mergePresets(presets: Array, dirname: string) { - this.resolvePresets(presets, dirname, (presetOpts, presetLoc) => { - this.mergeOptions({ - options: presetOpts, - alias: presetLoc, - loc: presetLoc, - dirname: path.dirname(presetLoc || ""), - }); - }); - } - /** * Resolves presets options which can be either direct object data, * or a module name to require. @@ -370,7 +393,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/plugin.js b/packages/babel-core/src/config/plugin.js similarity index 93% rename from packages/babel-core/src/transformation/plugin.js rename to packages/babel-core/src/config/plugin.js index 75665c1552..fb637d7cee 100644 --- a/packages/babel-core/src/transformation/plugin.js +++ b/packages/babel-core/src/config/plugin.js @@ -1,15 +1,12 @@ -import OptionManager from "./file/options/option-manager"; +import OptionManager from "./option-manager"; import * as messages from "babel-messages"; -import Store from "../store"; import traverse from "babel-traverse"; import clone from "lodash/clone"; const GLOBAL_VISITOR_PROPS = ["enter", "exit"]; -export default class Plugin extends Store { +export default class Plugin { constructor(plugin: Object, key?: string) { - super(); - this.initialized = false; this.raw = Object.assign({}, plugin); this.key = this.take("name") || key; diff --git a/packages/babel-core/src/transformation/file/options/removed.js b/packages/babel-core/src/config/removed.js similarity index 100% rename from packages/babel-core/src/transformation/file/options/removed.js rename to packages/babel-core/src/config/removed.js diff --git a/packages/babel-core/src/helpers/normalize-ast.js b/packages/babel-core/src/helpers/normalize-ast.js deleted file mode 100644 index d2c91cef91..0000000000 --- a/packages/babel-core/src/helpers/normalize-ast.js +++ /dev/null @@ -1,23 +0,0 @@ -import * as t from "babel-types"; - -/** - * Normalize an AST. - * - * - Wrap `Program` node with a `File` node. - */ - -export default function ( - ast: Object, - comments?: Array, - tokens?: Array, -) { - if (ast) { - if (ast.type === "Program") { - return t.file(ast, comments || [], tokens || []); - } else if (ast.type === "File") { - return ast; - } - } - - throw new Error("Not a valid ast?"); -} diff --git a/packages/babel-core/src/index.js b/packages/babel-core/src/index.js index f3fa340eb5..75741c26be 100644 --- a/packages/babel-core/src/index.js +++ b/packages/babel-core/src/index.js @@ -1,17 +1,30 @@ export File from "./transformation/file"; export buildExternalHelpers from "./tools/build-external-helpers"; -export resolvePlugin from "./helpers/resolve-plugin"; -export resolvePreset from "./helpers/resolve-preset"; +export resolvePlugin from "./config/helpers/resolve-plugin"; +export resolvePreset from "./config/helpers/resolve-preset"; export { version } from "../package"; -export { getEnv } from "./helpers/environment"; +export { getEnv } from "./config/helpers/environment"; export * as messages from "babel-messages"; export * as types from "babel-types"; export traverse from "babel-traverse"; export template from "babel-template"; -export OptionManager from "./transformation/file/options/option-manager"; +import loadConfig from "./config"; + +export function loadOptions(opts): Object|null { + const config = loadConfig(opts); + + return config ? config.options : null; +} + +// For easier backward-compatibility, provide an API like the one we exposed in Babel 6. +export class OptionManager { + init(opts) { + return loadOptions(opts); + } +} export function Plugin(alias) { throw new Error(`The (${alias}) Babel 5 plugin is being run with Babel 6.`); diff --git a/packages/babel-core/src/transformation/file/index.js b/packages/babel-core/src/transformation/file/index.js index 9d5af49ff0..dc940b53de 100644 --- a/packages/babel-core/src/transformation/file/index.js +++ b/packages/babel-core/src/transformation/file/index.js @@ -9,23 +9,28 @@ import sourceMap from "source-map"; import generate from "babel-generator"; import codeFrame from "babel-code-frame"; import traverse from "babel-traverse"; -import Store from "../../store"; +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 loadConfig, { type ResolvedConfig } from "../../config"; 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 = [ - [blockHoistPlugin], - [shadowFunctionsPlugin], -]; +const INTERNAL_PLUGINS = loadConfig({ + babelrc: false, + plugins: [ blockHoistPlugin, shadowFunctionsPlugin ], +}).passes[0]; const errorVisitor = { enter(path, state) { @@ -38,17 +43,11 @@ const errorVisitor = { }; export default class File extends Store { - constructor(opts: Object = {}) { + constructor({ options, passes }: ResolvedConfig) { super(); - let passes = []; - if (opts.plugins) passes.push(opts.plugins); - - // With "passPerPreset" enabled there may still be presets in the options. - if (opts.presets) passes = passes.concat(opts.presets.map((preset) => preset.plugins).filter(Boolean)); - this.pluginPasses = passes; - this.opts = opts; + this.opts = options; this.parserOpts = { sourceType: this.opts.sourceType, @@ -59,7 +58,7 @@ export default class File extends Store { for (const pluginPairs of passes) { for (const [ plugin ] of pluginPairs) { if (plugin.manipulateOptions) { - plugin.manipulateOptions(opts, this.parserOpts, this); + plugin.manipulateOptions(this.opts, this.parserOpts, this); } } } @@ -340,18 +339,7 @@ export default class File extends Store { parserOpts = Object.assign({}, this.parserOpts, parserOpts); if (parserOpts.parser) { - if (typeof parserOpts.parser === "string") { - const dirname = path.dirname(this.opts.filename) || process.cwd(); - const parser = resolve(parserOpts.parser, dirname); - if (parser) { - parseCode = require(parser).parse; - } else { - throw new Error(`Couldn't find parser ${parserOpts.parser} with "parse" method ` + - `relative to directory ${dirname}`); - } - } else { - parseCode = parserOpts.parser; - } + parseCode = parserOpts.parser; parserOpts.parser = { parse(source) { @@ -361,9 +349,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; } @@ -381,31 +369,43 @@ 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 { for (const pluginPairs of this.pluginPasses) { + const passPairs = []; const passes = []; const visitors = []; for (const [ plugin, pluginOpts ] of pluginPairs.concat(INTERNAL_PLUGINS)) { - const pass = new PluginPass(this, plugin, pluginOpts); + const pass = new PluginPass(this, plugin.key, pluginOpts); + + passPairs.push([ plugin, pass ]); passes.push(pass); visitors.push(plugin.visitor); } - this.call("pre", passes); - util.debug(this.opts, "Start transform traverse"); + for (const [ plugin, pass ] of passPairs) { + const fn = plugin.pre; + if (fn) fn.call(pass, this); + } + + 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"); - this.call("post", passes); + debug(this.opts, "End transform traverse"); + + for (const [ plugin, pass ] of passPairs) { + const fn = plugin.post; + if (fn) fn.call(pass, this); + } + } return this.generate(); @@ -458,14 +458,6 @@ export default class File extends Store { this.addAst(ast); } - call(key: "pre" | "post", pluginPasses: Array) { - for (const pass of pluginPasses) { - const plugin = pass.plugin; - const fn = plugin[key]; - if (fn) fn.call(pass, this); - } - } - parseInputSourceMap(code: string): string { const opts = this.opts; @@ -523,27 +515,16 @@ export default class File extends Store { let gen = generate; if (opts.generatorOpts && opts.generatorOpts.generator) { gen = opts.generatorOpts.generator; - - if (typeof gen === "string") { - const dirname = path.dirname(this.opts.filename) || process.cwd(); - const generator = resolve(gen, dirname); - if (generator) { - gen = require(generator).print; - } else { - throw new Error(`Couldn't find generator ${gen} with "print" method relative ` + - `to directory ${dirname}`); - } - } } - 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/transformation/internal-plugins/block-hoist.js b/packages/babel-core/src/transformation/internal-plugins/block-hoist.js index 35dee65312..4813b18d22 100644 --- a/packages/babel-core/src/transformation/internal-plugins/block-hoist.js +++ b/packages/babel-core/src/transformation/internal-plugins/block-hoist.js @@ -1,7 +1,6 @@ -import Plugin from "../plugin"; import sortBy from "lodash/sortBy"; -export default new Plugin({ +export default { /** * [Please add a description.] * @@ -39,4 +38,4 @@ export default new Plugin({ }, }, }, -}); +}; diff --git a/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js b/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js index ce50d21c01..45122a0a3f 100644 --- a/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js +++ b/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js @@ -1,4 +1,3 @@ -import Plugin from "../plugin"; import * as t from "babel-types"; const SUPER_THIS_BOUND = Symbol("super this bound"); @@ -15,7 +14,7 @@ const superVisitor = { }, }; -export default new Plugin({ +export default { name: "internal.shadowFunctions", visitor: { @@ -29,7 +28,7 @@ export default new Plugin({ } }, }, -}); +}; function shouldShadow(path, shadowPath) { if (path.is("_forceShadow")) { diff --git a/packages/babel-core/src/transformation/pipeline.js b/packages/babel-core/src/transformation/pipeline.js index 9bf718a47e..24066e9b1c 100644 --- a/packages/babel-core/src/transformation/pipeline.js +++ b/packages/babel-core/src/transformation/pipeline.js @@ -1,25 +1,24 @@ /* global BabelFileResult, BabelFileMetadata */ import fs from "fs"; -import normalizeAst from "../helpers/normalize-ast"; -import Plugin from "./plugin"; +import * as t from "babel-types"; import File from "./file"; -import OptionManager from "./file/options/option-manager"; +import loadConfig from "../config"; export function analyse(code: string, opts: Object = {}, visitor?: Object): ?BabelFileMetadata { opts.code = false; if (visitor) { opts.plugins = opts.plugins || []; - opts.plugins.push(new Plugin({ visitor })); + opts.plugins.push({ visitor }); } return transform(code, opts).metadata; } export function transform(code: string, opts?: Object): BabelFileResult { - opts = new OptionManager().init(opts); - if (opts === null) return null; + const config = loadConfig(opts); + if (config === null) return null; - const file = new File(opts); + const file = new File(config); return file.wrap(code, function () { file.addCode(code); file.parseCode(code); @@ -28,12 +27,16 @@ export function transform(code: string, opts?: Object): BabelFileResult { } export function transformFromAst(ast: Object, code: string, opts: Object): BabelFileResult { - opts = new OptionManager().init(opts); - if (opts === null) return null; + const config = loadConfig(opts); + if (config === null) return null; - ast = normalizeAst(ast); + if (ast && ast.type === "Program") { + return t.file(ast, [], []); + } else if (!ast || ast.type !== "File") { + throw new Error("Not a valid ast?"); + } - const file = new File(opts); + const file = new File(config); return file.wrap(code, function () { file.addCode(code); file.addAst(ast); @@ -48,15 +51,15 @@ export function transformFile(filename: string, opts?: Object, callback: Functio } opts.filename = filename; - opts = new OptionManager().init(opts); - if (opts === null) return callback(null, null); + const config = loadConfig(opts); + if (config === null) return callback(null, null); fs.readFile(filename, function (err, code) { let result; if (!err) { try { - const file = new File(opts); + const file = new File(config); result = file.wrap(code, function () { file.addCode(code); file.parseCode(code); @@ -77,11 +80,11 @@ export function transformFile(filename: string, opts?: Object, callback: Functio export function transformFileSync(filename: string, opts?: Object = {}): string { opts.filename = filename; - opts = new OptionManager().init(opts); - if (opts === null) return null; + const config = loadConfig(opts); + if (config === null) return null; const code = fs.readFileSync(filename, "utf8"); - const file = new File(opts); + const file = new File(config); return file.wrap(code, function () { file.addCode(code); diff --git a/packages/babel-core/src/transformation/plugin-pass.js b/packages/babel-core/src/transformation/plugin-pass.js index 5e7ddb205d..c0a6626cf5 100644 --- a/packages/babel-core/src/transformation/plugin-pass.js +++ b/packages/babel-core/src/transformation/plugin-pass.js @@ -1,18 +1,16 @@ -import type Plugin from "./plugin"; -import Store from "../store"; +import Store from "./store"; import File from "./file"; export default class PluginPass extends Store { - constructor(file: File, plugin: Plugin, options: Object = {}) { + constructor(file: File, key: string, options: Object = {}) { super(); - this.plugin = plugin; - this.key = plugin.key; + + this.key = key; this.file = file; this.opts = options; } key: string; - plugin: Plugin; file: File; opts: Object; diff --git a/packages/babel-core/src/store.js b/packages/babel-core/src/transformation/store.js similarity index 100% rename from packages/babel-core/src/store.js rename to packages/babel-core/src/transformation/store.js 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}`; -} diff --git a/packages/babel-core/test/api.js b/packages/babel-core/test/api.js index 6f345592c5..85c8d9eeaa 100644 --- a/packages/babel-core/test/api.js +++ b/packages/babel-core/test/api.js @@ -2,7 +2,7 @@ import * as babel from "../lib/index"; import buildExternalHelpers from "../lib/tools/build-external-helpers"; import sourceMap from "source-map"; import assert from "assert"; -import Plugin from "../lib/transformation/plugin"; +import Plugin from "../lib/config/plugin"; import generator from "babel-generator"; function assertIgnored(result) { diff --git a/packages/babel-core/test/config-chain.js b/packages/babel-core/test/config-chain.js index a9cc6bd2e9..c50046ff1d 100644 --- a/packages/babel-core/test/config-chain.js +++ b/packages/babel-core/test/config-chain.js @@ -1,6 +1,6 @@ import assert from "assert"; import path from "path"; -import buildConfigChain from "../lib/transformation/file/options/build-config-chain"; +import buildConfigChain from "../lib/config/build-config-chain"; function fixture() { const args = [__dirname, "fixtures", "config"]; @@ -40,6 +40,7 @@ describe("buildConfigChain", function () { const expected = [ { + type: "options", options: { plugins: [ "extended", @@ -50,6 +51,7 @@ describe("buildConfigChain", function () { dirname: fixture(), }, { + type: "options", options: { plugins: [ "root", @@ -60,6 +62,7 @@ describe("buildConfigChain", function () { dirname: fixture(), }, { + type: "options", options: { ignore: [ "root-ignore", @@ -70,6 +73,7 @@ describe("buildConfigChain", function () { dirname: fixture(), }, { + type: "arguments", options: { filename: fixture("dir1", "src.js"), }, @@ -89,6 +93,7 @@ describe("buildConfigChain", function () { const expected = [ { + type: "options", options: { ignore: [ "root-ignore", @@ -99,6 +104,7 @@ describe("buildConfigChain", function () { dirname: fixture(), }, { + type: "options", options: { plugins: [ "dir2", @@ -109,6 +115,7 @@ describe("buildConfigChain", function () { dirname: fixture("dir2"), }, { + type: "arguments", options: { filename: fixture("dir2", "src.js"), }, @@ -128,6 +135,7 @@ describe("buildConfigChain", function () { const expected = [ { + type: "options", options: { ignore: [ "root-ignore", @@ -138,6 +146,7 @@ describe("buildConfigChain", function () { dirname: fixture(), }, { + type: "options", options: { plugins: [ "env-base", @@ -148,6 +157,7 @@ describe("buildConfigChain", function () { dirname: fixture("env"), }, { + type: "arguments", options: { filename: fixture("env", "src.js"), }, @@ -169,6 +179,7 @@ describe("buildConfigChain", function () { const expected = [ { + type: "options", options: { ignore: [ "root-ignore", @@ -179,6 +190,7 @@ describe("buildConfigChain", function () { dirname: fixture(), }, { + type: "options", options: { plugins: [ "env-base", @@ -189,6 +201,7 @@ describe("buildConfigChain", function () { dirname: fixture("env"), }, { + type: "options", options: { plugins: [ "env-foo", @@ -199,6 +212,7 @@ describe("buildConfigChain", function () { dirname: fixture("env"), }, { + type: "arguments", options: { filename: fixture("env", "src.js"), }, @@ -221,6 +235,7 @@ describe("buildConfigChain", function () { const expected = [ { + type: "options", options: { ignore: [ "root-ignore", @@ -231,6 +246,7 @@ describe("buildConfigChain", function () { dirname: fixture(), }, { + type: "options", options: { plugins: [ "env-base", @@ -241,6 +257,7 @@ describe("buildConfigChain", function () { dirname: fixture("env"), }, { + type: "options", options: { plugins: [ "env-bar", @@ -251,6 +268,7 @@ describe("buildConfigChain", function () { dirname: fixture("env"), }, { + type: "arguments", options: { filename: fixture("env", "src.js"), }, @@ -273,6 +291,7 @@ describe("buildConfigChain", function () { const expected = [ { + type: "options", options: { plugins: ["pkg-plugin"], }, @@ -281,6 +300,7 @@ describe("buildConfigChain", function () { dirname: fixture("pkg"), }, { + type: "options", options: { ignore: ["pkg-ignore"], }, @@ -289,6 +309,7 @@ describe("buildConfigChain", function () { dirname: fixture("pkg"), }, { + type: "arguments", options: { filename: fixture("pkg", "src.js"), }, @@ -308,6 +329,7 @@ describe("buildConfigChain", function () { const expected = [ { + type: "options", options: { ignore: [ "root-ignore", @@ -318,6 +340,7 @@ describe("buildConfigChain", function () { dirname: fixture(), }, { + type: "options", options: { plugins: [ "foo", @@ -329,6 +352,7 @@ describe("buildConfigChain", function () { dirname: fixture("js-config"), }, { + type: "arguments", options: { filename: fixture("js-config", "src.js"), }, @@ -348,6 +372,7 @@ describe("buildConfigChain", function () { const expected = [ { + type: "options", options: { ignore: [ "root-ignore", @@ -358,6 +383,7 @@ describe("buildConfigChain", function () { dirname: fixture(), }, { + type: "options", options: { plugins: [ "foo", @@ -369,6 +395,7 @@ describe("buildConfigChain", function () { dirname: fixture("js-config-default"), }, { + type: "arguments", options: { filename: fixture("js-config-default", "src.js"), }, @@ -387,6 +414,7 @@ describe("buildConfigChain", function () { const expected = [ { + type: "options", options: { ignore: [ "root-ignore", @@ -397,6 +425,7 @@ describe("buildConfigChain", function () { dirname: fixture(), }, { + type: "options", options: { plugins: [ "extended", @@ -407,6 +436,7 @@ describe("buildConfigChain", function () { dirname: fixture(), }, { + type: "options", options: { plugins: [ "foo", @@ -418,6 +448,7 @@ describe("buildConfigChain", function () { dirname: fixture("js-config-extended"), }, { + type: "arguments", options: { filename: fixture("js-config-extended", "src.js"), }, @@ -438,6 +469,7 @@ describe("buildConfigChain", function () { const expected = [ { + type: "options", options: { ignore: [ "root-ignore", @@ -448,6 +480,7 @@ describe("buildConfigChain", function () { dirname: fixture(), }, { + type: "options", options: { plugins: [ "json", @@ -458,6 +491,7 @@ describe("buildConfigChain", function () { dirname: fixture("json-pkg-config-no-babel"), }, { + type: "arguments", options: { filename: fixture("json-pkg-config-no-babel", "src.js"), }, diff --git a/packages/babel-core/test/get-possible-plugin-names.js b/packages/babel-core/test/get-possible-plugin-names.js index 7ce8644769..d0c14e69f9 100644 --- a/packages/babel-core/test/get-possible-plugin-names.js +++ b/packages/babel-core/test/get-possible-plugin-names.js @@ -1,5 +1,5 @@ import assert from "assert"; -import getPossiblePluginNames from "../lib/helpers/get-possible-plugin-names"; +import getPossiblePluginNames from "../lib/config/helpers/get-possible-plugin-names"; describe("getPossiblePluginNames", function () { it("adds the babel-plugin prefix", function() { diff --git a/packages/babel-core/test/get-possible-preset-names.js b/packages/babel-core/test/get-possible-preset-names.js index 40052fdfbb..0630f0fb71 100644 --- a/packages/babel-core/test/get-possible-preset-names.js +++ b/packages/babel-core/test/get-possible-preset-names.js @@ -1,5 +1,5 @@ import assert from "assert"; -import getPossiblePresetNames from "../lib/helpers/get-possible-preset-names"; +import getPossiblePresetNames from "../lib/config/helpers/get-possible-preset-names"; describe("getPossiblePresetNames", function () { it("adds the babel-preset prefix", function() { diff --git a/packages/babel-core/test/option-manager.js b/packages/babel-core/test/option-manager.js index 126ed83c27..a2cfd86faf 100644 --- a/packages/babel-core/test/option-manager.js +++ b/packages/babel-core/test/option-manager.js @@ -1,5 +1,5 @@ import assert from "assert"; -import OptionManager from "../lib/transformation/file/options/option-manager"; +import OptionManager from "../lib/config/option-manager"; import path from "path"; describe("option-manager", () => { diff --git a/packages/babel-core/test/path.js b/packages/babel-core/test/path.js index f84d7eef8e..dbc30827c5 100644 --- a/packages/babel-core/test/path.js +++ b/packages/babel-core/test/path.js @@ -1,5 +1,5 @@ import { transform } from "../lib/index"; -import Plugin from "../lib/transformation/plugin"; +import Plugin from "../lib/config/plugin"; import chai from "chai"; describe("traversal path", function () { diff --git a/packages/babel-preset-react/src/index.js b/packages/babel-preset-react/src/index.js index 5b953685aa..99bc2eac3b 100644 --- a/packages/babel-preset-react/src/index.js +++ b/packages/babel-preset-react/src/index.js @@ -3,10 +3,6 @@ import transformReactJSX from "babel-plugin-transform-react-jsx"; import transformSyntaxJSX from "babel-plugin-syntax-jsx"; import transformReactDisplayName from "babel-plugin-transform-react-display-name"; -// These imports not yet used... -// import transformReactJSXSource from "babel-plugin-transform-react-jsx-source"; -// import transformReactJSXSelf from "babel-plugin-transform-react-jsx-self"; - export default function () { return { presets: [ @@ -17,13 +13,5 @@ export default function () { transformSyntaxJSX, transformReactDisplayName, ], - env: { - development: { - plugins: [ - // transformReactJSXSource, - // transformReactJSXSelf - ], - }, - }, }; } diff --git a/packages/babel-runtime/scripts/build-dist.js b/packages/babel-runtime/scripts/build-dist.js index 3aee330207..5e73c94c67 100644 --- a/packages/babel-runtime/scripts/build-dist.js +++ b/packages/babel-runtime/scripts/build-dist.js @@ -25,7 +25,6 @@ paths.forEach(function (path) { var helpers = require("babel-helpers"); var babel = require("../../babel-core"); -var util = require("../../babel-core/lib/util"); var t = require("../../babel-types"); function relative(filename) { diff --git a/yarn.lock b/yarn.lock index b730d5b88e..0fc054e20d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1926,9 +1926,9 @@ flat-cache@^1.2.1: graceful-fs "^4.1.2" write "^0.2.1" -flow-bin@^0.34.0: - version "0.34.0" - resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.34.0.tgz#093ed36981e8fafc39d16f0b0878d0968aa80fad" +flow-bin@^0.41.0: + version "0.41.0" + resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.41.0.tgz#8badac9a19da45004997e599bd316518db489b2e" for-in@^0.1.5: version "0.1.6"