@mapbox/mapbox-gl-style-spec 13.12.0 → 13.13.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 (43) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/index.es.js +1201 -297
  3. package/dist/index.es.js.map +1 -1
  4. package/dist/index.js +1201 -297
  5. package/dist/index.js.map +1 -1
  6. package/expression/compound_expression.js +5 -5
  7. package/expression/definitions/assertion.js +3 -4
  8. package/expression/definitions/at.js +3 -3
  9. package/expression/definitions/case.js +3 -6
  10. package/expression/definitions/coalesce.js +3 -4
  11. package/expression/definitions/coercion.js +3 -4
  12. package/expression/definitions/collator.js +5 -5
  13. package/expression/definitions/comparison.js +3 -3
  14. package/expression/definitions/format.js +3 -3
  15. package/expression/definitions/format_section_override.js +3 -4
  16. package/expression/definitions/image.js +6 -8
  17. package/expression/definitions/in.js +4 -4
  18. package/expression/definitions/index.js +4 -2
  19. package/expression/definitions/interpolate.js +3 -4
  20. package/expression/definitions/length.js +3 -3
  21. package/expression/definitions/let.js +3 -3
  22. package/expression/definitions/literal.js +2 -2
  23. package/expression/definitions/match.js +3 -6
  24. package/expression/definitions/number_format.js +3 -3
  25. package/expression/definitions/step.js +3 -4
  26. package/expression/definitions/var.js +2 -2
  27. package/expression/definitions/within.js +297 -0
  28. package/expression/evaluation_context.js +12 -1
  29. package/expression/expression.js +3 -5
  30. package/expression/index.js +24 -19
  31. package/expression/is_constant.js +5 -1
  32. package/expression/parsing_context.js +3 -0
  33. package/expression/scope.js +1 -1
  34. package/expression/types/resolved_image.js +2 -1
  35. package/feature_filter/convert.js +1 -1
  36. package/feature_filter/index.js +10 -5
  37. package/flow-typed/vector-tile.js +2 -2
  38. package/package.json +2 -1
  39. package/reference/v8.json +10 -1
  40. package/style-spec.js +1 -1
  41. package/types.js +2 -2
  42. package/validate/validate_expression.js +1 -1
  43. package/visit.js +2 -2
