Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d3.cumsum fails to transpile with babel6 + preset-react #147

Closed
TobbeLino opened this issue Jun 1, 2020 · 6 comments
Closed

d3.cumsum fails to transpile with babel6 + preset-react #147

TobbeLino opened this issue Jun 1, 2020 · 6 comments

Comments

@TobbeLino
Copy link

TobbeLino commented Jun 1, 2020

When trying to transpile "d3-array" with babel 6 + babel-preset-react, babel fails with a syntax error on "cumsum.js"

How to repeat:
Run:
npm install d3-array
npm install babel-cli
npm install babel-preset-react
node node_modules\babel-cli\bin\babel.js --presets babel-preset-react .\node_modules\d3-array\src\cumsum.js

Result:

SyntaxError: ./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 | }

Omitting "--presets babel-preset-react" and transpiling with e.g. preset-env works:
npm install babel-preset-env
node node_modules\babel-cli\bin\babel.js --presets babel-preset-env .\node_modules\d3-array\src\cumsum.js

Results in:

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = cumsum;
function cumsum(values, valueof) {
  var sum = 0,
      index = 0;
  return Float64Array.from(values, valueof === undefined ? function (v) {
    return sum += +v || 0;
  } : function (v) {
    return sum += +valueof(v, index++, values) || 0;
  });
}
@mbostock
Copy link
Member

mbostock commented Jun 1, 2020

Sorry, but this isn’t a help forum for Babel. You’ll need to find an alternative forum if you want help using Babel. Good luck!

@mbostock mbostock closed this as completed Jun 1, 2020
@williaster
Copy link

For anyone else that stumbles upon this babel/babel#11038

@CallMeProteus
Copy link

temporary solution but works by tweaking the input :

link to original post https://github.com/FormidableLabs/victory-native/issues/653#issuecomment-859398327

function cumsum(values, valueof) {
let fn = (v) => (sum += +valueof(v, index++, values) || 0);
if (valueof === undefined)
fn = (v) => (sum += +v || 0);
var sum = 0, index = 0;
return Float64Array.from(values, fn);
}

@1rjun
Copy link

1rjun commented Jul 8, 2021

Please downgrade the d3 version to "d3": "5.15.0".

@CallMeProteus
Copy link

CallMeProteus commented Jul 8, 2021 via email

@d3 d3 locked and limited conversation to collaborators Jul 8, 2021
@d3 d3 unlocked this conversation Aug 1, 2021
@mbostock
Copy link
Member

mbostock commented Aug 1, 2021

Unlocking briefly to mention that this bug (originally reported in January 2018 babel/babel#7235) has now been fixed in Babel by babel/babel#13581.

@d3 d3 locked as off-topic and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

5 participants