@mojir/lits 2.1.2 → 2.1.4

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/dist/index.esm.js CHANGED
@@ -93,9 +93,15 @@ function getCodeMarker(sourceCodeInfo) {
93
93
  }
94
94
 
95
95
  function getLitsErrorMessage(message, sourceCodeInfo) {
96
- var filePathLine = (sourceCodeInfo === null || sourceCodeInfo === void 0 ? void 0 : sourceCodeInfo.filePath) ? "\n".concat(sourceCodeInfo.filePath) : '';
97
- var codeLine = (sourceCodeInfo === null || sourceCodeInfo === void 0 ? void 0 : sourceCodeInfo.code) ? "\n".concat(sourceCodeInfo.code) : '';
98
- var codeMarker = sourceCodeInfo && codeLine ? "\n".concat(getCodeMarker(sourceCodeInfo)) : '';
96
+ if (!sourceCodeInfo) {
97
+ return message;
98
+ }
99
+ var location = "".concat(sourceCodeInfo.position.line, ":").concat(sourceCodeInfo.position.column);
100
+ var filePathLine = sourceCodeInfo.filePath
101
+ ? "\n".concat(sourceCodeInfo.filePath, ":").concat(location)
102
+ : "\nLocation ".concat(location);
103
+ var codeLine = "\n".concat(sourceCodeInfo.code);
104
+ var codeMarker = "\n".concat(getCodeMarker(sourceCodeInfo));
99
105
  return "".concat(message).concat(filePathLine).concat(codeLine).concat(codeMarker);
100
106
  }
