greybel-interpreter 1.1.7 → 1.2.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 (97) hide show
  1. package/.editorconfig +14 -14
  2. package/.eslintrc +47 -47
  3. package/LICENSE +21 -21
  4. package/README.md +2 -2
  5. package/dist/context.d.ts +109 -109
  6. package/dist/context.js +382 -382
  7. package/dist/cps.d.ts +14 -14
  8. package/dist/cps.js +213 -213
  9. package/dist/handler/error.d.ts +6 -6
  10. package/dist/handler/error.js +35 -35
  11. package/dist/handler/output.d.ts +6 -6
  12. package/dist/handler/output.js +35 -35
  13. package/dist/handler/resource.d.ts +12 -12
  14. package/dist/handler/resource.js +51 -51
  15. package/dist/handler-container.d.ts +14 -14
  16. package/dist/handler-container.js +16 -16
  17. package/dist/index.d.ts +44 -44
  18. package/dist/index.js +129 -129
  19. package/dist/interpreter.d.ts +41 -41
  20. package/dist/interpreter.js +315 -315
  21. package/dist/intrinsics-container.d.ts +7 -7
  22. package/dist/intrinsics-container.js +19 -19
  23. package/dist/operations/assign.d.ts +13 -13
  24. package/dist/operations/assign.js +111 -111
  25. package/dist/operations/block.d.ts +12 -12
  26. package/dist/operations/block.js +108 -108
  27. package/dist/operations/break.d.ts +10 -10
  28. package/dist/operations/break.js +41 -41
  29. package/dist/operations/call.d.ts +13 -13
  30. package/dist/operations/call.js +124 -124
  31. package/dist/operations/chunk.d.ts +12 -12
  32. package/dist/operations/chunk.js +85 -85
  33. package/dist/operations/continue.d.ts +10 -10
  34. package/dist/operations/continue.js +41 -41
  35. package/dist/operations/debugger-statement.d.ts +10 -10
  36. package/dist/operations/debugger-statement.js +39 -39
  37. package/dist/operations/evaluate.d.ts +39 -39
  38. package/dist/operations/evaluate.js +366 -366
  39. package/dist/operations/for.d.ts +14 -14
  40. package/dist/operations/for.js +152 -152
  41. package/dist/operations/function-reference.d.ts +12 -12
  42. package/dist/operations/function-reference.js +103 -103
  43. package/dist/operations/function.d.ts +14 -14
  44. package/dist/operations/function.js +200 -200
  45. package/dist/operations/if-statement.d.ts +19 -19
  46. package/dist/operations/if-statement.js +181 -181
  47. package/dist/operations/import.d.ts +17 -17
  48. package/dist/operations/import.js +119 -119
  49. package/dist/operations/include.d.ts +13 -13
  50. package/dist/operations/include.js +95 -95
  51. package/dist/operations/list.d.ts +11 -11
  52. package/dist/operations/list.js +111 -111
  53. package/dist/operations/literal.d.ts +11 -11
  54. package/dist/operations/literal.js +58 -58
  55. package/dist/operations/map.d.ts +11 -11
  56. package/dist/operations/map.js +171 -171
  57. package/dist/operations/negated-binary.d.ts +11 -11
  58. package/dist/operations/negated-binary.js +109 -109
  59. package/dist/operations/new-instance.d.ts +11 -11
  60. package/dist/operations/new-instance.js +100 -100
  61. package/dist/operations/noop.d.ts +9 -9
  62. package/dist/operations/noop.js +36 -36
  63. package/dist/operations/not.d.ts +11 -11
  64. package/dist/operations/not.js +96 -96
  65. package/dist/operations/operation.d.ts +13 -13
  66. package/dist/operations/operation.js +11 -11
  67. package/dist/operations/reference.d.ts +9 -9
  68. package/dist/operations/reference.js +37 -37
  69. package/dist/operations/resolve.d.ts +38 -38
  70. package/dist/operations/resolve.js +330 -330
  71. package/dist/operations/return.d.ts +11 -11
  72. package/dist/operations/return.js +107 -107
  73. package/dist/operations/while.d.ts +13 -13
  74. package/dist/operations/while.js +136 -136
  75. package/dist/types/boolean.d.ts +11 -11
  76. package/dist/types/boolean.js +46 -46
  77. package/dist/types/default.d.ts +11 -11
  78. package/dist/types/default.js +20 -20
  79. package/dist/types/function.d.ts +32 -32
  80. package/dist/types/function.js +174 -174
  81. package/dist/types/generics.d.ts +18 -18
  82. package/dist/types/generics.js +40 -40
  83. package/dist/types/interface.d.ts +23 -23
  84. package/dist/types/interface.js +103 -103
  85. package/dist/types/list.d.ts +31 -31
  86. package/dist/types/list.js +209 -209
  87. package/dist/types/map.d.ts +35 -35
  88. package/dist/types/map.js +287 -287
  89. package/dist/types/nil.d.ts +10 -10
  90. package/dist/types/nil.js +46 -46
  91. package/dist/types/number.d.ts +11 -11
  92. package/dist/types/number.js +46 -46
  93. package/dist/types/string.d.ts +33 -33
  94. package/dist/types/string.js +145 -145
  95. package/dist/utils/path.d.ts +10 -10
  96. package/dist/utils/path.js +59 -59
  97. package/package.json +58 -58
