Skip to content

Commit

Permalink
Don’t propagate empty properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Mar 30, 2017
1 parent 1cad3d2 commit 6c1709b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ function geomifyFeatureCollection(input) {
}

function geomifyFeature(input) {
var output = geomifyGeometry(input.geometry);
var output = geomifyGeometry(input.geometry), key; // eslint-disable-line no-unused-vars
if (input.id != null) output.id = input.id;
if (input.bbox != null) output.bbox = input.bbox;
if (input.properties != null) output.properties = input.properties;
for (key in input.properties) { output.properties = input.properties; break; }
return output;
}

Expand Down
5 changes: 2 additions & 3 deletions test/geometry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ tape("geometry preserves id", function(test) {
test.end();
});

tape("geometry preserves properties", function(test) {
tape("geometry preserves properties if non-empty", function(test) {
test.deepEqual(geometry({
foo: {
properties: {
Expand Down Expand Up @@ -171,7 +171,7 @@ tape("geometry applies a shallow copy for properties", function(test) {
test.end();
});

tape("geometry does not delete empty properties", function(test) {
tape("geometry deletes empty properties", function(test) {
test.deepEqual(geometry({
foo: {
properties: {},
Expand All @@ -183,7 +183,6 @@ tape("geometry does not delete empty properties", function(test) {
}
}), {
foo: {
properties: {},
type: "LineString",
arcs: [[0, 0]]
}
Expand Down
4 changes: 2 additions & 2 deletions test/topology-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -877,15 +877,15 @@ tape("topology converting a feature to a geometry preserves its bbox", function(
test.end();
});

tape("topology converting a feature to a geometry preserves its properties", function(test) {
tape("topology converting a feature to a geometry preserves its properties, but only if non-empty", function(test) {
var topology = topojson.topology({foo: {type: "Feature", id: "Foo", properties: {name: "George"}, geometry: {type: "LineString", coordinates: [[.1, .2], [.3, .4]]}}});
test.deepEqual(topology.objects.foo.properties, {name: "George"});
var topology = topojson.topology({foo: {type: "Feature", id: "Foo", properties: {name: "George"}, geometry: {type: "GeometryCollection", geometries: [{type: "LineString", coordinates: [[.1, .2], [.3, .4]]}]}}});
test.deepEqual(topology.objects.foo.properties, {name: "George"});
var topology = topojson.topology({foo: {type: "Feature", id: "Foo", properties: {name: "George", demeanor: "curious"}, geometry: {type: "LineString", coordinates: [[.1, .2], [.3, .4]]}}});
test.deepEqual(topology.objects.foo.properties, {name: "George", demeanor: "curious"});
var topology = topojson.topology({foo: {type: "Feature", id: "Foo", properties: {}, geometry: {type: "LineString", coordinates: [[.1, .2], [.3, .4]]}}});
test.deepEqual(topology.objects.foo.properties, {});
test.equal(topology.objects.foo.properties, undefined);
test.end();
});

Expand Down

0 comments on commit 6c1709b

Please sign in to comment.