1.0.2 ā€¢ Published 4 years ago

babel-plugin-transform-operator-overload v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

.github/workflows/main.yml npm version

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