@mapbox/mapbox-gl-style-spec 14.28.0 → 14.29.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 (63) hide show
  1. package/composite.ts +5 -5
  2. package/diff.ts +38 -40
  3. package/dist/index.cjs +362 -238
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +101 -13
  6. package/dist/index.es.js +362 -238
  7. package/dist/index.es.js.map +1 -1
  8. package/expression/compound_expression.ts +6 -6
  9. package/expression/definitions/assertion.ts +9 -12
  10. package/expression/definitions/at.ts +1 -1
  11. package/expression/definitions/at_interpolated.ts +1 -1
  12. package/expression/definitions/case.ts +1 -2
  13. package/expression/definitions/coalesce.ts +1 -1
  14. package/expression/definitions/coercion.ts +10 -12
  15. package/expression/definitions/collator.ts +8 -8
  16. package/expression/definitions/comparison.ts +0 -1
  17. package/expression/definitions/distance.ts +135 -73
  18. package/expression/definitions/format.ts +10 -13
  19. package/expression/definitions/image.ts +8 -8
  20. package/expression/definitions/index.ts +92 -90
  21. package/expression/definitions/interpolate.ts +18 -19
  22. package/expression/definitions/let.ts +1 -2
  23. package/expression/definitions/literal.ts +1 -1
  24. package/expression/definitions/match.ts +7 -8
  25. package/expression/definitions/number_format.ts +7 -8
  26. package/expression/definitions/step.ts +11 -11
  27. package/expression/definitions/within.ts +23 -24
  28. package/expression/evaluation_context.ts +4 -4
  29. package/expression/expression.ts +1 -1
  30. package/expression/index.ts +43 -21
  31. package/expression/parsing_context.ts +2 -2
  32. package/expression/stops.ts +2 -2
  33. package/expression/values.ts +2 -2
  34. package/feature_filter/index.ts +3 -3
  35. package/function/convert.ts +8 -8
  36. package/function/index.ts +4 -2
  37. package/group_by_layout.ts +6 -4
  38. package/package.json +1 -1
  39. package/read_style.ts +2 -2
  40. package/reference/v8.json +86 -5
  41. package/types/config_options.ts +1 -1
  42. package/types.ts +16 -6
  43. package/util/properties.ts +1 -1
  44. package/validate/validate.ts +15 -5
  45. package/validate/validate_appearance.ts +7 -7
  46. package/validate/validate_array.ts +7 -7
  47. package/validate/validate_enum.ts +2 -3
  48. package/validate/validate_fog.ts +2 -2
  49. package/validate/validate_function.ts +14 -13
  50. package/validate/validate_layer.ts +10 -9
  51. package/validate/validate_light.ts +2 -2
  52. package/validate/validate_lights.ts +3 -3
  53. package/validate/validate_number.ts +10 -7
  54. package/validate/validate_object.ts +11 -10
  55. package/validate/validate_option.ts +24 -9
  56. package/validate/validate_property.ts +4 -4
  57. package/validate/validate_rain.ts +1 -1
  58. package/validate/validate_snow.ts +1 -1
  59. package/validate/validate_style.ts +2 -1
  60. package/validate/validate_terrain.ts +2 -2
  61. package/validate_mapbox_api_supported.ts +5 -6
  62. package/validate_style.min.ts +2 -1
  63. package/visit.ts +11 -10
