@mapwhit/tilerenderer 0.50.0 → 0.51.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 (142) hide show
  1. package/build/min/package.json +1 -1
  2. package/build/min/src/shaders/.dir +0 -0
  3. package/build/min/src/shaders/_prelude.fragment.glsl.js +14 -0
  4. package/build/min/src/shaders/_prelude.vertex.glsl.js +14 -0
  5. package/build/min/src/shaders/background.fragment.glsl.js +5 -0
  6. package/build/min/src/shaders/background.vertex.glsl.js +1 -0
  7. package/build/min/src/shaders/background_pattern.fragment.glsl.js +5 -0
  8. package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -0
  9. package/build/min/src/shaders/circle.fragment.glsl.js +20 -0
  10. package/build/min/src/shaders/circle.vertex.glsl.js +17 -0
  11. package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -0
  12. package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -0
  13. package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -0
  14. package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -0
  15. package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -0
  16. package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -0
  17. package/build/min/src/shaders/debug.fragment.glsl.js +1 -0
  18. package/build/min/src/shaders/debug.vertex.glsl.js +1 -0
  19. package/build/min/src/shaders/fill.fragment.glsl.js +10 -0
  20. package/build/min/src/shaders/fill.vertex.glsl.js +7 -0
  21. package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +5 -0
  22. package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +9 -0
  23. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +15 -0
  24. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +11 -0
  25. package/build/min/src/shaders/fill_outline.fragment.glsl.js +10 -0
  26. package/build/min/src/shaders/fill_outline.vertex.glsl.js +7 -0
  27. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +13 -0
  28. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +9 -0
  29. package/build/min/src/shaders/fill_pattern.fragment.glsl.js +13 -0
  30. package/build/min/src/shaders/fill_pattern.vertex.glsl.js +9 -0
  31. package/build/min/src/shaders/heatmap.fragment.glsl.js +10 -0
  32. package/build/min/src/shaders/heatmap.vertex.glsl.js +8 -0
  33. package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +5 -0
  34. package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -0
  35. package/build/min/src/shaders/hillshade.fragment.glsl.js +7 -0
  36. package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -0
  37. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +8 -0
  38. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -0
  39. package/build/min/src/shaders/line.fragment.glsl.js +12 -0
  40. package/build/min/src/shaders/line.vertex.glsl.js +17 -0
  41. package/build/min/src/shaders/line_gradient.fragment.glsl.js +10 -0
  42. package/build/min/src/shaders/line_gradient.vertex.glsl.js +16 -0
  43. package/build/min/src/shaders/line_pattern.fragment.glsl.js +15 -0
  44. package/build/min/src/shaders/line_pattern.vertex.glsl.js +20 -0
  45. package/build/min/src/shaders/line_sdf.fragment.glsl.js +17 -0
  46. package/build/min/src/shaders/line_sdf.vertex.glsl.js +20 -0
  47. package/build/min/src/shaders/raster.fragment.glsl.js +5 -0
  48. package/build/min/src/shaders/raster.vertex.glsl.js +1 -0
  49. package/build/min/src/shaders/symbol_icon.fragment.glsl.js +9 -0
  50. package/build/min/src/shaders/symbol_icon.vertex.glsl.js +5 -0
  51. package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +19 -0
  52. package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +13 -0
  53. package/package.json +7 -7
  54. package/src/data/bucket/fill_bucket.js +1 -1
  55. package/src/data/bucket/fill_extrusion_bucket.js +2 -2
  56. package/src/data/bucket/line_bucket.js +1 -1
  57. package/src/data/bucket/symbol_bucket.js +2 -2
  58. package/src/data/feature_index.js +1 -1
  59. package/src/data/program_configuration.js +1 -1
  60. package/src/gl/color_mode.js +1 -1
  61. package/src/gl/value.js +1 -1
  62. package/src/render/draw_debug.js +1 -1
  63. package/src/render/draw_fill.js +1 -1
  64. package/src/render/draw_heatmap.js +1 -1
  65. package/src/render/glyph_manager.js +6 -130
  66. package/src/render/painter.js +1 -1
  67. package/src/render/uniform_binding.js +1 -1
  68. package/src/shaders/index.js +50 -50
  69. package/src/source/geojson_worker_source.js +4 -4
  70. package/src/source/geojson_wrapper.js +34 -26
  71. package/src/source/resources/glyphs.js +73 -0
  72. package/src/source/resources/images.js +68 -0
  73. package/src/source/resources/index.js +22 -0
  74. package/src/source/vector_tile_worker_source.js +5 -5
  75. package/src/source/worker.js +6 -5
  76. package/src/source/worker_tile.js +4 -4
  77. package/src/style/properties.js +1 -2
  78. package/src/style/style.js +3 -3
  79. package/src/style/style_layer/symbol_style_layer.js +1 -1
  80. package/src/style/style_layer.js +1 -1
  81. package/src/style-spec/feature_filter/index.js +43 -34
  82. package/src/style-spec/group_by_layout.js +10 -32
  83. package/src/symbol/mergelines.js +0 -2
  84. package/src/symbol/symbol_layout.js +0 -1
  85. package/src/symbol/symbol_size.js +1 -1
  86. package/src/symbol/transform_text.js +0 -1
  87. package/src/ui/map.js +11 -39
  88. package/src/util/browser.js +3 -18
  89. package/src/util/classify_rings.js +1 -1
  90. package/src/util/dom.js +0 -88
  91. package/src/util/find_pole_of_inaccessibility.js +2 -2
  92. package/src/util/web_worker_transfer.js +4 -4
  93. package/src/style/load_glyph_range.js +0 -17
  94. package/src/style-spec/expression/compound_expression.js +0 -132
  95. package/src/style-spec/expression/definitions/assertion.js +0 -116
  96. package/src/style-spec/expression/definitions/at.js +0 -57
  97. package/src/style-spec/expression/definitions/case.js +0 -73
  98. package/src/style-spec/expression/definitions/coalesce.js +0 -66
  99. package/src/style-spec/expression/definitions/coercion.js +0 -120
  100. package/src/style-spec/expression/definitions/collator.js +0 -80
  101. package/src/style-spec/expression/definitions/comparison.js +0 -193
  102. package/src/style-spec/expression/definitions/format.js +0 -97
  103. package/src/style-spec/expression/definitions/index.js +0 -339
  104. package/src/style-spec/expression/definitions/interpolate.js +0 -245
  105. package/src/style-spec/expression/definitions/length.js +0 -54
  106. package/src/style-spec/expression/definitions/let.js +0 -60
  107. package/src/style-spec/expression/definitions/literal.js +0 -69
  108. package/src/style-spec/expression/definitions/match.js +0 -142
  109. package/src/style-spec/expression/definitions/step.js +0 -116
  110. package/src/style-spec/expression/definitions/var.js +0 -38
  111. package/src/style-spec/expression/evaluation_context.js +0 -38
  112. package/src/style-spec/expression/index.js +0 -330
  113. package/src/style-spec/expression/is_constant.js +0 -63
  114. package/src/style-spec/expression/parsing_context.js +0 -221
  115. package/src/style-spec/expression/parsing_error.js +0 -9
  116. package/src/style-spec/expression/runtime_error.js +0 -12
  117. package/src/style-spec/expression/scope.js +0 -34
  118. package/src/style-spec/expression/stops.js +0 -37
  119. package/src/style-spec/expression/types/collator.js +0 -24
  120. package/src/style-spec/expression/types/formatted.js +0 -39
  121. package/src/style-spec/expression/types.js +0 -88
  122. package/src/style-spec/expression/values.js +0 -149
  123. package/src/style-spec/function/convert.js +0 -240
  124. package/src/style-spec/function/index.js +0 -303
  125. package/src/style-spec/util/color.js +0 -73
  126. package/src/style-spec/util/color_spaces.js +0 -128
  127. package/src/style-spec/util/get_type.js +0 -18
  128. package/src/style-spec/util/interpolate.js +0 -21
  129. package/src/style-spec/util/properties.js +0 -17
  130. package/src/style-spec/util/result.js +0 -19
  131. package/src/ui/anchor.js +0 -24
  132. package/src/ui/bind_handlers.js +0 -199
  133. package/src/ui/events.js +0 -210
  134. package/src/ui/handler/box_zoom.js +0 -151
  135. package/src/ui/handler/dblclick_zoom.js +0 -91
  136. package/src/ui/handler/drag_pan.js +0 -285
  137. package/src/ui/handler/drag_rotate.js +0 -290
  138. package/src/ui/handler/frame.js +0 -28
  139. package/src/ui/handler/inertia.js +0 -45
  140. package/src/ui/handler/keyboard.js +0 -148
  141. package/src/ui/handler/scroll_zoom.js +0 -284
  142. package/src/ui/handler/touch_zoom_rotate.js +0 -263
