@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/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;
|
|
@@ -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';
|
package/dist/src/index.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ export { normalExpressionKeys, specialExpressionKeys } from './builtin';
|
|
|
8
8
|
export { Lits } from './Lits/Lits';
|
|
9
9
|
export { type LitsError, isLitsError } from './errors';
|
|
10
10
|
export type { ContextParams, FilePathParams, MinifyParams, LitsRuntimeInfo, JsFunction } from './Lits/Lits';
|
|
11
|
-
export { createNativeJsFunction } from './utils';
|
|
12
11
|
export { apiReference, isDatatypeReference, isFunctionReference, isShorthandReference } from '../reference';
|
|
13
12
|
export type { Argument, CommonReference, DatatypeReference, FunctionReference, Reference, ShorthandReference } from '../reference';
|
|
14
13
|
export type { ApiName, FunctionName, ShorthandName, DatatypeName } from '../reference/api';
|
|
@@ -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;
|
|
@@ -4526,6 +4526,98 @@ function applyPlaceholders(templateString, placeholders, sourceCodeInfo) {
|
|
|
4526
4526
|
return templateString;
|
|
4527
4527
|
}
|
|
4528
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
|
+
|
|
4529
4621
|
var functionalNormalExpression = {
|
|
4530
4622
|
'|>': {
|
|
4531
4623
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
@@ -4559,11 +4651,13 @@ var functionalNormalExpression = {
|
|
|
4559
4651
|
'comp': {
|
|
4560
4652
|
evaluate: function (params, sourceCodeInfo) {
|
|
4561
4653
|
var _a;
|
|
4654
|
+
params.forEach(function (param) { return assertFunctionLike(param, sourceCodeInfo); });
|
|
4562
4655
|
return _a = {},
|
|
4563
4656
|
_a[FUNCTION_SYMBOL] = true,
|
|
4564
4657
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
4565
4658
|
_a.functionType = 'Comp',
|
|
4566
4659
|
_a.params = params,
|
|
4660
|
+
_a.paramCount = params.length > 0 ? getParamCountFromFunction(params.at(-1)) : 1,
|
|
4567
4661
|
_a;
|
|
4568
4662
|
},
|
|
4569
4663
|
paramCount: {},
|
|
@@ -4577,6 +4671,7 @@ var functionalNormalExpression = {
|
|
|
4577
4671
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4578
4672
|
_b.functionType = 'Constantly',
|
|
4579
4673
|
_b.value = toAny(value),
|
|
4674
|
+
_b.paramCount = {},
|
|
4580
4675
|
_b;
|
|
4581
4676
|
},
|
|
4582
4677
|
paramCount: 1,
|
|
@@ -4584,11 +4679,17 @@ var functionalNormalExpression = {
|
|
|
4584
4679
|
'juxt': {
|
|
4585
4680
|
evaluate: function (params, sourceCodeInfo) {
|
|
4586
4681
|
var _a;
|
|
4682
|
+
params.forEach(function (param) { return assertFunctionLike(param, sourceCodeInfo); });
|
|
4683
|
+
var paramCount = getCommonParamCountFromFunctions(params);
|
|
4684
|
+
if (paramCount === null) {
|
|
4685
|
+
throw new LitsError('All functions must accept the same number of arguments', sourceCodeInfo);
|
|
4686
|
+
}
|
|
4587
4687
|
return _a = {},
|
|
4588
4688
|
_a[FUNCTION_SYMBOL] = true,
|
|
4589
4689
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
4590
4690
|
_a.functionType = 'Juxt',
|
|
4591
4691
|
_a.params = params,
|
|
4692
|
+
_a.paramCount = paramCount,
|
|
4592
4693
|
_a;
|
|
4593
4694
|
},
|
|
4594
4695
|
paramCount: { min: 1 },
|
|
@@ -4597,11 +4698,13 @@ var functionalNormalExpression = {
|
|
|
4597
4698
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4598
4699
|
var _b;
|
|
4599
4700
|
var _c = __read(_a, 1), fn = _c[0];
|
|
4701
|
+
var fun = asFunctionLike(fn, sourceCodeInfo);
|
|
4600
4702
|
return _b = {},
|
|
4601
4703
|
_b[FUNCTION_SYMBOL] = true,
|
|
4602
4704
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4603
4705
|
_b.functionType = 'Complement',
|
|
4604
|
-
_b.function =
|
|
4706
|
+
_b.function = fun,
|
|
4707
|
+
_b.paramCount = getParamCountFromFunction(fun),
|
|
4605
4708
|
_b;
|
|
4606
4709
|
},
|
|
4607
4710
|
paramCount: 1,
|
|
@@ -4614,6 +4717,7 @@ var functionalNormalExpression = {
|
|
|
4614
4717
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
4615
4718
|
_a.functionType = 'EveryPred',
|
|
4616
4719
|
_a.params = params,
|
|
4720
|
+
_a.paramCount = 1,
|
|
4617
4721
|
_a;
|
|
4618
4722
|
},
|
|
4619
4723
|
paramCount: { min: 1 },
|
|
@@ -4626,6 +4730,7 @@ var functionalNormalExpression = {
|
|
|
4626
4730
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
4627
4731
|
_a.functionType = 'SomePred',
|
|
4628
4732
|
_a.params = params,
|
|
4733
|
+
_a.paramCount = 1,
|
|
4629
4734
|
_a;
|
|
4630
4735
|
},
|
|
4631
4736
|
paramCount: { min: 1 },
|
|
@@ -4634,12 +4739,14 @@ var functionalNormalExpression = {
|
|
|
4634
4739
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4635
4740
|
var _b;
|
|
4636
4741
|
var _c = __read(_a), fn = _c[0], params = _c.slice(1);
|
|
4742
|
+
var fun = asFunctionLike(fn, sourceCodeInfo);
|
|
4637
4743
|
return _b = {},
|
|
4638
4744
|
_b[FUNCTION_SYMBOL] = true,
|
|
4639
4745
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4640
4746
|
_b.functionType = 'Fnull',
|
|
4641
|
-
_b.function =
|
|
4747
|
+
_b.function = fun,
|
|
4642
4748
|
_b.params = params,
|
|
4749
|
+
_b.paramCount = getParamCountFromFunction(fun),
|
|
4643
4750
|
_b;
|
|
4644
4751
|
},
|
|
4645
4752
|
paramCount: { min: 2 },
|
|
@@ -11714,12 +11821,16 @@ var functionSpecialExpression = {
|
|
|
11714
11821
|
assertUserDefinedSymbolNode(functionSymbol, node[2]);
|
|
11715
11822
|
assertNameNotDefined(functionSymbol[1], contextStack, builtin, node[2]);
|
|
11716
11823
|
var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
|
|
11824
|
+
var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
11825
|
+
var max = evaluatedFunction[0].some(function (arg) { return arg[0] === bindingTargetTypes.rest; }) ? undefined : evaluatedFunction[0].length;
|
|
11826
|
+
var paramCount = min === max ? min : { min: min, max: max };
|
|
11717
11827
|
var litsFunction = (_b = {},
|
|
11718
11828
|
_b[FUNCTION_SYMBOL] = true,
|
|
11719
11829
|
_b.sourceCodeInfo = node[2],
|
|
11720
11830
|
_b.functionType = 'UserDefined',
|
|
11721
11831
|
_b.name = functionSymbol[1],
|
|
11722
11832
|
_b.evaluatedfunction = evaluatedFunction,
|
|
11833
|
+
_b.paramCount = paramCount,
|
|
11723
11834
|
_b);
|
|
11724
11835
|
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
11725
11836
|
return litsFunction;
|
|
@@ -11741,13 +11852,16 @@ var defnSpecialExpression = {
|
|
|
11741
11852
|
var _d = __read(node[1], 3), functionSymbol = _d[1], fn = _d[2];
|
|
11742
11853
|
assertUserDefinedSymbolNode(functionSymbol, node[2]);
|
|
11743
11854
|
assertNameNotDefined(functionSymbol[1], contextStack, builtin, node[2]);
|
|
11744
|
-
var
|
|
11855
|
+
var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
|
|
11856
|
+
var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
11857
|
+
var paramCount = { min: min };
|
|
11745
11858
|
var litsFunction = (_b = {},
|
|
11746
11859
|
_b[FUNCTION_SYMBOL] = true,
|
|
11747
11860
|
_b.sourceCodeInfo = node[2],
|
|
11748
11861
|
_b.functionType = 'UserDefined',
|
|
11749
11862
|
_b.name = functionSymbol[1],
|
|
11750
|
-
_b.evaluatedfunction =
|
|
11863
|
+
_b.evaluatedfunction = evaluatedFunction,
|
|
11864
|
+
_b.paramCount = paramCount,
|
|
11751
11865
|
_b);
|
|
11752
11866
|
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
11753
11867
|
return litsFunction;
|
|
@@ -11769,12 +11883,16 @@ var fnSpecialExpression = {
|
|
|
11769
11883
|
var builtin = _a.builtin, getUndefinedSymbols = _a.getUndefinedSymbols, evaluateNode = _a.evaluateNode;
|
|
11770
11884
|
var fn = node[1][1];
|
|
11771
11885
|
var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
|
|
11886
|
+
var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
11887
|
+
var max = evaluatedFunction[0].some(function (arg) { return arg[0] === bindingTargetTypes.rest; }) ? undefined : evaluatedFunction[0].length;
|
|
11888
|
+
var paramCount = min === max ? min : { min: min, max: max };
|
|
11772
11889
|
var litsFunction = (_b = {},
|
|
11773
11890
|
_b[FUNCTION_SYMBOL] = true,
|
|
11774
11891
|
_b.sourceCodeInfo = node[2],
|
|
11775
11892
|
_b.functionType = 'UserDefined',
|
|
11776
11893
|
_b.name = undefined,
|
|
11777
11894
|
_b.evaluatedfunction = evaluatedFunction,
|
|
11895
|
+
_b.paramCount = paramCount,
|
|
11778
11896
|
_b);
|
|
11779
11897
|
return litsFunction;
|
|
11780
11898
|
},
|
|
@@ -12390,12 +12508,6 @@ new Set(specialExpressionKeys);
|
|
|
12390
12508
|
// TODO, remove
|
|
12391
12509
|
// console.log('builtin', [...specialExpressionKeys, ...normalExpressionKeys].length)
|
|
12392
12510
|
|
|
12393
|
-
function checkParams(evaluatedFunction, nbrOfParams, sourceCodeInfo) {
|
|
12394
|
-
var minArity = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
12395
|
-
if (nbrOfParams < minArity) {
|
|
12396
|
-
throw new LitsError("Unexpected number of arguments. Expected at least ".concat(minArity, ", got ").concat(nbrOfParams, "."), sourceCodeInfo);
|
|
12397
|
-
}
|
|
12398
|
-
}
|
|
12399
12511
|
var functionExecutors = {
|
|
12400
12512
|
NativeJsFunction: function (fn, params, sourceCodeInfo) {
|
|
12401
12513
|
var _a;
|
|
@@ -12415,7 +12527,10 @@ var functionExecutors = {
|
|
|
12415
12527
|
var evaluateNode = _a.evaluateNode;
|
|
12416
12528
|
var _loop_1 = function () {
|
|
12417
12529
|
var e_1, _b;
|
|
12418
|
-
|
|
12530
|
+
if (!paramCountAcceptsMin(fn.paramCount, params.length)) {
|
|
12531
|
+
throw new LitsError("Expected ".concat(fn.paramCount, " arguments, got ").concat(params.length, "."), sourceCodeInfo);
|
|
12532
|
+
}
|
|
12533
|
+
// checkParams(fn.evaluatedfunction, params.length, sourceCodeInfo)
|
|
12419
12534
|
var evaluatedFunction = fn.evaluatedfunction;
|
|
12420
12535
|
var args = evaluatedFunction[0];
|
|
12421
12536
|
var nbrOfNonRestArgs = args.filter(function (arg) { return arg[0] !== bindingTargetTypes.rest; }).length;
|
|
@@ -12712,6 +12827,7 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12712
12827
|
_a.params = params,
|
|
12713
12828
|
_a.placeholders = placeholders,
|
|
12714
12829
|
_a.sourceCodeInfo = sourceCodeInfo,
|
|
12830
|
+
_a.paramCount = placeholders.length,
|
|
12715
12831
|
_a);
|
|
12716
12832
|
return partialFunction;
|
|
12717
12833
|
}
|
|
@@ -12734,11 +12850,12 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12734
12850
|
if (placeholders.length > 0) {
|
|
12735
12851
|
var partialFunction = (_b = {},
|
|
12736
12852
|
_b[FUNCTION_SYMBOL] = true,
|
|
12737
|
-
_b.function =
|
|
12853
|
+
_b.function = fn,
|
|
12738
12854
|
_b.functionType = 'Partial',
|
|
12739
12855
|
_b.params = params,
|
|
12740
12856
|
_b.placeholders = placeholders,
|
|
12741
12857
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
12858
|
+
_b.paramCount = placeholders.length,
|
|
12742
12859
|
_b);
|
|
12743
12860
|
return partialFunction;
|
|
12744
12861
|
}
|
|
@@ -12960,11 +13077,13 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
12960
13077
|
}
|
|
12961
13078
|
if (isNormalBuiltinSymbolNode(node)) {
|
|
12962
13079
|
var type = node[1];
|
|
13080
|
+
var normalExpression = allNormalExpressions[type];
|
|
12963
13081
|
return _b = {},
|
|
12964
13082
|
_b[FUNCTION_SYMBOL] = true,
|
|
12965
13083
|
_b.functionType = 'Builtin',
|
|
12966
13084
|
_b.normalBuitinSymbolType = type,
|
|
12967
13085
|
_b.sourceCodeInfo = node[2],
|
|
13086
|
+
_b.paramCount = normalExpression.paramCount,
|
|
12968
13087
|
_b;
|
|
12969
13088
|
}
|
|
12970
13089
|
var lookUpResult = this.lookUp(node);
|
|
@@ -12986,7 +13105,8 @@ function createContextStack(params) {
|
|
|
12986
13105
|
nativeJsFunctions: params.jsFunctions
|
|
12987
13106
|
&& Object.entries(params.jsFunctions).reduce(function (acc, _a) {
|
|
12988
13107
|
var _b;
|
|
12989
|
-
var _c
|
|
13108
|
+
var _c;
|
|
13109
|
+
var _d = __read(_a, 2), name = _d[0], jsFunction = _d[1];
|
|
12990
13110
|
if (specialExpressionKeys.includes(name)) {
|
|
12991
13111
|
console.warn("Cannot shadow special expression \"".concat(name, "\", ignoring."));
|
|
12992
13112
|
return acc;
|
|
@@ -13001,6 +13121,7 @@ function createContextStack(params) {
|
|
|
13001
13121
|
name: name
|
|
13002
13122
|
},
|
|
13003
13123
|
_b[FUNCTION_SYMBOL] = true,
|
|
13124
|
+
_b.paramCount = (_c = jsFunction.paramCount) !== null && _c !== void 0 ? _c : {},
|
|
13004
13125
|
_b);
|
|
13005
13126
|
return acc;
|
|
13006
13127
|
}, {}),
|