@mojir/lits 2.1.6 → 2.1.8

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.6";
95
+ var version = "2.1.8";
96
96
 
97
97
  function getCodeMarker(sourceCodeInfo) {
98
98
  if (!sourceCodeInfo.position || !sourceCodeInfo.code)
@@ -1545,13 +1545,15 @@ var arrayNormalExpression = {
1545
1545
  paramCount: 2,
1546
1546
  },
1547
1547
  flatten: {
1548
- evaluate: function (_a) {
1549
- var _b = __read(_a, 1), seq = _b[0];
1550
- if (!Array.isArray(seq))
1551
- return [];
1552
- return seq.flat(Number.POSITIVE_INFINITY);
1548
+ evaluate: function (_a, sourceCodeInfo) {
1549
+ var _b = __read(_a, 2), seq = _b[0], depth = _b[1];
1550
+ assertArray(seq, sourceCodeInfo);
1551
+ var actualDepth = depth === undefined || depth === Number.POSITIVE_INFINITY
1552
+ ? Number.POSITIVE_INFINITY
1553
+ : asNumber(depth, sourceCodeInfo, { integer: true, nonNegative: true });
1554
+ return seq.flat(actualDepth);
1553
1555
  },
1554
- paramCount: 1,
1556
+ paramCount: { min: 1, max: 2 },
1555
1557
  },
1556
1558
  mapcat: {
1557
1559
  evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
@@ -4001,6 +4003,13 @@ var regexpNormalExpression = {
4001
4003
  assertString(sourceArg, sourceCodeInfo);
4002
4004
  var source = sourceArg || '(?:)';
4003
4005
  var flags = typeof flagsArg === 'string' ? flagsArg : '';
4006
+ try {
4007
+ // eslint-disable-next-line no-new
4008
+ new RegExp(source, flags); // Throws if invalid regexp
4009
+ }
4010
+ catch (e) {
4011
+ throw new LitsError("Invalid regular expression: ".concat(source, " ").concat(flags), sourceCodeInfo);
4012
+ }
4004
4013
  return _b = {},
4005
4014
  _b[REGEXP_SYMBOL] = true,
4006
4015
  _b.sourceCodeInfo = sourceCodeInfo,
@@ -4729,6 +4738,7 @@ var gridNormalExpression = {
4729
4738
  return transpose(grid);
4730
4739
  },
4731
4740
  paramCount: 1,
4741
+ aliases: ['grid:tr'],
4732
4742
  },
4733
4743
  'grid:flip-h': {
4734
4744
  evaluate: function (_a, sourceCodeInfo) {
@@ -7107,10 +7117,10 @@ var linearAlgebraNormalExpression = {
7107
7117
  assertVector(vectorA, sourceCodeInfo);
7108
7118
  assertVector(vectorB, sourceCodeInfo);
7109
7119
  if (vectorA.length < 2) {
7110
- throw new Error('Vectors must have at least 2 elements');
7120
+ throw new LitsError('Vectors must have at least 2 elements', sourceCodeInfo);
7111
7121
  }
7112
7122
  if (vectorA.length !== vectorB.length) {
7113
- throw new Error('Vectors must be of the same length');
7123
+ throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
7114
7124
  }
7115
7125
  assertNumber(lag, sourceCodeInfo, {
7116
7126
  integer: true,
@@ -8362,7 +8372,7 @@ var partitionsNormalExpressions = {
8362
8372
  if (n === 0)
8363
8373
  return 1;
8364
8374
  if (n > partitionNumbers.length) {
8365
- throw new Error("n is too large. The maximum value is ".concat(partitionNumbers.length - 1, "."));
8375
+ throw new LitsError("n is too large. The maximum value is ".concat(partitionNumbers.length - 1, "."), sourceCodeInfo);
8366
8376
  }
8367
8377
  return partitionNumbers[n - 1];
8368
8378
  },
@@ -10501,7 +10511,12 @@ var combinatoricalNormalExpression = {
10501
10511
  var _b = __read(_a, 2), a = _b[0], m = _b[1];
10502
10512
  assertNumber(a, sourceCodeInfo, { integer: true, positive: true });
10503
10513
  assertNumber(m, sourceCodeInfo, { integer: true, positive: true });
10504
- return modInverse(a, m);
10514
+ try {
10515
+ return modInverse(a, m);
10516
+ }
10517
+ catch (error) {
10518
+ throw new LitsError(error, sourceCodeInfo);
10519
+ }
10505
10520
  },
10506
10521
  paramCount: 2,
10507
10522
  },
@@ -10520,7 +10535,7 @@ var combinatoricalNormalExpression = {
10520
10535
  assertVector(remainders, sourceCodeInfo);
10521
10536
  assertVector(moduli, sourceCodeInfo);
10522
10537
  if (remainders.length !== moduli.length) {
10523
- throw new Error('Remainders and moduli must have the same length.');
10538
+ throw new LitsError('Remainders and moduli must have the same length.', sourceCodeInfo);
10524
10539
  }
10525
10540
  try {
10526
10541
  return chineseRemainder(remainders, moduli);
@@ -11964,7 +11979,11 @@ var objectSpecialExpression = {
11964
11979
  }
11965
11980
  else {
11966
11981
  var key = evaluateNode(keyNode, contextStack);
11967
- var value = evaluateNode(params[i + 1], contextStack);
11982
+ var valueNode = params[i + 1];
11983
+ if (valueNode === undefined) {
11984
+ throw new LitsError('Missing value for key', keyNode[2]);
11985
+ }
11986
+ var value = evaluateNode(valueNode, contextStack);
11968
11987
  assertString(key, keyNode[2]);
11969
11988
  result[key] = value;
11970
11989
  }
@@ -12855,21 +12874,30 @@ var tokenizeNumber = function (input, position) {
12855
12874
  var char = input[i];
12856
12875
  if (char === '_') {
12857
12876
  if (!decimalNumberRegExp.test(input[i - 1]) || !decimalNumberRegExp.test(input[i + 1])) {
12858
- return NO_MATCH;
12877
+ if (i === start) {
12878
+ return NO_MATCH;
12879
+ }
12880
+ throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
12859
12881
  }
12860
12882
  }
12861
12883
  else if (char === '.') {
12862
- if (i === start || hasDecimalPoint || hasExponent) {
12884
+ if (i === start) {
12863
12885
  return NO_MATCH;
12864
12886
  }
12887
+ if (hasDecimalPoint || hasExponent) {
12888
+ throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
12889
+ }
12865
12890
  hasDecimalPoint = true;
12866
12891
  }
12867
12892
  else if (char === 'e' || char === 'E') {
12868
- if (i === start || hasExponent) {
12893
+ if (i === start) {
12869
12894
  return NO_MATCH;
12870
12895
  }
12896
+ if (hasExponent) {
12897
+ throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
12898
+ }
12871
12899
  if (input[i - 1] === '.' || input[i - 1] === '+' || input[i - 1] === '-') {
12872
- return NO_MATCH;
12900
+ throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
12873
12901
  }
12874
12902
  if (input[i + 1] === '+' || input[i + 1] === '-') {
12875
12903
  i += 1;
@@ -12889,7 +12917,7 @@ var tokenizeNumber = function (input, position) {
12889
12917
  }
12890
12918
  var nextChar = input[i];
12891
12919
  if (nextChar && !postNumberRegExp.test(nextChar)) {
12892
- return NO_MATCH;
12920
+ throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
12893
12921
  }
12894
12922
  return [length, ['Number', input.substring(position, i)]];
12895
12923
  };
@@ -13055,10 +13083,10 @@ function tokenize(input, debug, filePath) {
13055
13083
  hasDebugData: debug,
13056
13084
  };
13057
13085
  while (position < input.length) {
13058
- var tokenDescriptor = getCurrentToken(input, position);
13059
13086
  var sourceCodeInfo = debug
13060
13087
  ? createSourceCodeInfo(input, position, filePath)
13061
13088
  : undefined;
13089
+ var tokenDescriptor = getCurrentToken(input, position);
13062
13090
  if (!tokenDescriptor) {
13063
13091
  throw new LitsError("Unrecognized character '".concat(input[position], "'."), sourceCodeInfo);
13064
13092
  }
@@ -13168,9 +13196,6 @@ function isOperatorToken(token, operatorName) {
13168
13196
  }
13169
13197
  function assertOperatorToken(token, operatorName) {
13170
13198
  if (!isOperatorToken(token, operatorName)) {
13171
- if (operatorName) {
13172
- throw new LitsError("Unexpected token: ".concat(token, ", expected operator ").concat(operatorName), token[2]);
13173
- }
13174
13199
  throwUnexpectedToken('Operator', operatorName, token);
13175
13200
  }
13176
13201
  }
@@ -13240,8 +13265,8 @@ function isA_BinaryOperatorToken(token) {
13240
13265
  return (token === null || token === void 0 ? void 0 : token[0]) === 'Operator' && isBinaryOperator(token[1]);
13241
13266
  }
13242
13267
  function throwUnexpectedToken(expected, expectedValue, actual) {
13243
- var actualOutput = "".concat(actual[0], " '").concat(actual[1], "'");
13244
- throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual[2]);
13268
+ var actualOutput = actual ? "".concat(actual[0], " '").concat(actual[1], "'") : 'end of input';
13269
+ throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual === null || actual === void 0 ? void 0 : actual[2]);
13245
13270
  }
13246
13271
 
13247
13272
  function minifyTokenStream(tokenStream, _a) {
@@ -13389,6 +13414,11 @@ var Parser = /** @class */ (function () {
13389
13414
  Parser.prototype.peek = function () {
13390
13415
  return this.tokenStream.tokens[this.parseState.position];
13391
13416
  };
13417
+ Parser.prototype.peekSourceCodeInfo = function () {
13418
+ var _a;
13419
+ var currentToken = this.peek();
13420
+ return currentToken ? currentToken[2] : (_a = this.tokenStream.tokens.at(-1)) === null || _a === void 0 ? void 0 : _a[2];
13421
+ };
13392
13422
  Parser.prototype.peekAhead = function (count) {
13393
13423
  return this.tokenStream.tokens[this.parseState.position + count];
13394
13424
  };
@@ -13404,7 +13434,7 @@ var Parser = /** @class */ (function () {
13404
13434
  }
13405
13435
  else {
13406
13436
  if (!this.isAtEnd()) {
13407
- throw new LitsError('Expected ;', this.peek()[2]);
13437
+ throw new LitsError('Expected ;', this.peekSourceCodeInfo());
13408
13438
  }
13409
13439
  }
13410
13440
  }
@@ -13493,15 +13523,21 @@ var Parser = /** @class */ (function () {
13493
13523
  }
13494
13524
  return left;
13495
13525
  };
13526
+ Parser.prototype.asToken = function (token) {
13527
+ if (!token) {
13528
+ throw new LitsError('Unexpected end of input', this.peekSourceCodeInfo());
13529
+ }
13530
+ return token;
13531
+ };
13496
13532
  Parser.prototype.parseOperand = function () {
13497
13533
  var operand = this.parseOperandPart();
13498
13534
  var token = this.peek();
13499
13535
  while (isOperatorToken(token, '.') || isLBracketToken(token) || isLParenToken(token)) {
13500
13536
  if (token[1] === '.') {
13501
13537
  this.advance();
13502
- var symbolToken = this.peek();
13538
+ var symbolToken = this.asToken(this.peek());
13503
13539
  if (!isSymbolToken(symbolToken)) {
13504
- throw new LitsError('Expected symbol', this.peek()[2]);
13540
+ throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
13505
13541
  }
13506
13542
  var stringNode = withSourceCodeInfo([NodeTypes.String, symbolToken[1]], symbolToken[2]);
13507
13543
  operand = createAccessorNode(operand, stringNode, token[2]);
@@ -13512,7 +13548,7 @@ var Parser = /** @class */ (function () {
13512
13548
  this.advance();
13513
13549
  var expression = this.parseExpression();
13514
13550
  if (!isRBracketToken(this.peek())) {
13515
- throw new LitsError('Expected closing bracket', this.peek()[2]);
13551
+ throw new LitsError('Expected closing bracket', this.peekSourceCodeInfo());
13516
13552
  }
13517
13553
  operand = createAccessorNode(operand, expression, token[2]);
13518
13554
  this.advance();
@@ -13526,7 +13562,7 @@ var Parser = /** @class */ (function () {
13526
13562
  return operand;
13527
13563
  };
13528
13564
  Parser.prototype.parseOperandPart = function () {
13529
- var token = this.peek();
13565
+ var token = this.asToken(this.peek());
13530
13566
  // Parentheses
13531
13567
  if (isLParenToken(token)) {
13532
13568
  var positionBefore = this.parseState.position;
@@ -13538,7 +13574,7 @@ var Parser = /** @class */ (function () {
13538
13574
  this.advance();
13539
13575
  var expression = this.parseExpression();
13540
13576
  if (!isRParenToken(this.peek())) {
13541
- throw new LitsError('Expected closing parenthesis', this.peek()[2]);
13577
+ throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
13542
13578
  }
13543
13579
  this.advance();
13544
13580
  return expression;
@@ -13598,7 +13634,7 @@ var Parser = /** @class */ (function () {
13598
13634
  while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
13599
13635
  if (isOperatorToken(this.peek(), '...')) {
13600
13636
  this.advance();
13601
- params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peek()[2]));
13637
+ params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
13602
13638
  }
13603
13639
  else {
13604
13640
  var token = this.peek();
@@ -13614,7 +13650,7 @@ var Parser = /** @class */ (function () {
13614
13650
  this.advance();
13615
13651
  }
13616
13652
  else {
13617
- throw new LitsError('Expected key to be a symbol or a string', this.peek()[2]);
13653
+ throw new LitsError('Expected key to be a symbol or a string', this.peekSourceCodeInfo());
13618
13654
  }
13619
13655
  assertOperatorToken(this.peek(), ':=');
13620
13656
  this.advance();
@@ -13622,7 +13658,7 @@ var Parser = /** @class */ (function () {
13622
13658
  }
13623
13659
  var nextToken = this.peek();
13624
13660
  if (!isOperatorToken(nextToken, ',') && !isRBraceToken(nextToken)) {
13625
- throw new LitsError('Expected comma or closing brace', this.peek()[2]);
13661
+ throw new LitsError('Expected comma or closing brace', this.peekSourceCodeInfo());
13626
13662
  }
13627
13663
  if (isOperatorToken(nextToken, ',')) {
13628
13664
  this.advance();
@@ -13639,14 +13675,14 @@ var Parser = /** @class */ (function () {
13639
13675
  while (!this.isAtEnd() && !isRBracketToken(this.peek())) {
13640
13676
  if (isOperatorToken(this.peek(), '...')) {
13641
13677
  this.advance();
13642
- params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peek()[2]));
13678
+ params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
13643
13679
  }
13644
13680
  else {
13645
13681
  params.push(this.parseExpression());
13646
13682
  }
13647
13683
  var nextToken = this.peek();
13648
13684
  if (!isOperatorToken(nextToken, ',') && !isRBracketToken(nextToken)) {
13649
- throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
13685
+ throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
13650
13686
  }
13651
13687
  if (isOperatorToken(nextToken, ',')) {
13652
13688
  this.advance();
@@ -13657,26 +13693,27 @@ var Parser = /** @class */ (function () {
13657
13693
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.array, params]], firstToken[2]);
13658
13694
  };
13659
13695
  Parser.prototype.parseFunctionCall = function (symbol) {
13696
+ var _a;
13660
13697
  this.advance();
13661
13698
  var params = [];
13662
13699
  while (!this.isAtEnd() && !isRParenToken(this.peek())) {
13663
13700
  if (isOperatorToken(this.peek(), '...')) {
13664
13701
  this.advance();
13665
- params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peek()[2]));
13702
+ params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
13666
13703
  }
13667
13704
  else {
13668
13705
  params.push(this.parseExpression());
13669
13706
  }
13670
13707
  var nextToken = this.peek();
13671
13708
  if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
13672
- throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
13709
+ throw new LitsError('Expected comma or closing parenthesis', (_a = this.peek()) === null || _a === void 0 ? void 0 : _a[2]);
13673
13710
  }
13674
13711
  if (isOperatorToken(nextToken, ',')) {
13675
13712
  this.advance();
13676
13713
  }
13677
13714
  }
13678
13715
  if (!isRParenToken(this.peek())) {
13679
- throw new LitsError('Expected closing parenthesis', this.peek()[2]);
13716
+ throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
13680
13717
  }
13681
13718
  this.advance();
13682
13719
  if (isSpecialBuiltinSymbolNode(symbol)) { // Named function
@@ -13706,14 +13743,14 @@ var Parser = /** @class */ (function () {
13706
13743
  if (params.length !== 1) {
13707
13744
  throw new LitsError('Expected exactly one parameter', symbol[2]);
13708
13745
  }
13709
- var _a = __read(params, 1), param = _a[0];
13746
+ var _b = __read(params, 1), param = _b[0];
13710
13747
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
13711
13748
  }
13712
13749
  case specialExpressionTypes.throw: {
13713
13750
  if (params.length !== 1) {
13714
13751
  throw new LitsError('Expected exactly one parameter', symbol[2]);
13715
13752
  }
13716
- var _b = __read(params, 1), param = _b[0];
13753
+ var _c = __read(params, 1), param = _c[0];
13717
13754
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
13718
13755
  }
13719
13756
  case specialExpressionTypes['0_fn']:
@@ -13733,7 +13770,7 @@ var Parser = /** @class */ (function () {
13733
13770
  }
13734
13771
  };
13735
13772
  Parser.prototype.parseLambdaFunction = function () {
13736
- var firstToken = this.peek();
13773
+ var firstToken = this.asToken(this.peek());
13737
13774
  if (isLParenToken(firstToken)
13738
13775
  && isSymbolToken(this.peekAhead(1))
13739
13776
  && isOperatorToken(this.peekAhead(2), '->')) {
@@ -13767,7 +13804,7 @@ var Parser = /** @class */ (function () {
13767
13804
  var functionArguments = [];
13768
13805
  while (!this.isAtEnd() && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
13769
13806
  if (rest) {
13770
- throw new LitsError('Rest argument must be last', this.peek()[2]);
13807
+ throw new LitsError('Rest argument must be last', this.peekSourceCodeInfo());
13771
13808
  }
13772
13809
  var bindingTarget = this.parseBindingTarget();
13773
13810
  if (bindingTarget[1][1] !== undefined) {
@@ -13777,25 +13814,25 @@ var Parser = /** @class */ (function () {
13777
13814
  rest = true;
13778
13815
  }
13779
13816
  if (defaults && !bindingTarget[1][1]) {
13780
- throw new LitsError('Default arguments must be last', this.peek()[2]);
13817
+ throw new LitsError('Default arguments must be last', this.peekSourceCodeInfo());
13781
13818
  }
13782
13819
  functionArguments.push(bindingTarget);
13783
13820
  if (!isOperatorToken(this.peek(), ',') && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
13784
- throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
13821
+ throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
13785
13822
  }
13786
13823
  if (isOperatorToken(this.peek(), ',')) {
13787
13824
  this.advance();
13788
13825
  }
13789
13826
  }
13790
13827
  if (!isRParenToken(this.peek())) {
13791
- throw new LitsError('Expected closing parenthesis', this.peek()[2]);
13828
+ throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
13792
13829
  }
13793
13830
  this.advance();
13794
13831
  return functionArguments;
13795
13832
  };
13796
13833
  Parser.prototype.parseShorthandLamdaFunction = function () {
13797
13834
  var _a;
13798
- var firstToken = this.peek();
13835
+ var firstToken = this.asToken(this.peek());
13799
13836
  this.advance();
13800
13837
  var startPos = this.parseState.position;
13801
13838
  var exprNode = this.parseExpression();
@@ -13853,7 +13890,7 @@ var Parser = /** @class */ (function () {
13853
13890
  }
13854
13891
  var defaultValue = this.parseOptionalDefaulValue();
13855
13892
  if (requireDefaultValue && !defaultValue) {
13856
- throw new LitsError('Expected assignment', this.peek()[2]);
13893
+ throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
13857
13894
  }
13858
13895
  return withSourceCodeInfo([bindingTargetTypes.symbol, [symbol, defaultValue]], firstToken[2]);
13859
13896
  }
@@ -13865,7 +13902,7 @@ var Parser = /** @class */ (function () {
13865
13902
  this.advance();
13866
13903
  var symbol = asUserDefinedSymbolNode(this.parseSymbol());
13867
13904
  if (isOperatorToken(this.peek(), ':=')) {
13868
- throw new LitsError('Rest argument can not have default value', this.peek()[2]);
13905
+ throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
13869
13906
  }
13870
13907
  return withSourceCodeInfo([bindingTargetTypes.rest, [symbol[1], undefined]], firstToken[2]);
13871
13908
  }
@@ -13873,7 +13910,7 @@ var Parser = /** @class */ (function () {
13873
13910
  if (isLBracketToken(firstToken)) {
13874
13911
  this.advance();
13875
13912
  var elements = [];
13876
- var token = this.peek();
13913
+ var token = this.asToken(this.peek());
13877
13914
  var rest = false;
13878
13915
  while (!isRBracketToken(token)) {
13879
13916
  if (rest) {
@@ -13882,7 +13919,7 @@ var Parser = /** @class */ (function () {
13882
13919
  if (isOperatorToken(token, ',')) {
13883
13920
  elements.push(null);
13884
13921
  this.advance();
13885
- token = this.peek();
13922
+ token = this.asToken(this.peek());
13886
13923
  continue;
13887
13924
  }
13888
13925
  var target = this.parseBindingTarget();
@@ -13890,17 +13927,17 @@ var Parser = /** @class */ (function () {
13890
13927
  rest = true;
13891
13928
  }
13892
13929
  elements.push(target);
13893
- token = this.peek();
13930
+ token = this.asToken(this.peek());
13894
13931
  if (!isRBracketToken(token)) {
13895
13932
  assertOperatorToken(token, ',');
13896
13933
  this.advance();
13897
13934
  }
13898
- token = this.peek();
13935
+ token = this.asToken(this.peek());
13899
13936
  }
13900
13937
  this.advance();
13901
13938
  var defaultValue = this.parseOptionalDefaulValue();
13902
13939
  if (requireDefaultValue && !defaultValue) {
13903
- throw new LitsError('Expected assignment', this.peek()[2]);
13940
+ throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
13904
13941
  }
13905
13942
  return withSourceCodeInfo([bindingTargetTypes.array, [elements, defaultValue]], firstToken[2]);
13906
13943
  }
@@ -13908,7 +13945,7 @@ var Parser = /** @class */ (function () {
13908
13945
  if (isLBraceToken(firstToken)) {
13909
13946
  this.advance();
13910
13947
  var elements = {};
13911
- var token = this.peek();
13948
+ var token = this.asToken(this.peek());
13912
13949
  var rest = false;
13913
13950
  while (!isRBraceToken(token)) {
13914
13951
  if (rest) {
@@ -13919,7 +13956,7 @@ var Parser = /** @class */ (function () {
13919
13956
  this.advance();
13920
13957
  }
13921
13958
  var key = asUserDefinedSymbolNode(this.parseSymbol());
13922
- token = this.peek();
13959
+ token = this.asToken(this.peek());
13923
13960
  if (isReservedSymbolToken(token, 'as')) {
13924
13961
  if (rest) {
13925
13962
  throw new LitsError('Rest argument can not have alias', token[2]);
@@ -13936,7 +13973,7 @@ var Parser = /** @class */ (function () {
13936
13973
  throw new LitsError("Duplicate binding name: ".concat(key), token[2]);
13937
13974
  }
13938
13975
  if (rest && isOperatorToken(this.peek(), ':=')) {
13939
- throw new LitsError('Rest argument can not have default value', this.peek()[2]);
13976
+ throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
13940
13977
  }
13941
13978
  elements[key[1]] = rest
13942
13979
  ? withSourceCodeInfo([bindingTargetTypes.rest, [key[1], this.parseOptionalDefaulValue()]], firstToken[2])
@@ -13949,17 +13986,17 @@ var Parser = /** @class */ (function () {
13949
13986
  assertOperatorToken(this.peek(), ',');
13950
13987
  this.advance();
13951
13988
  }
13952
- token = this.peek();
13989
+ token = this.asToken(this.peek());
13953
13990
  }
13954
13991
  this.advance();
13955
- token = this.peek();
13992
+ token = this.asToken(this.peek());
13956
13993
  var defaultValue = this.parseOptionalDefaulValue();
13957
13994
  if (requireDefaultValue && !defaultValue) {
13958
13995
  throw new LitsError('Expected assignment', token[2]);
13959
13996
  }
13960
13997
  return withSourceCodeInfo([bindingTargetTypes.object, [elements, defaultValue]], firstToken[2]);
13961
13998
  }
13962
- throw new LitsError('Expected symbol', this.peek()[2]);
13999
+ throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
13963
14000
  };
13964
14001
  Parser.prototype.parseLet = function (token, optionalSemicolon) {
13965
14002
  if (optionalSemicolon === void 0) { optionalSemicolon = false; }
@@ -13982,7 +14019,7 @@ var Parser = /** @class */ (function () {
13982
14019
  this.advance();
13983
14020
  }
13984
14021
  else if (!isReservedSymbolToken(this.peek(), 'end')) {
13985
- throw new LitsError('Expected ;', this.peek()[2]);
14022
+ throw new LitsError('Expected ;', this.peekSourceCodeInfo());
13986
14023
  }
13987
14024
  }
13988
14025
  assertReservedSymbolToken(this.peek(), 'end');
@@ -14006,7 +14043,7 @@ var Parser = /** @class */ (function () {
14006
14043
  token = this.peek();
14007
14044
  }
14008
14045
  if (bindingNodes.length === 0) {
14009
- throw new LitsError('Expected binding', this.peek()[2]);
14046
+ throw new LitsError('Expected binding', this.peekSourceCodeInfo());
14010
14047
  }
14011
14048
  assertSymbolToken(token, 'do');
14012
14049
  this.advance();
@@ -14017,7 +14054,7 @@ var Parser = /** @class */ (function () {
14017
14054
  this.advance();
14018
14055
  }
14019
14056
  else if (!isReservedSymbolToken(this.peek(), 'end')) {
14020
- throw new LitsError('Expected ;', this.peek()[2]);
14057
+ throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14021
14058
  }
14022
14059
  }
14023
14060
  assertReservedSymbolToken(this.peek(), 'end');
@@ -14033,7 +14070,7 @@ var Parser = /** @class */ (function () {
14033
14070
  this.advance();
14034
14071
  }
14035
14072
  else if (!isReservedSymbolToken(this.peek(), 'catch')) {
14036
- throw new LitsError('Expected ;', this.peek()[2]);
14073
+ throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14037
14074
  }
14038
14075
  }
14039
14076
  var tryExpression = tryExpressions.length === 1
@@ -14055,7 +14092,7 @@ var Parser = /** @class */ (function () {
14055
14092
  this.advance();
14056
14093
  }
14057
14094
  else if (!isReservedSymbolToken(this.peek(), 'end')) {
14058
- throw new LitsError('Expected ;', this.peek()[2]);
14095
+ throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14059
14096
  }
14060
14097
  }
14061
14098
  assertReservedSymbolToken(this.peek(), 'end');
@@ -14091,7 +14128,7 @@ var Parser = /** @class */ (function () {
14091
14128
  this.advance();
14092
14129
  }
14093
14130
  else if (!isReservedSymbolToken(this.peek(), 'end')) {
14094
- throw new LitsError('Expected ;', this.peek()[2]);
14131
+ throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14095
14132
  }
14096
14133
  }
14097
14134
  assertReservedSymbolToken(this.peek(), 'end');
@@ -14105,13 +14142,13 @@ var Parser = /** @class */ (function () {
14105
14142
  this.advance();
14106
14143
  var bindingNode = this.parseBinding();
14107
14144
  var modifiers = [];
14108
- var token = this.peek();
14145
+ var token = this.asToken(this.peek());
14109
14146
  if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
14110
14147
  throw new LitsError('Expected do, each or comma', token[2]);
14111
14148
  }
14112
14149
  if (isOperatorToken(token, ',')) {
14113
14150
  this.advance();
14114
- token = this.peek();
14151
+ token = this.asToken(this.peek());
14115
14152
  }
14116
14153
  if (!isSymbolToken(token, 'let')
14117
14154
  && !isReservedSymbolToken(token, 'when')
@@ -14131,14 +14168,14 @@ var Parser = /** @class */ (function () {
14131
14168
  throw new LitsError('Duplicate binding', letNode[1][1][2]);
14132
14169
  }
14133
14170
  letBindings.push(letNode[1][1]);
14134
- token = this_2.peek();
14171
+ token = this_2.asToken(this_2.peek());
14135
14172
  if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this_2.peek(), 'each') && !isOperatorToken(token, ',')) {
14136
14173
  throw new LitsError('Expected do, each or comma', token[2]);
14137
14174
  }
14138
14175
  if (isOperatorToken(token, ',')) {
14139
14176
  this_2.advance();
14140
14177
  }
14141
- token = this_2.peek();
14178
+ token = this_2.asToken(this_2.peek());
14142
14179
  };
14143
14180
  var this_2 = this;
14144
14181
  while (isSymbolToken(token, 'let')) {
@@ -14164,14 +14201,14 @@ var Parser = /** @class */ (function () {
14164
14201
  modifiers.push('&while');
14165
14202
  whileNode = this.parseExpression();
14166
14203
  }
14167
- token = this.peek();
14204
+ token = this.asToken(this.peek());
14168
14205
  if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
14169
14206
  throw new LitsError('Expected do or comma', token[2]);
14170
14207
  }
14171
14208
  if (isOperatorToken(token, ',')) {
14172
14209
  this.advance();
14173
14210
  }
14174
- token = this.peek();
14211
+ token = this.asToken(this.peek());
14175
14212
  }
14176
14213
  if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each')) {
14177
14214
  throw new LitsError('Expected do or each', token[2]);
@@ -14208,7 +14245,7 @@ var Parser = /** @class */ (function () {
14208
14245
  this.advance();
14209
14246
  }
14210
14247
  else if (!isReservedSymbolToken(this.peek(), 'else') && !isReservedSymbolToken(this.peek(), 'end')) {
14211
- throw new LitsError('Expected ;', this.peek()[2]);
14248
+ throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14212
14249
  }
14213
14250
  }
14214
14251
  var thenExpression = thenExpressions.length === 1
@@ -14224,7 +14261,7 @@ var Parser = /** @class */ (function () {
14224
14261
  this.advance();
14225
14262
  }
14226
14263
  else if (!isReservedSymbolToken(this.peek(), 'end')) {
14227
- throw new LitsError('Expected ;', this.peek()[2]);
14264
+ throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14228
14265
  }
14229
14266
  }
14230
14267
  elseExpression = elseExpressions.length === 1
@@ -14255,7 +14292,7 @@ var Parser = /** @class */ (function () {
14255
14292
  this.advance();
14256
14293
  }
14257
14294
  else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
14258
- throw new LitsError('Expected ;', this.peek()[2]);
14295
+ throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14259
14296
  }
14260
14297
  }
14261
14298
  var thenExpression = expressions.length === 1
@@ -14290,7 +14327,7 @@ var Parser = /** @class */ (function () {
14290
14327
  this.advance();
14291
14328
  }
14292
14329
  else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
14293
- throw new LitsError('Expected ;', this.peek()[2]);
14330
+ throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14294
14331
  }
14295
14332
  }
14296
14333
  var thenExpression = expressions.length === 1
@@ -14317,7 +14354,7 @@ var Parser = /** @class */ (function () {
14317
14354
  this.advance();
14318
14355
  }
14319
14356
  else if (!isReservedSymbolToken(this.peek(), 'end')) {
14320
- throw new LitsError('Expected ;', this.peek()[2]);
14357
+ throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14321
14358
  }
14322
14359
  }
14323
14360
  assertReservedSymbolToken(this.peek(), 'end');
@@ -14361,7 +14398,7 @@ var Parser = /** @class */ (function () {
14361
14398
  this.advance();
14362
14399
  }
14363
14400
  else if (!isReservedSymbolToken(this.peek(), 'end')) {
14364
- throw new LitsError('Expected ;', this.peek()[2]);
14401
+ throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14365
14402
  }
14366
14403
  }
14367
14404
  assertReservedSymbolToken(this.peek(), 'end');
@@ -14372,7 +14409,7 @@ var Parser = /** @class */ (function () {
14372
14409
  ]]], token[2]);
14373
14410
  }
14374
14411
  else {
14375
- throw new LitsError('Expected let or function', this.peek()[2]);
14412
+ throw new LitsError('Expected let or function', this.peekSourceCodeInfo());
14376
14413
  }
14377
14414
  };
14378
14415
  Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
@@ -14397,7 +14434,7 @@ var Parser = /** @class */ (function () {
14397
14434
  });
14398
14435
  };
14399
14436
  Parser.prototype.parseSymbol = function () {
14400
- var token = this.peek();
14437
+ var token = this.asToken(this.peek());
14401
14438
  this.advance();
14402
14439
  if (!isSymbolToken(token)) {
14403
14440
  throw new LitsError("Expected symbol token, got ".concat(token[0]), token[2]);
@@ -14419,7 +14456,7 @@ var Parser = /** @class */ (function () {
14419
14456
  return withSourceCodeInfo([NodeTypes.ReservedSymbol, token[1]], token[2]);
14420
14457
  };
14421
14458
  Parser.prototype.parseNumber = function () {
14422
- var token = this.peek();
14459
+ var token = this.asToken(this.peek());
14423
14460
  this.advance();
14424
14461
  var value = token[1];
14425
14462
  var negative = value[0] === '-';
@@ -14427,7 +14464,7 @@ var Parser = /** @class */ (function () {
14427
14464
  return withSourceCodeInfo([NodeTypes.Number, negative ? -Number(numberString) : Number(numberString)], token[2]);
14428
14465
  };
14429
14466
  Parser.prototype.parseString = function () {
14430
- var token = this.peek();
14467
+ var token = this.asToken(this.peek());
14431
14468
  this.advance();
14432
14469
  var value = token[1].substring(1, token[1].length - 1)
14433
14470
  .replace(/(\\{2})|(\\")|(\\n)|(\\t)|(\\r)|(\\b)|(\\f)|\\(.)/g, function (_, backslash, doubleQuote, newline, tab, carriageReturn, backspace, formFeed, normalChar) {
@@ -14459,7 +14496,7 @@ var Parser = /** @class */ (function () {
14459
14496
  return withSourceCodeInfo([NodeTypes.String, value], token[2]);
14460
14497
  };
14461
14498
  Parser.prototype.parseRegexpShorthand = function () {
14462
- var token = this.peek();
14499
+ var token = this.asToken(this.peek());
14463
14500
  this.advance();
14464
14501
  var endStringPosition = token[1].lastIndexOf('"');
14465
14502
  var regexpString = token[1].substring(2, endStringPosition);
@@ -15357,7 +15394,6 @@ var arrayReference = {
15357
15394
  examples: [
15358
15395
  'flatten([1, 2, [3, 4], 5])',
15359
15396
  "\nlet foo := \"bar\";\nflatten([\n 1,\n \" 2 A \",\n [foo, [4, [\"ABC\"]]],\n 6,\n])",
15360
- 'flatten(12)',
15361
15397
  ],
15362
15398
  noOperatorDocumentation: true,
15363
15399
  },
@@ -19075,6 +19111,7 @@ var gridReference = {
19075
19111
  "grid:transpose(".concat(exampleGrid2, ")"),
19076
19112
  "grid:transpose(".concat(exampleGrid3, ")"),
19077
19113
  ],
19114
+ aliases: ['grid:tr'],
19078
19115
  },
19079
19116
  'grid:flip-h': {
19080
19117
  title: 'grid:flip-h',