diff --git a/index.js b/index.js index dbce22e2..2d775bf3 100644 --- a/index.js +++ b/index.js @@ -83,51 +83,48 @@ module.exports = { return this._cachedDebugTree.apply(null, arguments); }, - /** - * Default babel options - * @param {*} config - */ - _getDefaultBabelOptions(config = {}) { - let emberCLIBabelConfig = config["ember-cli-babel"]; - let providedAnnotation; - let throwUnlessParallelizable; - let sourceMaps = false; - let shouldCompileModules = _shouldCompileModules(config, this.project); - - if (emberCLIBabelConfig) { - providedAnnotation = emberCLIBabelConfig.annotation; - throwUnlessParallelizable = emberCLIBabelConfig.throwUnlessParallelizable; - } - - if (config.babel && "sourceMaps" in config.babel) { - sourceMaps = config.babel.sourceMaps; - } - - let options = { - annotation: providedAnnotation || `Babel: ${_parentName(this.parent)}`, - sourceMaps, - throwUnlessParallelizable, - filterExtensions: _getExtensions(config, this.parent), - plugins: [] - }; - - if (shouldCompileModules) { - options.moduleIds = true; - options.getModuleId = require("./lib/relative-module-paths").getRelativeModulePath; - } - - options.highlightCode = _shouldHighlightCode(this.parent); - options.babelrc = false; - options.configFile = false; - - return options; + _buildBroccoliBabelTranspilerOptions(config = {}) { + let emberCLIBabelConfig = config["ember-cli-babel"]; + + let providedAnnotation; + let throwUnlessParallelizable; + let sourceMaps = false; + let shouldCompileModules = _shouldCompileModules(config, this.project); + + if (emberCLIBabelConfig) { + providedAnnotation = emberCLIBabelConfig.annotation; + throwUnlessParallelizable = emberCLIBabelConfig.throwUnlessParallelizable; + } + + if (config.babel && "sourceMaps" in config.babel) { + sourceMaps = config.babel.sourceMaps; + } + + let options = { + annotation: providedAnnotation || `Babel: ${_parentName(this.parent)}`, + sourceMaps, + throwUnlessParallelizable, + filterExtensions: _getExtensions(config, this.parent), + plugins: [] + }; + + if (shouldCompileModules) { + options.moduleIds = true; + options.getModuleId = require("./lib/relative-module-paths").getRelativeModulePath; + } + + options.highlightCode = _shouldHighlightCode(this.parent); + options.babelrc = false; + options.configFile = false; + + return options; }, transpileTree(inputTree, _config) { let config = _config || this._getAddonOptions(); let description = `000${++count}`.slice(-3); let postDebugTree = this._debugTree(inputTree, `${description}:input`); - let options = Object.assign({}, this._getDefaultBabelOptions(config), this.buildBabelOptions(config)); + let options = Object.assign({}, this._buildBroccoliBabelTranspilerOptions(config), this.buildBabelOptions(config)); let output; const customAddonConfig = config['ember-cli-babel']; diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index 95580988..a33c42ba 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -1143,7 +1143,7 @@ describe('ember-cli-babel', function() { it('disables reading `.babelrc`', function() { let options = {}; - let result = this.addon._getDefaultBabelOptions(options); + let result = this.addon._buildBroccoliBabelTranspilerOptions(options); expect(result.babelrc).to.be.false; }); @@ -1153,7 +1153,7 @@ describe('ember-cli-babel', function() { name: 'derpy-herpy', dependencies() { return {}; }, }); - let result = this.addon._getDefaultBabelOptions(); + let result = this.addon._buildBroccoliBabelTranspilerOptions(); expect(result.annotation).to.include('derpy-herpy'); }); @@ -1162,7 +1162,7 @@ describe('ember-cli-babel', function() { name: 'derpy-herpy', dependencies() { return {}; }, }); - let result = this.addon._getDefaultBabelOptions(); + let result = this.addon._buildBroccoliBabelTranspilerOptions(); expect(result.annotation).to.include('derpy-herpy'); }); @@ -1173,7 +1173,7 @@ describe('ember-cli-babel', function() { } }; - let result = this.addon._getDefaultBabelOptions(options); + let result = this.addon._buildBroccoliBabelTranspilerOptions(options); expect(result.annotation).to.equal('Hello World!'); }); @@ -1184,14 +1184,14 @@ describe('ember-cli-babel', function() { } }; - let result = this.addon._getDefaultBabelOptions(options); + let result = this.addon._buildBroccoliBabelTranspilerOptions(options); expect(result.sourceMaps).to.equal('inline'); }); it('disables reading `.babelrc`', function() { let options = {}; - let result = this.addon._getDefaultBabelOptions(options); + let result = this.addon._buildBroccoliBabelTranspilerOptions(options); expect(result.babelrc).to.be.false; });