codalien/operator-overloading-js

Arrow functions aren't supported

roman-koshchei opened this issue · 3 comments

condition is arrow function for comfortable usage, but it doesn't work

type Where = (over: Over) => A
function where(condition: Where) {
  const o = new Over()

  const overloadedFunction = overload(condition)
  return overloadedFunction(o, condition)
}

const data = where(p => p.a1 || p.a2)

image

First of all, mixing JavaScript with type comments ("TypeScript") is ugly and you are better off writing JSDoc:

/**
 * @callback Where
 * @param {Over} over
 * @returns {A}
 */

/**
 * @param {Where} condition - TODO: Explain what this is...
 */
function where(condition) {
  const o = new Over();
  const overloadedFunction = overload(condition);
  return overloadedFunction(o, condition);
}
const data = where(p => p.a1 || p.a2);

Secondly, esprima@1 doesn't support ES6, you need to install esprima@2:

npm i esprima@2

Then it should work...