d3 / d3-array

Array manipulation, ordering, searching, summarizing, etc.

Home Page:https://d3js.org/d3-array

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code not compatible with babel

IlyaSemenov opened this issue · comments

FYI, latest babel wouldn't compile this code:

export default function cumsum(values, valueof) {
var sum = 0, index = 0;
return Float64Array.from(values, valueof === undefined
? v => (sum += +v || 0)
: v => (sum += +valueof(v, index++, values) || 0));
}

with this error:

ERROR in ./node_modules/d3-array/src/cumsum.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /xxx/node_modules/d3-array/src/cumsum.js: Only '=' operator can be used for specifying default value. (4:15)

  2 |   var sum = 0, index = 0;
  3 |   return Float64Array.from(values, valueof === undefined
> 4 |     ? v => (sum += +v || 0)
    |                ^
  5 |     : v => (sum += +valueof(v, index++, values) || 0));
  6 | }

It's probably babel's issue, but I thought it was worth reporting it here, as may be it is an issue with d3-array.

My bad! Apparently a duplicate of #147. Also see babel/babel#11038

Just ran into the same error. #147 has been closed, but without any resolution. Upgrading Babel or downgrading d3-array is not an option for me, as I am using Meteor (which fixed Babel to a certain version) and react-globe that relies on d3-array@2.12.2 and I wouldn't want to break it.

I would appreciate if the code could be rewritten without the assignment in the ternary operator.