@mapbox/mapbox-gl-style-spec 14.11.0 → 14.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/composite.ts +2 -0
  2. package/deref.ts +5 -5
  3. package/diff.ts +65 -31
  4. package/dist/index.cjs +816 -16
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.ts +224 -16
  7. package/dist/index.es.js +816 -16
  8. package/dist/index.es.js.map +1 -1
  9. package/error/validation_error.ts +1 -3
  10. package/expression/compound_expression.ts +1 -1
  11. package/expression/definitions/assertion.ts +2 -1
  12. package/expression/definitions/at.ts +1 -1
  13. package/expression/definitions/at_interpolated.ts +1 -1
  14. package/expression/definitions/case.ts +3 -1
  15. package/expression/definitions/coalesce.ts +3 -2
  16. package/expression/definitions/coercion.ts +3 -1
  17. package/expression/definitions/collator.ts +2 -1
  18. package/expression/definitions/comparison.ts +15 -1
  19. package/expression/definitions/config.ts +4 -1
  20. package/expression/definitions/distance.ts +6 -4
  21. package/expression/definitions/format.ts +1 -1
  22. package/expression/definitions/index.ts +24 -2
  23. package/expression/definitions/index_of.ts +1 -0
  24. package/expression/definitions/interpolate.ts +7 -3
  25. package/expression/definitions/let.ts +1 -0
  26. package/expression/definitions/literal.ts +2 -2
  27. package/expression/definitions/match.ts +4 -2
  28. package/expression/definitions/number_format.ts +3 -4
  29. package/expression/definitions/slice.ts +1 -0
  30. package/expression/definitions/step.ts +2 -1
  31. package/expression/definitions/var.ts +1 -0
  32. package/expression/definitions/within.ts +6 -2
  33. package/expression/evaluation_context.ts +3 -5
  34. package/expression/expression.ts +3 -0
  35. package/expression/index.ts +20 -10
  36. package/expression/parsing_context.ts +1 -1
  37. package/expression/types/image_variant.ts +2 -2
  38. package/expression/types.ts +1 -0
  39. package/expression/values.ts +1 -3
  40. package/feature_filter/convert.ts +13 -6
  41. package/feature_filter/index.ts +17 -1
  42. package/format.ts +1 -0
  43. package/function/convert.ts +5 -1
  44. package/function/index.ts +28 -0
  45. package/group_by_layout.ts +17 -8
  46. package/migrate/expressions.ts +3 -3
  47. package/migrate/v8.ts +10 -1
  48. package/migrate/v9.ts +2 -1
  49. package/migrate.ts +2 -1
  50. package/package.json +1 -1
  51. package/read_style.ts +1 -0
  52. package/reference/latest.ts +1 -0
  53. package/reference/v8.json +425 -8
  54. package/test.js +2 -4
  55. package/types.ts +207 -1
  56. package/union-to-intersection.ts +1 -0
  57. package/util/extend.ts +2 -1
  58. package/util/geometry_util.ts +25 -9
  59. package/util/interpolate.ts +1 -1
  60. package/validate/validate.ts +6 -0
  61. package/validate/validate_array.ts +2 -0
  62. package/validate/validate_enum.ts +1 -0
  63. package/validate/validate_expression.ts +4 -0
  64. package/validate/validate_filter.ts +4 -2
  65. package/validate/validate_fog.ts +4 -1
  66. package/validate/validate_function.ts +7 -2
  67. package/validate/validate_glyphs_url.ts +1 -1
  68. package/validate/validate_iconset.ts +1 -0
  69. package/validate/validate_layer.ts +3 -2
  70. package/validate/validate_light.ts +4 -1
  71. package/validate/validate_lights.ts +7 -1
  72. package/validate/validate_model.ts +4 -0
  73. package/validate/validate_object.ts +2 -2
  74. package/validate/validate_projection.ts +1 -0
  75. package/validate/validate_property.ts +5 -1
  76. package/validate/validate_rain.ts +3 -0
  77. package/validate/validate_snow.ts +3 -0
  78. package/validate/validate_source.ts +9 -9
  79. package/validate/validate_terrain.ts +5 -1
  80. package/validate_mapbox_api_supported.ts +31 -20
  81. package/validate_style.ts +1 -0
  82. package/visit.ts +4 -2
