From 6d2580e2880f11f1f0b532159fcf1748a06ca299 Mon Sep 17 00:00:00 2001 From: Eli Fitch Date: Thu, 6 Dec 2018 12:32:41 -0500 Subject: [PATCH] flattens nested single element all expressions when converting to expressions --- src/style-spec/feature_filter/convert.js | 2 +- test/unit/style-spec/feature_filter.test.js | 39 +++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/style-spec/feature_filter/convert.js b/src/style-spec/feature_filter/convert.js index 574c64779d1..1998eabc87a 100644 --- a/src/style-spec/feature_filter/convert.js +++ b/src/style-spec/feature_filter/convert.js @@ -92,7 +92,7 @@ function _convertFilter(filter: FilterSpecification, expectedTypes: ExpectedType return ['any'].concat(children); } else if (op === 'all') { const children = (filter: any).slice(1).map(f => _convertFilter(f, expectedTypes)); - return ['all'].concat(children); + return children.length > 1 ? ['all'].concat(children) : [].concat(...children); } else if (op === 'none') { return ['!', _convertFilter(['any'].concat(filter.slice(1)), {})]; } else if (op === 'in') { diff --git a/test/unit/style-spec/feature_filter.test.js b/test/unit/style-spec/feature_filter.test.js index d1624ca4487..81fb6e0caee 100644 --- a/test/unit/style-spec/feature_filter.test.js +++ b/test/unit/style-spec/feature_filter.test.js @@ -100,6 +100,45 @@ test('convert legacy filters to expressions', t => { t.end(); }); + t.test('foople barp garp', (t) => { + const filter = [ + "all", + [ + "in", + "$type", + "Polygon", + "LineString", + "Point" + ], + [ + "all", + ["in", "type", "island"] + ] + ]; + + const expected = [ + "all", + [ + "match", + ["geometry-type"], + ["Polygon", "LineString", "Point"], + true, + false + ], + [ + "match", + ["get", "type"], + ["island"], + true, + false + ] + ]; + + const converted = convertFilter(filter); + t.same(converted, expected); + t.end(); + }); + t.end(); });