Transform ternary operators (conditional expressions) into if-else statements.
In
const val = a1 ? a2 : a3;
Out
const val = function() {
if (a1) {
return a2;
}
return a3;
}();
npm install babel-plugin-transform-ternary-to-if-else
.babelrc
{
"plugins": ["transform-ternary-to-if-else"]
}
babel --plugins transform-ternary-to-if-else script.js
require("babel-core").transform("code", {
plugins: ["transform-ternary-to-if-else"]
});