Skip to content

Commit

Permalink
Merge pull request #204 from kellyselden/_shouldDoNothing
Browse files Browse the repository at this point in the history
add a no-op optimization
  • Loading branch information
stefanpenner authored Feb 27, 2018
2 parents 4b68bef + ea3a2c5 commit fd6c9a6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
},
Expand Down Expand Up @@ -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;
}
};
27 changes: 27 additions & 0 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit fd6c9a6

Please sign in to comment.