@mojir/lits 2.1.13 → 2.1.15

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 (40) hide show
  1. package/README.md +0 -6
  2. package/dist/cli/cli.js +351 -1312
  3. package/dist/cli/reference/api.d.ts +2 -2
  4. package/dist/cli/reference/index.d.ts +3 -5
  5. package/dist/cli/src/Lits/Lits.d.ts +1 -5
  6. package/dist/cli/src/builtin/index.d.ts +2 -2
  7. package/dist/cli/src/builtin/specialExpressionTypes.d.ts +1 -1
  8. package/dist/cli/src/builtin/specialExpressions/{do.d.ts → block.d.ts} +1 -1
  9. package/dist/cli/src/builtin/specialExpressions/def.d.ts +2 -1
  10. package/dist/cli/src/builtin/specialExpressions/functions.d.ts +2 -2
  11. package/dist/cli/src/builtin/specialExpressions/loops.d.ts +2 -2
  12. package/dist/cli/src/evaluator/ContextStack.d.ts +2 -4
  13. package/dist/cli/src/parser/Parser.d.ts +1 -1
  14. package/dist/cli/src/tokenizer/operators.d.ts +2 -2
  15. package/dist/cli/src/tokenizer/reservedNames.d.ts +0 -16
  16. package/dist/index.esm.js +350 -1311
  17. package/dist/index.esm.js.map +1 -1
  18. package/dist/index.js +350 -1311
  19. package/dist/index.js.map +1 -1
  20. package/dist/lits.iife.js +350 -1311
  21. package/dist/lits.iife.js.map +1 -1
  22. package/dist/reference/api.d.ts +2 -2
  23. package/dist/reference/index.d.ts +3 -5
  24. package/dist/src/Lits/Lits.d.ts +1 -5
  25. package/dist/src/builtin/index.d.ts +2 -2
  26. package/dist/src/builtin/specialExpressionTypes.d.ts +1 -1
  27. package/dist/src/builtin/specialExpressions/{do.d.ts → block.d.ts} +1 -1
  28. package/dist/src/builtin/specialExpressions/def.d.ts +2 -1
  29. package/dist/src/builtin/specialExpressions/functions.d.ts +2 -2
  30. package/dist/src/builtin/specialExpressions/loops.d.ts +2 -2
  31. package/dist/src/evaluator/ContextStack.d.ts +2 -4
  32. package/dist/src/index.d.ts +1 -1
  33. package/dist/src/parser/Parser.d.ts +1 -1
  34. package/dist/src/tokenizer/operators.d.ts +2 -2
  35. package/dist/src/tokenizer/reservedNames.d.ts +0 -16
  36. package/dist/testFramework.esm.js +145 -244
  37. package/dist/testFramework.esm.js.map +1 -1
  38. package/dist/testFramework.js +145 -244
  39. package/dist/testFramework.js.map +1 -1
  40. package/package.json +1 -1
