Support "env" in .babelrc files. (#8963)

This commit is contained in:
Jordan Brant Baker
2017-08-07 10:23:56 -07:00
committed by Ben Newman
parent 43ba3c9de5
commit 77ecbabf60
4 changed files with 38 additions and 0 deletions

View File

@@ -300,6 +300,16 @@ BCp._inferHelper = function (
merge(babelOptions, babelrc, "presets");
merge(babelOptions, babelrc, "plugins");
const babelEnv = (process.env.BABEL_ENV ||
process.env.NODE_ENV ||
"development");
if (babelrc && babelrc.env && babelrc.env[babelEnv]) {
const env = babelrc.env[babelEnv];
walkBabelRC(env);
merge(babelOptions, env, "presets");
merge(babelOptions, env, "plugins");
}
return !! (babelrc.presets ||
babelrc.plugins);
};

View File

@@ -0,0 +1,7 @@
{
"env": {
"development": {
"plugins": ["transform-do-expressions"]
}
}
}

View File

@@ -0,0 +1,18 @@
function babeltest() {
// use transform-do-expressions plugin to prove babel `env` subkey was loaded
let x = do {
1;
};
console.log(x)
}
/*
If the plugin is loaded correctly there will be no errors during the compilation of this file.
Without this plugin you will get the error:
W20170803-17:58:17.054(-7)? (STDERR) var x = do {
W20170803-17:58:17.055(-7)? (STDERR) ^^
W20170803-17:58:17.055(-7)? (STDERR)
W20170803-17:58:17.055(-7)? (STDERR) SyntaxError: Unexpected token do
*/

View File

@@ -19,5 +19,8 @@
"test": "METEOR_PROFILE=100 ../../../../meteor test --full-app --driver-package dispatch:mocha-phantomjs",
"browser": "METEOR_PROFILE=100 ../../../../meteor test --full-app --driver-package dispatch:mocha-browser",
"test-packages": "../../../../meteor test-packages --driver-package dispatch:mocha-phantomjs packages/modules-test-package"
},
"devDependencies": {
"babel-plugin-transform-do-expressions": "^6.22.0"
}
}