@mojir/lits 2.1.21 → 2.1.23
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 +135 -14
- package/dist/cli/src/Lits/Lits.d.ts +2 -0
- package/dist/cli/src/builtin/interface.d.ts +3 -3
- package/dist/cli/src/builtin/specialExpressions/functions.d.ts +1 -1
- package/dist/cli/src/parser/types.d.ts +2 -0
- package/dist/cli/src/typeGuards/index.d.ts +3 -3
- package/dist/cli/src/utils/index.d.ts +0 -2
- package/dist/cli/src/utils/paramCount.d.ts +7 -0
- package/dist/index.esm.js +135 -25
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +134 -25
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +134 -25
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/Lits/Lits.d.ts +2 -0
- package/dist/src/builtin/interface.d.ts +3 -3
- package/dist/src/builtin/specialExpressions/functions.d.ts +1 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/parser/types.d.ts +2 -0
- package/dist/src/typeGuards/index.d.ts +3 -3
- package/dist/src/utils/index.d.ts +0 -2
- package/dist/src/utils/paramCount.d.ts +7 -0
- package/dist/testFramework.esm.js +134 -13
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +134 -13
- 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.23";
|
|
96
96
|
|
|
97
97
|
function getCodeMarker(sourceCodeInfo) {
|
|
98
98
|
if (!sourceCodeInfo.position || !sourceCodeInfo.code)
|
|
@@ -4548,6 +4548,98 @@ function applyPlaceholders(templateString, placeholders, sourceCodeInfo) {
|
|
|
4548
4548
|
return templateString;
|
|
4549
4549
|
}
|
|
4550
4550
|
|
|
4551
|
+
function paramCountAccepts(paramsCount, nbrOfParams) {
|
|
4552
|
+
if (typeof paramsCount === 'number') {
|
|
4553
|
+
return paramsCount === nbrOfParams;
|
|
4554
|
+
}
|
|
4555
|
+
var min = paramsCount.min, max = paramsCount.max, even = paramsCount.even, odd = paramsCount.odd;
|
|
4556
|
+
if (even && nbrOfParams % 2 !== 0) {
|
|
4557
|
+
return false;
|
|
4558
|
+
}
|
|
4559
|
+
if (odd && nbrOfParams % 2 !== 1) {
|
|
4560
|
+
return false;
|
|
4561
|
+
}
|
|
4562
|
+
if (typeof min === 'number' && nbrOfParams < min) {
|
|
4563
|
+
return false;
|
|
4564
|
+
}
|
|
4565
|
+
if (typeof max === 'number' && nbrOfParams > max) {
|
|
4566
|
+
return false;
|
|
4567
|
+
}
|
|
4568
|
+
return true;
|
|
4569
|
+
}
|
|
4570
|
+
function paramCountAcceptsMin(paramsCount, nbrOfParams) {
|
|
4571
|
+
if (typeof paramsCount === 'number') {
|
|
4572
|
+
return nbrOfParams >= paramsCount;
|
|
4573
|
+
}
|
|
4574
|
+
var min = paramsCount.min;
|
|
4575
|
+
if (typeof min === 'number' && nbrOfParams < min) {
|
|
4576
|
+
return false;
|
|
4577
|
+
}
|
|
4578
|
+
return true;
|
|
4579
|
+
}
|
|
4580
|
+
function getCommonParamCountFromFunctions(params) {
|
|
4581
|
+
return params.reduce(function (acc, param) {
|
|
4582
|
+
if (acc === null) {
|
|
4583
|
+
return null;
|
|
4584
|
+
}
|
|
4585
|
+
var paramCount = (typeof param === 'number' || isColl(param)) ? 1 : param.paramCount;
|
|
4586
|
+
if (typeof acc === 'number' && typeof paramCount === 'number') {
|
|
4587
|
+
return acc === paramCount ? acc : null;
|
|
4588
|
+
}
|
|
4589
|
+
if (typeof paramCount === 'number') {
|
|
4590
|
+
if (paramCountAccepts(acc, paramCount)) {
|
|
4591
|
+
return paramCount;
|
|
4592
|
+
}
|
|
4593
|
+
return null;
|
|
4594
|
+
}
|
|
4595
|
+
if (typeof acc === 'number') {
|
|
4596
|
+
if (paramCountAccepts(paramCount, acc)) {
|
|
4597
|
+
return acc;
|
|
4598
|
+
}
|
|
4599
|
+
return null;
|
|
4600
|
+
}
|
|
4601
|
+
var aMin = paramCount.min, aMax = paramCount.max, aEven = paramCount.even, aOdd = paramCount.odd;
|
|
4602
|
+
var bMin = acc.min, bMax = acc.max, bEven = acc.even, bOdd = acc.odd;
|
|
4603
|
+
var min = typeof aMin === 'number' && typeof bMin === 'number'
|
|
4604
|
+
? Math.max(aMin, bMin)
|
|
4605
|
+
: typeof aMin === 'number' ? aMin : typeof bMin === 'number' ? bMin : undefined;
|
|
4606
|
+
var max = typeof aMax === 'number' && typeof bMax === 'number'
|
|
4607
|
+
? Math.min(aMax, bMax)
|
|
4608
|
+
: typeof aMax === 'number' ? aMax : typeof bMax === 'number' ? bMax : undefined;
|
|
4609
|
+
var even = aEven !== null && aEven !== void 0 ? aEven : bEven;
|
|
4610
|
+
var odd = aOdd !== null && aOdd !== void 0 ? aOdd : bOdd;
|
|
4611
|
+
if (even && odd) {
|
|
4612
|
+
return null;
|
|
4613
|
+
}
|
|
4614
|
+
if (even) {
|
|
4615
|
+
if (typeof min === 'number' && min % 2 !== 0) {
|
|
4616
|
+
min += 1;
|
|
4617
|
+
}
|
|
4618
|
+
if (typeof max === 'number' && max % 2 !== 0) {
|
|
4619
|
+
max -= 1;
|
|
4620
|
+
}
|
|
4621
|
+
}
|
|
4622
|
+
if (odd) {
|
|
4623
|
+
if (typeof min === 'number' && min % 2 === 0) {
|
|
4624
|
+
min += 1;
|
|
4625
|
+
}
|
|
4626
|
+
if (typeof max === 'number' && max % 2 === 0) {
|
|
4627
|
+
max -= 1;
|
|
4628
|
+
}
|
|
4629
|
+
}
|
|
4630
|
+
if (typeof min === 'number' && typeof max === 'number' && min > max) {
|
|
4631
|
+
return null;
|
|
4632
|
+
}
|
|
4633
|
+
if (typeof min === 'number' && min === max) {
|
|
4634
|
+
return min;
|
|
4635
|
+
}
|
|
4636
|
+
return { min: min, max: max, even: even, odd: odd };
|
|
4637
|
+
}, {});
|
|
4638
|
+
}
|
|
4639
|
+
function getParamCountFromFunction(param) {
|
|
4640
|
+
return (typeof param === 'number' || isColl(param)) ? 1 : param.paramCount;
|
|
4641
|
+
}
|
|
4642
|
+
|
|
4551
4643
|
var functionalNormalExpression = {
|
|
4552
4644
|
'|>': {
|
|
4553
4645
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
@@ -4581,11 +4673,13 @@ var functionalNormalExpression = {
|
|
|
4581
4673
|
'comp': {
|
|
4582
4674
|
evaluate: function (params, sourceCodeInfo) {
|
|
4583
4675
|
var _a;
|
|
4676
|
+
params.forEach(function (param) { return assertFunctionLike(param, sourceCodeInfo); });
|
|
4584
4677
|
return _a = {},
|
|
4585
4678
|
_a[FUNCTION_SYMBOL] = true,
|
|
4586
4679
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
4587
4680
|
_a.functionType = 'Comp',
|
|
4588
4681
|
_a.params = params,
|
|
4682
|
+
_a.paramCount = params.length > 0 ? getParamCountFromFunction(params.at(-1)) : 1,
|
|
4589
4683
|
_a;
|
|
4590
4684
|
},
|
|
4591
4685
|
paramCount: {},
|
|
@@ -4599,6 +4693,7 @@ var functionalNormalExpression = {
|
|
|
4599
4693
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4600
4694
|
_b.functionType = 'Constantly',
|
|
4601
4695
|
_b.value = toAny(value),
|
|
4696
|
+
_b.paramCount = {},
|
|
4602
4697
|
_b;
|
|
4603
4698
|
},
|
|
4604
4699
|
paramCount: 1,
|
|
@@ -4606,11 +4701,17 @@ var functionalNormalExpression = {
|
|
|
4606
4701
|
'juxt': {
|
|
4607
4702
|
evaluate: function (params, sourceCodeInfo) {
|
|
4608
4703
|
var _a;
|
|
4704
|
+
params.forEach(function (param) { return assertFunctionLike(param, sourceCodeInfo); });
|
|
4705
|
+
var paramCount = getCommonParamCountFromFunctions(params);
|
|
4706
|
+
if (paramCount === null) {
|
|
4707
|
+
throw new LitsError('All functions must accept the same number of arguments', sourceCodeInfo);
|
|
4708
|
+
}
|
|
4609
4709
|
return _a = {},
|
|
4610
4710
|
_a[FUNCTION_SYMBOL] = true,
|
|
4611
4711
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
4612
4712
|
_a.functionType = 'Juxt',
|
|
4613
4713
|
_a.params = params,
|
|
4714
|
+
_a.paramCount = paramCount,
|
|
4614
4715
|
_a;
|
|
4615
4716
|
},
|
|
4616
4717
|
paramCount: { min: 1 },
|
|
@@ -4619,11 +4720,13 @@ var functionalNormalExpression = {
|
|
|
4619
4720
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4620
4721
|
var _b;
|
|
4621
4722
|
var _c = __read(_a, 1), fn = _c[0];
|
|
4723
|
+
var fun = asFunctionLike(fn, sourceCodeInfo);
|
|
4622
4724
|
return _b = {},
|
|
4623
4725
|
_b[FUNCTION_SYMBOL] = true,
|
|
4624
4726
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4625
4727
|
_b.functionType = 'Complement',
|
|
4626
|
-
_b.function =
|
|
4728
|
+
_b.function = fun,
|
|
4729
|
+
_b.paramCount = getParamCountFromFunction(fun),
|
|
4627
4730
|
_b;
|
|
4628
4731
|
},
|
|
4629
4732
|
paramCount: 1,
|
|
@@ -4636,6 +4739,7 @@ var functionalNormalExpression = {
|
|
|
4636
4739
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
4637
4740
|
_a.functionType = 'EveryPred',
|
|
4638
4741
|
_a.params = params,
|
|
4742
|
+
_a.paramCount = 1,
|
|
4639
4743
|
_a;
|
|
4640
4744
|
},
|
|
4641
4745
|
paramCount: { min: 1 },
|
|
@@ -4648,6 +4752,7 @@ var functionalNormalExpression = {
|
|
|
4648
4752
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
4649
4753
|
_a.functionType = 'SomePred',
|
|
4650
4754
|
_a.params = params,
|
|
4755
|
+
_a.paramCount = 1,
|
|
4651
4756
|
_a;
|
|
4652
4757
|
},
|
|
4653
4758
|
paramCount: { min: 1 },
|
|
@@ -4656,12 +4761,14 @@ var functionalNormalExpression = {
|
|
|
4656
4761
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4657
4762
|
var _b;
|
|
4658
4763
|
var _c = __read(_a), fn = _c[0], params = _c.slice(1);
|
|
4764
|
+
var fun = asFunctionLike(fn, sourceCodeInfo);
|
|
4659
4765
|
return _b = {},
|
|
4660
4766
|
_b[FUNCTION_SYMBOL] = true,
|
|
4661
4767
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4662
4768
|
_b.functionType = 'Fnull',
|
|
4663
|
-
_b.function =
|
|
4769
|
+
_b.function = fun,
|
|
4664
4770
|
_b.params = params,
|
|
4771
|
+
_b.paramCount = getParamCountFromFunction(fun),
|
|
4665
4772
|
_b;
|
|
4666
4773
|
},
|
|
4667
4774
|
paramCount: { min: 2 },
|
|
@@ -11736,12 +11843,16 @@ var functionSpecialExpression = {
|
|
|
11736
11843
|
assertUserDefinedSymbolNode(functionSymbol, node[2]);
|
|
11737
11844
|
assertNameNotDefined(functionSymbol[1], contextStack, builtin, node[2]);
|
|
11738
11845
|
var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
|
|
11846
|
+
var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
11847
|
+
var max = evaluatedFunction[0].some(function (arg) { return arg[0] === bindingTargetTypes.rest; }) ? undefined : evaluatedFunction[0].length;
|
|
11848
|
+
var paramCount = min === max ? min : { min: min, max: max };
|
|
11739
11849
|
var litsFunction = (_b = {},
|
|
11740
11850
|
_b[FUNCTION_SYMBOL] = true,
|
|
11741
11851
|
_b.sourceCodeInfo = node[2],
|
|
11742
11852
|
_b.functionType = 'UserDefined',
|
|
11743
11853
|
_b.name = functionSymbol[1],
|
|
11744
11854
|
_b.evaluatedfunction = evaluatedFunction,
|
|
11855
|
+
_b.paramCount = paramCount,
|
|
11745
11856
|
_b);
|
|
11746
11857
|
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
11747
11858
|
return litsFunction;
|
|
@@ -11763,13 +11874,16 @@ var defnSpecialExpression = {
|
|
|
11763
11874
|
var _d = __read(node[1], 3), functionSymbol = _d[1], fn = _d[2];
|
|
11764
11875
|
assertUserDefinedSymbolNode(functionSymbol, node[2]);
|
|
11765
11876
|
assertNameNotDefined(functionSymbol[1], contextStack, builtin, node[2]);
|
|
11766
|
-
var
|
|
11877
|
+
var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
|
|
11878
|
+
var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
11879
|
+
var paramCount = { min: min };
|
|
11767
11880
|
var litsFunction = (_b = {},
|
|
11768
11881
|
_b[FUNCTION_SYMBOL] = true,
|
|
11769
11882
|
_b.sourceCodeInfo = node[2],
|
|
11770
11883
|
_b.functionType = 'UserDefined',
|
|
11771
11884
|
_b.name = functionSymbol[1],
|
|
11772
|
-
_b.evaluatedfunction =
|
|
11885
|
+
_b.evaluatedfunction = evaluatedFunction,
|
|
11886
|
+
_b.paramCount = paramCount,
|
|
11773
11887
|
_b);
|
|
11774
11888
|
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
11775
11889
|
return litsFunction;
|
|
@@ -11791,12 +11905,16 @@ var fnSpecialExpression = {
|
|
|
11791
11905
|
var builtin = _a.builtin, getUndefinedSymbols = _a.getUndefinedSymbols, evaluateNode = _a.evaluateNode;
|
|
11792
11906
|
var fn = node[1][1];
|
|
11793
11907
|
var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
|
|
11908
|
+
var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
11909
|
+
var max = evaluatedFunction[0].some(function (arg) { return arg[0] === bindingTargetTypes.rest; }) ? undefined : evaluatedFunction[0].length;
|
|
11910
|
+
var paramCount = min === max ? min : { min: min, max: max };
|
|
11794
11911
|
var litsFunction = (_b = {},
|
|
11795
11912
|
_b[FUNCTION_SYMBOL] = true,
|
|
11796
11913
|
_b.sourceCodeInfo = node[2],
|
|
11797
11914
|
_b.functionType = 'UserDefined',
|
|
11798
11915
|
_b.name = undefined,
|
|
11799
11916
|
_b.evaluatedfunction = evaluatedFunction,
|
|
11917
|
+
_b.paramCount = paramCount,
|
|
11800
11918
|
_b);
|
|
11801
11919
|
return litsFunction;
|
|
11802
11920
|
},
|
|
@@ -12412,12 +12530,6 @@ new Set(specialExpressionKeys);
|
|
|
12412
12530
|
// TODO, remove
|
|
12413
12531
|
// console.log('builtin', [...specialExpressionKeys, ...normalExpressionKeys].length)
|
|
12414
12532
|
|
|
12415
|
-
function checkParams(evaluatedFunction, nbrOfParams, sourceCodeInfo) {
|
|
12416
|
-
var minArity = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
12417
|
-
if (nbrOfParams < minArity) {
|
|
12418
|
-
throw new LitsError("Unexpected number of arguments. Expected at least ".concat(minArity, ", got ").concat(nbrOfParams, "."), sourceCodeInfo);
|
|
12419
|
-
}
|
|
12420
|
-
}
|
|
12421
12533
|
var functionExecutors = {
|
|
12422
12534
|
NativeJsFunction: function (fn, params, sourceCodeInfo) {
|
|
12423
12535
|
var _a;
|
|
@@ -12437,7 +12549,10 @@ var functionExecutors = {
|
|
|
12437
12549
|
var evaluateNode = _a.evaluateNode;
|
|
12438
12550
|
var _loop_1 = function () {
|
|
12439
12551
|
var e_1, _b;
|
|
12440
|
-
|
|
12552
|
+
if (!paramCountAcceptsMin(fn.paramCount, params.length)) {
|
|
12553
|
+
throw new LitsError("Expected ".concat(fn.paramCount, " arguments, got ").concat(params.length, "."), sourceCodeInfo);
|
|
12554
|
+
}
|
|
12555
|
+
// checkParams(fn.evaluatedfunction, params.length, sourceCodeInfo)
|
|
12441
12556
|
var evaluatedFunction = fn.evaluatedfunction;
|
|
12442
12557
|
var args = evaluatedFunction[0];
|
|
12443
12558
|
var nbrOfNonRestArgs = args.filter(function (arg) { return arg[0] !== bindingTargetTypes.rest; }).length;
|
|
@@ -12734,6 +12849,7 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12734
12849
|
_a.params = params,
|
|
12735
12850
|
_a.placeholders = placeholders,
|
|
12736
12851
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
12852
|
+
_a.paramCount = placeholders.length,
|
|
12737
12853
|
_a);
|
|
12738
12854
|
return partialFunction;
|
|
12739
12855
|
}
|
|
@@ -12756,11 +12872,12 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12756
12872
|
if (placeholders.length > 0) {
|
|
12757
12873
|
var partialFunction = (_b = {},
|
|
12758
12874
|
_b[FUNCTION_SYMBOL] = true,
|
|
12759
|
-
_b.function =
|
|
12875
|
+
_b.function = fn,
|
|
12760
12876
|
_b.functionType = 'Partial',
|
|
12761
12877
|
_b.params = params,
|
|
12762
12878
|
_b.placeholders = placeholders,
|
|
12763
12879
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
12880
|
+
_b.paramCount = placeholders.length,
|
|
12764
12881
|
_b);
|
|
12765
12882
|
return partialFunction;
|
|
12766
12883
|
}
|
|
@@ -12982,11 +13099,13 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
12982
13099
|
}
|
|
12983
13100
|
if (isNormalBuiltinSymbolNode(node)) {
|
|
12984
13101
|
var type = node[1];
|
|
13102
|
+
var normalExpression = allNormalExpressions[type];
|
|
12985
13103
|
return _b = {},
|
|
12986
13104
|
_b[FUNCTION_SYMBOL] = true,
|
|
12987
13105
|
_b.functionType = 'Builtin',
|
|
12988
13106
|
_b.normalBuitinSymbolType = type,
|
|
12989
13107
|
_b.sourceCodeInfo = node[2],
|
|
13108
|
+
_b.paramCount = normalExpression.paramCount,
|
|
12990
13109
|
_b;
|
|
12991
13110
|
}
|
|
12992
13111
|
var lookUpResult = this.lookUp(node);
|
|
@@ -13008,7 +13127,8 @@ function createContextStack(params) {
|
|
|
13008
13127
|
nativeJsFunctions: params.jsFunctions
|
|
13009
13128
|
&& Object.entries(params.jsFunctions).reduce(function (acc, _a) {
|
|
13010
13129
|
var _b;
|
|
13011
|
-
var _c
|
|
13130
|
+
var _c;
|
|
13131
|
+
var _d = __read(_a, 2), name = _d[0], jsFunction = _d[1];
|
|
13012
13132
|
if (specialExpressionKeys.includes(name)) {
|
|
13013
13133
|
console.warn("Cannot shadow special expression \"".concat(name, "\", ignoring."));
|
|
13014
13134
|
return acc;
|
|
@@ -13023,6 +13143,7 @@ function createContextStack(params) {
|
|
|
13023
13143
|
name: name
|
|
13024
13144
|
},
|
|
13025
13145
|
_b[FUNCTION_SYMBOL] = true,
|
|
13146
|
+
_b.paramCount = (_c = jsFunction.paramCount) !== null && _c !== void 0 ? _c : {},
|
|
13026
13147
|
_b);
|
|
13027
13148
|
return acc;
|
|
13028
13149
|
}, {}),
|
|
@@ -3,6 +3,7 @@ import type { Any } from '../interface';
|
|
|
3
3
|
import type { Ast, LitsFunction } from '../parser/types';
|
|
4
4
|
import type { TokenStream } from '../tokenizer/tokenize';
|
|
5
5
|
import { AutoCompleter } from '../AutoCompleter/AutoCompleter';
|
|
6
|
+
import type { ParamCount } from '../builtin/interface';
|
|
6
7
|
import { Cache } from './Cache';
|
|
7
8
|
export interface LitsRuntimeInfo {
|
|
8
9
|
astCache: Cache | null;
|
|
@@ -11,6 +12,7 @@ export interface LitsRuntimeInfo {
|
|
|
11
12
|
}
|
|
12
13
|
export interface JsFunction {
|
|
13
14
|
fn: (...args: any[]) => unknown;
|
|
15
|
+
paramCount?: ParamCount;
|
|
14
16
|
}
|
|
15
17
|
export interface ContextParams {
|
|
16
18
|
globalContext?: Context;
|
|
@@ -5,7 +5,7 @@ import type { Any, Arr } from '../interface';
|
|
|
5
5
|
import type { SpecialExpressionNode } from '../parser/types';
|
|
6
6
|
import type { SourceCodeInfo } from '../tokenizer/token';
|
|
7
7
|
import type { SpecialExpressions } from '.';
|
|
8
|
-
export type
|
|
8
|
+
export type ParamCount = number | {
|
|
9
9
|
min?: number;
|
|
10
10
|
max?: number;
|
|
11
11
|
even?: true;
|
|
@@ -16,7 +16,7 @@ export type NormalExpressionEvaluator<T> = (params: Arr, sourceCodeInfo: SourceC
|
|
|
16
16
|
}) => T;
|
|
17
17
|
export interface BuiltinNormalExpression<T> {
|
|
18
18
|
evaluate: NormalExpressionEvaluator<T>;
|
|
19
|
-
paramCount:
|
|
19
|
+
paramCount: ParamCount;
|
|
20
20
|
aliases?: string[];
|
|
21
21
|
}
|
|
22
22
|
export type BuiltinNormalExpressions = Record<string, BuiltinNormalExpression<Any>>;
|
|
@@ -29,7 +29,7 @@ export interface EvaluateHelpers {
|
|
|
29
29
|
export interface BuiltinSpecialExpression<T, N extends SpecialExpressionNode> {
|
|
30
30
|
evaluate: (node: N, contextStack: ContextStack, helpers: EvaluateHelpers) => T;
|
|
31
31
|
evaluateAsNormalExpression?: NormalExpressionEvaluator<T>;
|
|
32
|
-
paramCount:
|
|
32
|
+
paramCount: ParamCount;
|
|
33
33
|
getUndefinedSymbols: (node: N, contextStack: ContextStack, params: {
|
|
34
34
|
getUndefinedSymbols: GetUndefinedSymbols;
|
|
35
35
|
builtin: Builtin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LitsFunction, type SpecialExpressionNode, type SymbolNode } from '../../parser/types';
|
|
2
2
|
import type { BuiltinSpecialExpression } from '../interface';
|
|
3
3
|
import type { Function } from '../utils';
|
|
4
4
|
import type { specialExpressionTypes } from '../specialExpressionTypes';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JsFunction } from '../Lits/Lits';
|
|
2
2
|
import type { SpecialExpressionType } from '../builtin';
|
|
3
|
+
import type { ParamCount } from '../builtin/interface';
|
|
3
4
|
import type { specialExpressionTypes } from '../builtin/specialExpressionTypes';
|
|
4
5
|
import type { FunctionType, NodeType, NodeTypes } from '../constants/constants';
|
|
5
6
|
import type { Context } from '../evaluator/interface';
|
|
@@ -15,6 +16,7 @@ interface GenericLitsFunction {
|
|
|
15
16
|
[FUNCTION_SYMBOL]: true;
|
|
16
17
|
sourceCodeInfo?: SourceCodeInfo;
|
|
17
18
|
functionType: FunctionType;
|
|
19
|
+
paramCount: ParamCount;
|
|
18
20
|
}
|
|
19
21
|
export interface RegularExpression {
|
|
20
22
|
[REGEXP_SYMBOL]: true;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ParamCount } from '../builtin/interface';
|
|
2
2
|
import type { UnknownRecord } from '../interface';
|
|
3
3
|
import type { NormalExpressionNodeWithName } from '../parser/types';
|
|
4
4
|
import type { SourceCodeInfo } from '../tokenizer/token';
|
|
5
|
-
export declare function assertNumberOfParams(count:
|
|
5
|
+
export declare function assertNumberOfParams(count: ParamCount, node: NormalExpressionNodeWithName): void;
|
|
6
6
|
export declare function isNonUndefined<T>(value: T | undefined): value is T;
|
|
7
7
|
export declare function asNonUndefined<T>(value: T | undefined, sourceCodeInfo?: SourceCodeInfo): T;
|
|
8
8
|
export declare function assertNonUndefined<T>(value: T | undefined, sourceCodeInfo?: SourceCodeInfo): asserts value is T;
|
|
9
9
|
export declare function isUnknownRecord(value: unknown): value is Record<string, unknown>;
|
|
10
10
|
export declare function assertUnknownRecord(value: unknown, sourceCodeInfo?: SourceCodeInfo): asserts value is UnknownRecord;
|
|
11
11
|
export declare function asUnknownRecord(value: unknown, sourceCodeInfo?: SourceCodeInfo): UnknownRecord;
|
|
12
|
-
export declare function canBeOperator(count:
|
|
12
|
+
export declare function canBeOperator(count: ParamCount): boolean;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Any, Coll } from '../interface';
|
|
2
|
-
import type { NativeJsFunction } from '../parser/types';
|
|
3
2
|
import type { SourceCodeInfo } from '../tokenizer/token';
|
|
4
3
|
export declare function collHasKey(coll: unknown, key: string | number): boolean;
|
|
5
4
|
export declare function compare<T extends string | number>(a: T, b: T, sourceCodeInfo: SourceCodeInfo | undefined): number;
|
|
@@ -7,7 +6,6 @@ export declare function deepEqual(a: unknown, b: unknown, sourceCodeInfo?: Sourc
|
|
|
7
6
|
export declare function toNonNegativeInteger(num: number): number;
|
|
8
7
|
export declare function toAny(value: unknown): Any;
|
|
9
8
|
export declare function cloneColl<T extends Coll>(value: T): T;
|
|
10
|
-
export declare function createNativeJsFunction(fn: (...args: any[]) => unknown, name?: string): NativeJsFunction;
|
|
11
9
|
export declare function joinSets<T>(...results: Set<T>[]): Set<T>;
|
|
12
10
|
export declare function addToSet<T>(target: Set<T>, source: Set<T>): void;
|
|
13
11
|
export declare const EPSILON = 1e-10;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ParamCount } from '../builtin/interface';
|
|
2
|
+
import type { FunctionLike, NormalExpressionNodeWithName } from '../parser/types';
|
|
3
|
+
export declare function paramCountAccepts(paramsCount: ParamCount, nbrOfParams: number): boolean;
|
|
4
|
+
export declare function paramCountAcceptsMin(paramsCount: ParamCount, nbrOfParams: number): boolean;
|
|
5
|
+
export declare function getCommonParamCountFromFunctions(params: FunctionLike[]): ParamCount | null;
|
|
6
|
+
export declare function getParamCountFromFunction(param: FunctionLike): ParamCount;
|
|
7
|
+
export declare function assertNumberOfParams(count: ParamCount, node: NormalExpressionNodeWithName): void;
|