@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
package/{empty.js → empty.ts}
RENAMED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
// Note: Do not inherit from Error. It breaks when transpiling to ES5.
|
|
4
2
|
|
|
5
3
|
export default class ValidationError {
|
|
6
4
|
message: string;
|
|
7
|
-
identifier:
|
|
8
|
-
line:
|
|
5
|
+
identifier: string | null | undefined;
|
|
6
|
+
line: number | null | undefined;
|
|
9
7
|
|
|
10
|
-
constructor(key:
|
|
8
|
+
constructor(key: string | null | undefined, value: {
|
|
9
|
+
__line__: number;
|
|
10
|
+
} | null | undefined, message: string, identifier?: string | null) {
|
|
11
11
|
this.message = (key ? `${key}: ` : '') + message;
|
|
12
12
|
if (identifier) this.identifier = identifier;
|
|
13
13
|
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import {toString} from './types';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import ParsingContext from './parsing_context.js';
|
|
6
|
-
import EvaluationContext from './evaluation_context.js';
|
|
3
|
+
import ParsingContext from './parsing_context';
|
|
4
|
+
import EvaluationContext from './evaluation_context';
|
|
7
5
|
import assert from 'assert';
|
|
8
6
|
|
|
9
|
-
import type {Expression, ExpressionRegistry} from './expression
|
|
10
|
-
import type {Type} from './types
|
|
11
|
-
import type {Value} from './values
|
|
7
|
+
import type {Expression, ExpressionRegistry} from './expression';
|
|
8
|
+
import type {Type} from './types';
|
|
9
|
+
import type {Value} from './values';
|
|
12
10
|
|
|
13
|
-
export type Varargs = {
|
|
11
|
+
export type Varargs = {
|
|
12
|
+
type: Type;
|
|
13
|
+
};
|
|
14
14
|
type Signature = Array<Type> | Varargs;
|
|
15
|
-
type Evaluate = (EvaluationContext, Array<Expression>) => Value;
|
|
16
|
-
type Definition = [Type, Signature, Evaluate] |
|
|
17
|
-
|
|
15
|
+
type Evaluate = (arg1: EvaluationContext, arg2: Array<Expression>) => Value;
|
|
16
|
+
type Definition = [Type, Signature, Evaluate] | {
|
|
17
|
+
type: Type;
|
|
18
|
+
overloads: Array<[Signature, Evaluate]>;
|
|
19
|
+
};
|
|
18
20
|
|
|
19
21
|
class CompoundExpression implements Expression {
|
|
20
22
|
name: string;
|
|
@@ -23,7 +25,9 @@ class CompoundExpression implements Expression {
|
|
|
23
25
|
args: Array<Expression>;
|
|
24
26
|
_overloadIndex: number;
|
|
25
27
|
|
|
26
|
-
static definitions: {
|
|
28
|
+
static definitions: {
|
|
29
|
+
[_: string]: Definition;
|
|
30
|
+
};
|
|
27
31
|
|
|
28
32
|
constructor(name: string, type: Type, evaluate: Evaluate, args: Array<Expression>, overloadIndex: number) {
|
|
29
33
|
this.name = name;
|
|
@@ -49,14 +53,16 @@ class CompoundExpression implements Expression {
|
|
|
49
53
|
return false;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
serialize(): Array<
|
|
56
|
+
serialize(): Array<unknown> {
|
|
57
|
+
// @ts-expect-error - TS2769 - No overload matches this call.
|
|
53
58
|
return [this.name].concat(this.args.map(arg => arg.serialize()));
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
static parse(args:
|
|
57
|
-
const op: string = (args[0]
|
|
61
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Expression | null | undefined {
|
|
62
|
+
const op: string = (args[0] as any);
|
|
58
63
|
const definition = CompoundExpression.definitions[op];
|
|
59
64
|
if (!definition) {
|
|
65
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
60
66
|
return context.error(`Unknown expression "${op}". If you wanted a literal array, use ["literal", [...]].`, 0);
|
|
61
67
|
}
|
|
62
68
|
|
|
@@ -70,7 +76,7 @@ class CompoundExpression implements Expression {
|
|
|
70
76
|
|
|
71
77
|
const overloadParams = [];
|
|
72
78
|
|
|
73
|
-
let signatureContext: ParsingContext = (null
|
|
79
|
+
let signatureContext: ParsingContext = (null as any);
|
|
74
80
|
|
|
75
81
|
let overloadIndex = -1;
|
|
76
82
|
|
|
@@ -92,6 +98,7 @@ class CompoundExpression implements Expression {
|
|
|
92
98
|
const arg = args[i];
|
|
93
99
|
const expectedType = Array.isArray(params) ?
|
|
94
100
|
params[i - 1] :
|
|
101
|
+
// @ts-expect-error - TS2339 - Property 'type' does not exist on type 'Varargs | Evaluate'.
|
|
95
102
|
params.type;
|
|
96
103
|
|
|
97
104
|
const parsed = signatureContext.parse(arg, 1 + parsedArgs.length, expectedType);
|
|
@@ -115,12 +122,14 @@ class CompoundExpression implements Expression {
|
|
|
115
122
|
}
|
|
116
123
|
|
|
117
124
|
for (let i = 0; i < parsedArgs.length; i++) {
|
|
125
|
+
// @ts-expect-error - TS2339 - Property 'type' does not exist on type 'Varargs | Evaluate'.
|
|
118
126
|
const expected = Array.isArray(params) ? params[i] : params.type;
|
|
119
127
|
const arg = parsedArgs[i];
|
|
120
128
|
signatureContext.concat(i + 1).checkSubtype(expected, arg.type);
|
|
121
129
|
}
|
|
122
130
|
|
|
123
131
|
if (signatureContext.errors.length === 0) {
|
|
132
|
+
// @ts-expect-error - TS2345 - Argument of type 'Signature | Evaluate' is not assignable to parameter of type 'Evaluate'.
|
|
124
133
|
return new CompoundExpression(op, type, evaluate, parsedArgs, overloadIndex);
|
|
125
134
|
}
|
|
126
135
|
}
|
|
@@ -149,12 +158,13 @@ class CompoundExpression implements Expression {
|
|
|
149
158
|
|
|
150
159
|
static register(
|
|
151
160
|
registry: ExpressionRegistry,
|
|
152
|
-
definitions: {
|
|
161
|
+
definitions: {
|
|
162
|
+
[_: string]: Definition;
|
|
163
|
+
}
|
|
153
164
|
) {
|
|
154
165
|
assert(!CompoundExpression.definitions);
|
|
155
166
|
CompoundExpression.definitions = definitions;
|
|
156
167
|
for (const name in definitions) {
|
|
157
|
-
// $FlowFixMe[method-unbinding]
|
|
158
168
|
registry[name] = CompoundExpression;
|
|
159
169
|
}
|
|
160
170
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
|
|
5
3
|
import {
|
|
@@ -11,14 +9,14 @@ import {
|
|
|
11
9
|
checkSubtype,
|
|
12
10
|
toString,
|
|
13
11
|
array
|
|
14
|
-
} from '../types
|
|
15
|
-
import RuntimeError from '../runtime_error
|
|
16
|
-
import {typeOf} from '../values
|
|
12
|
+
} from '../types';
|
|
13
|
+
import RuntimeError from '../runtime_error';
|
|
14
|
+
import {typeOf} from '../values';
|
|
17
15
|
|
|
18
|
-
import type {Expression, SerializedExpression} from '../expression
|
|
19
|
-
import type ParsingContext from '../parsing_context
|
|
20
|
-
import type EvaluationContext from '../evaluation_context
|
|
21
|
-
import type {Type} from '../types
|
|
16
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
17
|
+
import type ParsingContext from '../parsing_context';
|
|
18
|
+
import type EvaluationContext from '../evaluation_context';
|
|
19
|
+
import type {Type} from '../types';
|
|
22
20
|
|
|
23
21
|
const types = {
|
|
24
22
|
string: StringType,
|
|
@@ -36,19 +34,21 @@ class Assertion implements Expression {
|
|
|
36
34
|
this.args = args;
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
static parse(args:
|
|
37
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Expression | null | undefined {
|
|
40
38
|
if (args.length < 2)
|
|
39
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
41
40
|
return context.error(`Expected at least one argument.`);
|
|
42
41
|
|
|
43
42
|
let i = 1;
|
|
44
43
|
let type;
|
|
45
44
|
|
|
46
|
-
const name: string = (args[0]
|
|
45
|
+
const name: string = (args[0] as any);
|
|
47
46
|
if (name === 'array') {
|
|
48
47
|
let itemType;
|
|
49
48
|
if (args.length > 2) {
|
|
50
49
|
const type = args[1];
|
|
51
50
|
if (typeof type !== 'string' || !(type in types) || type === 'object')
|
|
51
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
52
52
|
return context.error('The item type argument of "array" must be one of string, number, boolean', 1);
|
|
53
53
|
itemType = types[type];
|
|
54
54
|
i++;
|
|
@@ -56,16 +56,17 @@ class Assertion implements Expression {
|
|
|
56
56
|
itemType = ValueType;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
let N:
|
|
59
|
+
let N: number | null | undefined;
|
|
60
60
|
if (args.length > 3) {
|
|
61
61
|
if (args[2] !== null &&
|
|
62
62
|
(typeof args[2] !== 'number' ||
|
|
63
63
|
args[2] < 0 ||
|
|
64
64
|
args[2] !== Math.floor(args[2]))
|
|
65
65
|
) {
|
|
66
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
66
67
|
return context.error('The length argument to "array" must be a positive integer literal', 2);
|
|
67
68
|
}
|
|
68
|
-
N = (
|
|
69
|
+
N = (args[2] as number);
|
|
69
70
|
i++;
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -119,10 +120,12 @@ class Assertion implements Expression {
|
|
|
119
120
|
serialized.push(itemType.kind);
|
|
120
121
|
const N = type.N;
|
|
121
122
|
if (typeof N === 'number' || this.args.length > 1) {
|
|
123
|
+
// @ts-expect-error - TS2345 - Argument of type 'number' is not assignable to parameter of type '"string" | "number" | "boolean" | "object" | "error" | "color" | "value" | "null" | "collator" | "formatted" | "resolvedImage" | "array"'.
|
|
122
124
|
serialized.push(N);
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
}
|
|
128
|
+
// @ts-expect-error - TS2769 - No overload matches this call.
|
|
126
129
|
return serialized.concat(this.args.map(arg => arg.serialize()));
|
|
127
130
|
}
|
|
128
131
|
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import {array, ValueType, NumberType} from '../types';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import RuntimeError from '../runtime_error';
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import type
|
|
8
|
-
import type
|
|
9
|
-
import type
|
|
10
|
-
import type {Type, ArrayType} from '../types.js';
|
|
11
|
-
import type {Value} from '../values.js';
|
|
5
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
6
|
+
import type ParsingContext from '../parsing_context';
|
|
7
|
+
import type EvaluationContext from '../evaluation_context';
|
|
8
|
+
import type {Type, ArrayType} from '../types';
|
|
9
|
+
import type {Value} from '../values';
|
|
12
10
|
|
|
13
11
|
class At implements Expression {
|
|
14
12
|
type: Type;
|
|
@@ -21,8 +19,9 @@ class At implements Expression {
|
|
|
21
19
|
this.input = input;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
static parse(args:
|
|
22
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): At | null | undefined {
|
|
25
23
|
if (args.length !== 3)
|
|
24
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'At'.
|
|
26
25
|
return context.error(`Expected 2 arguments, but found ${args.length - 1} instead.`);
|
|
27
26
|
|
|
28
27
|
const index = context.parse(args[1], 1, NumberType);
|
|
@@ -30,13 +29,13 @@ class At implements Expression {
|
|
|
30
29
|
|
|
31
30
|
if (!index || !input) return null;
|
|
32
31
|
|
|
33
|
-
const t: ArrayType = (input.type
|
|
32
|
+
const t: ArrayType = (input.type as any);
|
|
34
33
|
return new At(t.itemType, index, input);
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
evaluate(ctx: EvaluationContext): Value {
|
|
38
|
-
const index = (
|
|
39
|
-
const array = (
|
|
37
|
+
const index = (this.index.evaluate(ctx) as number);
|
|
38
|
+
const array = (this.input.evaluate(ctx) as Array<Value>);
|
|
40
39
|
|
|
41
40
|
if (index < 0) {
|
|
42
41
|
throw new RuntimeError(`Array index out of bounds: ${index} < 0.`);
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
|
|
5
|
-
import {BooleanType} from '../types
|
|
3
|
+
import {BooleanType} from '../types';
|
|
6
4
|
|
|
7
|
-
import type {Expression, SerializedExpression} from '../expression
|
|
8
|
-
import type ParsingContext from '../parsing_context
|
|
9
|
-
import type EvaluationContext from '../evaluation_context
|
|
10
|
-
import type {Type} from '../types
|
|
5
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
6
|
+
import type ParsingContext from '../parsing_context';
|
|
7
|
+
import type EvaluationContext from '../evaluation_context';
|
|
8
|
+
import type {Type} from '../types';
|
|
11
9
|
|
|
12
10
|
type Branches = Array<[Expression, Expression]>;
|
|
13
11
|
|
|
@@ -23,13 +21,15 @@ class Case implements Expression {
|
|
|
23
21
|
this.otherwise = otherwise;
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
static parse(args:
|
|
24
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Case | null | undefined {
|
|
27
25
|
if (args.length < 4)
|
|
26
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Case'.
|
|
28
27
|
return context.error(`Expected at least 3 arguments, but found only ${args.length - 1}.`);
|
|
29
28
|
if (args.length % 2 !== 0)
|
|
29
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Case'.
|
|
30
30
|
return context.error(`Expected an odd number of arguments.`);
|
|
31
31
|
|
|
32
|
-
let outputType:
|
|
32
|
+
let outputType: Type | null | undefined;
|
|
33
33
|
if (context.expectedType && context.expectedType.kind !== 'value') {
|
|
34
34
|
outputType = context.expectedType;
|
|
35
35
|
}
|
|
@@ -51,7 +51,7 @@ class Case implements Expression {
|
|
|
51
51
|
if (!otherwise) return null;
|
|
52
52
|
|
|
53
53
|
assert(outputType);
|
|
54
|
-
return new Case((outputType
|
|
54
|
+
return new Case((outputType as any), branches, otherwise);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
evaluate(ctx: EvaluationContext): any {
|
|
@@ -72,11 +72,12 @@ class Case implements Expression {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
outputDefined(): boolean {
|
|
75
|
-
return this.branches.every(([_, out]) => out.outputDefined()) && this.otherwise.outputDefined();
|
|
75
|
+
return this.branches.every(([_, out]: [any, any]) => out.outputDefined()) && this.otherwise.outputDefined();
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
serialize(): SerializedExpression {
|
|
79
79
|
const serialized = ["case"];
|
|
80
|
+
// @ts-expect-error - TS2345 - Argument of type 'SerializedExpression' is not assignable to parameter of type 'string'.
|
|
80
81
|
this.eachChild(child => { serialized.push(child.serialize()); });
|
|
81
82
|
return serialized;
|
|
82
83
|
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
|
|
5
|
-
import {checkSubtype, ValueType} from '../types
|
|
6
|
-
import ResolvedImage from '../types/resolved_image
|
|
3
|
+
import {checkSubtype, ValueType} from '../types';
|
|
4
|
+
import ResolvedImage from '../types/resolved_image';
|
|
7
5
|
|
|
8
|
-
import type {Expression, SerializedExpression} from '../expression
|
|
9
|
-
import type ParsingContext from '../parsing_context
|
|
10
|
-
import type EvaluationContext from '../evaluation_context
|
|
11
|
-
import type {Type} from '../types
|
|
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 Coalesce implements Expression {
|
|
14
12
|
type: Type;
|
|
@@ -19,11 +17,12 @@ class Coalesce implements Expression {
|
|
|
19
17
|
this.args = args;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
static parse(args:
|
|
20
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Coalesce | null | undefined {
|
|
23
21
|
if (args.length < 2) {
|
|
22
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Coalesce'.
|
|
24
23
|
return context.error("Expectected at least one argument.");
|
|
25
24
|
}
|
|
26
|
-
let outputType: Type = (null
|
|
25
|
+
let outputType: Type = (null as any);
|
|
27
26
|
const expectedType = context.expectedType;
|
|
28
27
|
if (expectedType && expectedType.kind !== 'value') {
|
|
29
28
|
outputType = expectedType;
|
|
@@ -48,7 +47,7 @@ class Coalesce implements Expression {
|
|
|
48
47
|
|
|
49
48
|
return needsAnnotation ?
|
|
50
49
|
new Coalesce(ValueType, parsedArgs) :
|
|
51
|
-
new Coalesce((outputType
|
|
50
|
+
new Coalesce((outputType as any), parsedArgs);
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
evaluate(ctx: EvaluationContext): any | null {
|
|
@@ -87,6 +86,7 @@ class Coalesce implements Expression {
|
|
|
87
86
|
|
|
88
87
|
serialize(): SerializedExpression {
|
|
89
88
|
const serialized = ["coalesce"];
|
|
89
|
+
// @ts-expect-error - TS2345 - Argument of type 'SerializedExpression' is not assignable to parameter of type 'string'.
|
|
90
90
|
this.eachChild(child => { serialized.push(child.serialize()); });
|
|
91
91
|
return serialized;
|
|
92
92
|
}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
|
|
5
|
-
import {BooleanType, ColorType, NumberType, StringType, ValueType, array, NullType} from '../types
|
|
6
|
-
import {Color, isValue, toString as valueToString, typeOf, validateRGBA} from '../values
|
|
7
|
-
import RuntimeError from '../runtime_error
|
|
8
|
-
import Formatted from '../types/formatted
|
|
9
|
-
import FormatExpression from '../definitions/format
|
|
10
|
-
import ImageExpression from '../definitions/image
|
|
11
|
-
import ResolvedImage from '../types/resolved_image
|
|
3
|
+
import {BooleanType, ColorType, NumberType, StringType, ValueType, array, NullType} from '../types';
|
|
4
|
+
import {Color, isValue, toString as valueToString, typeOf, validateRGBA} from '../values';
|
|
5
|
+
import RuntimeError from '../runtime_error';
|
|
6
|
+
import Formatted from '../types/formatted';
|
|
7
|
+
import FormatExpression from '../definitions/format';
|
|
8
|
+
import ImageExpression from '../definitions/image';
|
|
9
|
+
import ResolvedImage from '../types/resolved_image';
|
|
12
10
|
|
|
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, ArrayType} from '../types
|
|
17
|
-
import getType from '../../util/get_type
|
|
11
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
12
|
+
import type ParsingContext from '../parsing_context';
|
|
13
|
+
import type EvaluationContext from '../evaluation_context';
|
|
14
|
+
import type {Type, ArrayType} from '../types';
|
|
15
|
+
import getType from '../../util/get_type';
|
|
18
16
|
|
|
19
17
|
const types = {
|
|
20
18
|
'to-boolean': BooleanType,
|
|
@@ -39,11 +37,12 @@ class Coercion implements Expression {
|
|
|
39
37
|
this.args = args;
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
static parse(args:
|
|
40
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Expression | null | undefined {
|
|
43
41
|
if (args.length < 2)
|
|
42
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
44
43
|
return context.error(`Expected at least one argument.`);
|
|
45
44
|
|
|
46
|
-
const name: string = (args[0]
|
|
45
|
+
const name: string = (args[0] as any);
|
|
47
46
|
const parsed = [];
|
|
48
47
|
let type: Type | ArrayType = NullType;
|
|
49
48
|
if (name === 'to-array') {
|
|
@@ -55,16 +54,16 @@ class Coercion implements Expression {
|
|
|
55
54
|
if (context.expectedType.kind === 'array') {
|
|
56
55
|
type = array(context.expectedType.itemType, arrayLength);
|
|
57
56
|
} else {
|
|
57
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
58
58
|
return context.error(`Expected ${context.expectedType.kind} but found array.`);
|
|
59
59
|
}
|
|
60
60
|
} else if (arrayLength > 0 && isValue(args[1][0])) {
|
|
61
|
-
const value = (args[1][0]
|
|
61
|
+
const value = (args[1][0]);
|
|
62
62
|
type = array(typeOf(value), arrayLength);
|
|
63
63
|
} else {
|
|
64
64
|
return null;
|
|
65
65
|
}
|
|
66
66
|
for (let i = 0; i < arrayLength; i++) {
|
|
67
|
-
// $FlowIgnore
|
|
68
67
|
const member = args[1][i];
|
|
69
68
|
let parsedMember;
|
|
70
69
|
if (getType(member) === 'array') {
|
|
@@ -72,6 +71,7 @@ class Coercion implements Expression {
|
|
|
72
71
|
} else {
|
|
73
72
|
const memberType = getType(member);
|
|
74
73
|
if (memberType !== type.itemType.kind) {
|
|
74
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
75
75
|
return context.error(`Expected ${type.itemType.kind} but found ${memberType}.`);
|
|
76
76
|
}
|
|
77
77
|
parsedMember = context.registry['literal'].parse(['literal', member === undefined ? null : member], context);
|
|
@@ -83,6 +83,7 @@ class Coercion implements Expression {
|
|
|
83
83
|
assert(types[name], name);
|
|
84
84
|
|
|
85
85
|
if ((name === 'to-boolean' || name === 'to-string') && args.length !== 2)
|
|
86
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
86
87
|
return context.error(`Expected one argument.`);
|
|
87
88
|
|
|
88
89
|
type = types[name];
|
|
@@ -118,7 +119,7 @@ class Coercion implements Expression {
|
|
|
118
119
|
error = validateRGBA(input[0], input[1], input[2], input[3]);
|
|
119
120
|
}
|
|
120
121
|
if (!error) {
|
|
121
|
-
return new Color((input[0]
|
|
122
|
+
return new Color((input[0]) / 255, (input[1]) / 255, (input[2]) / 255, (input[3]));
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
}
|
|
@@ -163,7 +164,7 @@ class Coercion implements Expression {
|
|
|
163
164
|
return new ImageExpression(this.args[0]).serialize();
|
|
164
165
|
}
|
|
165
166
|
|
|
166
|
-
const serialized: Array<
|
|
167
|
+
const serialized: Array<unknown> = this.type.kind === 'array' ? [] : [`to-${this.type.kind}`];
|
|
167
168
|
this.eachChild(child => { serialized.push(child.serialize()); });
|
|
168
169
|
return serialized;
|
|
169
170
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import {StringType, BooleanType, CollatorType} from '../types';
|
|
2
|
+
import Collator from '../types/collator';
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
import type EvaluationContext from '../evaluation_context.js';
|
|
8
|
-
import type ParsingContext from '../parsing_context.js';
|
|
9
|
-
import type {Type} from '../types.js';
|
|
4
|
+
import type {Expression, SerializedExpression} from '../expression';
|
|
5
|
+
import type EvaluationContext from '../evaluation_context';
|
|
6
|
+
import type ParsingContext from '../parsing_context';
|
|
7
|
+
import type {Type} from '../types';
|
|
10
8
|
|
|
11
9
|
export default class CollatorExpression implements Expression {
|
|
12
10
|
type: Type;
|
|
@@ -21,12 +19,14 @@ export default class CollatorExpression implements Expression {
|
|
|
21
19
|
this.diacriticSensitive = diacriticSensitive;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
static parse(args:
|
|
22
|
+
static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Expression | null | undefined {
|
|
25
23
|
if (args.length !== 2)
|
|
24
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
26
25
|
return context.error(`Expected one argument.`);
|
|
27
26
|
|
|
28
|
-
const options = (args[1]
|
|
27
|
+
const options = (args[1] as any);
|
|
29
28
|
if (typeof options !== "object" || Array.isArray(options))
|
|
29
|
+
// @ts-expect-error - TS2322 - Type 'void' is not assignable to type 'Expression'.
|
|
30
30
|
return context.error(`Collator options argument must be an object.`);
|
|
31
31
|
|
|
32
32
|
const caseSensitive = context.parse(
|
|
@@ -67,7 +67,7 @@ export default class CollatorExpression implements Expression {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
serialize(): SerializedExpression {
|
|
70
|
-
const options = {};
|
|
70
|
+
const options: Record<string, any> = {};
|
|
71
71
|
options['case-sensitive'] = this.caseSensitive.serialize();
|
|
72
72
|
options['diacritic-sensitive'] = this.diacriticSensitive.serialize();
|
|
73
73
|
if (this.locale) {
|