@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/cli/cli.js CHANGED
@@ -92,7 +92,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
92
92
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
93
93
  };
94
94
 
95
- var version = "2.1.2";
95
+ var version = "2.1.4";
96
96
 
97
97
  function getCodeMarker(sourceCodeInfo) {
98
98
  if (!sourceCodeInfo.position || !sourceCodeInfo.code)
@@ -103,9 +103,15 @@ function getCodeMarker(sourceCodeInfo) {
103
103
  }
104
104
 
105
105
  function getLitsErrorMessage(message, sourceCodeInfo) {
106
- var filePathLine = (sourceCodeInfo === null || sourceCodeInfo === void 0 ? void 0 : sourceCodeInfo.filePath) ? "\n".concat(sourceCodeInfo.filePath) : '';
107
- var codeLine = (sourceCodeInfo === null || sourceCodeInfo === void 0 ? void 0 : sourceCodeInfo.code) ? "\n".concat(sourceCodeInfo.code) : '';
108
- var codeMarker = sourceCodeInfo && codeLine ? "\n".concat(getCodeMarker(sourceCodeInfo)) : '';
106
+ if (!sourceCodeInfo) {
107
+ return message;
108
+ }
109
+ var location = "".concat(sourceCodeInfo.position.line, ":").concat(sourceCodeInfo.position.column);
110
+ var filePathLine = sourceCodeInfo.filePath
111
+ ? "\n".concat(sourceCodeInfo.filePath, ":").concat(location)
112
+ : "\nLocation ".concat(location);
113
+ var codeLine = "\n".concat(sourceCodeInfo.code);
114
+ var codeMarker = "\n".concat(getCodeMarker(sourceCodeInfo));
109
115
  return "".concat(message).concat(filePathLine).concat(codeLine).concat(codeMarker);
110
116
  }
111
117
  var RecurSignal = /** @class */ (function (_super) {
@@ -240,6 +246,7 @@ var functionTypes = [
240
246
  'SomePred',
241
247
  'Fnull',
242
248
  'Builtin',
249
+ 'SpecialBuiltin',
243
250
  'NativeJsFunction',
244
251
  ];
245
252
  var functionTypeSet = new Set(functionTypes);
@@ -411,7 +418,7 @@ function findUnresolvedSymbolsInNode(node, contextStack, builtin, evaluateNode)
411
418
  return findUnresolvedSymbolsInNode(node[1], contextStack, builtin, evaluateNode);
412
419
  /* v8 ignore next 2 */
413
420
  default:
414
- throw new Error("Unhandled node type: ".concat(nodeType));
421
+ throw new LitsError("Unhandled node type: ".concat(nodeType), node[2]);
415
422
  }
416
423
  }
417
424
 
@@ -689,6 +696,10 @@ function isLitsFunction(value) {
689
696
  return false;
690
697
  return !!value[FUNCTION_SYMBOL];
691
698
  }
699
+ function asLitsFunction(value, sourceCodeInfo) {
700
+ assertLitsFunction(value, sourceCodeInfo);
701
+ return value;
702
+ }
692
703
  function assertLitsFunction(value, sourceCodeInfo) {
693
704
  if (!isLitsFunction(value))
694
705
  throw getAssertionError('LitsFunction', value, sourceCodeInfo);
@@ -1377,26 +1388,37 @@ var sequenceNormalExpression = {
1377
1388
  paramCount: 1,
1378
1389
  },
1379
1390
  'map': {
1380
- evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
1381
- var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
1382
- var executeFunction = _b.executeFunction;
1383
- assertSeq(seq, sourceCodeInfo);
1384
- assertLitsFunction(fn, sourceCodeInfo);
1385
- if (Array.isArray(seq)) {
1386
- return seq.map(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); });
1391
+ evaluate: function (params, sourceCodeInfo, contextStack, _a) {
1392
+ var executeFunction = _a.executeFunction;
1393
+ var fn = asLitsFunction(params.at(-1));
1394
+ var seqs = params.slice(0, -1);
1395
+ assertSeq(seqs[0], sourceCodeInfo);
1396
+ var isString = typeof seqs[0] === 'string';
1397
+ var len = seqs[0].length;
1398
+ seqs.slice(1).forEach(function (seq) {
1399
+ if (isString) {
1400
+ assertString(seq, sourceCodeInfo);
1401
+ }
1402
+ else {
1403
+ assertArray(seq, sourceCodeInfo);
1404
+ }
1405
+ len = Math.min(len, seq.length);
1406
+ });
1407
+ var paramArray = [];
1408
+ var _loop_1 = function (i) {
1409
+ paramArray.push(seqs.map(function (seq) { return seq[i]; }));
1410
+ };
1411
+ for (var i = 0; i < len; i++) {
1412
+ _loop_1(i);
1387
1413
  }
1388
- else {
1389
- return seq
1390
- .split('')
1391
- .map(function (elem) {
1392
- var newVal = executeFunction(fn, [elem], contextStack, sourceCodeInfo);
1393
- assertString(newVal, sourceCodeInfo, { char: true });
1394
- return newVal;
1395
- })
1396
- .join('');
1414
+ var mapped = paramArray.map(function (p) { return executeFunction(fn, p, contextStack, sourceCodeInfo); });
1415
+ if (!isString) {
1416
+ return mapped;
1397
1417
  }
1418
+ mapped.forEach(function (char) { return assertString(char, sourceCodeInfo); });
1419
+ return mapped.join('');
1398
1420
  },
1399
- paramCount: 2,
1421
+ paramCount: { min: 2 },
1400
1422
  },
1401
1423
  'pop': {
1402
1424
  evaluate: function (_a, sourceCodeInfo) {
@@ -1946,7 +1968,7 @@ var sequenceNormalExpression = {
1946
1968
  assertSeq(input, sourceCodeInfo);
1947
1969
  if (Array.isArray(input)) {
1948
1970
  var result = [];
1949
- var _loop_1 = function (item) {
1971
+ var _loop_2 = function (item) {
1950
1972
  assertAny(item, sourceCodeInfo);
1951
1973
  if (!result.some(function (existingItem) { return deepEqual(existingItem, item, sourceCodeInfo); })) {
1952
1974
  result.push(item);
@@ -1955,7 +1977,7 @@ var sequenceNormalExpression = {
1955
1977
  try {
1956
1978
  for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
1957
1979
  var item = input_1_1.value;
1958
- _loop_1(item);
1980
+ _loop_2(item);
1959
1981
  }
1960
1982
  }
1961
1983
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -3791,6 +3813,26 @@ var andSpecialExpression = {
3791
3813
  }
3792
3814
  return value;
3793
3815
  },
3816
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
3817
+ var e_2, _a;
3818
+ var value = true;
3819
+ try {
3820
+ for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
3821
+ var param = params_1_1.value;
3822
+ value = asAny(param, sourceCodeInfo);
3823
+ if (!value)
3824
+ break;
3825
+ }
3826
+ }
3827
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
3828
+ finally {
3829
+ try {
3830
+ if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
3831
+ }
3832
+ finally { if (e_2) throw e_2.error; }
3833
+ }
3834
+ return value;
3835
+ },
3794
3836
  getUndefinedSymbols: function (node, contextStack, _a) {
3795
3837
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
3796
3838
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -4035,7 +4077,7 @@ var defSpecialExpression = {
4035
4077
  var value = bindingNode[1][1];
4036
4078
  var bindingValue = evaluateNode(value, contextStack);
4037
4079
  var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
4038
- contextStack.exportValues(values);
4080
+ contextStack.exportValues(values, target[2]);
4039
4081
  return null;
4040
4082
  },
4041
4083
  getUndefinedSymbols: function (node, contextStack, _a) {
@@ -4047,7 +4089,7 @@ var defSpecialExpression = {
4047
4089
  walkDefaults(target, function (defaultNode) {
4048
4090
  addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
4049
4091
  });
4050
- contextStack.addValues(getAllBindingTargetNames(target));
4092
+ contextStack.addValues(getAllBindingTargetNames(target), target[2]);
4051
4093
  return bindingResult;
4052
4094
  },
4053
4095
  };
@@ -4165,14 +4207,14 @@ var functionSpecialExpression = {
4165
4207
  _b.name = functionSymbol[1],
4166
4208
  _b.evaluatedfunction = evaluatedFunction,
4167
4209
  _b);
4168
- contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
4210
+ contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
4169
4211
  return null;
4170
4212
  },
4171
4213
  getUndefinedSymbols: function (node, contextStack, _a) {
4172
4214
  var _b, _c;
4173
4215
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4174
4216
  var functionName = node[1][1][1];
4175
- contextStack.addValues((_b = {}, _b[functionName] = true, _b));
4217
+ contextStack.addValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
4176
4218
  var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
4177
4219
  return getFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
4178
4220
  },
@@ -4193,7 +4235,7 @@ var defnSpecialExpression = {
4193
4235
  _b.name = functionSymbol[1],
4194
4236
  _b.evaluatedfunction = evaluatedFunctionOverloades,
4195
4237
  _b);
4196
- contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
4238
+ contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
4197
4239
  return null;
4198
4240
  },
4199
4241
  getUndefinedSymbols: function (node, contextStack, _a) {
@@ -4201,7 +4243,7 @@ var defnSpecialExpression = {
4201
4243
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4202
4244
  var functionName = node[1][1][1];
4203
4245
  var fn = node[1][2];
4204
- contextStack.exportValues((_b = {}, _b[functionName] = true, _b));
4246
+ contextStack.exportValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
4205
4247
  var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
4206
4248
  return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
4207
4249
  },
@@ -4313,7 +4355,7 @@ var letSpecialExpression = {
4313
4355
  var value = bindingNode[1][1];
4314
4356
  var bindingValue = evaluateNode(value, contextStack);
4315
4357
  var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
4316
- contextStack.addValues(values);
4358
+ contextStack.addValues(values, target[2]);
4317
4359
  return null;
4318
4360
  },
4319
4361
  getUndefinedSymbols: function (node, contextStack, _a) {
@@ -4325,7 +4367,7 @@ var letSpecialExpression = {
4325
4367
  walkDefaults(target, function (defaultNode) {
4326
4368
  addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
4327
4369
  });
4328
- contextStack.addValues(getAllBindingTargetNames(target));
4370
+ contextStack.addValues(getAllBindingTargetNames(target), target[2]);
4329
4371
  return bindingResult;
4330
4372
  },
4331
4373
  };
@@ -4596,6 +4638,26 @@ var orSpecialExpression = {
4596
4638
  }
4597
4639
  return value;
4598
4640
  },
4641
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4642
+ var e_2, _a;
4643
+ var value = false;
4644
+ try {
4645
+ for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
4646
+ var param = params_1_1.value;
4647
+ value = asAny(param, sourceCodeInfo);
4648
+ if (value)
4649
+ break;
4650
+ }
4651
+ }
4652
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
4653
+ finally {
4654
+ try {
4655
+ if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
4656
+ }
4657
+ finally { if (e_2) throw e_2.error; }
4658
+ }
4659
+ return value;
4660
+ },
4599
4661
  getUndefinedSymbols: function (node, contextStack, _a) {
4600
4662
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4601
4663
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -4614,6 +4676,11 @@ var qqSpecialExpression = {
4614
4676
  var firstResult = evaluateNode(firstNode, contextStack);
4615
4677
  return firstResult !== null && firstResult !== void 0 ? firstResult : (secondNode ? evaluateNode(secondNode, contextStack) : null);
4616
4678
  },
4679
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4680
+ var firstParam = asAny(params[0], sourceCodeInfo);
4681
+ var secondParam = params[1] !== undefined ? asAny(params[1], sourceCodeInfo) : null;
4682
+ return firstParam !== null && firstParam !== void 0 ? firstParam : secondParam;
4683
+ },
4617
4684
  getUndefinedSymbols: function (node, contextStack, _a) {
4618
4685
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4619
4686
  return getUndefinedSymbols(node[1][1].filter(function (n) { return !!n; }), contextStack, builtin, evaluateNode);
@@ -4628,6 +4695,9 @@ var recurSpecialExpression = {
4628
4695
  var evaluatedParams = params.map(function (paramNode) { return evaluateNode(paramNode, contextStack); });
4629
4696
  throw new RecurSignal(evaluatedParams);
4630
4697
  },
4698
+ evaluateAsNormalExpression: function (params) {
4699
+ throw new RecurSignal(params);
4700
+ },
4631
4701
  getUndefinedSymbols: function (node, contextStack, _a) {
4632
4702
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4633
4703
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -4643,6 +4713,12 @@ var throwSpecialExpression = {
4643
4713
  });
4644
4714
  throw new UserDefinedError(message, node[2]);
4645
4715
  },
4716
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4717
+ var message = asString(params[0], sourceCodeInfo, {
4718
+ nonEmpty: true,
4719
+ });
4720
+ throw new UserDefinedError(message, undefined);
4721
+ },
4646
4722
  getUndefinedSymbols: function (node, contextStack, _a) {
4647
4723
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4648
4724
  return getUndefinedSymbols([node[1][1]], contextStack, builtin, evaluateNode);
@@ -4710,6 +4786,24 @@ var arraySpecialExpression = {
4710
4786
  }
4711
4787
  return result;
4712
4788
  },
4789
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4790
+ var e_2, _a;
4791
+ var result = [];
4792
+ try {
4793
+ for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
4794
+ var param = params_1_1.value;
4795
+ result.push(asAny(param, sourceCodeInfo));
4796
+ }
4797
+ }
4798
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
4799
+ finally {
4800
+ try {
4801
+ if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
4802
+ }
4803
+ finally { if (e_2) throw e_2.error; }
4804
+ }
4805
+ return result;
4806
+ },
4713
4807
  getUndefinedSymbols: function (node, contextStack, _a) {
4714
4808
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4715
4809
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -4741,6 +4835,16 @@ var objectSpecialExpression = {
4741
4835
  }
4742
4836
  return result;
4743
4837
  },
