Skip to content

Commit

Permalink
Rename _getDefaultBabelOptions to `_buildBroccoliBabelTranspilerOpt…
Browse files Browse the repository at this point in the history
…ions`

This more correctly reflects what the method is doing, and what it is
for.
  • Loading branch information
rwjblue committed Mar 18, 2021
1 parent 73c0fda commit f7a1980
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 45 deletions.
75 changes: 36 additions & 39 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
12 changes: 6 additions & 6 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand All @@ -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');
});

Expand All @@ -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');
});

Expand All @@ -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!');
});

Expand All @@ -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;
});
Expand Down

0 comments on commit f7a1980

Please sign in to comment.