@@ -27,7 +27,7 @@ class EvaluationContext {
27
27
  };
28
28
 
29
29
  constructor(scope?: string | null, options?: ConfigOptions | null) {
30
- this.globals = (null as any);
30
+ this.globals = null;
31
31
  this.feature = null;
32
32
  this.featureState = null;
33
33
  this.formattedSection = null;
@@ -40,7 +40,7 @@ class EvaluationContext {
40
40
  this.options = options;
41
41
  }
42
42
 
43
- id(): number | null {
43
+ id(): string | number | null {
44
44
  return this.feature && this.feature.id !== undefined ? this.feature.id : null;
45
45
  }
46
46
 
@@ -56,9 +56,7 @@ class EvaluationContext {
56
56
  return this.canonical;
57
57
  }
58
58
 
59
- properties(): {
60
- [key: string]: any;
61
- } {
59
+ properties(): {readonly [key: string]: unknown} {
62
60
  return (this.feature && this.feature.properties) || {};
63
61
  }
64
62
 
@@ -6,7 +6,9 @@ export type SerializedExpression = Array<unknown> | Array<string> | string | num
6
6
 
7
7
  export interface Expression {
8
8
  readonly type: Type;
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
10
  value?: any;
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
12
  evaluate: (ctx: EvaluationContext) => any;
11
13
  eachChild: (fn: (arg1: Expression) => void) => void;
12
14
  /**
@@ -20,6 +22,7 @@ export interface Expression {
20
22
  export type ExpressionParser = (args: ReadonlyArray<unknown>, context: ParsingContext) => Expression | void;
21
23
 
22
24
  export type ExpressionRegistration = {
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
26
  new(...args: any[]): Expression;
24
27
  readonly parse: ExpressionParser;
25
28
  _classRegistryKey?: string;
@@ -39,13 +39,9 @@ import type {ImageId} from './types/image_id';
39
39
 
40
40
  export interface Feature {
41
41
  readonly type: 0 | 1 | 2 | 3 | 'Unknown' | 'Point' | 'LineString' | 'Polygon';
42
- readonly id?: number | null;
43
- readonly properties: {
44
- [_: string]: any;
45
- };
46
- readonly patterns?: {
47
- [_: string]: string;
48
- };
42
+ readonly id?: string | number | null;
43
+ readonly properties: Record<PropertyKey, unknown>;
44
+ readonly patterns?: Record<PropertyKey, string[]>;
49
45
  readonly geometry?: Array<Array<Point>>;
50
46
  }
51
47
 
@@ -93,6 +89,7 @@ export class StyleExpression {
93
89
  formattedSection?: FormattedSection,
94
90
  featureTileCoord?: Point,
95
91
  featureDistanceData?: FeatureDistanceData,
92
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
93
  ): any {
97
94
  this._evaluator.globals = globals;
98
95
  this._evaluator.feature = feature;
@@ -115,6 +112,7 @@ export class StyleExpression {
115
112
  formattedSection?: FormattedSection,
116
113
  featureTileCoord?: Point,
117
114
  featureDistanceData?: FeatureDistanceData,
115
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
116
  ): any {
119
117
  this._evaluator.globals = globals;
120
118
  this._evaluator.feature = feature || null;
@@ -135,7 +133,7 @@ export class StyleExpression {
135
133
  throw new RuntimeError(`Expected value to be one of ${Object.keys(this._enumValues).map(v => JSON.stringify(v)).join(', ')}, but found ${JSON.stringify(val)} instead.`);
136
134
  }
137
135
  return val;
138
- } catch (e: any) {
136
+ } catch (e) {
139
137
  if (!this._warningHistory[e.message]) {
140
138
  this._warningHistory[e.message] = true;
141
139
  if (typeof console !== 'undefined') {
@@ -205,6 +203,7 @@ export class ZoomConstantExpression<Kind extends EvaluationKind> {
205
203
  canonical?: CanonicalTileID,
206
204
  availableImages?: ImageId[],
207
205
  formattedSection?: FormattedSection,
206
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
208
207
  ): any {
209
208
  return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
210
209
  }
@@ -216,6 +215,7 @@ export class ZoomConstantExpression<Kind extends EvaluationKind> {
216
215
  canonical?: CanonicalTileID,
217
216
  availableImages?: ImageId[],
218
217
  formattedSection?: FormattedSection,
218
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
219
219
  ): any {
220
220
  return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
221
221
  }
@@ -250,6 +250,7 @@ export class ZoomDependentExpression<Kind extends EvaluationKind> {
250
250
  canonical?: CanonicalTileID,
251
251
  availableImages?: ImageId[],
252
252
  formattedSection?: FormattedSection,
253
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
253
254
  ): any {
254
255
  return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
255
256
  }
@@ -261,6 +262,7 @@ export class ZoomDependentExpression<Kind extends EvaluationKind> {
261
262
  canonical?: CanonicalTileID,
262
263
  availableImages?: ImageId[],
263
264
  formattedSection?: FormattedSection,
265
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
264
266
  ): any {
265
267
  return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
266
268
  }
@@ -283,6 +285,7 @@ export type ConstantExpression = {
283
285
  featureState?: FeatureState,
284
286
  canonical?: CanonicalTileID,
285
287
  availableImages?: ImageId[],
288
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
286
289
  ) => any;
287
290
  };
288
291
 
@@ -299,6 +302,7 @@ export type SourceExpression = {
299
302
  canonical?: CanonicalTileID,
300
303
  availableImages?: ImageId[],
301
304
  formattedSection?: FormattedSection,
305
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
302
306
  ) => any;
303
307
  };
304
308
 
@@ -312,6 +316,7 @@ export type CameraExpression = {
312
316
  featureState?: FeatureState,
313
317
  canonical?: CanonicalTileID,
314
318
  availableImages?: ImageId[],
319
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
315
320
  ) => any;
316
321
  readonly interpolationFactor: (input: number, lower: number, upper: number) => number;
317
322
  zoomStops: Array<number>;
@@ -331,6 +336,7 @@ export interface CompositeExpression {
331
336
  canonical?: CanonicalTileID,
332
337
  availableImages?: ImageId[],
333
338
  formattedSection?: FormattedSection,
339
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
334
340
  ) => any;
335
341
  readonly interpolationFactor: (input: number, lower: number, upper: number) => number;
336
342
  zoomStops: Array<number>;
@@ -340,6 +346,7 @@ export interface CompositeExpression {
340
346
  export type StylePropertyExpression = ConstantExpression | SourceExpression | CameraExpression | CompositeExpression;
341
347
 
342
348
  export function createPropertyExpression(
349
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
343
350
  expression: any,
344
351
  propertySpec: StylePropertySpecification,
345
352
  scope?: string | null,
@@ -347,6 +354,7 @@ export function createPropertyExpression(
347
354
  ): Result<StylePropertyExpression, Array<ParsingError>> {
348
355
  expression = createExpression(expression, propertySpec, scope, options);
349
356
  if (expression.result === 'error') {
357
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
350
358
  return expression;
351
359
  }
352
360
 
@@ -402,6 +410,7 @@ export class StylePropertyFunction<T> {
402
410
  _specification: StylePropertySpecification;
403
411
 
404
412
  kind: EvaluationKind;
413
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
405
414
  evaluate: (globals: GlobalProperties, feature?: Feature) => any;
406
415
  interpolationFactor: (input: number, lower: number, upper: number) => number | null | undefined;
407
416
  zoomStops: Array<number> | null | undefined;
@@ -439,7 +448,7 @@ export function normalizePropertyExpression<T>(
439
448
  options?: ConfigOptions | null,
440
449
  ): StylePropertyExpression {
441
450
  if (isFunction(value)) {
442
- return new StylePropertyFunction(value, specification) as any;
451
+ return new StylePropertyFunction(value, specification) as unknown as StylePropertyExpression;
443
452
 
444
453
  } else if (isExpression(value) || (Array.isArray(value) && value.length > 0)) {
445
454
  const expression = createPropertyExpression(value, specification, scope, options);
@@ -450,7 +459,7 @@ export function normalizePropertyExpression<T>(
450
459
  return expression.value;
451
460
 
452
461
  } else {
453
- let constant: any = value;
462
+ let constant = value as Color;
454
463
  if (typeof value === 'string' && specification.type === 'color') {
455
464
  constant = Color.parse(value);
456
465
  }
@@ -498,6 +507,7 @@ function findZoomCurve(expression: Expression): Step | Interpolate | ParsingErro
498
507
  }
499
508
  });
500
509
 
510
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
501
511
  return result;
502
512
  }
503
513
 
@@ -157,7 +157,7 @@ class ParsingContext {
157
157
  const ec = new EvaluationContext(this._scope, this.options);
158
158
  try {
159
159
  parsed = new Literal(parsed.type, parsed.evaluate(ec));
160
- } catch (e: any) {
160
+ } catch (e) {
161
161
  this.error(e.message);
162
162
  return null;
163
163
  }
@@ -72,8 +72,8 @@ export class ImageVariant {
72
72
  return new ImageVariant({name, iconsetId}, {params, transform: new DOMMatrix([a, b, c, d, e, f])});
73
73
  }
74
74
 
75
- scaleSelf(factor: number): this {
76
- this.options.transform.scaleSelf(factor);
75
+ scaleSelf(factor: number, yFactor?: number): this {
76
+ this.options.transform.scaleSelf(factor, yFactor);
77
77
  return this;
78
78
  }
79
79
  }
@@ -120,6 +120,7 @@ export function isValidType(provided: Type, allowedTypes: Array<Type>): boolean
120
120
  return allowedTypes.some(t => t.kind === provided.kind);
121
121
  }
122
122
 
123
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
123
124
  export function isValidNativeType(provided: any, allowedTypes: Array<NativeType>): boolean {
124
125
  return allowedTypes.some(t => {
125
126
  if (t === 'null') {
@@ -51,9 +51,7 @@ export function validateHSLA(h: unknown, s: unknown, l: unknown, a?: unknown): s
51
51
  return null;
52
52
  }
53
53
 
54
- export type Value = null | string | boolean | number | Color | Collator | Formatted | ResolvedImage | ReadonlyArray<Value> | {
55
- readonly [key: string]: Value;
56
- };
54
+ export type Value = null | string | boolean | number | Color | Collator | Formatted | ResolvedImage | ReadonlyArray<Value> | {readonly [key: string]: Value};
57
55
 
58
56
  export function isValue(mixed: unknown): boolean {
59
57
  if (mixed === null) {
@@ -1,6 +1,6 @@
1
1
  import {isExpressionFilter} from './index';
2
2
 
3
- import type {FilterSpecification} from '../types';
3
+ import type {FilterSpecification, ExpressionSpecification} from '../types';
4
4
 
5
5
  type ExpectedTypes = {
6
6
  [_: string]: 'string' | 'number' | 'boolean';
@@ -80,17 +80,19 @@ function _convertFilter(filter: FilterSpecification, expectedTypes: ExpectedType
80
80
  op === '<=' ||
81
81
  op === '>='
82
82
  ) {
83
- const [, property, value] = (filter as any);
83
+ const [, property, value] = filter;
84
84
  converted = convertComparisonOp(property, value, op, expectedTypes);
85
85
  } else if (op === 'any') {
86
- const children = (filter as any).slice(1).map(f => {
86
+ const children = filter.slice(1).map(f => {
87
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
88
  const types: Record<string, any> = {};
88
89
  const child = _convertFilter(f, types);
89
90
  const typechecks = runtimeTypeChecks(types);
90
91
  return typechecks === true ? child : ['case', typechecks, child, false];
91
- });
92
+ }) as ExpressionSpecification;
92
93
  return ['any'].concat(children);
93
94
  } else if (op === 'all') {
95
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
96
  const children: any[] = (filter).slice(1).map(f => _convertFilter(f, expectedTypes));
95
97
  return children.length > 1 ? ['all'].concat(children) : [].concat(...children);
96
98
  } else if (op === 'none') {
@@ -125,13 +127,16 @@ function runtimeTypeChecks(expectedTypes: ExpectedTypes) {
125
127
  conditions.push(['==', ['typeof', get], expectedTypes[property]]);
126
128
  }
127
129
  if (conditions.length === 0) return true;
130
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
128
131
  if (conditions.length === 1) return conditions[0];
129
132
  return ['all'].concat(conditions);
130
133
  }
131
134
 
135
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
132
136
  function convertComparisonOp(property: string, value: any, op: string, expectedTypes?: ExpectedTypes | null) {
133
137
  let get;
134
138
  if (property === '$type') {
139
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
135
140
  return [op, ['geometry-type'], value];
136
141
  } else if (property === '$id') {
137
142
  get = ['id'];
@@ -140,7 +145,7 @@ function convertComparisonOp(property: string, value: any, op: string, expectedT
140
145
  }
141
146
 
142
147
  if (expectedTypes && value !== null) {
143
- const type = ((typeof value) as any);
148
+ const type = typeof value as 'string' | 'number' | 'boolean';
144
149
  expectedTypes[property] = type;
145
150
  }
146
151
 
@@ -158,10 +163,11 @@ function convertComparisonOp(property: string, value: any, op: string, expectedT
158
163
  ];
159
164
  }
160
165
 
166
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
161
167
  return [op, get, value];
162
168
  }
163
169
 
164
- function convertInOp(property: string, values: Array<any>, negate: boolean = false) {
170
+ function convertInOp(property: string, values: Array<unknown>, negate: boolean = false) {
165
171
  if (values.length === 0) return negate;
166
172
 
167
173
  let get: string[];
@@ -193,6 +199,7 @@ function convertInOp(property: string, values: Array<any>, negate: boolean = fal
193
199
  }
194
200
 
195
201
  return [negate ? 'all' : 'any'].concat(
202
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
196
203
  values.map(v => [negate ? '!=' : '==', get, v]) as any[]
197
204
  );
198
205
  }
@@ -99,7 +99,7 @@ function createFilter(filter?: FilterSpecification, scope: string = "", options:
99
99
  let staticFilter = true;
100
100
  try {
101
101
  staticFilter = extractStaticFilter(filterExp);
102
- } catch (e: any) {
102
+ } catch (e) {
103
103
  console.warn(
104
104
  `Failed to extract static filter. Filter will continue working, but at higher memory usage and slower framerate.
105
105
  This is most likely a bug, please report this via https://github.com/mapbox/mapbox-gl-js/issues/new?assignees=&labels=&template=Bug_report.md
@@ -121,6 +121,7 @@ ${JSON.stringify(filterExp, null, 2)}
121
121
  if (compiledStaticFilter.result === 'error') {
122
122
  throw new Error(compiledStaticFilter.value.map(err => `${err.key}: ${err.message}`).join(', '));
123
123
  } else {
124
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
124
125
  filterFunc = (globalProperties: GlobalProperties, feature: Feature, canonical?: CanonicalTileID) => compiledStaticFilter.value.evaluate(globalProperties, feature, {}, canonical);
125
126
  }
126
127
  }
@@ -135,6 +136,7 @@ ${JSON.stringify(filterExp, null, 2)}
135
136
  if (compiledDynamicFilter.result === 'error') {
136
137
  throw new Error(compiledDynamicFilter.value.map(err => `${err.key}: ${err.message}`).join(', '));
137
138
  } else {
139
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
138
140
  dynamicFilterFunc = (globalProperties: GlobalProperties, feature: Feature, canonical?: CanonicalTileID, featureTileCoord?: Point, featureDistanceData?: FeatureDistanceData) => compiledDynamicFilter.value.evaluate(globalProperties, feature, {}, canonical, undefined, undefined, featureTileCoord, featureDistanceData);
139
141
  needFeature = !isFeatureConstant(compiledDynamicFilter.value.expression);
140
142
  }
@@ -151,6 +153,7 @@ ${JSON.stringify(filterExp, null, 2)}
151
153
  };
152
154
  }
153
155
 
156
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
154
157
  function extractStaticFilter(filter: any): any {
155
158
  if (!isDynamicFilter(filter)) {
156
159
  return filter;
@@ -168,6 +171,7 @@ function extractStaticFilter(filter: any): any {
168
171
  return result;
169
172
  }
170
173
 
174
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
171
175
  function collapseDynamicBooleanExpressions(expression: any): any {
172
176
  if (!Array.isArray(expression)) {
173
177
  return expression;
@@ -177,6 +181,7 @@ function collapseDynamicBooleanExpressions(expression: any): any {
177
181
  if (collapsed === true) {
178
182
  return collapsed;
179
183
  } else {
184
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
180
185
  return collapsed.map((subExpression) => collapseDynamicBooleanExpressions(subExpression));
181
186
  }
182
187
  }
@@ -190,6 +195,7 @@ function collapseDynamicBooleanExpressions(expression: any): any {
190
195
  *
191
196
  * @param {Array<any>} filter the filter expression mutated in-place.
192
197
  */
198
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
193
199
  function unionDynamicBranches(filter: any) {
194
200
  let isBranchingDynamically = false;
195
201
  const branches = [];
@@ -227,6 +233,7 @@ function unionDynamicBranches(filter: any) {
227
233
  }
228
234
  }
229
235
 
236
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
230
237
  function isDynamicFilter(filter: any): boolean {
231
238
  // Base Cases
232
239
  if (!Array.isArray(filter)) {
@@ -262,6 +269,7 @@ const dynamicConditionExpressions = new Set([
262
269
  'to-boolean'
263
270
  ]);
264
271
 
272
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
265
273
  function collapsedExpression(expression: any): any {
266
274
  if (dynamicConditionExpressions.has(expression[0])) {
267
275
 
@@ -280,6 +288,7 @@ function compare(a: number, b: number) {
280
288
  return a < b ? -1 : a > b ? 1 : 0;
281
289
  }
282
290
 
291
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
283
292
  function geometryNeeded(filter: Array<any> | boolean) {
284
293
  if (!Array.isArray(filter)) return false;
285
294
  if (filter[0] === 'within' || filter[0] === 'distance') return true;
@@ -289,6 +298,7 @@ function geometryNeeded(filter: Array<any> | boolean) {
289
298
  return false;
290
299
  }
291
300
 
301
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
292
302
  function convertFilter(filter?: Array<any> | null): unknown {
293
303
  if (!filter) return true;
294
304
  const op = filter[0];
@@ -313,22 +323,28 @@ function convertFilter(filter?: Array<any> | null): unknown {
313
323
  return converted;
314
324
  }
315
325
 
326
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
316
327
  function convertComparisonOp(property: string, value: any, op: string) {
317
328
  switch (property) {
318
329
  case '$type':
330
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
319
331
  return [`filter-type-${op}`, value];
320
332
  case '$id':
333
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
321
334
  return [`filter-id-${op}`, value];
322
335
  default:
336
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
323
337
  return [`filter-${op}`, property, value];
324
338
  }
325
339
  }
326
340
 
341
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
327
342
  function convertDisjunctionOp(filters: Array<Array<any>>) {
328
343
  // @ts-expect-error - TS2769 - No overload matches this call.
329
344
  return ['any'].concat(filters.map(convertFilter));
330
345
  }
331
346
 
347
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
332
348
  function convertInOp(property: string, values: Array<any>) {
333
349
  if (values.length === 0) { return false; }
334
350
  switch (property) {
package/format.ts CHANGED
@@ -5,6 +5,7 @@ import reference from './reference/latest';
5
5
  import stringifyPretty from 'json-stringify-pretty-compact';
6
6
 
7
7
  function sortKeysBy(obj, reference) {
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
9
  const result: Record<string, any> = {};
9
10
  for (const key in reference) {
10
11
  if (obj[key] !== undefined) {
@@ -33,6 +33,7 @@ export default function convertFunction<T>(parameters: FunctionSpecification<T>,
33
33
  if (zoomAndFeatureDependent) {
34
34
  return convertZoomAndPropertyFunction(parameters, propertySpec, stops as Array<ZoomAndPropertyFunctionStop<T>>);
35
35
  } else if (zoomDependent) {
36
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
36
37
  return convertZoomFunction(parameters, propertySpec, stops as PropertyFunctionStop<T>[]);
37
38
  } else {
38
39
  return convertPropertyFunction(parameters, propertySpec, stops as PropertyFunctionStop<T>[]);
@@ -76,7 +77,9 @@ function convertZoomAndPropertyFunction<T>(
76
77
  propertySpec: StylePropertySpecification,
77
78
  stops: Array<ZoomAndPropertyFunctionStop<T>>,
78
79
  ): ExpressionSpecification {
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
81
  const featureFunctionParameters: Record<string, any> = {};
82
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
83
  const featureFunctionStops: Record<string, any> = {};
81
84
  const zoomStops = [];
82
85
  for (let s = 0; s < stops.length; s++) {
@@ -221,6 +224,7 @@ function convertZoomFunction<T>(parameters: FunctionSpecification<T>, propertySp
221
224
 
222
225
  fixupDegenerateStepCurve(expression);
223
226
 
227
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
224
228
  return expression;
225
229
  }
226
230
 
@@ -250,7 +254,7 @@ function getFunctionType<T>(parameters: FunctionSpecification<T>, propertySpec:
250
254
  return parameters.type;
251
255
  } else {
252
256
  assert(propertySpec.expression);
253
- return (propertySpec.expression as any).interpolated ? 'exponential' : 'interval';
257
+ return propertySpec.expression.interpolated ? 'exponential' : 'interval';
254
258
  }
255
259
  }
256
260
 
package/function/index.ts CHANGED
@@ -17,6 +17,7 @@ export function isFunction(value) {
17
17
  }
18
18
 
19
19
  function identityFunction(x) {
20
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
20
21
  return x;
21
22
  }
22
23
 
@@ -32,6 +33,7 @@ export function createFunction(parameters, propertySpec) {
32
33
 
33
34
  if (parameters.stops) {
34
35
  parameters.stops = parameters.stops.map((stop) => {
36
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
35
37
  return [stop[0], Color.parse(stop[1])];
36
38
  });
37
39
  }
@@ -73,6 +75,7 @@ export function createFunction(parameters, propertySpec) {
73
75
  }
74
76
 
75
77
  if (zoomAndFeatureDependent) {
78
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
79
  const featureFunctions: Record<string, any> = {};
77
80
  const zoomStops = [];
78
81
  for (let s = 0; s < parameters.stops.length; s++) {
@@ -101,8 +104,10 @@ export function createFunction(parameters, propertySpec) {
101
104
  kind: 'composite',
102
105
  interpolationType,
103
106
  interpolationFactor: Interpolate.interpolationFactor.bind(undefined, interpolationType),
107
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
104
108
  zoomStops: featureFunctionStops.map(s => s[0]),
105
109
  evaluate({zoom}, properties) {
110
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
106
111
  return evaluateExponentialFunction({
107
112
  stops: featureFunctionStops,
108
113
  base: parameters.base
@@ -116,7 +121,9 @@ export function createFunction(parameters, propertySpec) {
116
121
  kind: 'camera',
117
122
  interpolationType,
118
123
  interpolationFactor: Interpolate.interpolationFactor.bind(undefined, interpolationType),
124
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
119
125
  zoomStops: parameters.stops.map(s => s[0]),
126
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
120
127
  evaluate: ({zoom}) => innerFun(parameters, propertySpec, zoom, hashedStops, categoricalKeyType)
121
128
  };
122
129
  } else {
@@ -125,8 +132,10 @@ export function createFunction(parameters, propertySpec) {
125
132
  evaluate(_, feature) {
126
133
  const value = feature && feature.properties ? feature.properties[parameters.property] : undefined;
127
134
  if (value === undefined) {
135
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
128
136
  return coalesce(parameters.default, propertySpec.default);
129
137
  }
138
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
130
139
  return innerFun(parameters, propertySpec, value, hashedStops, categoricalKeyType);
131
140
  }
132
141
  };
@@ -134,26 +143,36 @@ export function createFunction(parameters, propertySpec) {
134
143
  }
135
144
 
136
145
  function coalesce(a, b, c) {
146
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
137
147
  if (a !== undefined) return a;
148
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
138
149
  if (b !== undefined) return b;
150
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
139
151
  if (c !== undefined) return c;
140
152
  }
141
153
 
142
154
  function evaluateCategoricalFunction(parameters, propertySpec, input, hashedStops, keyType) {
143
155
  const evaluated = typeof input === keyType ? hashedStops[input] : undefined; // Enforce strict typing on input
156
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
144
157
  return coalesce(evaluated, parameters.default, propertySpec.default);
145
158
  }
146
159
 
147
160
  function evaluateIntervalFunction(parameters, propertySpec, input) {
148
161
  // Edge cases
162
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
149
163
  if (getType(input) !== 'number') return coalesce(parameters.default, propertySpec.default);
150
164
  const n = parameters.stops.length;
165
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
151
166
  if (n === 1) return parameters.stops[0][1];
167
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
152
168
  if (input <= parameters.stops[0][0]) return parameters.stops[0][1];
169
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
153
170
  if (input >= parameters.stops[n - 1][0]) return parameters.stops[n - 1][1];
154
171
 
172
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
155
173
  const index = findStopLessThanOrEqualTo(parameters.stops.map((stop) => stop[0]), input);
156
174
 
175
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
157
176
  return parameters.stops[index][1];
158
177
  }
159
178
 
@@ -161,12 +180,17 @@ function evaluateExponentialFunction(parameters, propertySpec, input) {
161
180
  const base = parameters.base !== undefined ? parameters.base : 1;
162
181
 
163
182
  // Edge cases
183
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
164
184
  if (getType(input) !== 'number') return coalesce(parameters.default, propertySpec.default);
165
185
  const n = parameters.stops.length;
186
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
166
187
  if (n === 1) return parameters.stops[0][1];
188
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
167
189
  if (input <= parameters.stops[0][0]) return parameters.stops[0][1];
190
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
168
191
  if (input >= parameters.stops[n - 1][0]) return parameters.stops[n - 1][1];
169
192
 
193
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
170
194
  const index = findStopLessThanOrEqualTo(parameters.stops.map((stop) => stop[0]), input);
171
195
  const t = interpolationFactor(
172
196
  input, base,
@@ -179,6 +203,7 @@ function evaluateExponentialFunction(parameters, propertySpec, input) {
179
203
 
180
204
  if (parameters.colorSpace && parameters.colorSpace !== 'rgb') {
181
205
  const colorspace = colorSpaces[parameters.colorSpace];
206
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
182
207
  interp = (a, b) => colorspace.reverse(colorspace.interpolate(colorspace.forward(a), colorspace.forward(b), t));
183
208
  }
184
209
 
@@ -191,11 +216,13 @@ function evaluateExponentialFunction(parameters, propertySpec, input) {
191
216
  if (evaluatedLower === undefined || evaluatedUpper === undefined) {
192
217
  return undefined;
193
218
  }
219
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
194
220
  return interp(evaluatedLower, evaluatedUpper, t);
195
221
  }
196
222
  };
197
223
  }
198
224
 
225
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
199
226
  return interp(outputLower, outputUpper, t);
200
227
  }
201
228
 
@@ -209,6 +236,7 @@ function evaluateIdentityFunction(parameters, propertySpec, input) {
209
236
  } else if (getType(input) !== propertySpec.type && (propertySpec.type !== 'enum' || !propertySpec.values[input])) {
210
237
  input = undefined;
211
238
  }
239
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
212
240
  return coalesce(input, parameters.default, propertySpec.default);
213
241
  }
214
242