@mojir/lits 2.1.2 → 2.1.3
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 +174 -37
- 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 +173 -36
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +173 -36
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +173 -36
- 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 +173 -36
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +173 -36
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -93,9 +93,15 @@ function getCodeMarker(sourceCodeInfo) {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
function getLitsErrorMessage(message, sourceCodeInfo) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
if (!sourceCodeInfo) {
|
|
97
|
+
return message;
|
|
98
|
+
}
|
|
99
|
+
var location = "".concat(sourceCodeInfo.position.line, ":").concat(sourceCodeInfo.position.column);
|
|
100
|
+
var filePathLine = sourceCodeInfo.filePath
|
|
101
|
+
? "\n".concat(sourceCodeInfo.filePath, ":").concat(location)
|
|
102
|
+
: "\nLocation ".concat(location);
|
|
103
|
+
var codeLine = "\n".concat(sourceCodeInfo.code);
|
|
104
|
+
var codeMarker = "\n".concat(getCodeMarker(sourceCodeInfo));
|
|
99
105
|
return "".concat(message).concat(filePathLine).concat(codeLine).concat(codeMarker);
|
|
100
106
|
}
|
|
101
107
|
var RecurSignal = /** @class */ (function (_super) {
|
|
@@ -208,6 +214,7 @@ var functionTypes = [
|
|
|
208
214
|
'SomePred',
|
|
209
215
|
'Fnull',
|
|
210
216
|
'Builtin',
|
|
217
|
+
'SpecialBuiltin',
|
|
211
218
|
'NativeJsFunction',
|
|
212
219
|
];
|
|
213
220
|
var functionTypeSet = new Set(functionTypes);
|
|
@@ -3669,6 +3676,26 @@ var andSpecialExpression = {
|
|
|
3669
3676
|
}
|
|
3670
3677
|
return value;
|
|
3671
3678
|
},
|
|
3679
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
3680
|
+
var e_2, _a;
|
|
3681
|
+
var value = true;
|
|
3682
|
+
try {
|
|
3683
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
3684
|
+
var param = params_1_1.value;
|
|
3685
|
+
value = asAny(param, sourceCodeInfo);
|
|
3686
|
+
if (!value)
|
|
3687
|
+
break;
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3690
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3691
|
+
finally {
|
|
3692
|
+
try {
|
|
3693
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
3694
|
+
}
|
|
3695
|
+
finally { if (e_2) throw e_2.error; }
|
|
3696
|
+
}
|
|
3697
|
+
return value;
|
|
3698
|
+
},
|
|
3672
3699
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
3673
3700
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
3674
3701
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -3953,7 +3980,7 @@ var defSpecialExpression = {
|
|
|
3953
3980
|
var value = bindingNode[1][1];
|
|
3954
3981
|
var bindingValue = evaluateNode(value, contextStack);
|
|
3955
3982
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
3956
|
-
contextStack.exportValues(values);
|
|
3983
|
+
contextStack.exportValues(values, target[2]);
|
|
3957
3984
|
return null;
|
|
3958
3985
|
},
|
|
3959
3986
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -3965,7 +3992,7 @@ var defSpecialExpression = {
|
|
|
3965
3992
|
walkDefaults(target, function (defaultNode) {
|
|
3966
3993
|
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
3967
3994
|
});
|
|
3968
|
-
contextStack.addValues(getAllBindingTargetNames(target));
|
|
3995
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
3969
3996
|
return bindingResult;
|
|
3970
3997
|
},
|
|
3971
3998
|
};
|
|
@@ -4108,14 +4135,14 @@ var functionSpecialExpression = {
|
|
|
4108
4135
|
_b.name = functionSymbol[1],
|
|
4109
4136
|
_b.evaluatedfunction = evaluatedFunction,
|
|
4110
4137
|
_b);
|
|
4111
|
-
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4138
|
+
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4112
4139
|
return null;
|
|
4113
4140
|
},
|
|
4114
4141
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4115
4142
|
var _b, _c;
|
|
4116
4143
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4117
4144
|
var functionName = node[1][1][1];
|
|
4118
|
-
contextStack.addValues((_b = {}, _b[functionName] = true, _b));
|
|
4145
|
+
contextStack.addValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4119
4146
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4120
4147
|
return getFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4121
4148
|
},
|
|
@@ -4136,7 +4163,7 @@ var defnSpecialExpression = {
|
|
|
4136
4163
|
_b.name = functionSymbol[1],
|
|
4137
4164
|
_b.evaluatedfunction = evaluatedFunctionOverloades,
|
|
4138
4165
|
_b);
|
|
4139
|
-
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4166
|
+
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4140
4167
|
return null;
|
|
4141
4168
|
},
|
|
4142
4169
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4144,7 +4171,7 @@ var defnSpecialExpression = {
|
|
|
4144
4171
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4145
4172
|
var functionName = node[1][1][1];
|
|
4146
4173
|
var fn = node[1][2];
|
|
4147
|
-
contextStack.exportValues((_b = {}, _b[functionName] = true, _b));
|
|
4174
|
+
contextStack.exportValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4148
4175
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4149
4176
|
return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4150
4177
|
},
|
|
@@ -4256,7 +4283,7 @@ var letSpecialExpression = {
|
|
|
4256
4283
|
var value = bindingNode[1][1];
|
|
4257
4284
|
var bindingValue = evaluateNode(value, contextStack);
|
|
4258
4285
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
4259
|
-
contextStack.addValues(values);
|
|
4286
|
+
contextStack.addValues(values, target[2]);
|
|
4260
4287
|
return null;
|
|
4261
4288
|
},
|
|
4262
4289
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4268,7 +4295,7 @@ var letSpecialExpression = {
|
|
|
4268
4295
|
walkDefaults(target, function (defaultNode) {
|
|
4269
4296
|
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
4270
4297
|
});
|
|
4271
|
-
contextStack.addValues(getAllBindingTargetNames(target));
|
|
4298
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
4272
4299
|
return bindingResult;
|
|
4273
4300
|
},
|
|
4274
4301
|
};
|
|
@@ -4539,6 +4566,26 @@ var orSpecialExpression = {
|
|
|
4539
4566
|
}
|
|
4540
4567
|
return value;
|
|
4541
4568
|
},
|
|
4569
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4570
|
+
var e_2, _a;
|
|
4571
|
+
var value = false;
|
|
4572
|
+
try {
|
|
4573
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4574
|
+
var param = params_1_1.value;
|
|
4575
|
+
value = asAny(param, sourceCodeInfo);
|
|
4576
|
+
if (value)
|
|
4577
|
+
break;
|
|
4578
|
+
}
|
|
4579
|
+
}
|
|
4580
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4581
|
+
finally {
|
|
4582
|
+
try {
|
|
4583
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4584
|
+
}
|
|
4585
|
+
finally { if (e_2) throw e_2.error; }
|
|
4586
|
+
}
|
|
4587
|
+
return value;
|
|
4588
|
+
},
|
|
4542
4589
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4543
4590
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4544
4591
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4557,6 +4604,11 @@ var qqSpecialExpression = {
|
|
|
4557
4604
|
var firstResult = evaluateNode(firstNode, contextStack);
|
|
4558
4605
|
return firstResult !== null && firstResult !== void 0 ? firstResult : (secondNode ? evaluateNode(secondNode, contextStack) : null);
|
|
4559
4606
|
},
|
|
4607
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4608
|
+
var firstParam = asAny(params[0], sourceCodeInfo);
|
|
4609
|
+
var secondParam = params[1] !== undefined ? asAny(params[1], sourceCodeInfo) : null;
|
|
4610
|
+
return firstParam !== null && firstParam !== void 0 ? firstParam : secondParam;
|
|
4611
|
+
},
|
|
4560
4612
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4561
4613
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4562
4614
|
return getUndefinedSymbols(node[1][1].filter(function (n) { return !!n; }), contextStack, builtin, evaluateNode);
|
|
@@ -4571,6 +4623,9 @@ var recurSpecialExpression = {
|
|
|
4571
4623
|
var evaluatedParams = params.map(function (paramNode) { return evaluateNode(paramNode, contextStack); });
|
|
4572
4624
|
throw new RecurSignal(evaluatedParams);
|
|
4573
4625
|
},
|
|
4626
|
+
evaluateAsNormalExpression: function (params) {
|
|
4627
|
+
throw new RecurSignal(params);
|
|
4628
|
+
},
|
|
4574
4629
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4575
4630
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4576
4631
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4586,6 +4641,12 @@ var throwSpecialExpression = {
|
|
|
4586
4641
|
});
|
|
4587
4642
|
throw new UserDefinedError(message, node[2]);
|
|
4588
4643
|
},
|
|
4644
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4645
|
+
var message = asString(params[0], sourceCodeInfo, {
|
|
4646
|
+
nonEmpty: true,
|
|
4647
|
+
});
|
|
4648
|
+
throw new UserDefinedError(message, undefined);
|
|
4649
|
+
},
|
|
4589
4650
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4590
4651
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4591
4652
|
return getUndefinedSymbols([node[1][1]], contextStack, builtin, evaluateNode);
|
|
@@ -4653,6 +4714,24 @@ var arraySpecialExpression = {
|
|
|
4653
4714
|
}
|
|
4654
4715
|
return result;
|
|
4655
4716
|
},
|
|
4717
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4718
|
+
var e_2, _a;
|
|
4719
|
+
var result = [];
|
|
4720
|
+
try {
|
|
4721
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4722
|
+
var param = params_1_1.value;
|
|
4723
|
+
result.push(asAny(param, sourceCodeInfo));
|
|
4724
|
+
}
|
|
4725
|
+
}
|
|
4726
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4727
|
+
finally {
|
|
4728
|
+
try {
|
|
4729
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4730
|
+
}
|
|
4731
|
+
finally { if (e_2) throw e_2.error; }
|
|
4732
|
+
}
|
|
4733
|
+
return result;
|
|
4734
|
+
},
|
|
4656
4735
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4657
4736
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4658
4737
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4684,6 +4763,16 @@ var objectSpecialExpression = {
|
|
|
4684
4763
|
}
|
|
4685
4764
|
return result;
|
|
4686
4765
|
},
|
|
4766
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4767
|
+
var result = {};
|
|
4768
|
+
for (var i = 0; i < params.length; i += 2) {
|
|
4769
|
+
var key = params[i];
|
|
4770
|
+
var value = params[i + 1];
|
|
4771
|
+
assertString(key, sourceCodeInfo);
|
|
4772
|
+
result[key] = value !== null && value !== void 0 ? value : null;
|
|
4773
|
+
}
|
|
4774
|
+
return result;
|
|
4775
|
+
},
|
|
4687
4776
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4688
4777
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4689
4778
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4809,7 +4898,7 @@ function findUnresolvedSymbolsInNode(node, contextStack, builtin, evaluateNode)
|
|
|
4809
4898
|
return findUnresolvedSymbolsInNode(node[1], contextStack, builtin, evaluateNode);
|
|
4810
4899
|
/* v8 ignore next 2 */
|
|
4811
4900
|
default:
|
|
4812
|
-
throw new
|
|
4901
|
+
throw new LitsError("Unhandled node type: ".concat(nodeType), node[2]);
|
|
4813
4902
|
}
|
|
4814
4903
|
}
|
|
4815
4904
|
|
|
@@ -5017,6 +5106,16 @@ var functionExecutors = {
|
|
|
5017
5106
|
var normalExpression = asNonUndefined(allNormalExpressions[fn.normalBuitinSymbolType], sourceCodeInfo);
|
|
5018
5107
|
return normalExpression.evaluate(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
5019
5108
|
},
|
|
5109
|
+
SpecialBuiltin: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
5110
|
+
var executeFunction = _a.executeFunction;
|
|
5111
|
+
var specialExpression = asNonUndefined(specialExpressions[fn.specialBuiltinSymbolType], sourceCodeInfo);
|
|
5112
|
+
if (specialExpression.evaluateAsNormalExpression) {
|
|
5113
|
+
return specialExpression.evaluateAsNormalExpression(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
5114
|
+
}
|
|
5115
|
+
else {
|
|
5116
|
+
throw new LitsError("Special builtin function ".concat(fn.specialBuiltinSymbolType, " is not supported as normal expression."), sourceCodeInfo);
|
|
5117
|
+
}
|
|
5118
|
+
},
|
|
5020
5119
|
};
|
|
5021
5120
|
|
|
5022
5121
|
function evaluate(ast, contextStack) {
|
|
@@ -5072,7 +5171,21 @@ function evaluateReservedSymbol(node) {
|
|
|
5072
5171
|
function evaluateNormalExpression(node, contextStack) {
|
|
5073
5172
|
var sourceCodeInfo = node[2];
|
|
5074
5173
|
var paramNodes = node[1][1];
|
|
5075
|
-
var params =
|
|
5174
|
+
var params = [];
|
|
5175
|
+
paramNodes.forEach(function (paramNode) {
|
|
5176
|
+
if (isSpreadNode(paramNode)) {
|
|
5177
|
+
var spreadValue = evaluateNode(paramNode[1], contextStack);
|
|
5178
|
+
if (Array.isArray(spreadValue)) {
|
|
5179
|
+
params.push.apply(params, __spreadArray([], __read(spreadValue), false));
|
|
5180
|
+
}
|
|
5181
|
+
else {
|
|
5182
|
+
throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
|
|
5183
|
+
}
|
|
5184
|
+
}
|
|
5185
|
+
else {
|
|
5186
|
+
params.push(evaluateNode(paramNode, contextStack));
|
|
5187
|
+
}
|
|
5188
|
+
});
|
|
5076
5189
|
if (isNormalExpressionNodeWithName(node)) {
|
|
5077
5190
|
var nameSymbol = node[1][0];
|
|
5078
5191
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
@@ -5174,19 +5287,19 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5174
5287
|
var contexts = [{}, context];
|
|
5175
5288
|
return new ContextStackImpl({ contexts: contexts });
|
|
5176
5289
|
};
|
|
5177
|
-
ContextStackImpl.prototype.exportValues = function (values) {
|
|
5290
|
+
ContextStackImpl.prototype.exportValues = function (values, sourceCodeInfo) {
|
|
5178
5291
|
var e_1, _a;
|
|
5179
5292
|
try {
|
|
5180
5293
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5181
5294
|
var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
|
|
5182
5295
|
if (this.globalContext[name_1]) {
|
|
5183
|
-
throw new
|
|
5296
|
+
throw new LitsError("Cannot redefine exported value \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5184
5297
|
}
|
|
5185
5298
|
if (specialExpressionKeys.includes(name_1)) {
|
|
5186
|
-
throw new
|
|
5299
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5187
5300
|
}
|
|
5188
5301
|
if (normalExpressionKeys.includes(name_1)) {
|
|
5189
|
-
throw new
|
|
5302
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5190
5303
|
}
|
|
5191
5304
|
this.globalContext[name_1] = { value: value };
|
|
5192
5305
|
}
|
|
@@ -5198,22 +5311,22 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5198
5311
|
}
|
|
5199
5312
|
finally { if (e_1) throw e_1.error; }
|
|
5200
5313
|
}
|
|
5201
|
-
this.addValues(values);
|
|
5314
|
+
this.addValues(values, sourceCodeInfo);
|
|
5202
5315
|
};
|
|
5203
|
-
ContextStackImpl.prototype.addValues = function (values) {
|
|
5316
|
+
ContextStackImpl.prototype.addValues = function (values, sourceCodeInfo) {
|
|
5204
5317
|
var e_2, _a;
|
|
5205
5318
|
var currentContext = this.contexts[0];
|
|
5206
5319
|
try {
|
|
5207
5320
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5208
5321
|
var _d = __read(_c.value, 2), name_2 = _d[0], value = _d[1];
|
|
5209
5322
|
if (currentContext[name_2]) {
|
|
5210
|
-
throw new
|
|
5323
|
+
throw new LitsError("Cannot redefine value \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5211
5324
|
}
|
|
5212
5325
|
if (specialExpressionKeys.includes(name_2)) {
|
|
5213
|
-
throw new
|
|
5326
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5214
5327
|
}
|
|
5215
5328
|
if (normalExpressionKeys.includes(name_2)) {
|
|
5216
|
-
throw new
|
|
5329
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5217
5330
|
}
|
|
5218
5331
|
currentContext[name_2] = { value: toAny(value) };
|
|
5219
5332
|
}
|
|
@@ -5293,18 +5406,36 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5293
5406
|
return null;
|
|
5294
5407
|
};
|
|
5295
5408
|
ContextStackImpl.prototype.evaluateSymbol = function (node) {
|
|
5296
|
-
var _a;
|
|
5409
|
+
var _a, _b;
|
|
5297
5410
|
if (isSpecialBuiltinSymbolNode(node)) {
|
|
5298
|
-
|
|
5411
|
+
var functionType = node[1];
|
|
5412
|
+
switch (functionType) {
|
|
5413
|
+
case specialExpressionTypes['&&']:
|
|
5414
|
+
case specialExpressionTypes['||']:
|
|
5415
|
+
case specialExpressionTypes.array:
|
|
5416
|
+
case specialExpressionTypes.object:
|
|
5417
|
+
case specialExpressionTypes['defined?']:
|
|
5418
|
+
case specialExpressionTypes.recur:
|
|
5419
|
+
case specialExpressionTypes.throw:
|
|
5420
|
+
case specialExpressionTypes['??']:
|
|
5421
|
+
return _a = {},
|
|
5422
|
+
_a[FUNCTION_SYMBOL] = true,
|
|
5423
|
+
_a.functionType = 'SpecialBuiltin',
|
|
5424
|
+
_a.specialBuiltinSymbolType = functionType,
|
|
5425
|
+
_a.sourceCodeInfo = node[2],
|
|
5426
|
+
_a;
|
|
5427
|
+
default:
|
|
5428
|
+
throw new LitsError("Unknown special builtin symbol type: ".concat(functionType), node[2]);
|
|
5429
|
+
}
|
|
5299
5430
|
}
|
|
5300
5431
|
if (isNormalBuiltinSymbolNode(node)) {
|
|
5301
5432
|
var type = node[1];
|
|
5302
|
-
return
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5433
|
+
return _b = {},
|
|
5434
|
+
_b[FUNCTION_SYMBOL] = true,
|
|
5435
|
+
_b.functionType = 'Builtin',
|
|
5436
|
+
_b.normalBuitinSymbolType = type,
|
|
5437
|
+
_b.sourceCodeInfo = node[2],
|
|
5438
|
+
_b;
|
|
5308
5439
|
}
|
|
5309
5440
|
var lookUpResult = this.lookUp(node);
|
|
5310
5441
|
if (isContextEntry(lookUpResult))
|
|
@@ -5976,7 +6107,7 @@ function withSourceCodeInfo(node, sourceCodeInfo) {
|
|
|
5976
6107
|
}
|
|
5977
6108
|
return node;
|
|
5978
6109
|
}
|
|
5979
|
-
function getPrecedence(operatorSign) {
|
|
6110
|
+
function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
5980
6111
|
switch (operatorSign) {
|
|
5981
6112
|
case '**': // exponentiation
|
|
5982
6113
|
return exponentiationPrecedence;
|
|
@@ -6015,7 +6146,7 @@ function getPrecedence(operatorSign) {
|
|
|
6015
6146
|
// leave room for binaryFunctionalOperatorPrecedence = 1
|
|
6016
6147
|
/* v8 ignore next 2 */
|
|
6017
6148
|
default:
|
|
6018
|
-
throw new
|
|
6149
|
+
throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
|
|
6019
6150
|
}
|
|
6020
6151
|
}
|
|
6021
6152
|
function createNamedNormalExpressionNode(symbolNode, params, sourceCodeInfo) {
|
|
@@ -6148,7 +6279,7 @@ var Parser = /** @class */ (function () {
|
|
|
6148
6279
|
while (!this.isAtExpressionEnd()) {
|
|
6149
6280
|
if (isA_BinaryOperatorToken(operator)) {
|
|
6150
6281
|
var name_1 = operator[1];
|
|
6151
|
-
var newPrecedece = getPrecedence(name_1);
|
|
6282
|
+
var newPrecedece = getPrecedence(name_1, operator[2]);
|
|
6152
6283
|
if (newPrecedece <= precedence
|
|
6153
6284
|
// ** (exponentiation) is right associative
|
|
6154
6285
|
&& !(newPrecedece === exponentiationPrecedence && precedence === exponentiationPrecedence)) {
|
|
@@ -6228,7 +6359,7 @@ var Parser = /** @class */ (function () {
|
|
|
6228
6359
|
this.advance();
|
|
6229
6360
|
var expression = this.parseExpression();
|
|
6230
6361
|
if (!isRParenToken(this.peek())) {
|
|
6231
|
-
throw new
|
|
6362
|
+
throw new LitsError('Expected closing parenthesis', this.peek()[2]);
|
|
6232
6363
|
}
|
|
6233
6364
|
this.advance();
|
|
6234
6365
|
return expression;
|
|
@@ -6350,7 +6481,13 @@ var Parser = /** @class */ (function () {
|
|
|
6350
6481
|
this.advance();
|
|
6351
6482
|
var params = [];
|
|
6352
6483
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
6353
|
-
|
|
6484
|
+
if (isOperatorToken(this.peek(), '...')) {
|
|
6485
|
+
this.advance();
|
|
6486
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peek()[2]));
|
|
6487
|
+
}
|
|
6488
|
+
else {
|
|
6489
|
+
params.push(this.parseExpression());
|
|
6490
|
+
}
|
|
6354
6491
|
var nextToken = this.peek();
|
|
6355
6492
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
6356
6493
|
throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
|
|
@@ -6406,7 +6543,7 @@ var Parser = /** @class */ (function () {
|
|
|
6406
6543
|
throw new LitsError("".concat(type, " is not allowed"), symbol[2]);
|
|
6407
6544
|
/* v8 ignore next 2 */
|
|
6408
6545
|
default:
|
|
6409
|
-
throw new
|
|
6546
|
+
throw new LitsError("Unknown special expression: ".concat(type), symbol[2]);
|
|
6410
6547
|
}
|
|
6411
6548
|
}
|
|
6412
6549
|
else if (isNormalBuiltinSymbolNode(symbol) || isNormalBuiltinSymbolNode(symbol)) {
|