babel-plugin-operators-chaining
v0.0.3
Published
Transpile arithmetic comparison chains to logical expressions
Downloads
3
Maintainers
Readme
babel-plugin-operators-chaining
For transpiling chained arithmetic comparison operators to normal logical expressions (as in python).
Important: this is an experimental plugin for an enclosed project. Be aware that it modifies the semantics. See the example below.
Example
In
if(0<=a<5) {
// something
}
console.log(2!=1===1==1<2); // false
console.log(2 > 3 < 4 == 4); // false
console.log(2 <= 4 === true); // true
transpiles to
Out
if (0 <= a && a < 5) {
// something
}
console.log(2 != 1 && 1 === 1 && 1 == 1 && 1 < 2); // prints true
console.log(2 > 3 && 3 < 4 && 4 == 4); // prints false
console.log(2 <= 4 && 4 === true); // prints false
Installation
$ npm install babel-plugin-operators-chaining
Usage
Via .babelrc
(Recommended)
.babelrc
{
"plugins": ["operators-chaining"]
}
Via CLI
$ babel --plugins operators-chaining script.js
Via Node API
require("babel-core").transform("code", {
plugins: ["operators-chaining"]
});