Skip to content

Commit 26344c9

Browse files
Fix slice expression type (#2009)
* Fix slice expression type (#1886) The endIndex was not specified as an optional argument to the slice expression in the type. It does work in practice. * Add changelog entry * Add tests for slice expression Fixes #1886 Builds on #1889 * Fix changelog Co-authored-by: Leon <me@leonekmi.fr>
1 parent 771fee9 commit 26344c9

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Fix issue [#1024](https://github.com/maplibre/maplibre-gl-js/pull/1024) - Zoom center not under cursor when terrain is on
88
- Fix errors when running style-spec bin scripts and added missing help. Removed unnecessary script 'gl-style-composite'. ([#1971](https://github.com/maplibre/maplibre-gl-js/pull/1971))
99
- *...Add new stuff here...*
10+
- Fix the `slice` expression type ([#1886](https://github.com/maplibre/maplibre-gl-js/issues/1886))
1011
-
1112
## 3.0.0-pre.2
1213

build/generate-style-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export type ExpressionSpecification =
176176
| ['in', ExpressionInputType | ExpressionSpecification, ExpressionInputType | ExpressionSpecification]
177177
| ['index-of', ExpressionInputType | ExpressionSpecification, ExpressionInputType | ExpressionSpecification] // number
178178
| ['length', string | ExpressionSpecification]
179-
| ['slice', string | ExpressionSpecification, number | ExpressionSpecification]
179+
| ['slice', string | ExpressionSpecification, number | ExpressionSpecification, (number | ExpressionSpecification)?]
180180
// Decision
181181
| ['!', boolean | ExpressionSpecification] // boolean
182182
| ['!=', ExpressionInputType | ExpressionSpecification, ExpressionInputType | ExpressionSpecification, CollatorExpressionSpecification?] // boolean

src/style-spec/feature_filter/feature_filter.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ describe('filter', () => {
4444
compileTimeCheck(['interpolate', ['linear'], ['line-progress'], 0, [10, 20, 30], 0.5, [20, 30, 40], 1, [30, 40, 80]]); // number array output!
4545
compileTimeCheck(['interpolate-hcl', ['linear'], ['line-progress'], 0, 'red', 0.5, 'green', 1, 'blue']);
4646
compileTimeCheck(['interpolate-lab', ['linear'], ['line-progress'], 0, 'red', 0.5, 'green', 1, 'blue']);
47+
compileTimeCheck(['slice', 'myString', 0]);
48+
compileTimeCheck(['slice', ['literal', [0]], 0]);
49+
compileTimeCheck(['slice', 'myString', 0, 1]);
50+
compileTimeCheck(['slice', ['literal', [0, 1, 2]], 0, 1]);
4751
compileTimeCheck(['step', ['get', 'point_count'], '#df2d43', 50, '#df2d43', 200, '#df2d43']);
4852
compileTimeCheck(['step', ['get', 'point_count'], 20, 50, 30, 200, 40]);
4953
compileTimeCheck(['step', ['get', 'point_count'], 0.6, 50, 0.7, 200, 0.8]);

0 commit comments

Comments
 (0)