4838
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4839
+ var result = {};
4840
+ for (var i = 0; i < params.length; i += 2) {
4841
+ var key = params[i];
4842
+ var value = params[i + 1];
4843
+ assertString(key, sourceCodeInfo);
4844
+ result[key] = value !== null && value !== void 0 ? value : null;
4845
+ }
4846
+ return result;
4847
+ },
4744
4848
  getUndefinedSymbols: function (node, contextStack, _a) {
4745
4849
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4746
4850
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -4984,6 +5088,16 @@ var functionExecutors = {
4984
5088
  var normalExpression = asNonUndefined(allNormalExpressions[fn.normalBuitinSymbolType], sourceCodeInfo);
4985
5089
  return normalExpression.evaluate(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
4986
5090
  },
5091
+ SpecialBuiltin: function (fn, params, sourceCodeInfo, contextStack, _a) {
5092
+ var executeFunction = _a.executeFunction;
5093
+ var specialExpression = asNonUndefined(specialExpressions[fn.specialBuiltinSymbolType], sourceCodeInfo);
5094
+ if (specialExpression.evaluateAsNormalExpression) {
5095
+ return specialExpression.evaluateAsNormalExpression(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
5096
+ }
5097
+ else {
5098
+ throw new LitsError("Special builtin function ".concat(fn.specialBuiltinSymbolType, " is not supported as normal expression."), sourceCodeInfo);
5099
+ }
5100
+ },
4987
5101
  };
4988
5102
 
4989
5103
  function evaluate(ast, contextStack) {
@@ -5039,7 +5153,21 @@ function evaluateReservedSymbol(node) {
5039
5153
  function evaluateNormalExpression(node, contextStack) {
5040
5154
  var sourceCodeInfo = node[2];
5041
5155
  var paramNodes = node[1][1];
5042
- var params = paramNodes.map(function (paramNode) { return evaluateNode(paramNode, contextStack); });
5156
+ var params = [];
5157
+ paramNodes.forEach(function (paramNode) {
5158
+ if (isSpreadNode(paramNode)) {
5159
+ var spreadValue = evaluateNode(paramNode[1], contextStack);
5160
+ if (Array.isArray(spreadValue)) {
5161
+ params.push.apply(params, __spreadArray([], __read(spreadValue), false));
5162
+ }
5163
+ else {
5164
+ throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
5165
+ }
5166
+ }
5167
+ else {
5168
+ params.push(evaluateNode(paramNode, contextStack));
5169
+ }
5170
+ });
5043
5171
  if (isNormalExpressionNodeWithName(node)) {
5044
5172
  var nameSymbol = node[1][0];
5045
5173
  if (isNormalBuiltinSymbolNode(nameSymbol)) {
@@ -5141,19 +5269,19 @@ var ContextStackImpl = /** @class */ (function () {
5141
5269
  var contexts = [{}, context];
5142
5270
  return new ContextStackImpl({ contexts: contexts });
5143
5271
  };
5144
- ContextStackImpl.prototype.exportValues = function (values) {
5272
+ ContextStackImpl.prototype.exportValues = function (values, sourceCodeInfo) {
5145
5273
  var e_1, _a;
5146
5274
  try {
5147
5275
  for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
5148
5276
  var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
5149
5277
  if (this.globalContext[name_1]) {
5150
- throw new Error("Cannot redefine exported value \"".concat(name_1, "\""));
5278
+ throw new LitsError("Cannot redefine exported value \"".concat(name_1, "\""), sourceCodeInfo);
5151
5279
  }
5152
5280
  if (specialExpressionKeys.includes(name_1)) {
5153
- throw new Error("Cannot shadow special expression \"".concat(name_1, "\""));
5281
+ throw new LitsError("Cannot shadow special expression \"".concat(name_1, "\""), sourceCodeInfo);
5154
5282
  }
5155
5283
  if (normalExpressionKeys.includes(name_1)) {
5156
- throw new Error("Cannot shadow builtin function \"".concat(name_1, "\""));
5284
+ throw new LitsError("Cannot shadow builtin function \"".concat(name_1, "\""), sourceCodeInfo);
5157
5285
  }
5158
5286
  this.globalContext[name_1] = { value: value };
5159
5287
  }
@@ -5165,22 +5293,22 @@ var ContextStackImpl = /** @class */ (function () {
5165
5293
  }
5166
5294
  finally { if (e_1) throw e_1.error; }
5167
5295
  }
5168
- this.addValues(values);
5296
+ this.addValues(values, sourceCodeInfo);
5169
5297
  };
5170
- ContextStackImpl.prototype.addValues = function (values) {
5298
+ ContextStackImpl.prototype.addValues = function (values, sourceCodeInfo) {
5171
5299
  var e_2, _a;
5172
5300
  var currentContext = this.contexts[0];
5173
5301
  try {
5174
5302
  for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
5175
5303
  var _d = __read(_c.value, 2), name_2 = _d[0], value = _d[1];
5176
5304
  if (currentContext[name_2]) {
5177
- throw new Error("Cannot redefine value \"".concat(name_2, "\""));
5305
+ throw new LitsError("Cannot redefine value \"".concat(name_2, "\""), sourceCodeInfo);
5178
5306
  }
5179
5307
  if (specialExpressionKeys.includes(name_2)) {
5180
- throw new Error("Cannot shadow special expression \"".concat(name_2, "\""));
5308
+ throw new LitsError("Cannot shadow special expression \"".concat(name_2, "\""), sourceCodeInfo);
5181
5309
  }
5182
5310
  if (normalExpressionKeys.includes(name_2)) {
5183
- throw new Error("Cannot shadow builtin function \"".concat(name_2, "\""));
5311
+ throw new LitsError("Cannot shadow builtin function \"".concat(name_2, "\""), sourceCodeInfo);
5184
5312
  }
5185
5313
  currentContext[name_2] = { value: toAny(value) };
5186
5314
  }
@@ -5260,18 +5388,36 @@ var ContextStackImpl = /** @class */ (function () {
5260
5388
  return null;
5261
5389
  };
5262
5390
  ContextStackImpl.prototype.evaluateSymbol = function (node) {
5263
- var _a;
5391
+ var _a, _b;
5264
5392
  if (isSpecialBuiltinSymbolNode(node)) {
5265
- throw new Error('Special builtin symbols should not be evaluated');
5393
+ var functionType = node[1];
5394
+ switch (functionType) {
5395
+ case specialExpressionTypes['&&']:
5396
+ case specialExpressionTypes['||']:
5397
+ case specialExpressionTypes.array:
5398
+ case specialExpressionTypes.object:
5399
+ case specialExpressionTypes['defined?']:
5400
+ case specialExpressionTypes.recur:
5401
+ case specialExpressionTypes.throw:
5402
+ case specialExpressionTypes['??']:
5403
+ return _a = {},
5404
+ _a[FUNCTION_SYMBOL] = true,
5405
+ _a.functionType = 'SpecialBuiltin',
5406
+ _a.specialBuiltinSymbolType = functionType,
5407
+ _a.sourceCodeInfo = node[2],
5408
+ _a;
5409
+ default:
5410
+ throw new LitsError("Unknown special builtin symbol type: ".concat(functionType), node[2]);
5411
+ }
5266
5412
  }
5267
5413
  if (isNormalBuiltinSymbolNode(node)) {
5268
5414
  var type = node[1];
5269
- return _a = {},
5270
- _a[FUNCTION_SYMBOL] = true,
5271
- _a.functionType = 'Builtin',
5272
- _a.normalBuitinSymbolType = type,
5273
- _a.sourceCodeInfo = node[2],
5274
- _a;
5415
+ return _b = {},
5416
+ _b[FUNCTION_SYMBOL] = true,
5417
+ _b.functionType = 'Builtin',
5418
+ _b.normalBuitinSymbolType = type,
5419
+ _b.sourceCodeInfo = node[2],
5420
+ _b;
5275
5421
  }
5276
5422
  var lookUpResult = this.lookUp(node);
5277
5423
  if (isContextEntry(lookUpResult))
@@ -5943,7 +6089,7 @@ function withSourceCodeInfo(node, sourceCodeInfo) {
5943
6089
  }
5944
6090
  return node;
5945
6091
  }
5946
- function getPrecedence(operatorSign) {
6092
+ function getPrecedence(operatorSign, sourceCodeInfo) {
5947
6093
  switch (operatorSign) {
5948
6094
  case '**': // exponentiation
5949
6095
  return exponentiationPrecedence;
@@ -5982,7 +6128,7 @@ function getPrecedence(operatorSign) {
5982
6128
  // leave room for binaryFunctionalOperatorPrecedence = 1
5983
6129
  /* v8 ignore next 2 */
5984
6130
  default:
5985
- throw new Error("Unknown binary operator: ".concat(operatorSign));
6131
+ throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
5986
6132
  }
5987
6133
  }
5988
6134
  function createNamedNormalExpressionNode(symbolNode, params, sourceCodeInfo) {
@@ -6115,7 +6261,7 @@ var Parser = /** @class */ (function () {
6115
6261
  while (!this.isAtExpressionEnd()) {
6116
6262
  if (isA_BinaryOperatorToken(operator)) {
6117
6263
  var name_1 = operator[1];
6118
- var newPrecedece = getPrecedence(name_1);
6264
+ var newPrecedece = getPrecedence(name_1, operator[2]);
6119
6265
  if (newPrecedece <= precedence
6120
6266
  // ** (exponentiation) is right associative
6121
6267
  && !(newPrecedece === exponentiationPrecedence && precedence === exponentiationPrecedence)) {
@@ -6195,7 +6341,7 @@ var Parser = /** @class */ (function () {
6195
6341
  this.advance();
6196
6342
  var expression = this.parseExpression();
6197
6343
  if (!isRParenToken(this.peek())) {
6198
- throw new Error('Expected closing parenthesis');
6344
+ throw new LitsError('Expected closing parenthesis', this.peek()[2]);
6199
6345
  }
6200
6346
  this.advance();
6201
6347
  return expression;
@@ -6317,7 +6463,13 @@ var Parser = /** @class */ (function () {
6317
6463
  this.advance();
6318
6464
  var params = [];
6319
6465
  while (!this.isAtEnd() && !isRParenToken(this.peek())) {
6320
- params.push(this.parseExpression());
6466
+ if (isOperatorToken(this.peek(), '...')) {
6467
+ this.advance();
6468
+ params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peek()[2]));
6469
+ }
6470
+ else {
6471
+ params.push(this.parseExpression());
6472
+ }
6321
6473
  var nextToken = this.peek();
6322
6474
  if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
6323
6475
  throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
@@ -6373,7 +6525,7 @@ var Parser = /** @class */ (function () {
6373
6525
  throw new LitsError("".concat(type, " is not allowed"), symbol[2]);
6374
6526
  /* v8 ignore next 2 */
6375
6527
  default:
6376
- throw new Error("Unknown special expression: ".concat(type));
6528
+ throw new LitsError("Unknown special expression: ".concat(type), symbol[2]);
6377
6529
  }
6378
6530
  }
6379
6531
  else if (isNormalBuiltinSymbolNode(symbol) || isNormalBuiltinSymbolNode(symbol)) {
@@ -11270,19 +11422,23 @@ var sequenceReference = {
11270
11422
  type: 'any',
11271
11423
  rest: true,
11272
11424
  },
11273
- args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { seq: {
11425
+ args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { seqs: {
11274
11426
  type: 'sequence',
11427
+ rest: true,
11428
+ description: 'At least one.',
11275
11429
  }, fun: {
11276
11430
  type: 'function',
11277
11431
  } }),
11278
11432
  variants: [
11279
- { argumentNames: ['seq', 'fun'] },
11433
+ { argumentNames: ['seqs', 'fun'] },
11280
11434
  ],
11281
- description: 'Creates a new array populated with the results of calling $fun on every elements in $seq.',
11435
+ description: 'Creates a new array populated with the results of calling $fun on every element in $seqs.',
11282
11436
  examples: [
11437
+ '[1, 2, 3] map -',
11283
11438
  '[1, 2, 3] map -> -($)',
11284
11439
  'map(["Albert", "Mojir", 42], str)',
11285
11440
  'map([1, 2, 3], inc)',
11441
+ 'map([1, 2, 3], [1, 10, 100], *)',
11286
11442
  ],
11287
11443
  },
11288
11444
  'filter': {
@@ -28,6 +28,7 @@ export interface EvaluateHelpers {
28
28
  }
29
29
  export interface BuiltinSpecialExpression<T, N extends SpecialExpressionNode> {
30
30
  evaluate: (node: N, contextStack: ContextStack, helpers: EvaluateHelpers) => T;
31
+ evaluateAsNormalExpression?: NormalExpressionEvaluator<T>;
31
32
  paramCount: Count;
32
33
  getUndefinedSymbols: (node: N, contextStack: ContextStack, params: {
33
34
  getUndefinedSymbols: GetUndefinedSymbols;
@@ -13,7 +13,7 @@ export declare const NodeTypes: {
13
13
  export type NodeType = typeof NodeTypes[keyof typeof NodeTypes];
14
14
  export declare function getNodeTypeName(type: NodeType): keyof typeof NodeTypes;
15
15
  export declare function isNodeType(type: unknown): type is NodeType;
16
- declare const functionTypes: readonly ["UserDefined", "Partial", "Comp", "Constantly", "Juxt", "Complement", "EveryPred", "SomePred", "Fnull", "Builtin", "NativeJsFunction"];
16
+ declare const functionTypes: readonly ["UserDefined", "Partial", "Comp", "Constantly", "Juxt", "Complement", "EveryPred", "SomePred", "Fnull", "Builtin", "SpecialBuiltin", "NativeJsFunction"];
17
17
  export type FunctionType = typeof functionTypes[number];
18
18
  export declare function isFunctionType(type: unknown): type is FunctionType;
19
19
  export {};
@@ -1,6 +1,7 @@
1
1
  import type { Any } from '../interface';
2
2
  import type { ContextParams, LazyValue } from '../Lits/Lits';
3
3
  import type { NativeJsFunction, SymbolNode, UserDefinedSymbolNode } from '../parser/types';
4
+ import type { SourceCodeInfo } from '../tokenizer/token';
4
5
  import type { Context, LookUpResult } from './interface';
5
6
  export type ContextStack = ContextStackImpl;
6
7
  export declare class ContextStackImpl {
@@ -17,8 +18,8 @@ export declare class ContextStackImpl {
17
18
  });
18
19
  create(context: Context): ContextStack;
19
20
  new(context: Context): ContextStack;
20
- exportValues(values: Record<string, Any>): void;
21
- addValues(values: Record<string, Any>): void;
21
+ exportValues(values: Record<string, Any>, sourceCodeInfo: SourceCodeInfo | undefined): void;
22
+ addValues(values: Record<string, Any>, sourceCodeInfo: SourceCodeInfo | undefined): void;
22
23
  getValue(name: string): unknown;
23
24
  lookUp(node: UserDefinedSymbolNode): LookUpResult;
24
25
  evaluateSymbol(node: SymbolNode): Any;
@@ -1,5 +1,5 @@
1
1
  import type { Any, Arr } from '../interface';
2
- import { type LitsFunctionType } from '../parser/types';
2
+ import type { LitsFunctionType } from '../parser/types';
3
3
  import type { SourceCodeInfo } from '../tokenizer/token';
4
4
  import type { ContextStack } from './ContextStack';
5
5
  import type { EvaluateNode, ExecuteFunction } from './interface';
@@ -1,5 +1,6 @@
1
1
  import type { JsFunction } from '../Lits/Lits';
2
2
  import type { SpecialExpressionType } from '../builtin';
3
+ import type { specialExpressionTypes } from '../builtin/specialExpressionTypes';
3
4
  import type { FunctionType, NodeType, NodeTypes } from '../constants/constants';
4
5
  import type { Context } from '../evaluator/interface';
5
6
  import type { Any, Arr } from '../interface';
@@ -69,7 +70,11 @@ export interface NormalBuiltinFunction extends GenericLitsFunction {
69
70
  functionType: 'Builtin';
70
71
  normalBuitinSymbolType: number;
71
72
  }
72
- export type LitsFunction = NativeJsFunction | UserDefinedFunction | NormalBuiltinFunction | PartialFunction | CompFunction | ConstantlyFunction | JuxtFunction | ComplementFunction | EveryPredFunction | SomePredFunction | FNullFunction;
73
+ export interface SpecialBuiltinFunction extends GenericLitsFunction {
74
+ functionType: 'SpecialBuiltin';
75
+ specialBuiltinSymbolType: typeof specialExpressionTypes['&&'] | typeof specialExpressionTypes['||'] | typeof specialExpressionTypes['array'] | typeof specialExpressionTypes['object'] | typeof specialExpressionTypes['defined?'] | typeof specialExpressionTypes['recur'] | typeof specialExpressionTypes['throw'] | typeof specialExpressionTypes['??'];
76
+ }
77
+ export type LitsFunction = NativeJsFunction | UserDefinedFunction | NormalBuiltinFunction | SpecialBuiltinFunction | PartialFunction | CompFunction | ConstantlyFunction | JuxtFunction | ComplementFunction | EveryPredFunction | SomePredFunction | FNullFunction;
73
78
  export type LitsFunctionType = LitsFunction['functionType'];
74
79
  export type DebugData = {
75
80
  token: Token;
@@ -24,11 +24,11 @@ export type WhitespaceToken = GenericToken<'Whitespace'>;
24
24
  export type Token = LBraceToken | LBracketToken | LParenToken | RBraceToken | RBracketToken | RParenToken | BasePrefixedNumberToken | MultiLineCommentToken | NumberToken | OperatorToken | RegexpShorthandToken | ReservedSymbolToken | SingleLineCommentToken | StringToken | SymbolToken | WhitespaceToken;
25
25
  export type TokenDescriptor<T extends Token> = [length: number, token?: T];
26
26
  export interface SourceCodeInfo {
27
- position?: {
27
+ position: {
28
28
  line: number;
29
29
  column: number;
30
30
  };
31
- code?: string;
31
+ code: string;
32
32
  filePath?: string;
33
33
  }
34
34
  export declare function isSymbolToken<T extends string>(token: Token, symbolName?: T): token is SymbolToken<T>;