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

ES6 syntax in module when using npm #158

Closed
jbrocher opened this issue Jan 15, 2019 · 3 comments
Closed

ES6 syntax in module when using npm #158

jbrocher opened this issue Jan 15, 2019 · 3 comments

Comments

@jbrocher
Copy link

Hello ! I'm using d3-geo-projection as part of a project built using browserify and babelify. In my code
I'm importing a projection form the module like so :
import {geoKavrayskiy7} from 'd3-geo-projection'
And after going through browserify and babelify it runs fine. However, after trying to minify the resulting file with uglify, I ran into this error :

Parse error at ..../app.browserify.browserified.js:13739,35
    if (step === 180) c = c.map(d => [d[0] * (1 - epsilon), d[1]]);
                                   ^
ERROR: Unexpected token: operator (>)

Which comes from the sphere function :

function sphere(step) {
  var c = d3Array.range(-180, 180 + step / 2, step).map(function(x, i) { return [x, i & 1 ? 90 - epsilon : healpixParallel]; })
      .concat(d3Array.range(180, -180 - step / 2, -step).map(function(x, i) { return [x, i & 1 ? -90 + epsilon : -healpixParallel]; }));
  if (step === 180) c = c.map(d => [d[0]*(1-epsilon), d[1]]);

  return {
    type: "Polygon",
    coordinates: [c]
  };
}

What happens here is that the d3-geo-projection module doesn't go through babelify before being imported .I'm guessing the projection I'm importing from the module doesn't use this function since no error is thrown in the browser. However uglify sees it and gets angry. I can probably fix that by including the module in the babelify transform.

So I guess my question is : Is it normal to have bits of ES6 syntax in a module distributed through npm ?

@mbostock
Copy link
Member

This is a bug introduced by @Fil in 942cb77. This repository shouldn’t currently ship ES6 syntax, but we will likely be switching to ES6+ syntax in the next major release, at which point you’ll need to update your toolchain or environment accordingly.

@Fil
Copy link
Member

Fil commented Jan 15, 2019

Oops! thank you both

@jbrocher
Copy link
Author

Crytal clear, thank you very much !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants