@mojir/lits 2.1.1 → 2.1.3

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 (36) hide show
  1. package/dist/cli/cli.js +228 -107
  2. package/dist/cli/reference/api.d.ts +0 -1
  3. package/dist/cli/src/builtin/bindingNode.d.ts +1 -0
  4. package/dist/cli/src/builtin/interface.d.ts +1 -0
  5. package/dist/cli/src/builtin/specialExpressionTypes.d.ts +3 -5
  6. package/dist/cli/src/builtin/specialExpressions/def.d.ts +1 -1
  7. package/dist/cli/src/builtin/specialExpressions/functions.d.ts +2 -2
  8. package/dist/cli/src/constants/constants.d.ts +1 -1
  9. package/dist/cli/src/evaluator/ContextStack.d.ts +3 -2
  10. package/dist/cli/src/evaluator/functionExecutors.d.ts +1 -1
  11. package/dist/cli/src/parser/types.d.ts +6 -1
  12. package/dist/cli/src/tokenizer/token.d.ts +2 -2
  13. package/dist/cli/src/typeGuards/astNode.d.ts +1 -6
  14. package/dist/index.esm.js +249 -125
  15. package/dist/index.esm.js.map +1 -1
  16. package/dist/index.js +249 -125
  17. package/dist/index.js.map +1 -1
  18. package/dist/lits.iife.js +249 -125
  19. package/dist/lits.iife.js.map +1 -1
  20. package/dist/reference/api.d.ts +0 -1
  21. package/dist/src/builtin/bindingNode.d.ts +1 -0
  22. package/dist/src/builtin/interface.d.ts +1 -0
  23. package/dist/src/builtin/specialExpressionTypes.d.ts +3 -5
  24. package/dist/src/builtin/specialExpressions/def.d.ts +1 -1
  25. package/dist/src/builtin/specialExpressions/functions.d.ts +2 -2
  26. package/dist/src/constants/constants.d.ts +1 -1
  27. package/dist/src/evaluator/ContextStack.d.ts +3 -2
  28. package/dist/src/evaluator/functionExecutors.d.ts +1 -1
  29. package/dist/src/parser/types.d.ts +6 -1
  30. package/dist/src/tokenizer/token.d.ts +2 -2
  31. package/dist/src/typeGuards/astNode.d.ts +1 -6
  32. package/dist/testFramework.esm.js +227 -84
  33. package/dist/testFramework.esm.js.map +1 -1
  34. package/dist/testFramework.js +227 -84
  35. package/dist/testFramework.js.map +1 -1
  36. package/package.json +1 -1
package/dist/lits.iife.js CHANGED
@@ -96,9 +96,15 @@ var Lits = (function (exports) {
96
96
  }
97
97
 
98
98
  function getLitsErrorMessage(message, sourceCodeInfo) {
99
- var filePathLine = (sourceCodeInfo === null || sourceCodeInfo === void 0 ? void 0 : sourceCodeInfo.filePath) ? "\n".concat(sourceCodeInfo.filePath) : '';
100
- var codeLine = (sourceCodeInfo === null || sourceCodeInfo === void 0 ? void 0 : sourceCodeInfo.code) ? "\n".concat(sourceCodeInfo.code) : '';
101
- var codeMarker = sourceCodeInfo && codeLine ? "\n".concat(getCodeMarker(sourceCodeInfo)) : '';
99
+ if (!sourceCodeInfo) {
100
+ return message;
101
+ }
102
+ var location = "".concat(sourceCodeInfo.position.line, ":").concat(sourceCodeInfo.position.column);
103
+ var filePathLine = sourceCodeInfo.filePath
104
+ ? "\n".concat(sourceCodeInfo.filePath, ":").concat(location)
105
+ : "\nLocation ".concat(location);
106
+ var codeLine = "\n".concat(sourceCodeInfo.code);
107
+ var codeMarker = "\n".concat(getCodeMarker(sourceCodeInfo));
102
108
  return "".concat(message).concat(filePathLine).concat(codeLine).concat(codeMarker);
103
109
  }
104
110
  var RecurSignal = /** @class */ (function (_super) {
@@ -211,6 +217,7 @@ var Lits = (function (exports) {
211
217
  'SomePred',
212
218
  'Fnull',
213
219
  'Builtin',
220
+ 'SpecialBuiltin',
214
221
  'NativeJsFunction',
215
222
  ];
216
223
  var functionTypeSet = new Set(functionTypes);
@@ -3672,6 +3679,26 @@ var Lits = (function (exports) {
3672
3679
  }
3673
3680
  return value;
3674
3681
  },
3682
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
3683
+ var e_2, _a;
3684
+ var value = true;
3685
+ try {
3686
+ for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
3687
+ var param = params_1_1.value;
3688
+ value = asAny(param, sourceCodeInfo);
3689
+ if (!value)
3690
+ break;
3691
+ }
3692
+ }
3693
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
3694
+ finally {
3695
+ try {
3696
+ if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
3697
+ }
3698
+ finally { if (e_2) throw e_2.error; }
3699
+ }
3700
+ return value;
3701
+ },
3675
3702
  getUndefinedSymbols: function (node, contextStack, _a) {
3676
3703
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
3677
3704
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -3739,31 +3766,6 @@ var Lits = (function (exports) {
3739
3766
  },
3740
3767
  };
3741
3768
 
3742
- var specialExpressionTypes = {
3743
- '??': 0,
3744
- '&&': 1,
3745
- '||': 2,
3746
- 'array': 3,
3747
- 'cond': 4,
3748
- 'def': 5,
3749
- 'defined?': 6,
3750
- 'defn': 7,
3751
- 'do': 8,
3752
- 'doseq': 9,
3753
- 'fn': 10,
3754
- 'for': 11,
3755
- 'function': 12,
3756
- 'if': 13,
3757
- 'let': 14,
3758
- 'loop': 15,
3759
- 'object': 16,
3760
- 'recur': 17,
3761
- 'switch': 18,
3762
- 'throw': 19,
3763
- 'try': 20,
3764
- 'unless': 21,
3765
- };
3766
-
3767
3769
  function isSymbolNode(node) {
3768
3770
  var nodeType = node[0];
3769
3771
  return NodeTypes.UserDefinedSymbol === nodeType
@@ -3788,25 +3790,9 @@ var Lits = (function (exports) {
3788
3790
  function isNormalBuiltinSymbolNode(node) {
3789
3791
  return NodeTypes.NormalBuiltinSymbol === node[0];
3790
3792
  }
3791
- function isSpecialBuiltinSymbolNode(node, name) {
3792
- if (NodeTypes.SpecialBuiltinSymbol !== node[0]) {
3793
- return false;
3794
- }
3795
- {
3796
- return true;
3797
- }
3793
+ function isSpecialBuiltinSymbolNode(node) {
3794
+ return NodeTypes.SpecialBuiltinSymbol === node[0];
3798
3795
  }
3799
- // export function isNumberNode(node: Node): node is NumberNode {
3800
- // return node[0] === NodeTypes.Number
3801
- // }
3802
- // export function asNumberNode(node: Node, sourceCodeInfo?: SourceCodeInfo): NumberNode {
3803
- // assertNumberNode(node, sourceCodeInfo)
3804
- // return node
3805
- // }
3806
- // export function assertNumberNode(node: Node, sourceCodeInfo?: SourceCodeInfo): asserts node is NumberNode {
3807
- // if (!isNumberNode(node))
3808
- // throw getAssertionError('NumberNode', node, sourceCodeInfo)
3809
- // }
3810
3796
  function isNormalExpressionNode(node) {
3811
3797
  return node[0] === NodeTypes.NormalExpression;
3812
3798
  }
@@ -3844,6 +3830,29 @@ var Lits = (function (exports) {
3844
3830
  array: 14,
3845
3831
  };
3846
3832
 
3833
+ function walkDefaults(bindingTarget, onDefault) {
3834
+ var _a;
3835
+ if (bindingTarget[0] === bindingTargetTypes.object) {
3836
+ Object.values(bindingTarget[1][0]).forEach(function (element) {
3837
+ if (element[1][1]) {
3838
+ onDefault(element[1][1]);
3839
+ }
3840
+ walkDefaults(element, onDefault);
3841
+ });
3842
+ }
3843
+ else if (bindingTarget[0] === bindingTargetTypes.array) {
3844
+ for (var index = 0; index < bindingTarget[1][0].length; index += 1) {
3845
+ var element = (_a = bindingTarget[1][0][index]) !== null && _a !== void 0 ? _a : null;
3846
+ if (element === null) {
3847
+ continue;
3848
+ }
3849
+ if (element[1][1]) {
3850
+ onDefault(element[1][1]);
3851
+ }
3852
+ walkDefaults(element, onDefault);
3853
+ }
3854
+ }
3855
+ }
3847
3856
  function evalueateBindingNodeValues(target, value, evaluate) {
3848
3857
  var sourceCodeInfo = target[2];
3849
3858
  var record = {};
@@ -3974,7 +3983,7 @@ var Lits = (function (exports) {
3974
3983
  var value = bindingNode[1][1];
3975
3984
  var bindingValue = evaluateNode(value, contextStack);
3976
3985
  var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
3977
- contextStack.exportValues(values);
3986
+ contextStack.exportValues(values, target[2]);
3978
3987
  return null;
3979
3988
  },
3980
3989
  getUndefinedSymbols: function (node, contextStack, _a) {
@@ -3983,7 +3992,10 @@ var Lits = (function (exports) {
3983
3992
  var target = bindingNode[1][0];
3984
3993
  var value = bindingNode[1][1];
3985
3994
  var bindingResult = getUndefinedSymbols([value], contextStack, builtin, evaluateNode);
3986
- contextStack.addValues(getAllBindingTargetNames(target));
3995
+ walkDefaults(target, function (defaultNode) {
3996
+ addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
3997
+ });
3998
+ contextStack.addValues(getAllBindingTargetNames(target), target[2]);
3987
3999
  return bindingResult;
3988
4000
  },
3989
4001
  };
@@ -4071,6 +4083,31 @@ var Lits = (function (exports) {
4071
4083
  return symbol in numberReservedSymbolRecord;
4072
4084
  }
4073
4085
 
4086
+ var specialExpressionTypes = {
4087
+ '??': 0,
4088
+ '&&': 1,
4089
+ '||': 2,
4090
+ 'array': 3,
4091
+ 'cond': 4,
4092
+ '0_def': 5,
4093
+ 'defined?': 6,
4094
+ '0_defn': 7,
4095
+ 'do': 8,
4096
+ 'doseq': 9,
4097
+ '0_fn': 10,
4098
+ 'for': 11,
4099
+ 'function': 12,
4100
+ 'if': 13,
4101
+ 'let': 14,
4102
+ 'loop': 15,
4103
+ 'object': 16,
4104
+ 'recur': 17,
4105
+ 'switch': 18,
4106
+ 'throw': 19,
4107
+ 'try': 20,
4108
+ 'unless': 21,
4109
+ };
4110
+
4074
4111
  function assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo) {
4075
4112
  if (typeof name !== 'string')
4076
4113
  return;
@@ -4101,16 +4138,16 @@ var Lits = (function (exports) {
4101
4138
  _b.name = functionSymbol[1],
4102
4139
  _b.evaluatedfunction = evaluatedFunction,
4103
4140
  _b);
4104
- contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
4141
+ contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
4105
4142
  return null;
4106
4143
  },
4107
4144
  getUndefinedSymbols: function (node, contextStack, _a) {
4108
4145
  var _b, _c;
4109
4146
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4110
4147
  var functionName = node[1][1][1];
4111
- contextStack.addValues((_b = {}, _b[functionName] = true, _b));
4148
+ contextStack.addValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
4112
4149
  var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
4113
- return addFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
4150
+ return getFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
4114
4151
  },
4115
4152
  };
4116
4153
  var defnSpecialExpression = {
@@ -4129,7 +4166,7 @@ var Lits = (function (exports) {
4129
4166
  _b.name = functionSymbol[1],
4130
4167
  _b.evaluatedfunction = evaluatedFunctionOverloades,
4131
4168
  _b);
4132
- contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
4169
+ contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
4133
4170
  return null;
4134
4171
  },
4135
4172
  getUndefinedSymbols: function (node, contextStack, _a) {
@@ -4137,9 +4174,9 @@ var Lits = (function (exports) {
4137
4174
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4138
4175
  var functionName = node[1][1][1];
4139
4176
  var fn = node[1][2];
4140
- contextStack.exportValues((_b = {}, _b[functionName] = true, _b));
4177
+ contextStack.exportValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
4141
4178
  var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
4142
- return addFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
4179
+ return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
4143
4180
  },
4144
4181
  };
4145
4182
  var fnSpecialExpression = {
@@ -4161,7 +4198,7 @@ var Lits = (function (exports) {
4161
4198
  getUndefinedSymbols: function (node, contextStack, _a) {
4162
4199
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4163
4200
  var fn = node[1][1];
4164
- return addFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode);
4201
+ return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode);
4165
4202
  },
4166
4203
  };
4167
4204
  function evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode) {
@@ -4186,12 +4223,15 @@ var Lits = (function (exports) {
4186
4223
  ];
4187
4224
  return evaluatedFunction;
4188
4225
  }
4189
- function addFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, functionNameContext) {
4226
+ function getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, functionNameContext) {
4190
4227
  var result = new Set();
4191
4228
  var contextStackWithFunctionName = functionNameContext ? contextStack.create(functionNameContext) : contextStack;
4192
4229
  var newContext = {};
4193
4230
  fn[0].forEach(function (arg) {
4194
4231
  Object.assign(newContext, getAllBindingTargetNames(arg));
4232
+ walkDefaults(arg, function (defaultNode) {
4233
+ addToSet(result, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
4234
+ });
4195
4235
  });
4196
4236
  var newContextStack = contextStackWithFunctionName.create(newContext);
4197
4237
  var overloadResult = getUndefinedSymbols(fn[1], newContextStack, builtin, evaluateNode);
@@ -4246,7 +4286,7 @@ var Lits = (function (exports) {
4246
4286
  var value = bindingNode[1][1];
4247
4287
  var bindingValue = evaluateNode(value, contextStack);
4248
4288
  var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
4249
- contextStack.addValues(values);
4289
+ contextStack.addValues(values, target[2]);
4250
4290
  return null;
4251
4291
  },
4252
4292
  getUndefinedSymbols: function (node, contextStack, _a) {
@@ -4255,7 +4295,10 @@ var Lits = (function (exports) {
4255
4295
  var target = bindingNode[1][0];
4256
4296
  var value = bindingNode[1][1];
4257
4297
  var bindingResult = getUndefinedSymbols([value], contextStack, builtin, evaluateNode);
4258
- contextStack.addValues(getAllBindingTargetNames(target));
4298
+ walkDefaults(target, function (defaultNode) {
4299
+ addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
4300
+ });
4301
+ contextStack.addValues(getAllBindingTargetNames(target), target[2]);
4259
4302
  return bindingResult;
4260
4303
  },
4261
4304
  };
@@ -4526,6 +4569,26 @@ var Lits = (function (exports) {
4526
4569
  }
4527
4570
  return value;
4528
4571
  },
4572
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4573
+ var e_2, _a;
4574
+ var value = false;
4575
+ try {
4576
+ for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
4577
+ var param = params_1_1.value;
4578
+ value = asAny(param, sourceCodeInfo);
4579
+ if (value)
4580
+ break;
4581
+ }
4582
+ }
4583
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
4584
+ finally {
4585
+ try {
4586
+ if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
4587
+ }
4588
+ finally { if (e_2) throw e_2.error; }
4589
+ }
4590
+ return value;
4591
+ },
4529
4592
  getUndefinedSymbols: function (node, contextStack, _a) {
4530
4593
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4531
4594
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -4544,6 +4607,11 @@ var Lits = (function (exports) {
4544
4607
  var firstResult = evaluateNode(firstNode, contextStack);
4545
4608
  return firstResult !== null && firstResult !== void 0 ? firstResult : (secondNode ? evaluateNode(secondNode, contextStack) : null);
4546
4609
  },
4610
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4611
+ var firstParam = asAny(params[0], sourceCodeInfo);
4612
+ var secondParam = params[1] !== undefined ? asAny(params[1], sourceCodeInfo) : null;
4613
+ return firstParam !== null && firstParam !== void 0 ? firstParam : secondParam;
4614
+ },
4547
4615
  getUndefinedSymbols: function (node, contextStack, _a) {
4548
4616
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4549
4617
  return getUndefinedSymbols(node[1][1].filter(function (n) { return !!n; }), contextStack, builtin, evaluateNode);
@@ -4558,6 +4626,9 @@ var Lits = (function (exports) {
4558
4626
  var evaluatedParams = params.map(function (paramNode) { return evaluateNode(paramNode, contextStack); });
4559
4627
  throw new RecurSignal(evaluatedParams);
4560
4628
  },
4629
+ evaluateAsNormalExpression: function (params) {
4630
+ throw new RecurSignal(params);
4631
+ },
4561
4632
  getUndefinedSymbols: function (node, contextStack, _a) {
4562
4633
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4563
4634
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -4573,6 +4644,12 @@ var Lits = (function (exports) {
4573
4644
  });
4574
4645
  throw new UserDefinedError(message, node[2]);
4575
4646
  },
4647
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4648
+ var message = asString(params[0], sourceCodeInfo, {
4649
+ nonEmpty: true,
4650
+ });
4651
+ throw new UserDefinedError(message, undefined);
4652
+ },
4576
4653
  getUndefinedSymbols: function (node, contextStack, _a) {
4577
4654
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4578
4655
  return getUndefinedSymbols([node[1][1]], contextStack, builtin, evaluateNode);
@@ -4640,6 +4717,24 @@ var Lits = (function (exports) {
4640
4717
  }
4641
4718
  return result;
4642
4719
  },
4720
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4721
+ var e_2, _a;
4722
+ var result = [];
4723
+ try {
4724
+ for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
4725
+ var param = params_1_1.value;
4726
+ result.push(asAny(param, sourceCodeInfo));
4727
+ }
4728
+ }
4729
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
4730
+ finally {
4731
+ try {
4732
+ if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
4733
+ }
4734
+ finally { if (e_2) throw e_2.error; }
4735
+ }
4736
+ return result;
4737
+ },
4643
4738
  getUndefinedSymbols: function (node, contextStack, _a) {
4644
4739
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4645
4740
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -4671,6 +4766,16 @@ var Lits = (function (exports) {
4671
4766
  }
4672
4767
  return result;
4673
4768
  },
4769
+ evaluateAsNormalExpression: function (params, sourceCodeInfo) {
4770
+ var result = {};
4771
+ for (var i = 0; i < params.length; i += 2) {
4772
+ var key = params[i];
4773
+ var value = params[i + 1];
4774
+ assertString(key, sourceCodeInfo);
4775
+ result[key] = value !== null && value !== void 0 ? value : null;
4776
+ }
4777
+ return result;
4778
+ },
4674
4779
  getUndefinedSymbols: function (node, contextStack, _a) {
4675
4780
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4676
4781
  return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
@@ -4749,6 +4854,7 @@ var Lits = (function (exports) {
4749
4854
  case NodeTypes.String:
4750
4855
  case NodeTypes.Number:
4751
4856
  case NodeTypes.ReservedSymbol:
4857
+ case NodeTypes.Binding:
4752
4858
  return null;
4753
4859
  case NodeTypes.NormalExpression: {
4754
4860
  var normalExpressionNode = node;
@@ -4793,12 +4899,9 @@ var Lits = (function (exports) {
4793
4899
  }
4794
4900
  case NodeTypes.Spread:
4795
4901
  return findUnresolvedSymbolsInNode(node[1], contextStack, builtin, evaluateNode);
4796
- case NodeTypes.Binding: {
4797
- var bindingNode = node;
4798
- return findUnresolvedSymbolsInNode(bindingNode[1][1], contextStack, builtin, evaluateNode);
4799
- }
4902
+ /* v8 ignore next 2 */
4800
4903
  default:
4801
- throw new Error("Unhandled node type: ".concat(nodeType));
4904
+ throw new LitsError("Unhandled node type: ".concat(nodeType), node[2]);
4802
4905
  }
4803
4906
  }
4804
4907
 
@@ -5006,6 +5109,16 @@ var Lits = (function (exports) {
5006
5109
  var normalExpression = asNonUndefined(allNormalExpressions[fn.normalBuitinSymbolType], sourceCodeInfo);
5007
5110
  return normalExpression.evaluate(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
5008
5111
  },
5112
+ SpecialBuiltin: function (fn, params, sourceCodeInfo, contextStack, _a) {
5113
+ var executeFunction = _a.executeFunction;
5114
+ var specialExpression = asNonUndefined(specialExpressions[fn.specialBuiltinSymbolType], sourceCodeInfo);
5115
+ if (specialExpression.evaluateAsNormalExpression) {
5116
+ return specialExpression.evaluateAsNormalExpression(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
5117
+ }
5118
+ else {
5119
+ throw new LitsError("Special builtin function ".concat(fn.specialBuiltinSymbolType, " is not supported as normal expression."), sourceCodeInfo);
5120
+ }
5121
+ },
5009
5122
  };
5010
5123
 
5011
5124
  function evaluate(ast, contextStack) {
@@ -5061,7 +5174,21 @@ var Lits = (function (exports) {
5061
5174
  function evaluateNormalExpression(node, contextStack) {
5062
5175
  var sourceCodeInfo = node[2];
5063
5176
  var paramNodes = node[1][1];
5064
- var params = paramNodes.map(function (paramNode) { return evaluateNode(paramNode, contextStack); });
5177
+ var params = [];
5178
+ paramNodes.forEach(function (paramNode) {
5179
+ if (isSpreadNode(paramNode)) {
5180
+ var spreadValue = evaluateNode(paramNode[1], contextStack);
5181
+ if (Array.isArray(spreadValue)) {
5182
+ params.push.apply(params, __spreadArray([], __read(spreadValue), false));
5183
+ }
5184
+ else {
5185
+ throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
5186
+ }
5187
+ }
5188
+ else {
5189
+ params.push(evaluateNode(paramNode, contextStack));
5190
+ }
5191
+ });
5065
5192
  if (isNormalExpressionNodeWithName(node)) {
5066
5193
  var nameSymbol = node[1][0];
5067
5194
  if (isNormalBuiltinSymbolNode(nameSymbol)) {
@@ -5163,19 +5290,19 @@ var Lits = (function (exports) {
5163
5290
  var contexts = [{}, context];
5164
5291
  return new ContextStackImpl({ contexts: contexts });
5165
5292
  };
5166
- ContextStackImpl.prototype.exportValues = function (values) {
5293
+ ContextStackImpl.prototype.exportValues = function (values, sourceCodeInfo) {
5167
5294
  var e_1, _a;
5168
5295
  try {
5169
5296
  for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
5170
5297
  var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
5171
5298
  if (this.globalContext[name_1]) {
5172
- throw new Error("Cannot redefine exported value \"".concat(name_1, "\""));
5299
+ throw new LitsError("Cannot redefine exported value \"".concat(name_1, "\""), sourceCodeInfo);
5173
5300
  }
5174
5301
  if (specialExpressionKeys.includes(name_1)) {
5175
- throw new Error("Cannot shadow special expression \"".concat(name_1, "\""));
5302
+ throw new LitsError("Cannot shadow special expression \"".concat(name_1, "\""), sourceCodeInfo);
5176
5303
  }
5177
5304
  if (normalExpressionKeys.includes(name_1)) {
5178
- throw new Error("Cannot shadow builtin function \"".concat(name_1, "\""));
5305
+ throw new LitsError("Cannot shadow builtin function \"".concat(name_1, "\""), sourceCodeInfo);
5179
5306
  }
5180
5307
  this.globalContext[name_1] = { value: value };
5181
5308
  }
@@ -5187,22 +5314,22 @@ var Lits = (function (exports) {
5187
5314
  }
5188
5315
  finally { if (e_1) throw e_1.error; }
5189
5316
  }
5190
- this.addValues(values);
5317
+ this.addValues(values, sourceCodeInfo);
5191
5318
  };
5192
- ContextStackImpl.prototype.addValues = function (values) {
5319
+ ContextStackImpl.prototype.addValues = function (values, sourceCodeInfo) {
5193
5320
  var e_2, _a;
5194
5321
  var currentContext = this.contexts[0];
5195
5322
  try {
5196
5323
  for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
5197
5324
  var _d = __read(_c.value, 2), name_2 = _d[0], value = _d[1];
5198
5325
  if (currentContext[name_2]) {
5199
- throw new Error("Cannot redefine value \"".concat(name_2, "\""));
5326
+ throw new LitsError("Cannot redefine value \"".concat(name_2, "\""), sourceCodeInfo);
5200
5327
  }
5201
5328
  if (specialExpressionKeys.includes(name_2)) {
5202
- throw new Error("Cannot shadow special expression \"".concat(name_2, "\""));
5329
+ throw new LitsError("Cannot shadow special expression \"".concat(name_2, "\""), sourceCodeInfo);
5203
5330
  }
5204
5331
  if (normalExpressionKeys.includes(name_2)) {
5205
- throw new Error("Cannot shadow builtin function \"".concat(name_2, "\""));
5332
+ throw new LitsError("Cannot shadow builtin function \"".concat(name_2, "\""), sourceCodeInfo);
5206
5333
  }
5207
5334
  currentContext[name_2] = { value: toAny(value) };
5208
5335
  }
@@ -5282,24 +5409,40 @@ var Lits = (function (exports) {
5282
5409
  return null;
5283
5410
  };
5284
5411
  ContextStackImpl.prototype.evaluateSymbol = function (node) {
5285
- var _a;
5412
+ var _a, _b;
5286
5413
  if (isSpecialBuiltinSymbolNode(node)) {
5287
- throw new Error('Special builtin symbols should not be evaluated');
5414
+ var functionType = node[1];
5415
+ switch (functionType) {
5416
+ case specialExpressionTypes['&&']:
5417
+ case specialExpressionTypes['||']:
5418
+ case specialExpressionTypes.array:
5419
+ case specialExpressionTypes.object:
5420
+ case specialExpressionTypes['defined?']:
5421
+ case specialExpressionTypes.recur:
5422
+ case specialExpressionTypes.throw:
5423
+ case specialExpressionTypes['??']:
5424
+ return _a = {},
5425
+ _a[FUNCTION_SYMBOL] = true,
5426
+ _a.functionType = 'SpecialBuiltin',
5427
+ _a.specialBuiltinSymbolType = functionType,
5428
+ _a.sourceCodeInfo = node[2],
5429
+ _a;
5430
+ default:
5431
+ throw new LitsError("Unknown special builtin symbol type: ".concat(functionType), node[2]);
5432
+ }
5288
5433
  }
5289
5434
  if (isNormalBuiltinSymbolNode(node)) {
5290
5435
  var type = node[1];
5291
- return _a = {},
5292
- _a[FUNCTION_SYMBOL] = true,
5293
- _a.functionType = 'Builtin',
5294
- _a.normalBuitinSymbolType = type,
5295
- _a.sourceCodeInfo = node[2],
5296
- _a;
5436
+ return _b = {},
5437
+ _b[FUNCTION_SYMBOL] = true,
5438
+ _b.functionType = 'Builtin',
5439
+ _b.normalBuitinSymbolType = type,
5440
+ _b.sourceCodeInfo = node[2],
5441
+ _b;
5297
5442
  }
5298
5443
  var lookUpResult = this.lookUp(node);
5299
5444
  if (isContextEntry(lookUpResult))
5300
5445
  return lookUpResult.value;
5301
- else if (isBuiltinFunction(lookUpResult))
5302
- return lookUpResult;
5303
5446
  throw new UndefinedSymbolError(node[1], node[2]);
5304
5447
  };
5305
5448
  return ContextStackImpl;
@@ -5383,10 +5526,10 @@ var Lits = (function (exports) {
5383
5526
  'cond',
5384
5527
  'def',
5385
5528
  'defined?',
5386
- 'defn',
5529
+ // 'defn',
5387
5530
  'do',
5388
5531
  'doseq',
5389
- 'fn',
5532
+ // 'fn',
5390
5533
  'if',
5391
5534
  'let',
5392
5535
  'loop',
@@ -5967,7 +6110,7 @@ var Lits = (function (exports) {
5967
6110
  }
5968
6111
  return node;
5969
6112
  }
5970
- function getPrecedence(operatorSign) {
6113
+ function getPrecedence(operatorSign, sourceCodeInfo) {
5971
6114
  switch (operatorSign) {
5972
6115
  case '**': // exponentiation
5973
6116
  return exponentiationPrecedence;
@@ -6006,7 +6149,7 @@ var Lits = (function (exports) {
6006
6149
  // leave room for binaryFunctionalOperatorPrecedence = 1
6007
6150
  /* v8 ignore next 2 */
6008
6151
  default:
6009
- throw new Error("Unknown binary operator: ".concat(operatorSign));
6152
+ throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
6010
6153
  }
6011
6154
  }
6012
6155
  function createNamedNormalExpressionNode(symbolNode, params, sourceCodeInfo) {
@@ -6139,7 +6282,7 @@ var Lits = (function (exports) {
6139
6282
  while (!this.isAtExpressionEnd()) {
6140
6283
  if (isA_BinaryOperatorToken(operator)) {
6141
6284
  var name_1 = operator[1];
6142
- var newPrecedece = getPrecedence(name_1);
6285
+ var newPrecedece = getPrecedence(name_1, operator[2]);
6143
6286
  if (newPrecedece <= precedence
6144
6287
  // ** (exponentiation) is right associative
6145
6288
  && !(newPrecedece === exponentiationPrecedence && precedence === exponentiationPrecedence)) {
@@ -6219,7 +6362,7 @@ var Lits = (function (exports) {
6219
6362
  this.advance();
6220
6363
  var expression = this.parseExpression();
6221
6364
  if (!isRParenToken(this.peek())) {
6222
- throw new Error('Expected closing parenthesis');
6365
+ throw new LitsError('Expected closing parenthesis', this.peek()[2]);
6223
6366
  }
6224
6367
  this.advance();
6225
6368
  return expression;
@@ -6231,10 +6374,7 @@ var Lits = (function (exports) {
6231
6374
  if (specialExpressionTypes[operatorName] !== undefined) {
6232
6375
  return withSourceCodeInfo([NodeTypes.SpecialBuiltinSymbol, specialExpressionTypes[operatorName]], token[2]);
6233
6376
  }
6234
- else if (normalExpressionTypes[operatorName] !== undefined) {
6235
- return withSourceCodeInfo([NodeTypes.NormalBuiltinSymbol, normalExpressionTypes[operatorName]], token[2]);
6236
- }
6237
- return withSourceCodeInfo([NodeTypes.UserDefinedSymbol, operatorName], token[2]);
6377
+ return withSourceCodeInfo([NodeTypes.NormalBuiltinSymbol, normalExpressionTypes[operatorName]], token[2]);
6238
6378
  }
6239
6379
  if (operatorName === '->') {
6240
6380
  return this.parseShorthandLamdaFunction();
@@ -6344,7 +6484,13 @@ var Lits = (function (exports) {
6344
6484
  this.advance();
6345
6485
  var params = [];
6346
6486
  while (!this.isAtEnd() && !isRParenToken(this.peek())) {
6347
- params.push(this.parseExpression());
6487
+ if (isOperatorToken(this.peek(), '...')) {
6488
+ this.advance();
6489
+ params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peek()[2]));
6490
+ }
6491
+ else {
6492
+ params.push(this.parseExpression());
6493
+ }
6348
6494
  var nextToken = this.peek();
6349
6495
  if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
6350
6496
  throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
@@ -6394,13 +6540,13 @@ var Lits = (function (exports) {
6394
6540
  var _b = __read(params, 1), param = _b[0];
6395
6541
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
6396
6542
  }
6397
- case specialExpressionTypes.fn:
6398
- case specialExpressionTypes.def:
6399
- case specialExpressionTypes.defn:
6543
+ case specialExpressionTypes['0_fn']:
6544
+ case specialExpressionTypes['0_def']:
6545
+ case specialExpressionTypes['0_defn']:
6400
6546
  throw new LitsError("".concat(type, " is not allowed"), symbol[2]);
6401
6547
  /* v8 ignore next 2 */
6402
6548
  default:
6403
- throw new Error("Unknown special expression: ".concat(type));
6549
+ throw new LitsError("Unknown special expression: ".concat(type), symbol[2]);
6404
6550
  }
6405
6551
  }
6406
6552
  else if (isNormalBuiltinSymbolNode(symbol) || isNormalBuiltinSymbolNode(symbol)) {
@@ -6424,7 +6570,7 @@ var Lits = (function (exports) {
6424
6570
  }
6425
6571
  this.advance();
6426
6572
  var body = this.parseExpression();
6427
- return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.fn, [
6573
+ return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_fn'], [
6428
6574
  functionArguments,
6429
6575
  [body],
6430
6576
  ]]], firstToken[2]);
@@ -6507,7 +6653,7 @@ var Lits = (function (exports) {
6507
6653
  functionArguments.push(withSourceCodeInfo([bindingTargetTypes.symbol, [[NodeTypes.UserDefinedSymbol, "$".concat(i)], undefined]], firstToken[2]));
6508
6654
  }
6509
6655
  }
6510
- var node = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.fn, [
6656
+ var node = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_fn'], [
6511
6657
  functionArguments,
6512
6658
  [exprNode],
6513
6659
  ]]], firstToken[2]);
@@ -7026,7 +7172,7 @@ var Lits = (function (exports) {
7026
7172
  this.advance();
7027
7173
  if (isSymbolToken(this.peek(), 'let')) {
7028
7174
  var letNode = this.parseLet(asSymbolToken(this.peek()));
7029
- return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.def, letNode[1][1]]], token[2]);
7175
+ return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_def'], letNode[1][1]]], token[2]);
7030
7176
  }
7031
7177
  else if (isReservedSymbolToken(this.peek(), 'function')) {
7032
7178
  this.advance();
@@ -7044,7 +7190,7 @@ var Lits = (function (exports) {
7044
7190
  }
7045
7191
  assertReservedSymbolToken(this.peek(), 'end');
7046
7192
  this.advance();
7047
- return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.defn, symbol, [
7193
+ return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_defn'], symbol, [
7048
7194
  functionArguments,
7049
7195
  body,
7050
7196
  ]]], token[2]);
@@ -7054,7 +7200,7 @@ var Lits = (function (exports) {
7054
7200
  }
7055
7201
  };
7056
7202
  Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
7057
- if (specialExpressionTypes[value] !== undefined) {
7203
+ if (specialExpressionTypes[value] !== undefined && value !== 'fn' && value !== 'def' && value !== 'defn') {
7058
7204
  return withSourceCodeInfo([NodeTypes.SpecialBuiltinSymbol, specialExpressionTypes[value]], sourceCodeInfo);
7059
7205
  }
7060
7206
  if (normalExpressionTypes[value] !== undefined) {
@@ -7512,28 +7658,6 @@ var Lits = (function (exports) {
7512
7658
  'replace',
7513
7659
  'replace-all',
7514
7660
  ],
7515
- specialExpressions: [
7516
- '&&',
7517
- '||',
7518
- 'def',
7519
- 'let',
7520
- 'fn',
7521
- 'defn',
7522
- 'function',
7523
- 'try',
7524
- 'throw',
7525
- 'if',
7526
- 'unless',
7527
- 'cond',
7528
- 'switch',
7529
- 'do',
7530
- 'recur',
7531
- 'loop',
7532
- 'doseq',
7533
- 'for',
7534
- 'defined?',
7535
- '??',
7536
- ],
7537
7661
  string: [
7538
7662
  'string-repeat',
7539
7663
  'str',