@@ -183,7 +183,7 @@ var specialExpressionTypes = {
183
183
  '0_def': 5,
184
184
  'defined?': 6,
185
185
  '0_defn': 7,
186
- 'do': 8,
186
+ 'block': 8,
187
187
  'doseq': 9,
188
188
  '0_fn': 10,
189
189
  'for': 11,
@@ -321,7 +321,7 @@ var getUndefinedSymbols = function (ast, contextStack, builtin, evaluateNode) {
321
321
  var _b;
322
322
  var nodes = Array.isArray(ast)
323
323
  ? ast
324
- : [[NodeTypes.SpecialExpression, [specialExpressionTypes.do, ast.body]]];
324
+ : [[NodeTypes.SpecialExpression, [specialExpressionTypes.block, ast.body]]];
325
325
  var unresolvedSymbols = new Set();
326
326
  try {
327
327
  for (var nodes_1 = __values(nodes), nodes_1_1 = nodes_1.next(); !nodes_1_1.done; nodes_1_1 = nodes_1.next()) {
@@ -3457,7 +3457,7 @@ function isIdentical(_a) {
3457
3457
  return true;
3458
3458
  }
3459
3459
  var miscNormalExpression = {
3460
- '=': {
3460
+ '==': {
3461
3461
  evaluate: function (params, sourceCodeInfo) {
3462
3462
  return isEqual(params, sourceCodeInfo);
3463
3463
  },
@@ -11600,7 +11600,7 @@ var defSpecialExpression = {
11600
11600
  var bindingValue = evaluateNode(value, contextStack);
11601
11601
  var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
11602
11602
  contextStack.exportValues(values, target[2]);
11603
- return null;
11603
+ return bindingValue;
11604
11604
  },
11605
11605
  getUndefinedSymbols: function (node, contextStack, _a) {
11606
11606
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
@@ -11649,9 +11649,7 @@ var nonNumberReservedSymbolRecord = {
11649
11649
  true: true,
11650
11650
  false: false,
11651
11651
  null: null,
11652
- then: null,
11653
11652
  else: null,
11654
- end: null,
11655
11653
  case: null,
11656
11654
  each: null,
11657
11655
  in: null,
@@ -11685,10 +11683,6 @@ var numberReservedSymbolRecord = {
11685
11683
  'MIN_SAFE_INTEGER': Number.MIN_SAFE_INTEGER,
11686
11684
  'MAX_VALUE': Number.MAX_VALUE,
11687
11685
  'MIN_VALUE': Number.MIN_VALUE,
11688
- 'DELTA': Number.EPSILON, // TODO use DELTA instead of DELTA δ
11689
- '-DELTA': -Number.EPSILON,
11690
- 'δ': Number.EPSILON, // TODO use DELTA instead of DELTA δ
11691
- '-δ': -Number.EPSILON,
11692
11686
  'NaN': Number.NaN,
11693
11687
  };
11694
11688
  var reservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
@@ -11731,7 +11725,7 @@ var functionSpecialExpression = {
11731
11725
  _b.evaluatedfunction = evaluatedFunction,
11732
11726
  _b);
11733
11727
  contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
11734
- return null;
11728
+ return litsFunction;
11735
11729
  },
11736
11730
  getUndefinedSymbols: function (node, contextStack, _a) {
11737
11731
  var _b, _c;
@@ -11759,7 +11753,7 @@ var defnSpecialExpression = {
11759
11753
  _b.evaluatedfunction = evaluatedFunctionOverloades,
11760
11754
  _b);
11761
11755
  contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
11762
- return null;
11756
+ return litsFunction;
11763
11757
  },
11764
11758
  getUndefinedSymbols: function (node, contextStack, _a) {
11765
11759
  var _b, _c;
@@ -11879,7 +11873,7 @@ var letSpecialExpression = {
11879
11873
  var bindingValue = evaluateNode(value, contextStack);
11880
11874
  var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
11881
11875
  contextStack.addValues(values, target[2]);
11882
- return null;
11876
+ return bindingValue;
11883
11877
  },
11884
11878
  getUndefinedSymbols: function (node, contextStack, _a) {
11885
11879
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
@@ -12011,13 +12005,12 @@ function evaluateLoop(returnResult, loopNode, contextStack, evaluateNode) {
12011
12005
  var bindingIndices = loopBindings.map(function () { return 0; });
12012
12006
  var abort = false;
12013
12007
  var _loop_1 = function () {
12014
- var e_2, _b;
12015
12008
  var context = {};
12016
12009
  var newContextStack = contextStack.create(context);
12017
12010
  var skip = false;
12018
12011
  bindingsLoop: for (var bindingIndex = 0; bindingIndex < loopBindings.length; bindingIndex += 1) {
12019
- var _c = __read(loopBindings[bindingIndex], 4), bindingNode = _c[0], letBindings = _c[1], whenNode = _c[2], whileNode = _c[3];
12020
- var _d = __read(bindingNode[1], 2), targetNode = _d[0], valueNode = _d[1];
12012
+ var _b = __read(loopBindings[bindingIndex], 4), bindingNode = _b[0], letBindings = _b[1], whenNode = _b[2], whileNode = _b[3];
12013
+ var _c = __read(bindingNode[1], 2), targetNode = _c[0], valueNode = _c[1];
12021
12014
  var coll = asColl(evaluateNode(valueNode, newContextStack), sourceCodeInfo);
12022
12015
  var seq = isSeq(coll) ? coll : Object.entries(coll);
12023
12016
  if (seq.length === 0) {
@@ -12057,20 +12050,7 @@ function evaluateLoop(returnResult, loopNode, contextStack, evaluateNode) {
12057
12050
  }
12058
12051
  }
12059
12052
  if (!skip) {
12060
- var value = null;
12061
- try {
12062
- for (var body_1 = (e_2 = void 0, __values(body)), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
12063
- var form = body_1_1.value;
12064
- value = evaluateNode(form, newContextStack);
12065
- }
12066
- }
12067
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
12068
- finally {
12069
- try {
12070
- if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
12071
- }
12072
- finally { if (e_2) throw e_2.error; }
12073
- }
12053
+ var value = evaluateNode(body, newContextStack);
12074
12054
  if (returnResult)
12075
12055
  result.push(value);
12076
12056
  if (bindingIndices.length > 0)
@@ -12113,7 +12093,7 @@ function analyze(loopNode, contextStack, getUndefinedSymbols, builtin, evaluateN
12113
12093
  });
12114
12094
  }
12115
12095
  });
12116
- getUndefinedSymbols(body, contextStack.create(newContext), builtin, evaluateNode).forEach(function (symbol) {
12096
+ getUndefinedSymbols([body], contextStack.create(newContext), builtin, evaluateNode).forEach(function (symbol) {
12117
12097
  return result.add(symbol);
12118
12098
  });
12119
12099
  return result;
@@ -12423,10 +12403,7 @@ var functionExecutors = {
12423
12403
  NativeJsFunction: function (fn, params, sourceCodeInfo) {
12424
12404
  var _a;
12425
12405
  try {
12426
- // eslint-disable-next-line ts/no-unsafe-assignment
12427
- var clonedParams = JSON.parse(JSON.stringify(params));
12428
- // eslint-disable-next-line ts/no-unsafe-argument
12429
- return toAny((_a = fn.nativeFn).fn.apply(_a, __spreadArray([], __read(clonedParams), false)));
12406
+ return toAny((_a = fn.nativeFn).fn.apply(_a, __spreadArray([], __read(params), false)));
12430
12407
  }
12431
12408
  catch (error) {
12432
12409
  var message = typeof error === 'string'
@@ -12831,11 +12808,10 @@ function isContextEntry(value) {
12831
12808
 
12832
12809
  var ContextStackImpl = /** @class */ (function () {
12833
12810
  function ContextStackImpl(_a) {
12834
- var contexts = _a.contexts, hostValues = _a.values, lazyHostValues = _a.lazyValues, nativeJsFunctions = _a.nativeJsFunctions;
12811
+ var contexts = _a.contexts, hostValues = _a.values, nativeJsFunctions = _a.nativeJsFunctions;
12835
12812
  this.globalContext = asNonUndefined(contexts[0]);
12836
12813
  this.contexts = contexts;
12837
12814
  this.values = hostValues;
12838
- this.lazyValues = lazyHostValues;
12839
12815
  this.nativeJsFunctions = nativeJsFunctions;
12840
12816
  }
12841
12817
  ContextStackImpl.prototype.create = function (context) {
@@ -12843,7 +12819,6 @@ var ContextStackImpl = /** @class */ (function () {
12843
12819
  var contextStack = new ContextStackImpl({
12844
12820
  contexts: __spreadArray([context], __read(this.contexts), false),
12845
12821
  values: this.values,
12846
- lazyValues: this.lazyValues,
12847
12822
  nativeJsFunctions: this.nativeJsFunctions,
12848
12823
  });
12849
12824
  contextStack.globalContext = globalContext;
@@ -12877,7 +12852,9 @@ var ContextStackImpl = /** @class */ (function () {
12877
12852
  }
12878
12853
  finally { if (e_1) throw e_1.error; }
12879
12854
  }
12880
- this.addValues(values, sourceCodeInfo);
12855
+ if (this.contexts[0] !== this.globalContext) {
12856
+ this.addValues(values, sourceCodeInfo);
12857
+ }
12881
12858
  };
12882
12859
  ContextStackImpl.prototype.addValues = function (values, sourceCodeInfo) {
12883
12860
  var e_2, _a;
@@ -12907,10 +12884,10 @@ var ContextStackImpl = /** @class */ (function () {
12907
12884
  };
12908
12885
  ContextStackImpl.prototype.getValue = function (name) {
12909
12886
  var e_3, _a;
12910
- var _b, _c, _d;
12887
+ var _b, _c;
12911
12888
  try {
12912
- for (var _e = __values(this.contexts), _f = _e.next(); !_f.done; _f = _e.next()) {
12913
- var context = _f.value;
12889
+ for (var _d = __values(this.contexts), _e = _d.next(); !_e.done; _e = _d.next()) {
12890
+ var context = _e.value;
12914
12891
  var contextEntry = context[name];
12915
12892
  if (contextEntry)
12916
12893
  return contextEntry.value;
@@ -12919,26 +12896,22 @@ var ContextStackImpl = /** @class */ (function () {
12919
12896
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
12920
12897
  finally {
12921
12898
  try {
12922
- if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
12899
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
12923
12900
  }
12924
12901
  finally { if (e_3) throw e_3.error; }
12925
12902
  }
12926
- var lazyHostValue = (_b = this.lazyValues) === null || _b === void 0 ? void 0 : _b[name];
12927
- if (lazyHostValue)
12928
- return lazyHostValue.read();
12929
- var nativeJsFunction = (_c = this.nativeJsFunctions) === null || _c === void 0 ? void 0 : _c[name];
12903
+ var nativeJsFunction = (_b = this.nativeJsFunctions) === null || _b === void 0 ? void 0 : _b[name];
12930
12904
  if (nativeJsFunction)
12931
12905
  return nativeJsFunction;
12932
- return (_d = this.values) === null || _d === void 0 ? void 0 : _d[name];
12906
+ return (_c = this.values) === null || _c === void 0 ? void 0 : _c[name];
12933
12907
  };
12934
12908
  ContextStackImpl.prototype.lookUp = function (node) {
12935
12909
  var e_4, _a;
12936
- var _b, _c, _d;
12910
+ var _b, _c;
12937
12911
  var value = node[1];
12938
12912
  try {
12939
- // const sourceCodeInfo = node[2]
12940
- for (var _e = __values(this.contexts), _f = _e.next(); !_f.done; _f = _e.next()) {
12941
- var context = _f.value;
12913
+ for (var _d = __values(this.contexts), _e = _d.next(); !_e.done; _e = _d.next()) {
12914
+ var context = _e.value;
12942
12915
  var contextEntry = context[value];
12943
12916
  if (contextEntry)
12944
12917
  return contextEntry;
@@ -12947,23 +12920,17 @@ var ContextStackImpl = /** @class */ (function () {
12947
12920
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
12948
12921
  finally {
12949
12922
  try {
12950
- if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
12923
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
12951
12924
  }
12952
12925
  finally { if (e_4) throw e_4.error; }
12953
12926
  }
12954
- var lazyHostValue = (_b = this.lazyValues) === null || _b === void 0 ? void 0 : _b[value];
12955
- if (lazyHostValue !== undefined) {
12956
- return {
12957
- value: toAny(lazyHostValue.read()),
12958
- };
12959
- }
12960
- var hostValue = (_c = this.values) === null || _c === void 0 ? void 0 : _c[value];
12927
+ var hostValue = (_b = this.values) === null || _b === void 0 ? void 0 : _b[value];
12961
12928
  if (hostValue !== undefined) {
12962
12929
  return {
12963
12930
  value: toAny(hostValue),
12964
12931
  };
12965
12932
  }
12966
- var nativeJsFunction = (_d = this.nativeJsFunctions) === null || _d === void 0 ? void 0 : _d[value];
12933
+ var nativeJsFunction = (_c = this.nativeJsFunctions) === null || _c === void 0 ? void 0 : _c[value];
12967
12934
  if (nativeJsFunction) {
12968
12935
  return {
12969
12936
  value: nativeJsFunction,
@@ -13019,7 +12986,6 @@ function createContextStack(params) {
13019
12986
  var contextStack = new ContextStackImpl({
13020
12987
  contexts: contexts,
13021
12988
  values: params.values,
13022
- lazyValues: params.lazyValues,
13023
12989
  nativeJsFunctions: params.jsFunctions
13024
12990
  && Object.entries(params.jsFunctions).reduce(function (acc, _a) {
13025
12991
  var _b;
@@ -13042,7 +13008,7 @@ function createContextStack(params) {
13042
13008
  return acc;
13043
13009
  }, {}),
13044
13010
  });
13045
- return contextStack.create({});
13011
+ return params.globalModuleScope ? contextStack : contextStack.create({});
13046
13012
  }
13047
13013
 
13048
13014
  var binaryOperators = [
@@ -13062,7 +13028,7 @@ var binaryOperators = [
13062
13028
  '>', // greater than
13063
13029
  '>=', // greater than or equal
13064
13030
  '≥', // greater than or equal
13065
- '=', // equal
13031
+ '==', // equal
13066
13032
  '!=', // not equal
13067
13033
  '≠', // not equal
13068
13034
  '&', // bitwise AND
@@ -13080,7 +13046,8 @@ var otherOperators = [
13080
13046
  '...', // rest
13081
13047
  '.', // property accessor
13082
13048
  ',', // item separator
13083
- ':=', // property assignment
13049
+ '=', // assignment
13050
+ ':', // property assignment
13084
13051
  ';', // statement terminator
13085
13052
  ];
13086
13053
  var symbolicOperators = __spreadArray(__spreadArray([], __read(binaryOperators), false), __read(otherOperators), false);
@@ -13089,7 +13056,7 @@ var nonFunctionOperators = [
13089
13056
  'cond',
13090
13057
  'def',
13091
13058
  'defined?',
13092
- 'do',
13059
+ 'block',
13093
13060
  'doseq',
13094
13061
  'if',
13095
13062
  'let',
@@ -13289,7 +13256,7 @@ var tokenizeNumber = function (input, position) {
13289
13256
  return NO_MATCH;
13290
13257
  }
13291
13258
  var nextChar = input[i];
13292
- if (nextChar && !postNumberRegExp.test(nextChar)) {
13259
+ if (nextChar && nextChar !== ':' && !postNumberRegExp.test(nextChar)) {
13293
13260
  throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
13294
13261
  }
13295
13262
  return [length, ['Number', input.substring(position, i)]];
@@ -13366,7 +13333,10 @@ var tokenizeSymbol = function (input, position) {
13366
13333
  position += 1;
13367
13334
  char = input[position];
13368
13335
  }
13369
- return [position - initialPosition, ['Symbol', value]];
13336
+ // : can be used as symbol character, but it must not be the last character
13337
+ return value.endsWith(':')
13338
+ ? [position - initialPosition - 1, ['Symbol', value.slice(0, -1)]]
13339
+ : [position - initialPosition, ['Symbol', value]];
13370
13340
  }
13371
13341
  return NO_MATCH;
13372
13342
  };
@@ -13702,7 +13672,7 @@ function getPrecedence(operatorSign, sourceCodeInfo) {
13702
13672
  case '>=': // greater than or equal
13703
13673
  case '≥': // greater than or equal
13704
13674
  return 7;
13705
- case '=': // equal
13675
+ case '==': // equal
13706
13676
  case '!=': // not equal
13707
13677
  case '≠': // not equal
13708
13678
  return 6;
@@ -13753,7 +13723,7 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
13753
13723
  case '>':
13754
13724
  case '>=':
13755
13725
  case '≥':
13756
- case '=':
13726
+ case '==':
13757
13727
  case '!=':
13758
13728
  case '≠':
13759
13729
  case '&':
@@ -13768,12 +13738,12 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
13768
13738
  /* v8 ignore next 11 */
13769
13739
  case '.':
13770
13740
  case ';':
13771
- case ':=':
13741
+ case ':':
13742
+ case '=':
13772
13743
  case ',':
13773
13744
  case '->':
13774
13745
  case '...':
13775
13746
  case '?':
13776
- case ':':
13777
13747
  throw new LitsError("Unknown binary operator: ".concat(operatorName), sourceCodeInfo);
13778
13748
  default:
13779
13749
  throw new LitsError("Unknown binary operator: ".concat(operatorName), sourceCodeInfo);
@@ -13836,9 +13806,9 @@ var Parser = /** @class */ (function () {
13836
13806
  case 'doseq':
13837
13807
  left = this.parseForOrDoseq(firstToken);
13838
13808
  break;
13839
- case 'do':
13840
- left = this.parseDo(firstToken);
13841
- break;
13809
+ // cas:
13810
+ // left = this.parseDo(firstToken)
13811
+ // break
13842
13812
  case 'loop':
13843
13813
  left = this.parseLoop(firstToken);
13844
13814
  break;
@@ -13981,9 +13951,17 @@ var Parser = /** @class */ (function () {
13981
13951
  throw new LitsError("Illegal operator: ".concat(operatorName), token[2]);
13982
13952
  }
13983
13953
  }
13984
- // Object litteral, e.g. {a=1, b=2}
13954
+ // Object litteral, e.g. {a: 1, b: 2}
13955
+ // Or block.
13985
13956
  if (isLBraceToken(token)) {
13986
- return this.parseObject();
13957
+ var positionBefore = this.parseState.position;
13958
+ try {
13959
+ return this.parseObject();
13960
+ }
13961
+ catch (_a) {
13962
+ this.parseState.position = positionBefore;
13963
+ return this.parseBlock();
13964
+ }
13987
13965
  }
13988
13966
  // Array litteral, e.g. [1, 2]
13989
13967
  if (isLBracketToken(token)) {
@@ -14038,7 +14016,7 @@ var Parser = /** @class */ (function () {
14038
14016
  else {
14039
14017
  throw new LitsError('Expected key to be a symbol or a string', this.peekSourceCodeInfo());
14040
14018
  }
14041
- assertOperatorToken(this.peek(), ':=');
14019
+ assertOperatorToken(this.peek(), ':');
14042
14020
  this.advance();
14043
14021
  params.push(this.parseExpression());
14044
14022
  }
@@ -14259,7 +14237,7 @@ var Parser = /** @class */ (function () {
14259
14237
  return node;
14260
14238
  };
14261
14239
  Parser.prototype.parseOptionalDefaulValue = function () {
14262
- if (isOperatorToken(this.peek(), ':=')) {
14240
+ if (isOperatorToken(this.peek(), '=')) {
14263
14241
  this.advance();
14264
14242
  return this.parseExpression();
14265
14243
  }
@@ -14287,7 +14265,7 @@ var Parser = /** @class */ (function () {
14287
14265
  }
14288
14266
  this.advance();
14289
14267
  var symbol = asUserDefinedSymbolNode(this.parseSymbol());
14290
- if (isOperatorToken(this.peek(), ':=')) {
14268
+ if (isOperatorToken(this.peek(), '=')) {
14291
14269
  throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
14292
14270
  }
14293
14271
  return withSourceCodeInfo([bindingTargetTypes.rest, [symbol[1], undefined]], firstToken[2]);
@@ -14354,11 +14332,11 @@ var Parser = /** @class */ (function () {
14354
14332
  }
14355
14333
  elements[key[1]] = withSourceCodeInfo([bindingTargetTypes.symbol, [name_2, this.parseOptionalDefaulValue()]], firstToken[2]);
14356
14334
  }
14357
- else if (isRBraceToken(token) || isOperatorToken(token, ',') || isOperatorToken(token, ':=')) {
14335
+ else if (isRBraceToken(token) || isOperatorToken(token, ',') || isOperatorToken(token, '=')) {
14358
14336
  if (elements[key[1]]) {
14359
14337
  throw new LitsError("Duplicate binding name: ".concat(key), token[2]);
14360
14338
  }
14361
- if (rest && isOperatorToken(this.peek(), ':=')) {
14339
+ if (rest && isOperatorToken(this.peek(), '=')) {
14362
14340
  throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
14363
14341
  }
14364
14342
  elements[key[1]] = rest
@@ -14384,45 +14362,45 @@ var Parser = /** @class */ (function () {
14384
14362
  }
14385
14363
  throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
14386
14364
  };
14387
- Parser.prototype.parseLet = function (token, optionalSemicolon) {
14388
- if (optionalSemicolon === void 0) { optionalSemicolon = false; }
14365
+ Parser.prototype.parseLet = function (token) {
14389
14366
  this.advance();
14390
14367
  var target = this.parseBindingTarget({ requireDefaultValue: true, noRest: true });
14391
14368
  var value = target[1][1];
14392
14369
  target[1][1] = undefined;
14393
- if (!optionalSemicolon) {
14394
- assertOperatorToken(this.peek(), ';');
14395
- }
14396
14370
  var bindingTarget = withSourceCodeInfo([NodeTypes.Binding, [target, value]], token[2]);
14397
14371
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.let, bindingTarget]], token[2]);
14398
14372
  };
14399
- Parser.prototype.parseDo = function (token) {
14373
+ Parser.prototype.parseBlock = function () {
14374
+ var token = asLBraceToken(this.peek());
14400
14375
  this.advance();
14401
14376
  var expressions = [];
14402
- while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
14377
+ while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
14403
14378
  expressions.push(this.parseExpression());
14404
14379
  if (isOperatorToken(this.peek(), ';')) {
14405
14380
  this.advance();
14406
14381
  }
14407
- else if (!isReservedSymbolToken(this.peek(), 'end')) {
14408
- throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14382
+ else if (!isRBraceToken(this.peek())) {
14383
+ throw new LitsError('Expected }', this.peekSourceCodeInfo());
14409
14384
  }
14410
14385
  }
14411
- assertReservedSymbolToken(this.peek(), 'end');
14386
+ if (expressions.length === 0) {
14387
+ expressions.push(withSourceCodeInfo([NodeTypes.ReservedSymbol, 'null'], token[2]));
14388
+ }
14389
+ assertRBraceToken(this.peek());
14412
14390
  this.advance();
14413
- return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, expressions]], token[2]);
14391
+ return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
14414
14392
  };
14415
14393
  Parser.prototype.parseLoop = function (firstToken) {
14394
+ this.advance();
14395
+ assertLParenToken(this.peek());
14416
14396
  this.advance();
14417
14397
  var bindingNodes = [];
14418
14398
  var token = this.peek();
14419
- while (!this.isAtEnd() && !isSymbolToken(token, 'do')) {
14420
- assertSymbolToken(token, 'let');
14421
- this.advance();
14399
+ while (!this.isAtEnd() && !isRParenToken(token)) {
14422
14400
  var target = this.parseBindingTarget({ requireDefaultValue: true, noRest: true });
14423
14401
  var value = target[1][1];
14424
14402
  target[1][1] = undefined;
14425
- bindingNodes.push(withSourceCodeInfo([NodeTypes.Binding, [target, value]], token[2]));
14403
+ bindingNodes.push(withSourceCodeInfo([NodeTypes.Binding, [target, value]], target[2]));
14426
14404
  if (isOperatorToken(this.peek(), ',')) {
14427
14405
  this.advance();
14428
14406
  }
@@ -14431,37 +14409,27 @@ var Parser = /** @class */ (function () {
14431
14409
  if (bindingNodes.length === 0) {
14432
14410
  throw new LitsError('Expected binding', this.peekSourceCodeInfo());
14433
14411
  }
14434
- assertSymbolToken(token, 'do');
14412
+ assertRParenToken(token);
14413
+ this.advance();
14414
+ assertLBraceToken(this.peek());
14435
14415
  this.advance();
14436
14416
  var params = [];
14437
- while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
14417
+ while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
14438
14418
  params.push(this.parseExpression());
14439
14419
  if (isOperatorToken(this.peek(), ';')) {
14440
14420
  this.advance();
14441
14421
  }
14442
- else if (!isReservedSymbolToken(this.peek(), 'end')) {
14422
+ else if (!isRBraceToken(this.peek())) {
14443
14423
  throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14444
14424
  }
14445
14425
  }
14446
- assertReservedSymbolToken(this.peek(), 'end');
14426
+ assertRBraceToken(this.peek());
14447
14427
  this.advance();
14448
14428
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.loop, bindingNodes, params]], firstToken[2]);
14449
14429
  };
14450
14430
  Parser.prototype.parseTry = function (token) {
14451
14431
  this.advance();
14452
- var tryExpressions = [];
14453
- while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'catch')) {
14454
- tryExpressions.push(this.parseExpression());
14455
- if (isOperatorToken(this.peek(), ';')) {
14456
- this.advance();
14457
- }
14458
- else if (!isReservedSymbolToken(this.peek(), 'catch')) {
14459
- throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14460
- }
14461
- }
14462
- var tryExpression = tryExpressions.length === 1
14463
- ? tryExpressions[0]
14464
- : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, tryExpressions]], token[2]);
14432
+ var tryExpression = this.parseBlock();
14465
14433
  assertReservedSymbolToken(this.peek(), 'catch');
14466
14434
  this.advance();
14467
14435
  var errorSymbol;
@@ -14471,26 +14439,14 @@ var Parser = /** @class */ (function () {
14471
14439
  assertRParenToken(this.peek());
14472
14440
  this.advance();
14473
14441
  }
14474
- var catchExpressions = [];
14475
- while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
14476
- catchExpressions.push(this.parseExpression());
14477
- if (isOperatorToken(this.peek(), ';')) {
14478
- this.advance();
14479
- }
14480
- else if (!isReservedSymbolToken(this.peek(), 'end')) {
14481
- throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14482
- }
14483
- }
14484
- assertReservedSymbolToken(this.peek(), 'end');
14485
- this.advance();
14486
- var catchExpression = catchExpressions.length === 1
14487
- ? catchExpressions[0]
14488
- : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, catchExpressions]], token[2]);
14442
+ var catchExpression = this.parseBlock();
14489
14443
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.try, tryExpression, errorSymbol, catchExpression]], token[2]);
14490
14444
  };
14491
14445
  Parser.prototype.parseForOrDoseq = function (firstToken) {
14492
14446
  var isDoseq = firstToken[1] === 'doseq';
14493
14447
  this.advance();
14448
+ assertLParenToken(this.peek());
14449
+ this.advance();
14494
14450
  var forLoopBindings = [];
14495
14451
  var _loop_1 = function () {
14496
14452
  var loopBinding = this_1.parseForLoopBinding();
@@ -14500,37 +14456,27 @@ var Parser = /** @class */ (function () {
14500
14456
  throw new LitsError('Duplicate binding', loopBinding[0][2]);
14501
14457
  }
14502
14458
  forLoopBindings.push(loopBinding);
14459
+ if (isOperatorToken(this_1.peek(), ';')) {
14460
+ this_1.advance();
14461
+ }
14503
14462
  };
14504
14463
  var this_1 = this;
14505
- while (!this.isAtEnd() && !isSymbolToken(this.peek(), 'do')) {
14464
+ while (!this.isAtEnd() && !isRParenToken(this.peek())) {
14506
14465
  _loop_1();
14507
14466
  }
14508
- assertSymbolToken(this.peek(), 'do');
14509
- this.advance();
14510
- var expressions = [];
14511
- while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
14512
- expressions.push(this.parseExpression());
14513
- if (isOperatorToken(this.peek(), ';')) {
14514
- this.advance();
14515
- }
14516
- else if (!isReservedSymbolToken(this.peek(), 'end')) {
14517
- throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14518
- }
14519
- }
14520
- assertReservedSymbolToken(this.peek(), 'end');
14467
+ assertRParenToken(this.peek());
14521
14468
  this.advance();
14469
+ var expression = this.parseExpression();
14522
14470
  return isDoseq
14523
- ? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.doseq, forLoopBindings, expressions]], firstToken[2])
14524
- : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.for, forLoopBindings, expressions]], firstToken[2]);
14471
+ ? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.doseq, forLoopBindings, expression]], firstToken[2])
14472
+ : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.for, forLoopBindings, expression]], firstToken[2]);
14525
14473
  };
14526
14474
  Parser.prototype.parseForLoopBinding = function () {
14527
- assertReservedSymbolToken(this.peek(), 'each');
14528
- this.advance();
14529
14475
  var bindingNode = this.parseBinding();
14530
14476
  var modifiers = [];
14531
14477
  var token = this.asToken(this.peek());
14532
- if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
14533
- throw new LitsError('Expected do, each or comma', token[2]);
14478
+ if (!isRParenToken(token) && !isOperatorToken(this.peek(), ';') && !isOperatorToken(token, ',')) {
14479
+ throw new LitsError('Expected ")", ";" or ","', token[2]);
14534
14480
  }
14535
14481
  if (isOperatorToken(token, ',')) {
14536
14482
  this.advance();
@@ -14539,15 +14485,15 @@ var Parser = /** @class */ (function () {
14539
14485
  if (!isSymbolToken(token, 'let')
14540
14486
  && !isReservedSymbolToken(token, 'when')
14541
14487
  && !isReservedSymbolToken(token, 'while')
14542
- && !isSymbolToken(token, 'do')
14543
- && !isReservedSymbolToken(token, 'each')) {
14544
- throw new LitsError('Expected symbol each, do, let, when or while', token[2]);
14488
+ && !isRParenToken(token)
14489
+ && !isOperatorToken(token, ';')) {
14490
+ throw new LitsError('Expected symbol ";", ")", let, when or while', token[2]);
14545
14491
  }
14546
14492
  var letBindings = [];
14547
14493
  if (token[1] === 'let') {
14548
14494
  modifiers.push('&let');
14549
14495
  var _loop_2 = function () {
14550
- var letNode = this_2.parseLet(token, true);
14496
+ var letNode = this_2.parseLet(token);
14551
14497
  var existingBoundNames = letBindings.flatMap(function (b) { return Object.keys(getAllBindingTargetNames(b[1][0])); });
14552
14498
  var newBoundNames = Object.keys(getAllBindingTargetNames(letNode[1][1][1][0]));
14553
14499
  if (newBoundNames.some(function (n) { return existingBoundNames.includes(n); })) {
@@ -14555,8 +14501,8 @@ var Parser = /** @class */ (function () {
14555
14501
  }
14556
14502
  letBindings.push(letNode[1][1]);
14557
14503
  token = this_2.asToken(this_2.peek());
14558
- if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this_2.peek(), 'each') && !isOperatorToken(token, ',')) {
14559
- throw new LitsError('Expected do, each or comma', token[2]);
14504
+ if (!isRParenToken(token) && !isOperatorToken(token, ';') && !isOperatorToken(token, ',')) {
14505
+ throw new LitsError('Expected ")", ";" or ","', token[2]);
14560
14506
  }
14561
14507
  if (isOperatorToken(token, ',')) {
14562
14508
  this_2.advance();
@@ -14588,7 +14534,7 @@ var Parser = /** @class */ (function () {
14588
14534
  whileNode = this.parseExpression();
14589
14535
  }
14590
14536
  token = this.asToken(this.peek());
14591
- if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
14537
+ if (!isRParenToken(token) && !isOperatorToken(token, ';') && !isOperatorToken(token, ',')) {
14592
14538
  throw new LitsError('Expected do or comma', token[2]);
14593
14539
  }
14594
14540
  if (isOperatorToken(token, ',')) {
@@ -14596,8 +14542,8 @@ var Parser = /** @class */ (function () {
14596
14542
  }
14597
14543
  token = this.asToken(this.peek());
14598
14544
  }
14599
- if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each')) {
14600
- throw new LitsError('Expected do or each', token[2]);
14545
+ if (!isRParenToken(token) && !isOperatorToken(token, ';')) {
14546
+ throw new LitsError('Expected "{" or ";"', token[2]);
14601
14547
  }
14602
14548
  return [bindingNode, letBindings, whenNode, whileNode];
14603
14549
  };
@@ -14619,113 +14565,95 @@ var Parser = /** @class */ (function () {
14619
14565
  Parser.prototype.parseIfOrUnless = function (token) {
14620
14566
  var isUnless = token[1] === 'unless';
14621
14567
  this.advance();
14568
+ assertLParenToken(this.peek());
14569
+ this.advance();
14622
14570
  var condition = this.parseExpression();
14623
- assertReservedSymbolToken(this.peek(), 'then');
14571
+ assertRParenToken(this.peek());
14624
14572
  this.advance();
14625
- var thenExpressions = [];
14626
- while (!this.isAtEnd()
14627
- && !isReservedSymbolToken(this.peek(), 'else')
14628
- && !isReservedSymbolToken(this.peek(), 'end')) {
14629
- thenExpressions.push(this.parseExpression());
14630
- if (isOperatorToken(this.peek(), ';')) {
14631
- this.advance();
14632
- }
14633
- else if (!isReservedSymbolToken(this.peek(), 'else') && !isReservedSymbolToken(this.peek(), 'end')) {
14634
- throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14635
- }
14636
- }
14637
- var thenExpression = thenExpressions.length === 1
14638
- ? thenExpressions[0]
14639
- : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, thenExpressions]], token[2]);
14573
+ var thenExpression = this.parseExpression();
14640
14574
  var elseExpression;
14641
14575
  if (isReservedSymbolToken(this.peek(), 'else')) {
14642
14576
  this.advance();
14643
- var elseExpressions = [];
14644
- while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
14645
- elseExpressions.push(this.parseExpression());
14646
- if (isOperatorToken(this.peek(), ';')) {
14647
- this.advance();
14648
- }
14649
- else if (!isReservedSymbolToken(this.peek(), 'end')) {
14650
- throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14651
- }
14652
- }
14653
- elseExpression = elseExpressions.length === 1
14654
- ? elseExpressions[0]
14655
- : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, elseExpressions]], token[2]);
14577
+ elseExpression = this.parseExpression();
14656
14578
  }
14657
- assertReservedSymbolToken(this.peek(), 'end');
14658
- this.advance();
14659
14579
  return isUnless
14660
14580
  ? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.unless, [condition, thenExpression, elseExpression]]], token[2])
14661
14581
  : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.if, [condition, thenExpression, elseExpression]]], token[2]);
14662
14582
  };
14663
14583
  Parser.prototype.parseCond = function (token) {
14584
+ this.advance();
14585
+ assertLBraceToken(this.peek());
14664
14586
  this.advance();
14665
14587
  var params = [];
14666
- while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
14588
+ while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
14667
14589
  assertReservedSymbolToken(this.peek(), 'case');
14668
14590
  this.advance();
14669
14591
  var caseExpression = this.parseExpression();
14670
- assertReservedSymbolToken(this.peek(), 'then');
14592
+ assertOperatorToken(this.peek(), ':');
14671
14593
  this.advance();
14672
14594
  var expressions = [];
14673
14595
  while (!this.isAtEnd()
14674
14596
  && !isReservedSymbolToken(this.peek(), 'case')
14675
- && !isReservedSymbolToken(this.peek(), 'end')) {
14597
+ && !isRBraceToken(this.peek())) {
14676
14598
  expressions.push(this.parseExpression());
14677
14599
  if (isOperatorToken(this.peek(), ';')) {
14678
14600
  this.advance();
14679
14601
  }
14680
- else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
14602
+ else if (!isReservedSymbolToken(this.peek(), 'case') && !isRBraceToken(this.peek())) {
14681
14603
  throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14682
14604
  }
14683
14605
  }
14684
14606
  var thenExpression = expressions.length === 1
14685
14607
  ? expressions[0]
14686
- : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, expressions]], token[2]);
14608
+ : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
14687
14609
  params.push([caseExpression, thenExpression]);
14688
- if (isReservedSymbolToken(this.peek(), 'end')) {
14610
+ if (isRBraceToken(this.peek())) {
14689
14611
  break;
14690
14612
  }
14691
14613
  assertReservedSymbolToken(this.peek(), 'case');
14692
14614
  }
14693
- assertReservedSymbolToken(this.peek(), 'end');
14615
+ assertRBraceToken(this.peek());
14694
14616
  this.advance();
14695
14617
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.cond, params]], token[2]);
14696
14618
  };
14697
14619
  Parser.prototype.parseSwitch = function (token) {
14620
+ this.advance();
14621
+ assertLParenToken(this.peek());
14698
14622
  this.advance();
14699
14623
  var valueExpression = this.parseExpression();
14624
+ assertRParenToken(this.peek());
14625
+ this.advance();
14626
+ assertLBraceToken(this.peek());
14627
+ this.advance();
14700
14628
  var params = [];
14701
- while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
14629
+ while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
14702
14630
  assertReservedSymbolToken(this.peek(), 'case');
14703
14631
  this.advance();
14704
14632
  var caseExpression = this.parseExpression();
14705
- assertReservedSymbolToken(this.peek(), 'then');
14633
+ assertOperatorToken(this.peek(), ':');
14706
14634
  this.advance();
14707
14635
  var expressions = [];
14708
14636
  while (!this.isAtEnd()
14709
14637
  && !isReservedSymbolToken(this.peek(), 'case')
14710
- && !isReservedSymbolToken(this.peek(), 'end')) {
14638
+ && !isRBraceToken(this.peek())) {
14711
14639
  expressions.push(this.parseExpression());
14712
14640
  if (isOperatorToken(this.peek(), ';')) {
14713
14641
  this.advance();
14714
14642
  }
14715
- else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
14643
+ else if (!isReservedSymbolToken(this.peek(), 'case') && !isRBraceToken(this.peek())) {
14716
14644
  throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14717
14645
  }
14718
14646
  }
14719
14647
  var thenExpression = expressions.length === 1
14720
14648
  ? expressions[0]
14721
- : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, expressions]], token[2]);
14649
+ : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
14722
14650
  params.push([caseExpression, thenExpression]);
14723
- if (isReservedSymbolToken(this.peek(), 'end')) {
14651
+ if (isRBraceToken(this.peek())) {
14724
14652
  break;
14725
14653
  }
14726
14654
  assertReservedSymbolToken(this.peek(), 'case');
14727
14655
  }
14728
- assertReservedSymbolToken(this.peek(), 'end');
14656
+ assertRBraceToken(this.peek());
14729
14657
  this.advance();
14730
14658
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.switch, valueExpression, params]], token[2]);
14731
14659
  };
@@ -14733,22 +14661,10 @@ var Parser = /** @class */ (function () {
14733
14661
  this.advance();
14734
14662
  var symbol = this.parseSymbol();
14735
14663
  var functionArguments = this.parseFunctionArguments();
14736
- var body = [];
14737
- while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
14738
- body.push(this.parseExpression());
14739
- if (isOperatorToken(this.peek(), ';')) {
14740
- this.advance();
14741
- }
14742
- else if (!isReservedSymbolToken(this.peek(), 'end')) {
14743
- throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14744
- }
14745
- }
14746
- assertReservedSymbolToken(this.peek(), 'end');
14747
- this.advance();
14748
- assertOperatorToken(this.peek(), ';');
14664
+ var block = this.parseBlock();
14749
14665
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.function, symbol, [
14750
14666
  functionArguments,
14751
- body,
14667
+ block[1][1],
14752
14668
  ]]], token[2]);
14753
14669
  };
14754
14670
  Parser.prototype.isAtEnd = function () {
@@ -14760,39 +14676,24 @@ var Parser = /** @class */ (function () {
14760
14676
  }
14761
14677
  var token = this.peek();
14762
14678
  if (isOperatorToken(token)) {
14763
- return [';', ',', ':='].includes(token[1]);
14679
+ return [';', ',', ':'].includes(token[1]);
14764
14680
  }
14765
14681
  if (isReservedSymbolToken(token)) {
14766
- return ['else', 'when', 'while', 'then', 'end', 'case', 'catch'].includes(token[1]);
14682
+ return ['else', 'when', 'while', 'case', 'catch'].includes(token[1]);
14767
14683
  }
14768
14684
  return false;
14769
14685
  };
14770
- Parser.prototype.parseExport = function (token) {
14686
+ Parser.prototype.parseExport = function (exportToken) {
14771
14687
  this.advance();
14772
- if (isSymbolToken(this.peek(), 'let')) {
14773
- var letNode = this.parseLet(asSymbolToken(this.peek()));
14774
- return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_def'], letNode[1][1]]], token[2]);
14775
- }
14776
- else if (isReservedSymbolToken(this.peek(), 'function')) {
14777
- this.advance();
14778
- var symbol = this.parseSymbol();
14779
- var functionArguments = this.parseFunctionArguments();
14780
- var body = [];
14781
- while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
14782
- body.push(this.parseExpression());
14783
- if (isOperatorToken(this.peek(), ';')) {
14784
- this.advance();
14785
- }
14786
- else if (!isReservedSymbolToken(this.peek(), 'end')) {
14787
- throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14788
- }
14789
- }
14790
- assertReservedSymbolToken(this.peek(), 'end');
14791
- this.advance();
14792
- return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_defn'], symbol, [
14793
- functionArguments,
14794
- body,
14795
- ]]], token[2]);
14688
+ var token = this.peek();
14689
+ if (isSymbolToken(token, 'let')) {
14690
+ var letNode = this.parseLet(asSymbolToken(token));
14691
+ return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_def'], letNode[1][1]]], exportToken[2]);
14692
+ }
14693
+ else if (isReservedSymbolToken(token, 'function')) {
14694
+ var functionNode = this.parseFunction(token);
14695
+ functionNode[1][0] = specialExpressionTypes['0_defn'];
14696
+ return functionNode;
14796
14697
  }
14797
14698
  else {
14798
14699
  throw new LitsError('Expected let or function', this.peekSourceCodeInfo());