@mojir/lits 2.1.22 → 2.1.24
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 +104 -98
- package/dist/cli/src/Lits/Lits.d.ts +2 -0
- package/dist/cli/src/utils/index.d.ts +0 -9
- package/dist/cli/src/utils/paramCount.d.ts +7 -0
- package/dist/index.esm.js +104 -110
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +103 -110
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +103 -110
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/Lits/Lits.d.ts +2 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/utils/index.d.ts +0 -9
- package/dist/src/utils/paramCount.d.ts +7 -0
- package/dist/testFramework.esm.js +103 -97
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +103 -97
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/src/Lits/Lits.d.ts
CHANGED
|
@@ -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;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { isBuiltinFunction, isLitsFunction, asLitsFunction, assertLitsFunction, isUserDefinedFunction, asUserDefinedFunction, assertUserDefinedFunction, isNativeJsFunction, asNativeJsFunction, assertNativeJsFunction, } from './typeGuards/litsFunction';
|
|
2
|
+
export { type ParamCount } from './builtin/interface';
|
|
2
3
|
export { type LitsFunction, type NativeJsFunction } from './parser/types';
|
|
3
4
|
export type { Context } from './evaluator/interface';
|
|
4
5
|
export type { Ast } from './parser/types';
|
|
@@ -8,7 +9,6 @@ export { normalExpressionKeys, specialExpressionKeys } from './builtin';
|
|
|
8
9
|
export { Lits } from './Lits/Lits';
|
|
9
10
|
export { type LitsError, isLitsError } from './errors';
|
|
10
11
|
export type { ContextParams, FilePathParams, MinifyParams, LitsRuntimeInfo, JsFunction } from './Lits/Lits';
|
|
11
|
-
export { createNativeJsFunction } from './utils';
|
|
12
12
|
export { apiReference, isDatatypeReference, isFunctionReference, isShorthandReference } from '../reference';
|
|
13
13
|
export type { Argument, CommonReference, DatatypeReference, FunctionReference, Reference, ShorthandReference } from '../reference';
|
|
14
14
|
export type { ApiName, FunctionName, ShorthandName, DatatypeName } from '../reference/api';
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import type { Any, Coll } from '../interface';
|
|
2
|
-
import type { FunctionLike, NativeJsFunction, NormalExpressionNodeWithName } from '../parser/types';
|
|
3
2
|
import type { SourceCodeInfo } from '../tokenizer/token';
|
|
4
|
-
import type { ParamCount } from '../builtin/interface';
|
|
5
3
|
export declare function collHasKey(coll: unknown, key: string | number): boolean;
|
|
6
4
|
export declare function compare<T extends string | number>(a: T, b: T, sourceCodeInfo: SourceCodeInfo | undefined): number;
|
|
7
5
|
export declare function deepEqual(a: unknown, b: unknown, sourceCodeInfo?: SourceCodeInfo): boolean;
|
|
8
6
|
export declare function toNonNegativeInteger(num: number): number;
|
|
9
7
|
export declare function toAny(value: unknown): Any;
|
|
10
8
|
export declare function cloneColl<T extends Coll>(value: T): T;
|
|
11
|
-
export declare function createNativeJsFunction(fn: (...args: any[]) => unknown, name?: string): NativeJsFunction;
|
|
12
9
|
export declare function joinSets<T>(...results: Set<T>[]): Set<T>;
|
|
13
10
|
export declare function addToSet<T>(target: Set<T>, source: Set<T>): void;
|
|
14
11
|
export declare const EPSILON = 1e-10;
|
|
15
12
|
export declare function approxEqual(a: number, b: number, epsilon?: number): boolean;
|
|
16
13
|
export declare function approxZero(value: number): boolean;
|
|
17
|
-
export declare function mergeParamCounts(count: ParamCount, node: NormalExpressionNodeWithName): void;
|
|
18
|
-
export declare function assertNumberOfParams(count: ParamCount, node: NormalExpressionNodeWithName): void;
|
|
19
|
-
export declare function paramCountAcceptsMin(paramsCount: ParamCount, nbrOfParams: number): boolean;
|
|
20
|
-
export declare function getCommonParamCount(params: FunctionLike[]): ParamCount | null;
|
|
21
|
-
export declare function getParamCount(param: FunctionLike): ParamCount;
|
|
22
|
-
export declare function paramCountMinus(paramCount: ParamCount, count: number): ParamCount;
|
|
@@ -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;
|
|
@@ -896,91 +896,6 @@ function approxEqual(a, b, epsilon) {
|
|
|
896
896
|
function approxZero(value) {
|
|
897
897
|
return Math.abs(value) < EPSILON;
|
|
898
898
|
}
|
|
899
|
-
function paramCountAccepts(paramsCount, nbrOfParams) {
|
|
900
|
-
if (typeof paramsCount === 'number') {
|
|
901
|
-
return paramsCount === nbrOfParams;
|
|
902
|
-
}
|
|
903
|
-
var min = paramsCount.min, max = paramsCount.max, even = paramsCount.even, odd = paramsCount.odd;
|
|
904
|
-
if (even && nbrOfParams % 2 !== 0) {
|
|
905
|
-
return false;
|
|
906
|
-
}
|
|
907
|
-
if (odd && nbrOfParams % 2 !== 1) {
|
|
908
|
-
return false;
|
|
909
|
-
}
|
|
910
|
-
if (typeof min === 'number' && nbrOfParams < min) {
|
|
911
|
-
return false;
|
|
912
|
-
}
|
|
913
|
-
if (typeof max === 'number' && nbrOfParams > max) {
|
|
914
|
-
return false;
|
|
915
|
-
}
|
|
916
|
-
return true;
|
|
917
|
-
}
|
|
918
|
-
function paramCountAcceptsMin(paramsCount, nbrOfParams) {
|
|
919
|
-
if (typeof paramsCount === 'number') {
|
|
920
|
-
return nbrOfParams >= paramsCount;
|
|
921
|
-
}
|
|
922
|
-
var min = paramsCount.min;
|
|
923
|
-
if (typeof min === 'number' && nbrOfParams < min) {
|
|
924
|
-
return false;
|
|
925
|
-
}
|
|
926
|
-
return true;
|
|
927
|
-
}
|
|
928
|
-
function getCommonParamCount(params) {
|
|
929
|
-
return params.reduce(function (acc, param) {
|
|
930
|
-
if (acc === null) {
|
|
931
|
-
return null;
|
|
932
|
-
}
|
|
933
|
-
var paramCount = (typeof param === 'number' || isColl(param)) ? 1 : param.paramCount;
|
|
934
|
-
if (typeof acc === 'number' && typeof paramCount === 'number') {
|
|
935
|
-
return acc === paramCount ? acc : null;
|
|
936
|
-
}
|
|
937
|
-
if (typeof paramCount === 'number') {
|
|
938
|
-
if (paramCountAccepts(acc, paramCount)) {
|
|
939
|
-
return paramCount;
|
|
940
|
-
}
|
|
941
|
-
return null;
|
|
942
|
-
}
|
|
943
|
-
if (typeof acc === 'number') {
|
|
944
|
-
if (paramCountAccepts(paramCount, acc)) {
|
|
945
|
-
return acc;
|
|
946
|
-
}
|
|
947
|
-
return null;
|
|
948
|
-
}
|
|
949
|
-
var aMin = paramCount.min, aMax = paramCount.max, aEven = paramCount.even, aOdd = paramCount.odd;
|
|
950
|
-
var bMin = acc.min, bMax = acc.max, bEven = acc.even, bOdd = acc.odd;
|
|
951
|
-
var min = typeof aMin === 'number' && typeof bMin === 'number'
|
|
952
|
-
? Math.max(aMin, bMin)
|
|
953
|
-
: typeof aMin === 'number' ? aMin : typeof bMin === 'number' ? bMin : undefined;
|
|
954
|
-
var max = typeof aMax === 'number' && typeof bMax === 'number'
|
|
955
|
-
? Math.min(aMax, bMax)
|
|
956
|
-
: typeof aMax === 'number' ? aMax : typeof bMax === 'number' ? bMax : undefined;
|
|
957
|
-
var even = aEven !== null && aEven !== void 0 ? aEven : bEven;
|
|
958
|
-
var odd = aOdd !== null && aOdd !== void 0 ? aOdd : bOdd;
|
|
959
|
-
if (min !== undefined && max !== undefined && min > max) {
|
|
960
|
-
return null;
|
|
961
|
-
}
|
|
962
|
-
if (even && odd) {
|
|
963
|
-
return null;
|
|
964
|
-
}
|
|
965
|
-
if (odd && min !== undefined && min < 1) {
|
|
966
|
-
return null;
|
|
967
|
-
}
|
|
968
|
-
return { min: min, max: max, even: even, odd: odd };
|
|
969
|
-
}, {});
|
|
970
|
-
}
|
|
971
|
-
function getParamCount(param) {
|
|
972
|
-
return (typeof param === 'number' || isColl(param)) ? 1 : param.paramCount;
|
|
973
|
-
}
|
|
974
|
-
function paramCountMinus(paramCount, count) {
|
|
975
|
-
if (typeof paramCount === 'number') {
|
|
976
|
-
return paramCount - count;
|
|
977
|
-
}
|
|
978
|
-
var min = paramCount.min === undefined ? undefined : paramCount.min - count;
|
|
979
|
-
var max = paramCount.max === undefined ? undefined : paramCount.max - count;
|
|
980
|
-
var even = paramCount.even === undefined ? undefined : count % 2 === 0 ? true : undefined;
|
|
981
|
-
var odd = paramCount.odd === undefined ? undefined : count % 2 === 0 ? true : undefined;
|
|
982
|
-
return { min: min, max: max, even: even, odd: odd };
|
|
983
|
-
}
|
|
984
899
|
|
|
985
900
|
// isArray not needed, use Array.isArary
|
|
986
901
|
function asArray(value, sourceCodeInfo) {
|
|
@@ -4611,6 +4526,98 @@ function applyPlaceholders(templateString, placeholders, sourceCodeInfo) {
|
|
|
4611
4526
|
return templateString;
|
|
4612
4527
|
}
|
|
4613
4528
|
|
|
4529
|
+
function paramCountAccepts(paramsCount, nbrOfParams) {
|
|
4530
|
+
if (typeof paramsCount === 'number') {
|
|
4531
|
+
return paramsCount === nbrOfParams;
|
|
4532
|
+
}
|
|
4533
|
+
var min = paramsCount.min, max = paramsCount.max, even = paramsCount.even, odd = paramsCount.odd;
|
|
4534
|
+
if (even && nbrOfParams % 2 !== 0) {
|
|
4535
|
+
return false;
|
|
4536
|
+
}
|
|
4537
|
+
if (odd && nbrOfParams % 2 !== 1) {
|
|
4538
|
+
return false;
|
|
4539
|
+
}
|
|
4540
|
+
if (typeof min === 'number' && nbrOfParams < min) {
|
|
4541
|
+
return false;
|
|
4542
|
+
}
|
|
4543
|
+
if (typeof max === 'number' && nbrOfParams > max) {
|
|
4544
|
+
return false;
|
|
4545
|
+
}
|
|
4546
|
+
return true;
|
|
4547
|
+
}
|
|
4548
|
+
function paramCountAcceptsMin(paramsCount, nbrOfParams) {
|
|
4549
|
+
if (typeof paramsCount === 'number') {
|
|
4550
|
+
return nbrOfParams >= paramsCount;
|
|
4551
|
+
}
|
|
4552
|
+
var min = paramsCount.min;
|
|
4553
|
+
if (typeof min === 'number' && nbrOfParams < min) {
|
|
4554
|
+
return false;
|
|
4555
|
+
}
|
|
4556
|
+
return true;
|
|
4557
|
+
}
|
|
4558
|
+
function getCommonParamCountFromFunctions(params) {
|
|
4559
|
+
return params.reduce(function (acc, param) {
|
|
4560
|
+
if (acc === null) {
|
|
4561
|
+
return null;
|
|
4562
|
+
}
|
|
4563
|
+
var paramCount = (typeof param === 'number' || isColl(param)) ? 1 : param.paramCount;
|
|
4564
|
+
if (typeof acc === 'number' && typeof paramCount === 'number') {
|
|
4565
|
+
return acc === paramCount ? acc : null;
|
|
4566
|
+
}
|
|
4567
|
+
if (typeof paramCount === 'number') {
|
|
4568
|
+
if (paramCountAccepts(acc, paramCount)) {
|
|
4569
|
+
return paramCount;
|
|
4570
|
+
}
|
|
4571
|
+
return null;
|
|
4572
|
+
}
|
|
4573
|
+
if (typeof acc === 'number') {
|
|
4574
|
+
if (paramCountAccepts(paramCount, acc)) {
|
|
4575
|
+
return acc;
|
|
4576
|
+
}
|
|
4577
|
+
return null;
|
|
4578
|
+
}
|
|
4579
|
+
var aMin = paramCount.min, aMax = paramCount.max, aEven = paramCount.even, aOdd = paramCount.odd;
|
|
4580
|
+
var bMin = acc.min, bMax = acc.max, bEven = acc.even, bOdd = acc.odd;
|
|
4581
|
+
var min = typeof aMin === 'number' && typeof bMin === 'number'
|
|
4582
|
+
? Math.max(aMin, bMin)
|
|
4583
|
+
: typeof aMin === 'number' ? aMin : typeof bMin === 'number' ? bMin : undefined;
|
|
4584
|
+
var max = typeof aMax === 'number' && typeof bMax === 'number'
|
|
4585
|
+
? Math.min(aMax, bMax)
|
|
4586
|
+
: typeof aMax === 'number' ? aMax : typeof bMax === 'number' ? bMax : undefined;
|
|
4587
|
+
var even = aEven !== null && aEven !== void 0 ? aEven : bEven;
|
|
4588
|
+
var odd = aOdd !== null && aOdd !== void 0 ? aOdd : bOdd;
|
|
4589
|
+
if (even && odd) {
|
|
4590
|
+
return null;
|
|
4591
|
+
}
|
|
4592
|
+
if (even) {
|
|
4593
|
+
if (typeof min === 'number' && min % 2 !== 0) {
|
|
4594
|
+
min += 1;
|
|
4595
|
+
}
|
|
4596
|
+
if (typeof max === 'number' && max % 2 !== 0) {
|
|
4597
|
+
max -= 1;
|
|
4598
|
+
}
|
|
4599
|
+
}
|
|
4600
|
+
if (odd) {
|
|
4601
|
+
if (typeof min === 'number' && min % 2 === 0) {
|
|
4602
|
+
min += 1;
|
|
4603
|
+
}
|
|
4604
|
+
if (typeof max === 'number' && max % 2 === 0) {
|
|
4605
|
+
max -= 1;
|
|
4606
|
+
}
|
|
4607
|
+
}
|
|
4608
|
+
if (typeof min === 'number' && typeof max === 'number' && min > max) {
|
|
4609
|
+
return null;
|
|
4610
|
+
}
|
|
4611
|
+
if (typeof min === 'number' && min === max) {
|
|
4612
|
+
return min;
|
|
4613
|
+
}
|
|
4614
|
+
return { min: min, max: max, even: even, odd: odd };
|
|
4615
|
+
}, {});
|
|
4616
|
+
}
|
|
4617
|
+
function getParamCountFromFunction(param) {
|
|
4618
|
+
return (typeof param === 'number' || isColl(param)) ? 1 : param.paramCount;
|
|
4619
|
+
}
|
|
4620
|
+
|
|
4614
4621
|
var functionalNormalExpression = {
|
|
4615
4622
|
'|>': {
|
|
4616
4623
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
@@ -4650,7 +4657,7 @@ var functionalNormalExpression = {
|
|
|
4650
4657
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
4651
4658
|
_a.functionType = 'Comp',
|
|
4652
4659
|
_a.params = params,
|
|
4653
|
-
_a.paramCount = params.length > 0 ?
|
|
4660
|
+
_a.paramCount = params.length > 0 ? getParamCountFromFunction(params.at(-1)) : 1,
|
|
4654
4661
|
_a;
|
|
4655
4662
|
},
|
|
4656
4663
|
paramCount: {},
|
|
@@ -4673,7 +4680,7 @@ var functionalNormalExpression = {
|
|
|
4673
4680
|
evaluate: function (params, sourceCodeInfo) {
|
|
4674
4681
|
var _a;
|
|
4675
4682
|
params.forEach(function (param) { return assertFunctionLike(param, sourceCodeInfo); });
|
|
4676
|
-
var paramCount =
|
|
4683
|
+
var paramCount = getCommonParamCountFromFunctions(params);
|
|
4677
4684
|
if (paramCount === null) {
|
|
4678
4685
|
throw new LitsError('All functions must accept the same number of arguments', sourceCodeInfo);
|
|
4679
4686
|
}
|
|
@@ -4697,7 +4704,7 @@ var functionalNormalExpression = {
|
|
|
4697
4704
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4698
4705
|
_b.functionType = 'Complement',
|
|
4699
4706
|
_b.function = fun,
|
|
4700
|
-
_b.paramCount =
|
|
4707
|
+
_b.paramCount = getParamCountFromFunction(fun),
|
|
4701
4708
|
_b;
|
|
4702
4709
|
},
|
|
4703
4710
|
paramCount: 1,
|
|
@@ -4739,7 +4746,7 @@ var functionalNormalExpression = {
|
|
|
4739
4746
|
_b.functionType = 'Fnull',
|
|
4740
4747
|
_b.function = fun,
|
|
4741
4748
|
_b.params = params,
|
|
4742
|
-
_b.paramCount =
|
|
4749
|
+
_b.paramCount = getParamCountFromFunction(fun),
|
|
4743
4750
|
_b;
|
|
4744
4751
|
},
|
|
4745
4752
|
paramCount: { min: 2 },
|
|
@@ -11847,8 +11854,7 @@ var defnSpecialExpression = {
|
|
|
11847
11854
|
assertNameNotDefined(functionSymbol[1], contextStack, builtin, node[2]);
|
|
11848
11855
|
var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
|
|
11849
11856
|
var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
11850
|
-
var
|
|
11851
|
-
var paramCount = min === max ? min : { min: min, max: max };
|
|
11857
|
+
var paramCount = { min: min };
|
|
11852
11858
|
var litsFunction = (_b = {},
|
|
11853
11859
|
_b[FUNCTION_SYMBOL] = true,
|
|
11854
11860
|
_b.sourceCodeInfo = node[2],
|
|
@@ -12821,7 +12827,7 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12821
12827
|
_a.params = params,
|
|
12822
12828
|
_a.placeholders = placeholders,
|
|
12823
12829
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
12824
|
-
_a.paramCount =
|
|
12830
|
+
_a.paramCount = placeholders.length,
|
|
12825
12831
|
_a);
|
|
12826
12832
|
return partialFunction;
|
|
12827
12833
|
}
|
|
@@ -12849,7 +12855,7 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12849
12855
|
_b.params = params,
|
|
12850
12856
|
_b.placeholders = placeholders,
|
|
12851
12857
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
12852
|
-
_b.paramCount =
|
|
12858
|
+
_b.paramCount = placeholders.length,
|
|
12853
12859
|
_b);
|
|
12854
12860
|
return partialFunction;
|
|
12855
12861
|
}
|
|
@@ -13099,7 +13105,8 @@ function createContextStack(params) {
|
|
|
13099
13105
|
nativeJsFunctions: params.jsFunctions
|
|
13100
13106
|
&& Object.entries(params.jsFunctions).reduce(function (acc, _a) {
|
|
13101
13107
|
var _b;
|
|
13102
|
-
var _c
|
|
13108
|
+
var _c;
|
|
13109
|
+
var _d = __read(_a, 2), name = _d[0], jsFunction = _d[1];
|
|
13103
13110
|
if (specialExpressionKeys.includes(name)) {
|
|
13104
13111
|
console.warn("Cannot shadow special expression \"".concat(name, "\", ignoring."));
|
|
13105
13112
|
return acc;
|
|
@@ -13114,7 +13121,7 @@ function createContextStack(params) {
|
|
|
13114
13121
|
name: name
|
|
13115
13122
|
},
|
|
13116
13123
|
_b[FUNCTION_SYMBOL] = true,
|
|
13117
|
-
_b.paramCount = {},
|
|
13124
|
+
_b.paramCount = (_c = jsFunction.paramCount) !== null && _c !== void 0 ? _c : {},
|
|
13118
13125
|
_b);
|
|
13119
13126
|
return acc;
|
|
13120
13127
|
}, {}),
|
|
@@ -13812,8 +13819,7 @@ function createNamedNormalExpressionNode(symbolNode, params, sourceCodeInfo) {
|
|
|
13812
13819
|
return node;
|
|
13813
13820
|
}
|
|
13814
13821
|
function createAccessorNode(left, right, sourceCodeInfo) {
|
|
13815
|
-
|
|
13816
|
-
return withSourceCodeInfo([NodeTypes.NormalExpression, [left, [right]]], sourceCodeInfo);
|
|
13822
|
+
return withSourceCodeInfo([NodeTypes.NormalExpression, [[NodeTypes.NormalBuiltinSymbol, normalExpressionTypes.get], [left, right]]], sourceCodeInfo);
|
|
13817
13823
|
}
|
|
13818
13824
|
function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeInfo) {
|
|
13819
13825
|
var operatorName = operator[1];
|