Skip to content

Babel feature detection #366

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

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion lib/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ if (prevHash === currHash) {
patterns: require('./enhance-assert').PATTERNS
});

options.presets = [require('babel-preset-stage-2'), require('babel-preset-es2015')];
options.presets = [require('babel-preset-stage-2'), require('babel-preset-features')];
options.plugins = [powerAssert, require('babel-plugin-transform-runtime')];

var transpiled = babel.transformFileSync(testPath, options);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"babel-core": "^6.3.21",
"babel-plugin-espower": "^2.0.0",
"babel-plugin-transform-runtime": "^6.3.13",
"babel-preset-es2015": "^6.3.13",
"babel-preset-features": "^2.0.2",
"babel-preset-stage-2": "^6.3.13",
"babel-runtime": "^6.3.19",
"bluebird": "^3.0.0",
Expand Down
11 changes: 11 additions & 0 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ test('generators support', function (t) {
});
});

test('babel is only applied when needed', function (t) {
t.plan(1);

var api = new Api([path.join(__dirname, 'fixture/only-babel-when-needed.js')]);

api.run()
.then(function () {
t.is(api.passCount, 1);
});
});

test('async/await support', function (t) {
t.plan(1);

Expand Down
14 changes: 14 additions & 0 deletions test/fixture/only-babel-when-needed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import test from '../../';

var arrowFunction = foo => "bar";

var arrowFunctionRaw = 'foo => "bar"';

test(function (t) {
console.log('gen:', arrowFunction.toString());
if (['0.10.', '0.11.', '0.12.'].indexOf(process.versions.node.slice(0, 5)) === -1) {
t.is(arrowFunction.toString(), arrowFunctionRaw);
} else {
t.not(arrowFunction.toString(), arrowFunctionRaw);
}
});