@mapbox/mapbox-gl-style-spec 14.4.0 → 14.5.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 (142) hide show
  1. package/bin/gl-style-composite.js +0 -5
  2. package/bin/gl-style-format.js +0 -5
  3. package/bin/gl-style-migrate.js +0 -5
  4. package/bin/gl-style-validate.js +0 -5
  5. package/{composite.js → composite.ts} +1 -1
  6. package/data/{extent.js → extent.ts} +0 -2
  7. package/{deref.js → deref.ts} +7 -9
  8. package/{diff.js → diff.ts} +44 -21
  9. package/dist/index.cjs +794 -1226
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +1746 -0
  12. package/dist/index.es.js +794 -1226
  13. package/dist/index.es.js.map +1 -1
  14. package/{empty.js → empty.ts} +1 -2
  15. package/error/{parsing_error.js → parsing_error.ts} +0 -2
  16. package/error/{validation_error.js → validation_error.ts} +5 -5
  17. package/expression/{compound_expression.js → compound_expression.ts} +29 -19
  18. package/expression/definitions/{assertion.js → assertion.ts} +16 -13
  19. package/expression/definitions/{at.js → at.ts} +12 -13
  20. package/expression/definitions/{case.js → case.ts} +12 -11
  21. package/expression/definitions/{coalesce.js → coalesce.ts} +11 -11
  22. package/expression/definitions/{coercion.js → coercion.ts} +21 -20
  23. package/expression/definitions/{collator.js → collator.ts} +11 -11
  24. package/expression/definitions/{comparison.js → comparison.ts} +30 -24
  25. package/expression/definitions/{config.js → config.ts} +16 -16
  26. package/expression/definitions/{distance.js → distance.ts} +60 -52
  27. package/expression/definitions/{format.js → format.ts} +26 -15
  28. package/expression/definitions/{image.js → image.ts} +12 -12
  29. package/expression/definitions/{in.js → in.ts} +22 -13
  30. package/expression/definitions/{index.js → index.ts} +70 -83
  31. package/expression/definitions/{index_of.js → index_of.ts} +24 -15
  32. package/expression/definitions/{interpolate.js → interpolate.ts} +44 -25
  33. package/expression/definitions/{length.js → length.ts} +11 -10
  34. package/expression/definitions/{let.js → let.ts} +10 -7
  35. package/expression/definitions/{literal.js → literal.ts} +11 -12
  36. package/expression/definitions/{match.js → match.ts} +25 -15
  37. package/expression/definitions/{number_format.js → number_format.ts} +10 -10
  38. package/expression/definitions/{slice.js → slice.ts} +23 -15
  39. package/expression/definitions/{step.js → step.ts} +14 -12
  40. package/expression/definitions/{var.js → var.ts} +5 -7
  41. package/expression/definitions/{within.js → within.ts} +41 -29
  42. package/expression/{evaluation_context.js → evaluation_context.ts} +26 -23
  43. package/expression/expression.ts +29 -0
  44. package/expression/{index.js → index.ts} +208 -110
  45. package/expression/{is_constant.js → is_constant.ts} +5 -7
  46. package/expression/{parsing_context.js → parsing_context.ts} +47 -34
  47. package/expression/{parsing_error.js → parsing_error.ts} +0 -2
  48. package/expression/{runtime_error.js → runtime_error.ts} +0 -2
  49. package/expression/{scope.js → scope.ts} +5 -5
  50. package/expression/{stops.js → stops.ts} +2 -4
  51. package/expression/types/{collator.js → collator.ts} +1 -3
  52. package/expression/types/{formatted.js → formatted.ts} +8 -7
  53. package/expression/types/{resolved_image.js → resolved_image.ts} +5 -7
  54. package/expression/{types.js → types.ts} +53 -45
  55. package/expression/{values.js → values.ts} +12 -12
  56. package/feature_filter/{convert.js → convert.ts} +19 -18
  57. package/feature_filter/{index.js → index.ts} +39 -21
  58. package/{format.js → format.ts} +3 -3
  59. package/function/{convert.js → convert.ts} +44 -44
  60. package/function/{index.js → index.ts} +12 -12
  61. package/{group_by_layout.js → group_by_layout.ts} +11 -8
  62. package/migrate/{expressions.js → expressions.ts} +7 -16
  63. package/migrate/{v8.js → v8.ts} +2 -2
  64. package/migrate/{v9.js → v9.ts} +2 -2
  65. package/{migrate.js → migrate.ts} +3 -3
  66. package/package.json +19 -18
  67. package/{read_style.js → read_style.ts} +5 -4
  68. package/reference/latest.ts +5 -0
  69. package/reference/v8.json +264 -7
  70. package/rollup.config.js +6 -24
  71. package/{style-spec.js → style-spec.ts} +41 -36
  72. package/test.js +3 -2
  73. package/types/config_options.ts +13 -0
  74. package/types/lut.ts +7 -0
  75. package/types/tile_id.ts +5 -0
  76. package/{types.js → types.ts} +527 -165
  77. package/util/{color.js → color.ts} +89 -3
  78. package/util/{color_spaces.js → color_spaces.ts} +12 -14
  79. package/util/{deep_equal.js → deep_equal.ts} +1 -3
  80. package/util/{extend.js → extend.ts} +1 -3
  81. package/util/{geometry_util.js → geometry_util.ts} +23 -11
  82. package/util/{get_type.js → get_type.ts} +1 -3
  83. package/util/{interpolate.js → interpolate.ts} +1 -3
  84. package/util/{properties.js → properties.ts} +5 -4
  85. package/util/{random.js → random.ts} +0 -2
  86. package/util/{ref_properties.js → ref_properties.ts} +0 -1
  87. package/util/{result.js → result.ts} +7 -5
  88. package/util/{unbundle_jsonlint.js → unbundle_jsonlint.ts} +5 -5
  89. package/validate/{validate.js → validate.ts} +33 -35
  90. package/validate/{validate_array.js → validate_array.ts} +5 -7
  91. package/validate/{validate_boolean.js → validate_boolean.ts} +3 -5
  92. package/validate/{validate_color.js → validate_color.ts} +3 -5
  93. package/validate/{validate_enum.js → validate_enum.ts} +4 -5
  94. package/validate/{validate_expression.js → validate_expression.ts} +7 -9
  95. package/validate/{validate_filter.js → validate_filter.ts} +16 -12
  96. package/validate/{validate_fog.js → validate_fog.ts} +4 -6
  97. package/validate/validate_formatted.ts +13 -0
  98. package/validate/{validate_function.js → validate_function.ts} +14 -16
  99. package/validate/{validate_glyphs_url.js → validate_glyphs_url.ts} +3 -5
  100. package/validate/validate_image.ts +13 -0
  101. package/validate/{validate_import.js → validate_import.ts} +6 -8
  102. package/validate/{validate_layer.js → validate_layer.ts} +17 -15
  103. package/validate/{validate_layout_property.js → validate_layout_property.ts} +3 -5
  104. package/validate/{validate_light.js → validate_light.ts} +4 -6
  105. package/validate/{validate_lights.js → validate_lights.ts} +7 -9
  106. package/validate/{validate_model.js → validate_model.ts} +4 -6
  107. package/validate/{validate_number.js → validate_number.ts} +4 -6
  108. package/validate/{validate_object.js → validate_object.ts} +5 -8
  109. package/validate/{validate_paint_property.js → validate_paint_property.ts} +3 -5
  110. package/validate/{validate_projection.js → validate_projection.ts} +4 -6
  111. package/validate/{validate_property.js → validate_property.ts} +15 -15
  112. package/validate/{validate_source.js → validate_source.ts} +16 -13
  113. package/validate/validate_string.ts +16 -0
  114. package/validate/validate_style.ts +33 -0
  115. package/validate/{validate_terrain.js → validate_terrain.ts} +5 -7
  116. package/{validate_mapbox_api_supported.js → validate_mapbox_api_supported.ts} +22 -18
  117. package/{validate_style.min.js → validate_style.min.ts} +20 -21
  118. package/{validate_style.js → validate_style.ts} +9 -9
  119. package/{visit.js → visit.ts} +22 -17
  120. package/.eslintrc +0 -10
  121. package/expression/expression.js +0 -28
  122. package/flow-typed/cheap-ruler.js +0 -25
  123. package/flow-typed/geojson.js +0 -44
  124. package/flow-typed/gl-matrix.js +0 -119
  125. package/flow-typed/gl.js +0 -5
  126. package/flow-typed/intl.js +0 -58
  127. package/flow-typed/kdbush.js +0 -9
  128. package/flow-typed/mapbox-gl-supported.js +0 -16
  129. package/flow-typed/mapbox-unitbezier.js +0 -14
  130. package/flow-typed/offscreen-canvas.js +0 -9
  131. package/flow-typed/pbf.js +0 -26
  132. package/flow-typed/point-geometry.js +0 -46
  133. package/flow-typed/potpack.js +0 -13
  134. package/flow-typed/tiny-sdf.js +0 -31
  135. package/flow-typed/tracked_parameters_proxy.js +0 -82
  136. package/flow-typed/vector-tile.js +0 -49
  137. package/flow-typed/webgl2.js +0 -41
  138. package/reference/latest.js +0 -7
  139. package/validate/validate_formatted.js +0 -15
  140. package/validate/validate_image.js +0 -15
  141. package/validate/validate_string.js +0 -18
  142. package/validate/validate_style.js +0 -29
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  class ParsingError extends Error {
4
2
  key: string;
5
3
  message: string;
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  class RuntimeError {
4
2
  name: string;
5
3
  message: string;
@@ -1,14 +1,14 @@
1
- // @flow
2
-
3
- import type {Expression} from './expression.js';
1
+ import type {Expression} from './expression';
4
2
 
5
3
  /**
6
4
  * Tracks `let` bindings during expression parsing.
7
5
  * @private
8
6
  */
9
7
  class Scope {
10
- parent: ?Scope;
11
- bindings: {[_: string]: Expression};
8
+ parent: Scope | null | undefined;
9
+ bindings: {
10
+ [_: string]: Expression;
11
+ };
12
12
  constructor(parent?: Scope, bindings: Array<[string, Expression]> = []) {
13
13
  this.parent = parent;
14
14
  this.bindings = {};
@@ -1,8 +1,6 @@
1
- // @flow
1
+ import RuntimeError from './runtime_error';
2
2
 
3
- import RuntimeError from './runtime_error.js';
4
-
5
- import type {Expression} from './expression.js';
3
+ import type {Expression} from './expression';
6
4
 
7
5
  export type Stops = Array<[number, Expression]>;
8
6
 
@@ -1,9 +1,7 @@
1
- // @flow
2
-
3
1
  export default class Collator {
4
2
  locale: string | null;
5
3
  sensitivity: 'base' | 'accent' | 'case' | 'variant';
6
- collator: Intl$Collator;
4
+ collator: Intl.Collator;
7
5
 
8
6
  constructor(caseSensitive: boolean, diacriticSensitive: boolean, locale: string | null) {
9
7
  if (caseSensitive)
@@ -1,6 +1,5 @@
1
- // @flow
2
- import type Color from '../../util/color.js';
3
- import type ResolvedImage from '../types/resolved_image.js';
1
+ import type Color from '../../util/color';
2
+ import type ResolvedImage from '../types/resolved_image';
4
3
 
5
4
  export class FormattedSection {
6
5
  text: string;
@@ -49,15 +48,17 @@ export default class Formatted {
49
48
  return this.sections.map(section => section.text).join('');
50
49
  }
51
50
 
52
- serialize(): Array<mixed> {
53
- const serialized: Array<mixed> = ["format"];
51
+ serialize(): Array<unknown> {
52
+ const serialized: Array<unknown> = ["format"];
54
53
  for (const section of this.sections) {
55
54
  if (section.image) {
56
55
  serialized.push(["image", section.image.namePrimary]);
57
56
  continue;
58
57
  }
59
58
  serialized.push(section.text);
60
- const options: { [key: string]: mixed } = {};
59
+ const options: {
60
+ [key: string]: unknown;
61
+ } = {};
61
62
  if (section.fontStack) {
62
63
  options["text-font"] = ["literal", section.fontStack.split(',')];
63
64
  }
@@ -65,7 +66,7 @@ export default class Formatted {
65
66
  options["font-scale"] = section.scale;
66
67
  }
67
68
  if (section.textColor) {
68
- options["text-color"] = (["rgba"]: Array<mixed>).concat(section.textColor.toArray());
69
+ options["text-color"] = (["rgba"] as Array<unknown>).concat(section.textColor.toRenderColor(null).toArray());
69
70
  }
70
71
  serialized.push(options);
71
72
  }
@@ -1,14 +1,12 @@
1
- // @flow
2
-
3
1
  export type ResolvedImageOptions = {
4
- namePrimary: string,
5
- nameSecondary: ?string,
6
- available: boolean
2
+ namePrimary: string;
3
+ nameSecondary: string | null | undefined;
4
+ available: boolean;
7
5
  };
8
6
 
9
7
  export default class ResolvedImage {
10
8
  namePrimary: string;
11
- nameSecondary: ?string;
9
+ nameSecondary: string | null | undefined;
12
10
  available: boolean;
13
11
 
14
12
  constructor(options: ResolvedImageOptions) {
@@ -26,7 +24,7 @@ export default class ResolvedImage {
26
24
  return this.namePrimary;
27
25
  }
28
26
 
29
- static fromString(namePrimary: string, nameSecondary: ?string): ResolvedImage | null {
27
+ static fromString(namePrimary: string, nameSecondary?: string | null): ResolvedImage | null {
30
28
  if (!namePrimary) return null; // treat empty values as no image
31
29
  return new ResolvedImage({namePrimary, nameSecondary, available: false});
32
30
  }
@@ -1,55 +1,63 @@
1
- // @flow
2
-
3
- export type NullTypeT = { kind: 'null' };
4
- export type NumberTypeT = { kind: 'number' };
5
- export type StringTypeT = { kind: 'string' };
6
- export type BooleanTypeT = { kind: 'boolean' };
7
- export type ColorTypeT = { kind: 'color' };
8
- export type ObjectTypeT = { kind: 'object' };
9
- export type ValueTypeT = { kind: 'value' };
10
- export type ErrorTypeT = { kind: 'error' };
11
- export type CollatorTypeT = { kind: 'collator' };
12
- export type FormattedTypeT = { kind: 'formatted' };
13
- export type ResolvedImageTypeT = { kind: 'resolvedImage' };
1
+ export type NullTypeT = {
2
+ kind: 'null';
3
+ };
4
+ export type NumberTypeT = {
5
+ kind: 'number';
6
+ };
7
+ export type StringTypeT = {
8
+ kind: 'string';
9
+ };
10
+ export type BooleanTypeT = {
11
+ kind: 'boolean';
12
+ };
13
+ export type ColorTypeT = {
14
+ kind: 'color';
15
+ };
16
+ export type ObjectTypeT = {
17
+ kind: 'object';
18
+ };
19
+ export type ValueTypeT = {
20
+ kind: 'value';
21
+ };
22
+ export type ErrorTypeT = {
23
+ kind: 'error';
24
+ };
25
+ export type CollatorTypeT = {
26
+ kind: 'collator';
27
+ };
28
+ export type FormattedTypeT = {
29
+ kind: 'formatted';
30
+ };
31
+ export type ResolvedImageTypeT = {
32
+ kind: 'resolvedImage';
33
+ };
14
34
 
15
35
  export type EvaluationKind = 'constant' | 'source' | 'camera' | 'composite';
16
36
 
17
- export type Type =
18
- NullTypeT |
19
- NumberTypeT |
20
- StringTypeT |
21
- BooleanTypeT |
22
- ColorTypeT |
23
- ObjectTypeT |
24
- ValueTypeT |
25
- ArrayType | // eslint-disable-line no-use-before-define
26
- ErrorTypeT |
27
- CollatorTypeT |
28
- FormattedTypeT |
29
- ResolvedImageTypeT |
30
- ArrayType;
37
+ export type Type = NullTypeT | NumberTypeT | StringTypeT | BooleanTypeT | ColorTypeT | ObjectTypeT | ValueTypeT | // eslint-disable-line no-use-before-define
38
+ ArrayType | ErrorTypeT | CollatorTypeT | FormattedTypeT | ResolvedImageTypeT;
31
39
 
32
40
  export type ArrayType = {
33
- kind: 'array',
34
- itemType: Type,
35
- N: ?number
36
- }
41
+ kind: 'array';
42
+ itemType: Type;
43
+ N: number | null | undefined;
44
+ };
37
45
 
38
- export type NativeType = 'number' | 'string' | 'boolean' | 'null' | 'array' | 'object'
46
+ export type NativeType = 'number' | 'string' | 'boolean' | 'null' | 'array' | 'object';
39
47
 
40
- export const NullType = {kind: 'null'};
41
- export const NumberType = {kind: 'number'};
42
- export const StringType = {kind: 'string'};
43
- export const BooleanType = {kind: 'boolean'};
44
- export const ColorType = {kind: 'color'};
45
- export const ObjectType = {kind: 'object'};
46
- export const ValueType = {kind: 'value'};
47
- export const ErrorType = {kind: 'error'};
48
- export const CollatorType = {kind: 'collator'};
49
- export const FormattedType = {kind: 'formatted'};
50
- export const ResolvedImageType = {kind: 'resolvedImage'};
48
+ export const NullType = {kind: 'null'} as const;
49
+ export const NumberType = {kind: 'number'} as const;
50
+ export const StringType = {kind: 'string'} as const;
51
+ export const BooleanType = {kind: 'boolean'} as const;
52
+ export const ColorType = {kind: 'color'} as const;
53
+ export const ObjectType = {kind: 'object'} as const;
54
+ export const ValueType = {kind: 'value'} as const;
55
+ export const ErrorType = {kind: 'error'} as const;
56
+ export const CollatorType = {kind: 'collator'} as const;
57
+ export const FormattedType = {kind: 'formatted'} as const;
58
+ export const ResolvedImageType = {kind: 'resolvedImage'} as const;
51
59
 
52
- export function array(itemType: Type, N: ?number): ArrayType {
60
+ export function array(itemType: Type, N?: number | null): ArrayType {
53
61
  return {
54
62
  kind: 'array',
55
63
  itemType,
@@ -85,7 +93,7 @@ const valueMemberTypes = [
85
93
  * error message.
86
94
  * @private
87
95
  */
88
- export function checkSubtype(expected: Type, t: Type): ?string {
96
+ export function checkSubtype(expected: Type, t: Type): string | null | undefined {
89
97
  if (t.kind === 'error') {
90
98
  // Error is a subtype of every type
91
99
  return null;
@@ -1,16 +1,14 @@
1
- // @flow
2
-
3
1
  import assert from 'assert';
4
2
 
5
- import Color from '../util/color.js';
6
- import Collator from './types/collator.js';
7
- import Formatted from './types/formatted.js';
8
- import ResolvedImage from './types/resolved_image.js';
9
- import {NullType, NumberType, StringType, BooleanType, ColorType, ObjectType, ValueType, CollatorType, FormattedType, ResolvedImageType, array} from './types.js';
3
+ import Color from '../util/color';
4
+ import Collator from './types/collator';
5
+ import Formatted from './types/formatted';
6
+ import ResolvedImage from './types/resolved_image';
7
+ import {NullType, NumberType, StringType, BooleanType, ColorType, ObjectType, ValueType, CollatorType, FormattedType, ResolvedImageType, array} from './types';
10
8
 
11
- import type {Type} from './types.js';
9
+ import type {Type} from './types';
12
10
 
13
- export function validateRGBA(r: mixed, g: mixed, b: mixed, a?: mixed): string | null {
11
+ export function validateRGBA(r: unknown, g: unknown, b: unknown, a?: unknown): string | null {
14
12
  if (!(
15
13
  typeof r === 'number' && r >= 0 && r <= 255 &&
16
14
  typeof g === 'number' && g >= 0 && g <= 255 &&
@@ -29,7 +27,7 @@ export function validateRGBA(r: mixed, g: mixed, b: mixed, a?: mixed): string |
29
27
  return null;
30
28
  }
31
29
 
32
- export function validateHSLA(h: mixed, s: mixed, l: mixed, a?: mixed): string | null {
30
+ export function validateHSLA(h: unknown, s: unknown, l: unknown, a?: unknown): string | null {
33
31
  if (!(
34
32
  typeof h === 'number' && h >= 0 && h <= 360
35
33
  )) {
@@ -54,9 +52,11 @@ export function validateHSLA(h: mixed, s: mixed, l: mixed, a?: mixed): string |
54
52
  return null;
55
53
  }
56
54
 
57
- export type Value = null | string | boolean | number | Color | Collator | Formatted | ResolvedImage | $ReadOnlyArray<Value> | { +[string]: Value }
55
+ export type Value = null | string | boolean | number | Color | Collator | Formatted | ResolvedImage | ReadonlyArray<Value> | {
56
+ readonly [key: string]: Value;
57
+ };
58
58
 
59
- export function isValue(mixed: mixed): boolean {
59
+ export function isValue(mixed: unknown): boolean {
60
60
  if (mixed === null) {
61
61
  return true;
62
62
  } else if (typeof mixed === 'string') {
@@ -1,17 +1,17 @@
1
- // @flow
1
+ import {isExpressionFilter} from './index';
2
2
 
3
- import {isExpressionFilter} from './index.js';
3
+ import type {FilterSpecification} from '../types';
4
4
 
5
- import type {FilterSpecification} from '../types.js';
6
-
7
- type ExpectedTypes = {[_: string]: 'string' | 'number' | 'boolean'};
5
+ type ExpectedTypes = {
6
+ [_: string]: 'string' | 'number' | 'boolean';
7
+ };
8
8
 
9
9
  /**
10
10
  * Convert the given legacy filter to (the JSON representation of) an
11
11
  * equivalent expression
12
12
  * @private
13
13
  */
14
- export default function convertFilter(filter: FilterSpecification): mixed {
14
+ export default function convertFilter(filter: FilterSpecification): unknown {
15
15
  return _convertFilter(filter, {});
16
16
  }
17
17
 
@@ -63,7 +63,7 @@ export default function convertFilter(filter: FilterSpecification): mixed {
63
63
  * false (legacy filter semantics) are equivalent: they cause the filter to
64
64
  * produce a `false` result.
65
65
  */
66
- function _convertFilter(filter: FilterSpecification, expectedTypes: ExpectedTypes): mixed {
66
+ function _convertFilter(filter: FilterSpecification, expectedTypes: ExpectedTypes): unknown {
67
67
  if (isExpressionFilter(filter)) { return filter; }
68
68
 
69
69
  if (!filter) return true;
@@ -80,29 +80,29 @@ function _convertFilter(filter: FilterSpecification, expectedTypes: ExpectedType
80
80
  op === '<=' ||
81
81
  op === '>='
82
82
  ) {
83
- const [, property, value] = (filter: any);
83
+ const [, property, value] = (filter as any);
84
84
  converted = convertComparisonOp(property, value, op, expectedTypes);
85
85
  } else if (op === 'any') {
86
- const children = (filter: any).slice(1).map(f => {
87
- const types = {};
86
+ const children = (filter as any).slice(1).map(f => {
87
+ const types: Record<string, any> = {};
88
88
  const child = _convertFilter(f, types);
89
89
  const typechecks = runtimeTypeChecks(types);
90
90
  return typechecks === true ? child : ['case', typechecks, child, false];
91
91
  });
92
92
  return ['any'].concat(children);
93
93
  } else if (op === 'all') {
94
- const children = (filter: any).slice(1).map(f => _convertFilter(f, expectedTypes));
94
+ const children = (filter as any).slice(1).map(f => _convertFilter(f, expectedTypes));
95
95
  return children.length > 1 ? ['all'].concat(children) : [].concat(...children);
96
96
  } else if (op === 'none') {
97
- return ['!', _convertFilter(['any'].concat((filter: any).slice(1)), {})];
97
+ return ['!', _convertFilter(['any'].concat((filter as any).slice(1)), {})];
98
98
  } else if (op === 'in') {
99
- converted = convertInOp((filter[1]: any), filter.slice(2));
99
+ converted = convertInOp((filter[1] as any), filter.slice(2));
100
100
  } else if (op === '!in') {
101
- converted = convertInOp((filter[1]: any), filter.slice(2), true);
101
+ converted = convertInOp((filter[1] as any), filter.slice(2), true);
102
102
  } else if (op === 'has') {
103
- converted = convertHasOp((filter[1]: any));
103
+ converted = convertHasOp((filter[1] as any));
104
104
  } else if (op === '!has') {
105
- converted = ['!', convertHasOp((filter[1]: any))];
105
+ converted = ['!', convertHasOp((filter[1] as any))];
106
106
  } else {
107
107
  converted = true;
108
108
  }
@@ -129,7 +129,7 @@ function runtimeTypeChecks(expectedTypes: ExpectedTypes) {
129
129
  return ['all'].concat(conditions);
130
130
  }
131
131
 
132
- function convertComparisonOp(property: string, value: any, op: string, expectedTypes: ?ExpectedTypes) {
132
+ function convertComparisonOp(property: string, value: any, op: string, expectedTypes?: ExpectedTypes | null) {
133
133
  let get;
134
134
  if (property === '$type') {
135
135
  return [op, ['geometry-type'], value];
@@ -140,7 +140,7 @@ function convertComparisonOp(property: string, value: any, op: string, expectedT
140
140
  }
141
141
 
142
142
  if (expectedTypes && value !== null) {
143
- const type = ((typeof value): any);
143
+ const type = ((typeof value) as any);
144
144
  expectedTypes[property] = type;
145
145
  }
146
146
 
@@ -193,6 +193,7 @@ function convertInOp(property: string, values: Array<any>, negate: boolean = fal
193
193
  }
194
194
 
195
195
  return [ negate ? 'all' : 'any' ].concat(
196
+ // @ts-expect-error - TS2769 - No overload matches this call.
196
197
  values.map(v => [negate ? '!=' : '==', get, v])
197
198
  );
198
199
  }
@@ -1,21 +1,36 @@
1
- // @flow
2
-
3
- import {createExpression} from '../expression/index.js';
4
- import {isFeatureConstant} from '../expression/is_constant.js';
5
- import {deepUnbundle} from '../util/unbundle_jsonlint.js';
6
- import latest from '../reference/latest.js';
7
- import type {GlobalProperties, Feature} from '../expression/index.js';
8
- import type {CanonicalTileID} from '../../source/tile_id.js';
9
1
  import type Point from '@mapbox/point-geometry';
10
-
11
- export type FeatureDistanceData = {bearing: [number, number], center: [number, number], scale: number};
12
- export type FilterExpression = (globalProperties: GlobalProperties, feature: Feature, canonical?: CanonicalTileID, featureTileCoord?: Point, featureDistanceData?: FeatureDistanceData) => boolean;
13
- export type FeatureFilter = {filter: FilterExpression, dynamicFilter?: FilterExpression, needGeometry: boolean, needFeature: boolean};
2
+ import latest from '../reference/latest';
3
+
4
+ import {deepUnbundle} from '../util/unbundle_jsonlint';
5
+ import {createExpression} from '../expression/index';
6
+ import {isFeatureConstant} from '../expression/is_constant';
7
+ import type {CanonicalTileID} from '../types/tile_id';
8
+ import type {GlobalProperties, Feature} from '../expression/index';
9
+ import type {FilterSpecification, ExpressionSpecification} from '../types';
10
+
11
+ export type FeatureDistanceData = {
12
+ bearing: [number, number];
13
+ center: [number, number];
14
+ scale: number;
15
+ };
16
+ export type FilterExpression = (
17
+ globalProperties: GlobalProperties,
18
+ feature: Feature,
19
+ canonical?: CanonicalTileID,
20
+ featureTileCoord?: Point,
21
+ featureDistanceData?: FeatureDistanceData,
22
+ ) => boolean;
23
+ export type FeatureFilter = {
24
+ filter: FilterExpression;
25
+ dynamicFilter?: FilterExpression;
26
+ needGeometry: boolean;
27
+ needFeature: boolean;
28
+ };
14
29
 
15
30
  export default createFilter;
16
31
  export {isExpressionFilter, isDynamicFilter, extractStaticFilter};
17
32
 
18
- function isExpressionFilter(filter: any): boolean {
33
+ function isExpressionFilter(filter: unknown): boolean {
19
34
  if (filter === true || filter === false) {
20
35
  return true;
21
36
  }
@@ -67,21 +82,21 @@ function isExpressionFilter(filter: any): boolean {
67
82
  * @param {string} layerType the type of the layer this filter will be applied to.
68
83
  * @returns {Function} filter-evaluating function
69
84
  */
70
- function createFilter(filter: any, layerType?: string = 'fill'): FeatureFilter {
85
+ function createFilter(filter?: FilterSpecification | ExpressionSpecification, layerType: string = 'fill'): FeatureFilter {
71
86
  if (filter === null || filter === undefined) {
72
87
  return {filter: () => true, needGeometry: false, needFeature: false};
73
88
  }
74
89
 
75
90
  if (!isExpressionFilter(filter)) {
76
- // $FlowFixMe[incompatible-call]
77
- filter = convertFilter(filter);
91
+ filter = convertFilter(filter) as ExpressionSpecification;
78
92
  }
79
- const filterExp = ((filter: any): string[] | string | boolean);
93
+
94
+ const filterExp = (filter as string[] | string | boolean);
80
95
 
81
96
  let staticFilter = true;
82
97
  try {
83
98
  staticFilter = extractStaticFilter(filterExp);
84
- } catch (e) {
99
+ } catch (e: any) {
85
100
  console.warn(
86
101
  `Failed to extract static filter. Filter will continue working, but at higher memory usage and slower framerate.
87
102
  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
@@ -118,7 +133,7 @@ ${JSON.stringify(filterExp, null, 2)}
118
133
  }
119
134
  }
120
135
 
121
- filterFunc = ((filterFunc: any): FilterExpression);
136
+ filterFunc = (filterFunc as FilterExpression);
122
137
  const needGeometry = geometryNeeded(staticFilter);
123
138
 
124
139
  return {
@@ -267,7 +282,7 @@ function geometryNeeded(filter: Array<any> | boolean) {
267
282
  return false;
268
283
  }
269
284
 
270
- function convertFilter(filter: ?Array<any>): mixed {
285
+ function convertFilter(filter?: Array<any> | null): unknown {
271
286
  if (!filter) return true;
272
287
  const op = filter[0];
273
288
  if (filter.length <= 1) return (op !== 'any');
@@ -279,7 +294,9 @@ function convertFilter(filter: ?Array<any>): mixed {
279
294
  op === '<=' ||
280
295
  op === '>=' ? convertComparisonOp(filter[1], filter[2], op) :
281
296
  op === 'any' ? convertDisjunctionOp(filter.slice(1)) :
297
+ // @ts-expect-error - TS2769 - No overload matches this call.
282
298
  op === 'all' ? ['all'].concat(filter.slice(1).map(convertFilter)) :
299
+ // @ts-expect-error - TS2769 - No overload matches this call.
283
300
  op === 'none' ? ['all'].concat(filter.slice(1).map(convertFilter).map(convertNegation)) :
284
301
  op === 'in' ? convertInOp(filter[1], filter.slice(2)) :
285
302
  op === '!in' ? convertNegation(convertInOp(filter[1], filter.slice(2))) :
@@ -301,6 +318,7 @@ function convertComparisonOp(property: string, value: any, op: string) {
301
318
  }
302
319
 
303
320
  function convertDisjunctionOp(filters: Array<Array<any>>) {
321
+ // @ts-expect-error - TS2769 - No overload matches this call.
304
322
  return ['any'].concat(filters.map(convertFilter));
305
323
  }
306
324
 
@@ -331,6 +349,6 @@ function convertHasOp(property: string) {
331
349
  }
332
350
  }
333
351
 
334
- function convertNegation(filter: mixed) {
352
+ function convertNegation(filter: unknown) {
335
353
  return ['!', filter];
336
354
  }
@@ -1,10 +1,10 @@
1
- // @noflow
1
+ // @ts-nocheck
2
2
 
3
- import reference from './reference/latest.js';
3
+ import reference from './reference/latest';
4
4
  import stringifyPretty from 'json-stringify-pretty-compact';
5
5
 
6
6
  function sortKeysBy(obj, reference) {
7
- const result = {};
7
+ const result: Record<string, any> = {};
8
8
  for (const key in reference) {
9
9
  if (obj[key] !== undefined) {
10
10
  result[key] = obj[key];