Skip to content

Commit

Permalink
Flattens nested single element all expressions when converting to exp…
Browse files Browse the repository at this point in the history
…ressions (#7679)
  • Loading branch information
elifitch authored and Asheem Mamoowala committed Dec 11, 2018
1 parent 0f370bf commit afe61bd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/style-spec/feature_filter/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
39 changes: 39 additions & 0 deletions test/unit/style-spec/feature_filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,45 @@ test('convert legacy filters to expressions', t => {
t.end();
});

t.test('flattens nested, single child all expressions', (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();
});

Expand Down

0 comments on commit afe61bd

Please sign in to comment.