Skip to content

Commit fd6c9a6

Browse files
authored
Merge pull request #204 from kellyselden/_shouldDoNothing
add a no-op optimization
2 parents 4b68bef + ea3a2c5 commit fd6c9a6

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

index.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,14 @@ module.exports = {
4949
let description = `000${++count}`.slice(-3);
5050
let postDebugTree = this._debugTree(inputTree, `${description}:input`);
5151

52-
let BabelTranspiler = require('broccoli-babel-transpiler');
53-
let output = new BabelTranspiler(postDebugTree, this.buildBabelOptions(config));
52+
let options = this.buildBabelOptions(config);
53+
let output;
54+
if (this._shouldDoNothing(options)) {
55+
output = postDebugTree;
56+
} else {
57+
let BabelTranspiler = require('broccoli-babel-transpiler');
58+
output = new BabelTranspiler(postDebugTree, options);
59+
}
5460

5561
return this._debugTree(output, `${description}:output`);
5662
},
@@ -378,4 +384,9 @@ module.exports = {
378384

379385
return checker.exists();
380386
},
387+
388+
// detect if running babel would do nothing... and do nothing instead
389+
_shouldDoNothing(options) {
390+
return !options.sourceMaps && !options.plugins.length;
391+
}
381392
};

node-tests/addon-test.js

+27
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,33 @@ describe('ember-cli-babel', function() {
343343
}));
344344

345345
});
346+
347+
describe('_shouldDoNothing', function() {
348+
it("will no-op if nothing to do", co.wrap(function* () {
349+
input.write({
350+
"foo.js": `invalid code`
351+
});
352+
353+
subject = this.addon.transpileTree(input.path(), {
354+
'ember-cli-babel': {
355+
compileModules: false,
356+
disablePresetEnv: true,
357+
disableDebugTooling: true,
358+
disableEmberModulesAPIPolyfill: true
359+
}
360+
});
361+
362+
output = createBuilder(subject);
363+
364+
yield output.build();
365+
366+
expect(
367+
output.read()
368+
).to.deep.equal({
369+
"foo.js": `invalid code`
370+
});
371+
}));
372+
});
346373
});
347374

348375
describe('_getAddonOptions', function() {

0 commit comments

Comments
 (0)