@mojir/lits 2.1.2 → 2.1.4
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 +215 -59
- package/dist/cli/src/builtin/interface.d.ts +1 -0
- package/dist/cli/src/constants/constants.d.ts +1 -1
- package/dist/cli/src/evaluator/ContextStack.d.ts +3 -2
- package/dist/cli/src/evaluator/functionExecutors.d.ts +1 -1
- package/dist/cli/src/parser/types.d.ts +6 -1
- package/dist/cli/src/tokenizer/token.d.ts +2 -2
- package/dist/index.esm.js +210 -58
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +210 -58
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +210 -58
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/builtin/interface.d.ts +1 -0
- package/dist/src/constants/constants.d.ts +1 -1
- package/dist/src/evaluator/ContextStack.d.ts +3 -2
- package/dist/src/evaluator/functionExecutors.d.ts +1 -1
- package/dist/src/parser/types.d.ts +6 -1
- package/dist/src/tokenizer/token.d.ts +2 -2
- package/dist/testFramework.esm.js +207 -55
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +207 -55
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/testFramework.js
CHANGED
|
@@ -98,9 +98,15 @@ function getCodeMarker(sourceCodeInfo) {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
function getLitsErrorMessage(message, sourceCodeInfo) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
if (!sourceCodeInfo) {
|
|
102
|
+
return message;
|
|
103
|
+
}
|
|
104
|
+
var location = "".concat(sourceCodeInfo.position.line, ":").concat(sourceCodeInfo.position.column);
|
|
105
|
+
var filePathLine = sourceCodeInfo.filePath
|
|
106
|
+
? "\n".concat(sourceCodeInfo.filePath, ":").concat(location)
|
|
107
|
+
: "\nLocation ".concat(location);
|
|
108
|
+
var codeLine = "\n".concat(sourceCodeInfo.code);
|
|
109
|
+
var codeMarker = "\n".concat(getCodeMarker(sourceCodeInfo));
|
|
104
110
|
return "".concat(message).concat(filePathLine).concat(codeLine).concat(codeMarker);
|
|
105
111
|
}
|
|
106
112
|
var RecurSignal = /** @class */ (function (_super) {
|
|
@@ -235,6 +241,7 @@ var functionTypes = [
|
|
|
235
241
|
'SomePred',
|
|
236
242
|
'Fnull',
|
|
237
243
|
'Builtin',
|
|
244
|
+
'SpecialBuiltin',
|
|
238
245
|
'NativeJsFunction',
|
|
239
246
|
];
|
|
240
247
|
var functionTypeSet = new Set(functionTypes);
|
|
@@ -406,7 +413,7 @@ function findUnresolvedSymbolsInNode(node, contextStack, builtin, evaluateNode)
|
|
|
406
413
|
return findUnresolvedSymbolsInNode(node[1], contextStack, builtin, evaluateNode);
|
|
407
414
|
/* v8 ignore next 2 */
|
|
408
415
|
default:
|
|
409
|
-
throw new
|
|
416
|
+
throw new LitsError("Unhandled node type: ".concat(nodeType), node[2]);
|
|
410
417
|
}
|
|
411
418
|
}
|
|
412
419
|
|
|
@@ -669,6 +676,10 @@ function isLitsFunction(value) {
|
|
|
669
676
|
return false;
|
|
670
677
|
return !!value[FUNCTION_SYMBOL];
|
|
671
678
|
}
|
|
679
|
+
function asLitsFunction(value, sourceCodeInfo) {
|
|
680
|
+
assertLitsFunction(value, sourceCodeInfo);
|
|
681
|
+
return value;
|
|
682
|
+
}
|
|
672
683
|
function assertLitsFunction(value, sourceCodeInfo) {
|
|
673
684
|
if (!isLitsFunction(value))
|
|
674
685
|
throw getAssertionError('LitsFunction', value, sourceCodeInfo);
|
|
@@ -1357,26 +1368,37 @@ var sequenceNormalExpression = {
|
|
|
1357
1368
|
paramCount: 1,
|
|
1358
1369
|
},
|
|
1359
1370
|
'map': {
|
|
1360
|
-
evaluate: function (
|
|
1361
|
-
var
|
|
1362
|
-
var
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1371
|
+
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1372
|
+
var executeFunction = _a.executeFunction;
|
|
1373
|
+
var fn = asLitsFunction(params.at(-1));
|
|
1374
|
+
var seqs = params.slice(0, -1);
|
|
1375
|
+
assertSeq(seqs[0], sourceCodeInfo);
|
|
1376
|
+
var isString = typeof seqs[0] === 'string';
|
|
1377
|
+
var len = seqs[0].length;
|
|
1378
|
+
seqs.slice(1).forEach(function (seq) {
|
|
1379
|
+
if (isString) {
|
|
1380
|
+
assertString(seq, sourceCodeInfo);
|
|
1381
|
+
}
|
|
1382
|
+
else {
|
|
1383
|
+
assertArray(seq, sourceCodeInfo);
|
|
1384
|
+
}
|
|
1385
|
+
len = Math.min(len, seq.length);
|
|
1386
|
+
});
|
|
1387
|
+
var paramArray = [];
|
|
1388
|
+
var _loop_1 = function (i) {
|
|
1389
|
+
paramArray.push(seqs.map(function (seq) { return seq[i]; }));
|
|
1390
|
+
};
|
|
1391
|
+
for (var i = 0; i < len; i++) {
|
|
1392
|
+
_loop_1(i);
|
|
1367
1393
|
}
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
.map(function (elem) {
|
|
1372
|
-
var newVal = executeFunction(fn, [elem], contextStack, sourceCodeInfo);
|
|
1373
|
-
assertString(newVal, sourceCodeInfo, { char: true });
|
|
1374
|
-
return newVal;
|
|
1375
|
-
})
|
|
1376
|
-
.join('');
|
|
1394
|
+
var mapped = paramArray.map(function (p) { return executeFunction(fn, p, contextStack, sourceCodeInfo); });
|
|
1395
|
+
if (!isString) {
|
|
1396
|
+
return mapped;
|
|
1377
1397
|
}
|
|
1398
|
+
mapped.forEach(function (char) { return assertString(char, sourceCodeInfo); });
|
|
1399
|
+
return mapped.join('');
|
|
1378
1400
|
},
|
|
1379
|
-
paramCount: 2,
|
|
1401
|
+
paramCount: { min: 2 },
|
|
1380
1402
|
},
|
|
1381
1403
|
'pop': {
|
|
1382
1404
|
evaluate: function (_a, sourceCodeInfo) {
|
|
@@ -1926,7 +1948,7 @@ var sequenceNormalExpression = {
|
|
|
1926
1948
|
assertSeq(input, sourceCodeInfo);
|
|
1927
1949
|
if (Array.isArray(input)) {
|
|
1928
1950
|
var result = [];
|
|
1929
|
-
var
|
|
1951
|
+
var _loop_2 = function (item) {
|
|
1930
1952
|
assertAny(item, sourceCodeInfo);
|
|
1931
1953
|
if (!result.some(function (existingItem) { return deepEqual(existingItem, item, sourceCodeInfo); })) {
|
|
1932
1954
|
result.push(item);
|
|
@@ -1935,7 +1957,7 @@ var sequenceNormalExpression = {
|
|
|
1935
1957
|
try {
|
|
1936
1958
|
for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
|
|
1937
1959
|
var item = input_1_1.value;
|
|
1938
|
-
|
|
1960
|
+
_loop_2(item);
|
|
1939
1961
|
}
|
|
1940
1962
|
}
|
|
1941
1963
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -3771,6 +3793,26 @@ var andSpecialExpression = {
|
|
|
3771
3793
|
}
|
|
3772
3794
|
return value;
|
|
3773
3795
|
},
|
|
3796
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
3797
|
+
var e_2, _a;
|
|
3798
|
+
var value = true;
|
|
3799
|
+
try {
|
|
3800
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
3801
|
+
var param = params_1_1.value;
|
|
3802
|
+
value = asAny(param, sourceCodeInfo);
|
|
3803
|
+
if (!value)
|
|
3804
|
+
break;
|
|
3805
|
+
}
|
|
3806
|
+
}
|
|
3807
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3808
|
+
finally {
|
|
3809
|
+
try {
|
|
3810
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
3811
|
+
}
|
|
3812
|
+
finally { if (e_2) throw e_2.error; }
|
|
3813
|
+
}
|
|
3814
|
+
return value;
|
|
3815
|
+
},
|
|
3774
3816
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
3775
3817
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
3776
3818
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4015,7 +4057,7 @@ var defSpecialExpression = {
|
|
|
4015
4057
|
var value = bindingNode[1][1];
|
|
4016
4058
|
var bindingValue = evaluateNode(value, contextStack);
|
|
4017
4059
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
4018
|
-
contextStack.exportValues(values);
|
|
4060
|
+
contextStack.exportValues(values, target[2]);
|
|
4019
4061
|
return null;
|
|
4020
4062
|
},
|
|
4021
4063
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4027,7 +4069,7 @@ var defSpecialExpression = {
|
|
|
4027
4069
|
walkDefaults(target, function (defaultNode) {
|
|
4028
4070
|
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
4029
4071
|
});
|
|
4030
|
-
contextStack.addValues(getAllBindingTargetNames(target));
|
|
4072
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
4031
4073
|
return bindingResult;
|
|
4032
4074
|
},
|
|
4033
4075
|
};
|
|
@@ -4145,14 +4187,14 @@ var functionSpecialExpression = {
|
|
|
4145
4187
|
_b.name = functionSymbol[1],
|
|
4146
4188
|
_b.evaluatedfunction = evaluatedFunction,
|
|
4147
4189
|
_b);
|
|
4148
|
-
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4190
|
+
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4149
4191
|
return null;
|
|
4150
4192
|
},
|
|
4151
4193
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4152
4194
|
var _b, _c;
|
|
4153
4195
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4154
4196
|
var functionName = node[1][1][1];
|
|
4155
|
-
contextStack.addValues((_b = {}, _b[functionName] = true, _b));
|
|
4197
|
+
contextStack.addValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4156
4198
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4157
4199
|
return getFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4158
4200
|
},
|
|
@@ -4173,7 +4215,7 @@ var defnSpecialExpression = {
|
|
|
4173
4215
|
_b.name = functionSymbol[1],
|
|
4174
4216
|
_b.evaluatedfunction = evaluatedFunctionOverloades,
|
|
4175
4217
|
_b);
|
|
4176
|
-
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4218
|
+
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4177
4219
|
return null;
|
|
4178
4220
|
},
|
|
4179
4221
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4181,7 +4223,7 @@ var defnSpecialExpression = {
|
|
|
4181
4223
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4182
4224
|
var functionName = node[1][1][1];
|
|
4183
4225
|
var fn = node[1][2];
|
|
4184
|
-
contextStack.exportValues((_b = {}, _b[functionName] = true, _b));
|
|
4226
|
+
contextStack.exportValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4185
4227
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4186
4228
|
return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4187
4229
|
},
|
|
@@ -4293,7 +4335,7 @@ var letSpecialExpression = {
|
|
|
4293
4335
|
var value = bindingNode[1][1];
|
|
4294
4336
|
var bindingValue = evaluateNode(value, contextStack);
|
|
4295
4337
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
4296
|
-
contextStack.addValues(values);
|
|
4338
|
+
contextStack.addValues(values, target[2]);
|
|
4297
4339
|
return null;
|
|
4298
4340
|
},
|
|
4299
4341
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4305,7 +4347,7 @@ var letSpecialExpression = {
|
|
|
4305
4347
|
walkDefaults(target, function (defaultNode) {
|
|
4306
4348
|
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
4307
4349
|
});
|
|
4308
|
-
contextStack.addValues(getAllBindingTargetNames(target));
|
|
4350
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
4309
4351
|
return bindingResult;
|
|
4310
4352
|
},
|
|
4311
4353
|
};
|
|
@@ -4576,6 +4618,26 @@ var orSpecialExpression = {
|
|
|
4576
4618
|
}
|
|
4577
4619
|
return value;
|
|
4578
4620
|
},
|
|
4621
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4622
|
+
var e_2, _a;
|
|
4623
|
+
var value = false;
|
|
4624
|
+
try {
|
|
4625
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4626
|
+
var param = params_1_1.value;
|
|
4627
|
+
value = asAny(param, sourceCodeInfo);
|
|
4628
|
+
if (value)
|
|
4629
|
+
break;
|
|
4630
|
+
}
|
|
4631
|
+
}
|
|
4632
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4633
|
+
finally {
|
|
4634
|
+
try {
|
|
4635
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4636
|
+
}
|
|
4637
|
+
finally { if (e_2) throw e_2.error; }
|
|
4638
|
+
}
|
|
4639
|
+
return value;
|
|
4640
|
+
},
|
|
4579
4641
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4580
4642
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4581
4643
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4594,6 +4656,11 @@ var qqSpecialExpression = {
|
|
|
4594
4656
|
var firstResult = evaluateNode(firstNode, contextStack);
|
|
4595
4657
|
return firstResult !== null && firstResult !== void 0 ? firstResult : (secondNode ? evaluateNode(secondNode, contextStack) : null);
|
|
4596
4658
|
},
|
|
4659
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4660
|
+
var firstParam = asAny(params[0], sourceCodeInfo);
|
|
4661
|
+
var secondParam = params[1] !== undefined ? asAny(params[1], sourceCodeInfo) : null;
|
|
4662
|
+
return firstParam !== null && firstParam !== void 0 ? firstParam : secondParam;
|
|
4663
|
+
},
|
|
4597
4664
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4598
4665
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4599
4666
|
return getUndefinedSymbols(node[1][1].filter(function (n) { return !!n; }), contextStack, builtin, evaluateNode);
|
|
@@ -4608,6 +4675,9 @@ var recurSpecialExpression = {
|
|
|
4608
4675
|
var evaluatedParams = params.map(function (paramNode) { return evaluateNode(paramNode, contextStack); });
|
|
4609
4676
|
throw new RecurSignal(evaluatedParams);
|
|
4610
4677
|
},
|
|
4678
|
+
evaluateAsNormalExpression: function (params) {
|
|
4679
|
+
throw new RecurSignal(params);
|
|
4680
|
+
},
|
|
4611
4681
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4612
4682
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4613
4683
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4623,6 +4693,12 @@ var throwSpecialExpression = {
|
|
|
4623
4693
|
});
|
|
4624
4694
|
throw new UserDefinedError(message, node[2]);
|
|
4625
4695
|
},
|
|
4696
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4697
|
+
var message = asString(params[0], sourceCodeInfo, {
|
|
4698
|
+
nonEmpty: true,
|
|
4699
|
+
});
|
|
4700
|
+
throw new UserDefinedError(message, undefined);
|
|
4701
|
+
},
|
|
4626
4702
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4627
4703
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4628
4704
|
return getUndefinedSymbols([node[1][1]], contextStack, builtin, evaluateNode);
|
|
@@ -4690,6 +4766,24 @@ var arraySpecialExpression = {
|
|
|
4690
4766
|
}
|
|
4691
4767
|
return result;
|
|
4692
4768
|
},
|
|
4769
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4770
|
+
var e_2, _a;
|
|
4771
|
+
var result = [];
|
|
4772
|
+
try {
|
|
4773
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4774
|
+
var param = params_1_1.value;
|
|
4775
|
+
result.push(asAny(param, sourceCodeInfo));
|
|
4776
|
+
}
|
|
4777
|
+
}
|
|
4778
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4779
|
+
finally {
|
|
4780
|
+
try {
|
|
4781
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4782
|
+
}
|
|
4783
|
+
finally { if (e_2) throw e_2.error; }
|
|
4784
|
+
}
|
|
4785
|
+
return result;
|
|
4786
|
+
},
|
|
4693
4787
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4694
4788
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4695
4789
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4721,6 +4815,16 @@ var objectSpecialExpression = {
|
|
|
4721
4815
|
}
|
|
4722
4816
|
return result;
|
|
4723
4817
|
},
|
|
4818
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4819
|
+
var result = {};
|
|
4820
|
+
for (var i = 0; i < params.length; i += 2) {
|
|
4821
|
+
var key = params[i];
|
|
4822
|
+
var value = params[i + 1];
|
|
4823
|
+
assertString(key, sourceCodeInfo);
|
|
4824
|
+
result[key] = value !== null && value !== void 0 ? value : null;
|
|
4825
|
+
}
|
|
4826
|
+
return result;
|
|
4827
|
+
},
|
|
4724
4828
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4725
4829
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4726
4830
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4964,6 +5068,16 @@ var functionExecutors = {
|
|
|
4964
5068
|
var normalExpression = asNonUndefined(allNormalExpressions[fn.normalBuitinSymbolType], sourceCodeInfo);
|
|
4965
5069
|
return normalExpression.evaluate(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
4966
5070
|
},
|
|
5071
|
+
SpecialBuiltin: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
5072
|
+
var executeFunction = _a.executeFunction;
|
|
5073
|
+
var specialExpression = asNonUndefined(specialExpressions[fn.specialBuiltinSymbolType], sourceCodeInfo);
|
|
5074
|
+
if (specialExpression.evaluateAsNormalExpression) {
|
|
5075
|
+
return specialExpression.evaluateAsNormalExpression(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
5076
|
+
}
|
|
5077
|
+
else {
|
|
5078
|
+
throw new LitsError("Special builtin function ".concat(fn.specialBuiltinSymbolType, " is not supported as normal expression."), sourceCodeInfo);
|
|
5079
|
+
}
|
|
5080
|
+
},
|
|
4967
5081
|
};
|
|
4968
5082
|
|
|
4969
5083
|
function evaluate(ast, contextStack) {
|
|
@@ -5019,7 +5133,21 @@ function evaluateReservedSymbol(node) {
|
|
|
5019
5133
|
function evaluateNormalExpression(node, contextStack) {
|
|
5020
5134
|
var sourceCodeInfo = node[2];
|
|
5021
5135
|
var paramNodes = node[1][1];
|
|
5022
|
-
var params =
|
|
5136
|
+
var params = [];
|
|
5137
|
+
paramNodes.forEach(function (paramNode) {
|
|
5138
|
+
if (isSpreadNode(paramNode)) {
|
|
5139
|
+
var spreadValue = evaluateNode(paramNode[1], contextStack);
|
|
5140
|
+
if (Array.isArray(spreadValue)) {
|
|
5141
|
+
params.push.apply(params, __spreadArray([], __read(spreadValue), false));
|
|
5142
|
+
}
|
|
5143
|
+
else {
|
|
5144
|
+
throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
|
|
5145
|
+
}
|
|
5146
|
+
}
|
|
5147
|
+
else {
|
|
5148
|
+
params.push(evaluateNode(paramNode, contextStack));
|
|
5149
|
+
}
|
|
5150
|
+
});
|
|
5023
5151
|
if (isNormalExpressionNodeWithName(node)) {
|
|
5024
5152
|
var nameSymbol = node[1][0];
|
|
5025
5153
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
@@ -5121,19 +5249,19 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5121
5249
|
var contexts = [{}, context];
|
|
5122
5250
|
return new ContextStackImpl({ contexts: contexts });
|
|
5123
5251
|
};
|
|
5124
|
-
ContextStackImpl.prototype.exportValues = function (values) {
|
|
5252
|
+
ContextStackImpl.prototype.exportValues = function (values, sourceCodeInfo) {
|
|
5125
5253
|
var e_1, _a;
|
|
5126
5254
|
try {
|
|
5127
5255
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5128
5256
|
var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
|
|
5129
5257
|
if (this.globalContext[name_1]) {
|
|
5130
|
-
throw new
|
|
5258
|
+
throw new LitsError("Cannot redefine exported value \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5131
5259
|
}
|
|
5132
5260
|
if (specialExpressionKeys.includes(name_1)) {
|
|
5133
|
-
throw new
|
|
5261
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5134
5262
|
}
|
|
5135
5263
|
if (normalExpressionKeys.includes(name_1)) {
|
|
5136
|
-
throw new
|
|
5264
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5137
5265
|
}
|
|
5138
5266
|
this.globalContext[name_1] = { value: value };
|
|
5139
5267
|
}
|
|
@@ -5145,22 +5273,22 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5145
5273
|
}
|
|
5146
5274
|
finally { if (e_1) throw e_1.error; }
|
|
5147
5275
|
}
|
|
5148
|
-
this.addValues(values);
|
|
5276
|
+
this.addValues(values, sourceCodeInfo);
|
|
5149
5277
|
};
|
|
5150
|
-
ContextStackImpl.prototype.addValues = function (values) {
|
|
5278
|
+
ContextStackImpl.prototype.addValues = function (values, sourceCodeInfo) {
|
|
5151
5279
|
var e_2, _a;
|
|
5152
5280
|
var currentContext = this.contexts[0];
|
|
5153
5281
|
try {
|
|
5154
5282
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5155
5283
|
var _d = __read(_c.value, 2), name_2 = _d[0], value = _d[1];
|
|
5156
5284
|
if (currentContext[name_2]) {
|
|
5157
|
-
throw new
|
|
5285
|
+
throw new LitsError("Cannot redefine value \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5158
5286
|
}
|
|
5159
5287
|
if (specialExpressionKeys.includes(name_2)) {
|
|
5160
|
-
throw new
|
|
5288
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5161
5289
|
}
|
|
5162
5290
|
if (normalExpressionKeys.includes(name_2)) {
|
|
5163
|
-
throw new
|
|
5291
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5164
5292
|
}
|
|
5165
5293
|
currentContext[name_2] = { value: toAny(value) };
|
|
5166
5294
|
}
|
|
@@ -5240,18 +5368,36 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5240
5368
|
return null;
|
|
5241
5369
|
};
|
|
5242
5370
|
ContextStackImpl.prototype.evaluateSymbol = function (node) {
|
|
5243
|
-
var _a;
|
|
5371
|
+
var _a, _b;
|
|
5244
5372
|
if (isSpecialBuiltinSymbolNode(node)) {
|
|
5245
|
-
|
|
5373
|
+
var functionType = node[1];
|
|
5374
|
+
switch (functionType) {
|
|
5375
|
+
case specialExpressionTypes['&&']:
|
|
5376
|
+
case specialExpressionTypes['||']:
|
|
5377
|
+
case specialExpressionTypes.array:
|
|
5378
|
+
case specialExpressionTypes.object:
|
|
5379
|
+
case specialExpressionTypes['defined?']:
|
|
5380
|
+
case specialExpressionTypes.recur:
|
|
5381
|
+
case specialExpressionTypes.throw:
|
|
5382
|
+
case specialExpressionTypes['??']:
|
|
5383
|
+
return _a = {},
|
|
5384
|
+
_a[FUNCTION_SYMBOL] = true,
|
|
5385
|
+
_a.functionType = 'SpecialBuiltin',
|
|
5386
|
+
_a.specialBuiltinSymbolType = functionType,
|
|
5387
|
+
_a.sourceCodeInfo = node[2],
|
|
5388
|
+
_a;
|
|
5389
|
+
default:
|
|
5390
|
+
throw new LitsError("Unknown special builtin symbol type: ".concat(functionType), node[2]);
|
|
5391
|
+
}
|
|
5246
5392
|
}
|
|
5247
5393
|
if (isNormalBuiltinSymbolNode(node)) {
|
|
5248
5394
|
var type = node[1];
|
|
5249
|
-
return
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5395
|
+
return _b = {},
|
|
5396
|
+
_b[FUNCTION_SYMBOL] = true,
|
|
5397
|
+
_b.functionType = 'Builtin',
|
|
5398
|
+
_b.normalBuitinSymbolType = type,
|
|
5399
|
+
_b.sourceCodeInfo = node[2],
|
|
5400
|
+
_b;
|
|
5255
5401
|
}
|
|
5256
5402
|
var lookUpResult = this.lookUp(node);
|
|
5257
5403
|
if (isContextEntry(lookUpResult))
|
|
@@ -5923,7 +6069,7 @@ function withSourceCodeInfo(node, sourceCodeInfo) {
|
|
|
5923
6069
|
}
|
|
5924
6070
|
return node;
|
|
5925
6071
|
}
|
|
5926
|
-
function getPrecedence(operatorSign) {
|
|
6072
|
+
function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
5927
6073
|
switch (operatorSign) {
|
|
5928
6074
|
case '**': // exponentiation
|
|
5929
6075
|
return exponentiationPrecedence;
|
|
@@ -5962,7 +6108,7 @@ function getPrecedence(operatorSign) {
|
|
|
5962
6108
|
// leave room for binaryFunctionalOperatorPrecedence = 1
|
|
5963
6109
|
/* v8 ignore next 2 */
|
|
5964
6110
|
default:
|
|
5965
|
-
throw new
|
|
6111
|
+
throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
|
|
5966
6112
|
}
|
|
5967
6113
|
}
|
|
5968
6114
|
function createNamedNormalExpressionNode(symbolNode, params, sourceCodeInfo) {
|
|
@@ -6095,7 +6241,7 @@ var Parser = /** @class */ (function () {
|
|
|
6095
6241
|
while (!this.isAtExpressionEnd()) {
|
|
6096
6242
|
if (isA_BinaryOperatorToken(operator)) {
|
|
6097
6243
|
var name_1 = operator[1];
|
|
6098
|
-
var newPrecedece = getPrecedence(name_1);
|
|
6244
|
+
var newPrecedece = getPrecedence(name_1, operator[2]);
|
|
6099
6245
|
if (newPrecedece <= precedence
|
|
6100
6246
|
// ** (exponentiation) is right associative
|
|
6101
6247
|
&& !(newPrecedece === exponentiationPrecedence && precedence === exponentiationPrecedence)) {
|
|
@@ -6175,7 +6321,7 @@ var Parser = /** @class */ (function () {
|
|
|
6175
6321
|
this.advance();
|
|
6176
6322
|
var expression = this.parseExpression();
|
|
6177
6323
|
if (!isRParenToken(this.peek())) {
|
|
6178
|
-
throw new
|
|
6324
|
+
throw new LitsError('Expected closing parenthesis', this.peek()[2]);
|
|
6179
6325
|
}
|
|
6180
6326
|
this.advance();
|
|
6181
6327
|
return expression;
|
|
@@ -6297,7 +6443,13 @@ var Parser = /** @class */ (function () {
|
|
|
6297
6443
|
this.advance();
|
|
6298
6444
|
var params = [];
|
|
6299
6445
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
6300
|
-
|
|
6446
|
+
if (isOperatorToken(this.peek(), '...')) {
|
|
6447
|
+
this.advance();
|
|
6448
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peek()[2]));
|
|
6449
|
+
}
|
|
6450
|
+
else {
|
|
6451
|
+
params.push(this.parseExpression());
|
|
6452
|
+
}
|
|
6301
6453
|
var nextToken = this.peek();
|
|
6302
6454
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
6303
6455
|
throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
|
|
@@ -6353,7 +6505,7 @@ var Parser = /** @class */ (function () {
|
|
|
6353
6505
|
throw new LitsError("".concat(type, " is not allowed"), symbol[2]);
|
|
6354
6506
|
/* v8 ignore next 2 */
|
|
6355
6507
|
default:
|
|
6356
|
-
throw new
|
|
6508
|
+
throw new LitsError("Unknown special expression: ".concat(type), symbol[2]);
|
|
6357
6509
|
}
|
|
6358
6510
|
}
|
|
6359
6511
|
else if (isNormalBuiltinSymbolNode(symbol) || isNormalBuiltinSymbolNode(symbol)) {
|