From 5442a39e0a3d9992ea088579e801e2726d91682a Mon Sep 17 00:00:00 2001 From: Kelly Selden Date: Sat, 17 Feb 2018 16:07:43 -0800 Subject: [PATCH 1/2] add a no-op optimization --- index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b7bdf9a8..45298b12 100644 --- a/index.js +++ b/index.js @@ -49,8 +49,14 @@ module.exports = { let description = `000${++count}`.slice(-3); let postDebugTree = this._debugTree(inputTree, `${description}:input`); - let BabelTranspiler = require('broccoli-babel-transpiler'); - let output = new BabelTranspiler(postDebugTree, this.buildBabelOptions(config)); + let options = this.buildBabelOptions(config); + let output; + if (this._shouldDoNothing(options)) { + output = postDebugTree; + } else { + let BabelTranspiler = require('broccoli-babel-transpiler'); + output = new BabelTranspiler(postDebugTree, options); + } return this._debugTree(output, `${description}:output`); }, @@ -378,4 +384,9 @@ module.exports = { return checker.exists(); }, + + // detect if running babel would do nothing... and do nothing instead + _shouldDoNothing(options) { + return !options.sourceMaps && !options.plugins.length; + } }; From ea3a2c5012eabefa97ad072dfac968a63e615ed4 Mon Sep 17 00:00:00 2001 From: Kelly Selden Date: Wed, 21 Feb 2018 19:03:58 -0800 Subject: [PATCH 2/2] add test --- node-tests/addon-test.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index c267adcf..ff1a1f29 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -343,6 +343,33 @@ describe('ember-cli-babel', function() { })); }); + + describe('_shouldDoNothing', function() { + it("will no-op if nothing to do", co.wrap(function* () { + input.write({ + "foo.js": `invalid code` + }); + + subject = this.addon.transpileTree(input.path(), { + 'ember-cli-babel': { + compileModules: false, + disablePresetEnv: true, + disableDebugTooling: true, + disableEmberModulesAPIPolyfill: true + } + }); + + output = createBuilder(subject); + + yield output.build(); + + expect( + output.read() + ).to.deep.equal({ + "foo.js": `invalid code` + }); + })); + }); }); describe('_getAddonOptions', function() {