d3 / d3-geo-projection

Extended geographic projections for d3-geo.
https://observablehq.com/collection/@d3/d3-geo-projection
Other
1.1k stars 199 forks source link

ES6 syntax in module when using npm #158

Closed jbrocher closed 5 years ago

jbrocher commented 5 years ago

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 commented 5 years ago

This is a bug introduced by @Fil in 942cb77638e1d1c0b6833c8840738d5c4a139b5a. 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 commented 5 years ago

Oops! thank you both

jbrocher commented 5 years ago

Crytal clear, thank you very much !