@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/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);
|
|
@@ -3672,6 +3679,26 @@ var Lits = (function (exports) {
|
|
|
3672
3679
|
}
|
|
3673
3680
|
return value;
|
|
3674
3681
|
},
|
|
3682
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
3683
|
+
var e_2, _a;
|
|
3684
|
+
var value = true;
|
|
3685
|
+
try {
|
|
3686
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
3687
|
+
var param = params_1_1.value;
|
|
3688
|
+
value = asAny(param, sourceCodeInfo);
|
|
3689
|
+
if (!value)
|
|
3690
|
+
break;
|
|
3691
|
+
}
|
|
3692
|
+
}
|
|
3693
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3694
|
+
finally {
|
|
3695
|
+
try {
|
|
3696
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
3697
|
+
}
|
|
3698
|
+
finally { if (e_2) throw e_2.error; }
|
|
3699
|
+
}
|
|
3700
|
+
return value;
|
|
3701
|
+
},
|
|
3675
3702
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
3676
3703
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
3677
3704
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -3956,7 +3983,7 @@ var Lits = (function (exports) {
|
|
|
3956
3983
|
var value = bindingNode[1][1];
|
|
3957
3984
|
var bindingValue = evaluateNode(value, contextStack);
|
|
3958
3985
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
3959
|
-
contextStack.exportValues(values);
|
|
3986
|
+
contextStack.exportValues(values, target[2]);
|
|
3960
3987
|
return null;
|
|
3961
3988
|
},
|
|
3962
3989
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -3968,7 +3995,7 @@ var Lits = (function (exports) {
|
|
|
3968
3995
|
walkDefaults(target, function (defaultNode) {
|
|
3969
3996
|
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
3970
3997
|
});
|
|
3971
|
-
contextStack.addValues(getAllBindingTargetNames(target));
|
|
3998
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
3972
3999
|
return bindingResult;
|
|
3973
4000
|
},
|
|
3974
4001
|
};
|
|
@@ -4111,14 +4138,14 @@ var Lits = (function (exports) {
|
|
|
4111
4138
|
_b.name = functionSymbol[1],
|
|
4112
4139
|
_b.evaluatedfunction = evaluatedFunction,
|
|
4113
4140
|
_b);
|
|
4114
|
-
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4141
|
+
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4115
4142
|
return null;
|
|
4116
4143
|
},
|
|
4117
4144
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4118
4145
|
var _b, _c;
|
|
4119
4146
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4120
4147
|
var functionName = node[1][1][1];
|
|
4121
|
-
contextStack.addValues((_b = {}, _b[functionName] = true, _b));
|
|
4148
|
+
contextStack.addValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4122
4149
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4123
4150
|
return getFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4124
4151
|
},
|
|
@@ -4139,7 +4166,7 @@ var Lits = (function (exports) {
|
|
|
4139
4166
|
_b.name = functionSymbol[1],
|
|
4140
4167
|
_b.evaluatedfunction = evaluatedFunctionOverloades,
|
|
4141
4168
|
_b);
|
|
4142
|
-
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4169
|
+
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4143
4170
|
return null;
|
|
4144
4171
|
},
|
|
4145
4172
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4147,7 +4174,7 @@ var Lits = (function (exports) {
|
|
|
4147
4174
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4148
4175
|
var functionName = node[1][1][1];
|
|
4149
4176
|
var fn = node[1][2];
|
|
4150
|
-
contextStack.exportValues((_b = {}, _b[functionName] = true, _b));
|
|
4177
|
+
contextStack.exportValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4151
4178
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4152
4179
|
return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4153
4180
|
},
|
|
@@ -4259,7 +4286,7 @@ var Lits = (function (exports) {
|
|
|
4259
4286
|
var value = bindingNode[1][1];
|
|
4260
4287
|
var bindingValue = evaluateNode(value, contextStack);
|
|
4261
4288
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
4262
|
-
contextStack.addValues(values);
|
|
4289
|
+
contextStack.addValues(values, target[2]);
|
|
4263
4290
|
return null;
|
|
4264
4291
|
},
|
|
4265
4292
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4271,7 +4298,7 @@ var Lits = (function (exports) {
|
|
|
4271
4298
|
walkDefaults(target, function (defaultNode) {
|
|
4272
4299
|
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
4273
4300
|
});
|
|
4274
|
-
contextStack.addValues(getAllBindingTargetNames(target));
|
|
4301
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
4275
4302
|
return bindingResult;
|
|
4276
4303
|
},
|
|
4277
4304
|
};
|
|
@@ -4542,6 +4569,26 @@ var Lits = (function (exports) {
|
|
|
4542
4569
|
}
|
|
4543
4570
|
return value;
|
|
4544
4571
|
},
|
|
4572
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4573
|
+
var e_2, _a;
|
|
4574
|
+
var value = false;
|
|
4575
|
+
try {
|
|
4576
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4577
|
+
var param = params_1_1.value;
|
|
4578
|
+
value = asAny(param, sourceCodeInfo);
|
|
4579
|
+
if (value)
|
|
4580
|
+
break;
|
|
4581
|
+
}
|
|
4582
|
+
}
|
|
4583
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4584
|
+
finally {
|
|
4585
|
+
try {
|
|
4586
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4587
|
+
}
|
|
4588
|
+
finally { if (e_2) throw e_2.error; }
|
|
4589
|
+
}
|
|
4590
|
+
return value;
|
|
4591
|
+
},
|
|
4545
4592
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4546
4593
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4547
4594
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4560,6 +4607,11 @@ var Lits = (function (exports) {
|
|
|
4560
4607
|
var firstResult = evaluateNode(firstNode, contextStack);
|
|
4561
4608
|
return firstResult !== null && firstResult !== void 0 ? firstResult : (secondNode ? evaluateNode(secondNode, contextStack) : null);
|
|
4562
4609
|
},
|
|
4610
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4611
|
+
var firstParam = asAny(params[0], sourceCodeInfo);
|
|
4612
|
+
var secondParam = params[1] !== undefined ? asAny(params[1], sourceCodeInfo) : null;
|
|
4613
|
+
return firstParam !== null && firstParam !== void 0 ? firstParam : secondParam;
|
|
4614
|
+
},
|
|
4563
4615
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4564
4616
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4565
4617
|
return getUndefinedSymbols(node[1][1].filter(function (n) { return !!n; }), contextStack, builtin, evaluateNode);
|
|
@@ -4574,6 +4626,9 @@ var Lits = (function (exports) {
|
|
|
4574
4626
|
var evaluatedParams = params.map(function (paramNode) { return evaluateNode(paramNode, contextStack); });
|
|
4575
4627
|
throw new RecurSignal(evaluatedParams);
|
|
4576
4628
|
},
|
|
4629
|
+
evaluateAsNormalExpression: function (params) {
|
|
4630
|
+
throw new RecurSignal(params);
|
|
4631
|
+
},
|
|
4577
4632
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4578
4633
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4579
4634
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4589,6 +4644,12 @@ var Lits = (function (exports) {
|
|
|
4589
4644
|
});
|
|
4590
4645
|
throw new UserDefinedError(message, node[2]);
|
|
4591
4646
|
},
|
|
4647
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4648
|
+
var message = asString(params[0], sourceCodeInfo, {
|
|
4649
|
+
nonEmpty: true,
|
|
4650
|
+
});
|
|
4651
|
+
throw new UserDefinedError(message, undefined);
|
|
4652
|
+
},
|
|
4592
4653
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4593
4654
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4594
4655
|
return getUndefinedSymbols([node[1][1]], contextStack, builtin, evaluateNode);
|
|
@@ -4656,6 +4717,24 @@ var Lits = (function (exports) {
|
|
|
4656
4717
|
}
|
|
4657
4718
|
return result;
|
|
4658
4719
|
},
|
|
4720
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4721
|
+
var e_2, _a;
|
|
4722
|
+
var result = [];
|
|
4723
|
+
try {
|
|
4724
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4725
|
+
var param = params_1_1.value;
|
|
4726
|
+
result.push(asAny(param, sourceCodeInfo));
|
|
4727
|
+
}
|
|
4728
|
+
}
|
|
4729
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4730
|
+
finally {
|
|
4731
|
+
try {
|
|
4732
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4733
|
+
}
|
|
4734
|
+
finally { if (e_2) throw e_2.error; }
|
|
4735
|
+
}
|
|
4736
|
+
return result;
|
|
4737
|
+
},
|
|
4659
4738
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4660
4739
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4661
4740
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4687,6 +4766,16 @@ var Lits = (function (exports) {
|
|
|
4687
4766
|
}
|
|
4688
4767
|
return result;
|
|
4689
4768
|
},
|
|
4769
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4770
|
+
var result = {};
|
|
4771
|
+
for (var i = 0; i < params.length; i += 2) {
|
|
4772
|
+
var key = params[i];
|
|
4773
|
+
var value = params[i + 1];
|
|
4774
|
+
assertString(key, sourceCodeInfo);
|
|
4775
|
+
result[key] = value !== null && value !== void 0 ? value : null;
|
|
4776
|
+
}
|
|
4777
|
+
return result;
|
|
4778
|
+
},
|
|
4690
4779
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4691
4780
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4692
4781
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4812,7 +4901,7 @@ var Lits = (function (exports) {
|
|
|
4812
4901
|
return findUnresolvedSymbolsInNode(node[1], contextStack, builtin, evaluateNode);
|
|
4813
4902
|
/* v8 ignore next 2 */
|
|
4814
4903
|
default:
|
|
4815
|
-
throw new
|
|
4904
|
+
throw new LitsError("Unhandled node type: ".concat(nodeType), node[2]);
|
|
4816
4905
|
}
|
|
4817
4906
|
}
|
|
4818
4907
|
|
|
@@ -5020,6 +5109,16 @@ var Lits = (function (exports) {
|
|
|
5020
5109
|
var normalExpression = asNonUndefined(allNormalExpressions[fn.normalBuitinSymbolType], sourceCodeInfo);
|
|
5021
5110
|
return normalExpression.evaluate(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
5022
5111
|
},
|
|
5112
|
+
SpecialBuiltin: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
5113
|
+
var executeFunction = _a.executeFunction;
|
|
5114
|
+
var specialExpression = asNonUndefined(specialExpressions[fn.specialBuiltinSymbolType], sourceCodeInfo);
|
|
5115
|
+
if (specialExpression.evaluateAsNormalExpression) {
|
|
5116
|
+
return specialExpression.evaluateAsNormalExpression(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
5117
|
+
}
|
|
5118
|
+
else {
|
|
5119
|
+
throw new LitsError("Special builtin function ".concat(fn.specialBuiltinSymbolType, " is not supported as normal expression."), sourceCodeInfo);
|
|
5120
|
+
}
|
|
5121
|
+
},
|
|
5023
5122
|
};
|
|
5024
5123
|
|
|
5025
5124
|
function evaluate(ast, contextStack) {
|
|
@@ -5075,7 +5174,21 @@ var Lits = (function (exports) {
|
|
|
5075
5174
|
function evaluateNormalExpression(node, contextStack) {
|
|
5076
5175
|
var sourceCodeInfo = node[2];
|
|
5077
5176
|
var paramNodes = node[1][1];
|
|
5078
|
-
var params =
|
|
5177
|
+
var params = [];
|
|
5178
|
+
paramNodes.forEach(function (paramNode) {
|
|
5179
|
+
if (isSpreadNode(paramNode)) {
|
|
5180
|
+
var spreadValue = evaluateNode(paramNode[1], contextStack);
|
|
5181
|
+
if (Array.isArray(spreadValue)) {
|
|
5182
|
+
params.push.apply(params, __spreadArray([], __read(spreadValue), false));
|
|
5183
|
+
}
|
|
5184
|
+
else {
|
|
5185
|
+
throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
|
|
5186
|
+
}
|
|
5187
|
+
}
|
|
5188
|
+
else {
|
|
5189
|
+
params.push(evaluateNode(paramNode, contextStack));
|
|
5190
|
+
}
|
|
5191
|
+
});
|
|
5079
5192
|
if (isNormalExpressionNodeWithName(node)) {
|
|
5080
5193
|
var nameSymbol = node[1][0];
|
|
5081
5194
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
@@ -5177,19 +5290,19 @@ var Lits = (function (exports) {
|
|
|
5177
5290
|
var contexts = [{}, context];
|
|
5178
5291
|
return new ContextStackImpl({ contexts: contexts });
|
|
5179
5292
|
};
|
|
5180
|
-
ContextStackImpl.prototype.exportValues = function (values) {
|
|
5293
|
+
ContextStackImpl.prototype.exportValues = function (values, sourceCodeInfo) {
|
|
5181
5294
|
var e_1, _a;
|
|
5182
5295
|
try {
|
|
5183
5296
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5184
5297
|
var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
|
|
5185
5298
|
if (this.globalContext[name_1]) {
|
|
5186
|
-
throw new
|
|
5299
|
+
throw new LitsError("Cannot redefine exported value \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5187
5300
|
}
|
|
5188
5301
|
if (specialExpressionKeys.includes(name_1)) {
|
|
5189
|
-
throw new
|
|
5302
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5190
5303
|
}
|
|
5191
5304
|
if (normalExpressionKeys.includes(name_1)) {
|
|
5192
|
-
throw new
|
|
5305
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5193
5306
|
}
|
|
5194
5307
|
this.globalContext[name_1] = { value: value };
|
|
5195
5308
|
}
|
|
@@ -5201,22 +5314,22 @@ var Lits = (function (exports) {
|
|
|
5201
5314
|
}
|
|
5202
5315
|
finally { if (e_1) throw e_1.error; }
|
|
5203
5316
|
}
|
|
5204
|
-
this.addValues(values);
|
|
5317
|
+
this.addValues(values, sourceCodeInfo);
|
|
5205
5318
|
};
|
|
5206
|
-
ContextStackImpl.prototype.addValues = function (values) {
|
|
5319
|
+
ContextStackImpl.prototype.addValues = function (values, sourceCodeInfo) {
|
|
5207
5320
|
var e_2, _a;
|
|
5208
5321
|
var currentContext = this.contexts[0];
|
|
5209
5322
|
try {
|
|
5210
5323
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5211
5324
|
var _d = __read(_c.value, 2), name_2 = _d[0], value = _d[1];
|
|
5212
5325
|
if (currentContext[name_2]) {
|
|
5213
|
-
throw new
|
|
5326
|
+
throw new LitsError("Cannot redefine value \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5214
5327
|
}
|
|
5215
5328
|
if (specialExpressionKeys.includes(name_2)) {
|
|
5216
|
-
throw new
|
|
5329
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5217
5330
|
}
|
|
5218
5331
|
if (normalExpressionKeys.includes(name_2)) {
|
|
5219
|
-
throw new
|
|
5332
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5220
5333
|
}
|
|
5221
5334
|
currentContext[name_2] = { value: toAny(value) };
|
|
5222
5335
|
}
|
|
@@ -5296,18 +5409,36 @@ var Lits = (function (exports) {
|
|
|
5296
5409
|
return null;
|
|
5297
5410
|
};
|
|
5298
5411
|
ContextStackImpl.prototype.evaluateSymbol = function (node) {
|
|
5299
|
-
var _a;
|
|
5412
|
+
var _a, _b;
|
|
5300
5413
|
if (isSpecialBuiltinSymbolNode(node)) {
|
|
5301
|
-
|
|
5414
|
+
var functionType = node[1];
|
|
5415
|
+
switch (functionType) {
|
|
5416
|
+
case specialExpressionTypes['&&']:
|
|
5417
|
+
case specialExpressionTypes['||']:
|
|
5418
|
+
case specialExpressionTypes.array:
|
|
5419
|
+
case specialExpressionTypes.object:
|
|
5420
|
+
case specialExpressionTypes['defined?']:
|
|
5421
|
+
case specialExpressionTypes.recur:
|
|
5422
|
+
case specialExpressionTypes.throw:
|
|
5423
|
+
case specialExpressionTypes['??']:
|
|
5424
|
+
return _a = {},
|
|
5425
|
+
_a[FUNCTION_SYMBOL] = true,
|
|
5426
|
+
_a.functionType = 'SpecialBuiltin',
|
|
5427
|
+
_a.specialBuiltinSymbolType = functionType,
|
|
5428
|
+
_a.sourceCodeInfo = node[2],
|
|
5429
|
+
_a;
|
|
5430
|
+
default:
|
|
5431
|
+
throw new LitsError("Unknown special builtin symbol type: ".concat(functionType), node[2]);
|
|
5432
|
+
}
|
|
5302
5433
|
}
|
|
5303
5434
|
if (isNormalBuiltinSymbolNode(node)) {
|
|
5304
5435
|
var type = node[1];
|
|
5305
|
-
return
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5436
|
+
return _b = {},
|
|
5437
|
+
_b[FUNCTION_SYMBOL] = true,
|
|
5438
|
+
_b.functionType = 'Builtin',
|
|
5439
|
+
_b.normalBuitinSymbolType = type,
|
|
5440
|
+
_b.sourceCodeInfo = node[2],
|
|
5441
|
+
_b;
|
|
5311
5442
|
}
|
|
5312
5443
|
var lookUpResult = this.lookUp(node);
|
|
5313
5444
|
if (isContextEntry(lookUpResult))
|
|
@@ -5979,7 +6110,7 @@ var Lits = (function (exports) {
|
|
|
5979
6110
|
}
|
|
5980
6111
|
return node;
|
|
5981
6112
|
}
|
|
5982
|
-
function getPrecedence(operatorSign) {
|
|
6113
|
+
function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
5983
6114
|
switch (operatorSign) {
|
|
5984
6115
|
case '**': // exponentiation
|
|
5985
6116
|
return exponentiationPrecedence;
|
|
@@ -6018,7 +6149,7 @@ var Lits = (function (exports) {
|
|
|
6018
6149
|
// leave room for binaryFunctionalOperatorPrecedence = 1
|
|
6019
6150
|
/* v8 ignore next 2 */
|
|
6020
6151
|
default:
|
|
6021
|
-
throw new
|
|
6152
|
+
throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
|
|
6022
6153
|
}
|
|
6023
6154
|
}
|
|
6024
6155
|
function createNamedNormalExpressionNode(symbolNode, params, sourceCodeInfo) {
|
|
@@ -6151,7 +6282,7 @@ var Lits = (function (exports) {
|
|
|
6151
6282
|
while (!this.isAtExpressionEnd()) {
|
|
6152
6283
|
if (isA_BinaryOperatorToken(operator)) {
|
|
6153
6284
|
var name_1 = operator[1];
|
|
6154
|
-
var newPrecedece = getPrecedence(name_1);
|
|
6285
|
+
var newPrecedece = getPrecedence(name_1, operator[2]);
|
|
6155
6286
|
if (newPrecedece <= precedence
|
|
6156
6287
|
// ** (exponentiation) is right associative
|
|
6157
6288
|
&& !(newPrecedece === exponentiationPrecedence && precedence === exponentiationPrecedence)) {
|
|
@@ -6231,7 +6362,7 @@ var Lits = (function (exports) {
|
|
|
6231
6362
|
this.advance();
|
|
6232
6363
|
var expression = this.parseExpression();
|
|
6233
6364
|
if (!isRParenToken(this.peek())) {
|
|
6234
|
-
throw new
|
|
6365
|
+
throw new LitsError('Expected closing parenthesis', this.peek()[2]);
|
|
6235
6366
|
}
|
|
6236
6367
|
this.advance();
|
|
6237
6368
|
return expression;
|
|
@@ -6353,7 +6484,13 @@ var Lits = (function (exports) {
|
|
|
6353
6484
|
this.advance();
|
|
6354
6485
|
var params = [];
|
|
6355
6486
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
6356
|
-
|
|
6487
|
+
if (isOperatorToken(this.peek(), '...')) {
|
|
6488
|
+
this.advance();
|
|
6489
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peek()[2]));
|
|
6490
|
+
}
|
|
6491
|
+
else {
|
|
6492
|
+
params.push(this.parseExpression());
|
|
6493
|
+
}
|
|
6357
6494
|
var nextToken = this.peek();
|
|
6358
6495
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
6359
6496
|
throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
|
|
@@ -6409,7 +6546,7 @@ var Lits = (function (exports) {
|
|
|
6409
6546
|
throw new LitsError("".concat(type, " is not allowed"), symbol[2]);
|
|
6410
6547
|
/* v8 ignore next 2 */
|
|
6411
6548
|
default:
|
|
6412
|
-
throw new
|
|
6549
|
+
throw new LitsError("Unknown special expression: ".concat(type), symbol[2]);
|
|
6413
6550
|
}
|
|
6414
6551
|
}
|
|
6415
6552
|
else if (isNormalBuiltinSymbolNode(symbol) || isNormalBuiltinSymbolNode(symbol)) {
|