101
107
  var RecurSignal = /** @class */ (function (_super) {
@@ -208,6 +214,7 @@ var functionTypes = [
208
214
  'SomePred',
209
215
  'Fnull',
210
216
  'Builtin',
217
+ 'SpecialBuiltin',
211
218
  'NativeJsFunction',
212
219
  ];
213
220
  var functionTypeSet = new Set(functionTypes);
@@ -1255,26 +1262,37 @@ var sequenceNormalExpression = {
1255
1262
  paramCount: 1,
1256
1263
  },
1257
1264
  'map': {
1258
- evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
1259
- var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
1260
- var executeFunction = _b.executeFunction;
1261
- assertSeq(seq, sourceCodeInfo);
1262
- assertLitsFunction(fn, sourceCodeInfo);
1263
- if (Array.isArray(seq)) {
1264
- return seq.map(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); });
1265
+ evaluate: function (params, sourceCodeInfo, contextStack, _a) {
1266
+ var executeFunction = _a.executeFunction;
1267
+ var fn = asLitsFunction(params.at(-1));
1268
+ var seqs = params.slice(0, -1);
1269
+ assertSeq(seqs[0], sourceCodeInfo);
1270
+ var isString = typeof seqs[0] === 'string';
1271
+ var len = seqs[0].length;
1272
+ seqs.slice(1).forEach(function (seq) {
1273
+ if (isString) {
1274
+ assertString(seq, sourceCodeInfo);
1275
+ }
1276
+ else {
1277
+ assertArray(seq, sourceCodeInfo);
1278
+ }
1279
+ len = Math.min(len, seq.length);
1280
+ });
1281
+ var paramArray = [];
1282
+ var _loop_1 = function (i) {
1283
+ paramArray.push(seqs.map(function (seq) { return seq[i]; }));
1284
+ };
1285
+ for (var i = 0; i < len; i++) {
1286
+ _loop_1(i);
1265
1287
  }
1266
- else {
1267
- return seq
1268
- .split('')
1269
- .map(function (elem) {
1270
- var newVal = executeFunction(fn, [elem], contextStack, sourceCodeInfo);
1271
- assertString(newVal, sourceCodeInfo, { char: true });
1272
- return newVal;
1273
- })
1274
- .join('');
1288
+ var mapped = paramArray.map(function (p) { return executeFunction(fn, p, contextStack, sourceCodeInfo); });
1289
+ if (!isString) {
1290
+ return mapped;
1275
1291
  }
1292
+ mapped.forEach(function (char) { return assertString(char, sourceCodeInfo); });
1293
+ return mapped.join('');
1276
1294
  },
1277
- paramCount: 2,
1295
+ paramCount: { min: 2 },
1278
1296
  },
1279
1297
  'pop': {
1280
1298
  evaluate: function (_a, sourceCodeInfo) {
@@ -1824,7 +1842,7 @@ var sequenceNormalExpression = {
1824
1842
  assertSeq(input, sourceCodeInfo);
1825
1843
  if (Array.isArray(input)) {
1826
1844
  var result = [];
1827
- var _loop_1 = function (item) {
1845
+ var _loop_2 = function (item) {
1828
1846
  assertAny(item, sourceCodeInfo);
1829
1847
  if (!result.some(function (existingItem) { return deepEqual(existingItem, item, sourceCodeInfo); })) {
1830
1848
  result.push(item);
@@ -1833,7 +1851,7 @@ var sequenceNormalExpression = {
1833
1851
  try {
1834
1852
  for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
1835
1853
  var item = input_1_1.value;
1836
- _loop_1(item);
1854
+ _loop_2(item);
1837
1855
  }
1838
1856
  }
1839
1857
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -3669,6 +3687,26 @@ var andSpecialExpression = {
3669
3687
  }
3670
3688
  return value;
3671
3689
  },
3690
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
3691
+ var e_2, _a;
3692
+ var value = true;
3693
+ try {
3694
+ for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
3695
+ var param = params_1_1.value;
3696
+ value = asAny(param, sourceCodeInfo);
3697
+ if (!value)
3698
+ break;
3699
+ }
3700
+ }
3701
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
3702
+ finally {
3703
+ try {
3704
+ if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
3705
+ }
3706
+ finally { if (e_2) throw e_2.error; }
3707
+ }
3708
+ return value;
3709
+ },
3672
3710
  getUndefinedSymbols: function (node, contextStack, _a) {
3673
3711
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
3674
3712
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -3953,7 +3991,7 @@ var defSpecialExpression = {
3953
3991
  var value = bindingNode[1][1];
3954
3992
  var bindingValue = evaluateNode(value, contextStack);
3955
3993
  var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
3956
- contextStack.exportValues(values);
3994
+ contextStack.exportValues(values, target[2]);
3957
3995
  return null;
3958
3996
  },
3959
3997
  getUndefinedSymbols: function (node, contextStack, _a) {
@@ -3965,7 +4003,7 @@ var defSpecialExpression = {
3965
4003
  walkDefaults(target, function (defaultNode) {
3966
4004
  addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
3967
4005
  });
3968
- contextStack.addValues(getAllBindingTargetNames(target));
4006
+ contextStack.addValues(getAllBindingTargetNames(target), target[2]);
3969
4007
  return bindingResult;
3970
4008
  },
3971
4009
  };
@@ -4108,14 +4146,14 @@ var functionSpecialExpression = {
4108
4146
  _b.name = functionSymbol[1],
4109
4147
  _b.evaluatedfunction = evaluatedFunction,
4110
4148
  _b);
4111
- contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
4149
+ contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
4112
4150
  return null;
4113
4151
  },
4114
4152
  getUndefinedSymbols: function (node, contextStack, _a) {
4115
4153
  var _b, _c;
4116
4154
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4117
4155
  var functionName = node[1][1][1];
4118
- contextStack.addValues((_b = {}, _b[functionName] = true, _b));
4156
+ contextStack.addValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
4119
4157
  var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
4120
4158
  return getFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
4121
4159
  },
@@ -4136,7 +4174,7 @@ var defnSpecialExpression = {
4136
4174
  _b.name = functionSymbol[1],
4137
4175
  _b.evaluatedfunction = evaluatedFunctionOverloades,
4138
4176
  _b);
4139
- contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
4177
+ contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
4140
4178
  return null;
4141
4179
  },
4142
4180
  getUndefinedSymbols: function (node, contextStack, _a) {
@@ -4144,7 +4182,7 @@ var defnSpecialExpression = {
4144
4182
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4145
4183
  var functionName = node[1][1][1];
4146
4184
  var fn = node[1][2];
4147
- contextStack.exportValues((_b = {}, _b[functionName] = true, _b));
4185
+ contextStack.exportValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
4148
4186
  var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
4149
4187
  return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
4150
4188
  },
@@ -4256,7 +4294,7 @@ var letSpecialExpression = {
4256
4294
  var value = bindingNode[1][1];
4257
4295
  var bindingValue = evaluateNode(value, contextStack);
4258
4296
  var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
4259
- contextStack.addValues(values);
4297
+ contextStack.addValues(values, target[2]);
4260
4298
  return null;
4261
4299
  },
4262
4300
  getUndefinedSymbols: function (node, contextStack, _a) {
@@ -4268,7 +4306,7 @@ var letSpecialExpression = {
4268
4306
  walkDefaults(target, function (defaultNode) {
4269
4307
  addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
4270
4308
  });
4271
- contextStack.addValues(getAllBindingTargetNames(target));
4309
+ contextStack.addValues(getAllBindingTargetNames(target), target[2]);
4272
4310
  return bindingResult;
4273
4311
  },
4274
4312
  };
@@ -4539,6 +4577,26 @@ var orSpecialExpression = {
4539
4577
  }
4540
4578
  return value;
4541
4579
  },
4580
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4581
+ var e_2, _a;
4582
+ var value = false;
4583
+ try {
4584
+ for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
4585
+ var param = params_1_1.value;
4586
+ value = asAny(param, sourceCodeInfo);
4587
+ if (value)
4588
+ break;
4589
+ }
4590
+ }
4591
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
4592
+ finally {
4593
+ try {
4594
+ if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
4595
+ }
4596
+ finally { if (e_2) throw e_2.error; }
4597
+ }
4598
+ return value;
4599
+ },
4542
4600
  getUndefinedSymbols: function (node, contextStack, _a) {
4543
4601
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4544
4602
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -4557,6 +4615,11 @@ var qqSpecialExpression = {
4557
4615
  var firstResult = evaluateNode(firstNode, contextStack);
4558
4616
  return firstResult !== null && firstResult !== void 0 ? firstResult : (secondNode ? evaluateNode(secondNode, contextStack) : null);
4559
4617
  },
4618
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4619
+ var firstParam = asAny(params[0], sourceCodeInfo);
4620
+ var secondParam = params[1] !== undefined ? asAny(params[1], sourceCodeInfo) : null;
4621
+ return firstParam !== null && firstParam !== void 0 ? firstParam : secondParam;
4622
+ },
4560
4623
  getUndefinedSymbols: function (node, contextStack, _a) {
4561
4624
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4562
4625
  return getUndefinedSymbols(node[1][1].filter(function (n) { return !!n; }), contextStack, builtin, evaluateNode);
@@ -4571,6 +4634,9 @@ var recurSpecialExpression = {
4571
4634
  var evaluatedParams = params.map(function (paramNode) { return evaluateNode(paramNode, contextStack); });
4572
4635
  throw new RecurSignal(evaluatedParams);
4573
4636
  },
4637
+ evaluateAsNormalExpression: function (params) {
4638
+ throw new RecurSignal(params);
4639
+ },
4574
4640
  getUndefinedSymbols: function (node, contextStack, _a) {
4575
4641
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4576
4642
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -4586,6 +4652,12 @@ var throwSpecialExpression = {
4586
4652
  });
4587
4653
  throw new UserDefinedError(message, node[2]);
4588
4654
  },
4655
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4656
+ var message = asString(params[0], sourceCodeInfo, {
4657
+ nonEmpty: true,
4658
+ });
4659
+ throw new UserDefinedError(message, undefined);
4660
+ },
4589
4661
  getUndefinedSymbols: function (node, contextStack, _a) {
4590
4662
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4591
4663
  return getUndefinedSymbols([node[1][1]], contextStack, builtin, evaluateNode);
@@ -4653,6 +4725,24 @@ var arraySpecialExpression = {
4653
4725
  }
4654
4726
  return result;
4655
4727
  },
4728
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4729
+ var e_2, _a;
4730
+ var result = [];
4731
+ try {
4732
+ for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
4733
+ var param = params_1_1.value;
4734
+ result.push(asAny(param, sourceCodeInfo));
4735
+ }
4736
+ }
4737
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
4738
+ finally {
4739
+ try {
4740
+ if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
4741
+ }
4742
+ finally { if (e_2) throw e_2.error; }
4743
+ }
4744
+ return result;
4745
+ },
4656
4746
  getUndefinedSymbols: function (node, contextStack, _a) {
4657
4747
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4658
4748
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -4684,6 +4774,16 @@ var objectSpecialExpression = {
4684
4774
  }
4685
4775
  return result;
4686
4776
  },
