@mapbox/mapbox-gl-style-spec 13.24.0-alpha.6 → 13.24.0-beta.1

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 (72) hide show
  1. package/.eslintrc +10 -0
  2. package/CHANGELOG.md +10 -4
  3. package/bin/gl-style-composite.js +6 -2
  4. package/bin/gl-style-format.js +6 -2
  5. package/bin/gl-style-migrate.js +6 -2
  6. package/bin/gl-style-validate.js +5 -1
  7. package/dist/index.cjs +41 -23
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.es.js +41 -23
  10. package/dist/index.es.js.map +1 -1
  11. package/expression/compound_expression.js +2 -2
  12. package/expression/definitions/assertion.js +3 -3
  13. package/expression/definitions/at.js +5 -5
  14. package/expression/definitions/case.js +4 -4
  15. package/expression/definitions/coalesce.js +4 -4
  16. package/expression/definitions/coercion.js +3 -3
  17. package/expression/definitions/collator.js +4 -4
  18. package/expression/definitions/comparison.js +22 -22
  19. package/expression/definitions/format.js +4 -4
  20. package/expression/definitions/image.js +4 -4
  21. package/expression/definitions/in.js +5 -5
  22. package/expression/definitions/index_of.js +5 -5
  23. package/expression/definitions/interpolate.js +6 -5
  24. package/expression/definitions/length.js +5 -5
  25. package/expression/definitions/let.js +5 -5
  26. package/expression/definitions/literal.js +5 -5
  27. package/expression/definitions/match.js +4 -4
  28. package/expression/definitions/number_format.js +4 -4
  29. package/expression/definitions/slice.js +5 -5
  30. package/expression/definitions/step.js +4 -4
  31. package/expression/definitions/var.js +4 -4
  32. package/expression/definitions/within.js +16 -8
  33. package/expression/evaluation_context.js +8 -8
  34. package/expression/expression.js +1 -1
  35. package/expression/index.js +4 -4
  36. package/expression/is_constant.js +3 -3
  37. package/expression/parsing_context.js +1 -1
  38. package/expression/runtime_error.js +1 -1
  39. package/expression/scope.js +1 -1
  40. package/expression/stops.js +1 -1
  41. package/expression/values.js +1 -1
  42. package/feature_filter/index.js +1 -1
  43. package/function/convert.js +4 -4
  44. package/migrate/expressions.js +1 -1
  45. package/package.json +1 -1
  46. package/reference/latest.js +4 -0
  47. package/reference/v8.json +1 -4
  48. package/types.js +1 -1
  49. package/validate/validate.js +13 -1
  50. package/validate/validate_array.js +10 -2
  51. package/validate/validate_boolean.js +4 -1
  52. package/validate/validate_color.js +4 -1
  53. package/validate/validate_enum.js +4 -1
  54. package/validate/validate_expression.js +5 -2
  55. package/validate/validate_filter.js +12 -4
  56. package/validate/validate_fog.js +4 -1
  57. package/validate/validate_formatted.js +5 -1
  58. package/validate/validate_function.js +24 -15
  59. package/validate/validate_glyphs_url.js +4 -1
  60. package/validate/validate_image.js +5 -1
  61. package/validate/validate_layer.js +15 -2
  62. package/validate/validate_layout_property.js +5 -1
  63. package/validate/validate_light.js +4 -1
  64. package/validate/validate_number.js +8 -1
  65. package/validate/validate_object.js +12 -2
  66. package/validate/validate_paint_property.js +5 -1
  67. package/validate/validate_projection.js +5 -1
  68. package/validate/validate_property.js +9 -1
  69. package/validate/validate_source.js +4 -1
  70. package/validate/validate_string.js +4 -1
  71. package/validate/validate_terrain.js +5 -2
  72. package/validate_style.min.js +1 -1
@@ -1,9 +1,12 @@
1
+ // @flow
1
2
 
2
3
  import ValidationError from '../error/validation_error.js';
3
4
  import validate from './validate.js';
4
5
  import getType from '../util/get_type.js';
5
6
 