package/src/util/dom.js CHANGED
@@ -1,7 +1,3 @@
1
- const Point = require('@mapbox/point-geometry');
2
-
3
- const assert = require('assert');
4
-
5
1
  const DOM = {};
6
2
  module.exports = DOM;
7
3
 
@@ -16,87 +12,3 @@ DOM.createNS = function (namespaceURI, tagName) {
16
12
  const el = window.document.createElementNS(namespaceURI, tagName);
17
13
  return el;
18
14
  };
19
-
20
- let docStyle;
21
- let selectProp;
22
-
23
- DOM.initEnableDisableDrag = function () {
24
- docStyle = window.document ? window.document.documentElement.style : null;
25
-
26
- function testProp(props) {
27
- if (!docStyle) return null;
28
- for (let i = 0; i < props.length; i++) {
29
- if (props[i] in docStyle) {
30
- return props[i];
31
- }
32
- }
33
- return props[0];
34
- }
35
-
36
- selectProp = testProp(['userSelect', 'MozUserSelect', 'WebkitUserSelect', 'msUserSelect']);
37
- };
38
-
39
- let userSelect;
40
-
41
- DOM.disableDrag = function () {
42
- if (docStyle && selectProp) {
43
- userSelect = docStyle[selectProp];
44
- docStyle[selectProp] = 'none';
45
- }
46
- };
47
-
48
- DOM.enableDrag = function () {
49
- if (docStyle && selectProp) {
50
- docStyle[selectProp] = userSelect;
51
- }
52
- };
53
-
54
- // Suppress the next click, but only if it's immediate.
55
- const suppressClick = function (e) {
56
- e.preventDefault();
57
- e.stopPropagation();
58
- window.removeEventListener('click', suppressClick, true);
59
- };
60
-
61
- DOM.suppressClick = function () {
62
- window.addEventListener('click', suppressClick, true);
63
- window.setTimeout(() => {
64
- if (typeof window === 'object' && window) {
65
- window.removeEventListener('click', suppressClick, true);
66
- }
67
- }, 0);
68
- };
69
-
70
- DOM.mousePos = function (el, e) {
71
- const rect = el.getBoundingClientRect();
72
- e = e.touches ? e.touches[0] : e;
73
- return new Point(e.clientX - rect.left - el.clientLeft, e.clientY - rect.top - el.clientTop);
74
- };
75
-
76
- DOM.touchPos = function (el, e) {
77
- const rect = el.getBoundingClientRect();
78
- const points = [];
79
- const touches = e.type === 'touchend' ? e.changedTouches : e.touches;
80
- for (let i = 0; i < touches.length; i++) {
81
- points.push(
82
- new Point(touches[i].clientX - rect.left - el.clientLeft, touches[i].clientY - rect.top - el.clientTop)
83
- );
84
- }
85
- return points;
86
- };
87
-
88
- DOM.mouseButton = function (e) {
89
- assert(e.type === 'mousedown' || e.type === 'mouseup');
90
- if (
91
- typeof window.InstallTrigger !== 'undefined' &&
92
- e.button === 2 &&
93
- e.ctrlKey &&
94
- window.navigator.platform.toUpperCase().indexOf('MAC') >= 0
95
- ) {
96
- // Fix for https://github.com/mapbox/mapbox-gl-js/issues/3131:
97
- // Firefox (detected by InstallTrigger) on Mac determines e.button = 2 when
98
- // using Control + left click
99
- return 0;
100
- }
101
- return e.button;
102
- };
@@ -1,4 +1,4 @@
1
- const Queue = require('tinyqueue');
1
+ const { default: Queue } = require('tinyqueue');
2
2
 