package/dist/types/map.js CHANGED
@@ -1,287 +1,287 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __values = (this && this.__values) || function(o) {
18
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
19
- if (m) return m.call(o);
20
- if (o && typeof o.length === "number") return {
21
- next: function () {
22
- if (o && i >= o.length) o = void 0;
23
- return { value: o && o[i++], done: !o };
24
- }
25
- };
26
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
27
- };
28
- var __read = (this && this.__read) || function (o, n) {
29
- var m = typeof Symbol === "function" && o[Symbol.iterator];
30
- if (!m) return o;
31
- var i = m.call(o), r, ar = [], e;
32
- try {
33
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
34
- }
35
- catch (error) { e = { error: error }; }
36
- finally {
37
- try {
38
- if (r && !r.done && (m = i["return"])) m.call(i);
39
- }
40
- finally { if (e) throw e.error; }
41
- }
42
- return ar;
43
- };
44
- var __importDefault = (this && this.__importDefault) || function (mod) {
45
- return (mod && mod.__esModule) ? mod : { "default": mod };
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.CustomMapIterator = exports.setValue = exports.hasValue = exports.getValue = exports.CLASS_ID_PROPERTY = void 0;
49
- var intrinsics_container_1 = __importDefault(require("../intrinsics-container"));
50
- var path_1 = __importDefault(require("../utils/path"));
51
- var default_1 = __importDefault(require("./default"));
52
- var generics_1 = require("./generics");
53
- var nil_1 = __importDefault(require("./nil"));
54
- var string_1 = __importDefault(require("./string"));
55
- exports.CLASS_ID_PROPERTY = new string_1.default('classID');
56
- var getValue = function (map, mapKey) {
57
- var e_1, _a;
58
- try {
59
- for (var _b = __values(map.value), _c = _b.next(); !_c.done; _c = _b.next()) {
60
- var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
61
- if (key.value === mapKey.value) {
62
- return value;
63
- }
64
- }
65
- }
66
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
67
- finally {
68
- try {
69
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
70
- }
71
- finally { if (e_1) throw e_1.error; }
72
- }
73
- return default_1.default.Void;
74
- };
75
- exports.getValue = getValue;
76
- var hasValue = function (map, mapKey) {
77
- var e_2, _a;
78
- try {
79
- for (var _b = __values(map.value.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
80
- var key = _c.value;
81
- if (key.value === mapKey.value) {
82
- return true;
83
- }
84
- }
85
- }
86
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
87
- finally {
88
- try {
89
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
90
- }
91
- finally { if (e_2) throw e_2.error; }
92
- }
93
- return false;
94
- };
95
- exports.hasValue = hasValue;
96
- var setValue = function (map, mapKey, mapValue) {
97
- var e_3, _a;
98
- try {
99
- for (var _b = __values(map.value.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
100
- var key = _c.value;
101
- if (key.value === mapKey.value) {
102
- map.value.set(key, mapValue);
103
- return;
104
- }
105
- }
106
- }
107
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
108
- finally {
109
- try {
110
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
111
- }
112
- finally { if (e_3) throw e_3.error; }
113
- }
114
- map.value.set(mapKey, mapValue);
115
- };
116
- exports.setValue = setValue;
117
- var CustomMapIterator = /** @class */ (function () {
118
- function CustomMapIterator(value) {
119
- var me = this;
120
- me.value = value;
121
- me.index = 0;
122
- }
123
- CustomMapIterator.prototype.next = function () {
124
- var me = this;
125
- var keys = Array.from(me.value.keys());
126
- if (me.index === keys.length) {
127
- return {
128
- value: new nil_1.default(),
129
- done: true
130
- };
131
- }
132
- var key = keys[me.index++];
133
- return {
134
- value: new CustomMap(new Map([
135
- [new string_1.default('key'), key],
136
- [new string_1.default('value'), me.value.get(key)]
137
- ])),
138
- done: false
139
- };
140
- };
141
- return CustomMapIterator;
142
- }());
143
- exports.CustomMapIterator = CustomMapIterator;
144
- var CustomMap = /** @class */ (function (_super) {
145
- __extends(CustomMap, _super);
146
- function CustomMap(value) {
147
- if (value === void 0) { value = new Map(); }
148
- var _this = _super.call(this) || this;
149
- _this.isInstance = false;
150
- _this.value = new Map(value);
151
- return _this;
152
- }
153
- CustomMap.getIntrinsics = function () {
154
- return this.intrinsics;
155
- };
156
- CustomMap.addIntrinsic = function (name, fn) {
157
- this.intrinsics.add(name, fn);
158
- };
159
- CustomMap.prototype.getCustomType = function () {
160
- if ((0, exports.hasValue)(this, exports.CLASS_ID_PROPERTY)) {
161
- return (0, exports.getValue)(this, exports.CLASS_ID_PROPERTY).toString();
162
- }
163
- return 'map';
164
- };
165
- CustomMap.prototype.toString = function () {
166
- var e_4, _a;
167
- var values = [];
168
- try {
169
- for (var _b = __values(this.value), _c = _b.next(); !_c.done; _c = _b.next()) {
170
- var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
171
- values.push("".concat(key, ": ").concat(value.toString()));
172
- }
173
- }
174
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
175
- finally {
176
- try {
177
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
178
- }
179
- finally { if (e_4) throw e_4.error; }
180
- }
181
- return "{ ".concat(values.join(', '), " }");
182
- };
183
- CustomMap.prototype.fork = function () {
184
- return new CustomMap(this.value);
185
- };
186
- CustomMap.prototype.toNumber = function () {
187
- return 0;
188
- };
189
- CustomMap.prototype.toInt = function () {
190
- return 0;
191
- };
192
- CustomMap.prototype.toTruthy = function () {
193
- return this.value.size > 0;
194
- };
195
- CustomMap.prototype[Symbol.iterator] = function () {
196
- return new CustomMapIterator(this.value);
197
- };
198
- CustomMap.prototype.extend = function (map) {
199
- var e_5, _a;
200
- if (map instanceof CustomMap) {
201
- map = map.value;
202
- }
203
- try {
204
- for (var map_1 = __values(map), map_1_1 = map_1.next(); !map_1_1.done; map_1_1 = map_1.next()) {
205
- var _b = __read(map_1_1.value, 2), key = _b[0], value = _b[1];
206
- (0, exports.setValue)(this, key, value);
207
- }
208
- }
209
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
210
- finally {
211
- try {
212
- if (map_1_1 && !map_1_1.done && (_a = map_1.return)) _a.call(map_1);
213
- }
214
- finally { if (e_5) throw e_5.error; }
215
- }
216
- return this;
217
- };
218
- CustomMap.prototype.has = function (path) {
219
- if (path instanceof generics_1.CustomValue) {
220
- return this.has(new path_1.default([path]));
221
- }
222
- var traversalPath = path.clone();
223
- var current = traversalPath.next();
224
- if (current !== null) {
225
- if ((0, exports.hasValue)(this, current)) {
226
- var sub = (0, exports.getValue)(this, current);
227
- if (traversalPath.count() > 0 &&
228
- sub instanceof generics_1.CustomValueWithIntrinsics) {
229
- return sub.has(traversalPath);
230
- }
231
- return traversalPath.count() === 0;
232
- }
233
- }
234
- return false;
235
- };
236
- CustomMap.prototype.set = function (path, newValue) {
237
- if (path instanceof generics_1.CustomValue) {
238
- return this.set(new path_1.default([path]), newValue);
239
- }
240
- var traversalPath = path.clone();
241
- var last = traversalPath.last();
242
- var current = traversalPath.next();
243
- if (current !== null) {
244
- if ((0, exports.hasValue)(this, current)) {
245
- var sub = (0, exports.getValue)(this, current);
246
- if (sub instanceof generics_1.CustomValueWithIntrinsics) {
247
- sub.set(traversalPath, newValue);
248
- return;
249
- }
250
- }
251
- throw new Error("Cannot set path ".concat(path.toString(), "."));
252
- }
253
- (0, exports.setValue)(this, last, newValue);
254
- };
255
- CustomMap.prototype.get = function (path) {
256
- if (path instanceof generics_1.CustomValue) {
257
- return this.get(new path_1.default([path]));
258
- }
259
- var traversalPath = path.clone();
260
- var current = traversalPath.next();
261
- if (current !== null) {
262
- if ((0, exports.hasValue)(this, current)) {
263
- var sub = (0, exports.getValue)(this, current);
264
- if (traversalPath.count() > 0) {
265
- if (sub instanceof generics_1.CustomValueWithIntrinsics) {
266
- return sub.get(traversalPath);
267
- }
268
- }
269
- else if (traversalPath.count() === 0) {
270
- return sub;
271
- }
272
- }
273
- else if (path.count() === 1 && CustomMap.getIntrinsics().has(current.toString())) {
274
- return CustomMap.getIntrinsics().get(current.toString());
275
- }
276
- }
277
- throw new Error("Unknown path in map ".concat(path.toString(), "."));
278
- };
279
- CustomMap.prototype.createInstance = function () {
280
- var newInstance = new CustomMap(this.value);
281
- newInstance.isInstance = true;
282
- return newInstance;
283
- };
284
- CustomMap.intrinsics = new intrinsics_container_1.default();
285
- return CustomMap;
286
- }(generics_1.CustomObject));
287
- exports.default = CustomMap;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __values = (this && this.__values) || function(o) {
18
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
19
+ if (m) return m.call(o);
20
+ if (o && typeof o.length === "number") return {
21
+ next: function () {
22
+ if (o && i >= o.length) o = void 0;
23
+ return { value: o && o[i++], done: !o };
24
+ }
25
+ };
26
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
27
+ };
28
+ var __read = (this && this.__read) || function (o, n) {
29
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
30
+ if (!m) return o;
31
+ var i = m.call(o), r, ar = [], e;
32
+ try {
33
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
34
+ }
35
+ catch (error) { e = { error: error }; }
36
+ finally {
37
+ try {
38
+ if (r && !r.done && (m = i["return"])) m.call(i);
39
+ }
40
+ finally { if (e) throw e.error; }
41
+ }
42
+ return ar;
43
+ };
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.CustomMapIterator = exports.setValue = exports.hasValue = exports.getValue = exports.CLASS_ID_PROPERTY = void 0;
49
+ var intrinsics_container_1 = __importDefault(require("../intrinsics-container"));
50
+ var path_1 = __importDefault(require("../utils/path"));
51
+ var default_1 = __importDefault(require("./default"));
52
+ var generics_1 = require("./generics");
53
+ var nil_1 = __importDefault(require("./nil"));
54
+ var string_1 = __importDefault(require("./string"));
55
+ exports.CLASS_ID_PROPERTY = new string_1.default('classID');
56
+ var getValue = function (map, mapKey) {
57
+ var e_1, _a;
58
+ try {
59
+ for (var _b = __values(map.value), _c = _b.next(); !_c.done; _c = _b.next()) {
60
+ var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
61
+ if (key.value === mapKey.value) {
62
+ return value;
63
+ }
64
+ }
65
+ }
66
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
67
+ finally {
68
+ try {
69
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
70
+ }
71
+ finally { if (e_1) throw e_1.error; }
72
+ }
73
+ return default_1.default.Void;
74
+ };
75
+ exports.getValue = getValue;
76
+ var hasValue = function (map, mapKey) {
77
+ var e_2, _a;
78
+ try {
79
+ for (var _b = __values(map.value.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
80
+ var key = _c.value;
81
+ if (key.value === mapKey.value) {
82
+ return true;
83
+ }
84
+ }
85
+ }
86
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
87
+ finally {
88
+ try {
89
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
90
+ }
91
+ finally { if (e_2) throw e_2.error; }
92
+ }
93
+ return false;
94
+ };
95
+ exports.hasValue = hasValue;
96
+ var setValue = function (map, mapKey, mapValue) {
97
+ var e_3, _a;
98
+ try {
99
+ for (var _b = __values(map.value.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
100
+ var key = _c.value;
101
+ if (key.value === mapKey.value) {
102
+ map.value.set(key, mapValue);
103
+ return;
104
+ }
105
+ }
106
+ }
107
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
108
+ finally {
109
+ try {
110
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
111
+ }
112
+ finally { if (e_3) throw e_3.error; }
113
+ }
114
+ map.value.set(mapKey, mapValue);
115
+ };
116
+ exports.setValue = setValue;
117
+ var CustomMapIterator = /** @class */ (function () {
118
+ function CustomMapIterator(value) {
119
+ var me = this;
120
+ me.value = value;
121
+ me.index = 0;
122
+ }
123
+ CustomMapIterator.prototype.next = function () {
124
+ var me = this;
125
+ var keys = Array.from(me.value.keys());
126
+ if (me.index === keys.length) {
127
+ return {
128
+ value: new nil_1.default(),
129
+ done: true
130
+ };
131
+ }
132
+ var key = keys[me.index++];
133
+ return {
134
+ value: new CustomMap(new Map([
135
+ [new string_1.default('key'), key],
136
+ [new string_1.default('value'), me.value.get(key)]
137
+ ])),
138
+ done: false
139
+ };
140
+ };
141
+ return CustomMapIterator;
142
+ }());
143
+ exports.CustomMapIterator = CustomMapIterator;
144
+ var CustomMap = /** @class */ (function (_super) {
145
+ __extends(CustomMap, _super);
146
+ function CustomMap(value) {
147
+ if (value === void 0) { value = new Map(); }
148
+ var _this = _super.call(this) || this;
149
+ _this.isInstance = false;
150
+ _this.value = new Map(value);
151
+ return _this;
152
+ }
153
+ CustomMap.getIntrinsics = function () {
154
+ return this.intrinsics;
155
+ };
156
+ CustomMap.addIntrinsic = function (name, fn) {
157
+ this.intrinsics.add(name, fn);
158
+ };
159
+ CustomMap.prototype.getCustomType = function () {
160
+ if ((0, exports.hasValue)(this, exports.CLASS_ID_PROPERTY)) {
161
+ return (0, exports.getValue)(this, exports.CLASS_ID_PROPERTY).toString();
162
+ }
163
+ return 'map';
164
+ };
165
+ CustomMap.prototype.toString = function () {
166
+ var e_4, _a;
167
+ var values = [];
168
+ try {
169
+ for (var _b = __values(this.value), _c = _b.next(); !_c.done; _c = _b.next()) {
170
+ var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
171
+ values.push("".concat(key, ": ").concat(value.toString()));
172
+ }
173
+ }
174
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
175
+ finally {
176
+ try {
177
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
178
+ }
179
+ finally { if (e_4) throw e_4.error; }
180
+ }
181
+ return "{ ".concat(values.join(', '), " }");
182
+ };
183
+ CustomMap.prototype.fork = function () {
184
+ return new CustomMap(this.value);
185
+ };
186
+ CustomMap.prototype.toNumber = function () {
187
+ return 0;
188
+ };
189
+ CustomMap.prototype.toInt = function () {
190
+ return 0;
191
+ };
192
+ CustomMap.prototype.toTruthy = function () {
193
+ return this.value.size > 0;
194
+ };
195
+ CustomMap.prototype[Symbol.iterator] = function () {
196
+ return new CustomMapIterator(this.value);
197
+ };
198
+ CustomMap.prototype.extend = function (map) {
199
+ var e_5, _a;
200
+ if (map instanceof CustomMap) {
201
+ map = map.value;
202
+ }
203
+ try {
204
+ for (var map_1 = __values(map), map_1_1 = map_1.next(); !map_1_1.done; map_1_1 = map_1.next()) {
205
+ var _b = __read(map_1_1.value, 2), key = _b[0], value = _b[1];
206
+ (0, exports.setValue)(this, key, value);
207
+ }
208
+ }
209
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
210
+ finally {
211
+ try {
212
+ if (map_1_1 && !map_1_1.done && (_a = map_1.return)) _a.call(map_1);
213
+ }
214
+ finally { if (e_5) throw e_5.error; }
215
+ }
216
+ return this;
217
+ };
218
+ CustomMap.prototype.has = function (path) {
219
+ if (path instanceof generics_1.CustomValue) {
220
+ return this.has(new path_1.default([path]));
221
+ }
222
+ var traversalPath = path.clone();
223
+ var current = traversalPath.next();
224
+ if (current !== null) {
225
+ if ((0, exports.hasValue)(this, current)) {
226
+ var sub = (0, exports.getValue)(this, current);
227
+ if (traversalPath.count() > 0 &&
228
+ sub instanceof generics_1.CustomValueWithIntrinsics) {
229
+ return sub.has(traversalPath);
230
+ }
231
+ return traversalPath.count() === 0;
232
+ }
233
+ }
234
+ return false;
235
+ };
236
+ CustomMap.prototype.set = function (path, newValue) {
237
+ if (path instanceof generics_1.CustomValue) {
238
+ return this.set(new path_1.default([path]), newValue);
239
+ }
240
+ var traversalPath = path.clone();
241
+ var last = traversalPath.last();
242
+ var current = traversalPath.next();
243
+ if (current !== null) {
244
+ if ((0, exports.hasValue)(this, current)) {
245
+ var sub = (0, exports.getValue)(this, current);
246
+ if (sub instanceof generics_1.CustomValueWithIntrinsics) {
247
+ sub.set(traversalPath, newValue);
248
+ return;
249
+ }
250
+ }
251
+ throw new Error("Cannot set path ".concat(path.toString(), "."));
252
+ }
253
+ (0, exports.setValue)(this, last, newValue);
254
+ };
255
+ CustomMap.prototype.get = function (path) {
256
+ if (path instanceof generics_1.CustomValue) {
257
+ return this.get(new path_1.default([path]));
258
+ }
259
+ var traversalPath = path.clone();
260
+ var current = traversalPath.next();
261
+ if (current !== null) {
262
+ if ((0, exports.hasValue)(this, current)) {
263
+ var sub = (0, exports.getValue)(this, current);
264
+ if (traversalPath.count() > 0) {
265
+ if (sub instanceof generics_1.CustomValueWithIntrinsics) {
266
+ return sub.get(traversalPath);
267
+ }
268
+ }
269
+ else if (traversalPath.count() === 0) {
270
+ return sub;
271
+ }
272
+ }
273
+ else if (path.count() === 1 && CustomMap.getIntrinsics().has(current.toString())) {
274
+ return CustomMap.getIntrinsics().get(current.toString());
275
+ }
276
+ }
277
+ throw new Error("Unknown path in map ".concat(path.toString(), "."));
278
+ };
279
+ CustomMap.prototype.createInstance = function () {
280
+ var newInstance = new CustomMap(this.value);
281
+ newInstance.isInstance = true;
282
+ return newInstance;
283
+ };
284
+ CustomMap.intrinsics = new intrinsics_container_1.default();
285
+ return CustomMap;
286
+ }(generics_1.CustomObject));
287
+ exports.default = CustomMap;
@@ -1,10 +1,10 @@
1
- import { CustomValue } from './generics';
2
- export default class CustomNil extends CustomValue {
3
- value: null;
4
- getCustomType(): string;
5
- toString(): string;
6
- fork(): CustomNil;
7
- toNumber(): number;
8
- toInt(): number;
9
- toTruthy(): boolean;
10
- }
1
+ import { CustomValue } from './generics';
2
+ export default class CustomNil extends CustomValue {
3
+ value: null;
4
+ getCustomType(): string;
5
+ toString(): string;
6
+ fork(): CustomNil;
7
+ toNumber(): number;
8
+ toInt(): number;
9
+ toTruthy(): boolean;
10
+ }