@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/lits.iife.js
CHANGED
|
@@ -96,9 +96,15 @@ var Lits = (function (exports) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
function getLitsErrorMessage(message, sourceCodeInfo) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
if (!sourceCodeInfo) {
|
|
100
|
+
return message;
|
|
101
|
+
}
|
|
102
|
+
var location = "".concat(sourceCodeInfo.position.line, ":").concat(sourceCodeInfo.position.column);
|
|
103
|
+
var filePathLine = sourceCodeInfo.filePath
|
|
104
|
+
? "\n".concat(sourceCodeInfo.filePath, ":").concat(location)
|
|
105
|
+
: "\nLocation ".concat(location);
|
|
106
|
+
var codeLine = "\n".concat(sourceCodeInfo.code);
|
|
107
|
+
var codeMarker = "\n".concat(getCodeMarker(sourceCodeInfo));
|
|
102
108
|
return "".concat(message).concat(filePathLine).concat(codeLine).concat(codeMarker);
|
|
103
109
|
}
|
|
104
110
|
var RecurSignal = /** @class */ (function (_super) {
|
|
@@ -211,6 +217,7 @@ var Lits = (function (exports) {
|
|
|
211
217
|
'SomePred',
|
|
212
218
|
'Fnull',
|
|
213
219
|
'Builtin',
|
|
220
|
+
'SpecialBuiltin',
|
|
214
221
|
'NativeJsFunction',
|
|
215
222
|
];
|
|
216
223
|
var functionTypeSet = new Set(functionTypes);
|
|
@@ -1258,26 +1265,37 @@ var Lits = (function (exports) {
|
|
|
1258
1265
|
paramCount: 1,
|
|
1259
1266
|
},
|
|
1260
1267
|
'map': {
|
|
1261
|
-
evaluate: function (
|
|
1262
|
-
var
|
|
1263
|
-
var
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
+
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1269
|
+
var executeFunction = _a.executeFunction;
|
|
1270
|
+
var fn = asLitsFunction(params.at(-1));
|
|
1271
|
+
var seqs = params.slice(0, -1);
|
|
1272
|
+
assertSeq(seqs[0], sourceCodeInfo);
|
|
1273
|
+
var isString = typeof seqs[0] === 'string';
|
|
1274
|
+
var len = seqs[0].length;
|
|
1275
|
+
seqs.slice(1).forEach(function (seq) {
|
|
1276
|
+
if (isString) {
|
|
1277
|
+
assertString(seq, sourceCodeInfo);
|
|
1278
|
+
}
|
|
1279
|
+
else {
|
|
1280
|
+
assertArray(seq, sourceCodeInfo);
|
|
1281
|
+
}
|
|
1282
|
+
len = Math.min(len, seq.length);
|
|
1283
|
+
});
|
|
1284
|
+
var paramArray = [];
|
|
1285
|
+
var _loop_1 = function (i) {
|
|
1286
|
+
paramArray.push(seqs.map(function (seq) { return seq[i]; }));
|
|
1287
|
+
};
|
|
1288
|
+
for (var i = 0; i < len; i++) {
|
|
1289
|
+
_loop_1(i);
|
|
1268
1290
|
}
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
.map(function (elem) {
|
|
1273
|
-
var newVal = executeFunction(fn, [elem], contextStack, sourceCodeInfo);
|
|
1274
|
-
assertString(newVal, sourceCodeInfo, { char: true });
|
|
1275
|
-
return newVal;
|
|
1276
|
-
})
|
|
1277
|
-
.join('');
|
|
1291
|
+
var mapped = paramArray.map(function (p) { return executeFunction(fn, p, contextStack, sourceCodeInfo); });
|
|
1292
|
+
if (!isString) {
|
|
1293
|
+
return mapped;
|
|
1278
1294
|
}
|
|
1295
|
+
mapped.forEach(function (char) { return assertString(char, sourceCodeInfo); });
|
|
1296
|
+
return mapped.join('');
|
|
1279
1297
|
},
|
|
1280
|
-
paramCount: 2,
|
|
1298
|
+
paramCount: { min: 2 },
|
|
1281
1299
|
},
|
|
1282
1300
|
'pop': {
|
|
1283
1301
|
evaluate: function (_a, sourceCodeInfo) {
|
|
@@ -1827,7 +1845,7 @@ var Lits = (function (exports) {
|
|
|
1827
1845
|
assertSeq(input, sourceCodeInfo);
|
|
1828
1846
|
if (Array.isArray(input)) {
|
|
1829
1847
|
var result = [];
|
|
1830
|
-
var
|
|
1848
|
+
var _loop_2 = function (item) {
|
|
1831
1849
|
assertAny(item, sourceCodeInfo);
|
|
1832
1850
|
if (!result.some(function (existingItem) { return deepEqual(existingItem, item, sourceCodeInfo); })) {
|
|
1833
1851
|
result.push(item);
|
|
@@ -1836,7 +1854,7 @@ var Lits = (function (exports) {
|
|
|
1836
1854
|
try {
|
|
1837
1855
|
for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
|
|
1838
1856
|
var item = input_1_1.value;
|
|
1839
|
-
|
|
1857
|
+
_loop_2(item);
|
|
1840
1858
|
}
|
|
1841
1859
|
}
|
|
1842
1860
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -3672,6 +3690,26 @@ var Lits = (function (exports) {
|
|
|
3672
3690
|
}
|
|
3673
3691
|
return value;
|
|
3674
3692
|
},
|
|
3693
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
3694
|
+
var e_2, _a;
|
|
3695
|
+
var value = true;
|
|
3696
|
+
try {
|
|
3697
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
3698
|
+
var param = params_1_1.value;
|
|
3699
|
+
value = asAny(param, sourceCodeInfo);
|
|
3700
|
+
if (!value)
|
|
3701
|
+
break;
|
|
3702
|
+
}
|
|
3703
|
+
}
|
|
3704
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3705
|
+
finally {
|
|
3706
|
+
try {
|
|
3707
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
3708
|
+
}
|
|
3709
|
+
finally { if (e_2) throw e_2.error; }
|
|
3710
|
+
}
|
|
3711
|
+
return value;
|
|
3712
|
+
},
|
|
3675
3713
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
3676
3714
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
3677
3715
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -3956,7 +3994,7 @@ var Lits = (function (exports) {
|
|
|
3956
3994
|
var value = bindingNode[1][1];
|
|
3957
3995
|
var bindingValue = evaluateNode(value, contextStack);
|
|
3958
3996
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
3959
|
-
contextStack.exportValues(values);
|
|
3997
|
+
contextStack.exportValues(values, target[2]);
|
|
3960
3998
|
return null;
|
|
3961
3999
|
},
|
|
3962
4000
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -3968,7 +4006,7 @@ var Lits = (function (exports) {
|
|
|
3968
4006
|
walkDefaults(target, function (defaultNode) {
|
|
3969
4007
|
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
3970
4008
|
});
|
|
3971
|
-
contextStack.addValues(getAllBindingTargetNames(target));
|
|
4009
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
3972
4010
|
return bindingResult;
|
|
3973
4011
|
},
|
|
3974
4012
|
};
|
|
@@ -4111,14 +4149,14 @@ var Lits = (function (exports) {
|
|
|
4111
4149
|
_b.name = functionSymbol[1],
|
|
4112
4150
|
_b.evaluatedfunction = evaluatedFunction,
|
|
4113
4151
|
_b);
|
|
4114
|
-
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4152
|
+
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4115
4153
|
return null;
|
|
4116
4154
|
},
|
|
4117
4155
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4118
4156
|
var _b, _c;
|
|
4119
4157
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4120
4158
|
var functionName = node[1][1][1];
|
|
4121
|
-
contextStack.addValues((_b = {}, _b[functionName] = true, _b));
|
|
4159
|
+
contextStack.addValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4122
4160
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4123
4161
|
return getFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4124
4162
|
},
|
|
@@ -4139,7 +4177,7 @@ var Lits = (function (exports) {
|
|
|
4139
4177
|
_b.name = functionSymbol[1],
|
|
4140
4178
|
_b.evaluatedfunction = evaluatedFunctionOverloades,
|
|
4141
4179
|
_b);
|
|
4142
|
-
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4180
|
+
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4143
4181
|
return null;
|
|
4144
4182
|
},
|
|
4145
4183
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4147,7 +4185,7 @@ var Lits = (function (exports) {
|
|
|
4147
4185
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4148
4186
|
var functionName = node[1][1][1];
|
|
4149
4187
|
var fn = node[1][2];
|
|
4150
|
-
contextStack.exportValues((_b = {}, _b[functionName] = true, _b));
|
|
4188
|
+
contextStack.exportValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4151
4189
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4152
4190
|
return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4153
4191
|
},
|
|
@@ -4259,7 +4297,7 @@ var Lits = (function (exports) {
|
|
|
4259
4297
|
var value = bindingNode[1][1];
|
|
4260
4298
|
var bindingValue = evaluateNode(value, contextStack);
|
|
4261
4299
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
4262
|
-
contextStack.addValues(values);
|
|
4300
|
+
contextStack.addValues(values, target[2]);
|
|
4263
4301
|
return null;
|
|
4264
4302
|
},
|
|
4265
4303
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4271,7 +4309,7 @@ var Lits = (function (exports) {
|
|
|
4271
4309
|
walkDefaults(target, function (defaultNode) {
|
|
4272
4310
|
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
4273
4311
|
});
|
|
4274
|
-
contextStack.addValues(getAllBindingTargetNames(target));
|
|
4312
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
4275
4313
|
return bindingResult;
|
|
4276
4314
|
},
|
|
4277
4315
|
};
|
|
@@ -4542,6 +4580,26 @@ var Lits = (function (exports) {
|
|
|
4542
4580
|
}
|
|
4543
4581
|
return value;
|
|
4544
4582
|
},
|
|
4583
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4584
|
+
var e_2, _a;
|
|
4585
|
+
var value = false;
|
|
4586
|
+
try {
|
|
4587
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4588
|
+
var param = params_1_1.value;
|
|
4589
|
+
value = asAny(param, sourceCodeInfo);
|
|
4590
|
+
if (value)
|
|
4591
|
+
break;
|
|
4592
|
+
}
|
|
4593
|
+
}
|
|
4594
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4595
|
+
finally {
|
|
4596
|
+
try {
|
|
4597
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4598
|
+
}
|
|
4599
|
+
finally { if (e_2) throw e_2.error; }
|
|
4600
|
+
}
|
|
4601
|
+
return value;
|
|
4602
|
+
},
|
|
4545
4603
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4546
4604
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4547
4605
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4560,6 +4618,11 @@ var Lits = (function (exports) {
|
|
|
4560
4618
|
var firstResult = evaluateNode(firstNode, contextStack);
|
|
4561
4619
|
return firstResult !== null && firstResult !== void 0 ? firstResult : (secondNode ? evaluateNode(secondNode, contextStack) : null);
|
|
4562
4620
|
},
|
|
4621
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4622
|
+
var firstParam = asAny(params[0], sourceCodeInfo);
|
|
4623
|
+
var secondParam = params[1] !== undefined ? asAny(params[1], sourceCodeInfo) : null;
|
|
4624
|
+
return firstParam !== null && firstParam !== void 0 ? firstParam : secondParam;
|
|
4625
|
+
},
|
|
4563
4626
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4564
4627
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4565
4628
|
return getUndefinedSymbols(node[1][1].filter(function (n) { return !!n; }), contextStack, builtin, evaluateNode);
|
|
@@ -4574,6 +4637,9 @@ var Lits = (function (exports) {
|
|
|
4574
4637
|
var evaluatedParams = params.map(function (paramNode) { return evaluateNode(paramNode, contextStack); });
|
|
4575
4638
|
throw new RecurSignal(evaluatedParams);
|
|
4576
4639
|
},
|
|
4640
|
+
evaluateAsNormalExpression: function (params) {
|
|
4641
|
+
throw new RecurSignal(params);
|
|
4642
|
+
},
|
|
4577
4643
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4578
4644
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4579
4645
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4589,6 +4655,12 @@ var Lits = (function (exports) {
|
|
|
4589
4655
|
});
|
|
4590
4656
|
throw new UserDefinedError(message, node[2]);
|
|
4591
4657
|
},
|
|
4658
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4659
|
+
var message = asString(params[0], sourceCodeInfo, {
|
|
4660
|
+
nonEmpty: true,
|
|
4661
|
+
});
|
|
4662
|
+
throw new UserDefinedError(message, undefined);
|
|
4663
|
+
},
|
|
4592
4664
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4593
4665
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4594
4666
|
return getUndefinedSymbols([node[1][1]], contextStack, builtin, evaluateNode);
|
|
@@ -4656,6 +4728,24 @@ var Lits = (function (exports) {
|
|
|
4656
4728
|
}
|
|
4657
4729
|
return result;
|
|
4658
4730
|
},
|
|
4731
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4732
|
+
var e_2, _a;
|
|
4733
|
+
var result = [];
|
|
4734
|
+
try {
|
|
4735
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4736
|
+
var param = params_1_1.value;
|
|
4737
|
+
result.push(asAny(param, sourceCodeInfo));
|
|
4738
|
+
}
|
|
4739
|
+
}
|
|
4740
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4741
|
+
finally {
|
|
4742
|
+
try {
|
|
4743
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4744
|
+
}
|
|
4745
|
+
finally { if (e_2) throw e_2.error; }
|
|
4746
|
+
}
|
|
4747
|
+
return result;
|
|
4748
|
+
},
|
|
4659
4749
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4660
4750
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4661
4751
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4687,6 +4777,16 @@ var Lits = (function (exports) {
|
|
|
4687
4777
|
}
|
|
4688
4778
|
return result;
|
|
4689
4779
|
},
|
|
4780
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4781
|
+
var result = {};
|
|
4782
|
+
for (var i = 0; i < params.length; i += 2) {
|
|
4783
|
+
var key = params[i];
|
|
4784
|
+
var value = params[i + 1];
|
|
4785
|
+
assertString(key, sourceCodeInfo);
|
|
4786
|
+
result[key] = value !== null && value !== void 0 ? value : null;
|
|
4787
|
+
}
|
|
4788
|
+
return result;
|
|
4789
|
+
},
|
|
4690
4790
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4691
4791
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4692
4792
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4812,7 +4912,7 @@ var Lits = (function (exports) {
|
|
|
4812
4912
|
return findUnresolvedSymbolsInNode(node[1], contextStack, builtin, evaluateNode);
|
|
4813
4913
|
/* v8 ignore next 2 */
|
|
4814
4914
|
default:
|
|
4815
|
-
throw new
|
|
4915
|
+
throw new LitsError("Unhandled node type: ".concat(nodeType), node[2]);
|
|
4816
4916
|
}
|
|
4817
4917
|
}
|
|
4818
4918
|
|
|
@@ -5020,6 +5120,16 @@ var Lits = (function (exports) {
|
|
|
5020
5120
|
var normalExpression = asNonUndefined(allNormalExpressions[fn.normalBuitinSymbolType], sourceCodeInfo);
|
|
5021
5121
|
return normalExpression.evaluate(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
5022
5122
|
},
|
|
5123
|
+
SpecialBuiltin: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
5124
|
+
var executeFunction = _a.executeFunction;
|
|
5125
|
+
var specialExpression = asNonUndefined(specialExpressions[fn.specialBuiltinSymbolType], sourceCodeInfo);
|
|
5126
|
+
if (specialExpression.evaluateAsNormalExpression) {
|
|
5127
|
+
return specialExpression.evaluateAsNormalExpression(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
5128
|
+
}
|
|
5129
|
+
else {
|
|
5130
|
+
throw new LitsError("Special builtin function ".concat(fn.specialBuiltinSymbolType, " is not supported as normal expression."), sourceCodeInfo);
|
|
5131
|
+
}
|
|
5132
|
+
},
|
|
5023
5133
|
};
|
|
5024
5134
|
|
|
5025
5135
|
function evaluate(ast, contextStack) {
|
|
@@ -5075,7 +5185,21 @@ var Lits = (function (exports) {
|
|
|
5075
5185
|
function evaluateNormalExpression(node, contextStack) {
|
|
5076
5186
|
var sourceCodeInfo = node[2];
|
|
5077
5187
|
var paramNodes = node[1][1];
|
|
5078
|
-
var params =
|
|
5188
|
+
var params = [];
|
|
5189
|
+
paramNodes.forEach(function (paramNode) {
|
|
5190
|
+
if (isSpreadNode(paramNode)) {
|
|
5191
|
+
var spreadValue = evaluateNode(paramNode[1], contextStack);
|
|
5192
|
+
if (Array.isArray(spreadValue)) {
|
|
5193
|
+
params.push.apply(params, __spreadArray([], __read(spreadValue), false));
|
|
5194
|
+
}
|
|
5195
|
+
else {
|
|
5196
|
+
throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
|
|
5197
|
+
}
|
|
5198
|
+
}
|
|
5199
|
+
else {
|
|
5200
|
+
params.push(evaluateNode(paramNode, contextStack));
|
|
5201
|
+
}
|
|
5202
|
+
});
|
|
5079
5203
|
if (isNormalExpressionNodeWithName(node)) {
|
|
5080
5204
|
var nameSymbol = node[1][0];
|
|
5081
5205
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
@@ -5177,19 +5301,19 @@ var Lits = (function (exports) {
|
|
|
5177
5301
|
var contexts = [{}, context];
|
|
5178
5302
|
return new ContextStackImpl({ contexts: contexts });
|
|
5179
5303
|
};
|
|
5180
|
-
ContextStackImpl.prototype.exportValues = function (values) {
|
|
5304
|
+
ContextStackImpl.prototype.exportValues = function (values, sourceCodeInfo) {
|
|
5181
5305
|
var e_1, _a;
|
|
5182
5306
|
try {
|
|
5183
5307
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5184
5308
|
var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
|
|
5185
5309
|
if (this.globalContext[name_1]) {
|
|
5186
|
-
throw new
|
|
5310
|
+
throw new LitsError("Cannot redefine exported value \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5187
5311
|
}
|
|
5188
5312
|
if (specialExpressionKeys.includes(name_1)) {
|
|
5189
|
-
throw new
|
|
5313
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5190
5314
|
}
|
|
5191
5315
|
if (normalExpressionKeys.includes(name_1)) {
|
|
5192
|
-
throw new
|
|
5316
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5193
5317
|
}
|
|
5194
5318
|
this.globalContext[name_1] = { value: value };
|
|
5195
5319
|
}
|
|
@@ -5201,22 +5325,22 @@ var Lits = (function (exports) {
|
|
|
5201
5325
|
}
|
|
5202
5326
|
finally { if (e_1) throw e_1.error; }
|
|
5203
5327
|
}
|
|
5204
|
-
this.addValues(values);
|
|
5328
|
+
this.addValues(values, sourceCodeInfo);
|
|
5205
5329
|
};
|
|
5206
|
-
ContextStackImpl.prototype.addValues = function (values) {
|
|
5330
|
+
ContextStackImpl.prototype.addValues = function (values, sourceCodeInfo) {
|
|
5207
5331
|
var e_2, _a;
|
|
5208
5332
|
var currentContext = this.contexts[0];
|
|
5209
5333
|
try {
|
|
5210
5334
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5211
5335
|
var _d = __read(_c.value, 2), name_2 = _d[0], value = _d[1];
|
|
5212
5336
|
if (currentContext[name_2]) {
|
|
5213
|
-
throw new
|
|
5337
|
+
throw new LitsError("Cannot redefine value \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5214
5338
|
}
|
|
5215
5339
|
if (specialExpressionKeys.includes(name_2)) {
|
|
5216
|
-
throw new
|
|
5340
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5217
5341
|
}
|
|
5218
5342
|
if (normalExpressionKeys.includes(name_2)) {
|
|
5219
|
-
throw new
|
|
5343
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5220
5344
|
}
|
|
5221
5345
|
currentContext[name_2] = { value: toAny(value) };
|
|
5222
5346
|
}
|
|
@@ -5296,18 +5420,36 @@ var Lits = (function (exports) {
|
|
|
5296
5420
|
return null;
|
|
5297
5421
|
};
|
|
5298
5422
|
ContextStackImpl.prototype.evaluateSymbol = function (node) {
|
|
5299
|
-
var _a;
|
|
5423
|
+
var _a, _b;
|
|
5300
5424
|
if (isSpecialBuiltinSymbolNode(node)) {
|
|
5301
|
-
|
|
5425
|
+
var functionType = node[1];
|
|
5426
|
+
switch (functionType) {
|
|
5427
|
+
case specialExpressionTypes['&&']:
|
|
5428
|
+
case specialExpressionTypes['||']:
|
|
5429
|
+
case specialExpressionTypes.array:
|
|
5430
|
+
case specialExpressionTypes.object:
|
|
5431
|
+
case specialExpressionTypes['defined?']:
|
|
5432
|
+
case specialExpressionTypes.recur:
|
|
5433
|
+
case specialExpressionTypes.throw:
|
|
5434
|
+
case specialExpressionTypes['??']:
|
|
5435
|
+
return _a = {},
|
|
5436
|
+
_a[FUNCTION_SYMBOL] = true,
|
|
5437
|
+
_a.functionType = 'SpecialBuiltin',
|
|
5438
|
+
_a.specialBuiltinSymbolType = functionType,
|
|
5439
|
+
_a.sourceCodeInfo = node[2],
|
|
5440
|
+
_a;
|
|
5441
|
+
default:
|
|
5442
|
+
throw new LitsError("Unknown special builtin symbol type: ".concat(functionType), node[2]);
|
|
5443
|
+
}
|
|
5302
5444
|
}
|
|
5303
5445
|
if (isNormalBuiltinSymbolNode(node)) {
|
|
5304
5446
|
var type = node[1];
|
|
5305
|
-
return
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5447
|
+
return _b = {},
|
|
5448
|
+
_b[FUNCTION_SYMBOL] = true,
|
|
5449
|
+
_b.functionType = 'Builtin',
|
|
5450
|
+
_b.normalBuitinSymbolType = type,
|
|
5451
|
+
_b.sourceCodeInfo = node[2],
|
|
5452
|
+
_b;
|
|
5311
5453
|
}
|
|
5312
5454
|
var lookUpResult = this.lookUp(node);
|
|
5313
5455
|
if (isContextEntry(lookUpResult))
|
|
@@ -5979,7 +6121,7 @@ var Lits = (function (exports) {
|
|
|
5979
6121
|
}
|
|
5980
6122
|
return node;
|
|
5981
6123
|
}
|
|
5982
|
-
function getPrecedence(operatorSign) {
|
|
6124
|
+
function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
5983
6125
|
switch (operatorSign) {
|
|
5984
6126
|
case '**': // exponentiation
|
|
5985
6127
|
return exponentiationPrecedence;
|
|
@@ -6018,7 +6160,7 @@ var Lits = (function (exports) {
|
|
|
6018
6160
|
// leave room for binaryFunctionalOperatorPrecedence = 1
|
|
6019
6161
|
/* v8 ignore next 2 */
|
|
6020
6162
|
default:
|
|
6021
|
-
throw new
|
|
6163
|
+
throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
|
|
6022
6164
|
}
|
|
6023
6165
|
}
|
|
6024
6166
|
function createNamedNormalExpressionNode(symbolNode, params, sourceCodeInfo) {
|
|
@@ -6151,7 +6293,7 @@ var Lits = (function (exports) {
|
|
|
6151
6293
|
while (!this.isAtExpressionEnd()) {
|
|
6152
6294
|
if (isA_BinaryOperatorToken(operator)) {
|
|
6153
6295
|
var name_1 = operator[1];
|
|
6154
|
-
var newPrecedece = getPrecedence(name_1);
|
|
6296
|
+
var newPrecedece = getPrecedence(name_1, operator[2]);
|
|
6155
6297
|
if (newPrecedece <= precedence
|
|
6156
6298
|
// ** (exponentiation) is right associative
|
|
6157
6299
|
&& !(newPrecedece === exponentiationPrecedence && precedence === exponentiationPrecedence)) {
|
|
@@ -6231,7 +6373,7 @@ var Lits = (function (exports) {
|
|
|
6231
6373
|
this.advance();
|
|
6232
6374
|
var expression = this.parseExpression();
|
|
6233
6375
|
if (!isRParenToken(this.peek())) {
|
|
6234
|
-
throw new
|
|
6376
|
+
throw new LitsError('Expected closing parenthesis', this.peek()[2]);
|
|
6235
6377
|
}
|
|
6236
6378
|
this.advance();
|
|
6237
6379
|
return expression;
|
|
@@ -6353,7 +6495,13 @@ var Lits = (function (exports) {
|
|
|
6353
6495
|
this.advance();
|
|
6354
6496
|
var params = [];
|
|
6355
6497
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
6356
|
-
|
|
6498
|
+
if (isOperatorToken(this.peek(), '...')) {
|
|
6499
|
+
this.advance();
|
|
6500
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peek()[2]));
|
|
6501
|
+
}
|
|
6502
|
+
else {
|
|
6503
|
+
params.push(this.parseExpression());
|
|
6504
|
+
}
|
|
6357
6505
|
var nextToken = this.peek();
|
|
6358
6506
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
6359
6507
|
throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
|
|
@@ -6409,7 +6557,7 @@ var Lits = (function (exports) {
|
|
|
6409
6557
|
throw new LitsError("".concat(type, " is not allowed"), symbol[2]);
|
|
6410
6558
|
/* v8 ignore next 2 */
|
|
6411
6559
|
default:
|
|
6412
|
-
throw new
|
|
6560
|
+
throw new LitsError("Unknown special expression: ".concat(type), symbol[2]);
|
|
6413
6561
|
}
|
|
6414
6562
|
}
|
|
6415
6563
|
else if (isNormalBuiltinSymbolNode(symbol) || isNormalBuiltinSymbolNode(symbol)) {
|
|
@@ -11167,19 +11315,23 @@ var Lits = (function (exports) {
|
|
|
11167
11315
|
type: 'any',
|
|
11168
11316
|
rest: true,
|
|
11169
11317
|
},
|
|
11170
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), {
|
|
11318
|
+
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { seqs: {
|
|
11171
11319
|
type: 'sequence',
|
|
11320
|
+
rest: true,
|
|
11321
|
+
description: 'At least one.',
|
|
11172
11322
|
}, fun: {
|
|
11173
11323
|
type: 'function',
|
|
11174
11324
|
} }),
|
|
11175
11325
|
variants: [
|
|
11176
|
-
{ argumentNames: ['
|
|
11326
|
+
{ argumentNames: ['seqs', 'fun'] },
|
|
11177
11327
|
],
|
|
11178
|
-
description: 'Creates a new array populated with the results of calling $fun on every
|
|
11328
|
+
description: 'Creates a new array populated with the results of calling $fun on every element in $seqs.',
|
|
11179
11329
|
examples: [
|
|
11330
|
+
'[1, 2, 3] map -',
|
|
11180
11331
|
'[1, 2, 3] map -> -($)',
|
|
11181
11332
|
'map(["Albert", "Mojir", 42], str)',
|
|
11182
11333
|
'map([1, 2, 3], inc)',
|
|
11334
|
+
'map([1, 2, 3], [1, 10, 100], *)',
|
|
11183
11335
|
],
|
|
11184
11336
|
},
|
|
11185
11337
|
'filter': {
|