3
3
  const Point = require('@mapbox/point-geometry');
4
4
  const { distToSegmentSquared } = require('./intersection_tests');
@@ -34,7 +34,7 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
34
34
  let h = cellSize / 2;
35
35
 
36
36
  // a priority queue of cells in order of their "potential" (max distance to polygon)
37
- const cellQueue = new Queue(null, compareMax);
37
+ const cellQueue = new Queue(undefined, compareMax);
38
38
 
39
39
  if (cellSize === 0) return new Point(minX, minY);
40
40
 
@@ -1,13 +1,13 @@
1
1
  const Grid = require('grid-index');
2
- const Color = require('../style-spec/util/color');
2
+ const { Color } = require('@mapwhit/style-expressions');
3
3
  const {
4
+ CompoundExpression,
5
+ definitions: expressions,
4
6
  StylePropertyFunction,
5
7
  StyleExpression,
6
8
  ZoomDependentExpression,
7
9
  ZoomConstantExpression
8
- } = require('../style-spec/expression');
9
- const CompoundExpression = require('../style-spec/expression/compound_expression');
10
- const expressions = require('../style-spec/expression/definitions');
10
+ } = require('@mapwhit/style-expressions');
11
11
 
12
12
  const { register, serialize, deserialize } = require('./transfer_registry');
