@mojir/lits 2.1.1 → 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 +228 -107
- package/dist/cli/reference/api.d.ts +0 -1
- package/dist/cli/src/builtin/bindingNode.d.ts +1 -0
- package/dist/cli/src/builtin/interface.d.ts +1 -0
- package/dist/cli/src/builtin/specialExpressionTypes.d.ts +3 -5
- package/dist/cli/src/builtin/specialExpressions/def.d.ts +1 -1
- package/dist/cli/src/builtin/specialExpressions/functions.d.ts +2 -2
- 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/cli/src/typeGuards/astNode.d.ts +1 -6
- package/dist/index.esm.js +249 -125
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +249 -125
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +249 -125
- package/dist/lits.iife.js.map +1 -1
- package/dist/reference/api.d.ts +0 -1
- package/dist/src/builtin/bindingNode.d.ts +1 -0
- package/dist/src/builtin/interface.d.ts +1 -0
- package/dist/src/builtin/specialExpressionTypes.d.ts +3 -5
- package/dist/src/builtin/specialExpressions/def.d.ts +1 -1
- package/dist/src/builtin/specialExpressions/functions.d.ts +2 -2
- 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/src/typeGuards/astNode.d.ts +1 -6
- package/dist/testFramework.esm.js +227 -84
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +227 -84
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/cli.js
CHANGED
|
@@ -92,7 +92,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
92
92
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
var version = "2.1.
|
|
95
|
+
var version = "2.1.3";
|
|
96
96
|
|
|
97
97
|
function getCodeMarker(sourceCodeInfo) {
|
|
98
98
|
if (!sourceCodeInfo.position || !sourceCodeInfo.code)
|
|
@@ -103,9 +103,15 @@ function getCodeMarker(sourceCodeInfo) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
function getLitsErrorMessage(message, sourceCodeInfo) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
if (!sourceCodeInfo) {
|
|
107
|
+
return message;
|
|
108
|
+
}
|
|
109
|
+
var location = "".concat(sourceCodeInfo.position.line, ":").concat(sourceCodeInfo.position.column);
|
|
110
|
+
var filePathLine = sourceCodeInfo.filePath
|
|
111
|
+
? "\n".concat(sourceCodeInfo.filePath, ":").concat(location)
|
|
112
|
+
: "\nLocation ".concat(location);
|
|
113
|
+
var codeLine = "\n".concat(sourceCodeInfo.code);
|
|
114
|
+
var codeMarker = "\n".concat(getCodeMarker(sourceCodeInfo));
|
|
109
115
|
return "".concat(message).concat(filePathLine).concat(codeLine).concat(codeMarker);
|
|
110
116
|
}
|
|
111
117
|
var RecurSignal = /** @class */ (function (_super) {
|
|
@@ -190,12 +196,12 @@ var specialExpressionTypes = {
|
|
|
190
196
|
'||': 2,
|
|
191
197
|
'array': 3,
|
|
192
198
|
'cond': 4,
|
|
193
|
-
'
|
|
199
|
+
'0_def': 5,
|
|
194
200
|
'defined?': 6,
|
|
195
|
-
'
|
|
201
|
+
'0_defn': 7,
|
|
196
202
|
'do': 8,
|
|
197
203
|
'doseq': 9,
|
|
198
|
-
'
|
|
204
|
+
'0_fn': 10,
|
|
199
205
|
'for': 11,
|
|
200
206
|
'function': 12,
|
|
201
207
|
'if': 13,
|
|
@@ -240,6 +246,7 @@ var functionTypes = [
|
|
|
240
246
|
'SomePred',
|
|
241
247
|
'Fnull',
|
|
242
248
|
'Builtin',
|
|
249
|
+
'SpecialBuiltin',
|
|
243
250
|
'NativeJsFunction',
|
|
244
251
|
];
|
|
245
252
|
var functionTypeSet = new Set(functionTypes);
|
|
@@ -309,25 +316,9 @@ function assertUserDefinedSymbolNode(node, sourceCodeInfo) {
|
|
|
309
316
|
function isNormalBuiltinSymbolNode(node) {
|
|
310
317
|
return NodeTypes.NormalBuiltinSymbol === node[0];
|
|
311
318
|
}
|
|
312
|
-
function isSpecialBuiltinSymbolNode(node
|
|
313
|
-
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
{
|
|
317
|
-
return true;
|
|
318
|
-
}
|
|
319
|
+
function isSpecialBuiltinSymbolNode(node) {
|
|
320
|
+
return NodeTypes.SpecialBuiltinSymbol === node[0];
|
|
319
321
|
}
|
|
320
|
-
// export function isNumberNode(node: Node): node is NumberNode {
|
|
321
|
-
// return node[0] === NodeTypes.Number
|
|
322
|
-
// }
|
|
323
|
-
// export function asNumberNode(node: Node, sourceCodeInfo?: SourceCodeInfo): NumberNode {
|
|
324
|
-
// assertNumberNode(node, sourceCodeInfo)
|
|
325
|
-
// return node
|
|
326
|
-
// }
|
|
327
|
-
// export function assertNumberNode(node: Node, sourceCodeInfo?: SourceCodeInfo): asserts node is NumberNode {
|
|
328
|
-
// if (!isNumberNode(node))
|
|
329
|
-
// throw getAssertionError('NumberNode', node, sourceCodeInfo)
|
|
330
|
-
// }
|
|
331
322
|
function isNormalExpressionNode(node) {
|
|
332
323
|
return node[0] === NodeTypes.NormalExpression;
|
|
333
324
|
}
|
|
@@ -380,6 +371,7 @@ function findUnresolvedSymbolsInNode(node, contextStack, builtin, evaluateNode)
|
|
|
380
371
|
case NodeTypes.String:
|
|
381
372
|
case NodeTypes.Number:
|
|
382
373
|
case NodeTypes.ReservedSymbol:
|
|
374
|
+
case NodeTypes.Binding:
|
|
383
375
|
return null;
|
|
384
376
|
case NodeTypes.NormalExpression: {
|
|
385
377
|
var normalExpressionNode = node;
|
|
@@ -424,12 +416,9 @@ function findUnresolvedSymbolsInNode(node, contextStack, builtin, evaluateNode)
|
|
|
424
416
|
}
|
|
425
417
|
case NodeTypes.Spread:
|
|
426
418
|
return findUnresolvedSymbolsInNode(node[1], contextStack, builtin, evaluateNode);
|
|
427
|
-
|
|
428
|
-
var bindingNode = node;
|
|
429
|
-
return findUnresolvedSymbolsInNode(bindingNode[1][1], contextStack, builtin, evaluateNode);
|
|
430
|
-
}
|
|
419
|
+
/* v8 ignore next 2 */
|
|
431
420
|
default:
|
|
432
|
-
throw new
|
|
421
|
+
throw new LitsError("Unhandled node type: ".concat(nodeType), node[2]);
|
|
433
422
|
}
|
|
434
423
|
}
|
|
435
424
|
|
|
@@ -711,9 +700,6 @@ function assertLitsFunction(value, sourceCodeInfo) {
|
|
|
711
700
|
if (!isLitsFunction(value))
|
|
712
701
|
throw getAssertionError('LitsFunction', value, sourceCodeInfo);
|
|
713
702
|
}
|
|
714
|
-
function isBuiltinFunction(value) {
|
|
715
|
-
return isUnknownRecord(value) && value.functionType === 'Builtin';
|
|
716
|
-
}
|
|
717
703
|
|
|
718
704
|
function isAny(value) {
|
|
719
705
|
// TODO weak test
|
|
@@ -3812,6 +3798,26 @@ var andSpecialExpression = {
|
|
|
3812
3798
|
}
|
|
3813
3799
|
return value;
|
|
3814
3800
|
},
|
|
3801
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
3802
|
+
var e_2, _a;
|
|
3803
|
+
var value = true;
|
|
3804
|
+
try {
|
|
3805
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
3806
|
+
var param = params_1_1.value;
|
|
3807
|
+
value = asAny(param, sourceCodeInfo);
|
|
3808
|
+
if (!value)
|
|
3809
|
+
break;
|
|
3810
|
+
}
|
|
3811
|
+
}
|
|
3812
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3813
|
+
finally {
|
|
3814
|
+
try {
|
|
3815
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
3816
|
+
}
|
|
3817
|
+
finally { if (e_2) throw e_2.error; }
|
|
3818
|
+
}
|
|
3819
|
+
return value;
|
|
3820
|
+
},
|
|
3815
3821
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
3816
3822
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
3817
3823
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -3903,6 +3909,29 @@ var bindingTargetTypes = {
|
|
|
3903
3909
|
array: 14,
|
|
3904
3910
|
};
|
|
3905
3911
|
|
|
3912
|
+
function walkDefaults(bindingTarget, onDefault) {
|
|
3913
|
+
var _a;
|
|
3914
|
+
if (bindingTarget[0] === bindingTargetTypes.object) {
|
|
3915
|
+
Object.values(bindingTarget[1][0]).forEach(function (element) {
|
|
3916
|
+
if (element[1][1]) {
|
|
3917
|
+
onDefault(element[1][1]);
|
|
3918
|
+
}
|
|
3919
|
+
walkDefaults(element, onDefault);
|
|
3920
|
+
});
|
|
3921
|
+
}
|
|
3922
|
+
else if (bindingTarget[0] === bindingTargetTypes.array) {
|
|
3923
|
+
for (var index = 0; index < bindingTarget[1][0].length; index += 1) {
|
|
3924
|
+
var element = (_a = bindingTarget[1][0][index]) !== null && _a !== void 0 ? _a : null;
|
|
3925
|
+
if (element === null) {
|
|
3926
|
+
continue;
|
|
3927
|
+
}
|
|
3928
|
+
if (element[1][1]) {
|
|
3929
|
+
onDefault(element[1][1]);
|
|
3930
|
+
}
|
|
3931
|
+
walkDefaults(element, onDefault);
|
|
3932
|
+
}
|
|
3933
|
+
}
|
|
3934
|
+
}
|
|
3906
3935
|
function evalueateBindingNodeValues(target, value, evaluate) {
|
|
3907
3936
|
var sourceCodeInfo = target[2];
|
|
3908
3937
|
var record = {};
|
|
@@ -4033,7 +4062,7 @@ var defSpecialExpression = {
|
|
|
4033
4062
|
var value = bindingNode[1][1];
|
|
4034
4063
|
var bindingValue = evaluateNode(value, contextStack);
|
|
4035
4064
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
4036
|
-
contextStack.exportValues(values);
|
|
4065
|
+
contextStack.exportValues(values, target[2]);
|
|
4037
4066
|
return null;
|
|
4038
4067
|
},
|
|
4039
4068
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4042,7 +4071,10 @@ var defSpecialExpression = {
|
|
|
4042
4071
|
var target = bindingNode[1][0];
|
|
4043
4072
|
var value = bindingNode[1][1];
|
|
4044
4073
|
var bindingResult = getUndefinedSymbols([value], contextStack, builtin, evaluateNode);
|
|
4045
|
-
|
|
4074
|
+
walkDefaults(target, function (defaultNode) {
|
|
4075
|
+
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
4076
|
+
});
|
|
4077
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
4046
4078
|
return bindingResult;
|
|
4047
4079
|
},
|
|
4048
4080
|
};
|
|
@@ -4160,16 +4192,16 @@ var functionSpecialExpression = {
|
|
|
4160
4192
|
_b.name = functionSymbol[1],
|
|
4161
4193
|
_b.evaluatedfunction = evaluatedFunction,
|
|
4162
4194
|
_b);
|
|
4163
|
-
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4195
|
+
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4164
4196
|
return null;
|
|
4165
4197
|
},
|
|
4166
4198
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4167
4199
|
var _b, _c;
|
|
4168
4200
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4169
4201
|
var functionName = node[1][1][1];
|
|
4170
|
-
contextStack.addValues((_b = {}, _b[functionName] = true, _b));
|
|
4202
|
+
contextStack.addValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4171
4203
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4172
|
-
return
|
|
4204
|
+
return getFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4173
4205
|
},
|
|
4174
4206
|
};
|
|
4175
4207
|
var defnSpecialExpression = {
|
|
@@ -4188,7 +4220,7 @@ var defnSpecialExpression = {
|
|
|
4188
4220
|
_b.name = functionSymbol[1],
|
|
4189
4221
|
_b.evaluatedfunction = evaluatedFunctionOverloades,
|
|
4190
4222
|
_b);
|
|
4191
|
-
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4223
|
+
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4192
4224
|
return null;
|
|
4193
4225
|
},
|
|
4194
4226
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4196,9 +4228,9 @@ var defnSpecialExpression = {
|
|
|
4196
4228
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4197
4229
|
var functionName = node[1][1][1];
|
|
4198
4230
|
var fn = node[1][2];
|
|
4199
|
-
contextStack.exportValues((_b = {}, _b[functionName] = true, _b));
|
|
4231
|
+
contextStack.exportValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4200
4232
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4201
|
-
return
|
|
4233
|
+
return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4202
4234
|
},
|
|
4203
4235
|
};
|
|
4204
4236
|
var fnSpecialExpression = {
|
|
@@ -4220,7 +4252,7 @@ var fnSpecialExpression = {
|
|
|
4220
4252
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4221
4253
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4222
4254
|
var fn = node[1][1];
|
|
4223
|
-
return
|
|
4255
|
+
return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode);
|
|
4224
4256
|
},
|
|
4225
4257
|
};
|
|
4226
4258
|
function evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode) {
|
|
@@ -4245,12 +4277,15 @@ function evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evalua
|
|
|
4245
4277
|
];
|
|
4246
4278
|
return evaluatedFunction;
|
|
4247
4279
|
}
|
|
4248
|
-
function
|
|
4280
|
+
function getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, functionNameContext) {
|
|
4249
4281
|
var result = new Set();
|
|
4250
4282
|
var contextStackWithFunctionName = functionNameContext ? contextStack.create(functionNameContext) : contextStack;
|
|
4251
4283
|
var newContext = {};
|
|
4252
4284
|
fn[0].forEach(function (arg) {
|
|
4253
4285
|
Object.assign(newContext, getAllBindingTargetNames(arg));
|
|
4286
|
+
walkDefaults(arg, function (defaultNode) {
|
|
4287
|
+
addToSet(result, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
4288
|
+
});
|
|
4254
4289
|
});
|
|
4255
4290
|
var newContextStack = contextStackWithFunctionName.create(newContext);
|
|
4256
4291
|
var overloadResult = getUndefinedSymbols(fn[1], newContextStack, builtin, evaluateNode);
|
|
@@ -4305,7 +4340,7 @@ var letSpecialExpression = {
|
|
|
4305
4340
|
var value = bindingNode[1][1];
|
|
4306
4341
|
var bindingValue = evaluateNode(value, contextStack);
|
|
4307
4342
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
4308
|
-
contextStack.addValues(values);
|
|
4343
|
+
contextStack.addValues(values, target[2]);
|
|
4309
4344
|
return null;
|
|
4310
4345
|
},
|
|
4311
4346
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4314,7 +4349,10 @@ var letSpecialExpression = {
|
|
|
4314
4349
|
var target = bindingNode[1][0];
|
|
4315
4350
|
var value = bindingNode[1][1];
|
|
4316
4351
|
var bindingResult = getUndefinedSymbols([value], contextStack, builtin, evaluateNode);
|
|
4317
|
-
|
|
4352
|
+
walkDefaults(target, function (defaultNode) {
|
|
4353
|
+
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
4354
|
+
});
|
|
4355
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
4318
4356
|
return bindingResult;
|
|
4319
4357
|
},
|
|
4320
4358
|
};
|
|
@@ -4585,6 +4623,26 @@ var orSpecialExpression = {
|
|
|
4585
4623
|
}
|
|
4586
4624
|
return value;
|
|
4587
4625
|
},
|
|
4626
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4627
|
+
var e_2, _a;
|
|
4628
|
+
var value = false;
|
|
4629
|
+
try {
|
|
4630
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4631
|
+
var param = params_1_1.value;
|
|
4632
|
+
value = asAny(param, sourceCodeInfo);
|
|
4633
|
+
if (value)
|
|
4634
|
+
break;
|
|
4635
|
+
}
|
|
4636
|
+
}
|
|
4637
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4638
|
+
finally {
|
|
4639
|
+
try {
|
|
4640
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4641
|
+
}
|
|
4642
|
+
finally { if (e_2) throw e_2.error; }
|
|
4643
|
+
}
|
|
4644
|
+
return value;
|
|
4645
|
+
},
|
|
4588
4646
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4589
4647
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4590
4648
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4603,6 +4661,11 @@ var qqSpecialExpression = {
|
|
|
4603
4661
|
var firstResult = evaluateNode(firstNode, contextStack);
|
|
4604
4662
|
return firstResult !== null && firstResult !== void 0 ? firstResult : (secondNode ? evaluateNode(secondNode, contextStack) : null);
|
|
4605
4663
|
},
|
|
4664
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4665
|
+
var firstParam = asAny(params[0], sourceCodeInfo);
|
|
4666
|
+
var secondParam = params[1] !== undefined ? asAny(params[1], sourceCodeInfo) : null;
|
|
4667
|
+
return firstParam !== null && firstParam !== void 0 ? firstParam : secondParam;
|
|
4668
|
+
},
|
|
4606
4669
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4607
4670
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4608
4671
|
return getUndefinedSymbols(node[1][1].filter(function (n) { return !!n; }), contextStack, builtin, evaluateNode);
|
|
@@ -4617,6 +4680,9 @@ var recurSpecialExpression = {
|
|
|
4617
4680
|
var evaluatedParams = params.map(function (paramNode) { return evaluateNode(paramNode, contextStack); });
|
|
4618
4681
|
throw new RecurSignal(evaluatedParams);
|
|
4619
4682
|
},
|
|
4683
|
+
evaluateAsNormalExpression: function (params) {
|
|
4684
|
+
throw new RecurSignal(params);
|
|
4685
|
+
},
|
|
4620
4686
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4621
4687
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4622
4688
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4632,6 +4698,12 @@ var throwSpecialExpression = {
|
|
|
4632
4698
|
});
|
|
4633
4699
|
throw new UserDefinedError(message, node[2]);
|
|
4634
4700
|
},
|
|
4701
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4702
|
+
var message = asString(params[0], sourceCodeInfo, {
|
|
4703
|
+
nonEmpty: true,
|
|
4704
|
+
});
|
|
4705
|
+
throw new UserDefinedError(message, undefined);
|
|
4706
|
+
},
|
|
4635
4707
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4636
4708
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4637
4709
|
return getUndefinedSymbols([node[1][1]], contextStack, builtin, evaluateNode);
|
|
@@ -4699,6 +4771,24 @@ var arraySpecialExpression = {
|
|
|
4699
4771
|
}
|
|
4700
4772
|
return result;
|
|
4701
4773
|
},
|
|
4774
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4775
|
+
var e_2, _a;
|
|
4776
|
+
var result = [];
|
|
4777
|
+
try {
|
|
4778
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4779
|
+
var param = params_1_1.value;
|
|
4780
|
+
result.push(asAny(param, sourceCodeInfo));
|
|
4781
|
+
}
|
|
4782
|
+
}
|
|
4783
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4784
|
+
finally {
|
|
4785
|
+
try {
|
|
4786
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4787
|
+
}
|
|
4788
|
+
finally { if (e_2) throw e_2.error; }
|
|
4789
|
+
}
|
|
4790
|
+
return result;
|
|
4791
|
+
},
|
|
4702
4792
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4703
4793
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4704
4794
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4730,6 +4820,16 @@ var objectSpecialExpression = {
|
|
|
4730
4820
|
}
|
|
4731
4821
|
return result;
|
|
4732
4822
|
},
|
|
4823
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4824
|
+
var result = {};
|
|
4825
|
+
for (var i = 0; i < params.length; i += 2) {
|
|
4826
|
+
var key = params[i];
|
|
4827
|
+
var value = params[i + 1];
|
|
4828
|
+
assertString(key, sourceCodeInfo);
|
|
4829
|
+
result[key] = value !== null && value !== void 0 ? value : null;
|
|
4830
|
+
}
|
|
4831
|
+
return result;
|
|
4832
|
+
},
|
|
4733
4833
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4734
4834
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4735
4835
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4973,6 +5073,16 @@ var functionExecutors = {
|
|
|
4973
5073
|
var normalExpression = asNonUndefined(allNormalExpressions[fn.normalBuitinSymbolType], sourceCodeInfo);
|
|
4974
5074
|
return normalExpression.evaluate(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
4975
5075
|
},
|
|
5076
|
+
SpecialBuiltin: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
5077
|
+
var executeFunction = _a.executeFunction;
|
|
5078
|
+
var specialExpression = asNonUndefined(specialExpressions[fn.specialBuiltinSymbolType], sourceCodeInfo);
|
|
5079
|
+
if (specialExpression.evaluateAsNormalExpression) {
|
|
5080
|
+
return specialExpression.evaluateAsNormalExpression(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
5081
|
+
}
|
|
5082
|
+
else {
|
|
5083
|
+
throw new LitsError("Special builtin function ".concat(fn.specialBuiltinSymbolType, " is not supported as normal expression."), sourceCodeInfo);
|
|
5084
|
+
}
|
|
5085
|
+
},
|
|
4976
5086
|
};
|
|
4977
5087
|
|
|
4978
5088
|
function evaluate(ast, contextStack) {
|
|
@@ -5028,7 +5138,21 @@ function evaluateReservedSymbol(node) {
|
|
|
5028
5138
|
function evaluateNormalExpression(node, contextStack) {
|
|
5029
5139
|
var sourceCodeInfo = node[2];
|
|
5030
5140
|
var paramNodes = node[1][1];
|
|
5031
|
-
var params =
|
|
5141
|
+
var params = [];
|
|
5142
|
+
paramNodes.forEach(function (paramNode) {
|
|
5143
|
+
if (isSpreadNode(paramNode)) {
|
|
5144
|
+
var spreadValue = evaluateNode(paramNode[1], contextStack);
|
|
5145
|
+
if (Array.isArray(spreadValue)) {
|
|
5146
|
+
params.push.apply(params, __spreadArray([], __read(spreadValue), false));
|
|
5147
|
+
}
|
|
5148
|
+
else {
|
|
5149
|
+
throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
|
|
5150
|
+
}
|
|
5151
|
+
}
|
|
5152
|
+
else {
|
|
5153
|
+
params.push(evaluateNode(paramNode, contextStack));
|
|
5154
|
+
}
|
|
5155
|
+
});
|
|
5032
5156
|
if (isNormalExpressionNodeWithName(node)) {
|
|
5033
5157
|
var nameSymbol = node[1][0];
|
|
5034
5158
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
@@ -5130,19 +5254,19 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5130
5254
|
var contexts = [{}, context];
|
|
5131
5255
|
return new ContextStackImpl({ contexts: contexts });
|
|
5132
5256
|
};
|
|
5133
|
-
ContextStackImpl.prototype.exportValues = function (values) {
|
|
5257
|
+
ContextStackImpl.prototype.exportValues = function (values, sourceCodeInfo) {
|
|
5134
5258
|
var e_1, _a;
|
|
5135
5259
|
try {
|
|
5136
5260
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5137
5261
|
var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
|
|
5138
5262
|
if (this.globalContext[name_1]) {
|
|
5139
|
-
throw new
|
|
5263
|
+
throw new LitsError("Cannot redefine exported value \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5140
5264
|
}
|
|
5141
5265
|
if (specialExpressionKeys.includes(name_1)) {
|
|
5142
|
-
throw new
|
|
5266
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5143
5267
|
}
|
|
5144
5268
|
if (normalExpressionKeys.includes(name_1)) {
|
|
5145
|
-
throw new
|
|
5269
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5146
5270
|
}
|
|
5147
5271
|
this.globalContext[name_1] = { value: value };
|
|
5148
5272
|
}
|
|
@@ -5154,22 +5278,22 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5154
5278
|
}
|
|
5155
5279
|
finally { if (e_1) throw e_1.error; }
|
|
5156
5280
|
}
|
|
5157
|
-
this.addValues(values);
|
|
5281
|
+
this.addValues(values, sourceCodeInfo);
|
|
5158
5282
|
};
|
|
5159
|
-
ContextStackImpl.prototype.addValues = function (values) {
|
|
5283
|
+
ContextStackImpl.prototype.addValues = function (values, sourceCodeInfo) {
|
|
5160
5284
|
var e_2, _a;
|
|
5161
5285
|
var currentContext = this.contexts[0];
|
|
5162
5286
|
try {
|
|
5163
5287
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5164
5288
|
var _d = __read(_c.value, 2), name_2 = _d[0], value = _d[1];
|
|
5165
5289
|
if (currentContext[name_2]) {
|
|
5166
|
-
throw new
|
|
5290
|
+
throw new LitsError("Cannot redefine value \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5167
5291
|
}
|
|
5168
5292
|
if (specialExpressionKeys.includes(name_2)) {
|
|
5169
|
-
throw new
|
|
5293
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5170
5294
|
}
|
|
5171
5295
|
if (normalExpressionKeys.includes(name_2)) {
|
|
5172
|
-
throw new
|
|
5296
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5173
5297
|
}
|
|
5174
5298
|
currentContext[name_2] = { value: toAny(value) };
|
|
5175
5299
|
}
|
|
@@ -5249,24 +5373,40 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5249
5373
|
return null;
|
|
5250
5374
|
};
|
|
5251
5375
|
ContextStackImpl.prototype.evaluateSymbol = function (node) {
|
|
5252
|
-
var _a;
|
|
5376
|
+
var _a, _b;
|
|
5253
5377
|
if (isSpecialBuiltinSymbolNode(node)) {
|
|
5254
|
-
|
|
5378
|
+
var functionType = node[1];
|
|
5379
|
+
switch (functionType) {
|
|
5380
|
+
case specialExpressionTypes['&&']:
|
|
5381
|
+
case specialExpressionTypes['||']:
|
|
5382
|
+
case specialExpressionTypes.array:
|
|
5383
|
+
case specialExpressionTypes.object:
|
|
5384
|
+
case specialExpressionTypes['defined?']:
|
|
5385
|
+
case specialExpressionTypes.recur:
|
|
5386
|
+
case specialExpressionTypes.throw:
|
|
5387
|
+
case specialExpressionTypes['??']:
|
|
5388
|
+
return _a = {},
|
|
5389
|
+
_a[FUNCTION_SYMBOL] = true,
|
|
5390
|
+
_a.functionType = 'SpecialBuiltin',
|
|
5391
|
+
_a.specialBuiltinSymbolType = functionType,
|
|
5392
|
+
_a.sourceCodeInfo = node[2],
|
|
5393
|
+
_a;
|
|
5394
|
+
default:
|
|
5395
|
+
throw new LitsError("Unknown special builtin symbol type: ".concat(functionType), node[2]);
|
|
5396
|
+
}
|
|
5255
5397
|
}
|
|
5256
5398
|
if (isNormalBuiltinSymbolNode(node)) {
|
|
5257
5399
|
var type = node[1];
|
|
5258
|
-
return
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5400
|
+
return _b = {},
|
|
5401
|
+
_b[FUNCTION_SYMBOL] = true,
|
|
5402
|
+
_b.functionType = 'Builtin',
|
|
5403
|
+
_b.normalBuitinSymbolType = type,
|
|
5404
|
+
_b.sourceCodeInfo = node[2],
|
|
5405
|
+
_b;
|
|
5264
5406
|
}
|
|
5265
5407
|
var lookUpResult = this.lookUp(node);
|
|
5266
5408
|
if (isContextEntry(lookUpResult))
|
|
5267
5409
|
return lookUpResult.value;
|
|
5268
|
-
else if (isBuiltinFunction(lookUpResult))
|
|
5269
|
-
return lookUpResult;
|
|
5270
5410
|
throw new UndefinedSymbolError(node[1], node[2]);
|
|
5271
5411
|
};
|
|
5272
5412
|
return ContextStackImpl;
|
|
@@ -5350,10 +5490,10 @@ var nonFunctionOperators = [
|
|
|
5350
5490
|
'cond',
|
|
5351
5491
|
'def',
|
|
5352
5492
|
'defined?',
|
|
5353
|
-
'defn',
|
|
5493
|
+
// 'defn',
|
|
5354
5494
|
'do',
|
|
5355
5495
|
'doseq',
|
|
5356
|
-
'fn',
|
|
5496
|
+
// 'fn',
|
|
5357
5497
|
'if',
|
|
5358
5498
|
'let',
|
|
5359
5499
|
'loop',
|
|
@@ -5934,7 +6074,7 @@ function withSourceCodeInfo(node, sourceCodeInfo) {
|
|
|
5934
6074
|
}
|
|
5935
6075
|
return node;
|
|
5936
6076
|
}
|
|
5937
|
-
function getPrecedence(operatorSign) {
|
|
6077
|
+
function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
5938
6078
|
switch (operatorSign) {
|
|
5939
6079
|
case '**': // exponentiation
|
|
5940
6080
|
return exponentiationPrecedence;
|
|
@@ -5973,7 +6113,7 @@ function getPrecedence(operatorSign) {
|
|
|
5973
6113
|
// leave room for binaryFunctionalOperatorPrecedence = 1
|
|
5974
6114
|
/* v8 ignore next 2 */
|
|
5975
6115
|
default:
|
|
5976
|
-
throw new
|
|
6116
|
+
throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
|
|
5977
6117
|
}
|
|
5978
6118
|
}
|
|
5979
6119
|
function createNamedNormalExpressionNode(symbolNode, params, sourceCodeInfo) {
|
|
@@ -6106,7 +6246,7 @@ var Parser = /** @class */ (function () {
|
|
|
6106
6246
|
while (!this.isAtExpressionEnd()) {
|
|
6107
6247
|
if (isA_BinaryOperatorToken(operator)) {
|
|
6108
6248
|
var name_1 = operator[1];
|
|
6109
|
-
var newPrecedece = getPrecedence(name_1);
|
|
6249
|
+
var newPrecedece = getPrecedence(name_1, operator[2]);
|
|
6110
6250
|
if (newPrecedece <= precedence
|
|
6111
6251
|
// ** (exponentiation) is right associative
|
|
6112
6252
|
&& !(newPrecedece === exponentiationPrecedence && precedence === exponentiationPrecedence)) {
|
|
@@ -6186,7 +6326,7 @@ var Parser = /** @class */ (function () {
|
|
|
6186
6326
|
this.advance();
|
|
6187
6327
|
var expression = this.parseExpression();
|
|
6188
6328
|
if (!isRParenToken(this.peek())) {
|
|
6189
|
-
throw new
|
|
6329
|
+
throw new LitsError('Expected closing parenthesis', this.peek()[2]);
|
|
6190
6330
|
}
|
|
6191
6331
|
this.advance();
|
|
6192
6332
|
return expression;
|
|
@@ -6198,10 +6338,7 @@ var Parser = /** @class */ (function () {
|
|
|
6198
6338
|
if (specialExpressionTypes[operatorName] !== undefined) {
|
|
6199
6339
|
return withSourceCodeInfo([NodeTypes.SpecialBuiltinSymbol, specialExpressionTypes[operatorName]], token[2]);
|
|
6200
6340
|
}
|
|
6201
|
-
|
|
6202
|
-
return withSourceCodeInfo([NodeTypes.NormalBuiltinSymbol, normalExpressionTypes[operatorName]], token[2]);
|
|
6203
|
-
}
|
|
6204
|
-
return withSourceCodeInfo([NodeTypes.UserDefinedSymbol, operatorName], token[2]);
|
|
6341
|
+
return withSourceCodeInfo([NodeTypes.NormalBuiltinSymbol, normalExpressionTypes[operatorName]], token[2]);
|
|
6205
6342
|
}
|
|
6206
6343
|
if (operatorName === '->') {
|
|
6207
6344
|
return this.parseShorthandLamdaFunction();
|
|
@@ -6311,7 +6448,13 @@ var Parser = /** @class */ (function () {
|
|
|
6311
6448
|
this.advance();
|
|
6312
6449
|
var params = [];
|
|
6313
6450
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
6314
|
-
|
|
6451
|
+
if (isOperatorToken(this.peek(), '...')) {
|
|
6452
|
+
this.advance();
|
|
6453
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peek()[2]));
|
|
6454
|
+
}
|
|
6455
|
+
else {
|
|
6456
|
+
params.push(this.parseExpression());
|
|
6457
|
+
}
|
|
6315
6458
|
var nextToken = this.peek();
|
|
6316
6459
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
6317
6460
|
throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
|
|
@@ -6361,13 +6504,13 @@ var Parser = /** @class */ (function () {
|
|
|
6361
6504
|
var _b = __read(params, 1), param = _b[0];
|
|
6362
6505
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
6363
6506
|
}
|
|
6364
|
-
case specialExpressionTypes
|
|
6365
|
-
case specialExpressionTypes
|
|
6366
|
-
case specialExpressionTypes
|
|
6507
|
+
case specialExpressionTypes['0_fn']:
|
|
6508
|
+
case specialExpressionTypes['0_def']:
|
|
6509
|
+
case specialExpressionTypes['0_defn']:
|
|
6367
6510
|
throw new LitsError("".concat(type, " is not allowed"), symbol[2]);
|
|
6368
6511
|
/* v8 ignore next 2 */
|
|
6369
6512
|
default:
|
|
6370
|
-
throw new
|
|
6513
|
+
throw new LitsError("Unknown special expression: ".concat(type), symbol[2]);
|
|
6371
6514
|
}
|
|
6372
6515
|
}
|
|
6373
6516
|
else if (isNormalBuiltinSymbolNode(symbol) || isNormalBuiltinSymbolNode(symbol)) {
|
|
@@ -6391,7 +6534,7 @@ var Parser = /** @class */ (function () {
|
|
|
6391
6534
|
}
|
|
6392
6535
|
this.advance();
|
|
6393
6536
|
var body = this.parseExpression();
|
|
6394
|
-
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes
|
|
6537
|
+
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_fn'], [
|
|
6395
6538
|
functionArguments,
|
|
6396
6539
|
[body],
|
|
6397
6540
|
]]], firstToken[2]);
|
|
@@ -6474,7 +6617,7 @@ var Parser = /** @class */ (function () {
|
|
|
6474
6617
|
functionArguments.push(withSourceCodeInfo([bindingTargetTypes.symbol, [[NodeTypes.UserDefinedSymbol, "$".concat(i)], undefined]], firstToken[2]));
|
|
6475
6618
|
}
|
|
6476
6619
|
}
|
|
6477
|
-
var node = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes
|
|
6620
|
+
var node = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_fn'], [
|
|
6478
6621
|
functionArguments,
|
|
6479
6622
|
[exprNode],
|
|
6480
6623
|
]]], firstToken[2]);
|
|
@@ -6993,7 +7136,7 @@ var Parser = /** @class */ (function () {
|
|
|
6993
7136
|
this.advance();
|
|
6994
7137
|
if (isSymbolToken(this.peek(), 'let')) {
|
|
6995
7138
|
var letNode = this.parseLet(asSymbolToken(this.peek()));
|
|
6996
|
-
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes
|
|
7139
|
+
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_def'], letNode[1][1]]], token[2]);
|
|
6997
7140
|
}
|
|
6998
7141
|
else if (isReservedSymbolToken(this.peek(), 'function')) {
|
|
6999
7142
|
this.advance();
|
|
@@ -7011,7 +7154,7 @@ var Parser = /** @class */ (function () {
|
|
|
7011
7154
|
}
|
|
7012
7155
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
7013
7156
|
this.advance();
|
|
7014
|
-
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes
|
|
7157
|
+
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_defn'], symbol, [
|
|
7015
7158
|
functionArguments,
|
|
7016
7159
|
body,
|
|
7017
7160
|
]]], token[2]);
|
|
@@ -7021,7 +7164,7 @@ var Parser = /** @class */ (function () {
|
|
|
7021
7164
|
}
|
|
7022
7165
|
};
|
|
7023
7166
|
Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
|
|
7024
|
-
if (specialExpressionTypes[value] !== undefined) {
|
|
7167
|
+
if (specialExpressionTypes[value] !== undefined && value !== 'fn' && value !== 'def' && value !== 'defn') {
|
|
7025
7168
|
return withSourceCodeInfo([NodeTypes.SpecialBuiltinSymbol, specialExpressionTypes[value]], sourceCodeInfo);
|
|
7026
7169
|
}
|
|
7027
7170
|
if (normalExpressionTypes[value] !== undefined) {
|
|
@@ -7636,28 +7779,6 @@ var api = {
|
|
|
7636
7779
|
'replace',
|
|
7637
7780
|
'replace-all',
|
|
7638
7781
|
],
|
|
7639
|
-
specialExpressions: [
|
|
7640
|
-
'&&',
|
|
7641
|
-
'||',
|
|
7642
|
-
'def',
|
|
7643
|
-
'let',
|
|
7644
|
-
'fn',
|
|
7645
|
-
'defn',
|
|
7646
|
-
'function',
|
|
7647
|
-
'try',
|
|
7648
|
-
'throw',
|
|
7649
|
-
'if',
|
|
7650
|
-
'unless',
|
|
7651
|
-
'cond',
|
|
7652
|
-
'switch',
|
|
7653
|
-
'do',
|
|
7654
|
-
'recur',
|
|
7655
|
-
'loop',
|
|
7656
|
-
'doseq',
|
|
7657
|
-
'for',
|
|
7658
|
-
'defined?',
|
|
7659
|
-
'??',
|
|
7660
|
-
],
|
|
7661
7782
|
string: [
|
|
7662
7783
|
'string-repeat',
|
|
7663
7784
|
'str',
|