diff --git a/index.js b/index.js index ac53bfe0..ba93cdb6 100644 --- a/index.js +++ b/index.js @@ -91,15 +91,7 @@ module.exports = { return options; } else { // legacy codepath - let transpilerOptions = this._buildBroccoliBabelTranspilerOptions(config); - - return { - ...transpilerOptions, - babel: { - ...transpilerOptions.babel, - ...options, - }, - }; + return Object.assign({}, this._buildBroccoliBabelTranspilerOptions(config), options); } }, @@ -134,19 +126,20 @@ module.exports = { let options = { annotation: providedAnnotation || `Babel: ${_parentName(this.parent)}`, + sourceMaps, throwUnlessParallelizable, filterExtensions: this.getSupportedExtensions(config), - babel: { plugins: [], sourceMaps }, + plugins: [], }; if (shouldCompileModules) { - options.babel.moduleIds = true; - options.babel.getModuleId = require("./lib/relative-module-paths").getRelativeModulePath; + options.moduleIds = true; + options.getModuleId = require("./lib/relative-module-paths").getRelativeModulePath; } - options.babel.highlightCode = _shouldHighlightCode(this.parent); - options.babel.babelrc = false; - options.babel.configFile = false; + options.highlightCode = _shouldHighlightCode(this.parent); + options.babelrc = false; + options.configFile = false; return options; }, @@ -155,13 +148,30 @@ module.exports = { let config = _config || this._getAddonOptions(); let description = `000${++count}`.slice(-3); let postDebugTree = this._debugTree(inputTree, `${description}:input`); - let transpilerOptions = this._buildBroccoliBabelTranspilerOptions(config); - let babelOptions = this.buildBabelOptions('babel', config); + let { + // Separate Babel options from `broccoli-babel-transpiler` options. + babelrc, + configFile, + getModuleId, + highlightCode, + moduleIds, + plugins, + sourceMaps, + ...transpilerOptions + } = this._buildBroccoliBabelTranspilerOptions(config); let options = { ...transpilerOptions, + // `broccoli-babel-transpiler` now expects all Babel options to be + // present under a `babel` key. babel: { - ...transpilerOptions.babel, - ...babelOptions, + babelrc, + configFile, + getModuleId, + highlightCode, + moduleIds, + plugins, + sourceMaps, + ...this.buildBabelOptions('babel', config), }, }; diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index cf641c5d..8b70fa32 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -1592,7 +1592,7 @@ describe('ember-cli-babel', function() { let result = this.addon._buildBroccoliBabelTranspilerOptions(options); - expect(result.babel.babelrc).to.be.false; + expect(result.babelrc).to.be.false; }); it('provides an annotation including parent name - addon', function() { @@ -1632,7 +1632,7 @@ describe('ember-cli-babel', function() { }; let result = this.addon._buildBroccoliBabelTranspilerOptions(options); - expect(result.babel.sourceMaps).to.equal('inline'); + expect(result.sourceMaps).to.equal('inline'); }); it('disables reading `.babelrc`', function() { @@ -1640,7 +1640,7 @@ describe('ember-cli-babel', function() { let result = this.addon._buildBroccoliBabelTranspilerOptions(options); - expect(result.babel.babelrc).to.be.false; + expect(result.babelrc).to.be.false; }); }); @@ -1653,9 +1653,9 @@ describe('ember-cli-babel', function() { let result = this.addon.buildBabelOptions(); expect(result.annotation).to.equal('Babel: foo'); - expect(result.babel.moduleIds).to.be.true; - expect(result.babel.babelrc).to.be.false; - expect(result.babel.configFile).to.be.false; + expect(result.moduleIds).to.be.true; + expect(result.babelrc).to.be.false; + expect(result.configFile).to.be.false; }); it('returns broccoli-babel-transpiler options when asked for', function() { @@ -1664,9 +1664,9 @@ describe('ember-cli-babel', function() { let result = this.addon.buildBabelOptions('broccoli'); expect(result.annotation).to.equal('Babel: foo'); - expect(result.babel.moduleIds).to.be.true; - expect(result.babel.babelrc).to.be.false; - expect(result.babel.configFile).to.be.false; + expect(result.moduleIds).to.be.true; + expect(result.babelrc).to.be.false; + expect(result.configFile).to.be.false; }); it('returns broccoli-babel-transpiler options with customizations when provided', function() { @@ -1677,9 +1677,9 @@ describe('ember-cli-babel', function() { }); expect(result.annotation).to.equal('hello!!!'); - expect(result.babel.moduleIds).to.be.true; - expect(result.babel.babelrc).to.be.false; - expect(result.babel.configFile).to.be.false; + expect(result.moduleIds).to.be.true; + expect(result.babelrc).to.be.false; + expect(result.configFile).to.be.false; }); it('returns babel options when asked for', function() { @@ -1726,7 +1726,7 @@ describe('ember-cli-babel', function() { }); let result = this.addon.buildBabelOptions(); - expect(result.babel.plugins).to.deep.include(plugin); + expect(result.plugins).to.deep.include(plugin); }); it('includes postTransformPlugins after preset-env plugins', function() { @@ -1744,8 +1744,8 @@ describe('ember-cli-babel', function() { let result = this.addon.buildBabelOptions(); - expect(result.babel.plugins).to.deep.include(plugin); - expect(result.babel.plugins.slice(-1)).to.deep.equal([pluginAfter]); + expect(result.plugins).to.deep.include(plugin); + expect(result.plugins.slice(-1)).to.deep.equal([pluginAfter]); expect(result.postTransformPlugins).to.be.undefined; }); @@ -1765,7 +1765,7 @@ describe('ember-cli-babel', function() { }); let result = this.addon.buildBabelOptions(options); - expect(result.babel.presets).to.deep.equal([]); + expect(result.presets).to.deep.equal([]); }); it('user plugins are before preset-env plugins', function() { @@ -1780,7 +1780,7 @@ describe('ember-cli-babel', function() { }); let result = this.addon.buildBabelOptions(); - expect(result.babel.plugins[0]).to.equal(plugin); + expect(result.plugins[0]).to.equal(plugin); }); it('includes resolveModuleSource if compiling modules', function() { @@ -1792,7 +1792,7 @@ describe('ember-cli-babel', function() { compileModules: true, } }); - let found = result.babel.plugins.find(plugin => plugin[0] === expectedPlugin); + let found = result.plugins.find(plugin => plugin[0] === expectedPlugin); expect(typeof found[1].resolvePath).to.equal('function'); }); @@ -1806,7 +1806,7 @@ describe('ember-cli-babel', function() { compileModules: false, } }); - let found = result.babel.plugins.find(plugin => plugin[0] === expectedPlugin); + let found = result.plugins.find(plugin => plugin[0] === expectedPlugin); expect(found).to.equal(undefined); }); @@ -1842,7 +1842,7 @@ describe('ember-cli-babel', function() { let options = this.addon.buildBabelOptions(); - expect(options.babel.presets).to.deep.equal([ + expect(options.presets).to.deep.equal([ [require.resolve('@babel/preset-env'), { loose: true, modules: false,