13
13
  module.exports = {
@@ -1,17 +0,0 @@
1
- const parseGlyphPBF = require('./parse_glyph_pbf');
2
- const { callback } = require('../util/callback');
3
-
4
- module.exports = loadGlyphRange;
5
-
6
- function loadGlyphRange(fontstack, range, load, fn) {
7
- return callback(fn, perform());
8
-
9
- async function perform() {
10
- const data = await load(fontstack, range);
11
- const glyphs = {};
12
- for (const glyph of parseGlyphPBF(data)) {
13
- glyphs[glyph.id] = glyph;
14
- }
15
- return glyphs;
16
- }
17
- }
@@ -1,132 +0,0 @@
1
- const { toString } = require('./types');
2
-
3
- const assert = require('assert');
4
-
5
- class CompoundExpression {
6
- constructor(name, type, evaluate, args) {
7
- this.name = name;
8
- this.type = type;
9
- this._evaluate = evaluate;
10
- this.args = args;
11
- }
12
-
13
- evaluate(ctx) {
14
- return this._evaluate(ctx, this.args);
15
- }
16
-
17
- eachChild(fn) {
18
- this.args.forEach(fn);
19
- }
20
-
21
- possibleOutputs() {
22
- return [undefined];
23
- }
24
-
25
- serialize() {
26
- return [this.name].concat(this.args.map(arg => arg.serialize()));
27
- }
28
-
29
- static parse(args, context) {
30
- const ParsingContext = require('./parsing_context');
31
-
32
- const op = args[0];
33
- const definition = CompoundExpression.definitions[op];
34
- if (!definition) {
35
- return context.error(`Unknown expression "${op}". If you wanted a literal array, use ["literal", [...]].`, 0);
36
- }
37
-
38
- // Now check argument types against each signature
39
- const type = Array.isArray(definition) ? definition[0] : definition.type;
40
-
41
- const availableOverloads = Array.isArray(definition) ? [[definition[1], definition[2]]] : definition.overloads;
42
-
43
- const overloads = availableOverloads.filter(
44
- ([signature]) =>
45
- !Array.isArray(signature) || // varags
46
- signature.length === args.length - 1 // correct param count
47
- );
48
-
49
- let signatureContext = null;
50
-
51
- for (const [params, evaluate] of overloads) {
52
- // Use a fresh context for each attempted signature so that, if
53
- // we eventually succeed, we haven't polluted `context.errors`.
54
- signatureContext = new ParsingContext(context.registry, context.path, null, context.scope);
55
-
56
- // First parse all the args, potentially coercing to the
57
- // types expected by this overload.
58
- const parsedArgs = [];
59
- let argParseFailed = false;
60
- for (let i = 1; i < args.length; i++) {
61
- const arg = args[i];
62
- const expectedType = Array.isArray(params) ? params[i - 1] : params.type;
63
-
64
- const parsed = signatureContext.parse(arg, 1 + parsedArgs.length, expectedType);
65
- if (!parsed) {
66
- argParseFailed = true;
67
- break;
68
- }
69
- parsedArgs.push(parsed);
70
- }
71
- if (argParseFailed) {
72
- // Couldn't coerce args of this overload to expected type, move
73
- // on to next one.
74
- continue;
75
- }
76
-
77
- if (Array.isArray(params)) {
78
- if (params.length !== parsedArgs.length) {
79
- signatureContext.error(`Expected ${params.length} arguments, but found ${parsedArgs.length} instead.`);
80
- continue;
81
- }
82
- }
83
-
84
- for (let i = 0; i < parsedArgs.length; i++) {
85
- const expected = Array.isArray(params) ? params[i] : params.type;
86
- const arg = parsedArgs[i];
87
- signatureContext.concat(i + 1).checkSubtype(expected, arg.type);
88
- }
89
-
90
- if (signatureContext.errors.length === 0) {
91
- return new CompoundExpression(op, type, evaluate, parsedArgs);
92
- }
93
- }
94
-
95
- assert(!signatureContext || signatureContext.errors.length > 0);
96
-
97
- if (overloads.length === 1) {
98
- context.errors.push.apply(context.errors, signatureContext.errors);
99
- } else {
100
- const expected = overloads.length ? overloads : availableOverloads;
101
- const signatures = expected.map(([params]) => stringifySignature(params)).join(' | ');
102
- const actualTypes = [];
103
- // For error message, re-parse arguments without trying to
104
- // apply any coercions
105
- for (let i = 1; i < args.length; i++) {
106
- const parsed = context.parse(args[i], 1 + actualTypes.length);
107
- if (!parsed) return null;
108
- actualTypes.push(toString(parsed.type));
109
- }
110
- context.error(`Expected arguments of type ${signatures}, but found (${actualTypes.join(', ')}) instead.`);
111
- }
112
-
113
- return null;
114
- }
115
-
116
- static register(registry, definitions) {
117
- assert(!CompoundExpression.definitions);
118
- CompoundExpression.definitions = definitions;
119
- for (const name in definitions) {
120
- registry[name] = CompoundExpression;
121
- }
122
- }
123
- }
124
-
125
- function stringifySignature(signature) {
126
- if (Array.isArray(signature)) {
127
- return `(${signature.map(toString).join(', ')})`;
128
- }
129
- return `(${toString(signature.type)}...)`;
130
- }
131
-
132
- module.exports = CompoundExpression;
@@ -1,116 +0,0 @@
1
- const assert = require('assert');
2
-
3
- const {
4
- ObjectType,
5
- ValueType,
6
- StringType,
7
- NumberType,
8
- BooleanType,
9
- checkSubtype,
10
- toString,
11
- array
12
- } = require('../types');
13
- const RuntimeError = require('../runtime_error');
14
- const { typeOf } = require('../values');
15
-
16
- const types = {
17
- string: StringType,
18
- number: NumberType,
19
- boolean: BooleanType,
20
- object: ObjectType
21
- };
22
-
23
- class Assertion {
24
- constructor(type, args) {
25
- this.type = type;
26
- this.args = args;
27
- }
28
-
29
- static parse(args, context) {
30
- if (args.length < 2) return context.error('Expected at least one argument.');
31
-
32
- let i = 1;
33
- let type;
34
-
35
- const name = args[0];
36
- if (name === 'array') {
37
- let itemType;
38
- if (args.length > 2) {
39
- const type = args[1];
40
- if (typeof type !== 'string' || !(type in types) || type === 'object')
41
- return context.error('The item type argument of "array" must be one of string, number, boolean', 1);
42
- itemType = types[type];
43
- i++;
44
- } else {
45
- itemType = ValueType;
46
- }
47
-
48
- let N;
49
- if (args.length > 3) {
50
- if (args[2] !== null && (typeof args[2] !== 'number' || args[2] < 0 || args[2] !== Math.floor(args[2]))) {
51
- return context.error('The length argument to "array" must be a positive integer literal', 2);
52
- }
53
- N = args[2];
54
- i++;
55
- }
56
-
57
- type = array(itemType, N);
58
- } else {
59
- assert(types[name], name);
60
- type = types[name];
61
- }
62
-
63
- const parsed = [];
64
- for (; i < args.length; i++) {
65
- const input = context.parse(args[i], i, ValueType);
66
- if (!input) return null;
67
- parsed.push(input);
68
- }
69
-
70
- return new Assertion(type, parsed);
71
- }
72
-
73
- evaluate(ctx) {
74
- for (let i = 0; i < this.args.length; i++) {
75
- const value = this.args[i].evaluate(ctx);
76
- const error = checkSubtype(this.type, typeOf(value));
77
- if (!error) {
78
- return value;
79
- }
80
- if (i === this.args.length - 1) {
81
- throw new RuntimeError(
82
- `Expected value to be of type ${toString(this.type)}, but found ${toString(typeOf(value))} instead.`
83
- );
84
- }
85
- }
86
-
87
- assert(false);
88
- return null;
89
- }
90
-
91
- eachChild(fn) {
92
- this.args.forEach(fn);
93
- }
94
-
95
- possibleOutputs() {
96
- return [].concat(...this.args.map(arg => arg.possibleOutputs()));
97
- }
98
-
99
- serialize() {
100
- const type = this.type;
101
- const serialized = [type.kind];
102
- if (type.kind === 'array') {
103
- const itemType = type.itemType;
104
- if (itemType.kind === 'string' || itemType.kind === 'number' || itemType.kind === 'boolean') {
105
- serialized.push(itemType.kind);
106
- const N = type.N;
107
- if (typeof N === 'number' || this.args.length > 1) {
108
- serialized.push(N);
109
- }
110
- }
111
- }
112
- return serialized.concat(this.args.map(arg => arg.serialize()));
113
- }
114
- }
115
-
116
- module.exports = Assertion;
@@ -1,57 +0,0 @@
1
- const { array, ValueType, NumberType } = require('../types');
2
-
3
- const RuntimeError = require('../runtime_error');
4
-
5
- class At {
6
- constructor(type, index, input) {
7
- this.type = type;
8
- this.index = index;
9
- this.input = input;
10
- }
11
-
12
- static parse(args, context) {
13
- if (args.length !== 3) return context.error(`Expected 2 arguments, but found ${args.length - 1} instead.`);
14
-
15
- const index = context.parse(args[1], 1, NumberType);
16
- const input = context.parse(args[2], 2, array(context.expectedType || ValueType));
17
-
18
- if (!index || !input) return null;
19
-
20
- const t = input.type;
21
- return new At(t.itemType, index, input);
22
- }
23
-
24
- evaluate(ctx) {
25
- const index = this.index.evaluate(ctx);
26
- const array = this.input.evaluate(ctx);
27
-
28
- if (index < 0) {
29
- throw new RuntimeError(`Array index out of bounds: ${index} < 0.`);
30
- }
31
-
32
- if (index >= array.length) {
33
- throw new RuntimeError(`Array index out of bounds: ${index} > ${array.length - 1}.`);
34
- }
35
-
36
- if (index !== Math.floor(index)) {
37
- throw new RuntimeError(`Array index must be an integer, but found ${index} instead.`);
38
- }
39
-
40
- return array[index];
41
- }
42
-
43
- eachChild(fn) {
44
- fn(this.index);
45
- fn(this.input);
46
- }
47
-
48
- possibleOutputs() {
49
- return [undefined];
50
- }
51
-
52
- serialize() {
53
- return ['at', this.index.serialize(), this.input.serialize()];
54
- }
55
- }
56
-
57
- module.exports = At;
@@ -1,73 +0,0 @@
1
- const assert = require('assert');
2
-
3
- const { BooleanType } = require('../types');
4
-
5
- class Case {
6
- constructor(type, branches, otherwise) {
7
- this.type = type;
8
- this.branches = branches;
9
- this.otherwise = otherwise;
10
- }
11
-
12
- static parse(args, context) {
13
- if (args.length < 4) return context.error(`Expected at least 3 arguments, but found only ${args.length - 1}.`);
14
- if (args.length % 2 !== 0) return context.error('Expected an odd number of arguments.');
15
-
16
- let outputType;
17
- if (context.expectedType && context.expectedType.kind !== 'value') {
18
- outputType = context.expectedType;
19
- }
20
-
21
- const branches = [];
22
- for (let i = 1; i < args.length - 1; i += 2) {
23
- const test = context.parse(args[i], i, BooleanType);
24
- if (!test) return null;
25
-
26
- const result = context.parse(args[i + 1], i + 1, outputType);
27
- if (!result) return null;
28
-
29
- branches.push([test, result]);
30
-
31
- outputType = outputType || result.type;
32
- }
33
-
34
- const otherwise = context.parse(args[args.length - 1], args.length - 1, outputType);
35
- if (!otherwise) return null;
36
-
37
- assert(outputType);
38
- return new Case(outputType, branches, otherwise);
39
- }
40
-
41
- evaluate(ctx) {
42
- for (const [test, expression] of this.branches) {
43
- if (test.evaluate(ctx)) {
44
- return expression.evaluate(ctx);
45
- }
46
- }
47
- return this.otherwise.evaluate(ctx);
48
- }
49
-
50
- eachChild(fn) {
51
- for (const [test, expression] of this.branches) {
52
- fn(test);
53
- fn(expression);
54
- }
55
- fn(this.otherwise);
56
- }
57
-
58
- possibleOutputs() {
59
- return []
60
- .concat(...this.branches.map(branch => branch[1].possibleOutputs()))
61
- .concat(this.otherwise.possibleOutputs());
62
- }
63
-
64
- serialize() {
65
- const serialized = ['case'];
66
- this.eachChild(child => {
67
- serialized.push(child.serialize());
68
- });
69
- return serialized;
70
- }
71
- }
72
-
73
- module.exports = Case;
@@ -1,66 +0,0 @@
1
- const assert = require('assert');
2
-
3
- const { checkSubtype, ValueType } = require('../types');
4
-
5
- class Coalesce {
6
- constructor(type, args) {
7
- this.type = type;
8
- this.args = args;
9
- }
10
-
11
- static parse(args, context) {
12
- if (args.length < 2) {
13
- return context.error('Expectected at least one argument.');
14
- }
15
- let outputType = null;
16
- const expectedType = context.expectedType;
17
- if (expectedType && expectedType.kind !== 'value') {
18
- outputType = expectedType;
19
- }
20
- const parsedArgs = [];
21
-
22
- for (const arg of args.slice(1)) {
23
- const parsed = context.parse(arg, 1 + parsedArgs.length, outputType, undefined, { typeAnnotation: 'omit' });
24
- if (!parsed) return null;
25
- outputType = outputType || parsed.type;
26
- parsedArgs.push(parsed);
27
- }
28
- assert(outputType);
29
-
30
- // Above, we parse arguments without inferred type annotation so that
31
- // they don't produce a runtime error for `null` input, which would
32
- // preempt the desired null-coalescing behavior.
33
- // Thus, if any of our arguments would have needed an annotation, we
34
- // need to wrap the enclosing coalesce expression with it instead.
35
- const needsAnnotation = expectedType && parsedArgs.some(arg => checkSubtype(expectedType, arg.type));
36
-
37
- return needsAnnotation ? new Coalesce(ValueType, parsedArgs) : new Coalesce(outputType, parsedArgs);
38
- }
39
-
40
- evaluate(ctx) {
41
- let result = null;
42
- for (const arg of this.args) {
43
- result = arg.evaluate(ctx);
44
- if (result !== null) break;
45
- }
46
- return result;
47
- }
48
-
49
- eachChild(fn) {
50
- this.args.forEach(fn);
51
- }
52
-
53
- possibleOutputs() {
54
- return [].concat(...this.args.map(arg => arg.possibleOutputs()));
55
- }
56
-
57
- serialize() {
58
- const serialized = ['coalesce'];
59
- this.eachChild(child => {
60
- serialized.push(child.serialize());
61
- });
62
- return serialized;
63
- }
64
- }
65
-
66
- module.exports = Coalesce;