@mapbox/mapbox-gl-style-spec 13.24.0-alpha.3 → 13.24.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 (93) hide show
  1. package/.eslintrc +10 -0
  2. package/CHANGELOG.md +10 -4
  3. package/bin/gl-style-composite.js +25 -0
  4. package/bin/gl-style-format.js +30 -0
  5. package/bin/gl-style-migrate.js +25 -0
  6. package/bin/{gl-style-validate → gl-style-validate.js} +19 -12
  7. package/build/.gitkeep +0 -0
  8. package/deref.js +8 -7
  9. package/diff.js +11 -6
  10. package/dist/index.cjs +51 -72
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.es.js +51 -72
  13. package/dist/index.es.js.map +1 -1
  14. package/empty.js +9 -28
  15. package/expression/compound_expression.js +2 -2
  16. package/expression/definitions/assertion.js +3 -3
  17. package/expression/definitions/at.js +5 -5
  18. package/expression/definitions/case.js +4 -4
  19. package/expression/definitions/coalesce.js +4 -4
  20. package/expression/definitions/coercion.js +3 -3
  21. package/expression/definitions/collator.js +4 -4
  22. package/expression/definitions/comparison.js +22 -22
  23. package/expression/definitions/format.js +4 -4
  24. package/expression/definitions/image.js +4 -4
  25. package/expression/definitions/in.js +6 -6
  26. package/expression/definitions/index_of.js +5 -5
  27. package/expression/definitions/interpolate.js +6 -5
  28. package/expression/definitions/length.js +5 -5
  29. package/expression/definitions/let.js +5 -5
  30. package/expression/definitions/literal.js +5 -5
  31. package/expression/definitions/match.js +4 -4
  32. package/expression/definitions/number_format.js +4 -4
  33. package/expression/definitions/slice.js +5 -5
  34. package/expression/definitions/step.js +4 -4
  35. package/expression/definitions/var.js +4 -4
  36. package/expression/definitions/within.js +16 -8
  37. package/expression/evaluation_context.js +8 -8
  38. package/expression/expression.js +1 -1
  39. package/expression/index.js +4 -4
  40. package/expression/is_constant.js +3 -3
  41. package/expression/parsing_context.js +1 -1
  42. package/expression/runtime_error.js +1 -1
  43. package/expression/scope.js +1 -1
  44. package/expression/stops.js +1 -1
  45. package/expression/values.js +1 -1
  46. package/feature_filter/index.js +2 -2
  47. package/flow-typed/gl-matrix.js +1 -0
  48. package/function/convert.js +4 -4
  49. package/group_by_layout.js +8 -10
  50. package/migrate/expressions.js +1 -1
  51. package/package.json +9 -7
  52. package/reference/latest.js +4 -0
  53. package/reference/v8.json +1 -4
  54. package/style-spec.js +0 -3
  55. package/test.js +31 -0
  56. package/types.js +1 -1
  57. package/util/color_spaces.js +2 -2
  58. package/util/extend.js +1 -1
  59. package/util/interpolate.js +2 -2
  60. package/util/ref_properties.js +1 -1
  61. package/util/unbundle_jsonlint.js +1 -1
  62. package/validate/validate.js +13 -3
  63. package/validate/validate_array.js +10 -2
  64. package/validate/validate_boolean.js +4 -1
  65. package/validate/validate_color.js +4 -1
  66. package/validate/validate_enum.js +4 -1
  67. package/validate/validate_expression.js +5 -2
  68. package/validate/validate_filter.js +12 -4
  69. package/validate/validate_fog.js +4 -1
  70. package/validate/validate_formatted.js +5 -1
  71. package/validate/validate_function.js +24 -15
  72. package/validate/validate_glyphs_url.js +4 -1
  73. package/validate/validate_image.js +5 -1
  74. package/validate/validate_layer.js +15 -2
  75. package/validate/validate_layout_property.js +5 -1
  76. package/validate/validate_light.js +4 -1
  77. package/validate/validate_number.js +8 -1
  78. package/validate/validate_object.js +12 -2
  79. package/validate/validate_paint_property.js +5 -1
  80. package/validate/validate_projection.js +5 -1
  81. package/validate/validate_property.js +9 -1
  82. package/validate/validate_source.js +4 -1
  83. package/validate/validate_string.js +4 -1
  84. package/validate/validate_terrain.js +5 -2
  85. package/validate_mapbox_api_supported.js +8 -6
  86. package/validate_style.js +14 -9
  87. package/validate_style.min.js +32 -47
  88. package/bin/gl-style-composite +0 -9
  89. package/bin/gl-style-format +0 -22
  90. package/bin/gl-style-migrate +0 -9
  91. package/declass.js +0 -42
  92. package/validate/latest.js +0 -11
  93. package/validate/validate_constants.js +0 -13
