@mojir/lits 2.1.6 → 2.1.7
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 +118 -83
- package/dist/cli/src/parser/Parser.d.ts +3 -1
- package/dist/cli/src/tokenizer/token.d.ts +51 -51
- package/dist/index.esm.js +117 -82
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +117 -82
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +117 -82
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/parser/Parser.d.ts +3 -1
- package/dist/src/tokenizer/token.d.ts +51 -51
- package/dist/testFramework.esm.js +117 -81
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +117 -81
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
|
@@ -1523,13 +1523,15 @@ var arrayNormalExpression = {
|
|
|
1523
1523
|
paramCount: 2,
|
|
1524
1524
|
},
|
|
1525
1525
|
flatten: {
|
|
1526
|
-
evaluate: function (_a) {
|
|
1527
|
-
var _b = __read(_a,
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1526
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
1527
|
+
var _b = __read(_a, 2), seq = _b[0], depth = _b[1];
|
|
1528
|
+
assertArray(seq, sourceCodeInfo);
|
|
1529
|
+
var actualDepth = depth === undefined || depth === Number.POSITIVE_INFINITY
|
|
1530
|
+
? Number.POSITIVE_INFINITY
|
|
1531
|
+
: asNumber(depth, sourceCodeInfo, { integer: true, nonNegative: true });
|
|
1532
|
+
return seq.flat(actualDepth);
|
|
1531
1533
|
},
|
|
1532
|
-
paramCount: 1,
|
|
1534
|
+
paramCount: { min: 1, max: 2 },
|
|
1533
1535
|
},
|
|
1534
1536
|
mapcat: {
|
|
1535
1537
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
@@ -3979,6 +3981,13 @@ var regexpNormalExpression = {
|
|
|
3979
3981
|
assertString(sourceArg, sourceCodeInfo);
|
|
3980
3982
|
var source = sourceArg || '(?:)';
|
|
3981
3983
|
var flags = typeof flagsArg === 'string' ? flagsArg : '';
|
|
3984
|
+
try {
|
|
3985
|
+
// eslint-disable-next-line no-new
|
|
3986
|
+
new RegExp(source, flags); // Throws if invalid regexp
|
|
3987
|
+
}
|
|
3988
|
+
catch (e) {
|
|
3989
|
+
throw new LitsError("Invalid regular expression: ".concat(source, " ").concat(flags), sourceCodeInfo);
|
|
3990
|
+
}
|
|
3982
3991
|
return _b = {},
|
|
3983
3992
|
_b[REGEXP_SYMBOL] = true,
|
|
3984
3993
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
@@ -7085,10 +7094,10 @@ var linearAlgebraNormalExpression = {
|
|
|
7085
7094
|
assertVector(vectorA, sourceCodeInfo);
|
|
7086
7095
|
assertVector(vectorB, sourceCodeInfo);
|
|
7087
7096
|
if (vectorA.length < 2) {
|
|
7088
|
-
throw new
|
|
7097
|
+
throw new LitsError('Vectors must have at least 2 elements', sourceCodeInfo);
|
|
7089
7098
|
}
|
|
7090
7099
|
if (vectorA.length !== vectorB.length) {
|
|
7091
|
-
throw new
|
|
7100
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
7092
7101
|
}
|
|
7093
7102
|
assertNumber(lag, sourceCodeInfo, {
|
|
7094
7103
|
integer: true,
|
|
@@ -8340,7 +8349,7 @@ var partitionsNormalExpressions = {
|
|
|
8340
8349
|
if (n === 0)
|
|
8341
8350
|
return 1;
|
|
8342
8351
|
if (n > partitionNumbers.length) {
|
|
8343
|
-
throw new
|
|
8352
|
+
throw new LitsError("n is too large. The maximum value is ".concat(partitionNumbers.length - 1, "."), sourceCodeInfo);
|
|
8344
8353
|
}
|
|
8345
8354
|
return partitionNumbers[n - 1];
|
|
8346
8355
|
},
|
|
@@ -10479,7 +10488,12 @@ var combinatoricalNormalExpression = {
|
|
|
10479
10488
|
var _b = __read(_a, 2), a = _b[0], m = _b[1];
|
|
10480
10489
|
assertNumber(a, sourceCodeInfo, { integer: true, positive: true });
|
|
10481
10490
|
assertNumber(m, sourceCodeInfo, { integer: true, positive: true });
|
|
10482
|
-
|
|
10491
|
+
try {
|
|
10492
|
+
return modInverse(a, m);
|
|
10493
|
+
}
|
|
10494
|
+
catch (error) {
|
|
10495
|
+
throw new LitsError(error, sourceCodeInfo);
|
|
10496
|
+
}
|
|
10483
10497
|
},
|
|
10484
10498
|
paramCount: 2,
|
|
10485
10499
|
},
|
|
@@ -10498,7 +10512,7 @@ var combinatoricalNormalExpression = {
|
|
|
10498
10512
|
assertVector(remainders, sourceCodeInfo);
|
|
10499
10513
|
assertVector(moduli, sourceCodeInfo);
|
|
10500
10514
|
if (remainders.length !== moduli.length) {
|
|
10501
|
-
throw new
|
|
10515
|
+
throw new LitsError('Remainders and moduli must have the same length.', sourceCodeInfo);
|
|
10502
10516
|
}
|
|
10503
10517
|
try {
|
|
10504
10518
|
return chineseRemainder(remainders, moduli);
|
|
@@ -11942,7 +11956,11 @@ var objectSpecialExpression = {
|
|
|
11942
11956
|
}
|
|
11943
11957
|
else {
|
|
11944
11958
|
var key = evaluateNode(keyNode, contextStack);
|
|
11945
|
-
var
|
|
11959
|
+
var valueNode = params[i + 1];
|
|
11960
|
+
if (valueNode === undefined) {
|
|
11961
|
+
throw new LitsError('Missing value for key', keyNode[2]);
|
|
11962
|
+
}
|
|
11963
|
+
var value = evaluateNode(valueNode, contextStack);
|
|
11946
11964
|
assertString(key, keyNode[2]);
|
|
11947
11965
|
result[key] = value;
|
|
11948
11966
|
}
|
|
@@ -12833,21 +12851,30 @@ var tokenizeNumber = function (input, position) {
|
|
|
12833
12851
|
var char = input[i];
|
|
12834
12852
|
if (char === '_') {
|
|
12835
12853
|
if (!decimalNumberRegExp.test(input[i - 1]) || !decimalNumberRegExp.test(input[i + 1])) {
|
|
12836
|
-
|
|
12854
|
+
if (i === start) {
|
|
12855
|
+
return NO_MATCH;
|
|
12856
|
+
}
|
|
12857
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12837
12858
|
}
|
|
12838
12859
|
}
|
|
12839
12860
|
else if (char === '.') {
|
|
12840
|
-
if (i === start
|
|
12861
|
+
if (i === start) {
|
|
12841
12862
|
return NO_MATCH;
|
|
12842
12863
|
}
|
|
12864
|
+
if (hasDecimalPoint || hasExponent) {
|
|
12865
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12866
|
+
}
|
|
12843
12867
|
hasDecimalPoint = true;
|
|
12844
12868
|
}
|
|
12845
12869
|
else if (char === 'e' || char === 'E') {
|
|
12846
|
-
if (i === start
|
|
12870
|
+
if (i === start) {
|
|
12847
12871
|
return NO_MATCH;
|
|
12848
12872
|
}
|
|
12873
|
+
if (hasExponent) {
|
|
12874
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12875
|
+
}
|
|
12849
12876
|
if (input[i - 1] === '.' || input[i - 1] === '+' || input[i - 1] === '-') {
|
|
12850
|
-
|
|
12877
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12851
12878
|
}
|
|
12852
12879
|
if (input[i + 1] === '+' || input[i + 1] === '-') {
|
|
12853
12880
|
i += 1;
|
|
@@ -12867,7 +12894,7 @@ var tokenizeNumber = function (input, position) {
|
|
|
12867
12894
|
}
|
|
12868
12895
|
var nextChar = input[i];
|
|
12869
12896
|
if (nextChar && !postNumberRegExp.test(nextChar)) {
|
|
12870
|
-
|
|
12897
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12871
12898
|
}
|
|
12872
12899
|
return [length, ['Number', input.substring(position, i)]];
|
|
12873
12900
|
};
|
|
@@ -13033,10 +13060,10 @@ function tokenize(input, debug, filePath) {
|
|
|
13033
13060
|
hasDebugData: debug,
|
|
13034
13061
|
};
|
|
13035
13062
|
while (position < input.length) {
|
|
13036
|
-
var tokenDescriptor = getCurrentToken(input, position);
|
|
13037
13063
|
var sourceCodeInfo = debug
|
|
13038
13064
|
? createSourceCodeInfo(input, position, filePath)
|
|
13039
13065
|
: undefined;
|
|
13066
|
+
var tokenDescriptor = getCurrentToken(input, position);
|
|
13040
13067
|
if (!tokenDescriptor) {
|
|
13041
13068
|
throw new LitsError("Unrecognized character '".concat(input[position], "'."), sourceCodeInfo);
|
|
13042
13069
|
}
|
|
@@ -13146,9 +13173,6 @@ function isOperatorToken(token, operatorName) {
|
|
|
13146
13173
|
}
|
|
13147
13174
|
function assertOperatorToken(token, operatorName) {
|
|
13148
13175
|
if (!isOperatorToken(token, operatorName)) {
|
|
13149
|
-
if (operatorName) {
|
|
13150
|
-
throw new LitsError("Unexpected token: ".concat(token, ", expected operator ").concat(operatorName), token[2]);
|
|
13151
|
-
}
|
|
13152
13176
|
throwUnexpectedToken('Operator', operatorName, token);
|
|
13153
13177
|
}
|
|
13154
13178
|
}
|
|
@@ -13218,8 +13242,8 @@ function isA_BinaryOperatorToken(token) {
|
|
|
13218
13242
|
return (token === null || token === void 0 ? void 0 : token[0]) === 'Operator' && isBinaryOperator(token[1]);
|
|
13219
13243
|
}
|
|
13220
13244
|
function throwUnexpectedToken(expected, expectedValue, actual) {
|
|
13221
|
-
var actualOutput = "".concat(actual[0], " '").concat(actual[1], "'");
|
|
13222
|
-
throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual[2]);
|
|
13245
|
+
var actualOutput = actual ? "".concat(actual[0], " '").concat(actual[1], "'") : 'end of input';
|
|
13246
|
+
throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual === null || actual === void 0 ? void 0 : actual[2]);
|
|
13223
13247
|
}
|
|
13224
13248
|
|
|
13225
13249
|
function minifyTokenStream(tokenStream, _a) {
|
|
@@ -13367,6 +13391,11 @@ var Parser = /** @class */ (function () {
|
|
|
13367
13391
|
Parser.prototype.peek = function () {
|
|
13368
13392
|
return this.tokenStream.tokens[this.parseState.position];
|
|
13369
13393
|
};
|
|
13394
|
+
Parser.prototype.peekSourceCodeInfo = function () {
|
|
13395
|
+
var _a;
|
|
13396
|
+
var currentToken = this.peek();
|
|
13397
|
+
return currentToken ? currentToken[2] : (_a = this.tokenStream.tokens.at(-1)) === null || _a === void 0 ? void 0 : _a[2];
|
|
13398
|
+
};
|
|
13370
13399
|
Parser.prototype.peekAhead = function (count) {
|
|
13371
13400
|
return this.tokenStream.tokens[this.parseState.position + count];
|
|
13372
13401
|
};
|
|
@@ -13382,7 +13411,7 @@ var Parser = /** @class */ (function () {
|
|
|
13382
13411
|
}
|
|
13383
13412
|
else {
|
|
13384
13413
|
if (!this.isAtEnd()) {
|
|
13385
|
-
throw new LitsError('Expected ;', this.
|
|
13414
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13386
13415
|
}
|
|
13387
13416
|
}
|
|
13388
13417
|
}
|
|
@@ -13471,15 +13500,21 @@ var Parser = /** @class */ (function () {
|
|
|
13471
13500
|
}
|
|
13472
13501
|
return left;
|
|
13473
13502
|
};
|
|
13503
|
+
Parser.prototype.asToken = function (token) {
|
|
13504
|
+
if (!token) {
|
|
13505
|
+
throw new LitsError('Unexpected end of input', this.peekSourceCodeInfo());
|
|
13506
|
+
}
|
|
13507
|
+
return token;
|
|
13508
|
+
};
|
|
13474
13509
|
Parser.prototype.parseOperand = function () {
|
|
13475
13510
|
var operand = this.parseOperandPart();
|
|
13476
13511
|
var token = this.peek();
|
|
13477
13512
|
while (isOperatorToken(token, '.') || isLBracketToken(token) || isLParenToken(token)) {
|
|
13478
13513
|
if (token[1] === '.') {
|
|
13479
13514
|
this.advance();
|
|
13480
|
-
var symbolToken = this.peek();
|
|
13515
|
+
var symbolToken = this.asToken(this.peek());
|
|
13481
13516
|
if (!isSymbolToken(symbolToken)) {
|
|
13482
|
-
throw new LitsError('Expected symbol', this.
|
|
13517
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
13483
13518
|
}
|
|
13484
13519
|
var stringNode = withSourceCodeInfo([NodeTypes.String, symbolToken[1]], symbolToken[2]);
|
|
13485
13520
|
operand = createAccessorNode(operand, stringNode, token[2]);
|
|
@@ -13490,7 +13525,7 @@ var Parser = /** @class */ (function () {
|
|
|
13490
13525
|
this.advance();
|
|
13491
13526
|
var expression = this.parseExpression();
|
|
13492
13527
|
if (!isRBracketToken(this.peek())) {
|
|
13493
|
-
throw new LitsError('Expected closing bracket', this.
|
|
13528
|
+
throw new LitsError('Expected closing bracket', this.peekSourceCodeInfo());
|
|
13494
13529
|
}
|
|
13495
13530
|
operand = createAccessorNode(operand, expression, token[2]);
|
|
13496
13531
|
this.advance();
|
|
@@ -13504,7 +13539,7 @@ var Parser = /** @class */ (function () {
|
|
|
13504
13539
|
return operand;
|
|
13505
13540
|
};
|
|
13506
13541
|
Parser.prototype.parseOperandPart = function () {
|
|
13507
|
-
var token = this.peek();
|
|
13542
|
+
var token = this.asToken(this.peek());
|
|
13508
13543
|
// Parentheses
|
|
13509
13544
|
if (isLParenToken(token)) {
|
|
13510
13545
|
var positionBefore = this.parseState.position;
|
|
@@ -13516,7 +13551,7 @@ var Parser = /** @class */ (function () {
|
|
|
13516
13551
|
this.advance();
|
|
13517
13552
|
var expression = this.parseExpression();
|
|
13518
13553
|
if (!isRParenToken(this.peek())) {
|
|
13519
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13554
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13520
13555
|
}
|
|
13521
13556
|
this.advance();
|
|
13522
13557
|
return expression;
|
|
@@ -13576,7 +13611,7 @@ var Parser = /** @class */ (function () {
|
|
|
13576
13611
|
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
13577
13612
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13578
13613
|
this.advance();
|
|
13579
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13614
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13580
13615
|
}
|
|
13581
13616
|
else {
|
|
13582
13617
|
var token = this.peek();
|
|
@@ -13592,7 +13627,7 @@ var Parser = /** @class */ (function () {
|
|
|
13592
13627
|
this.advance();
|
|
13593
13628
|
}
|
|
13594
13629
|
else {
|
|
13595
|
-
throw new LitsError('Expected key to be a symbol or a string', this.
|
|
13630
|
+
throw new LitsError('Expected key to be a symbol or a string', this.peekSourceCodeInfo());
|
|
13596
13631
|
}
|
|
13597
13632
|
assertOperatorToken(this.peek(), ':=');
|
|
13598
13633
|
this.advance();
|
|
@@ -13600,7 +13635,7 @@ var Parser = /** @class */ (function () {
|
|
|
13600
13635
|
}
|
|
13601
13636
|
var nextToken = this.peek();
|
|
13602
13637
|
if (!isOperatorToken(nextToken, ',') && !isRBraceToken(nextToken)) {
|
|
13603
|
-
throw new LitsError('Expected comma or closing brace', this.
|
|
13638
|
+
throw new LitsError('Expected comma or closing brace', this.peekSourceCodeInfo());
|
|
13604
13639
|
}
|
|
13605
13640
|
if (isOperatorToken(nextToken, ',')) {
|
|
13606
13641
|
this.advance();
|
|
@@ -13617,14 +13652,14 @@ var Parser = /** @class */ (function () {
|
|
|
13617
13652
|
while (!this.isAtEnd() && !isRBracketToken(this.peek())) {
|
|
13618
13653
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13619
13654
|
this.advance();
|
|
13620
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13655
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13621
13656
|
}
|
|
13622
13657
|
else {
|
|
13623
13658
|
params.push(this.parseExpression());
|
|
13624
13659
|
}
|
|
13625
13660
|
var nextToken = this.peek();
|
|
13626
13661
|
if (!isOperatorToken(nextToken, ',') && !isRBracketToken(nextToken)) {
|
|
13627
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13662
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13628
13663
|
}
|
|
13629
13664
|
if (isOperatorToken(nextToken, ',')) {
|
|
13630
13665
|
this.advance();
|
|
@@ -13635,26 +13670,27 @@ var Parser = /** @class */ (function () {
|
|
|
13635
13670
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.array, params]], firstToken[2]);
|
|
13636
13671
|
};
|
|
13637
13672
|
Parser.prototype.parseFunctionCall = function (symbol) {
|
|
13673
|
+
var _a;
|
|
13638
13674
|
this.advance();
|
|
13639
13675
|
var params = [];
|
|
13640
13676
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
13641
13677
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13642
13678
|
this.advance();
|
|
13643
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13679
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13644
13680
|
}
|
|
13645
13681
|
else {
|
|
13646
13682
|
params.push(this.parseExpression());
|
|
13647
13683
|
}
|
|
13648
13684
|
var nextToken = this.peek();
|
|
13649
13685
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
13650
|
-
throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
|
|
13686
|
+
throw new LitsError('Expected comma or closing parenthesis', (_a = this.peek()) === null || _a === void 0 ? void 0 : _a[2]);
|
|
13651
13687
|
}
|
|
13652
13688
|
if (isOperatorToken(nextToken, ',')) {
|
|
13653
13689
|
this.advance();
|
|
13654
13690
|
}
|
|
13655
13691
|
}
|
|
13656
13692
|
if (!isRParenToken(this.peek())) {
|
|
13657
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13693
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13658
13694
|
}
|
|
13659
13695
|
this.advance();
|
|
13660
13696
|
if (isSpecialBuiltinSymbolNode(symbol)) { // Named function
|
|
@@ -13684,14 +13720,14 @@ var Parser = /** @class */ (function () {
|
|
|
13684
13720
|
if (params.length !== 1) {
|
|
13685
13721
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13686
13722
|
}
|
|
13687
|
-
var
|
|
13723
|
+
var _b = __read(params, 1), param = _b[0];
|
|
13688
13724
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13689
13725
|
}
|
|
13690
13726
|
case specialExpressionTypes.throw: {
|
|
13691
13727
|
if (params.length !== 1) {
|
|
13692
13728
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13693
13729
|
}
|
|
13694
|
-
var
|
|
13730
|
+
var _c = __read(params, 1), param = _c[0];
|
|
13695
13731
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13696
13732
|
}
|
|
13697
13733
|
case specialExpressionTypes['0_fn']:
|
|
@@ -13711,7 +13747,7 @@ var Parser = /** @class */ (function () {
|
|
|
13711
13747
|
}
|
|
13712
13748
|
};
|
|
13713
13749
|
Parser.prototype.parseLambdaFunction = function () {
|
|
13714
|
-
var firstToken = this.peek();
|
|
13750
|
+
var firstToken = this.asToken(this.peek());
|
|
13715
13751
|
if (isLParenToken(firstToken)
|
|
13716
13752
|
&& isSymbolToken(this.peekAhead(1))
|
|
13717
13753
|
&& isOperatorToken(this.peekAhead(2), '->')) {
|
|
@@ -13745,7 +13781,7 @@ var Parser = /** @class */ (function () {
|
|
|
13745
13781
|
var functionArguments = [];
|
|
13746
13782
|
while (!this.isAtEnd() && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13747
13783
|
if (rest) {
|
|
13748
|
-
throw new LitsError('Rest argument must be last', this.
|
|
13784
|
+
throw new LitsError('Rest argument must be last', this.peekSourceCodeInfo());
|
|
13749
13785
|
}
|
|
13750
13786
|
var bindingTarget = this.parseBindingTarget();
|
|
13751
13787
|
if (bindingTarget[1][1] !== undefined) {
|
|
@@ -13755,25 +13791,25 @@ var Parser = /** @class */ (function () {
|
|
|
13755
13791
|
rest = true;
|
|
13756
13792
|
}
|
|
13757
13793
|
if (defaults && !bindingTarget[1][1]) {
|
|
13758
|
-
throw new LitsError('Default arguments must be last', this.
|
|
13794
|
+
throw new LitsError('Default arguments must be last', this.peekSourceCodeInfo());
|
|
13759
13795
|
}
|
|
13760
13796
|
functionArguments.push(bindingTarget);
|
|
13761
13797
|
if (!isOperatorToken(this.peek(), ',') && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13762
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13798
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13763
13799
|
}
|
|
13764
13800
|
if (isOperatorToken(this.peek(), ',')) {
|
|
13765
13801
|
this.advance();
|
|
13766
13802
|
}
|
|
13767
13803
|
}
|
|
13768
13804
|
if (!isRParenToken(this.peek())) {
|
|
13769
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13805
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13770
13806
|
}
|
|
13771
13807
|
this.advance();
|
|
13772
13808
|
return functionArguments;
|
|
13773
13809
|
};
|
|
13774
13810
|
Parser.prototype.parseShorthandLamdaFunction = function () {
|
|
13775
13811
|
var _a;
|
|
13776
|
-
var firstToken = this.peek();
|
|
13812
|
+
var firstToken = this.asToken(this.peek());
|
|
13777
13813
|
this.advance();
|
|
13778
13814
|
var startPos = this.parseState.position;
|
|
13779
13815
|
var exprNode = this.parseExpression();
|
|
@@ -13831,7 +13867,7 @@ var Parser = /** @class */ (function () {
|
|
|
13831
13867
|
}
|
|
13832
13868
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13833
13869
|
if (requireDefaultValue && !defaultValue) {
|
|
13834
|
-
throw new LitsError('Expected assignment', this.
|
|
13870
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13835
13871
|
}
|
|
13836
13872
|
return withSourceCodeInfo([bindingTargetTypes.symbol, [symbol, defaultValue]], firstToken[2]);
|
|
13837
13873
|
}
|
|
@@ -13843,7 +13879,7 @@ var Parser = /** @class */ (function () {
|
|
|
13843
13879
|
this.advance();
|
|
13844
13880
|
var symbol = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13845
13881
|
if (isOperatorToken(this.peek(), ':=')) {
|
|
13846
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
13882
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13847
13883
|
}
|
|
13848
13884
|
return withSourceCodeInfo([bindingTargetTypes.rest, [symbol[1], undefined]], firstToken[2]);
|
|
13849
13885
|
}
|
|
@@ -13851,7 +13887,7 @@ var Parser = /** @class */ (function () {
|
|
|
13851
13887
|
if (isLBracketToken(firstToken)) {
|
|
13852
13888
|
this.advance();
|
|
13853
13889
|
var elements = [];
|
|
13854
|
-
var token = this.peek();
|
|
13890
|
+
var token = this.asToken(this.peek());
|
|
13855
13891
|
var rest = false;
|
|
13856
13892
|
while (!isRBracketToken(token)) {
|
|
13857
13893
|
if (rest) {
|
|
@@ -13860,7 +13896,7 @@ var Parser = /** @class */ (function () {
|
|
|
13860
13896
|
if (isOperatorToken(token, ',')) {
|
|
13861
13897
|
elements.push(null);
|
|
13862
13898
|
this.advance();
|
|
13863
|
-
token = this.peek();
|
|
13899
|
+
token = this.asToken(this.peek());
|
|
13864
13900
|
continue;
|
|
13865
13901
|
}
|
|
13866
13902
|
var target = this.parseBindingTarget();
|
|
@@ -13868,17 +13904,17 @@ var Parser = /** @class */ (function () {
|
|
|
13868
13904
|
rest = true;
|
|
13869
13905
|
}
|
|
13870
13906
|
elements.push(target);
|
|
13871
|
-
token = this.peek();
|
|
13907
|
+
token = this.asToken(this.peek());
|
|
13872
13908
|
if (!isRBracketToken(token)) {
|
|
13873
13909
|
assertOperatorToken(token, ',');
|
|
13874
13910
|
this.advance();
|
|
13875
13911
|
}
|
|
13876
|
-
token = this.peek();
|
|
13912
|
+
token = this.asToken(this.peek());
|
|
13877
13913
|
}
|
|
13878
13914
|
this.advance();
|
|
13879
13915
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13880
13916
|
if (requireDefaultValue && !defaultValue) {
|
|
13881
|
-
throw new LitsError('Expected assignment', this.
|
|
13917
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13882
13918
|
}
|
|
13883
13919
|
return withSourceCodeInfo([bindingTargetTypes.array, [elements, defaultValue]], firstToken[2]);
|
|
13884
13920
|
}
|
|
@@ -13886,7 +13922,7 @@ var Parser = /** @class */ (function () {
|
|
|
13886
13922
|
if (isLBraceToken(firstToken)) {
|
|
13887
13923
|
this.advance();
|
|
13888
13924
|
var elements = {};
|
|
13889
|
-
var token = this.peek();
|
|
13925
|
+
var token = this.asToken(this.peek());
|
|
13890
13926
|
var rest = false;
|
|
13891
13927
|
while (!isRBraceToken(token)) {
|
|
13892
13928
|
if (rest) {
|
|
@@ -13897,7 +13933,7 @@ var Parser = /** @class */ (function () {
|
|
|
13897
13933
|
this.advance();
|
|
13898
13934
|
}
|
|
13899
13935
|
var key = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13900
|
-
token = this.peek();
|
|
13936
|
+
token = this.asToken(this.peek());
|
|
13901
13937
|
if (isReservedSymbolToken(token, 'as')) {
|
|
13902
13938
|
if (rest) {
|
|
13903
13939
|
throw new LitsError('Rest argument can not have alias', token[2]);
|
|
@@ -13914,7 +13950,7 @@ var Parser = /** @class */ (function () {
|
|
|
13914
13950
|
throw new LitsError("Duplicate binding name: ".concat(key), token[2]);
|
|
13915
13951
|
}
|
|
13916
13952
|
if (rest && isOperatorToken(this.peek(), ':=')) {
|
|
13917
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
13953
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13918
13954
|
}
|
|
13919
13955
|
elements[key[1]] = rest
|
|
13920
13956
|
? withSourceCodeInfo([bindingTargetTypes.rest, [key[1], this.parseOptionalDefaulValue()]], firstToken[2])
|
|
@@ -13927,17 +13963,17 @@ var Parser = /** @class */ (function () {
|
|
|
13927
13963
|
assertOperatorToken(this.peek(), ',');
|
|
13928
13964
|
this.advance();
|
|
13929
13965
|
}
|
|
13930
|
-
token = this.peek();
|
|
13966
|
+
token = this.asToken(this.peek());
|
|
13931
13967
|
}
|
|
13932
13968
|
this.advance();
|
|
13933
|
-
token = this.peek();
|
|
13969
|
+
token = this.asToken(this.peek());
|
|
13934
13970
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13935
13971
|
if (requireDefaultValue && !defaultValue) {
|
|
13936
13972
|
throw new LitsError('Expected assignment', token[2]);
|
|
13937
13973
|
}
|
|
13938
13974
|
return withSourceCodeInfo([bindingTargetTypes.object, [elements, defaultValue]], firstToken[2]);
|
|
13939
13975
|
}
|
|
13940
|
-
throw new LitsError('Expected symbol', this.
|
|
13976
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
13941
13977
|
};
|
|
13942
13978
|
Parser.prototype.parseLet = function (token, optionalSemicolon) {
|
|
13943
13979
|
if (optionalSemicolon === void 0) { optionalSemicolon = false; }
|
|
@@ -13960,7 +13996,7 @@ var Parser = /** @class */ (function () {
|
|
|
13960
13996
|
this.advance();
|
|
13961
13997
|
}
|
|
13962
13998
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
13963
|
-
throw new LitsError('Expected ;', this.
|
|
13999
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13964
14000
|
}
|
|
13965
14001
|
}
|
|
13966
14002
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -13984,7 +14020,7 @@ var Parser = /** @class */ (function () {
|
|
|
13984
14020
|
token = this.peek();
|
|
13985
14021
|
}
|
|
13986
14022
|
if (bindingNodes.length === 0) {
|
|
13987
|
-
throw new LitsError('Expected binding', this.
|
|
14023
|
+
throw new LitsError('Expected binding', this.peekSourceCodeInfo());
|
|
13988
14024
|
}
|
|
13989
14025
|
assertSymbolToken(token, 'do');
|
|
13990
14026
|
this.advance();
|
|
@@ -13995,7 +14031,7 @@ var Parser = /** @class */ (function () {
|
|
|
13995
14031
|
this.advance();
|
|
13996
14032
|
}
|
|
13997
14033
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
13998
|
-
throw new LitsError('Expected ;', this.
|
|
14034
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13999
14035
|
}
|
|
14000
14036
|
}
|
|
14001
14037
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14011,7 +14047,7 @@ var Parser = /** @class */ (function () {
|
|
|
14011
14047
|
this.advance();
|
|
14012
14048
|
}
|
|
14013
14049
|
else if (!isReservedSymbolToken(this.peek(), 'catch')) {
|
|
14014
|
-
throw new LitsError('Expected ;', this.
|
|
14050
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14015
14051
|
}
|
|
14016
14052
|
}
|
|
14017
14053
|
var tryExpression = tryExpressions.length === 1
|
|
@@ -14033,7 +14069,7 @@ var Parser = /** @class */ (function () {
|
|
|
14033
14069
|
this.advance();
|
|
14034
14070
|
}
|
|
14035
14071
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14036
|
-
throw new LitsError('Expected ;', this.
|
|
14072
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14037
14073
|
}
|
|
14038
14074
|
}
|
|
14039
14075
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14069,7 +14105,7 @@ var Parser = /** @class */ (function () {
|
|
|
14069
14105
|
this.advance();
|
|
14070
14106
|
}
|
|
14071
14107
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14072
|
-
throw new LitsError('Expected ;', this.
|
|
14108
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14073
14109
|
}
|
|
14074
14110
|
}
|
|
14075
14111
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14083,13 +14119,13 @@ var Parser = /** @class */ (function () {
|
|
|
14083
14119
|
this.advance();
|
|
14084
14120
|
var bindingNode = this.parseBinding();
|
|
14085
14121
|
var modifiers = [];
|
|
14086
|
-
var token = this.peek();
|
|
14122
|
+
var token = this.asToken(this.peek());
|
|
14087
14123
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14088
14124
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14089
14125
|
}
|
|
14090
14126
|
if (isOperatorToken(token, ',')) {
|
|
14091
14127
|
this.advance();
|
|
14092
|
-
token = this.peek();
|
|
14128
|
+
token = this.asToken(this.peek());
|
|
14093
14129
|
}
|
|
14094
14130
|
if (!isSymbolToken(token, 'let')
|
|
14095
14131
|
&& !isReservedSymbolToken(token, 'when')
|
|
@@ -14109,14 +14145,14 @@ var Parser = /** @class */ (function () {
|
|
|
14109
14145
|
throw new LitsError('Duplicate binding', letNode[1][1][2]);
|
|
14110
14146
|
}
|
|
14111
14147
|
letBindings.push(letNode[1][1]);
|
|
14112
|
-
token = this_2.peek();
|
|
14148
|
+
token = this_2.asToken(this_2.peek());
|
|
14113
14149
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this_2.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14114
14150
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14115
14151
|
}
|
|
14116
14152
|
if (isOperatorToken(token, ',')) {
|
|
14117
14153
|
this_2.advance();
|
|
14118
14154
|
}
|
|
14119
|
-
token = this_2.peek();
|
|
14155
|
+
token = this_2.asToken(this_2.peek());
|
|
14120
14156
|
};
|
|
14121
14157
|
var this_2 = this;
|
|
14122
14158
|
while (isSymbolToken(token, 'let')) {
|
|
@@ -14142,14 +14178,14 @@ var Parser = /** @class */ (function () {
|
|
|
14142
14178
|
modifiers.push('&while');
|
|
14143
14179
|
whileNode = this.parseExpression();
|
|
14144
14180
|
}
|
|
14145
|
-
token = this.peek();
|
|
14181
|
+
token = this.asToken(this.peek());
|
|
14146
14182
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14147
14183
|
throw new LitsError('Expected do or comma', token[2]);
|
|
14148
14184
|
}
|
|
14149
14185
|
if (isOperatorToken(token, ',')) {
|
|
14150
14186
|
this.advance();
|
|
14151
14187
|
}
|
|
14152
|
-
token = this.peek();
|
|
14188
|
+
token = this.asToken(this.peek());
|
|
14153
14189
|
}
|
|
14154
14190
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each')) {
|
|
14155
14191
|
throw new LitsError('Expected do or each', token[2]);
|
|
@@ -14186,7 +14222,7 @@ var Parser = /** @class */ (function () {
|
|
|
14186
14222
|
this.advance();
|
|
14187
14223
|
}
|
|
14188
14224
|
else if (!isReservedSymbolToken(this.peek(), 'else') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14189
|
-
throw new LitsError('Expected ;', this.
|
|
14225
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14190
14226
|
}
|
|
14191
14227
|
}
|
|
14192
14228
|
var thenExpression = thenExpressions.length === 1
|
|
@@ -14202,7 +14238,7 @@ var Parser = /** @class */ (function () {
|
|
|
14202
14238
|
this.advance();
|
|
14203
14239
|
}
|
|
14204
14240
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14205
|
-
throw new LitsError('Expected ;', this.
|
|
14241
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14206
14242
|
}
|
|
14207
14243
|
}
|
|
14208
14244
|
elseExpression = elseExpressions.length === 1
|
|
@@ -14233,7 +14269,7 @@ var Parser = /** @class */ (function () {
|
|
|
14233
14269
|
this.advance();
|
|
14234
14270
|
}
|
|
14235
14271
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14236
|
-
throw new LitsError('Expected ;', this.
|
|
14272
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14237
14273
|
}
|
|
14238
14274
|
}
|
|
14239
14275
|
var thenExpression = expressions.length === 1
|
|
@@ -14268,7 +14304,7 @@ var Parser = /** @class */ (function () {
|
|
|
14268
14304
|
this.advance();
|
|
14269
14305
|
}
|
|
14270
14306
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14271
|
-
throw new LitsError('Expected ;', this.
|
|
14307
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14272
14308
|
}
|
|
14273
14309
|
}
|
|
14274
14310
|
var thenExpression = expressions.length === 1
|
|
@@ -14295,7 +14331,7 @@ var Parser = /** @class */ (function () {
|
|
|
14295
14331
|
this.advance();
|
|
14296
14332
|
}
|
|
14297
14333
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14298
|
-
throw new LitsError('Expected ;', this.
|
|
14334
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14299
14335
|
}
|
|
14300
14336
|
}
|
|
14301
14337
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14339,7 +14375,7 @@ var Parser = /** @class */ (function () {
|
|
|
14339
14375
|
this.advance();
|
|
14340
14376
|
}
|
|
14341
14377
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14342
|
-
throw new LitsError('Expected ;', this.
|
|
14378
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14343
14379
|
}
|
|
14344
14380
|
}
|
|
14345
14381
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14350,7 +14386,7 @@ var Parser = /** @class */ (function () {
|
|
|
14350
14386
|
]]], token[2]);
|
|
14351
14387
|
}
|
|
14352
14388
|
else {
|
|
14353
|
-
throw new LitsError('Expected let or function', this.
|
|
14389
|
+
throw new LitsError('Expected let or function', this.peekSourceCodeInfo());
|
|
14354
14390
|
}
|
|
14355
14391
|
};
|
|
14356
14392
|
Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
|
|
@@ -14375,7 +14411,7 @@ var Parser = /** @class */ (function () {
|
|
|
14375
14411
|
});
|
|
14376
14412
|
};
|
|
14377
14413
|
Parser.prototype.parseSymbol = function () {
|
|
14378
|
-
var token = this.peek();
|
|
14414
|
+
var token = this.asToken(this.peek());
|
|
14379
14415
|
this.advance();
|
|
14380
14416
|
if (!isSymbolToken(token)) {
|
|
14381
14417
|
throw new LitsError("Expected symbol token, got ".concat(token[0]), token[2]);
|
|
@@ -14397,7 +14433,7 @@ var Parser = /** @class */ (function () {
|
|
|
14397
14433
|
return withSourceCodeInfo([NodeTypes.ReservedSymbol, token[1]], token[2]);
|
|
14398
14434
|
};
|
|
14399
14435
|
Parser.prototype.parseNumber = function () {
|
|
14400
|
-
var token = this.peek();
|
|
14436
|
+
var token = this.asToken(this.peek());
|
|
14401
14437
|
this.advance();
|
|
14402
14438
|
var value = token[1];
|
|
14403
14439
|
var negative = value[0] === '-';
|
|
@@ -14405,7 +14441,7 @@ var Parser = /** @class */ (function () {
|
|
|
14405
14441
|
return withSourceCodeInfo([NodeTypes.Number, negative ? -Number(numberString) : Number(numberString)], token[2]);
|
|
14406
14442
|
};
|
|
14407
14443
|
Parser.prototype.parseString = function () {
|
|
14408
|
-
var token = this.peek();
|
|
14444
|
+
var token = this.asToken(this.peek());
|
|
14409
14445
|
this.advance();
|
|
14410
14446
|
var value = token[1].substring(1, token[1].length - 1)
|
|
14411
14447
|
.replace(/(\\{2})|(\\")|(\\n)|(\\t)|(\\r)|(\\b)|(\\f)|\\(.)/g, function (_, backslash, doubleQuote, newline, tab, carriageReturn, backspace, formFeed, normalChar) {
|
|
@@ -14437,7 +14473,7 @@ var Parser = /** @class */ (function () {
|
|
|
14437
14473
|
return withSourceCodeInfo([NodeTypes.String, value], token[2]);
|
|
14438
14474
|
};
|
|
14439
14475
|
Parser.prototype.parseRegexpShorthand = function () {
|
|
14440
|
-
var token = this.peek();
|
|
14476
|
+
var token = this.asToken(this.peek());
|
|
14441
14477
|
this.advance();
|
|
14442
14478
|
var endStringPosition = token[1].lastIndexOf('"');
|
|
14443
14479
|
var regexpString = token[1].substring(2, endStringPosition);
|