@mojir/lits 2.1.5 → 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 +575 -489
- package/dist/cli/reference/api.d.ts +4 -4
- package/dist/cli/reference/index.d.ts +3 -3
- package/dist/cli/src/parser/Parser.d.ts +3 -1
- package/dist/cli/src/parser/types.d.ts +1 -0
- package/dist/cli/src/tokenizer/operators.d.ts +2 -2
- package/dist/cli/src/tokenizer/reservedNames.d.ts +2 -0
- package/dist/cli/src/tokenizer/token.d.ts +51 -51
- package/dist/index.esm.js +574 -488
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +574 -488
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +574 -488
- package/dist/lits.iife.js.map +1 -1
- package/dist/reference/api.d.ts +4 -4
- package/dist/reference/index.d.ts +3 -3
- package/dist/src/parser/Parser.d.ts +3 -1
- package/dist/src/parser/types.d.ts +1 -0
- package/dist/src/tokenizer/operators.d.ts +2 -2
- package/dist/src/tokenizer/reservedNames.d.ts +2 -0
- package/dist/src/tokenizer/token.d.ts +51 -51
- package/dist/testFramework.esm.js +415 -326
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +415 -326
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/testFramework.js
CHANGED
|
@@ -922,6 +922,32 @@ function assertCharArray(value, sourceCodeInfo) {
|
|
|
922
922
|
throw getAssertionError('array of strings', value, sourceCodeInfo);
|
|
923
923
|
}
|
|
924
924
|
|
|
925
|
+
function mapObjects(_a) {
|
|
926
|
+
var colls = _a.colls, contextStack = _a.contextStack, executeFunction = _a.executeFunction, fn = _a.fn, sourceCodeInfo = _a.sourceCodeInfo;
|
|
927
|
+
assertObj(colls[0], sourceCodeInfo);
|
|
928
|
+
var keys = Object.keys(colls[0]);
|
|
929
|
+
var params = {};
|
|
930
|
+
colls.forEach(function (obj) {
|
|
931
|
+
assertObj(obj, sourceCodeInfo);
|
|
932
|
+
var objKeys = Object.keys(obj);
|
|
933
|
+
if (objKeys.length !== keys.length) {
|
|
934
|
+
throw new LitsError("All objects must have the same keys. Expected: ".concat(keys.join(', '), ". Found: ").concat(objKeys.join(', ')), sourceCodeInfo);
|
|
935
|
+
}
|
|
936
|
+
if (!objKeys.every(function (key) { return keys.includes(key); })) {
|
|
937
|
+
throw new LitsError("All objects must have the same keys. Expected: ".concat(keys.join(', '), ". Found: ").concat(objKeys.join(', ')), sourceCodeInfo);
|
|
938
|
+
}
|
|
939
|
+
Object.entries(obj).forEach(function (_a) {
|
|
940
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
941
|
+
if (!params[key])
|
|
942
|
+
params[key] = [];
|
|
943
|
+
params[key].push(value);
|
|
944
|
+
});
|
|
945
|
+
});
|
|
946
|
+
return keys.reduce(function (result, key) {
|
|
947
|
+
result[key] = executeFunction(fn, params[key], contextStack, sourceCodeInfo);
|
|
948
|
+
return result;
|
|
949
|
+
}, {});
|
|
950
|
+
}
|
|
925
951
|
function cloneAndGetMeta(originalColl, keys, sourceCodeInfo) {
|
|
926
952
|
var coll = cloneColl(originalColl);
|
|
927
953
|
var butLastKeys = keys.slice(0, keys.length - 1);
|
|
@@ -1014,6 +1040,188 @@ function assoc(coll, key, value, sourceCodeInfo) {
|
|
|
1014
1040
|
return copy;
|
|
1015
1041
|
}
|
|
1016
1042
|
var collectionNormalExpression = {
|
|
1043
|
+
'filter': {
|
|
1044
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1045
|
+
var _c = __read(_a, 2), coll = _c[0], fn = _c[1];
|
|
1046
|
+
var executeFunction = _b.executeFunction;
|
|
1047
|
+
assertColl(coll, sourceCodeInfo);
|
|
1048
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1049
|
+
if (Array.isArray(coll)) {
|
|
1050
|
+
var result = coll.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); });
|
|
1051
|
+
return result;
|
|
1052
|
+
}
|
|
1053
|
+
if (isString(coll)) {
|
|
1054
|
+
return coll
|
|
1055
|
+
.split('')
|
|
1056
|
+
.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); })
|
|
1057
|
+
.join('');
|
|
1058
|
+
}
|
|
1059
|
+
return Object.entries(coll)
|
|
1060
|
+
.filter(function (_a) {
|
|
1061
|
+
var _b = __read(_a, 2), value = _b[1];
|
|
1062
|
+
return executeFunction(fn, [value], contextStack, sourceCodeInfo);
|
|
1063
|
+
})
|
|
1064
|
+
.reduce(function (result, _a) {
|
|
1065
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
1066
|
+
result[key] = value;
|
|
1067
|
+
return result;
|
|
1068
|
+
}, {});
|
|
1069
|
+
},
|
|
1070
|
+
paramCount: 2,
|
|
1071
|
+
},
|
|
1072
|
+
'map': {
|
|
1073
|
+
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1074
|
+
var executeFunction = _a.executeFunction;
|
|
1075
|
+
var fn = asFunctionLike(params.at(-1), sourceCodeInfo);
|
|
1076
|
+
if (isObj(params[0])) {
|
|
1077
|
+
return mapObjects({
|
|
1078
|
+
colls: params.slice(0, -1),
|
|
1079
|
+
fn: fn,
|
|
1080
|
+
sourceCodeInfo: sourceCodeInfo,
|
|
1081
|
+
contextStack: contextStack,
|
|
1082
|
+
executeFunction: executeFunction,
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
var seqs = params.slice(0, -1);
|
|
1086
|
+
assertSeq(seqs[0], sourceCodeInfo);
|
|
1087
|
+
var isStr = typeof seqs[0] === 'string';
|
|
1088
|
+
var len = seqs[0].length;
|
|
1089
|
+
seqs.slice(1).forEach(function (seq) {
|
|
1090
|
+
if (isStr) {
|
|
1091
|
+
assertString(seq, sourceCodeInfo);
|
|
1092
|
+
}
|
|
1093
|
+
else {
|
|
1094
|
+
assertArray(seq, sourceCodeInfo);
|
|
1095
|
+
}
|
|
1096
|
+
len = Math.min(len, seq.length);
|
|
1097
|
+
});
|
|
1098
|
+
var paramArray = [];
|
|
1099
|
+
var _loop_1 = function (i) {
|
|
1100
|
+
paramArray.push(seqs.map(function (seq) { return seq[i]; }));
|
|
1101
|
+
};
|
|
1102
|
+
for (var i = 0; i < len; i++) {
|
|
1103
|
+
_loop_1(i);
|
|
1104
|
+
}
|
|
1105
|
+
var mapped = paramArray.map(function (p) { return executeFunction(fn, p, contextStack, sourceCodeInfo); });
|
|
1106
|
+
if (!isStr) {
|
|
1107
|
+
return mapped;
|
|
1108
|
+
}
|
|
1109
|
+
mapped.forEach(function (char) { return assertString(char, sourceCodeInfo); });
|
|
1110
|
+
return mapped.join('');
|
|
1111
|
+
},
|
|
1112
|
+
paramCount: { min: 2 },
|
|
1113
|
+
},
|
|
1114
|
+
'reduce': {
|
|
1115
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1116
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1117
|
+
var executeFunction = _b.executeFunction;
|
|
1118
|
+
assertColl(coll, sourceCodeInfo);
|
|
1119
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1120
|
+
assertAny(initial, sourceCodeInfo);
|
|
1121
|
+
if (typeof coll === 'string') {
|
|
1122
|
+
assertString(initial, sourceCodeInfo);
|
|
1123
|
+
if (coll.length === 0)
|
|
1124
|
+
return initial;
|
|
1125
|
+
return coll.split('').reduce(function (result, elem) {
|
|
1126
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1127
|
+
}, initial);
|
|
1128
|
+
}
|
|
1129
|
+
else if (Array.isArray(coll)) {
|
|
1130
|
+
if (coll.length === 0)
|
|
1131
|
+
return initial;
|
|
1132
|
+
return coll.reduce(function (result, elem) {
|
|
1133
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1134
|
+
}, initial);
|
|
1135
|
+
}
|
|
1136
|
+
else {
|
|
1137
|
+
if (Object.keys(coll).length === 0)
|
|
1138
|
+
return initial;
|
|
1139
|
+
return Object.entries(coll).reduce(function (result, _a) {
|
|
1140
|
+
var _b = __read(_a, 2), elem = _b[1];
|
|
1141
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1142
|
+
}, initial);
|
|
1143
|
+
}
|
|
1144
|
+
},
|
|
1145
|
+
paramCount: 3,
|
|
1146
|
+
},
|
|
1147
|
+
'reduce-right': {
|
|
1148
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1149
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1150
|
+
var executeFunction = _b.executeFunction;
|
|
1151
|
+
assertColl(coll, sourceCodeInfo);
|
|
1152
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1153
|
+
assertAny(initial, sourceCodeInfo);
|
|
1154
|
+
if (typeof coll === 'string') {
|
|
1155
|
+
if (coll.length === 0)
|
|
1156
|
+
return initial;
|
|
1157
|
+
return coll.split('').reduceRight(function (result, elem) {
|
|
1158
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1159
|
+
}, initial);
|
|
1160
|
+
}
|
|
1161
|
+
else if (Array.isArray(coll)) {
|
|
1162
|
+
if (coll.length === 0)
|
|
1163
|
+
return initial;
|
|
1164
|
+
return coll.reduceRight(function (result, elem) {
|
|
1165
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1166
|
+
}, initial);
|
|
1167
|
+
}
|
|
1168
|
+
else {
|
|
1169
|
+
if (Object.keys(coll).length === 0)
|
|
1170
|
+
return initial;
|
|
1171
|
+
return Object.entries(coll).reduceRight(function (result, _a) {
|
|
1172
|
+
var _b = __read(_a, 2), elem = _b[1];
|
|
1173
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1174
|
+
}, initial);
|
|
1175
|
+
}
|
|
1176
|
+
},
|
|
1177
|
+
paramCount: 3,
|
|
1178
|
+
},
|
|
1179
|
+
'reductions': {
|
|
1180
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1181
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1182
|
+
var executeFunction = _b.executeFunction;
|
|
1183
|
+
assertColl(coll, sourceCodeInfo);
|
|
1184
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1185
|
+
assertAny(initial, sourceCodeInfo);
|
|
1186
|
+
assertAny(initial, sourceCodeInfo);
|
|
1187
|
+
if (typeof coll === 'string') {
|
|
1188
|
+
assertString(initial, sourceCodeInfo);
|
|
1189
|
+
if (coll.length === 0)
|
|
1190
|
+
return [initial];
|
|
1191
|
+
var resultArray_1 = [initial];
|
|
1192
|
+
coll.split('').reduce(function (result, elem) {
|
|
1193
|
+
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1194
|
+
resultArray_1.push(newVal);
|
|
1195
|
+
return newVal;
|
|
1196
|
+
}, initial);
|
|
1197
|
+
return resultArray_1;
|
|
1198
|
+
}
|
|
1199
|
+
else if (Array.isArray(coll)) {
|
|
1200
|
+
if (coll.length === 0)
|
|
1201
|
+
return [initial];
|
|
1202
|
+
var resultArray_2 = [initial];
|
|
1203
|
+
coll.reduce(function (result, elem) {
|
|
1204
|
+
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1205
|
+
resultArray_2.push(newVal);
|
|
1206
|
+
return newVal;
|
|
1207
|
+
}, initial);
|
|
1208
|
+
return resultArray_2;
|
|
1209
|
+
}
|
|
1210
|
+
else {
|
|
1211
|
+
if (Object.keys(coll).length === 0)
|
|
1212
|
+
return [initial];
|
|
1213
|
+
var resultArray_3 = [initial];
|
|
1214
|
+
Object.entries(coll).reduce(function (result, _a) {
|
|
1215
|
+
var _b = __read(_a, 2), elem = _b[1];
|
|
1216
|
+
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1217
|
+
resultArray_3.push(newVal);
|
|
1218
|
+
return newVal;
|
|
1219
|
+
}, initial);
|
|
1220
|
+
return resultArray_3;
|
|
1221
|
+
}
|
|
1222
|
+
},
|
|
1223
|
+
paramCount: 3,
|
|
1224
|
+
},
|
|
1017
1225
|
'get': {
|
|
1018
1226
|
evaluate: function (params, sourceCodeInfo) {
|
|
1019
1227
|
var _a = __read(params, 2), coll = _a[0], key = _a[1];
|
|
@@ -1317,13 +1525,15 @@ var arrayNormalExpression = {
|
|
|
1317
1525
|
paramCount: 2,
|
|
1318
1526
|
},
|
|
1319
1527
|
flatten: {
|
|
1320
|
-
evaluate: function (_a) {
|
|
1321
|
-
var _b = __read(_a,
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1528
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
1529
|
+
var _b = __read(_a, 2), seq = _b[0], depth = _b[1];
|
|
1530
|
+
assertArray(seq, sourceCodeInfo);
|
|
1531
|
+
var actualDepth = depth === undefined || depth === Number.POSITIVE_INFINITY
|
|
1532
|
+
? Number.POSITIVE_INFINITY
|
|
1533
|
+
: asNumber(depth, sourceCodeInfo, { integer: true, nonNegative: true });
|
|
1534
|
+
return seq.flat(actualDepth);
|
|
1325
1535
|
},
|
|
1326
|
-
paramCount: 1,
|
|
1536
|
+
paramCount: { min: 1, max: 2 },
|
|
1327
1537
|
},
|
|
1328
1538
|
mapcat: {
|
|
1329
1539
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
@@ -1356,23 +1566,6 @@ var sequenceNormalExpression = {
|
|
|
1356
1566
|
},
|
|
1357
1567
|
paramCount: { min: 2, max: 3 },
|
|
1358
1568
|
},
|
|
1359
|
-
'filter': {
|
|
1360
|
-
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1361
|
-
var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
|
|
1362
|
-
var executeFunction = _b.executeFunction;
|
|
1363
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1364
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1365
|
-
if (Array.isArray(seq)) {
|
|
1366
|
-
var result = seq.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); });
|
|
1367
|
-
return result;
|
|
1368
|
-
}
|
|
1369
|
-
return seq
|
|
1370
|
-
.split('')
|
|
1371
|
-
.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); })
|
|
1372
|
-
.join('');
|
|
1373
|
-
},
|
|
1374
|
-
paramCount: 2,
|
|
1375
|
-
},
|
|
1376
1569
|
'first': {
|
|
1377
1570
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1378
1571
|
var _b = __read(_a, 1), array = _b[0];
|
|
@@ -1395,39 +1588,6 @@ var sequenceNormalExpression = {
|
|
|
1395
1588
|
},
|
|
1396
1589
|
paramCount: 1,
|
|
1397
1590
|
},
|
|
1398
|
-
'map': {
|
|
1399
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1400
|
-
var executeFunction = _a.executeFunction;
|
|
1401
|
-
var fn = asFunctionLike(params.at(-1), sourceCodeInfo);
|
|
1402
|
-
var seqs = params.slice(0, -1);
|
|
1403
|
-
assertSeq(seqs[0], sourceCodeInfo);
|
|
1404
|
-
var isString = typeof seqs[0] === 'string';
|
|
1405
|
-
var len = seqs[0].length;
|
|
1406
|
-
seqs.slice(1).forEach(function (seq) {
|
|
1407
|
-
if (isString) {
|
|
1408
|
-
assertString(seq, sourceCodeInfo);
|
|
1409
|
-
}
|
|
1410
|
-
else {
|
|
1411
|
-
assertArray(seq, sourceCodeInfo);
|
|
1412
|
-
}
|
|
1413
|
-
len = Math.min(len, seq.length);
|
|
1414
|
-
});
|
|
1415
|
-
var paramArray = [];
|
|
1416
|
-
var _loop_1 = function (i) {
|
|
1417
|
-
paramArray.push(seqs.map(function (seq) { return seq[i]; }));
|
|
1418
|
-
};
|
|
1419
|
-
for (var i = 0; i < len; i++) {
|
|
1420
|
-
_loop_1(i);
|
|
1421
|
-
}
|
|
1422
|
-
var mapped = paramArray.map(function (p) { return executeFunction(fn, p, contextStack, sourceCodeInfo); });
|
|
1423
|
-
if (!isString) {
|
|
1424
|
-
return mapped;
|
|
1425
|
-
}
|
|
1426
|
-
mapped.forEach(function (char) { return assertString(char, sourceCodeInfo); });
|
|
1427
|
-
return mapped.join('');
|
|
1428
|
-
},
|
|
1429
|
-
paramCount: { min: 2 },
|
|
1430
|
-
},
|
|
1431
1591
|
'pop': {
|
|
1432
1592
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1433
1593
|
var _b = __read(_a, 1), seq = _b[0];
|
|
@@ -1510,160 +1670,6 @@ var sequenceNormalExpression = {
|
|
|
1510
1670
|
},
|
|
1511
1671
|
paramCount: { min: 2 },
|
|
1512
1672
|
},
|
|
1513
|
-
'reductions': {
|
|
1514
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1515
|
-
var executeFunction = _a.executeFunction;
|
|
1516
|
-
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
1517
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1518
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1519
|
-
if (params.length === 2) {
|
|
1520
|
-
if (seq.length === 0)
|
|
1521
|
-
return [executeFunction(fn, [], contextStack, sourceCodeInfo)];
|
|
1522
|
-
else if (seq.length === 1)
|
|
1523
|
-
return [toAny(seq[0])];
|
|
1524
|
-
if (typeof seq === 'string') {
|
|
1525
|
-
var chars = seq.split('');
|
|
1526
|
-
var resultArray_1 = [asAny(chars[0], sourceCodeInfo)];
|
|
1527
|
-
chars.slice(1).reduce(function (result, elem) {
|
|
1528
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1529
|
-
resultArray_1.push(newVal);
|
|
1530
|
-
return newVal;
|
|
1531
|
-
}, asAny(chars[0], sourceCodeInfo));
|
|
1532
|
-
return resultArray_1;
|
|
1533
|
-
}
|
|
1534
|
-
else {
|
|
1535
|
-
var resultArray_2 = [toAny(seq[0])];
|
|
1536
|
-
seq.slice(1).reduce(function (result, elem) {
|
|
1537
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1538
|
-
resultArray_2.push(newVal);
|
|
1539
|
-
return newVal;
|
|
1540
|
-
}, toAny(seq[0]));
|
|
1541
|
-
return resultArray_2;
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1544
|
-
else {
|
|
1545
|
-
var val = params[2];
|
|
1546
|
-
assertAny(val, sourceCodeInfo);
|
|
1547
|
-
if (typeof seq === 'string') {
|
|
1548
|
-
assertString(val, sourceCodeInfo);
|
|
1549
|
-
if (seq.length === 0)
|
|
1550
|
-
return [val];
|
|
1551
|
-
var resultArray_3 = [val];
|
|
1552
|
-
seq.split('').reduce(function (result, elem) {
|
|
1553
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1554
|
-
resultArray_3.push(newVal);
|
|
1555
|
-
return newVal;
|
|
1556
|
-
}, val);
|
|
1557
|
-
return resultArray_3;
|
|
1558
|
-
}
|
|
1559
|
-
else {
|
|
1560
|
-
if (seq.length === 0)
|
|
1561
|
-
return [val];
|
|
1562
|
-
var resultArray_4 = [val];
|
|
1563
|
-
seq.reduce(function (result, elem) {
|
|
1564
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1565
|
-
resultArray_4.push(newVal);
|
|
1566
|
-
return newVal;
|
|
1567
|
-
}, val);
|
|
1568
|
-
return resultArray_4;
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
},
|
|
1572
|
-
paramCount: { min: 2, max: 3 },
|
|
1573
|
-
},
|
|
1574
|
-
'reduce': {
|
|
1575
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1576
|
-
var executeFunction = _a.executeFunction;
|
|
1577
|
-
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
1578
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1579
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1580
|
-
if (params.length === 2) {
|
|
1581
|
-
if (seq.length === 0)
|
|
1582
|
-
return executeFunction(fn, [], contextStack, sourceCodeInfo);
|
|
1583
|
-
else if (seq.length === 1)
|
|
1584
|
-
return toAny(seq[0]);
|
|
1585
|
-
if (typeof seq === 'string') {
|
|
1586
|
-
var chars = seq.split('');
|
|
1587
|
-
return chars.slice(1).reduce(function (result, elem) {
|
|
1588
|
-
var val = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1589
|
-
return val;
|
|
1590
|
-
}, asAny(chars[0], sourceCodeInfo));
|
|
1591
|
-
}
|
|
1592
|
-
else {
|
|
1593
|
-
return seq.slice(1).reduce(function (result, elem) {
|
|
1594
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1595
|
-
}, toAny(seq[0]));
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
else {
|
|
1599
|
-
var val = params[2];
|
|
1600
|
-
assertAny(val, sourceCodeInfo);
|
|
1601
|
-
if (typeof seq === 'string') {
|
|
1602
|
-
assertString(val, sourceCodeInfo);
|
|
1603
|
-
if (seq.length === 0)
|
|
1604
|
-
return val;
|
|
1605
|
-
return seq.split('').reduce(function (result, elem) {
|
|
1606
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1607
|
-
}, val);
|
|
1608
|
-
}
|
|
1609
|
-
else {
|
|
1610
|
-
if (seq.length === 0)
|
|
1611
|
-
return val;
|
|
1612
|
-
return seq.reduce(function (result, elem) {
|
|
1613
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1614
|
-
}, val);
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
},
|
|
1618
|
-
paramCount: { min: 2, max: 3 },
|
|
1619
|
-
},
|
|
1620
|
-
'reduce-right': {
|
|
1621
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1622
|
-
var executeFunction = _a.executeFunction;
|
|
1623
|
-
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
1624
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1625
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1626
|
-
if (params.length === 2) {
|
|
1627
|
-
if (seq.length === 0)
|
|
1628
|
-
return executeFunction(fn, [], contextStack, sourceCodeInfo);
|
|
1629
|
-
else if (seq.length === 1)
|
|
1630
|
-
return toAny(seq[0]);
|
|
1631
|
-
if (typeof seq === 'string') {
|
|
1632
|
-
var chars = seq.split('');
|
|
1633
|
-
return chars.slice(0, chars.length - 1).reduceRight(function (result, elem) {
|
|
1634
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1635
|
-
assertString(newVal, sourceCodeInfo);
|
|
1636
|
-
return newVal;
|
|
1637
|
-
}, chars[chars.length - 1]);
|
|
1638
|
-
}
|
|
1639
|
-
else {
|
|
1640
|
-
return seq.slice(0, seq.length - 1).reduceRight(function (result, elem) {
|
|
1641
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1642
|
-
}, asAny(seq[seq.length - 1], sourceCodeInfo));
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
else {
|
|
1646
|
-
var val = params[2];
|
|
1647
|
-
assertAny(val, sourceCodeInfo);
|
|
1648
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1649
|
-
if (typeof seq === 'string') {
|
|
1650
|
-
if (seq.length === 0)
|
|
1651
|
-
return val;
|
|
1652
|
-
return seq.split('').reduceRight(function (result, elem) {
|
|
1653
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1654
|
-
}, val);
|
|
1655
|
-
}
|
|
1656
|
-
else {
|
|
1657
|
-
if (seq.length === 0)
|
|
1658
|
-
return val;
|
|
1659
|
-
return seq.reduceRight(function (result, elem) {
|
|
1660
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1661
|
-
}, val);
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
},
|
|
1665
|
-
paramCount: { min: 2, max: 3 },
|
|
1666
|
-
},
|
|
1667
1673
|
'rest': {
|
|
1668
1674
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1669
1675
|
var _b = __read(_a, 1), seq = _b[0];
|
|
@@ -1982,7 +1988,7 @@ var sequenceNormalExpression = {
|
|
|
1982
1988
|
assertSeq(input, sourceCodeInfo);
|
|
1983
1989
|
if (Array.isArray(input)) {
|
|
1984
1990
|
var result = [];
|
|
1985
|
-
var
|
|
1991
|
+
var _loop_1 = function (item) {
|
|
1986
1992
|
assertAny(item, sourceCodeInfo);
|
|
1987
1993
|
if (!result.some(function (existingItem) { return deepEqual(existingItem, item, sourceCodeInfo); })) {
|
|
1988
1994
|
result.push(item);
|
|
@@ -1991,7 +1997,7 @@ var sequenceNormalExpression = {
|
|
|
1991
1997
|
try {
|
|
1992
1998
|
for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
|
|
1993
1999
|
var item = input_1_1.value;
|
|
1994
|
-
|
|
2000
|
+
_loop_1(item);
|
|
1995
2001
|
}
|
|
1996
2002
|
}
|
|
1997
2003
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -3977,6 +3983,13 @@ var regexpNormalExpression = {
|
|
|
3977
3983
|
assertString(sourceArg, sourceCodeInfo);
|
|
3978
3984
|
var source = sourceArg || '(?:)';
|
|
3979
3985
|
var flags = typeof flagsArg === 'string' ? flagsArg : '';
|
|
3986
|
+
try {
|
|
3987
|
+
// eslint-disable-next-line no-new
|
|
3988
|
+
new RegExp(source, flags); // Throws if invalid regexp
|
|
3989
|
+
}
|
|
3990
|
+
catch (e) {
|
|
3991
|
+
throw new LitsError("Invalid regular expression: ".concat(source, " ").concat(flags), sourceCodeInfo);
|
|
3992
|
+
}
|
|
3980
3993
|
return _b = {},
|
|
3981
3994
|
_b[REGEXP_SYMBOL] = true,
|
|
3982
3995
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
@@ -4295,6 +4308,15 @@ function applyPlaceholders(templateString, placeholders, sourceCodeInfo) {
|
|
|
4295
4308
|
}
|
|
4296
4309
|
|
|
4297
4310
|
var functionalNormalExpression = {
|
|
4311
|
+
'|>': {
|
|
4312
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
4313
|
+
var _c = __read(_a, 2), value = _c[0], func = _c[1];
|
|
4314
|
+
var executeFunction = _b.executeFunction;
|
|
4315
|
+
assertFunctionLike(func, sourceCodeInfo);
|
|
4316
|
+
return executeFunction(func, [value], contextStack, sourceCodeInfo);
|
|
4317
|
+
},
|
|
4318
|
+
paramCount: 2,
|
|
4319
|
+
},
|
|
4298
4320
|
'apply': {
|
|
4299
4321
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
4300
4322
|
var _c = __read(_a), func = _c[0], params = _c.slice(1);
|
|
@@ -4315,20 +4337,6 @@ var functionalNormalExpression = {
|
|
|
4315
4337
|
},
|
|
4316
4338
|
paramCount: 1,
|
|
4317
4339
|
},
|
|
4318
|
-
'partial': {
|
|
4319
|
-
evaluate: function (_a, sourceCodeInfo) {
|
|
4320
|
-
var _b;
|
|
4321
|
-
var _c = __read(_a), fn = _c[0], params = _c.slice(1);
|
|
4322
|
-
return _b = {},
|
|
4323
|
-
_b[FUNCTION_SYMBOL] = true,
|
|
4324
|
-
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4325
|
-
_b.functionType = 'Partial',
|
|
4326
|
-
_b.function = asFunctionLike(fn, sourceCodeInfo),
|
|
4327
|
-
_b.params = params,
|
|
4328
|
-
_b;
|
|
4329
|
-
},
|
|
4330
|
-
paramCount: { min: 1 },
|
|
4331
|
-
},
|
|
4332
4340
|
'comp': {
|
|
4333
4341
|
evaluate: function (params, sourceCodeInfo) {
|
|
4334
4342
|
var _a;
|
|
@@ -7088,10 +7096,10 @@ var linearAlgebraNormalExpression = {
|
|
|
7088
7096
|
assertVector(vectorA, sourceCodeInfo);
|
|
7089
7097
|
assertVector(vectorB, sourceCodeInfo);
|
|
7090
7098
|
if (vectorA.length < 2) {
|
|
7091
|
-
throw new
|
|
7099
|
+
throw new LitsError('Vectors must have at least 2 elements', sourceCodeInfo);
|
|
7092
7100
|
}
|
|
7093
7101
|
if (vectorA.length !== vectorB.length) {
|
|
7094
|
-
throw new
|
|
7102
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
7095
7103
|
}
|
|
7096
7104
|
assertNumber(lag, sourceCodeInfo, {
|
|
7097
7105
|
integer: true,
|
|
@@ -8343,7 +8351,7 @@ var partitionsNormalExpressions = {
|
|
|
8343
8351
|
if (n === 0)
|
|
8344
8352
|
return 1;
|
|
8345
8353
|
if (n > partitionNumbers.length) {
|
|
8346
|
-
throw new
|
|
8354
|
+
throw new LitsError("n is too large. The maximum value is ".concat(partitionNumbers.length - 1, "."), sourceCodeInfo);
|
|
8347
8355
|
}
|
|
8348
8356
|
return partitionNumbers[n - 1];
|
|
8349
8357
|
},
|
|
@@ -10482,7 +10490,12 @@ var combinatoricalNormalExpression = {
|
|
|
10482
10490
|
var _b = __read(_a, 2), a = _b[0], m = _b[1];
|
|
10483
10491
|
assertNumber(a, sourceCodeInfo, { integer: true, positive: true });
|
|
10484
10492
|
assertNumber(m, sourceCodeInfo, { integer: true, positive: true });
|
|
10485
|
-
|
|
10493
|
+
try {
|
|
10494
|
+
return modInverse(a, m);
|
|
10495
|
+
}
|
|
10496
|
+
catch (error) {
|
|
10497
|
+
throw new LitsError(error, sourceCodeInfo);
|
|
10498
|
+
}
|
|
10486
10499
|
},
|
|
10487
10500
|
paramCount: 2,
|
|
10488
10501
|
},
|
|
@@ -10501,7 +10514,7 @@ var combinatoricalNormalExpression = {
|
|
|
10501
10514
|
assertVector(remainders, sourceCodeInfo);
|
|
10502
10515
|
assertVector(moduli, sourceCodeInfo);
|
|
10503
10516
|
if (remainders.length !== moduli.length) {
|
|
10504
|
-
throw new
|
|
10517
|
+
throw new LitsError('Remainders and moduli must have the same length.', sourceCodeInfo);
|
|
10505
10518
|
}
|
|
10506
10519
|
try {
|
|
10507
10520
|
return chineseRemainder(remainders, moduli);
|
|
@@ -11255,6 +11268,7 @@ var nonNumberReservedSymbolRecord = {
|
|
|
11255
11268
|
function: null,
|
|
11256
11269
|
export: null,
|
|
11257
11270
|
as: null,
|
|
11271
|
+
_: null,
|
|
11258
11272
|
};
|
|
11259
11273
|
var phi = (1 + Math.sqrt(5)) / 2;
|
|
11260
11274
|
var numberReservedSymbolRecord = {
|
|
@@ -11944,7 +11958,11 @@ var objectSpecialExpression = {
|
|
|
11944
11958
|
}
|
|
11945
11959
|
else {
|
|
11946
11960
|
var key = evaluateNode(keyNode, contextStack);
|
|
11947
|
-
var
|
|
11961
|
+
var valueNode = params[i + 1];
|
|
11962
|
+
if (valueNode === undefined) {
|
|
11963
|
+
throw new LitsError('Missing value for key', keyNode[2]);
|
|
11964
|
+
}
|
|
11965
|
+
var value = evaluateNode(valueNode, contextStack);
|
|
11948
11966
|
assertString(key, keyNode[2]);
|
|
11949
11967
|
result[key] = value;
|
|
11950
11968
|
}
|
|
@@ -12104,8 +12122,27 @@ var functionExecutors = {
|
|
|
12104
12122
|
}
|
|
12105
12123
|
},
|
|
12106
12124
|
Partial: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12125
|
+
var e_2, _b;
|
|
12107
12126
|
var executeFunction = _a.executeFunction;
|
|
12108
|
-
|
|
12127
|
+
var actualParams = __spreadArray([], __read(fn.params), false);
|
|
12128
|
+
if (params.length !== fn.placeholders.length) {
|
|
12129
|
+
throw new LitsError("(partial) expects ".concat(fn.placeholders.length, " arguments, got ").concat(params.length, "."), sourceCodeInfo);
|
|
12130
|
+
}
|
|
12131
|
+
var paramsCopy = __spreadArray([], __read(params), false);
|
|
12132
|
+
try {
|
|
12133
|
+
for (var _c = __values(fn.placeholders), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
12134
|
+
var placeholderIndex = _d.value;
|
|
12135
|
+
actualParams.splice(placeholderIndex, 0, paramsCopy.shift());
|
|
12136
|
+
}
|
|
12137
|
+
}
|
|
12138
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
12139
|
+
finally {
|
|
12140
|
+
try {
|
|
12141
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
12142
|
+
}
|
|
12143
|
+
finally { if (e_2) throw e_2.error; }
|
|
12144
|
+
}
|
|
12145
|
+
return executeFunction(fn.function, actualParams, contextStack, sourceCodeInfo);
|
|
12109
12146
|
},
|
|
12110
12147
|
Comp: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12111
12148
|
var executeFunction = _a.executeFunction;
|
|
@@ -12131,66 +12168,66 @@ var functionExecutors = {
|
|
|
12131
12168
|
return !executeFunction(fn.function, params, contextStack, sourceCodeInfo);
|
|
12132
12169
|
},
|
|
12133
12170
|
EveryPred: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12134
|
-
var
|
|
12171
|
+
var e_3, _b, e_4, _c;
|
|
12135
12172
|
var executeFunction = _a.executeFunction;
|
|
12136
12173
|
try {
|
|
12137
12174
|
for (var _d = __values(fn.params), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
12138
12175
|
var f = _e.value;
|
|
12139
12176
|
try {
|
|
12140
|
-
for (var params_1 = (
|
|
12177
|
+
for (var params_1 = (e_4 = void 0, __values(params)), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
12141
12178
|
var param = params_1_1.value;
|
|
12142
12179
|
var result = executeFunction(asFunctionLike(f, sourceCodeInfo), [param], contextStack, sourceCodeInfo);
|
|
12143
12180
|
if (!result)
|
|
12144
12181
|
return false;
|
|
12145
12182
|
}
|
|
12146
12183
|
}
|
|
12147
|
-
catch (
|
|
12184
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
12148
12185
|
finally {
|
|
12149
12186
|
try {
|
|
12150
12187
|
if (params_1_1 && !params_1_1.done && (_c = params_1.return)) _c.call(params_1);
|
|
12151
12188
|
}
|
|
12152
|
-
finally { if (
|
|
12189
|
+
finally { if (e_4) throw e_4.error; }
|
|
12153
12190
|
}
|
|
12154
12191
|
}
|
|
12155
12192
|
}
|
|
12156
|
-
catch (
|
|
12193
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
12157
12194
|
finally {
|
|
12158
12195
|
try {
|
|
12159
12196
|
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
12160
12197
|
}
|
|
12161
|
-
finally { if (
|
|
12198
|
+
finally { if (e_3) throw e_3.error; }
|
|
12162
12199
|
}
|
|
12163
12200
|
return true;
|
|
12164
12201
|
},
|
|
12165
12202
|
SomePred: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12166
|
-
var
|
|
12203
|
+
var e_5, _b, e_6, _c;
|
|
12167
12204
|
var executeFunction = _a.executeFunction;
|
|
12168
12205
|
try {
|
|
12169
12206
|
for (var _d = __values(fn.params), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
12170
12207
|
var f = _e.value;
|
|
12171
12208
|
try {
|
|
12172
|
-
for (var params_2 = (
|
|
12209
|
+
for (var params_2 = (e_6 = void 0, __values(params)), params_2_1 = params_2.next(); !params_2_1.done; params_2_1 = params_2.next()) {
|
|
12173
12210
|
var param = params_2_1.value;
|
|
12174
12211
|
var result = executeFunction(asFunctionLike(f, sourceCodeInfo), [param], contextStack, sourceCodeInfo);
|
|
12175
12212
|
if (result)
|
|
12176
12213
|
return true;
|
|
12177
12214
|
}
|
|
12178
12215
|
}
|
|
12179
|
-
catch (
|
|
12216
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
12180
12217
|
finally {
|
|
12181
12218
|
try {
|
|
12182
12219
|
if (params_2_1 && !params_2_1.done && (_c = params_2.return)) _c.call(params_2);
|
|
12183
12220
|
}
|
|
12184
|
-
finally { if (
|
|
12221
|
+
finally { if (e_6) throw e_6.error; }
|
|
12185
12222
|
}
|
|
12186
12223
|
}
|
|
12187
12224
|
}
|
|
12188
|
-
catch (
|
|
12225
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
12189
12226
|
finally {
|
|
12190
12227
|
try {
|
|
12191
12228
|
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
12192
12229
|
}
|
|
12193
|
-
finally { if (
|
|
12230
|
+
finally { if (e_5) throw e_5.error; }
|
|
12194
12231
|
}
|
|
12195
12232
|
return false;
|
|
12196
12233
|
},
|
|
@@ -12263,6 +12300,9 @@ function evaluateString(node) {
|
|
|
12263
12300
|
}
|
|
12264
12301
|
function evaluateReservedSymbol(node) {
|
|
12265
12302
|
var reservedName = node[1];
|
|
12303
|
+
if (!['true', 'false', 'null'].includes(reservedName)) {
|
|
12304
|
+
throw new LitsError("Reserved symbol ".concat(reservedName, " cannot be evaluated"), node[2]);
|
|
12305
|
+
}
|
|
12266
12306
|
var value = reservedSymbolRecord[reservedName];
|
|
12267
12307
|
return asNonUndefined(value, node[2]);
|
|
12268
12308
|
}
|
|
@@ -12270,7 +12310,8 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12270
12310
|
var sourceCodeInfo = node[2];
|
|
12271
12311
|
var paramNodes = node[1][1];
|
|
12272
12312
|
var params = [];
|
|
12273
|
-
|
|
12313
|
+
var placeholders = [];
|
|
12314
|
+
paramNodes.forEach(function (paramNode, index) {
|
|
12274
12315
|
if (isSpreadNode(paramNode)) {
|
|
12275
12316
|
var spreadValue = evaluateNode(paramNode[1], contextStack);
|
|
12276
12317
|
if (Array.isArray(spreadValue)) {
|
|
@@ -12280,12 +12321,27 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12280
12321
|
throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
|
|
12281
12322
|
}
|
|
12282
12323
|
}
|
|
12324
|
+
else if (paramNode[0] === NodeTypes.ReservedSymbol && paramNode[1] === '_') {
|
|
12325
|
+
placeholders.push(index);
|
|
12326
|
+
}
|
|
12283
12327
|
else {
|
|
12284
12328
|
params.push(evaluateNode(paramNode, contextStack));
|
|
12285
12329
|
}
|
|
12286
12330
|
});
|
|
12287
12331
|
if (isNormalExpressionNodeWithName(node)) {
|
|
12288
12332
|
var nameSymbol = node[1][0];
|
|
12333
|
+
if (placeholders.length > 0) {
|
|
12334
|
+
var fn = evaluateNode(nameSymbol, contextStack);
|
|
12335
|
+
var partialFunction = {
|
|
12336
|
+
'^^fn^^': true,
|
|
12337
|
+
'function': asFunctionLike(fn, sourceCodeInfo),
|
|
12338
|
+
'functionType': 'Partial',
|
|
12339
|
+
params: params,
|
|
12340
|
+
placeholders: placeholders,
|
|
12341
|
+
sourceCodeInfo: sourceCodeInfo,
|
|
12342
|
+
};
|
|
12343
|
+
return partialFunction;
|
|
12344
|
+
}
|
|
12289
12345
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
12290
12346
|
var type = nameSymbol[1];
|
|
12291
12347
|
var normalExpression = builtin.allNormalExpressions[type];
|
|
@@ -12302,6 +12358,17 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12302
12358
|
else {
|
|
12303
12359
|
var fnNode = node[1][0];
|
|
12304
12360
|
var fn = asFunctionLike(evaluateNode(fnNode, contextStack), sourceCodeInfo);
|
|
12361
|
+
if (placeholders.length > 0) {
|
|
12362
|
+
var partialFunction = {
|
|
12363
|
+
'^^fn^^': true,
|
|
12364
|
+
'function': asFunctionLike(fn, sourceCodeInfo),
|
|
12365
|
+
'functionType': 'Partial',
|
|
12366
|
+
params: params,
|
|
12367
|
+
placeholders: placeholders,
|
|
12368
|
+
sourceCodeInfo: sourceCodeInfo,
|
|
12369
|
+
};
|
|
12370
|
+
return partialFunction;
|
|
12371
|
+
}
|
|
12305
12372
|
return executeFunction(fn, params, contextStack, sourceCodeInfo);
|
|
12306
12373
|
}
|
|
12307
12374
|
}
|
|
@@ -12607,6 +12674,7 @@ var binaryOperators = [
|
|
|
12607
12674
|
'&&', // logical AND
|
|
12608
12675
|
'||', // logical OR
|
|
12609
12676
|
'??', // nullish coalescing
|
|
12677
|
+
'|>', // pipe
|
|
12610
12678
|
];
|
|
12611
12679
|
var otherOperators = [
|
|
12612
12680
|
'->', // lambda
|
|
@@ -12785,21 +12853,30 @@ var tokenizeNumber = function (input, position) {
|
|
|
12785
12853
|
var char = input[i];
|
|
12786
12854
|
if (char === '_') {
|
|
12787
12855
|
if (!decimalNumberRegExp.test(input[i - 1]) || !decimalNumberRegExp.test(input[i + 1])) {
|
|
12788
|
-
|
|
12856
|
+
if (i === start) {
|
|
12857
|
+
return NO_MATCH;
|
|
12858
|
+
}
|
|
12859
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12789
12860
|
}
|
|
12790
12861
|
}
|
|
12791
12862
|
else if (char === '.') {
|
|
12792
|
-
if (i === start
|
|
12863
|
+
if (i === start) {
|
|
12793
12864
|
return NO_MATCH;
|
|
12794
12865
|
}
|
|
12866
|
+
if (hasDecimalPoint || hasExponent) {
|
|
12867
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12868
|
+
}
|
|
12795
12869
|
hasDecimalPoint = true;
|
|
12796
12870
|
}
|
|
12797
12871
|
else if (char === 'e' || char === 'E') {
|
|
12798
|
-
if (i === start
|
|
12872
|
+
if (i === start) {
|
|
12799
12873
|
return NO_MATCH;
|
|
12800
12874
|
}
|
|
12875
|
+
if (hasExponent) {
|
|
12876
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12877
|
+
}
|
|
12801
12878
|
if (input[i - 1] === '.' || input[i - 1] === '+' || input[i - 1] === '-') {
|
|
12802
|
-
|
|
12879
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12803
12880
|
}
|
|
12804
12881
|
if (input[i + 1] === '+' || input[i + 1] === '-') {
|
|
12805
12882
|
i += 1;
|
|
@@ -12819,7 +12896,7 @@ var tokenizeNumber = function (input, position) {
|
|
|
12819
12896
|
}
|
|
12820
12897
|
var nextChar = input[i];
|
|
12821
12898
|
if (nextChar && !postNumberRegExp.test(nextChar)) {
|
|
12822
|
-
|
|
12899
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12823
12900
|
}
|
|
12824
12901
|
return [length, ['Number', input.substring(position, i)]];
|
|
12825
12902
|
};
|
|
@@ -12985,10 +13062,10 @@ function tokenize(input, debug, filePath) {
|
|
|
12985
13062
|
hasDebugData: debug,
|
|
12986
13063
|
};
|
|
12987
13064
|
while (position < input.length) {
|
|
12988
|
-
var tokenDescriptor = getCurrentToken(input, position);
|
|
12989
13065
|
var sourceCodeInfo = debug
|
|
12990
13066
|
? createSourceCodeInfo(input, position, filePath)
|
|
12991
13067
|
: undefined;
|
|
13068
|
+
var tokenDescriptor = getCurrentToken(input, position);
|
|
12992
13069
|
if (!tokenDescriptor) {
|
|
12993
13070
|
throw new LitsError("Unrecognized character '".concat(input[position], "'."), sourceCodeInfo);
|
|
12994
13071
|
}
|
|
@@ -13098,9 +13175,6 @@ function isOperatorToken(token, operatorName) {
|
|
|
13098
13175
|
}
|
|
13099
13176
|
function assertOperatorToken(token, operatorName) {
|
|
13100
13177
|
if (!isOperatorToken(token, operatorName)) {
|
|
13101
|
-
if (operatorName) {
|
|
13102
|
-
throw new LitsError("Unexpected token: ".concat(token, ", expected operator ").concat(operatorName), token[2]);
|
|
13103
|
-
}
|
|
13104
13178
|
throwUnexpectedToken('Operator', operatorName, token);
|
|
13105
13179
|
}
|
|
13106
13180
|
}
|
|
@@ -13170,8 +13244,8 @@ function isA_BinaryOperatorToken(token) {
|
|
|
13170
13244
|
return (token === null || token === void 0 ? void 0 : token[0]) === 'Operator' && isBinaryOperator(token[1]);
|
|
13171
13245
|
}
|
|
13172
13246
|
function throwUnexpectedToken(expected, expectedValue, actual) {
|
|
13173
|
-
var actualOutput = "".concat(actual[0], " '").concat(actual[1], "'");
|
|
13174
|
-
throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual[2]);
|
|
13247
|
+
var actualOutput = actual ? "".concat(actual[0], " '").concat(actual[1], "'") : 'end of input';
|
|
13248
|
+
throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual === null || actual === void 0 ? void 0 : actual[2]);
|
|
13175
13249
|
}
|
|
13176
13250
|
|
|
13177
13251
|
function minifyTokenStream(tokenStream, _a) {
|
|
@@ -13200,8 +13274,8 @@ function untokenize(tokenStream) {
|
|
|
13200
13274
|
}, '');
|
|
13201
13275
|
}
|
|
13202
13276
|
|
|
13203
|
-
var exponentiationPrecedence =
|
|
13204
|
-
var binaryFunctionalOperatorPrecedence =
|
|
13277
|
+
var exponentiationPrecedence = 11;
|
|
13278
|
+
var binaryFunctionalOperatorPrecedence = 2;
|
|
13205
13279
|
var placeholderRegexp = /^\$([1-9]\d?)?$/;
|
|
13206
13280
|
function withSourceCodeInfo(node, sourceCodeInfo) {
|
|
13207
13281
|
if (sourceCodeInfo) {
|
|
@@ -13216,38 +13290,40 @@ function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
|
13216
13290
|
case '*': // multiplication
|
|
13217
13291
|
case '/': // division
|
|
13218
13292
|
case '%': // remainder
|
|
13219
|
-
return
|
|
13293
|
+
return 10;
|
|
13220
13294
|
case '+': // addition
|
|
13221
13295
|
case '-': // subtraction
|
|
13222
|
-
return
|
|
13296
|
+
return 9;
|
|
13223
13297
|
case '<<': // left shift
|
|
13224
13298
|
case '>>': // signed right shift
|
|
13225
13299
|
case '>>>': // unsigned right shift
|
|
13226
|
-
return
|
|
13300
|
+
return 8;
|
|
13227
13301
|
case '++': // string concatenation
|
|
13228
|
-
return
|
|
13302
|
+
return 7;
|
|
13229
13303
|
case '<': // less than
|
|
13230
13304
|
case '<=': // less than or equal
|
|
13231
13305
|
case '≤': // less than or equal
|
|
13232
13306
|
case '>': // greater than
|
|
13233
13307
|
case '>=': // greater than or equal
|
|
13234
13308
|
case '≥': // greater than or equal
|
|
13235
|
-
return
|
|
13309
|
+
return 6;
|
|
13236
13310
|
case '=': // equal
|
|
13237
13311
|
case '!=': // not equal
|
|
13238
13312
|
case '≠': // not equal
|
|
13239
13313
|
case '~': // approximate
|
|
13240
13314
|
case '≈': // approximate
|
|
13241
|
-
return
|
|
13315
|
+
return 5;
|
|
13242
13316
|
case '&': // bitwise AND
|
|
13243
13317
|
case 'xor': // bitwise XOR
|
|
13244
13318
|
case '|': // bitwise OR
|
|
13245
|
-
return
|
|
13319
|
+
return 4;
|
|
13246
13320
|
case '&&': // logical AND
|
|
13247
13321
|
case '||': // logical OR
|
|
13248
13322
|
case '??': // nullish coalescing
|
|
13249
|
-
return
|
|
13250
|
-
|
|
13323
|
+
return 3;
|
|
13324
|
+
case '|>': // pipe
|
|
13325
|
+
return 1;
|
|
13326
|
+
// leave room for binaryFunctionalOperatorPrecedence = 2
|
|
13251
13327
|
/* v8 ignore next 2 */
|
|
13252
13328
|
default:
|
|
13253
13329
|
throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
|
|
@@ -13291,6 +13367,7 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
|
|
|
13291
13367
|
case '|':
|
|
13292
13368
|
case '~':
|
|
13293
13369
|
case '≈':
|
|
13370
|
+
case '|>':
|
|
13294
13371
|
return createNamedNormalExpressionNode(symbolNode, [left, right], sourceCodeInfo);
|
|
13295
13372
|
case '&&':
|
|
13296
13373
|
case '||':
|
|
@@ -13316,6 +13393,11 @@ var Parser = /** @class */ (function () {
|
|
|
13316
13393
|
Parser.prototype.peek = function () {
|
|
13317
13394
|
return this.tokenStream.tokens[this.parseState.position];
|
|
13318
13395
|
};
|
|
13396
|
+
Parser.prototype.peekSourceCodeInfo = function () {
|
|
13397
|
+
var _a;
|
|
13398
|
+
var currentToken = this.peek();
|
|
13399
|
+
return currentToken ? currentToken[2] : (_a = this.tokenStream.tokens.at(-1)) === null || _a === void 0 ? void 0 : _a[2];
|
|
13400
|
+
};
|
|
13319
13401
|
Parser.prototype.peekAhead = function (count) {
|
|
13320
13402
|
return this.tokenStream.tokens[this.parseState.position + count];
|
|
13321
13403
|
};
|
|
@@ -13331,7 +13413,7 @@ var Parser = /** @class */ (function () {
|
|
|
13331
13413
|
}
|
|
13332
13414
|
else {
|
|
13333
13415
|
if (!this.isAtEnd()) {
|
|
13334
|
-
throw new LitsError('Expected ;', this.
|
|
13416
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13335
13417
|
}
|
|
13336
13418
|
}
|
|
13337
13419
|
}
|
|
@@ -13420,15 +13502,21 @@ var Parser = /** @class */ (function () {
|
|
|
13420
13502
|
}
|
|
13421
13503
|
return left;
|
|
13422
13504
|
};
|
|
13505
|
+
Parser.prototype.asToken = function (token) {
|
|
13506
|
+
if (!token) {
|
|
13507
|
+
throw new LitsError('Unexpected end of input', this.peekSourceCodeInfo());
|
|
13508
|
+
}
|
|
13509
|
+
return token;
|
|
13510
|
+
};
|
|
13423
13511
|
Parser.prototype.parseOperand = function () {
|
|
13424
13512
|
var operand = this.parseOperandPart();
|
|
13425
13513
|
var token = this.peek();
|
|
13426
13514
|
while (isOperatorToken(token, '.') || isLBracketToken(token) || isLParenToken(token)) {
|
|
13427
13515
|
if (token[1] === '.') {
|
|
13428
13516
|
this.advance();
|
|
13429
|
-
var symbolToken = this.peek();
|
|
13517
|
+
var symbolToken = this.asToken(this.peek());
|
|
13430
13518
|
if (!isSymbolToken(symbolToken)) {
|
|
13431
|
-
throw new LitsError('Expected symbol', this.
|
|
13519
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
13432
13520
|
}
|
|
13433
13521
|
var stringNode = withSourceCodeInfo([NodeTypes.String, symbolToken[1]], symbolToken[2]);
|
|
13434
13522
|
operand = createAccessorNode(operand, stringNode, token[2]);
|
|
@@ -13439,7 +13527,7 @@ var Parser = /** @class */ (function () {
|
|
|
13439
13527
|
this.advance();
|
|
13440
13528
|
var expression = this.parseExpression();
|
|
13441
13529
|
if (!isRBracketToken(this.peek())) {
|
|
13442
|
-
throw new LitsError('Expected closing bracket', this.
|
|
13530
|
+
throw new LitsError('Expected closing bracket', this.peekSourceCodeInfo());
|
|
13443
13531
|
}
|
|
13444
13532
|
operand = createAccessorNode(operand, expression, token[2]);
|
|
13445
13533
|
this.advance();
|
|
@@ -13453,7 +13541,7 @@ var Parser = /** @class */ (function () {
|
|
|
13453
13541
|
return operand;
|
|
13454
13542
|
};
|
|
13455
13543
|
Parser.prototype.parseOperandPart = function () {
|
|
13456
|
-
var token = this.peek();
|
|
13544
|
+
var token = this.asToken(this.peek());
|
|
13457
13545
|
// Parentheses
|
|
13458
13546
|
if (isLParenToken(token)) {
|
|
13459
13547
|
var positionBefore = this.parseState.position;
|
|
@@ -13465,7 +13553,7 @@ var Parser = /** @class */ (function () {
|
|
|
13465
13553
|
this.advance();
|
|
13466
13554
|
var expression = this.parseExpression();
|
|
13467
13555
|
if (!isRParenToken(this.peek())) {
|
|
13468
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13556
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13469
13557
|
}
|
|
13470
13558
|
this.advance();
|
|
13471
13559
|
return expression;
|
|
@@ -13525,7 +13613,7 @@ var Parser = /** @class */ (function () {
|
|
|
13525
13613
|
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
13526
13614
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13527
13615
|
this.advance();
|
|
13528
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13616
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13529
13617
|
}
|
|
13530
13618
|
else {
|
|
13531
13619
|
var token = this.peek();
|
|
@@ -13541,7 +13629,7 @@ var Parser = /** @class */ (function () {
|
|
|
13541
13629
|
this.advance();
|
|
13542
13630
|
}
|
|
13543
13631
|
else {
|
|
13544
|
-
throw new LitsError('Expected key to be a symbol or a string', this.
|
|
13632
|
+
throw new LitsError('Expected key to be a symbol or a string', this.peekSourceCodeInfo());
|
|
13545
13633
|
}
|
|
13546
13634
|
assertOperatorToken(this.peek(), ':=');
|
|
13547
13635
|
this.advance();
|
|
@@ -13549,7 +13637,7 @@ var Parser = /** @class */ (function () {
|
|
|
13549
13637
|
}
|
|
13550
13638
|
var nextToken = this.peek();
|
|
13551
13639
|
if (!isOperatorToken(nextToken, ',') && !isRBraceToken(nextToken)) {
|
|
13552
|
-
throw new LitsError('Expected comma or closing brace', this.
|
|
13640
|
+
throw new LitsError('Expected comma or closing brace', this.peekSourceCodeInfo());
|
|
13553
13641
|
}
|
|
13554
13642
|
if (isOperatorToken(nextToken, ',')) {
|
|
13555
13643
|
this.advance();
|
|
@@ -13566,14 +13654,14 @@ var Parser = /** @class */ (function () {
|
|
|
13566
13654
|
while (!this.isAtEnd() && !isRBracketToken(this.peek())) {
|
|
13567
13655
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13568
13656
|
this.advance();
|
|
13569
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13657
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13570
13658
|
}
|
|
13571
13659
|
else {
|
|
13572
13660
|
params.push(this.parseExpression());
|
|
13573
13661
|
}
|
|
13574
13662
|
var nextToken = this.peek();
|
|
13575
13663
|
if (!isOperatorToken(nextToken, ',') && !isRBracketToken(nextToken)) {
|
|
13576
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13664
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13577
13665
|
}
|
|
13578
13666
|
if (isOperatorToken(nextToken, ',')) {
|
|
13579
13667
|
this.advance();
|
|
@@ -13584,26 +13672,27 @@ var Parser = /** @class */ (function () {
|
|
|
13584
13672
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.array, params]], firstToken[2]);
|
|
13585
13673
|
};
|
|
13586
13674
|
Parser.prototype.parseFunctionCall = function (symbol) {
|
|
13675
|
+
var _a;
|
|
13587
13676
|
this.advance();
|
|
13588
13677
|
var params = [];
|
|
13589
13678
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
13590
13679
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13591
13680
|
this.advance();
|
|
13592
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13681
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13593
13682
|
}
|
|
13594
13683
|
else {
|
|
13595
13684
|
params.push(this.parseExpression());
|
|
13596
13685
|
}
|
|
13597
13686
|
var nextToken = this.peek();
|
|
13598
13687
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
13599
|
-
throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
|
|
13688
|
+
throw new LitsError('Expected comma or closing parenthesis', (_a = this.peek()) === null || _a === void 0 ? void 0 : _a[2]);
|
|
13600
13689
|
}
|
|
13601
13690
|
if (isOperatorToken(nextToken, ',')) {
|
|
13602
13691
|
this.advance();
|
|
13603
13692
|
}
|
|
13604
13693
|
}
|
|
13605
13694
|
if (!isRParenToken(this.peek())) {
|
|
13606
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13695
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13607
13696
|
}
|
|
13608
13697
|
this.advance();
|
|
13609
13698
|
if (isSpecialBuiltinSymbolNode(symbol)) { // Named function
|
|
@@ -13633,14 +13722,14 @@ var Parser = /** @class */ (function () {
|
|
|
13633
13722
|
if (params.length !== 1) {
|
|
13634
13723
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13635
13724
|
}
|
|
13636
|
-
var
|
|
13725
|
+
var _b = __read(params, 1), param = _b[0];
|
|
13637
13726
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13638
13727
|
}
|
|
13639
13728
|
case specialExpressionTypes.throw: {
|
|
13640
13729
|
if (params.length !== 1) {
|
|
13641
13730
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13642
13731
|
}
|
|
13643
|
-
var
|
|
13732
|
+
var _c = __read(params, 1), param = _c[0];
|
|
13644
13733
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13645
13734
|
}
|
|
13646
13735
|
case specialExpressionTypes['0_fn']:
|
|
@@ -13660,7 +13749,7 @@ var Parser = /** @class */ (function () {
|
|
|
13660
13749
|
}
|
|
13661
13750
|
};
|
|
13662
13751
|
Parser.prototype.parseLambdaFunction = function () {
|
|
13663
|
-
var firstToken = this.peek();
|
|
13752
|
+
var firstToken = this.asToken(this.peek());
|
|
13664
13753
|
if (isLParenToken(firstToken)
|
|
13665
13754
|
&& isSymbolToken(this.peekAhead(1))
|
|
13666
13755
|
&& isOperatorToken(this.peekAhead(2), '->')) {
|
|
@@ -13694,7 +13783,7 @@ var Parser = /** @class */ (function () {
|
|
|
13694
13783
|
var functionArguments = [];
|
|
13695
13784
|
while (!this.isAtEnd() && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13696
13785
|
if (rest) {
|
|
13697
|
-
throw new LitsError('Rest argument must be last', this.
|
|
13786
|
+
throw new LitsError('Rest argument must be last', this.peekSourceCodeInfo());
|
|
13698
13787
|
}
|
|
13699
13788
|
var bindingTarget = this.parseBindingTarget();
|
|
13700
13789
|
if (bindingTarget[1][1] !== undefined) {
|
|
@@ -13704,25 +13793,25 @@ var Parser = /** @class */ (function () {
|
|
|
13704
13793
|
rest = true;
|
|
13705
13794
|
}
|
|
13706
13795
|
if (defaults && !bindingTarget[1][1]) {
|
|
13707
|
-
throw new LitsError('Default arguments must be last', this.
|
|
13796
|
+
throw new LitsError('Default arguments must be last', this.peekSourceCodeInfo());
|
|
13708
13797
|
}
|
|
13709
13798
|
functionArguments.push(bindingTarget);
|
|
13710
13799
|
if (!isOperatorToken(this.peek(), ',') && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13711
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13800
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13712
13801
|
}
|
|
13713
13802
|
if (isOperatorToken(this.peek(), ',')) {
|
|
13714
13803
|
this.advance();
|
|
13715
13804
|
}
|
|
13716
13805
|
}
|
|
13717
13806
|
if (!isRParenToken(this.peek())) {
|
|
13718
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13807
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13719
13808
|
}
|
|
13720
13809
|
this.advance();
|
|
13721
13810
|
return functionArguments;
|
|
13722
13811
|
};
|
|
13723
13812
|
Parser.prototype.parseShorthandLamdaFunction = function () {
|
|
13724
13813
|
var _a;
|
|
13725
|
-
var firstToken = this.peek();
|
|
13814
|
+
var firstToken = this.asToken(this.peek());
|
|
13726
13815
|
this.advance();
|
|
13727
13816
|
var startPos = this.parseState.position;
|
|
13728
13817
|
var exprNode = this.parseExpression();
|
|
@@ -13780,7 +13869,7 @@ var Parser = /** @class */ (function () {
|
|
|
13780
13869
|
}
|
|
13781
13870
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13782
13871
|
if (requireDefaultValue && !defaultValue) {
|
|
13783
|
-
throw new LitsError('Expected assignment', this.
|
|
13872
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13784
13873
|
}
|
|
13785
13874
|
return withSourceCodeInfo([bindingTargetTypes.symbol, [symbol, defaultValue]], firstToken[2]);
|
|
13786
13875
|
}
|
|
@@ -13792,7 +13881,7 @@ var Parser = /** @class */ (function () {
|
|
|
13792
13881
|
this.advance();
|
|
13793
13882
|
var symbol = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13794
13883
|
if (isOperatorToken(this.peek(), ':=')) {
|
|
13795
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
13884
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13796
13885
|
}
|
|
13797
13886
|
return withSourceCodeInfo([bindingTargetTypes.rest, [symbol[1], undefined]], firstToken[2]);
|
|
13798
13887
|
}
|
|
@@ -13800,7 +13889,7 @@ var Parser = /** @class */ (function () {
|
|
|
13800
13889
|
if (isLBracketToken(firstToken)) {
|
|
13801
13890
|
this.advance();
|
|
13802
13891
|
var elements = [];
|
|
13803
|
-
var token = this.peek();
|
|
13892
|
+
var token = this.asToken(this.peek());
|
|
13804
13893
|
var rest = false;
|
|
13805
13894
|
while (!isRBracketToken(token)) {
|
|
13806
13895
|
if (rest) {
|
|
@@ -13809,7 +13898,7 @@ var Parser = /** @class */ (function () {
|
|
|
13809
13898
|
if (isOperatorToken(token, ',')) {
|
|
13810
13899
|
elements.push(null);
|
|
13811
13900
|
this.advance();
|
|
13812
|
-
token = this.peek();
|
|
13901
|
+
token = this.asToken(this.peek());
|
|
13813
13902
|
continue;
|
|
13814
13903
|
}
|
|
13815
13904
|
var target = this.parseBindingTarget();
|
|
@@ -13817,17 +13906,17 @@ var Parser = /** @class */ (function () {
|
|
|
13817
13906
|
rest = true;
|
|
13818
13907
|
}
|
|
13819
13908
|
elements.push(target);
|
|
13820
|
-
token = this.peek();
|
|
13909
|
+
token = this.asToken(this.peek());
|
|
13821
13910
|
if (!isRBracketToken(token)) {
|
|
13822
13911
|
assertOperatorToken(token, ',');
|
|
13823
13912
|
this.advance();
|
|
13824
13913
|
}
|
|
13825
|
-
token = this.peek();
|
|
13914
|
+
token = this.asToken(this.peek());
|
|
13826
13915
|
}
|
|
13827
13916
|
this.advance();
|
|
13828
13917
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13829
13918
|
if (requireDefaultValue && !defaultValue) {
|
|
13830
|
-
throw new LitsError('Expected assignment', this.
|
|
13919
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13831
13920
|
}
|
|
13832
13921
|
return withSourceCodeInfo([bindingTargetTypes.array, [elements, defaultValue]], firstToken[2]);
|
|
13833
13922
|
}
|
|
@@ -13835,7 +13924,7 @@ var Parser = /** @class */ (function () {
|
|
|
13835
13924
|
if (isLBraceToken(firstToken)) {
|
|
13836
13925
|
this.advance();
|
|
13837
13926
|
var elements = {};
|
|
13838
|
-
var token = this.peek();
|
|
13927
|
+
var token = this.asToken(this.peek());
|
|
13839
13928
|
var rest = false;
|
|
13840
13929
|
while (!isRBraceToken(token)) {
|
|
13841
13930
|
if (rest) {
|
|
@@ -13846,7 +13935,7 @@ var Parser = /** @class */ (function () {
|
|
|
13846
13935
|
this.advance();
|
|
13847
13936
|
}
|
|
13848
13937
|
var key = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13849
|
-
token = this.peek();
|
|
13938
|
+
token = this.asToken(this.peek());
|
|
13850
13939
|
if (isReservedSymbolToken(token, 'as')) {
|
|
13851
13940
|
if (rest) {
|
|
13852
13941
|
throw new LitsError('Rest argument can not have alias', token[2]);
|
|
@@ -13863,7 +13952,7 @@ var Parser = /** @class */ (function () {
|
|
|
13863
13952
|
throw new LitsError("Duplicate binding name: ".concat(key), token[2]);
|
|
13864
13953
|
}
|
|
13865
13954
|
if (rest && isOperatorToken(this.peek(), ':=')) {
|
|
13866
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
13955
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13867
13956
|
}
|
|
13868
13957
|
elements[key[1]] = rest
|
|
13869
13958
|
? withSourceCodeInfo([bindingTargetTypes.rest, [key[1], this.parseOptionalDefaulValue()]], firstToken[2])
|
|
@@ -13876,17 +13965,17 @@ var Parser = /** @class */ (function () {
|
|
|
13876
13965
|
assertOperatorToken(this.peek(), ',');
|
|
13877
13966
|
this.advance();
|
|
13878
13967
|
}
|
|
13879
|
-
token = this.peek();
|
|
13968
|
+
token = this.asToken(this.peek());
|
|
13880
13969
|
}
|
|
13881
13970
|
this.advance();
|
|
13882
|
-
token = this.peek();
|
|
13971
|
+
token = this.asToken(this.peek());
|
|
13883
13972
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13884
13973
|
if (requireDefaultValue && !defaultValue) {
|
|
13885
13974
|
throw new LitsError('Expected assignment', token[2]);
|
|
13886
13975
|
}
|
|
13887
13976
|
return withSourceCodeInfo([bindingTargetTypes.object, [elements, defaultValue]], firstToken[2]);
|
|
13888
13977
|
}
|
|
13889
|
-
throw new LitsError('Expected symbol', this.
|
|
13978
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
13890
13979
|
};
|
|
13891
13980
|
Parser.prototype.parseLet = function (token, optionalSemicolon) {
|
|
13892
13981
|
if (optionalSemicolon === void 0) { optionalSemicolon = false; }
|
|
@@ -13909,7 +13998,7 @@ var Parser = /** @class */ (function () {
|
|
|
13909
13998
|
this.advance();
|
|
13910
13999
|
}
|
|
13911
14000
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
13912
|
-
throw new LitsError('Expected ;', this.
|
|
14001
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13913
14002
|
}
|
|
13914
14003
|
}
|
|
13915
14004
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -13933,7 +14022,7 @@ var Parser = /** @class */ (function () {
|
|
|
13933
14022
|
token = this.peek();
|
|
13934
14023
|
}
|
|
13935
14024
|
if (bindingNodes.length === 0) {
|
|
13936
|
-
throw new LitsError('Expected binding', this.
|
|
14025
|
+
throw new LitsError('Expected binding', this.peekSourceCodeInfo());
|
|
13937
14026
|
}
|
|
13938
14027
|
assertSymbolToken(token, 'do');
|
|
13939
14028
|
this.advance();
|
|
@@ -13944,7 +14033,7 @@ var Parser = /** @class */ (function () {
|
|
|
13944
14033
|
this.advance();
|
|
13945
14034
|
}
|
|
13946
14035
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
13947
|
-
throw new LitsError('Expected ;', this.
|
|
14036
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13948
14037
|
}
|
|
13949
14038
|
}
|
|
13950
14039
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -13960,7 +14049,7 @@ var Parser = /** @class */ (function () {
|
|
|
13960
14049
|
this.advance();
|
|
13961
14050
|
}
|
|
13962
14051
|
else if (!isReservedSymbolToken(this.peek(), 'catch')) {
|
|
13963
|
-
throw new LitsError('Expected ;', this.
|
|
14052
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13964
14053
|
}
|
|
13965
14054
|
}
|
|
13966
14055
|
var tryExpression = tryExpressions.length === 1
|
|
@@ -13982,7 +14071,7 @@ var Parser = /** @class */ (function () {
|
|
|
13982
14071
|
this.advance();
|
|
13983
14072
|
}
|
|
13984
14073
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
13985
|
-
throw new LitsError('Expected ;', this.
|
|
14074
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13986
14075
|
}
|
|
13987
14076
|
}
|
|
13988
14077
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14018,7 +14107,7 @@ var Parser = /** @class */ (function () {
|
|
|
14018
14107
|
this.advance();
|
|
14019
14108
|
}
|
|
14020
14109
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14021
|
-
throw new LitsError('Expected ;', this.
|
|
14110
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14022
14111
|
}
|
|
14023
14112
|
}
|
|
14024
14113
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14032,13 +14121,13 @@ var Parser = /** @class */ (function () {
|
|
|
14032
14121
|
this.advance();
|
|
14033
14122
|
var bindingNode = this.parseBinding();
|
|
14034
14123
|
var modifiers = [];
|
|
14035
|
-
var token = this.peek();
|
|
14124
|
+
var token = this.asToken(this.peek());
|
|
14036
14125
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14037
14126
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14038
14127
|
}
|
|
14039
14128
|
if (isOperatorToken(token, ',')) {
|
|
14040
14129
|
this.advance();
|
|
14041
|
-
token = this.peek();
|
|
14130
|
+
token = this.asToken(this.peek());
|
|
14042
14131
|
}
|
|
14043
14132
|
if (!isSymbolToken(token, 'let')
|
|
14044
14133
|
&& !isReservedSymbolToken(token, 'when')
|
|
@@ -14058,14 +14147,14 @@ var Parser = /** @class */ (function () {
|
|
|
14058
14147
|
throw new LitsError('Duplicate binding', letNode[1][1][2]);
|
|
14059
14148
|
}
|
|
14060
14149
|
letBindings.push(letNode[1][1]);
|
|
14061
|
-
token = this_2.peek();
|
|
14150
|
+
token = this_2.asToken(this_2.peek());
|
|
14062
14151
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this_2.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14063
14152
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14064
14153
|
}
|
|
14065
14154
|
if (isOperatorToken(token, ',')) {
|
|
14066
14155
|
this_2.advance();
|
|
14067
14156
|
}
|
|
14068
|
-
token = this_2.peek();
|
|
14157
|
+
token = this_2.asToken(this_2.peek());
|
|
14069
14158
|
};
|
|
14070
14159
|
var this_2 = this;
|
|
14071
14160
|
while (isSymbolToken(token, 'let')) {
|
|
@@ -14091,14 +14180,14 @@ var Parser = /** @class */ (function () {
|
|
|
14091
14180
|
modifiers.push('&while');
|
|
14092
14181
|
whileNode = this.parseExpression();
|
|
14093
14182
|
}
|
|
14094
|
-
token = this.peek();
|
|
14183
|
+
token = this.asToken(this.peek());
|
|
14095
14184
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14096
14185
|
throw new LitsError('Expected do or comma', token[2]);
|
|
14097
14186
|
}
|
|
14098
14187
|
if (isOperatorToken(token, ',')) {
|
|
14099
14188
|
this.advance();
|
|
14100
14189
|
}
|
|
14101
|
-
token = this.peek();
|
|
14190
|
+
token = this.asToken(this.peek());
|
|
14102
14191
|
}
|
|
14103
14192
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each')) {
|
|
14104
14193
|
throw new LitsError('Expected do or each', token[2]);
|
|
@@ -14135,7 +14224,7 @@ var Parser = /** @class */ (function () {
|
|
|
14135
14224
|
this.advance();
|
|
14136
14225
|
}
|
|
14137
14226
|
else if (!isReservedSymbolToken(this.peek(), 'else') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14138
|
-
throw new LitsError('Expected ;', this.
|
|
14227
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14139
14228
|
}
|
|
14140
14229
|
}
|
|
14141
14230
|
var thenExpression = thenExpressions.length === 1
|
|
@@ -14151,7 +14240,7 @@ var Parser = /** @class */ (function () {
|
|
|
14151
14240
|
this.advance();
|
|
14152
14241
|
}
|
|
14153
14242
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14154
|
-
throw new LitsError('Expected ;', this.
|
|
14243
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14155
14244
|
}
|
|
14156
14245
|
}
|
|
14157
14246
|
elseExpression = elseExpressions.length === 1
|
|
@@ -14182,7 +14271,7 @@ var Parser = /** @class */ (function () {
|
|
|
14182
14271
|
this.advance();
|
|
14183
14272
|
}
|
|
14184
14273
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14185
|
-
throw new LitsError('Expected ;', this.
|
|
14274
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14186
14275
|
}
|
|
14187
14276
|
}
|
|
14188
14277
|
var thenExpression = expressions.length === 1
|
|
@@ -14217,7 +14306,7 @@ var Parser = /** @class */ (function () {
|
|
|
14217
14306
|
this.advance();
|
|
14218
14307
|
}
|
|
14219
14308
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14220
|
-
throw new LitsError('Expected ;', this.
|
|
14309
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14221
14310
|
}
|
|
14222
14311
|
}
|
|
14223
14312
|
var thenExpression = expressions.length === 1
|
|
@@ -14244,7 +14333,7 @@ var Parser = /** @class */ (function () {
|
|
|
14244
14333
|
this.advance();
|
|
14245
14334
|
}
|
|
14246
14335
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14247
|
-
throw new LitsError('Expected ;', this.
|
|
14336
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14248
14337
|
}
|
|
14249
14338
|
}
|
|
14250
14339
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14288,7 +14377,7 @@ var Parser = /** @class */ (function () {
|
|
|
14288
14377
|
this.advance();
|
|
14289
14378
|
}
|
|
14290
14379
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14291
|
-
throw new LitsError('Expected ;', this.
|
|
14380
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14292
14381
|
}
|
|
14293
14382
|
}
|
|
14294
14383
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14299,7 +14388,7 @@ var Parser = /** @class */ (function () {
|
|
|
14299
14388
|
]]], token[2]);
|
|
14300
14389
|
}
|
|
14301
14390
|
else {
|
|
14302
|
-
throw new LitsError('Expected let or function', this.
|
|
14391
|
+
throw new LitsError('Expected let or function', this.peekSourceCodeInfo());
|
|
14303
14392
|
}
|
|
14304
14393
|
};
|
|
14305
14394
|
Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
|
|
@@ -14324,7 +14413,7 @@ var Parser = /** @class */ (function () {
|
|
|
14324
14413
|
});
|
|
14325
14414
|
};
|
|
14326
14415
|
Parser.prototype.parseSymbol = function () {
|
|
14327
|
-
var token = this.peek();
|
|
14416
|
+
var token = this.asToken(this.peek());
|
|
14328
14417
|
this.advance();
|
|
14329
14418
|
if (!isSymbolToken(token)) {
|
|
14330
14419
|
throw new LitsError("Expected symbol token, got ".concat(token[0]), token[2]);
|
|
@@ -14346,7 +14435,7 @@ var Parser = /** @class */ (function () {
|
|
|
14346
14435
|
return withSourceCodeInfo([NodeTypes.ReservedSymbol, token[1]], token[2]);
|
|
14347
14436
|
};
|
|
14348
14437
|
Parser.prototype.parseNumber = function () {
|
|
14349
|
-
var token = this.peek();
|
|
14438
|
+
var token = this.asToken(this.peek());
|
|
14350
14439
|
this.advance();
|
|
14351
14440
|
var value = token[1];
|
|
14352
14441
|
var negative = value[0] === '-';
|
|
@@ -14354,7 +14443,7 @@ var Parser = /** @class */ (function () {
|
|
|
14354
14443
|
return withSourceCodeInfo([NodeTypes.Number, negative ? -Number(numberString) : Number(numberString)], token[2]);
|
|
14355
14444
|
};
|
|
14356
14445
|
Parser.prototype.parseString = function () {
|
|
14357
|
-
var token = this.peek();
|
|
14446
|
+
var token = this.asToken(this.peek());
|
|
14358
14447
|
this.advance();
|
|
14359
14448
|
var value = token[1].substring(1, token[1].length - 1)
|
|
14360
14449
|
.replace(/(\\{2})|(\\")|(\\n)|(\\t)|(\\r)|(\\b)|(\\f)|\\(.)/g, function (_, backslash, doubleQuote, newline, tab, carriageReturn, backspace, formFeed, normalChar) {
|
|
@@ -14386,7 +14475,7 @@ var Parser = /** @class */ (function () {
|
|
|
14386
14475
|
return withSourceCodeInfo([NodeTypes.String, value], token[2]);
|
|
14387
14476
|
};
|
|
14388
14477
|
Parser.prototype.parseRegexpShorthand = function () {
|
|
14389
|
-
var token = this.peek();
|
|
14478
|
+
var token = this.asToken(this.peek());
|
|
14390
14479
|
this.advance();
|
|
14391
14480
|
var endStringPosition = token[1].lastIndexOf('"');
|
|
14392
14481
|
var regexpString = token[1].substring(2, endStringPosition);
|