Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a no-op optimization #204

Merged
merged 2 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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