package/empty.js CHANGED
@@ -1,29 +1,10 @@
1
- import latest from './reference/latest.js';
2
-
3
- export default function emptyStyle() {
4
- const style = {};
5
-
6
- const version = latest['$version'];
7
- for (const styleKey in latest['$root']) {
8
- const spec = latest['$root'][styleKey];
9
-
10
- if (spec.required) {
11
- let value = null;
12
- if (styleKey === 'version') {
13
- value = version;
14
- } else {
15
- if (spec.type === 'array') {
16
- value = [];
17
- } else {
18
- value = {};
19
- }
20
- }
21
-
22
- if (value != null) {
23
- style[styleKey] = value;
24
- }
25
- }
26
- }
27
-
28
- return style;
1
+ // @flow
2
+ import type {StyleSpecification} from './types.js';
3
+
4
+ export default function emptyStyle(): StyleSpecification {
5
+ return {
6
+ version: 8,
7
+ layers: [],
8
+ sources: {}
9
+ };
29
10
  }
@@ -31,7 +31,7 @@ class CompoundExpression implements Expression {
31
31
  this.args = args;
32
32
  }
33
33
 
34
- evaluate(ctx: EvaluationContext) {
34
+ evaluate(ctx: EvaluationContext): Value {
35
35
  return this._evaluate(ctx, this.args);
36
36
  }
37
37
 
@@ -39,7 +39,7 @@ class CompoundExpression implements Expression {
39
39
  this.args.forEach(fn);
40
40
  }
41
41
 
42
- outputDefined() {
42
+ outputDefined(): boolean {
43
43
  return false;
44
44
  }
45
45
 
@@ -15,7 +15,7 @@ import {
15
15
  import RuntimeError from '../runtime_error.js';
16
16
  import {typeOf} from '../values.js';
17
17
 
18
- import type {Expression} from '../expression.js';
18
+ import type {Expression, SerializedExpression} from '../expression.js';
19
19
  import type ParsingContext from '../parsing_context.js';
20
20
  import type EvaluationContext from '../evaluation_context.js';
21
21
  import type {Type} from '../types.js';
@@ -85,7 +85,7 @@ class Assertion implements Expression {
85
85
  return new Assertion(type, parsed);
86
86
  }
87
87
 
88
- evaluate(ctx: EvaluationContext) {
88
+ evaluate(ctx: EvaluationContext): any | null {
89
89
  for (let i = 0; i < this.args.length; i++) {
90
90
  const value = this.args[i].evaluate(ctx);
91
91
  const error = checkSubtype(this.type, typeOf(value));
@@ -108,7 +108,7 @@ class Assertion implements Expression {
108
108
  return this.args.every(arg => arg.outputDefined());
109
109
  }
110
110
 
111
- serialize(): Array<mixed> {
111
+ serialize(): SerializedExpression {
112
112
  const type = this.type;
113
113
  const serialized = [type.kind];
114
114
  if (type.kind === 'array') {
@@ -4,7 +4,7 @@ import {array, ValueType, NumberType} from '../types.js';
4
4
 
5
5
  import RuntimeError from '../runtime_error.js';
6
6
 
7
- import type {Expression} from '../expression.js';
7
+ import type {Expression, SerializedExpression} from '../expression.js';
8
8
  import type ParsingContext from '../parsing_context.js';
9
9
  import type EvaluationContext from '../evaluation_context.js';
10
10
  import type {Type, ArrayType} from '../types.js';
@@ -21,7 +21,7 @@ class At implements Expression {
21
21
  this.input = input;
22
22
  }
23
23
 
24
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
24
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?At {
25
25
  if (args.length !== 3)
26
26
  return context.error(`Expected 2 arguments, but found ${args.length - 1} instead.`);
27
27
 
@@ -34,7 +34,7 @@ class At implements Expression {
34
34
  return new At(t.itemType, index, input);
35
35
  }
36
36
 
37
- evaluate(ctx: EvaluationContext) {
37
+ evaluate(ctx: EvaluationContext): Value {
38
38
  const index = ((this.index.evaluate(ctx): any): number);
39
39
  const array = ((this.input.evaluate(ctx): any): Array<Value>);
40
40
 
@@ -58,11 +58,11 @@ class At implements Expression {
58
58
  fn(this.input);
59
59
  }
60
60
 
61
- outputDefined() {
61
+ outputDefined(): boolean {
62
62
  return false;
63
63
  }
64
64
 
65
- serialize() {
65
+ serialize(): SerializedExpression {
66
66
  return ["at", this.index.serialize(), this.input.serialize()];
67
67
  }
68
68
  }
@@ -4,7 +4,7 @@ import assert from 'assert';
4
4
 
5
5
  import {BooleanType} from '../types.js';
6
6
 
7
- import type {Expression} from '../expression.js';
7
+ import type {Expression, SerializedExpression} from '../expression.js';
8
8
  import type ParsingContext from '../parsing_context.js';
9
9
  import type EvaluationContext from '../evaluation_context.js';
10
10
  import type {Type} from '../types.js';
@@ -23,7 +23,7 @@ class Case implements Expression {
23
23
  this.otherwise = otherwise;
24
24
  }
25
25
 
26
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
26
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Case {
27
27
  if (args.length < 4)
28
28
  return context.error(`Expected at least 3 arguments, but found only ${args.length - 1}.`);
29
29
  if (args.length % 2 !== 0)
@@ -54,7 +54,7 @@ class Case implements Expression {
54
54
  return new Case((outputType: any), branches, otherwise);
55
55
  }
56
56
 
57
- evaluate(ctx: EvaluationContext) {
57
+ evaluate(ctx: EvaluationContext): any {
58
58
  for (const [test, expression] of this.branches) {
59
59
  if (test.evaluate(ctx)) {
60
60
  return expression.evaluate(ctx);
@@ -75,7 +75,7 @@ class Case implements Expression {
75
75
  return this.branches.every(([_, out]) => out.outputDefined()) && this.otherwise.outputDefined();
76
76
  }
77
77
 
78
- serialize() {
78
+ serialize(): SerializedExpression {
79
79
  const serialized = ["case"];
80
80
  this.eachChild(child => { serialized.push(child.serialize()); });
81
81
  return serialized;
@@ -5,7 +5,7 @@ import assert from 'assert';
5
5
  import {checkSubtype, ValueType} from '../types.js';
6
6
  import ResolvedImage from '../types/resolved_image.js';
7
7
 
8
- import type {Expression} from '../expression.js';
8
+ import type {Expression, SerializedExpression} from '../expression.js';
9
9
  import type ParsingContext from '../parsing_context.js';
10
10
  import type EvaluationContext from '../evaluation_context.js';
11
11
  import type {Type} from '../types.js';
@@ -19,7 +19,7 @@ class Coalesce implements Expression {
19
19
  this.args = args;
20
20
  }
21
21
 
22
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
22
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Coalesce {
23
23
  if (args.length < 2) {
24
24
  return context.error("Expectected at least one argument.");
25
25
  }
@@ -51,7 +51,7 @@ class Coalesce implements Expression {
51
51
  new Coalesce((outputType: any), parsedArgs);
52
52
  }
53
53
 
54
- evaluate(ctx: EvaluationContext) {
54
+ evaluate(ctx: EvaluationContext): any | null {
55
55
  let result = null;
56
56
  let argCount = 0;
57
57
  let firstImage;
@@ -85,7 +85,7 @@ class Coalesce implements Expression {
85
85
  return this.args.every(arg => arg.outputDefined());
86
86
  }
87
87
 
88
- serialize() {
88
+ serialize(): SerializedExpression {
89
89
  const serialized = ["coalesce"];
90
90
  this.eachChild(child => { serialized.push(child.serialize()); });
91
91
  return serialized;
@@ -10,7 +10,7 @@ import FormatExpression from '../definitions/format.js';
10
10
  import ImageExpression from '../definitions/image.js';
11
11
  import ResolvedImage from '../types/resolved_image.js';
12
12
 
13
- import type {Expression} from '../expression.js';
13
+ import type {Expression, SerializedExpression} from '../expression.js';
14
14
  import type ParsingContext from '../parsing_context.js';
15
15
  import type EvaluationContext from '../evaluation_context.js';
16
16
  import type {Type} from '../types.js';
@@ -60,7 +60,7 @@ class Coercion implements Expression {
60
60
  return new Coercion(type, parsed);
61
61
  }
62
62
 
63
- evaluate(ctx: EvaluationContext) {
63
+ evaluate(ctx: EvaluationContext): null | boolean | number | string | Color | Formatted | ResolvedImage {
64
64
  if (this.type.kind === 'boolean') {
65
65
  return Boolean(this.args[0].evaluate(ctx));
66
66
  } else if (this.type.kind === 'color') {
@@ -115,7 +115,7 @@ class Coercion implements Expression {
115
115
  return this.args.every(arg => arg.outputDefined());
116
116
  }
117
117
 
118
- serialize() {
118
+ serialize(): SerializedExpression {
119
119
  if (this.type.kind === 'formatted') {
120
120
  return new FormatExpression([{content: this.args[0], scale: null, font: null, textColor: null}]).serialize();
121
121
  }
@@ -3,7 +3,7 @@
3
3
  import {StringType, BooleanType, CollatorType} from '../types.js';
4
4
  import Collator from '../types/collator.js';
5
5
 
6
- import type {Expression} from '../expression.js';
6
+ import type {Expression, SerializedExpression} from '../expression.js';
7
7
  import type EvaluationContext from '../evaluation_context.js';
8
8
  import type ParsingContext from '../parsing_context.js';
9
9
  import type {Type} from '../types.js';
@@ -46,7 +46,7 @@ export default class CollatorExpression implements Expression {
46
46
  return new CollatorExpression(caseSensitive, diacriticSensitive, locale);
47
47
  }
48
48
 
49
- evaluate(ctx: EvaluationContext) {
49
+ evaluate(ctx: EvaluationContext): Collator {
50
50
  return new Collator(this.caseSensitive.evaluate(ctx), this.diacriticSensitive.evaluate(ctx), this.locale ? this.locale.evaluate(ctx) : null);
51
51
  }
52
52
 
@@ -58,7 +58,7 @@ export default class CollatorExpression implements Expression {
58
58
  }
59
59
  }
60
60
 
61
- outputDefined() {
61
+ outputDefined(): boolean {
62
62
  // Technically the set of possible outputs is the combinatoric set of Collators produced
63
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
@@ -66,7 +66,7 @@ export default class CollatorExpression implements Expression {
66
66
  return false;
67
67
  }
68
68
 
69
- serialize() {
69
+ serialize(): SerializedExpression {
70
70
  const options = {};
71
71
  options['case-sensitive'] = this.caseSensitive.serialize();
72
72
  options['diacritic-sensitive'] = this.diacriticSensitive.serialize();
@@ -5,7 +5,7 @@ import Assertion from './assertion.js';
5
5
  import {typeOf} from '../values.js';
6
6
  import RuntimeError from '../runtime_error.js';
7
7
 
8
- import type {Expression} from '../expression.js';
8
+ import type {Expression, SerializedExpression, ExpressionRegistration} from '../expression.js';
9
9
  import type EvaluationContext from '../evaluation_context.js';
10
10
  import type ParsingContext from '../parsing_context.js';
11
11
  import type {Type} from '../types.js';
@@ -28,19 +28,19 @@ function isComparableType(op: ComparisonOperator, type: Type) {
28
28
  }
29
29
  }
30
30
 
31
- function eq(ctx, a, b) { return a === b; }
32
- function neq(ctx, a, b) { return a !== b; }
33
- function lt(ctx, a, b) { return a < b; }
34
- function gt(ctx, a, b) { return a > b; }
35
- function lteq(ctx, a, b) { return a <= b; }
36
- function gteq(ctx, a, b) { return a >= b; }
31
+ function eq(ctx: EvaluationContext, a: any, b: any): boolean { return a === b; }
32
+ function neq(ctx: EvaluationContext, a: any, b: any): boolean { return a !== b; }
33
+ function lt(ctx: EvaluationContext, a: any, b: any): boolean { return a < b; }
34
+ function gt(ctx: EvaluationContext, a: any, b: any): boolean { return a > b; }
35
+ function lteq(ctx: EvaluationContext, a: any, b: any): boolean { return a <= b; }
36
+ function gteq(ctx: EvaluationContext, a: any, b: any): boolean { return a >= b; }
37
37
 
38
- function eqCollate(ctx, a, b, c) { return c.compare(a, b) === 0; }
39
- function neqCollate(ctx, a, b, c) { return !eqCollate(ctx, a, b, c); }
40
- function ltCollate(ctx, a, b, c) { return c.compare(a, b) < 0; }
41
- function gtCollate(ctx, a, b, c) { return c.compare(a, b) > 0; }
42
- function lteqCollate(ctx, a, b, c) { return c.compare(a, b) <= 0; }
43
- function gteqCollate(ctx, a, b, c) { return c.compare(a, b) >= 0; }
38
+ function eqCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean { return c.compare(a, b) === 0; }
39
+ function neqCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean { return !eqCollate(ctx, a, b, c); }
40
+ function ltCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean { return c.compare(a, b) < 0; }
41
+ function gtCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean { return c.compare(a, b) > 0; }
42
+ function lteqCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean { return c.compare(a, b) <= 0; }
43
+ function gteqCollate(ctx: EvaluationContext, a: any, b: any, c: any): boolean { return c.compare(a, b) >= 0; }
44
44
 
45
45
  /**
46
46
  * Special form for comparison operators, implementing the signatures:
@@ -59,7 +59,7 @@ function gteqCollate(ctx, a, b, c) { return c.compare(a, b) >= 0; }
59
59
  *
60
60
  * @private
61
61
  */
62
- function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollator) {
62
+ function makeComparison(op: ComparisonOperator, compareBasic: (EvaluationContext, any, any) => boolean, compareWithCollator: (EvaluationContext, any, any, any) => boolean): ExpressionRegistration {
63
63
  const isOrderComparison = op !== '==' && op !== '!=';
64
64
 
65
65
  return class Comparison implements Expression {
@@ -130,7 +130,7 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato
130
130
  return new Comparison(lhs, rhs, collator);
131
131
  }
132
132
 
133
- evaluate(ctx: EvaluationContext) {
133
+ evaluate(ctx: EvaluationContext): boolean {
134
134
  const lhs = this.lhs.evaluate(ctx);
135
135
  const rhs = this.rhs.evaluate(ctx);
136
136
 
@@ -168,7 +168,7 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato
168
168
  return true;
169
169
  }
170
170
 
171
- serialize() {
171
+ serialize(): SerializedExpression {
172
172
  const serialized = [op];
173
173
  this.eachChild(child => { serialized.push(child.serialize()); });
174
174
  return serialized;
@@ -176,9 +176,9 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato
176
176
  };
177
177
  }
178
178
 
179
- export const Equals = makeComparison('==', eq, eqCollate);
180
- export const NotEquals = makeComparison('!=', neq, neqCollate);
181
- export const LessThan = makeComparison('<', lt, ltCollate);
182
- export const GreaterThan = makeComparison('>', gt, gtCollate);
183
- export const LessThanOrEqual = makeComparison('<=', lteq, lteqCollate);
184
- export const GreaterThanOrEqual = makeComparison('>=', gteq, gteqCollate);
179
+ export const Equals: $Call<typeof makeComparison, '==', typeof eq, typeof eqCollate> = makeComparison('==', eq, eqCollate);
180
+ export const NotEquals: $Call<typeof makeComparison, '!=', typeof neq, typeof neqCollate> = makeComparison('!=', neq, neqCollate);
181
+ export const LessThan: $Call<typeof makeComparison, '<', typeof lt, typeof ltCollate> = makeComparison('<', lt, ltCollate);
182
+ export const GreaterThan: $Call<typeof makeComparison, '>', typeof gt, typeof gtCollate> = makeComparison('>', gt, gtCollate);
183
+ export const LessThanOrEqual: $Call<typeof makeComparison, '<=', typeof lteq, typeof lteqCollate> = makeComparison('<=', lteq, lteqCollate);
184
+ export const GreaterThanOrEqual: $Call<typeof makeComparison, '>=', typeof gteq, typeof gteqCollate> = makeComparison('>=', gteq, gteqCollate);
@@ -4,7 +4,7 @@ import {NumberType, ValueType, FormattedType, array, StringType, ColorType, Reso
4
4
  import Formatted, {FormattedSection} from '../types/formatted.js';
5
5
  import {toString, typeOf} from '../values.js';
6
6
 
7
- import type {Expression} from '../expression.js';
7
+ import type {Expression, SerializedExpression} from '../expression.js';
8
8
  import type EvaluationContext from '../evaluation_context.js';
9
9
  import type ParsingContext from '../parsing_context.js';
10
10
  import type {Type} from '../types.js';
@@ -83,7 +83,7 @@ export default class FormatExpression implements Expression {
83
83
  return new FormatExpression(sections);
84
84
  }
85
85
 
86
- evaluate(ctx: EvaluationContext) {
86
+ evaluate(ctx: EvaluationContext): Formatted {
87
87
  const evaluateSection = section => {
88
88
  const evaluatedContent = section.content.evaluate(ctx);
89
89
  if (typeOf(evaluatedContent) === ResolvedImageType) {
@@ -117,13 +117,13 @@ export default class FormatExpression implements Expression {
117
117
  }
118
118
  }
119
119
 
120
- outputDefined() {
120
+ outputDefined(): boolean {
121
121
  // Technically the combinatoric set of all children
122
122
  // Usually, this.text will be undefined anyway
123
123
  return false;
124
124
  }
125
125
 
126
- serialize() {
126
+ serialize(): SerializedExpression {
127
127
  const serialized = ["format"];
128
128
  for (const section of this.sections) {
129
129
  serialized.push(section.content.serialize());
@@ -3,7 +3,7 @@
3
3
  import {ResolvedImageType, StringType} from '../types.js';
4
4
  import ResolvedImage from '../types/resolved_image.js';
5
5
 
6
- import type {Expression} from '../expression.js';
6
+ import type {Expression, SerializedExpression} from '../expression.js';
7
7
  import type EvaluationContext from '../evaluation_context.js';
8
8
  import type ParsingContext from '../parsing_context.js';
9
9
  import type {Type} from '../types.js';
@@ -28,7 +28,7 @@ export default class ImageExpression implements Expression {
28
28
  return new ImageExpression(name);
29
29
  }
30
30
 
31
- evaluate(ctx: EvaluationContext) {
31
+ evaluate(ctx: EvaluationContext): null | ResolvedImage {
32
32
  const evaluatedImageName = this.input.evaluate(ctx);
33
33
 
34
34
  const value = ResolvedImage.fromString(evaluatedImageName);
@@ -41,12 +41,12 @@ export default class ImageExpression implements Expression {
41
41
  fn(this.input);
42
42
  }
43
43
 
44
- outputDefined() {
44
+ outputDefined(): boolean {
45
45
  // The output of image is determined by the list of available images in the evaluation context
46
46
  return false;
47
47
  }
48
48
 
49
- serialize() {
49
+ serialize(): SerializedExpression {
50
50
  return ["image", this.input.serialize()];
51
51
  }
52
52
  }
@@ -4,7 +4,7 @@ import {BooleanType, StringType, ValueType, NullType, toString, NumberType, isVa
4
4
  import RuntimeError from '../runtime_error.js';
5
5
  import {typeOf} from '../values.js';
6
6
 
7
- import type {Expression} from '../expression.js';
7
+ import type {Expression, SerializedExpression} from '../expression.js';
8
8
  import type ParsingContext from '../parsing_context.js';
9
9
  import type EvaluationContext from '../evaluation_context.js';
10
10
  import type {Type} from '../types.js';
@@ -20,7 +20,7 @@ class In implements Expression {
20
20
  this.haystack = haystack;
21
21
  }
22
22
 
23
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
23
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?In {
24
24
  if (args.length !== 3) {
25
25
  return context.error(`Expected 2 arguments, but found ${args.length - 1} instead.`);
26
26
  }
@@ -38,11 +38,11 @@ class In implements Expression {
38
38
  return new In(needle, haystack);
39
39
  }
40
40
 
41
- evaluate(ctx: EvaluationContext) {
41
+ evaluate(ctx: EvaluationContext): boolean {
42
42
  const needle = (this.needle.evaluate(ctx): any);
43
43
  const haystack = (this.haystack.evaluate(ctx): any);
44
44
 
45
- if (!haystack) return false;
45
+ if (haystack == null) return false;
46
46
 
47
47
  if (!isValidNativeType(needle, ['boolean', 'string', 'number', 'null'])) {
48
48
  throw new RuntimeError(`Expected first argument to be of type boolean, string, number or null, but found ${toString(typeOf(needle))} instead.`);
@@ -60,11 +60,11 @@ class In implements Expression {
60
60
  fn(this.haystack);
61
61
  }
62
62
 
63
- outputDefined() {
63
+ outputDefined(): boolean {
64
64
  return true;
65
65
  }
66
66
 
67
- serialize() {
67
+ serialize(): SerializedExpression {
68
68
  return ["in", this.needle.serialize(), this.haystack.serialize()];
69
69
  }
70
70
  }
@@ -4,7 +4,7 @@ import {BooleanType, StringType, ValueType, NullType, toString, NumberType, isVa
4
4
  import RuntimeError from '../runtime_error.js';
5
5
  import {typeOf} from '../values.js';
6
6
 
7
- import type {Expression} from '../expression.js';
7
+ import type {Expression, SerializedExpression} from '../expression.js';
8
8
  import type ParsingContext from '../parsing_context.js';
9
9
  import type EvaluationContext from '../evaluation_context.js';
10
10
  import type {Type} from '../types.js';
@@ -22,7 +22,7 @@ class IndexOf implements Expression {
22
22
  this.fromIndex = fromIndex;
23
23
  }
24
24
 
25
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
25
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?IndexOf {
26
26
  if (args.length <= 2 || args.length >= 5) {
27
27
  return context.error(`Expected 3 or 4 arguments, but found ${args.length - 1} instead.`);
28
28
  }
@@ -45,7 +45,7 @@ class IndexOf implements Expression {
45
45
  }
46
46
  }
47
47
 
48
- evaluate(ctx: EvaluationContext) {
48
+ evaluate(ctx: EvaluationContext): any {
49
49
  const needle = (this.needle.evaluate(ctx): any);
50
50
  const haystack = (this.haystack.evaluate(ctx): any);
51
51
 
@@ -73,11 +73,11 @@ class IndexOf implements Expression {
73
73
  }
74
74
  }
75
75
 
76
- outputDefined() {
76
+ outputDefined(): boolean {
77
77
  return false;
78
78
  }
79
79
 
80
- serialize() {
80
+ serialize(): SerializedExpression {
81
81
  if (this.fromIndex != null && this.fromIndex !== undefined) {
82
82
  const fromIndex = this.fromIndex.serialize();
83
83
  return ["index-of", this.needle.serialize(), this.haystack.serialize(), fromIndex];
@@ -6,9 +6,10 @@ import * as interpolate from '../../util/interpolate.js';
6
6
  import {toString, NumberType, ColorType} from '../types.js';
7
7
  import {findStopLessThanOrEqualTo} from '../stops.js';
8
8
  import {hcl, lab} from '../../util/color_spaces.js';
9
+ import Color from '../../util/color.js';
9
10
 
10
11
  import type {Stops} from '../stops.js';
11
- import type {Expression} from '../expression.js';
12
+ import type {Expression, SerializedExpression} from '../expression.js';
12
13
  import type ParsingContext from '../parsing_context.js';
13
14
  import type EvaluationContext from '../evaluation_context.js';
14
15
  import type {Type} from '../types.js';
@@ -41,7 +42,7 @@ class Interpolate implements Expression {
41
42
  }
42
43
  }
43
44
 
44
- static interpolationFactor(interpolation: InterpolationType, input: number, lower: number, upper: number) {
45
+ static interpolationFactor(interpolation: InterpolationType, input: number, lower: number, upper: number): number {
45
46
  let t = 0;
46
47
  if (interpolation.name === 'exponential') {
47
48
  t = exponentialInterpolation(input, interpolation.base, lower, upper);
@@ -55,7 +56,7 @@ class Interpolate implements Expression {
55
56
  return t;
56
57
  }
57
58
 
58
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
59
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Interpolate {
59
60
  let [operator, interpolation, input, ...rest] = args;
60
61
 
61
62
  if (!Array.isArray(interpolation) || interpolation.length === 0) {
@@ -144,7 +145,7 @@ class Interpolate implements Expression {
144
145
  return new Interpolate(outputType, (operator: any), interpolation, input, stops);
145
146
  }
146
147
 
147
- evaluate(ctx: EvaluationContext) {
148
+ evaluate(ctx: EvaluationContext): Color {
148
149
  const labels = this.labels;
149
150
  const outputs = this.outputs;
150
151
 
@@ -190,7 +191,7 @@ class Interpolate implements Expression {
190
191
  return this.outputs.every(out => out.outputDefined());
191
192
  }
192
193
 
193
- serialize(): Array<mixed> {
194
+ serialize(): SerializedExpression {
194
195
  let interpolation;
195
196
  if (this.interpolation.name === 'linear') {
196
197
  interpolation = ["linear"];
@@ -5,7 +5,7 @@ import {NumberType, toString} from '../types.js';
5
5
  import {typeOf} from '../values.js';
6
6
  import RuntimeError from '../runtime_error.js';
7
7
 
8
- import type {Expression} from '../expression.js';
8
+ import type {Expression, SerializedExpression} from '../expression.js';
9
9
  import type ParsingContext from '../parsing_context.js';
10
10
  import type EvaluationContext from '../evaluation_context.js';
11
11
  import type {Type} from '../types.js';
@@ -19,7 +19,7 @@ class Length implements Expression {
19
19
  this.input = input;
20
20
  }
21
21
 
22
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
22
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Length {
23
23
  if (args.length !== 2)
24
24
  return context.error(`Expected 1 argument, but found ${args.length - 1} instead.`);
25
25
 
@@ -32,7 +32,7 @@ class Length implements Expression {
32
32
  return new Length(input);
33
33
  }
34
34
 
35
- evaluate(ctx: EvaluationContext) {
35
+ evaluate(ctx: EvaluationContext): any | number {
36
36
  const input = this.input.evaluate(ctx);
37
37
  if (typeof input === 'string') {
38
38
  return input.length;
@@ -47,11 +47,11 @@ class Length implements Expression {
47
47
  fn(this.input);
48
48
  }
49
49
 
50
- outputDefined() {
50
+ outputDefined(): boolean {
51
51
  return false;
52
52
  }
53
53
 
54
- serialize() {
54
+ serialize(): SerializedExpression {
55
55
  const serialized = ["length"];
56
56
  this.eachChild(child => { serialized.push(child.serialize()); });
57
57
  return serialized;
@@ -1,7 +1,7 @@
1
1
  // @flow
2
2
 
3
3
  import type {Type} from '../types.js';
4
- import type {Expression} from '../expression.js';
4
+ import type {Expression, SerializedExpression} from '../expression.js';
5
5
  import type ParsingContext from '../parsing_context.js';
6
6
  import type EvaluationContext from '../evaluation_context.js';
7
7
 
@@ -16,7 +16,7 @@ class Let implements Expression {
16
16
  this.result = result;
17
17
  }
18
18
 
19
- evaluate(ctx: EvaluationContext) {
19
+ evaluate(ctx: EvaluationContext): any {
20
20
  return this.result.evaluate(ctx);
21
21
  }
22
22
 
@@ -27,7 +27,7 @@ class Let implements Expression {
27
27
  fn(this.result);
28
28
  }
29
29
 
30
- static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
30
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Let {
31
31
  if (args.length < 4)
32
32
  return context.error(`Expected at least 3 arguments, but found ${args.length - 1} instead.`);
33
33
 
@@ -55,11 +55,11 @@ class Let implements Expression {
55
55
  return new Let(bindings, result);
56
56
  }
57
57
 
58
- outputDefined() {
58
+ outputDefined(): boolean {
59
59
  return this.result.outputDefined();
60
60
  }
61
61
 
62
- serialize() {
62
+ serialize(): SerializedExpression {
63
63
  const serialized = ["let"];
64
64
  for (const [name, expr] of this.bindings) {
65
65
  serialized.push(name, expr.serialize());