@@ -22,7 +22,7 @@ class CompoundExpression implements Expression {
22
22
  _evaluate: Evaluate;
23
23
  args: Array<Expression>;
24
24
 
25
- static definitions: { [string]: Definition };
25
+ static definitions: {[_: string]: Definition };
26
26
 
27
27
  constructor(name: string, type: Type, evaluate: Evaluate, args: Array<Expression>) {
28
28
  this.name = name;
@@ -35,12 +35,12 @@ class CompoundExpression implements Expression {
35
35
  return this._evaluate(ctx, this.args);
36
36
  }
37
37
 
38
- eachChild(fn: (Expression) => void) {
38
+ eachChild(fn: (_: Expression) => void) {
39
39
  this.args.forEach(fn);
40
40
  }
41
41
 
42
- possibleOutputs() {
43
- return [undefined];
42
+ outputDefined() {
43
+ return false;
44
44
  }
45
45
 
46
46
  serialize(): Array<mixed> {
@@ -141,7 +141,7 @@ class CompoundExpression implements Expression {
141
141
 
142
142
  static register(
143
143
  registry: ExpressionRegistry,
144
- definitions: { [string]: Definition }
144
+ definitions: {[_: string]: Definition }
145
145
  ) {
146
146
  assert(!CompoundExpression.definitions);
147
147
  CompoundExpression.definitions = definitions;
@@ -18,7 +18,6 @@ import {typeOf} from '../values';
18
18
  import type {Expression} from '../expression';
19
19
  import type ParsingContext from '../parsing_context';
20
20
  import type EvaluationContext from '../evaluation_context';
21
- import type {Value} from '../values';
22
21
  import type {Type} from '../types';
23
22
 
24
23
  const types = {
@@ -101,12 +100,12 @@ class Assertion implements Expression {
101
100
  return null;
102
101
  }
103
102
 
104
- eachChild(fn: (Expression) => void) {
103
+ eachChild(fn: (_: Expression) => void) {
105
104
  this.args.forEach(fn);
106
105
  }
107
106
 
108
- possibleOutputs(): Array<Value | void> {
109
- return [].concat(...this.args.map((arg) => arg.possibleOutputs()));
107
+ outputDefined(): boolean {
108
+ return this.args.every(arg => arg.outputDefined());
110
109
  }
111
110
 
112
111
  serialize(): Array<mixed> {
@@ -53,13 +53,13 @@ class At implements Expression {
53
53
  return array[index];
54
54
  }
55
55
 
56
- eachChild(fn: (Expression) => void) {
56
+ eachChild(fn: (_: Expression) => void) {
57
57
  fn(this.index);
58
58
  fn(this.input);
59
59
  }
60
60
 
61
- possibleOutputs() {
62
- return [undefined];
61
+ outputDefined() {
62
+ return false;
63
63
  }
64
64
 
65
65
  serialize() {
@@ -7,7 +7,6 @@ import {BooleanType} from '../types';
7
7
  import type {Expression} from '../expression';
8
8
  import type ParsingContext from '../parsing_context';
9
9
  import type EvaluationContext from '../evaluation_context';
10
- import type {Value} from '../values';
11
10
  import type {Type} from '../types';
12
11
 
13
12
  type Branches = Array<[Expression, Expression]>;
@@ -64,7 +63,7 @@ class Case implements Expression {
64
63
  return this.otherwise.evaluate(ctx);
65
64
  }
66
65
 
67
- eachChild(fn: (Expression) => void) {
66
+ eachChild(fn: (_: Expression) => void) {
68
67
  for (const [test, expression] of this.branches) {
69
68
  fn(test);
70
69
  fn(expression);
@@ -72,10 +71,8 @@ class Case implements Expression {
72
71
  fn(this.otherwise);
73
72
  }
74
73
 
75
- possibleOutputs(): Array<Value | void> {
76
- return []
77
- .concat(...this.branches.map(([_, out]) => out.possibleOutputs()))
78
- .concat(this.otherwise.possibleOutputs());
74
+ outputDefined(): boolean {
75
+ return this.branches.every(([_, out]) => out.outputDefined()) && this.otherwise.outputDefined();
79
76
  }
80
77
 
81
78
  serialize() {
@@ -8,7 +8,6 @@ import ResolvedImage from '../types/resolved_image';
8
8
  import type {Expression} from '../expression';
9
9
  import type ParsingContext from '../parsing_context';
10
10
  import type EvaluationContext from '../evaluation_context';
11
- import type {Value} from '../values';
12
11
  import type {Type} from '../types';
13
12
 
14
13
  class Coalesce implements Expression {
@@ -76,12 +75,12 @@ class Coalesce implements Expression {
76
75
  return result;
77
76
  }
78
77
 
79
- eachChild(fn: (Expression) => void) {
78
+ eachChild(fn: (_: Expression) => void) {
80
79
  this.args.forEach(fn);
81
80
  }
82
81
 
83
- possibleOutputs(): Array<Value | void> {
84
- return [].concat(...this.args.map((arg) => arg.possibleOutputs()));
82
+ outputDefined(): boolean {
83
+ return this.args.every(arg => arg.outputDefined());
85
84
  }
86
85
 
87
86
  serialize() {
@@ -13,7 +13,6 @@ import ResolvedImage from '../types/resolved_image';
13
13
  import type {Expression} from '../expression';
14
14
  import type ParsingContext from '../parsing_context';
15
15
  import type EvaluationContext from '../evaluation_context';
16
- import type {Value} from '../values';
17
16
  import type {Type} from '../types';
18
17
 
19
18
  const types = {
@@ -108,12 +107,12 @@ class Coercion implements Expression {
108
107
  }
109
108
  }
110
109
 
111
- eachChild(fn: (Expression) => void) {
110
+ eachChild(fn: (_: Expression) => void) {
112
111
  this.args.forEach(fn);
113
112
  }
114
113
 
115
- possibleOutputs(): Array<Value | void> {
116
- return [].concat(...this.args.map((arg) => arg.possibleOutputs()));
114
+ outputDefined(): boolean {
115
+ return this.args.every(arg => arg.outputDefined());
117
116
  }
118
117
 
119
118
  serialize() {
@@ -50,7 +50,7 @@ export default class CollatorExpression implements Expression {
50
50
  return new Collator(this.caseSensitive.evaluate(ctx), this.diacriticSensitive.evaluate(ctx), this.locale ? this.locale.evaluate(ctx) : null);
51
51
  }
52
52
 
53
- eachChild(fn: (Expression) => void) {
53
+ eachChild(fn: (_: Expression) => void) {
54
54
  fn(this.caseSensitive);
55
55
  fn(this.diacriticSensitive);
56
56
  if (this.locale) {
@@ -58,12 +58,12 @@ export default class CollatorExpression implements Expression {
58
58
  }
59
59
  }
60
60
 
61
- possibleOutputs() {
61
+ outputDefined() {
62
62
  // Technically the set of possible outputs is the combinatoric set of Collators produced
63
- // by all possibleOutputs of locale/caseSensitive/diacriticSensitive
63
+ // by all possible outputs of locale/caseSensitive/diacriticSensitive
64
64
  // But for the primary use of Collators in comparison operators, we ignore the Collator's
65
- // possibleOutputs anyway, so we can get away with leaving this undefined for now.
66
- return [undefined];
65
+ // possible outputs anyway, so we can get away with leaving this false for now.
66
+ return false;
67
67
  }
68
68
 
69
69
  serialize() {
@@ -156,7 +156,7 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato
156
156
  compareBasic(ctx, lhs, rhs);
157
157
  }
158
158
 
159
- eachChild(fn: (Expression) => void) {
159
+ eachChild(fn: (_: Expression) => void) {
160
160
  fn(this.lhs);
161
161
  fn(this.rhs);
162
162
  if (this.collator) {
@@ -164,8 +164,8 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato
164
164
  }
165
165
  }
166
166
 
167
- possibleOutputs() {
168
- return [true, false];
167
+ outputDefined(): boolean {
168
+ return true;
169
169
  }
170
170
 
171
171
  serialize() {
@@ -102,7 +102,7 @@ export default class FormatExpression implements Expression {
102
102
  return new Formatted(this.sections.map(evaluateSection));
103
103
  }
104
104
 
105
- eachChild(fn: (Expression) => void) {
105
+ eachChild(fn: (_: Expression) => void) {
106
106
  for (const section of this.sections) {
107
107
  fn(section.content);
108
108
  if (section.scale) {
@@ -117,10 +117,10 @@ export default class FormatExpression implements Expression {
117
117
  }
118
118
  }
119
119
 
120
- possibleOutputs() {
120
+ outputDefined() {
121
121
  // Technically the combinatoric set of all children
122
122
  // Usually, this.text will be undefined anyway
123
- return [undefined];
123
+ return false;
124
124
  }
125
125
 
126
126
  serialize() {
@@ -3,7 +3,6 @@
3
3
  import assert from 'assert';
4
4
  import type {Expression} from '../expression';
5
5
  import type EvaluationContext from '../evaluation_context';
6
- import type {Value} from '../values';
7
6
  import type {Type} from '../types';
8
7
  import type {ZoomConstantExpression} from '../../expression';
9
8
  import {NullType} from '../types';
@@ -35,7 +34,7 @@ export default class FormatSectionOverride<T> implements Expression {
35
34
  return this.defaultValue.property.specification.default;
36
35
  }
37
36
 
38
- eachChild(fn: (Expression) => void) {
37
+ eachChild(fn: (_: Expression) => void) {
39
38
  if (!this.defaultValue.isConstant()) {
40
39
  const expr: ZoomConstantExpression<'source'> = ((this.defaultValue.value): any);
41
40
  fn(expr._styleExpression.expression);
@@ -43,8 +42,8 @@ export default class FormatSectionOverride<T> implements Expression {
43
42
  }
44
43
 
45
44
  // Cannot be statically evaluated, as the output depends on the evaluation context.
46
- possibleOutputs(): Array<Value | void> {
47
- return [undefined];
45
+ outputDefined() {
46
+ return false;
48
47
  }
49
48
 
50
49
  serialize() {
@@ -30,22 +30,20 @@ export default class ImageExpression implements Expression {
30
30
 
31
31
  evaluate(ctx: EvaluationContext) {
32
32
  const evaluatedImageName = this.input.evaluate(ctx);
33
- let available = false;
34
33
 
35
- if (ctx.availableImages && ctx.availableImages.indexOf(evaluatedImageName) > -1) {
36
- available = true;
37
- }
34
+ const value = ResolvedImage.fromString(evaluatedImageName);
35
+ if (value && ctx.availableImages) value.available = ctx.availableImages.indexOf(evaluatedImageName) > -1;
38
36
 
39
- return new ResolvedImage({name: evaluatedImageName, available});
37
+ return value;
40
38
  }
41
39
 
42
- eachChild(fn: (Expression) => void) {
40
+ eachChild(fn: (_: Expression) => void) {
43
41
  fn(this.input);
44
42
  }
45
43
 
46
- possibleOutputs() {
44
+ outputDefined() {
47
45
  // The output of image is determined by the list of available images in the evaluation context
48
- return [undefined];
46
+ return false;
49
47
  }
50
48
 
51
49
  serialize() {
@@ -62,7 +62,7 @@ class In implements Expression {
62
62
  const needle = (this.needle.evaluate(ctx): any);
63
63
  const haystack = (this.haystack.evaluate(ctx): any);
64
64
 
65
- if (!needle || !haystack) return false;
65
+ if (needle == null || !haystack) return false;
66
66
 
67
67
  if (!isComparableRuntimeValue(needle)) {
68
68
  throw new RuntimeError(`Expected first argument to be of type boolean, string or number, but found ${toString(typeOf(needle))} instead.`);
@@ -75,13 +75,13 @@ class In implements Expression {
75
75
  return haystack.indexOf(needle) >= 0;
76
76
  }
77
77
 
78
- eachChild(fn: (Expression) => void) {
78
+ eachChild(fn: (_: Expression) => void) {
79
79
  fn(this.needle);
80
80
  fn(this.haystack);
81
81
  }
82
82
 
83
- possibleOutputs() {
84
- return [true, false];
83
+ outputDefined() {
84
+ return true;
85
85
  }
86
86
 
87
87
  serialize() {
@@ -42,6 +42,7 @@ import NumberFormat from './number_format';
42
42
  import FormatExpression from './format';
43
43
  import ImageExpression from './image';
44
44
  import Length from './length';
45
+ import Within from './within';
45
46
 
46
47
  import type {Varargs} from '../compound_expression';
47
48
  import type {ExpressionRegistry} from '../expression';
@@ -79,7 +80,8 @@ const expressions: ExpressionRegistry = {
79
80
  'to-color': Coercion,
80
81
  'to-number': Coercion,
81
82
  'to-string': Coercion,
82
- 'var': Var
83
+ 'var': Var,
84
+ 'within': Within
83
85
  };
84
86
 
85
87
  function rgba(ctx, [r, g, b, a]) {
@@ -455,7 +457,7 @@ CompoundExpression.register(expressions, {
455
457
  'filter-has-id': [
456
458
  BooleanType,
457
459
  [],
458
- (ctx) => ctx.id() !== null
460
+ (ctx) => (ctx.id() !== null && ctx.id() !== undefined)
459
461
  ],
460
462
  'filter-type-in': [
461
463
  BooleanType,
@@ -11,7 +11,6 @@ import type {Stops} from '../stops';
11
11
  import type {Expression} from '../expression';
12
12
  import type ParsingContext from '../parsing_context';
13
13
  import type EvaluationContext from '../evaluation_context';
14
- import type {Value} from '../values';
15
14
  import type {Type} from '../types';
16
15
 
17
16
  export type InterpolationType =
@@ -180,15 +179,15 @@ class Interpolate implements Expression {
180
179
  }
181
180
  }
182
181
 
183
- eachChild(fn: (Expression) => void) {
182
+ eachChild(fn: (_: Expression) => void) {
184
183
  fn(this.input);
185
184
  for (const expression of this.outputs) {
186
185
  fn(expression);
187
186
  }
188
187
  }
189
188
 
190
- possibleOutputs(): Array<Value | void> {
191
- return [].concat(...this.outputs.map((output) => output.possibleOutputs()));
189
+ outputDefined(): boolean {
190
+ return this.outputs.every(out => out.outputDefined());
192
191
  }
193
192
 
194
193
  serialize(): Array<mixed> {
@@ -43,12 +43,12 @@ class Length implements Expression {
43
43
  }
44
44
  }
45
45
 
46
- eachChild(fn: (Expression) => void) {
46
+ eachChild(fn: (_: Expression) => void) {
47
47
  fn(this.input);
48
48
  }
49
49
 
50
- possibleOutputs() {
51
- return [undefined];
50
+ outputDefined() {
51
+ return false;
52
52
  }
53
53
 
54
54
  serialize() {
@@ -20,7 +20,7 @@ class Let implements Expression {
20
20
  return this.result.evaluate(ctx);
21
21
  }
22
22
 
23
- eachChild(fn: (Expression) => void) {
23
+ eachChild(fn: (_: Expression) => void) {
24
24
  for (const binding of this.bindings) {
25
25
  fn(binding[1]);
26
26
  }
@@ -55,8 +55,8 @@ class Let implements Expression {
55
55
  return new Let(bindings, result);
56
56
  }
57
57
 
58
- possibleOutputs() {
59
- return this.result.possibleOutputs();
58
+ outputDefined() {
59
+ return this.result.outputDefined();
60
60
  }
61
61
 
62
62
  serialize() {
@@ -49,8 +49,8 @@ class Literal implements Expression {
49
49
 
50
50
  eachChild() {}
51
51
 
52
- possibleOutputs() {
53
- return [this.value];
52
+ outputDefined() {
53
+ return true;
54
54
  }
55
55
 
56
56
  serialize(): Array<mixed> {
@@ -8,7 +8,6 @@ import {ValueType, type Type} from '../types';
8
8
  import type {Expression} from '../expression';
9
9
  import type ParsingContext from '../parsing_context';
10
10
  import type EvaluationContext from '../evaluation_context';
11
- import type {Value} from '../values';
12
11
 
13
12
  // Map input label values to output expression index
14
13
  type Cases = {[number | string]: number};
@@ -106,16 +105,14 @@ class Match implements Expression {
106
105
  return output.evaluate(ctx);
107
106
  }
108
107
 
109
- eachChild(fn: (Expression) => void) {
108
+ eachChild(fn: (_: Expression) => void) {
110
109
  fn(this.input);
111
110
  this.outputs.forEach(fn);
112
111
  fn(this.otherwise);
113
112
  }
114
113
 
115
- possibleOutputs(): Array<Value | void> {
116
- return []
117
- .concat(...this.outputs.map((out) => out.possibleOutputs()))
118
- .concat(this.otherwise.possibleOutputs());
114
+ outputDefined(): boolean {
115
+ return this.outputs.every(out => out.outputDefined()) && this.otherwise.outputDefined();
119
116
  }
120
117
 
121
118
  serialize(): Array<mixed> {
@@ -103,7 +103,7 @@ export default class NumberFormat implements Expression {
103
103
  }).format(this.number.evaluate(ctx));
104
104
  }
105
105
 
106
- eachChild(fn: (Expression) => void) {
106
+ eachChild(fn: (_: Expression) => void) {
107
107
  fn(this.number);
108
108
  if (this.locale) {
109
109
  fn(this.locale);
@@ -119,8 +119,8 @@ export default class NumberFormat implements Expression {
119
119
  }
120
120
  }
121
121
 
122
- possibleOutputs() {
123
- return [undefined];
122
+ outputDefined() {
123
+ return false;
124
124
  }
125
125
 
126
126
  serialize() {
@@ -8,7 +8,6 @@ import type {Stops} from '../stops';
8
8
  import type {Expression} from '../expression';
9
9
  import type ParsingContext from '../parsing_context';
10
10
  import type EvaluationContext from '../evaluation_context';
11
- import type {Value} from '../values';
12
11
  import type {Type} from '../types';
13
12
 
14
13
  class Step implements Expression {
@@ -95,15 +94,15 @@ class Step implements Expression {
95
94
  return outputs[index].evaluate(ctx);
96
95
  }
97
96
 
98
- eachChild(fn: (Expression) => void) {
97
+ eachChild(fn: (_: Expression) => void) {
99
98
  fn(this.input);
100
99
  for (const expression of this.outputs) {
101
100
  fn(expression);
102
101
  }
103
102
  }
104
103
 
105
- possibleOutputs(): Array<Value | void> {
106
- return [].concat(...this.outputs.map((output) => output.possibleOutputs()));
104
+ outputDefined(): boolean {
105
+ return this.outputs.every(out => out.outputDefined());
107
106
  }
108
107
 
109
108
  serialize() {
@@ -34,8 +34,8 @@ class Var implements Expression {
34
34
 
35
35
  eachChild() {}
36
36
 
37
- possibleOutputs() {
38
- return [undefined];
37
+ outputDefined() {
38
+ return false;
39
39
  }
40
40
 
41
41
  serialize() {