@@ -38,8 +38,8 @@ class CompoundExpression implements Expression {
38
38
 
39
39
  evaluate(ctx: EvaluationContext): Value {
40
40
  if (!this._evaluate) { // restore evaluate function after transfer between threads
41
- const definition = CompoundExpression.definitions[this.name];
42
- this._evaluate = Array.isArray(definition) ? definition[2] : definition.overloads[this._overloadIndex][1];
41
+ const definition = CompoundExpression.definitions[this.name]!;
42
+ this._evaluate = Array.isArray(definition) ? definition[2] : definition.overloads[this._overloadIndex]![1];
43
43
  }
44
44
  return this._evaluate(ctx, this.args);
45
45
  }
@@ -73,7 +73,7 @@ class CompoundExpression implements Expression {
73
73
 
74
74
  const overloadParams = [];
75
75
 
76
- let signatureContext: ParsingContext = null;
76
+ let signatureContext: ParsingContext | null = null;
77
77
 
78
78
  let overloadIndex = -1;
79
79
 
@@ -125,8 +125,8 @@ class CompoundExpression implements Expression {
125
125
  }
126
126
 
127
127
  for (let i = 0; i < parsedArgs.length; i++) {
128
- const expected = Array.isArray(params) ? params[i] : params.type;
129
- const arg = parsedArgs[i];
128
+ const expected = Array.isArray(params) ? params[i]! : params.type;
129
+ const arg = parsedArgs[i]!;
130
130
  signatureContext.checkSubtype(expected, arg.type, i + 1);
131
131
  }
132
132
 
@@ -138,7 +138,7 @@ class CompoundExpression implements Expression {
138
138
  assert(!signatureContext || signatureContext.errors.length > 0);
139
139
 
140
140
  if (overloadParams.length === 1) {
141
- context.errors.push(...signatureContext.errors);
141
+ context.errors.push(...signatureContext!.errors);
142
142
  } else {
143
143
  const expected = overloadParams.length ? overloadParams : availableOverloads.map(([params]) => params);
144
144
  const signatures = expected.map(stringifySignature).join(' | ');
@@ -17,7 +17,7 @@ import type ParsingContext from '../parsing_context';
17
17
  import type EvaluationContext from '../evaluation_context';
18
18
  import type {Type} from '../types';
19
19
 
20
- const types = {
20
+ const types: Record<string, Type> = {
21
21
  string: StringType,
22
22
  number: NumberType,
23
23
  boolean: BooleanType,
@@ -33,7 +33,7 @@ class Assertion implements Expression {
33
33
  this.args = args;
34
34
  }
35
35
 
36
- static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Expression | void {
36
+ static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Expression | null | void {
37
37
  if (args.length < 2)
38
38
  return context.error(`Expected at least one argument.`);
39
39
 
@@ -47,8 +47,7 @@ class Assertion implements Expression {
47
47
  const type = args[1];
48
48
  if (typeof type !== 'string' || !(type in types) || type === 'object')
49
49
  return context.error('The item type argument of "array" must be one of string, number, boolean', 1);
50
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
51
- itemType = types[type];
50
+ itemType = types[type]!;
52
51
  i++;
53
52
  } else {
54
53
  itemType = ValueType;
@@ -63,25 +62,23 @@ class Assertion implements Expression {
63
62
  ) {
64
63
  return context.error('The length argument to "array" must be a positive integer literal', 2);
65
64
  }
66
- N = (args[2] as number);
65
+ N = args[2];
67
66
  i++;
68
67
  }
69
68
 
70
69
  type = array(itemType, N);
71
70
  } else {
72
71
  assert(types[name], name);
73
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
74
- type = types[name];
72
+ type = types[name]!;
75
73
  }
76
74
 
77
- const parsed = [];
75
+ const parsed: Expression[] = [];
78
76
  for (; i < args.length; i++) {
79
77
  const input = context.parse(args[i], i, ValueType);
80
78
  if (!input) return null;
81
79
  parsed.push(input);
82
80
  }
83
81
 
84
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
85
82
  return new Assertion(type, parsed);
86
83
  }
87
84
 
@@ -89,14 +86,14 @@ class Assertion implements Expression {
89
86
  evaluate(ctx: EvaluationContext): any {
90
87
  for (let i = 0; i < this.args.length; i++) {
91
88
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
92
- const value = this.args[i].evaluate(ctx);
89
+ const value = this.args[i]!.evaluate(ctx);
93
90
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
94
91
  const error = checkSubtype(this.type, typeOf(value));
95
92
  if (!error) {
96
93
  return value;
97
94
  } else if (i === this.args.length - 1) {
98
95
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
99
- throw new RuntimeError(`The expression ${JSON.stringify(this.args[i].serialize())} evaluated to ${toString(typeOf(value))} but was expected to be of type ${toString(this.type)}.`);
96
+ throw new RuntimeError(`The expression ${JSON.stringify(this.args[i]!.serialize())} evaluated to ${toString(typeOf(value))} but was expected to be of type ${toString(this.type)}.`);
100
97
  }
101
98
  }
102
99
 
@@ -123,7 +120,7 @@ class Assertion implements Expression {
123
120
  serialized.push(itemType.kind);
124
121
  const N = type.N;
125
122
  if (typeof N === 'number' || this.args.length > 1) {
126
- serialized.push(N);
123
+ serialized.push(N!);
127
124
  }
128
125
  }
129
126
  }
@@ -47,7 +47,7 @@ class At implements Expression {
47
47
  throw new RuntimeError(`Array index must be an integer. Use at-interpolated for fractional indices`);
48
48
  }
49
49
 
50
- return array[index];
50
+ return array[index]!;
51
51
  }
52
52
 
53
53
  eachChild(fn: (_: Expression) => void) {
@@ -45,7 +45,7 @@ class AtInterpolated implements Expression {
45
45
  }
46
46
 
47
47
  if (index === Math.floor(index)) {
48
- return array[index];
48
+ return array[index]!;
49
49
  }
50
50
 
51
51
  // Interpolation logic for non-integer indices
@@ -35,7 +35,7 @@ class Case implements Expression {
35
35
  outputType = context.expectedType;
36
36
  }
37
37
 
38
- const branches = [];
38
+ const branches: Branches = [];
39
39
  for (let i = 1; i < args.length - 1; i += 2) {
40
40
  const test = context.parse(args[i], i, BooleanType);
41
41
  if (!test) return null;
@@ -52,7 +52,6 @@ class Case implements Expression {
52
52
  if (!otherwise) return null;
53
53
 
54
54
  assert(outputType);
55
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
56
55
  return new Case(outputType, branches, otherwise);
57
56
  }
58
57
 
@@ -21,7 +21,7 @@ class Coalesce implements Expression {
21
21
  context.error("Expectected at least one argument.");
22
22
  return null;
23
23
  }
24
- let outputType: Type = null;
24
+ let outputType: Type | null = null;
25
25
  const expectedType = context.expectedType;
26
26
  if (expectedType && expectedType.kind !== 'value') {
27
27
  outputType = expectedType;
@@ -40,8 +40,8 @@ class Coercion implements Expression {
40
40
  if (args.length < 2)
41
41
  return context.error(`Expected at least one argument.`);
42
42
 
43
- const name = args[0] as string;
44
- const parsed = [];
43
+ const name = args[0] as 'to-array' | keyof typeof types;
44
+ const parsed: Expression[] = [];
45
45
  let type: Type | ArrayType = NullType;
46
46
  if (name === 'to-array') {
47
47
  if (!Array.isArray(args[1])) {
@@ -73,7 +73,7 @@ class Coercion implements Expression {
73
73
  if (memberType !== type.itemType.kind) {
74
74
  return context.error(`Expected ${type.itemType.kind} but found ${memberType}.`);
75
75
  }
76
- parsedMember = context.registry['literal'].parse(['literal', member === undefined ? null : member], context);
76
+ parsedMember = context.registry['literal']!.parse(['literal', member === undefined ? null : member], context);
77
77
  }
78
78
  if (!parsedMember) return null;
79
79
  parsed.push(parsedMember);
@@ -84,7 +84,6 @@ class Coercion implements Expression {
84
84
  if ((name === 'to-boolean' || name === 'to-string') && args.length !== 2)
85
85
  return context.error(`Expected one argument.`);
86
86
 
87
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
88
87
  type = types[name];
89
88
 
90
89
  for (let i = 1; i < args.length; i++) {
@@ -94,18 +93,17 @@ class Coercion implements Expression {
94
93
  }
95
94
  }
96
95
 
97
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
98
96
  return new Coercion(type, parsed);
99
97
  }
100
98
 
101
99
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
102
100
  evaluate(ctx: EvaluationContext): any {
103
101
  if (this.type.kind === 'boolean') {
104
- return Boolean(this.args[0].evaluate(ctx));
102
+ return Boolean(this.args[0]!.evaluate(ctx));
105
103
  } else if (this.type.kind === 'color') {
106
104
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
107
105
  let input: any;
108
- let error: string | null;
106
+ let error!: string | null;
109
107
  for (const arg of this.args) {
110
108
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
111
109
  input = arg.evaluate(ctx);
@@ -143,16 +141,16 @@ class Coercion implements Expression {
143
141
  // There is no explicit 'to-formatted' but this coercion can be implicitly
144
142
  // created by properties that expect the 'formatted' type.
145
143
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
146
- return Formatted.fromString(valueToString(this.args[0].evaluate(ctx)));
144
+ return Formatted.fromString(valueToString(this.args[0]!.evaluate(ctx)));
147
145
  } else if (this.type.kind === 'resolvedImage') {
148
146
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
149
- return ResolvedImage.build(valueToString(this.args[0].evaluate(ctx)));
147
+ return ResolvedImage.build(valueToString(this.args[0]!.evaluate(ctx)));
150
148
  } else if (this.type.kind === 'array') {
151
149
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
152
150
  return this.args.map(arg => { return arg.evaluate(ctx); });
153
151
  } else {
154
152
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
155
- return valueToString(this.args[0].evaluate(ctx));
153
+ return valueToString(this.args[0]!.evaluate(ctx));
156
154
  }
157
155
  }
158
156
 
@@ -166,11 +164,11 @@ class Coercion implements Expression {
166
164
 
167
165
  serialize(): SerializedExpression {
168
166
  if (this.type.kind === 'formatted') {
169
- return new FormatExpression([{content: this.args[0], scale: null, font: null, textColor: null}]).serialize();
167
+ return new FormatExpression([{content: this.args[0]!, scale: null, font: null, textColor: null}]).serialize();
170
168
  }
171
169
 
172
170
  if (this.type.kind === 'resolvedImage') {
173
- return new ImageExpression(this.args[0]).serialize();
171
+ return new ImageExpression(this.args[0]!).serialize();
174
172
  }
175
173
 
176
174
  const serialized: Array<unknown> = this.type.kind === 'array' ? [] : [`to-${this.type.kind}`];
@@ -25,25 +25,25 @@ export default class CollatorExpression implements Expression {
25
25
  return null;
26
26
  }
27
27
 
28
- const options = args[1];
28
+ const options = args[1] as Record<string, unknown> | unknown[] | null;
29
29
  if (typeof options !== "object" || Array.isArray(options)) {
30
30
  context.error(`Collator options argument must be an object.`);
31
31
  return null;
32
32
  }
33
33
 
34
- const caseSensitive = options['case-sensitive'] === undefined ?
34
+ const caseSensitive = options!['case-sensitive'] === undefined ?
35
35
  context.parse(false, 1, BooleanType) :
36
- context.parseObjectValue(options['case-sensitive'], 1, 'case-sensitive', BooleanType);
36
+ context.parseObjectValue(options!['case-sensitive'], 1, 'case-sensitive', BooleanType);
37
37
  if (!caseSensitive) return null;
38
38
 
39
- const diacriticSensitive = options['diacritic-sensitive'] === undefined ?
39
+ const diacriticSensitive = options!['diacritic-sensitive'] === undefined ?
40
40
  context.parse(false, 1, BooleanType) :
41
- context.parseObjectValue(options['diacritic-sensitive'], 1, 'diacritic-sensitive', BooleanType);
41
+ context.parseObjectValue(options!['diacritic-sensitive'], 1, 'diacritic-sensitive', BooleanType);
42
42
  if (!diacriticSensitive) return null;
43
43
 
44
- let locale: Expression = null;
45
- if (options['locale']) {
46
- locale = context.parseObjectValue(options['locale'], 1, 'locale', StringType) as Expression;
44
+ let locale: Expression | null = null;
45
+ if (options!['locale']) {
46
+ locale = context.parseObjectValue(options!['locale'], 1, 'locale', StringType) as Expression | null;
47
47
  if (!locale) return null;
48
48
  }
49
49
 
@@ -143,7 +143,6 @@ function makeComparison(
143
143
  if (!collator) return null;
144
144
  }
145
145
 
146
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
147
146
  return new Comparison(lhs, rhs, collator);
148
147
  }
149
148