babel-plugin-transform-operator-overload
v1.0.2
Published
enable to 'operator overload' in JavaScript.
Downloads
89
Readme
babel-plugin-transform-operator-overload
Instration
# npm
npm install -D babel-plugin-transform-operator-overload
# yarn
yarn add -D babel-plugin-transform-operator-overload
Usage
Please add this in babel.config.js
.
{
"plugins": [
... ,
"babel-plugin-transform-operator-overload"
],
}
This plugin works inside a block labeled 'opol'.
opol: {
const c = a + b;
console.log(c);
}
↓
{
const c = ((left, right) => left["+"] ? left["+"](right) : left + right)(a, b);
console.log(c);
}
e.g.)
const obj = {
value: 5,
['+'](num) {
return this.value + num;
},
['-'](num) {
return this.value - num;
}
};
const puts = { '<<': console.log };
opol: {
puts << 'hello world';
// => hello world
puts << (obj + 3);
// => 8
}
Works Operators
+
, -
, /
, %
, *
, **
, &
, ,
, >>
, >>>
, <<
, ^
, ==
, ===
, !=
, !==
, instanceof
, >
, <
, >=
, <=
License
MIT