@mojir/lits 2.1.20 → 2.1.22
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 +129 -16
- 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/tokenizer/reservedNames.d.ts +1 -39
- package/dist/cli/src/tokenizer/token.d.ts +5 -5
- package/dist/cli/src/typeGuards/index.d.ts +3 -3
- package/dist/cli/src/utils/index.d.ts +8 -1
- package/dist/index.esm.js +129 -15
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +129 -15
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +129 -15
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/builtin/interface.d.ts +3 -3
- package/dist/src/builtin/specialExpressions/functions.d.ts +1 -1
- package/dist/src/parser/types.d.ts +2 -0
- package/dist/src/tokenizer/reservedNames.d.ts +1 -39
- package/dist/src/tokenizer/token.d.ts +5 -5
- package/dist/src/typeGuards/index.d.ts +3 -3
- package/dist/src/utils/index.d.ts +8 -1
- package/dist/testFramework.esm.js +128 -15
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +128 -15
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -58,44 +58,6 @@ export declare const reservedSymbolRecord: {
|
|
|
58
58
|
readonly as: null;
|
|
59
59
|
readonly _: null;
|
|
60
60
|
};
|
|
61
|
-
export declare const validReservedSymbolRecord: {
|
|
62
|
-
readonly E: number;
|
|
63
|
-
readonly '-E': number;
|
|
64
|
-
readonly ε: number;
|
|
65
|
-
readonly '-\u03B5': number;
|
|
66
|
-
readonly PI: number;
|
|
67
|
-
readonly '-PI': number;
|
|
68
|
-
readonly π: number;
|
|
69
|
-
readonly '-\u03C0': number;
|
|
70
|
-
readonly PHI: number;
|
|
71
|
-
readonly '-PHI': number;
|
|
72
|
-
readonly φ: number;
|
|
73
|
-
readonly '-\u03C6': number;
|
|
74
|
-
readonly POSITIVE_INFINITY: number;
|
|
75
|
-
readonly '\u221E': number;
|
|
76
|
-
readonly NEGATIVE_INFINITY: number;
|
|
77
|
-
readonly '-\u221E': number;
|
|
78
|
-
readonly MAX_SAFE_INTEGER: number;
|
|
79
|
-
readonly MIN_SAFE_INTEGER: number;
|
|
80
|
-
readonly MAX_VALUE: number;
|
|
81
|
-
readonly MIN_VALUE: number;
|
|
82
|
-
readonly NaN: number;
|
|
83
|
-
readonly true: true;
|
|
84
|
-
readonly false: false;
|
|
85
|
-
readonly null: null;
|
|
86
|
-
readonly else: null;
|
|
87
|
-
readonly case: null;
|
|
88
|
-
readonly each: null;
|
|
89
|
-
readonly in: null;
|
|
90
|
-
readonly when: null;
|
|
91
|
-
readonly while: null;
|
|
92
|
-
readonly catch: null;
|
|
93
|
-
readonly function: null;
|
|
94
|
-
readonly export: null;
|
|
95
|
-
readonly as: null;
|
|
96
|
-
readonly _: null;
|
|
97
|
-
};
|
|
98
|
-
export type ValidReservedSymbol = keyof typeof validReservedSymbolRecord;
|
|
99
61
|
export type ReservedSymbol = keyof typeof reservedSymbolRecord;
|
|
100
|
-
export declare function isReservedSymbol(symbol: string): symbol is keyof typeof
|
|
62
|
+
export declare function isReservedSymbol(symbol: string): symbol is keyof typeof reservedSymbolRecord;
|
|
101
63
|
export declare function isNumberReservedSymbol(symbol: string): symbol is keyof typeof numberReservedSymbolRecord;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReservedSymbol } from './reservedNames';
|
|
2
2
|
import { type SymbolicBinaryOperator, type SymbolicOperator } from './operators';
|
|
3
3
|
export declare const tokenTypes: readonly ["LBrace", "LBracket", "RBrace", "RBracket", "LParen", "RParen", "BasePrefixedNumber", "MultiLineComment", "Number", "Operator", "RegexpShorthand", "ReservedSymbol", "SingleLineComment", "String", "Symbol", "Whitespace"];
|
|
4
4
|
export type TokenType = typeof tokenTypes[number];
|
|
@@ -16,7 +16,7 @@ export type MultiLineCommentToken = GenericToken<'MultiLineComment'>;
|
|
|
16
16
|
export type NumberToken = GenericToken<'Number'>;
|
|
17
17
|
export type OperatorToken<T extends SymbolicOperator = SymbolicOperator> = GenericToken<'Operator', T>;
|
|
18
18
|
export type RegexpShorthandToken = GenericToken<'RegexpShorthand'>;
|
|
19
|
-
export type ReservedSymbolToken<T extends
|
|
19
|
+
export type ReservedSymbolToken<T extends ReservedSymbol = ReservedSymbol> = GenericToken<'ReservedSymbol', T>;
|
|
20
20
|
export type SingleLineCommentToken = GenericToken<'SingleLineComment'>;
|
|
21
21
|
export type StringToken = GenericToken<'String'>;
|
|
22
22
|
export type SymbolToken<T extends string = string> = GenericToken<'Symbol', T>;
|
|
@@ -34,9 +34,9 @@ export interface SourceCodeInfo {
|
|
|
34
34
|
export declare function isSymbolToken<T extends string>(token: Token | undefined | undefined, symbolName?: T): token is SymbolToken<T>;
|
|
35
35
|
export declare function assertSymbolToken<T extends string>(token: Token | undefined | undefined, symbolName?: T): asserts token is SymbolToken<T>;
|
|
36
36
|
export declare function asSymbolToken<T extends string>(token: Token | undefined | undefined, symbolName?: T): SymbolToken<T>;
|
|
37
|
-
export declare function isReservedSymbolToken<T extends
|
|
38
|
-
export declare function assertReservedSymbolToken<T extends
|
|
39
|
-
export declare function asReservedSymbolToken<T extends
|
|
37
|
+
export declare function isReservedSymbolToken<T extends ReservedSymbol>(token: Token | undefined | undefined, symbolName?: T): token is ReservedSymbolToken<T>;
|
|
38
|
+
export declare function assertReservedSymbolToken<T extends ReservedSymbol>(token: Token | undefined | undefined, symbolName?: T): asserts token is ReservedSymbolToken<T>;
|
|
39
|
+
export declare function asReservedSymbolToken<T extends ReservedSymbol>(token: Token | undefined | undefined, symbolName?: T): ReservedSymbolToken<T>;
|
|
40
40
|
export declare function isSingleLineCommentToken(token: Token | undefined): token is SingleLineCommentToken;
|
|
41
41
|
export declare function assertSingleLineCommentToken(token: Token | undefined): asserts token is SingleLineCommentToken;
|
|
42
42
|
export declare function asSingleLineCommentToken(token: Token | undefined): SingleLineCommentToken;
|
|
@@ -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,6 +1,7 @@
|
|
|
1
1
|
import type { Any, Coll } from '../interface';
|
|
2
|
-
import type { NativeJsFunction } from '../parser/types';
|
|
2
|
+
import type { FunctionLike, NativeJsFunction, NormalExpressionNodeWithName } from '../parser/types';
|
|
3
3
|
import type { SourceCodeInfo } from '../tokenizer/token';
|
|
4
|
+
import type { ParamCount } from '../builtin/interface';
|
|
4
5
|
export declare function collHasKey(coll: unknown, key: string | number): boolean;
|
|
5
6
|
export declare function compare<T extends string | number>(a: T, b: T, sourceCodeInfo: SourceCodeInfo | undefined): number;
|
|
6
7
|
export declare function deepEqual(a: unknown, b: unknown, sourceCodeInfo?: SourceCodeInfo): boolean;
|
|
@@ -13,3 +14,9 @@ export declare function addToSet<T>(target: Set<T>, source: Set<T>): void;
|
|
|
13
14
|
export declare const EPSILON = 1e-10;
|
|
14
15
|
export declare function approxEqual(a: number, b: number, epsilon?: number): boolean;
|
|
15
16
|
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;
|
|
@@ -896,6 +896,91 @@ 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
|
+
}
|
|
899
984
|
|
|
900
985
|
// isArray not needed, use Array.isArary
|
|
901
986
|
function asArray(value, sourceCodeInfo) {
|
|
@@ -4559,11 +4644,13 @@ var functionalNormalExpression = {
|
|
|
4559
4644
|
'comp': {
|
|
4560
4645
|
evaluate: function (params, sourceCodeInfo) {
|
|
4561
4646
|
var _a;
|
|
4647
|
+
params.forEach(function (param) { return assertFunctionLike(param, sourceCodeInfo); });
|
|
4562
4648
|
return _a = {},
|
|
4563
4649
|
_a[FUNCTION_SYMBOL] = true,
|
|
4564
4650
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
4565
4651
|
_a.functionType = 'Comp',
|
|
4566
4652
|
_a.params = params,
|
|
4653
|
+
_a.paramCount = params.length > 0 ? getParamCount(params.at(-1)) : 1,
|
|
4567
4654
|
_a;
|
|
4568
4655
|
},
|
|
4569
4656
|
paramCount: {},
|
|
@@ -4577,6 +4664,7 @@ var functionalNormalExpression = {
|
|
|
4577
4664
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4578
4665
|
_b.functionType = 'Constantly',
|
|
4579
4666
|
_b.value = toAny(value),
|
|
4667
|
+
_b.paramCount = {},
|
|
4580
4668
|
_b;
|
|
4581
4669
|
},
|
|
4582
4670
|
paramCount: 1,
|
|
@@ -4584,11 +4672,17 @@ var functionalNormalExpression = {
|
|
|
4584
4672
|
'juxt': {
|
|
4585
4673
|
evaluate: function (params, sourceCodeInfo) {
|
|
4586
4674
|
var _a;
|
|
4675
|
+
params.forEach(function (param) { return assertFunctionLike(param, sourceCodeInfo); });
|
|
4676
|
+
var paramCount = getCommonParamCount(params);
|
|
4677
|
+
if (paramCount === null) {
|
|
4678
|
+
throw new LitsError('All functions must accept the same number of arguments', sourceCodeInfo);
|
|
4679
|
+
}
|
|
4587
4680
|
return _a = {},
|
|
4588
4681
|
_a[FUNCTION_SYMBOL] = true,
|
|
4589
4682
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
4590
4683
|
_a.functionType = 'Juxt',
|
|
4591
4684
|
_a.params = params,
|
|
4685
|
+
_a.paramCount = paramCount,
|
|
4592
4686
|
_a;
|
|
4593
4687
|
},
|
|
4594
4688
|
paramCount: { min: 1 },
|
|
@@ -4597,11 +4691,13 @@ var functionalNormalExpression = {
|
|
|
4597
4691
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4598
4692
|
var _b;
|
|
4599
4693
|
var _c = __read(_a, 1), fn = _c[0];
|
|
4694
|
+
var fun = asFunctionLike(fn, sourceCodeInfo);
|
|
4600
4695
|
return _b = {},
|
|
4601
4696
|
_b[FUNCTION_SYMBOL] = true,
|
|
4602
4697
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4603
4698
|
_b.functionType = 'Complement',
|
|
4604
|
-
_b.function =
|
|
4699
|
+
_b.function = fun,
|
|
4700
|
+
_b.paramCount = getParamCount(fun),
|
|
4605
4701
|
_b;
|
|
4606
4702
|
},
|
|
4607
4703
|
paramCount: 1,
|
|
@@ -4614,6 +4710,7 @@ var functionalNormalExpression = {
|
|
|
4614
4710
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
4615
4711
|
_a.functionType = 'EveryPred',
|
|
4616
4712
|
_a.params = params,
|
|
4713
|
+
_a.paramCount = 1,
|
|
4617
4714
|
_a;
|
|
4618
4715
|
},
|
|
4619
4716
|
paramCount: { min: 1 },
|
|
@@ -4626,6 +4723,7 @@ var functionalNormalExpression = {
|
|
|
4626
4723
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
4627
4724
|
_a.functionType = 'SomePred',
|
|
4628
4725
|
_a.params = params,
|
|
4726
|
+
_a.paramCount = 1,
|
|
4629
4727
|
_a;
|
|
4630
4728
|
},
|
|
4631
4729
|
paramCount: { min: 1 },
|
|
@@ -4634,12 +4732,14 @@ var functionalNormalExpression = {
|
|
|
4634
4732
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4635
4733
|
var _b;
|
|
4636
4734
|
var _c = __read(_a), fn = _c[0], params = _c.slice(1);
|
|
4735
|
+
var fun = asFunctionLike(fn, sourceCodeInfo);
|
|
4637
4736
|
return _b = {},
|
|
4638
4737
|
_b[FUNCTION_SYMBOL] = true,
|
|
4639
4738
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4640
4739
|
_b.functionType = 'Fnull',
|
|
4641
|
-
_b.function =
|
|
4740
|
+
_b.function = fun,
|
|
4642
4741
|
_b.params = params,
|
|
4742
|
+
_b.paramCount = getParamCount(fun),
|
|
4643
4743
|
_b;
|
|
4644
4744
|
},
|
|
4645
4745
|
paramCount: { min: 2 },
|
|
@@ -11684,9 +11784,8 @@ var numberReservedSymbolRecord = {
|
|
|
11684
11784
|
'NaN': Number.NaN,
|
|
11685
11785
|
};
|
|
11686
11786
|
var reservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
|
|
11687
|
-
var validReservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
|
|
11688
11787
|
function isReservedSymbol(symbol) {
|
|
11689
|
-
return symbol in
|
|
11788
|
+
return symbol in reservedSymbolRecord;
|
|
11690
11789
|
}
|
|
11691
11790
|
function isNumberReservedSymbol(symbol) {
|
|
11692
11791
|
return symbol in numberReservedSymbolRecord;
|
|
@@ -11715,12 +11814,16 @@ var functionSpecialExpression = {
|
|
|
11715
11814
|
assertUserDefinedSymbolNode(functionSymbol, node[2]);
|
|
11716
11815
|
assertNameNotDefined(functionSymbol[1], contextStack, builtin, node[2]);
|
|
11717
11816
|
var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
|
|
11817
|
+
var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
11818
|
+
var max = evaluatedFunction[0].some(function (arg) { return arg[0] === bindingTargetTypes.rest; }) ? undefined : evaluatedFunction[0].length;
|
|
11819
|
+
var paramCount = min === max ? min : { min: min, max: max };
|
|
11718
11820
|
var litsFunction = (_b = {},
|
|
11719
11821
|
_b[FUNCTION_SYMBOL] = true,
|
|
11720
11822
|
_b.sourceCodeInfo = node[2],
|
|
11721
11823
|
_b.functionType = 'UserDefined',
|
|
11722
11824
|
_b.name = functionSymbol[1],
|
|
11723
11825
|
_b.evaluatedfunction = evaluatedFunction,
|
|
11826
|
+
_b.paramCount = paramCount,
|
|
11724
11827
|
_b);
|
|
11725
11828
|
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
11726
11829
|
return litsFunction;
|
|
@@ -11742,13 +11845,17 @@ var defnSpecialExpression = {
|
|
|
11742
11845
|
var _d = __read(node[1], 3), functionSymbol = _d[1], fn = _d[2];
|
|
11743
11846
|
assertUserDefinedSymbolNode(functionSymbol, node[2]);
|
|
11744
11847
|
assertNameNotDefined(functionSymbol[1], contextStack, builtin, node[2]);
|
|
11745
|
-
var
|
|
11848
|
+
var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
|
|
11849
|
+
var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
11850
|
+
var max = evaluatedFunction[0].some(function (arg) { return arg[0] === bindingTargetTypes.rest; }) ? undefined : evaluatedFunction[0].length;
|
|
11851
|
+
var paramCount = min === max ? min : { min: min, max: max };
|
|
11746
11852
|
var litsFunction = (_b = {},
|
|
11747
11853
|
_b[FUNCTION_SYMBOL] = true,
|
|
11748
11854
|
_b.sourceCodeInfo = node[2],
|
|
11749
11855
|
_b.functionType = 'UserDefined',
|
|
11750
11856
|
_b.name = functionSymbol[1],
|
|
11751
|
-
_b.evaluatedfunction =
|
|
11857
|
+
_b.evaluatedfunction = evaluatedFunction,
|
|
11858
|
+
_b.paramCount = paramCount,
|
|
11752
11859
|
_b);
|
|
11753
11860
|
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
11754
11861
|
return litsFunction;
|
|
@@ -11770,12 +11877,16 @@ var fnSpecialExpression = {
|
|
|
11770
11877
|
var builtin = _a.builtin, getUndefinedSymbols = _a.getUndefinedSymbols, evaluateNode = _a.evaluateNode;
|
|
11771
11878
|
var fn = node[1][1];
|
|
11772
11879
|
var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
|
|
11880
|
+
var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
11881
|
+
var max = evaluatedFunction[0].some(function (arg) { return arg[0] === bindingTargetTypes.rest; }) ? undefined : evaluatedFunction[0].length;
|
|
11882
|
+
var paramCount = min === max ? min : { min: min, max: max };
|
|
11773
11883
|
var litsFunction = (_b = {},
|
|
11774
11884
|
_b[FUNCTION_SYMBOL] = true,
|
|
11775
11885
|
_b.sourceCodeInfo = node[2],
|
|
11776
11886
|
_b.functionType = 'UserDefined',
|
|
11777
11887
|
_b.name = undefined,
|
|
11778
11888
|
_b.evaluatedfunction = evaluatedFunction,
|
|
11889
|
+
_b.paramCount = paramCount,
|
|
11779
11890
|
_b);
|
|
11780
11891
|
return litsFunction;
|
|
11781
11892
|
},
|
|
@@ -12391,12 +12502,6 @@ new Set(specialExpressionKeys);
|
|
|
12391
12502
|
// TODO, remove
|
|
12392
12503
|
// console.log('builtin', [...specialExpressionKeys, ...normalExpressionKeys].length)
|
|
12393
12504
|
|
|
12394
|
-
function checkParams(evaluatedFunction, nbrOfParams, sourceCodeInfo) {
|
|
12395
|
-
var minArity = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
12396
|
-
if (nbrOfParams < minArity) {
|
|
12397
|
-
throw new LitsError("Unexpected number of arguments. Expected at least ".concat(minArity, ", got ").concat(nbrOfParams, "."), sourceCodeInfo);
|
|
12398
|
-
}
|
|
12399
|
-
}
|
|
12400
12505
|
var functionExecutors = {
|
|
12401
12506
|
NativeJsFunction: function (fn, params, sourceCodeInfo) {
|
|
12402
12507
|
var _a;
|
|
@@ -12416,7 +12521,10 @@ var functionExecutors = {
|
|
|
12416
12521
|
var evaluateNode = _a.evaluateNode;
|
|
12417
12522
|
var _loop_1 = function () {
|
|
12418
12523
|
var e_1, _b;
|
|
12419
|
-
|
|
12524
|
+
if (!paramCountAcceptsMin(fn.paramCount, params.length)) {
|
|
12525
|
+
throw new LitsError("Expected ".concat(fn.paramCount, " arguments, got ").concat(params.length, "."), sourceCodeInfo);
|
|
12526
|
+
}
|
|
12527
|
+
// checkParams(fn.evaluatedfunction, params.length, sourceCodeInfo)
|
|
12420
12528
|
var evaluatedFunction = fn.evaluatedfunction;
|
|
12421
12529
|
var args = evaluatedFunction[0];
|
|
12422
12530
|
var nbrOfNonRestArgs = args.filter(function (arg) { return arg[0] !== bindingTargetTypes.rest; }).length;
|
|
@@ -12713,6 +12821,7 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12713
12821
|
_a.params = params,
|
|
12714
12822
|
_a.placeholders = placeholders,
|
|
12715
12823
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
12824
|
+
_a.paramCount = paramCountMinus(getParamCount(fn), params.length),
|
|
12716
12825
|
_a);
|
|
12717
12826
|
return partialFunction;
|
|
12718
12827
|
}
|
|
@@ -12735,11 +12844,12 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12735
12844
|
if (placeholders.length > 0) {
|
|
12736
12845
|
var partialFunction = (_b = {},
|
|
12737
12846
|
_b[FUNCTION_SYMBOL] = true,
|
|
12738
|
-
_b.function =
|
|
12847
|
+
_b.function = fn,
|
|
12739
12848
|
_b.functionType = 'Partial',
|
|
12740
12849
|
_b.params = params,
|
|
12741
12850
|
_b.placeholders = placeholders,
|
|
12742
12851
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
12852
|
+
_b.paramCount = paramCountMinus(getParamCount(fn), params.length),
|
|
12743
12853
|
_b);
|
|
12744
12854
|
return partialFunction;
|
|
12745
12855
|
}
|
|
@@ -12961,11 +13071,13 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
12961
13071
|
}
|
|
12962
13072
|
if (isNormalBuiltinSymbolNode(node)) {
|
|
12963
13073
|
var type = node[1];
|
|
13074
|
+
var normalExpression = allNormalExpressions[type];
|
|
12964
13075
|
return _b = {},
|
|
12965
13076
|
_b[FUNCTION_SYMBOL] = true,
|
|
12966
13077
|
_b.functionType = 'Builtin',
|
|
12967
13078
|
_b.normalBuitinSymbolType = type,
|
|
12968
13079
|
_b.sourceCodeInfo = node[2],
|
|
13080
|
+
_b.paramCount = normalExpression.paramCount,
|
|
12969
13081
|
_b;
|
|
12970
13082
|
}
|
|
12971
13083
|
var lookUpResult = this.lookUp(node);
|
|
@@ -13002,6 +13114,7 @@ function createContextStack(params) {
|
|
|
13002
13114
|
name: name
|
|
13003
13115
|
},
|
|
13004
13116
|
_b[FUNCTION_SYMBOL] = true,
|
|
13117
|
+
_b.paramCount = {},
|
|
13005
13118
|
_b);
|
|
13006
13119
|
return acc;
|
|
13007
13120
|
}, {}),
|
|
@@ -14800,7 +14913,7 @@ var Parser = /** @class */ (function () {
|
|
|
14800
14913
|
return Parser;
|
|
14801
14914
|
}());
|
|
14802
14915
|
|
|
14803
|
-
var litsCommands = new Set(__spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false));
|
|
14916
|
+
var litsCommands = new Set(__spreadArray(__spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false), __read(Object.keys(reservedSymbolRecord)), false));
|
|
14804
14917
|
// TODO: replace with get suggestions function
|
|
14805
14918
|
var AutoCompleter = /** @class */ (function () {
|
|
14806
14919
|
function AutoCompleter(originalProgram, originalPosition, lits, params) {
|