@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.
- package/bin/gl-style-composite.js +0 -5
- package/bin/gl-style-format.js +0 -5
- package/bin/gl-style-migrate.js +0 -5
- package/bin/gl-style-validate.js +0 -5
- package/{composite.js → composite.ts} +1 -1
- package/data/{extent.js → extent.ts} +0 -2
- package/{deref.js → deref.ts} +7 -9
- package/{diff.js → diff.ts} +44 -21
- package/dist/index.cjs +794 -1226
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1746 -0
- package/dist/index.es.js +794 -1226
- package/dist/index.es.js.map +1 -1
- package/{empty.js → empty.ts} +1 -2
- package/error/{parsing_error.js → parsing_error.ts} +0 -2
- package/error/{validation_error.js → validation_error.ts} +5 -5
- package/expression/{compound_expression.js → compound_expression.ts} +29 -19
- package/expression/definitions/{assertion.js → assertion.ts} +16 -13
- package/expression/definitions/{at.js → at.ts} +12 -13
- package/expression/definitions/{case.js → case.ts} +12 -11
- package/expression/definitions/{coalesce.js → coalesce.ts} +11 -11
- package/expression/definitions/{coercion.js → coercion.ts} +21 -20
- package/expression/definitions/{collator.js → collator.ts} +11 -11
- package/expression/definitions/{comparison.js → comparison.ts} +30 -24
- package/expression/definitions/{config.js → config.ts} +16 -16
- package/expression/definitions/{distance.js → distance.ts} +60 -52
- package/expression/definitions/{format.js → format.ts} +26 -15
- package/expression/definitions/{image.js → image.ts} +12 -12
- package/expression/definitions/{in.js → in.ts} +22 -13
- package/expression/definitions/{index.js → index.ts} +70 -83
- package/expression/definitions/{index_of.js → index_of.ts} +24 -15
- package/expression/definitions/{interpolate.js → interpolate.ts} +44 -25
- package/expression/definitions/{length.js → length.ts} +11 -10
- package/expression/definitions/{let.js → let.ts} +10 -7
- package/expression/definitions/{literal.js → literal.ts} +11 -12
- package/expression/definitions/{match.js → match.ts} +25 -15
- package/expression/definitions/{number_format.js → number_format.ts} +10 -10
- package/expression/definitions/{slice.js → slice.ts} +23 -15
- package/expression/definitions/{step.js → step.ts} +14 -12
- package/expression/definitions/{var.js → var.ts} +5 -7
- package/expression/definitions/{within.js → within.ts} +41 -29
- package/expression/{evaluation_context.js → evaluation_context.ts} +26 -23
- package/expression/expression.ts +29 -0
- package/expression/{index.js → index.ts} +208 -110
- package/expression/{is_constant.js → is_constant.ts} +5 -7
- package/expression/{parsing_context.js → parsing_context.ts} +47 -34
- package/expression/{parsing_error.js → parsing_error.ts} +0 -2
- package/expression/{runtime_error.js → runtime_error.ts} +0 -2
- package/expression/{scope.js → scope.ts} +5 -5
- package/expression/{stops.js → stops.ts} +2 -4
- package/expression/types/{collator.js → collator.ts} +1 -3
- package/expression/types/{formatted.js → formatted.ts} +8 -7
- package/expression/types/{resolved_image.js → resolved_image.ts} +5 -7
- package/expression/{types.js → types.ts} +53 -45
- package/expression/{values.js → values.ts} +12 -12
- package/feature_filter/{convert.js → convert.ts} +19 -18
- package/feature_filter/{index.js → index.ts} +39 -21
- package/{format.js → format.ts} +3 -3
- package/function/{convert.js → convert.ts} +44 -44
- package/function/{index.js → index.ts} +12 -12
- package/{group_by_layout.js → group_by_layout.ts} +11 -8
- package/migrate/{expressions.js → expressions.ts} +7 -16
- package/migrate/{v8.js → v8.ts} +2 -2
- package/migrate/{v9.js → v9.ts} +2 -2
- package/{migrate.js → migrate.ts} +3 -3
- package/package.json +19 -18
- package/{read_style.js → read_style.ts} +5 -4
- package/reference/latest.ts +5 -0
- package/reference/v8.json +264 -7
- package/rollup.config.js +6 -24
- package/{style-spec.js → style-spec.ts} +41 -36
- package/test.js +3 -2
- package/types/config_options.ts +13 -0
- package/types/lut.ts +7 -0
- package/types/tile_id.ts +5 -0
- package/{types.js → types.ts} +527 -165
- package/util/{color.js → color.ts} +89 -3
- package/util/{color_spaces.js → color_spaces.ts} +12 -14
- package/util/{deep_equal.js → deep_equal.ts} +1 -3
- package/util/{extend.js → extend.ts} +1 -3
- package/util/{geometry_util.js → geometry_util.ts} +23 -11
- package/util/{get_type.js → get_type.ts} +1 -3
- package/util/{interpolate.js → interpolate.ts} +1 -3
- package/util/{properties.js → properties.ts} +5 -4
- package/util/{random.js → random.ts} +0 -2
- package/util/{ref_properties.js → ref_properties.ts} +0 -1
- package/util/{result.js → result.ts} +7 -5
- package/util/{unbundle_jsonlint.js → unbundle_jsonlint.ts} +5 -5
- package/validate/{validate.js → validate.ts} +33 -35
- package/validate/{validate_array.js → validate_array.ts} +5 -7
- package/validate/{validate_boolean.js → validate_boolean.ts} +3 -5
- package/validate/{validate_color.js → validate_color.ts} +3 -5
- package/validate/{validate_enum.js → validate_enum.ts} +4 -5
- package/validate/{validate_expression.js → validate_expression.ts} +7 -9
- package/validate/{validate_filter.js → validate_filter.ts} +16 -12
- package/validate/{validate_fog.js → validate_fog.ts} +4 -6
- package/validate/validate_formatted.ts +13 -0
- package/validate/{validate_function.js → validate_function.ts} +14 -16
- package/validate/{validate_glyphs_url.js → validate_glyphs_url.ts} +3 -5
- package/validate/validate_image.ts +13 -0
- package/validate/{validate_import.js → validate_import.ts} +6 -8
- package/validate/{validate_layer.js → validate_layer.ts} +17 -15
- package/validate/{validate_layout_property.js → validate_layout_property.ts} +3 -5
- package/validate/{validate_light.js → validate_light.ts} +4 -6
- package/validate/{validate_lights.js → validate_lights.ts} +7 -9
- package/validate/{validate_model.js → validate_model.ts} +4 -6
- package/validate/{validate_number.js → validate_number.ts} +4 -6
- package/validate/{validate_object.js → validate_object.ts} +5 -8
- package/validate/{validate_paint_property.js → validate_paint_property.ts} +3 -5
- package/validate/{validate_projection.js → validate_projection.ts} +4 -6
- package/validate/{validate_property.js → validate_property.ts} +15 -15
- package/validate/{validate_source.js → validate_source.ts} +16 -13
- package/validate/validate_string.ts +16 -0
- package/validate/validate_style.ts +33 -0
- package/validate/{validate_terrain.js → validate_terrain.ts} +5 -7
- package/{validate_mapbox_api_supported.js → validate_mapbox_api_supported.ts} +22 -18
- package/{validate_style.min.js → validate_style.min.ts} +20 -21
- package/{validate_style.js → validate_style.ts} +9 -9
- package/{visit.js → visit.ts} +22 -17
- package/.eslintrc +0 -10
- package/expression/expression.js +0 -28
- package/flow-typed/cheap-ruler.js +0 -25
- package/flow-typed/geojson.js +0 -44
- package/flow-typed/gl-matrix.js +0 -119
- package/flow-typed/gl.js +0 -5
- package/flow-typed/intl.js +0 -58
- package/flow-typed/kdbush.js +0 -9
- package/flow-typed/mapbox-gl-supported.js +0 -16
- package/flow-typed/mapbox-unitbezier.js +0 -14
- package/flow-typed/offscreen-canvas.js +0 -9
- package/flow-typed/pbf.js +0 -26
- package/flow-typed/point-geometry.js +0 -46
- package/flow-typed/potpack.js +0 -13
- package/flow-typed/tiny-sdf.js +0 -31
- package/flow-typed/tracked_parameters_proxy.js +0 -82
- package/flow-typed/vector-tile.js +0 -49
- package/flow-typed/webgl2.js +0 -41
- package/reference/latest.js +0 -7
- package/validate/validate_formatted.js +0 -15
- package/validate/validate_image.js +0 -15
- package/validate/validate_string.js +0 -18
- package/validate/validate_style.js +0 -29
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import UnitBezier from '@mapbox/unitbezier';
|
|
4
2
|
|
|
5
|
-
import * as interpolate from '../../util/interpolate
|
|
6
|
-
import {toString, NumberType, ColorType} from '../types
|
|
7
|
-
import {findStopLessThanOrEqualTo} from '../stops
|
|
8
|
-
import {hcl, lab} from '../../util/color_spaces
|
|
9
|
-
import Color from '../../util/color
|
|
10
|
-
|
|
11
|
-
import type {Stops} from '../stops
|
|
12
|
-
import type {Expression, SerializedExpression} from '../expression
|
|
13
|
-
import type ParsingContext from '../parsing_context
|
|
14
|
-
import type EvaluationContext from '../evaluation_context
|
|
15
|
-
import type {Type} from '../types
|
|
16
|
-
|
|
17
|
-
export type InterpolationType =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
import * as interpolate from '../../util/interpolate';
|
|
4
|
+
import {toString, NumberType, ColorType} from '../types';
|
|
5
|
+
import {findStopLessThanOrEqualTo} from '../stops';
|
|
6
|
+
import {hcl, lab} from '../../util/color_spaces';
|
|
7
|
+
import Color from '../../util/color';
|
|
8
|
+
|
|
9
|
+
import type {Stops} from '../stops';
|
|
10
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
11
|
+
import type ParsingContext from '../parsing_context';
|
|
12
|
+
import type EvaluationContext from '../evaluation_context';
|
|
13
|
+
import type {Type} from '../types';
|
|
14
|
+
|
|
15
|
+
export type InterpolationType = {
|
|
16
|
+
name: 'linear';
|
|
17
|
+
} | {
|
|
18
|
+
name: 'exponential';
|
|
19
|
+
base: number;
|
|
20
|
+
} | {
|
|
21
|
+
name: 'cubic-bezier';
|
|
22
|
+
controlPoints: [number, number, number, number];
|
|
23
|
+
};
|
|
21
24
|
|
|
22
25
|
class Interpolate implements Expression {
|
|
23
26
|
type: Type;
|
|
@@ -42,7 +45,12 @@ class Interpolate implements Expression {
|
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
static interpolationFactor(
|
|
48
|
+
static interpolationFactor(
|
|
49
|
+
interpolation: InterpolationType,
|
|
50
|
+
input: number,
|
|
51
|
+
lower: number,
|
|
52
|
+
upper: number,
|
|
53
|
+
): number {
|
|
46
54
|
let t = 0;
|
|
47
55
|
if (interpolation.name === 'exponential') {
|
|
48
56
|
t = exponentialInterpolation(input, interpolation.base, lower, upper);
|
|
@@ -56,10 +64,11 @@ class Interpolate implements Expression {
|
|
|
56
64
|
return t;
|
|
57
65
|
}
|
|
58
66
|
|
|
59
|
-
static parse(args:
|
|
67
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Interpolate | null | undefined {
|
|
60
68
|
let [operator, interpolation, input, ...rest] = args;
|
|
61
69
|
|
|
62
70
|
if (!Array.isArray(interpolation) || interpolation.length === 0) {
|
|
71
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Interpolate'.
|
|
63
72
|
return context.error(`Expected an interpolation type expression.`, 1);
|
|
64
73
|
}
|
|
65
74
|
|
|
@@ -68,6 +77,7 @@ class Interpolate implements Expression {
|
|
|
68
77
|
} else if (interpolation[0] === 'exponential') {
|
|
69
78
|
const base = interpolation[1];
|
|
70
79
|
if (typeof base !== 'number')
|
|
80
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Interpolate'.
|
|
71
81
|
return context.error(`Exponential interpolation requires a numeric base.`, 1, 1);
|
|
72
82
|
interpolation = {
|
|
73
83
|
name: 'exponential',
|
|
@@ -79,22 +89,26 @@ class Interpolate implements Expression {
|
|
|
79
89
|
controlPoints.length !== 4 ||
|
|
80
90
|
controlPoints.some(t => typeof t !== 'number' || t < 0 || t > 1)
|
|
81
91
|
) {
|
|
92
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Interpolate'.
|
|
82
93
|
return context.error('Cubic bezier interpolation requires four numeric arguments with values between 0 and 1.', 1);
|
|
83
94
|
}
|
|
84
95
|
|
|
85
96
|
interpolation = {
|
|
86
97
|
name: 'cubic-bezier',
|
|
87
|
-
controlPoints: (controlPoints
|
|
98
|
+
controlPoints: (controlPoints as any)
|
|
88
99
|
};
|
|
89
100
|
} else {
|
|
101
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Interpolate'.
|
|
90
102
|
return context.error(`Unknown interpolation type ${String(interpolation[0])}`, 1, 0);
|
|
91
103
|
}
|
|
92
104
|
|
|
93
105
|
if (args.length - 1 < 4) {
|
|
106
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Interpolate'.
|
|
94
107
|
return context.error(`Expected at least 4 arguments, but found only ${args.length - 1}.`);
|
|
95
108
|
}
|
|
96
109
|
|
|
97
110
|
if ((args.length - 1) % 2 !== 0) {
|
|
111
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Interpolate'.
|
|
98
112
|
return context.error(`Expected an even number of arguments.`);
|
|
99
113
|
}
|
|
100
114
|
|
|
@@ -103,7 +117,7 @@ class Interpolate implements Expression {
|
|
|
103
117
|
|
|
104
118
|
const stops: Stops = [];
|
|
105
119
|
|
|
106
|
-
let outputType: Type = (null
|
|
120
|
+
let outputType: Type = (null as any);
|
|
107
121
|
if (operator === 'interpolate-hcl' || operator === 'interpolate-lab') {
|
|
108
122
|
outputType = ColorType;
|
|
109
123
|
} else if (context.expectedType && context.expectedType.kind !== 'value') {
|
|
@@ -118,10 +132,12 @@ class Interpolate implements Expression {
|
|
|
118
132
|
const valueKey = i + 4;
|
|
119
133
|
|
|
120
134
|
if (typeof label !== 'number') {
|
|
135
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Interpolate'.
|
|
121
136
|
return context.error('Input/output pairs for "interpolate" expressions must be defined using literal numeric values (not computed expressions) for the input values.', labelKey);
|
|
122
137
|
}
|
|
123
138
|
|
|
124
139
|
if (stops.length && stops[stops.length - 1][0] >= label) {
|
|
140
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Interpolate'.
|
|
125
141
|
return context.error('Input/output pairs for "interpolate" expressions must be arranged with input values in strictly ascending order.', labelKey);
|
|
126
142
|
}
|
|
127
143
|
|
|
@@ -139,10 +155,12 @@ class Interpolate implements Expression {
|
|
|
139
155
|
typeof outputType.N === 'number'
|
|
140
156
|
)
|
|
141
157
|
) {
|
|
158
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Interpolate'.
|
|
142
159
|
return context.error(`Type ${toString(outputType)} is not interpolatable.`);
|
|
143
160
|
}
|
|
144
161
|
|
|
145
|
-
|
|
162
|
+
// @ts-expect-error - TS2345 - Argument of type 'unknown' is not assignable to parameter of type 'InterpolationType'.
|
|
163
|
+
return new Interpolate(outputType, (operator as any), interpolation, input, stops);
|
|
146
164
|
}
|
|
147
165
|
|
|
148
166
|
evaluate(ctx: EvaluationContext): Color {
|
|
@@ -153,7 +171,7 @@ class Interpolate implements Expression {
|
|
|
153
171
|
return outputs[0].evaluate(ctx);
|
|
154
172
|
}
|
|
155
173
|
|
|
156
|
-
const value = (
|
|
174
|
+
const value = (this.input.evaluate(ctx) as number);
|
|
157
175
|
if (value <= labels[0]) {
|
|
158
176
|
return outputs[0].evaluate(ctx);
|
|
159
177
|
}
|
|
@@ -172,7 +190,7 @@ class Interpolate implements Expression {
|
|
|
172
190
|
const outputUpper = outputs[index + 1].evaluate(ctx);
|
|
173
191
|
|
|
174
192
|
if (this.operator === 'interpolate') {
|
|
175
|
-
return (interpolate[this.type.kind.toLowerCase()]
|
|
193
|
+
return (interpolate[this.type.kind.toLowerCase()] as any)(outputLower, outputUpper, t); // eslint-disable-line import/namespace
|
|
176
194
|
} else if (this.operator === 'interpolate-hcl') {
|
|
177
195
|
return hcl.reverse(hcl.interpolate(hcl.forward(outputLower), hcl.forward(outputUpper), t));
|
|
178
196
|
} else {
|
|
@@ -202,6 +220,7 @@ class Interpolate implements Expression {
|
|
|
202
220
|
interpolation = ["exponential", this.interpolation.base];
|
|
203
221
|
}
|
|
204
222
|
} else {
|
|
223
|
+
// @ts-expect-error - TS2769 - No overload matches this call.
|
|
205
224
|
interpolation = ["cubic-bezier" ].concat(this.interpolation.controlPoints);
|
|
206
225
|
}
|
|
207
226
|
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import {NumberType, toString} from '../types';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {typeOf} from '../values';
|
|
4
|
+
import RuntimeError from '../runtime_error';
|
|
4
5
|
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import type {
|
|
9
|
-
import type ParsingContext from '../parsing_context.js';
|
|
10
|
-
import type EvaluationContext from '../evaluation_context.js';
|
|
11
|
-
import type {Type} from '../types.js';
|
|
6
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
7
|
+
import type ParsingContext from '../parsing_context';
|
|
8
|
+
import type EvaluationContext from '../evaluation_context';
|
|
9
|
+
import type {Type} from '../types';
|
|
12
10
|
|
|
13
11
|
class Length implements Expression {
|
|
14
12
|
type: Type;
|
|
@@ -19,14 +17,16 @@ class Length implements Expression {
|
|
|
19
17
|
this.input = input;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
static parse(args:
|
|
20
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Length | null | undefined {
|
|
23
21
|
if (args.length !== 2)
|
|
22
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Length'.
|
|
24
23
|
return context.error(`Expected 1 argument, but found ${args.length - 1} instead.`);
|
|
25
24
|
|
|
26
25
|
const input = context.parse(args[1], 1);
|
|
27
26
|
if (!input) return null;
|
|
28
27
|
|
|
29
28
|
if (input.type.kind !== 'array' && input.type.kind !== 'string' && input.type.kind !== 'value')
|
|
29
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Length'.
|
|
30
30
|
return context.error(`Expected argument of type string or array, but found ${toString(input.type)} instead.`);
|
|
31
31
|
|
|
32
32
|
return new Length(input);
|
|
@@ -53,6 +53,7 @@ class Length implements Expression {
|
|
|
53
53
|
|
|
54
54
|
serialize(): SerializedExpression {
|
|
55
55
|
const serialized = ["length"];
|
|
56
|
+
// @ts-expect-error - TS2345 - Argument of type 'SerializedExpression' is not assignable to parameter of type 'string'.
|
|
56
57
|
this.eachChild(child => { serialized.push(child.serialize()); });
|
|
57
58
|
return serialized;
|
|
58
59
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type
|
|
4
|
-
import type
|
|
5
|
-
import type ParsingContext from '../parsing_context.js';
|
|
6
|
-
import type EvaluationContext from '../evaluation_context.js';
|
|
1
|
+
import type {Type} from '../types';
|
|
2
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
3
|
+
import type ParsingContext from '../parsing_context';
|
|
4
|
+
import type EvaluationContext from '../evaluation_context';
|
|
7
5
|
|
|
8
6
|
class Let implements Expression {
|
|
9
7
|
type: Type;
|
|
@@ -27,8 +25,9 @@ class Let implements Expression {
|
|
|
27
25
|
fn(this.result);
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
static parse(args:
|
|
28
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Let | null | undefined {
|
|
31
29
|
if (args.length < 4)
|
|
30
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Let'.
|
|
32
31
|
return context.error(`Expected at least 3 arguments, but found ${args.length - 1} instead.`);
|
|
33
32
|
|
|
34
33
|
const bindings: Array<[string, Expression]> = [];
|
|
@@ -36,10 +35,12 @@ class Let implements Expression {
|
|
|
36
35
|
const name = args[i];
|
|
37
36
|
|
|
38
37
|
if (typeof name !== 'string') {
|
|
38
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Let'.
|
|
39
39
|
return context.error(`Expected string, but found ${typeof name} instead.`, i);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
if (/[^a-zA-Z0-9_]/.test(name)) {
|
|
43
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Let'.
|
|
43
44
|
return context.error(`Variable names must contain only alphanumeric characters or '_'.`, i);
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -62,8 +63,10 @@ class Let implements Expression {
|
|
|
62
63
|
serialize(): SerializedExpression {
|
|
63
64
|
const serialized = ["let"];
|
|
64
65
|
for (const [name, expr] of this.bindings) {
|
|
66
|
+
// @ts-expect-error - TS2345 - Argument of type 'SerializedExpression' is not assignable to parameter of type 'string'.
|
|
65
67
|
serialized.push(name, expr.serialize());
|
|
66
68
|
}
|
|
69
|
+
// @ts-expect-error - TS2345 - Argument of type 'SerializedExpression' is not assignable to parameter of type 'string'.
|
|
67
70
|
serialized.push(this.result.serialize());
|
|
68
71
|
return serialized;
|
|
69
72
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
|
-
import {isValue, typeOf, Color} from '../values
|
|
5
|
-
import Formatted from '../types/formatted
|
|
2
|
+
import {isValue, typeOf, Color} from '../values';
|
|
3
|
+
import Formatted from '../types/formatted';
|
|
6
4
|
|
|
7
|
-
import type {Type} from '../types
|
|
8
|
-
import type {Value} from '../values
|
|
9
|
-
import type {Expression, SerializedExpression} from '../expression
|
|
10
|
-
import type ParsingContext from '../parsing_context
|
|
5
|
+
import type {Type} from '../types';
|
|
6
|
+
import type {Value} from '../values';
|
|
7
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
8
|
+
import type ParsingContext from '../parsing_context';
|
|
11
9
|
|
|
12
10
|
class Literal implements Expression {
|
|
13
11
|
type: Type;
|
|
@@ -18,14 +16,14 @@ class Literal implements Expression {
|
|
|
18
16
|
this.value = value;
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
static parse(args:
|
|
19
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): void | Literal {
|
|
22
20
|
if (args.length !== 2)
|
|
23
21
|
return context.error(`'literal' expression requires exactly one argument, but found ${args.length - 1} instead.`);
|
|
24
22
|
|
|
25
23
|
if (!isValue(args[1]))
|
|
26
24
|
return context.error(`invalid value`);
|
|
27
25
|
|
|
28
|
-
const value = (args[1]
|
|
26
|
+
const value = (args[1] as any);
|
|
29
27
|
let type = typeOf(value);
|
|
30
28
|
|
|
31
29
|
// special case: infer the item type if possible for zero-length arrays
|
|
@@ -60,7 +58,8 @@ class Literal implements Expression {
|
|
|
60
58
|
// Constant-folding can generate Literal expressions that you
|
|
61
59
|
// couldn't actually generate with a "literal" expression,
|
|
62
60
|
// so we have to implement an equivalent serialization here
|
|
63
|
-
|
|
61
|
+
// @ts-expect-error - TS2769 - No overload matches this call.
|
|
62
|
+
return ["rgba"].concat(this.value.toRenderColor(null).toArray());
|
|
64
63
|
} else if (this.value instanceof Formatted) {
|
|
65
64
|
// Same as Color
|
|
66
65
|
return this.value.serialize();
|
|
@@ -69,7 +68,7 @@ class Literal implements Expression {
|
|
|
69
68
|
typeof this.value === 'string' ||
|
|
70
69
|
typeof this.value === 'number' ||
|
|
71
70
|
typeof this.value === 'boolean');
|
|
72
|
-
return
|
|
71
|
+
return this.value as any;
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
|
|
5
|
-
import {typeOf} from '../values
|
|
6
|
-
import {ValueType
|
|
3
|
+
import {typeOf} from '../values';
|
|
4
|
+
import {ValueType} from '../types';
|
|
7
5
|
|
|
8
|
-
import type {
|
|
9
|
-
import type
|
|
10
|
-
import type
|
|
6
|
+
import type {Type} from '../types';
|
|
7
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
8
|
+
import type ParsingContext from '../parsing_context';
|
|
9
|
+
import type EvaluationContext from '../evaluation_context';
|
|
11
10
|
|
|
12
11
|
// Map input label values to output expression index
|
|
13
|
-
type Cases =
|
|
12
|
+
type Cases = Partial<Record<number | string, number>>;
|
|
14
13
|
|
|
15
14
|
class Match implements Expression {
|
|
16
15
|
type: Type;
|
|
@@ -30,18 +29,20 @@ class Match implements Expression {
|
|
|
30
29
|
this.otherwise = otherwise;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
static parse(args:
|
|
32
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Match | null | undefined {
|
|
34
33
|
if (args.length < 5)
|
|
34
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Match'.
|
|
35
35
|
return context.error(`Expected at least 4 arguments, but found only ${args.length - 1}.`);
|
|
36
36
|
if (args.length % 2 !== 1)
|
|
37
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Match'.
|
|
37
38
|
return context.error(`Expected an even number of arguments.`);
|
|
38
39
|
|
|
39
40
|
let inputType;
|
|
40
|
-
let outputType:
|
|
41
|
+
let outputType: Type | null | undefined;
|
|
41
42
|
if (context.expectedType && context.expectedType.kind !== 'value') {
|
|
42
43
|
outputType = context.expectedType;
|
|
43
44
|
}
|
|
44
|
-
const cases = {};
|
|
45
|
+
const cases: Record<string, any> = {};
|
|
45
46
|
const outputs = [];
|
|
46
47
|
for (let i = 2; i < args.length - 1; i += 2) {
|
|
47
48
|
let labels = args[i];
|
|
@@ -52,17 +53,23 @@ class Match implements Expression {
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
const labelContext = context.concat(i);
|
|
56
|
+
// @ts-expect-error - TS2339 - Property 'length' does not exist on type 'unknown'.
|
|
55
57
|
if (labels.length === 0) {
|
|
58
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Match'.
|
|
56
59
|
return labelContext.error('Expected at least one branch label.');
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
// @ts-expect-error - TS2488 - Type 'unknown' must have a '[Symbol.iterator]()' method that returns an iterator.
|
|
59
63
|
for (const label of labels) {
|
|
60
64
|
if (typeof label !== 'number' && typeof label !== 'string') {
|
|
65
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Match'.
|
|
61
66
|
return labelContext.error(`Branch labels must be numbers or strings.`);
|
|
62
67
|
} else if (typeof label === 'number' && Math.abs(label) > Number.MAX_SAFE_INTEGER) {
|
|
68
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Match'.
|
|
63
69
|
return labelContext.error(`Branch labels must be integers no larger than ${Number.MAX_SAFE_INTEGER}.`);
|
|
64
70
|
|
|
65
71
|
} else if (typeof label === 'number' && Math.floor(label) !== label) {
|
|
72
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Match'.
|
|
66
73
|
return labelContext.error(`Numeric branch labels must be integer values.`);
|
|
67
74
|
|
|
68
75
|
} else if (!inputType) {
|
|
@@ -72,6 +79,7 @@ class Match implements Expression {
|
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
if (typeof cases[String(label)] !== 'undefined') {
|
|
82
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Match'.
|
|
75
83
|
return labelContext.error('Branch labels must be unique.');
|
|
76
84
|
}
|
|
77
85
|
|
|
@@ -92,15 +100,15 @@ class Match implements Expression {
|
|
|
92
100
|
|
|
93
101
|
assert(inputType && outputType);
|
|
94
102
|
|
|
95
|
-
if (input.type.kind !== 'value' && context.concat(1).checkSubtype((inputType
|
|
103
|
+
if (input.type.kind !== 'value' && context.concat(1).checkSubtype((inputType), input.type)) {
|
|
96
104
|
return null;
|
|
97
105
|
}
|
|
98
106
|
|
|
99
|
-
return new Match((inputType
|
|
107
|
+
return new Match((inputType), (outputType as any), input, cases, outputs, otherwise);
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
evaluate(ctx: EvaluationContext): any {
|
|
103
|
-
const input = (this.input.evaluate(ctx)
|
|
111
|
+
const input = (this.input.evaluate(ctx));
|
|
104
112
|
const output = (typeOf(input) === this.inputType && this.outputs[this.cases[input]]) || this.otherwise;
|
|
105
113
|
return output.evaluate(ctx);
|
|
106
114
|
}
|
|
@@ -125,7 +133,9 @@ class Match implements Expression {
|
|
|
125
133
|
// Group branches by unique match expression to support condensed
|
|
126
134
|
// serializations of the form [case1, case2, ...] -> matchExpression
|
|
127
135
|
const groupedByOutput: Array<[number, Array<number | string>]> = [];
|
|
128
|
-
const outputLookup: {
|
|
136
|
+
const outputLookup: {
|
|
137
|
+
[index: number]: number;
|
|
138
|
+
} = {}; // lookup index into groupedByOutput for a given output expression
|
|
129
139
|
for (const label of sortedLabels) {
|
|
130
140
|
const outputIndex = outputLookup[this.cases[label]];
|
|
131
141
|
if (outputIndex === undefined) {
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import {StringType, NumberType} from '../types';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import type
|
|
6
|
-
import type
|
|
7
|
-
import type ParsingContext from '../parsing_context.js';
|
|
8
|
-
import type {Type} from '../types.js';
|
|
3
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
4
|
+
import type EvaluationContext from '../evaluation_context';
|
|
5
|
+
import type ParsingContext from '../parsing_context';
|
|
6
|
+
import type {Type} from '../types';
|
|
9
7
|
|
|
10
8
|
export default class NumberFormat implements Expression {
|
|
11
9
|
type: Type;
|
|
@@ -31,15 +29,17 @@ export default class NumberFormat implements Expression {
|
|
|
31
29
|
this.maxFractionDigits = maxFractionDigits;
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
static parse(args:
|
|
32
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Expression | null | undefined {
|
|
35
33
|
if (args.length !== 3)
|
|
34
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
36
35
|
return context.error(`Expected two arguments.`);
|
|
37
36
|
|
|
38
37
|
const number = context.parse(args[1], 1, NumberType);
|
|
39
38
|
if (!number) return null;
|
|
40
39
|
|
|
41
|
-
const options = (args[2]
|
|
40
|
+
const options = (args[2] as any);
|
|
42
41
|
if (typeof options !== "object" || Array.isArray(options))
|
|
42
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
43
43
|
return context.error(`NumberFormat options argument must be an object.`);
|
|
44
44
|
|
|
45
45
|
let locale = null;
|
|
@@ -113,7 +113,7 @@ export default class NumberFormat implements Expression {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
serialize(): SerializedExpression {
|
|
116
|
-
const options = {};
|
|
116
|
+
const options: Record<string, any> = {};
|
|
117
117
|
if (this.locale) {
|
|
118
118
|
options['locale'] = this.locale.serialize();
|
|
119
119
|
}
|
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
ValueType,
|
|
3
|
+
NumberType,
|
|
4
|
+
StringType,
|
|
5
|
+
array,
|
|
6
|
+
toString,
|
|
7
|
+
isValidType,
|
|
8
|
+
isValidNativeType,
|
|
9
|
+
} from '../types';
|
|
10
|
+
import RuntimeError from '../runtime_error';
|
|
11
|
+
import {typeOf} from '../values';
|
|
12
|
+
|
|
13
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
14
|
+
import type ParsingContext from '../parsing_context';
|
|
15
|
+
import type EvaluationContext from '../evaluation_context';
|
|
16
|
+
import type {Type} from '../types';
|
|
11
17
|
|
|
12
18
|
class Slice implements Expression {
|
|
13
19
|
type: Type;
|
|
14
20
|
input: Expression;
|
|
15
21
|
beginIndex: Expression;
|
|
16
|
-
endIndex:
|
|
22
|
+
endIndex: Expression | null | undefined;
|
|
17
23
|
|
|
18
24
|
constructor(type: Type, input: Expression, beginIndex: Expression, endIndex?: Expression) {
|
|
19
25
|
this.type = type;
|
|
@@ -23,8 +29,9 @@ class Slice implements Expression {
|
|
|
23
29
|
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
static parse(args:
|
|
32
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Slice | null | undefined {
|
|
27
33
|
if (args.length <= 2 || args.length >= 5) {
|
|
34
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Slice'.
|
|
28
35
|
return context.error(`Expected 3 or 4 arguments, but found ${args.length - 1} instead.`);
|
|
29
36
|
}
|
|
30
37
|
|
|
@@ -34,6 +41,7 @@ class Slice implements Expression {
|
|
|
34
41
|
if (!input || !beginIndex) return null;
|
|
35
42
|
|
|
36
43
|
if (!isValidType(input.type, [array(ValueType), StringType, ValueType])) {
|
|
44
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Slice'.
|
|
37
45
|
return context.error(`Expected first argument to be of type array or string, but found ${toString(input.type)} instead`);
|
|
38
46
|
}
|
|
39
47
|
|
|
@@ -47,15 +55,15 @@ class Slice implements Expression {
|
|
|
47
55
|
}
|
|
48
56
|
|
|
49
57
|
evaluate(ctx: EvaluationContext): any {
|
|
50
|
-
const input = (this.input.evaluate(ctx)
|
|
51
|
-
const beginIndex = (this.beginIndex.evaluate(ctx)
|
|
58
|
+
const input = (this.input.evaluate(ctx));
|
|
59
|
+
const beginIndex = (this.beginIndex.evaluate(ctx) as number);
|
|
52
60
|
|
|
53
61
|
if (!isValidNativeType(input, ['string', 'array'])) {
|
|
54
62
|
throw new RuntimeError(`Expected first argument to be of type array or string, but found ${toString(typeOf(input))} instead.`);
|
|
55
63
|
}
|
|
56
64
|
|
|
57
65
|
if (this.endIndex) {
|
|
58
|
-
const endIndex = (this.endIndex.evaluate(ctx)
|
|
66
|
+
const endIndex = (this.endIndex.evaluate(ctx) as number);
|
|
59
67
|
return input.slice(beginIndex, endIndex);
|
|
60
68
|
}
|
|
61
69
|
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import {NumberType} from '../types';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {findStopLessThanOrEqualTo} from '../stops';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import type
|
|
8
|
-
import type
|
|
9
|
-
import type
|
|
10
|
-
import type EvaluationContext from '../evaluation_context.js';
|
|
11
|
-
import type {Type} from '../types.js';
|
|
5
|
+
import type {Stops} from '../stops';
|
|
6
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
7
|
+
import type ParsingContext from '../parsing_context';
|
|
8
|
+
import type EvaluationContext from '../evaluation_context';
|
|
9
|
+
import type {Type} from '../types';
|
|
12
10
|
|
|
13
11
|
class Step implements Expression {
|
|
14
12
|
type: Type;
|
|
@@ -29,12 +27,14 @@ class Step implements Expression {
|
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
static parse(args:
|
|
30
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Step | null | undefined {
|
|
33
31
|
if (args.length - 1 < 4) {
|
|
32
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Step'.
|
|
34
33
|
return context.error(`Expected at least 4 arguments, but found only ${args.length - 1}.`);
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
if ((args.length - 1) % 2 !== 0) {
|
|
37
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Step'.
|
|
38
38
|
return context.error(`Expected an even number of arguments.`);
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -43,7 +43,7 @@ class Step implements Expression {
|
|
|
43
43
|
|
|
44
44
|
const stops: Stops = [];
|
|
45
45
|
|
|
46
|
-
let outputType: Type = (null
|
|
46
|
+
let outputType: Type = (null as any);
|
|
47
47
|
if (context.expectedType && context.expectedType.kind !== 'value') {
|
|
48
48
|
outputType = context.expectedType;
|
|
49
49
|
}
|
|
@@ -56,10 +56,12 @@ class Step implements Expression {
|
|
|
56
56
|
const valueKey = i + 1;
|
|
57
57
|
|
|
58
58
|
if (typeof label !== 'number') {
|
|
59
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Step'.
|
|
59
60
|
return context.error('Input/output pairs for "step" expressions must be defined using literal numeric values (not computed expressions) for the input values.', labelKey);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
if (stops.length && stops[stops.length - 1][0] >= label) {
|
|
64
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Step'.
|
|
63
65
|
return context.error('Input/output pairs for "step" expressions must be arranged with input values in strictly ascending order.', labelKey);
|
|
64
66
|
}
|
|
65
67
|
|
|
@@ -80,7 +82,7 @@ class Step implements Expression {
|
|
|
80
82
|
return outputs[0].evaluate(ctx);
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
const value = (
|
|
85
|
+
const value = (this.input.evaluate(ctx) as number);
|
|
84
86
|
if (value <= labels[0]) {
|
|
85
87
|
return outputs[0].evaluate(ctx);
|
|
86
88
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type
|
|
4
|
-
import type
|
|
5
|
-
import type ParsingContext from '../parsing_context.js';
|
|
6
|
-
import type EvaluationContext from '../evaluation_context.js';
|
|
1
|
+
import type {Type} from '../types';
|
|
2
|
+
import type {Expression} from '../expression';
|
|
3
|
+
import type ParsingContext from '../parsing_context';
|
|
4
|
+
import type EvaluationContext from '../evaluation_context';
|
|
7
5
|
|
|
8
6
|
class Var implements Expression {
|
|
9
7
|
type: Type;
|
|
@@ -16,7 +14,7 @@ class Var implements Expression {
|
|
|
16
14
|
this.boundExpression = boundExpression;
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
static parse(args:
|
|
17
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): void | Var {
|
|
20
18
|
if (args.length !== 2 || typeof args[1] !== 'string')
|
|
21
19
|
return context.error(`'var' expression requires exactly one string literal argument.`);
|
|
22
20
|
|