6
- export default function validateFog(options) {
7
+ import type {ValidationOptions} from './validate.js';
8
+
9
+ export default function validateFog(options: ValidationOptions): Array<ValidationError> {
7
10
  const fog = options.value;
8
11
  const style = options.style;
9
12
  const styleSpec = options.styleSpec;
@@ -1,8 +1,12 @@
1
1
  // @flow
2
+
2
3
  import validateExpression from './validate_expression.js';
3
4
  import validateString from './validate_string.js';
4
5
 
5
- export default function validateFormatted(options: any) {
6
+ import type {ValidationOptions} from './validate.js';
7
+ import type ValidationError from '../error/validation_error.js';
8
+
9
+ export default function validateFormatted(options: ValidationOptions): Array<ValidationError> {
6
10
  if (validateString(options).length === 0) {
7
11
  return [];
8
12
  }
@@ -1,3 +1,4 @@
1
+ // @flow
1
2
 
2
3
  import ValidationError from '../error/validation_error.js';
3
4
  import getType from '../util/get_type.js';
@@ -13,11 +14,13 @@ import {
13
14
  supportsInterpolation
14
15
  } from '../util/properties.js';
15
16
 
16
- export default function validateFunction(options) {
17
+ import type {ValidationOptions} from './validate.js';
18
+
19
+ export default function validateFunction(options: ValidationOptions): any {
17
20
  const functionValueSpec = options.valueSpec;
18
21
  const functionType = unbundle(options.value.type);
19
22
  let stopKeyType;
20
- let stopDomainValues = {};
23
+ let stopDomainValues: {[string | number]: boolean} = {};
21
24
  let previousStopDomainValue;
22
25
  let previousStopDomainZoom;
23
26
 
@@ -66,7 +69,7 @@ export default function validateFunction(options) {
66
69
 
67
70
  return errors;
68
71
 
69
- function validateFunctionStops(options) {
72
+ function validateFunctionStops(options: ValidationOptions) {
70
73
  if (functionType === 'identity') {
71
74
  return [new ValidationError(options.key, options.value, 'identity function may not have a "stops" property')];
72
75
  }
@@ -90,7 +93,7 @@ export default function validateFunction(options) {
90
93
  return errors;
91
94
  }
92
95
 
93
- function validateFunctionStop(options) {
96
+ function validateFunctionStop(options: ValidationOptions) {
94
97
  let errors = [];
95
98
  const value = options.value;
96
99
  const key = options.key;
@@ -113,11 +116,17 @@ export default function validateFunction(options) {
113
116
  if (value[0].value === undefined) {
114
117
  return [new ValidationError(key, value, 'object stop key must have value')];
115
118
  }
116
- if (previousStopDomainZoom && previousStopDomainZoom > unbundle(value[0].zoom)) {
119
+
120
+ const nextStopDomainZoom = unbundle(value[0].zoom);
121
+ if (typeof nextStopDomainZoom !== 'number') {
122
+ return [new ValidationError(key, value[0].zoom, 'stop zoom values must be numbers')];
123
+ }
124
+
125
+ if (previousStopDomainZoom && previousStopDomainZoom > nextStopDomainZoom) {
117
126
  return [new ValidationError(key, value[0].zoom, 'stop zoom values must appear in ascending order')];
118
127
  }
119
- if (unbundle(value[0].zoom) !== previousStopDomainZoom) {
120
- previousStopDomainZoom = unbundle(value[0].zoom);
128
+ if (nextStopDomainZoom !== previousStopDomainZoom) {
129
+ previousStopDomainZoom = nextStopDomainZoom;
121
130
  previousStopDomainValue = undefined;
122
131
  stopDomainValues = {};
123
132
  }
@@ -152,7 +161,7 @@ export default function validateFunction(options) {
152
161
  }));
153
162
  }
154
163
 
155
- function validateStopDomainValue(options, stop) {
164
+ function validateStopDomainValue(options: ValidationOptions, stop) {
156
165
  const type = getType(options.value);
157
166
  const value = unbundle(options.value);
158
167
 
@@ -164,7 +173,7 @@ export default function validateFunction(options) {
164
173
  return [new ValidationError(options.key, reportValue, `${type} stop domain type must match previous stop domain type ${stopKeyType}`)];
165
174
  }
166
175
 
167
- if (type !== 'number' && type !== 'string' && type !== 'boolean') {
176
+ if (type !== 'number' && type !== 'string' && type !== 'boolean' && typeof value !== 'number' && typeof value !== 'string' && typeof value !== 'boolean') {
168
177
  return [new ValidationError(options.key, reportValue, 'stop domain value must be a number, string, or boolean')];
169
178
  }
170
179
 
@@ -176,26 +185,26 @@ export default function validateFunction(options) {
176
185
  return [new ValidationError(options.key, reportValue, message)];
177
186
  }
178
187
 
179
- if (functionType === 'categorical' && type === 'number' && (!isFinite(value) || Math.floor(value) !== value)) {
180
- return [new ValidationError(options.key, reportValue, `integer expected, found ${value}`)];
188
+ if (functionType === 'categorical' && type === 'number' && (typeof value !== 'number' || !isFinite(value) || Math.floor(value) !== value)) {
189
+ return [new ValidationError(options.key, reportValue, `integer expected, found ${String(value)}`)];
181
190
  }
182
191
 
183
- if (functionType !== 'categorical' && type === 'number' && previousStopDomainValue !== undefined && value < previousStopDomainValue) {
192
+ if (functionType !== 'categorical' && type === 'number' && typeof value === 'number' && typeof previousStopDomainValue === 'number' && previousStopDomainValue !== undefined && value < previousStopDomainValue) {
184
193
  return [new ValidationError(options.key, reportValue, 'stop domain values must appear in ascending order')];
185
194
  } else {
186
195
  previousStopDomainValue = value;
187
196
  }
188
197
 
189
- if (functionType === 'categorical' && value in stopDomainValues) {
198
+ if (functionType === 'categorical' && (value: any) in stopDomainValues) {
190
199
  return [new ValidationError(options.key, reportValue, 'stop domain values must be unique')];
191
200
  } else {
192
- stopDomainValues[value] = true;
201
+ stopDomainValues[(value: any)] = true;
193
202
  }
194
203
 
195
204
  return [];
196
205
  }
197
206
 
198
- function validateFunctionDefault(options) {
207
+ function validateFunctionDefault(options: ValidationOptions) {
199
208
  return validate({
200
209
  key: options.key,
201
210
  value: options.value,
@@ -1,8 +1,11 @@
1
+ // @flow
1
2
 
2
3
  import ValidationError from '../error/validation_error.js';
3
4
  import validateString from './validate_string.js';
4
5
 
5
- export default function(options) {
6
+ import type {ValidationOptions} from './validate.js';
7
+
8
+ export default function(options: ValidationOptions): Array<ValidationError> {
6
9
  const value = options.value;
7
10
  const key = options.key;
8
11
 
@@ -1,8 +1,12 @@
1
1
  // @flow
2
+
2
3
  import validateExpression from './validate_expression.js';
3
4
  import validateString from './validate_string.js';
4
5
 
5
- export default function validateImage(options: any) {
6
+ import type {ValidationOptions} from './validate.js';
7
+ import type ValidationError from '../error/validation_error.js';
8
+
9
+ export default function validateImage(options: ValidationOptions): Array<ValidationError> {
6
10
  if (validateString(options).length === 0) {
7
11
  return [];
8
12
  }
@@ -1,3 +1,4 @@
1
+ // @flow
1
2
 
2
3
  import ValidationError from '../error/validation_error.js';
3
4
  import {unbundle} from '../util/unbundle_jsonlint.js';
@@ -8,7 +9,15 @@ import validateLayoutProperty from './validate_layout_property.js';
8
9
  import validateSpec from './validate.js';
9
10
  import extend from '../util/extend.js';
10
11
 
11
- export default function validateLayer(options) {
12
+ import type {ValidationOptions} from './validate.js';
13
+ import type {LayerSpecification} from '../types.js';
14
+
15
+ type Options = ValidationOptions & {
16
+ value: LayerSpecification;
17
+ arrayIndex: number;
18
+ }
19
+
20
+ export default function validateLayer(options: Options): Array<ValidationError> {
12
21
  let errors = [];
13
22
 
14
23
  const layer = options.value;
@@ -27,6 +36,7 @@ export default function validateLayer(options) {
27
36
  for (let i = 0; i < options.arrayIndex; i++) {
28
37
  const otherLayer = style.layers[i];
29
38
  if (unbundle(otherLayer.id) === layerId) {
39
+ // $FlowFixMe[prop-missing] - id.__line__ is added dynamically during the readStyle step
30
40
  errors.push(new ValidationError(key, layer.id, `duplicate layer id "${layer.id}", previously used at line ${otherLayer.id.__line__}`));
31
41
  }
32
42
  }
@@ -46,7 +56,8 @@ export default function validateLayer(options) {
46
56
  });
47
57
 
48
58
  if (!parent) {
49
- errors.push(new ValidationError(key, layer.ref, `ref layer "${ref}" not found`));
59
+ if (typeof ref === 'string')
60
+ errors.push(new ValidationError(key, layer.ref, `ref layer "${ref}" not found`));
50
61
  } else if (parent.ref) {
51
62
  errors.push(new ValidationError(key, layer.ref, 'ref cannot reference another ref layer'));
52
63
  } else {
@@ -106,6 +117,7 @@ export default function validateLayer(options) {
106
117
  layer,
107
118
  key: options.key,
108
119
  value: options.value,
120
+ valueSpec: {},
109
121
  style: options.style,
110
122
  styleSpec: options.styleSpec,
111
123
  objectElementValidators: {
@@ -120,6 +132,7 @@ export default function validateLayer(options) {
120
132
  layer,
121
133
  key: options.key,
122
134
  value: options.value,
135
+ valueSpec: {},
123
136
  style: options.style,
124
137
  styleSpec: options.styleSpec,
125
138
  objectElementValidators: {
@@ -1,6 +1,10 @@
1
+ // @flow
1
2
 
2
3
  import validateProperty from './validate_property.js';
3
4
 
4
- export default function validateLayoutProperty(options) {
5
+ import type ValidationError from '../error/validation_error.js';
6
+ import type {PropertyValidationOptions} from './validate_property.js';
7
+
8
+ export default function validateLayoutProperty(options: PropertyValidationOptions): Array<ValidationError> {
5
9
  return validateProperty(options, 'layout');
6
10
  }
@@ -1,9 +1,12 @@
1
+ // @flow
1
2
 
2
3
  import ValidationError from '../error/validation_error.js';
3
4
  import getType from '../util/get_type.js';
4
5
  import validate from './validate.js';
5
6
 
6
- export default function validateLight(options) {
7
+ import type {ValidationOptions} from './validate.js';
8
+
9
+ export default function validateLight(options: ValidationOptions): Array<ValidationError> {
7
10
  const light = options.value;
8
11
  const styleSpec = options.styleSpec;
9
12
  const lightSpec = styleSpec.light;
@@ -1,8 +1,15 @@
1
+ // @flow
1
2
 
2
3
  import getType from '../util/get_type.js';
3
4
  import ValidationError from '../error/validation_error.js';
4
5
 
5
- export default function validateNumber(options) {
6
+ import type {ValidationOptions} from './validate.js';
7
+
8
+ type Options = ValidationOptions & {
9
+ arrayIndex: number;
10
+ }
11
+
12
+ export default function validateNumber(options: Options): Array<ValidationError> {
6
13
  const key = options.key;
7
14
  const value = options.value;
8
15
  const valueSpec = options.valueSpec;
@@ -1,9 +1,16 @@
1
+ // @flow
1
2
 
2
3
  import ValidationError from '../error/validation_error.js';
3
4
  import getType from '../util/get_type.js';
4
5
  import validateSpec from './validate.js';
5
6
 
6
- export default function validateObject(options) {
7
+ import type {ValidationOptions} from './validate.js';
8
+
9
+ type Options = ValidationOptions & {
10
+ objectElementValidators?: Function;
11
+ };
12
+
13
+ export default function validateObject(options: Options): Array<ValidationError> {
7
14
  const key = options.key;
8
15
  const object = options.value;
9
16
  const elementSpecs = options.valueSpec || {};
@@ -30,7 +37,9 @@ export default function validateObject(options) {
30
37
  validateElement = elementValidators['*'];
31
38
  } else if (elementSpecs['*']) {
32
39
  validateElement = validateSpec;
33
- } else {
40
+ }
41
+
42
+ if (!validateElement) {
34
43
  errors.push(new ValidationError(key, object[objectKey], `unknown property "${objectKey}"`));
35
44
  continue;
36
45
  }
@@ -43,6 +52,7 @@ export default function validateObject(options) {
43
52
  styleSpec,
44
53
  object,
45
54
  objectKey
55
+ // $FlowFixMe[extra-arg]
46
56
  }, object));
47
57
  }
48
58
 
@@ -1,6 +1,10 @@
1
+ // @flow
1
2
 
2
3
  import validateProperty from './validate_property.js';
3
4
 
4
- export default function validatePaintProperty(options) {
5
+ import type ValidationError from '../error/validation_error.js';
6
+ import type {PropertyValidationOptions} from './validate_property.js';
7
+
8
+ export default function validatePaintProperty(options: PropertyValidationOptions): Array<ValidationError> {
5
9
  return validateProperty(options, 'paint');
6
10
  }
@@ -1,8 +1,12 @@
1
+ // @flow
2
+
1
3
  import ValidationError from '../error/validation_error.js';
2
4
  import getType from '../util/get_type.js';
3
5
  import validate from './validate.js';
4
6
 
5
- export default function validateProjection(options) {
7
+ import type {ValidationOptions} from './validate.js';
8
+
9
+ export default function validateProjection(options: ValidationOptions): Array<ValidationError> {
6
10
  const projection = options.value;
7
11
  const styleSpec = options.styleSpec;
8
12
  const projectionSpec = styleSpec.projection;
@@ -1,3 +1,4 @@
1
+ // @flow
1
2
 
2
3
  import validate from './validate.js';
3
4
  import ValidationError from '../error/validation_error.js';
@@ -6,7 +7,14 @@ import {isFunction} from '../function/index.js';
6
7
  import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint.js';
7
8
  import {supportsPropertyExpression} from '../util/properties.js';
8
9
 
9
- export default function validateProperty(options, propertyType) {
10
+ import type {ValidationOptions} from './validate.js';
11
+
12
+ export type PropertyValidationOptions = ValidationOptions & {
13
+ objectKey: string;
14
+ layerType: string;
15
+ }
16
+
17
+ export default function validateProperty(options: PropertyValidationOptions, propertyType: string): Array<ValidationError> {
10
18
  const key = options.key;
11
19
  const style = options.style;
12
20
  const styleSpec = options.styleSpec;
@@ -1,3 +1,4 @@
1
+ // @flow
1
2
 
2
3
  import ValidationError from '../error/validation_error.js';
3
4
  import {unbundle} from '../util/unbundle_jsonlint.js';
@@ -7,11 +8,13 @@ import validateExpression from './validate_expression.js';
7
8
  import validateString from './validate_string.js';
8
9
  import getType from '../util/get_type.js';
9
10
 
11
+ import type {ValidationOptions} from './validate.js';
12
+
10
13
  const objectElementValidators = {
11
14
  promoteId: validatePromoteId
12
15
  };
13
16
 
14
- export default function validateSource(options) {
17
+ export default function validateSource(options: ValidationOptions): Array<ValidationError> {
15
18
  const value = options.value;
16
19
  const key = options.key;
17
20
  const styleSpec = options.styleSpec;
@@ -1,8 +1,11 @@
1
+ // @flow
1
2
 
2
3
  import getType from '../util/get_type.js';
3
4
  import ValidationError from '../error/validation_error.js';
4
5
 
5
- export default function validateString(options) {
6
+ import type {ValidationOptions} from './validate.js';
7
+
8
+ export default function validateString(options: $Shape<ValidationOptions>): Array<ValidationError> {
6
9
  const value = options.value;
7
10
  const key = options.key;
8
11
  const type = getType(value);
@@ -1,10 +1,13 @@
1
+ // @flow
1
2
 
2
3
  import ValidationError from '../error/validation_error.js';
3
4
  import validate from './validate.js';
4
5
  import getType from '../util/get_type.js';
5
6
  import {unbundle} from '../util/unbundle_jsonlint.js';
6
7
 
7
- export default function validateTerrain(options) {
8
+ import type {ValidationOptions} from './validate.js';
9
+
10
+ export default function validateTerrain(options: ValidationOptions): Array<ValidationError> {
8
11
  const terrain = options.value;
9
12
  const key = options.key;
10
13
  const style = options.style;
@@ -52,7 +55,7 @@ export default function validateTerrain(options) {
52
55
  if (!source) {
53
56
  errors.push(new ValidationError(key, terrain.source, `source "${terrain.source}" not found`));
54
57
  } else if (sourceType !== 'raster-dem') {
55
- errors.push(new ValidationError(key, terrain.source, `terrain cannot be used with a source of type ${sourceType}, it only be used with a "raster-dem" source type`));
58
+ errors.push(new ValidationError(key, terrain.source, `terrain cannot be used with a source of type ${String(sourceType)}, it only be used with a "raster-dem" source type`));
56
59
  }
57
60
  }
58
61
 
@@ -63,5 +63,5 @@ export const validatePaintProperty: Validator = opts => sortErrors(_validatePain
63
63
  export const validateLayoutProperty: Validator = opts => sortErrors(_validateLayoutProperty(opts));
64
64
 
65
65
  function sortErrors(errors) {
66
- return errors.slice().sort((a, b) => a.line - b.line);
66
+ return errors.slice().sort((a, b) => a.line && b.line ? a.line - b.line : 0);
67
67
  }