4777
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4778
+ var result = {};
4779
+ for (var i = 0; i < params.length; i += 2) {
4780
+ var key = params[i];
4781
+ var value = params[i + 1];
4782
+ assertString(key, sourceCodeInfo);
4783
+ result[key] = value !== null && value !== void 0 ? value : null;
4784
+ }
4785
+ return result;
4786
+ },
4687
4787
  getUndefinedSymbols: function (node, contextStack, _a) {
4688
4788
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4689
4789
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -4809,7 +4909,7 @@ function findUnresolvedSymbolsInNode(node, contextStack, builtin, evaluateNode)
4809
4909
  return findUnresolvedSymbolsInNode(node[1], contextStack, builtin, evaluateNode);
4810
4910
  /* v8 ignore next 2 */
4811
4911
  default:
4812
- throw new Error("Unhandled node type: ".concat(nodeType));
4912
+ throw new LitsError("Unhandled node type: ".concat(nodeType), node[2]);
4813
4913
  }
4814
4914
  }
4815
4915
 
@@ -5017,6 +5117,16 @@ var functionExecutors = {
5017
5117
  var normalExpression = asNonUndefined(allNormalExpressions[fn.normalBuitinSymbolType], sourceCodeInfo);
5018
5118
  return normalExpression.evaluate(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
5019
5119
  },
5120
+ SpecialBuiltin: function (fn, params, sourceCodeInfo, contextStack, _a) {
5121
+ var executeFunction = _a.executeFunction;
5122
+ var specialExpression = asNonUndefined(specialExpressions[fn.specialBuiltinSymbolType], sourceCodeInfo);
5123
+ if (specialExpression.evaluateAsNormalExpression) {
5124
+ return specialExpression.evaluateAsNormalExpression(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
5125
+ }
5126
+ else {
5127
+ throw new LitsError("Special builtin function ".concat(fn.specialBuiltinSymbolType, " is not supported as normal expression."), sourceCodeInfo);
5128
+ }
5129
+ },
5020
5130
  };
5021
5131
 
5022
5132
  function evaluate(ast, contextStack) {
@@ -5072,7 +5182,21 @@ function evaluateReservedSymbol(node) {
5072
5182
  function evaluateNormalExpression(node, contextStack) {
5073
5183
  var sourceCodeInfo = node[2];
5074
5184
  var paramNodes = node[1][1];
5075
- var params = paramNodes.map(function (paramNode) { return evaluateNode(paramNode, contextStack); });
5185
+ var params = [];
5186
+ paramNodes.forEach(function (paramNode) {
5187
+ if (isSpreadNode(paramNode)) {
5188
+ var spreadValue = evaluateNode(paramNode[1], contextStack);
5189
+ if (Array.isArray(spreadValue)) {
5190
+ params.push.apply(params, __spreadArray([], __read(spreadValue), false));
5191
+ }
5192
+ else {
5193
+ throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
5194
+ }
5195
+ }
5196
+ else {
5197
+ params.push(evaluateNode(paramNode, contextStack));
5198
+ }
5199
+ });
5076
5200
  if (isNormalExpressionNodeWithName(node)) {
5077
5201
  var nameSymbol = node[1][0];
5078
5202
  if (isNormalBuiltinSymbolNode(nameSymbol)) {
@@ -5174,19 +5298,19 @@ var ContextStackImpl = /** @class */ (function () {
5174
5298
  var contexts = [{}, context];
5175
5299
  return new ContextStackImpl({ contexts: contexts });
5176
5300
  };
5177
- ContextStackImpl.prototype.exportValues = function (values) {
5301
+ ContextStackImpl.prototype.exportValues = function (values, sourceCodeInfo) {
5178
5302
  var e_1, _a;
5179
5303
  try {
5180
5304
  for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
5181
5305
  var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
5182
5306
  if (this.globalContext[name_1]) {
5183
- throw new Error("Cannot redefine exported value \"".concat(name_1, "\""));
5307
+ throw new LitsError("Cannot redefine exported value \"".concat(name_1, "\""), sourceCodeInfo);
5184
5308
  }
5185
5309
  if (specialExpressionKeys.includes(name_1)) {
5186
- throw new Error("Cannot shadow special expression \"".concat(name_1, "\""));
5310
+ throw new LitsError("Cannot shadow special expression \"".concat(name_1, "\""), sourceCodeInfo);
5187
5311
  }
5188
5312
  if (normalExpressionKeys.includes(name_1)) {
5189
- throw new Error("Cannot shadow builtin function \"".concat(name_1, "\""));
5313
+ throw new LitsError("Cannot shadow builtin function \"".concat(name_1, "\""), sourceCodeInfo);
5190
5314
  }
5191
5315
  this.globalContext[name_1] = { value: value };
5192
5316
  }
@@ -5198,22 +5322,22 @@ var ContextStackImpl = /** @class */ (function () {
5198
5322
  }
5199
5323
  finally { if (e_1) throw e_1.error; }
5200
5324
  }
5201
- this.addValues(values);
5325
+ this.addValues(values, sourceCodeInfo);
5202
5326
  };
5203
- ContextStackImpl.prototype.addValues = function (values) {
5327
+ ContextStackImpl.prototype.addValues = function (values, sourceCodeInfo) {
5204
5328
  var e_2, _a;
5205
5329
  var currentContext = this.contexts[0];
5206
5330
  try {
5207
5331
  for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
5208
5332
  var _d = __read(_c.value, 2), name_2 = _d[0], value = _d[1];
5209
5333
  if (currentContext[name_2]) {
5210
- throw new Error("Cannot redefine value \"".concat(name_2, "\""));
5334
+ throw new LitsError("Cannot redefine value \"".concat(name_2, "\""), sourceCodeInfo);
5211
5335
  }
5212
5336
  if (specialExpressionKeys.includes(name_2)) {
5213
- throw new Error("Cannot shadow special expression \"".concat(name_2, "\""));
5337
+ throw new LitsError("Cannot shadow special expression \"".concat(name_2, "\""), sourceCodeInfo);
5214
5338
  }
5215
5339
  if (normalExpressionKeys.includes(name_2)) {
5216
- throw new Error("Cannot shadow builtin function \"".concat(name_2, "\""));
5340
+ throw new LitsError("Cannot shadow builtin function \"".concat(name_2, "\""), sourceCodeInfo);
5217
5341
  }
5218
5342
  currentContext[name_2] = { value: toAny(value) };
5219
5343
  }
@@ -5293,18 +5417,36 @@ var ContextStackImpl = /** @class */ (function () {
5293
5417
  return null;
5294
5418
  };
5295
5419
  ContextStackImpl.prototype.evaluateSymbol = function (node) {
5296
- var _a;
5420
+ var _a, _b;
5297
5421
  if (isSpecialBuiltinSymbolNode(node)) {
5298
- throw new Error('Special builtin symbols should not be evaluated');
5422
+ var functionType = node[1];
5423
+ switch (functionType) {
5424
+ case specialExpressionTypes['&&']:
5425
+ case specialExpressionTypes['||']:
5426
+ case specialExpressionTypes.array:
5427
+ case specialExpressionTypes.object:
5428
+ case specialExpressionTypes['defined?']:
5429
+ case specialExpressionTypes.recur:
5430
+ case specialExpressionTypes.throw:
5431
+ case specialExpressionTypes['??']:
5432
+ return _a = {},
5433
+ _a[FUNCTION_SYMBOL] = true,
5434
+ _a.functionType = 'SpecialBuiltin',
5435
+ _a.specialBuiltinSymbolType = functionType,
5436
+ _a.sourceCodeInfo = node[2],
5437
+ _a;
5438
+ default:
5439
+ throw new LitsError("Unknown special builtin symbol type: ".concat(functionType), node[2]);
5440
+ }
5299
5441
  }
5300
5442
  if (isNormalBuiltinSymbolNode(node)) {
5301
5443
  var type = node[1];
5302
- return _a = {},
5303
- _a[FUNCTION_SYMBOL] = true,
5304
- _a.functionType = 'Builtin',
5305
- _a.normalBuitinSymbolType = type,
5306
- _a.sourceCodeInfo = node[2],
5307
- _a;
5444
+ return _b = {},
5445
+ _b[FUNCTION_SYMBOL] = true,
5446
+ _b.functionType = 'Builtin',
5447
+ _b.normalBuitinSymbolType = type,
5448
+ _b.sourceCodeInfo = node[2],
5449
+ _b;
5308
5450
  }
5309
5451
  var lookUpResult = this.lookUp(node);
5310
5452
  if (isContextEntry(lookUpResult))
@@ -5976,7 +6118,7 @@ function withSourceCodeInfo(node, sourceCodeInfo) {
5976
6118
  }
5977
6119
  return node;
5978
6120
  }
5979
- function getPrecedence(operatorSign) {
6121
+ function getPrecedence(operatorSign, sourceCodeInfo) {
5980
6122
  switch (operatorSign) {
5981
6123
  case '**': // exponentiation
5982
6124
  return exponentiationPrecedence;
@@ -6015,7 +6157,7 @@ function getPrecedence(operatorSign) {
6015
6157
  // leave room for binaryFunctionalOperatorPrecedence = 1
6016
6158
  /* v8 ignore next 2 */
6017
6159
  default:
6018
- throw new Error("Unknown binary operator: ".concat(operatorSign));
6160
+ throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
6019
6161
  }
6020
6162
  }
6021
6163
  function createNamedNormalExpressionNode(symbolNode, params, sourceCodeInfo) {
@@ -6148,7 +6290,7 @@ var Parser = /** @class */ (function () {
6148
6290
  while (!this.isAtExpressionEnd()) {
6149
6291
  if (isA_BinaryOperatorToken(operator)) {
6150
6292
  var name_1 = operator[1];
6151
- var newPrecedece = getPrecedence(name_1);
6293
+ var newPrecedece = getPrecedence(name_1, operator[2]);
6152
6294
  if (newPrecedece <= precedence
6153
6295
  // ** (exponentiation) is right associative
6154
6296
  && !(newPrecedece === exponentiationPrecedence && precedence === exponentiationPrecedence)) {
@@ -6228,7 +6370,7 @@ var Parser = /** @class */ (function () {
6228
6370
  this.advance();
6229
6371
  var expression = this.parseExpression();
6230
6372
  if (!isRParenToken(this.peek())) {
6231
- throw new Error('Expected closing parenthesis');
6373
+ throw new LitsError('Expected closing parenthesis', this.peek()[2]);
6232
6374
  }
6233
6375
  this.advance();
6234
6376
  return expression;
@@ -6350,7 +6492,13 @@ var Parser = /** @class */ (function () {
6350
6492
  this.advance();
6351
6493
  var params = [];
6352
6494
  while (!this.isAtEnd() && !isRParenToken(this.peek())) {
6353
- params.push(this.parseExpression());
6495
+ if (isOperatorToken(this.peek(), '...')) {
6496
+ this.advance();
6497
+ params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peek()[2]));
6498
+ }
6499
+ else {
6500
+ params.push(this.parseExpression());
6501
+ }
6354
6502
  var nextToken = this.peek();
6355
6503
  if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
6356
6504
  throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
@@ -6406,7 +6554,7 @@ var Parser = /** @class */ (function () {
6406
6554
  throw new LitsError("".concat(type, " is not allowed"), symbol[2]);
6407
6555
  /* v8 ignore next 2 */
6408
6556
  default:
6409
- throw new Error("Unknown special expression: ".concat(type));
6557
+ throw new LitsError("Unknown special expression: ".concat(type), symbol[2]);
6410
6558
  }
6411
6559
  }
6412
6560
  else if (isNormalBuiltinSymbolNode(symbol) || isNormalBuiltinSymbolNode(symbol)) {
@@ -11164,19 +11312,23 @@ var sequenceReference = {
11164
11312
  type: 'any',
11165
11313
  rest: true,
11166
11314
  },
11167
- args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { seq: {
11315
+ args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { seqs: {
11168
11316
  type: 'sequence',
11317
+ rest: true,
11318
+ description: 'At least one.',
11169
11319
  }, fun: {
11170
11320
  type: 'function',
11171
11321
  } }),
11172
11322
  variants: [
11173
- { argumentNames: ['seq', 'fun'] },
11323
+ { argumentNames: ['seqs', 'fun'] },
11174
11324
  ],
11175
- description: 'Creates a new array populated with the results of calling $fun on every elements in $seq.',
11325
+ description: 'Creates a new array populated with the results of calling $fun on every element in $seqs.',
11176
11326
  examples: [
11327
+ '[1, 2, 3] map -',
11177
11328
  '[1, 2, 3] map -> -($)',
11178
11329
  'map(["Albert", "Mojir", 42], str)',
11179
11330
  'map([1, 2, 3], inc)',
11331
+ 'map([1, 2, 3], [1, 10, 100], *)',
11180
11332
  ],
11181
11333
  },
11182
11334
  'filter': {