pacc 6.8.1 → 6.9.1
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/package.json +2 -2
- package/src/expression.mjs +50 -16
- package/types/expression.d.mts +10 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pacc",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.9.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"ava": "^6.4.1",
|
|
42
|
-
"browser-ava": "^2.3.
|
|
42
|
+
"browser-ava": "^2.3.50",
|
|
43
43
|
"c8": "^10.1.3",
|
|
44
44
|
"documentation": "^14.0.3",
|
|
45
45
|
"semantic-release": "^25.0.2",
|
package/src/expression.mjs
CHANGED
|
@@ -53,19 +53,39 @@ export function binop(op, left, right, fallback) {
|
|
|
53
53
|
return fallback(op, left, right);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @param {string} message
|
|
59
|
+
*/
|
|
60
|
+
function error(message) {
|
|
61
|
+
const error = new Error(message);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
* @param {Token} op
|
|
67
|
+
* @param {AST} left
|
|
68
|
+
* @param {AST} right
|
|
69
|
+
*/
|
|
70
|
+
function binopError(op, left, right) {
|
|
71
|
+
error(`Unexpected '${op.str || op}'`);
|
|
72
|
+
}
|
|
73
|
+
|
|
56
74
|
export function parse(input, context = { globals }) {
|
|
57
75
|
input = tokens(input);
|
|
58
76
|
|
|
59
77
|
let node, token, value;
|
|
60
78
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
79
|
+
const predicateIteratorEval = (node, current) => {
|
|
80
|
+
if (current instanceof Set) {
|
|
81
|
+
current = [...current];
|
|
82
|
+
} else if (current instanceof Map) {
|
|
83
|
+
current = [...current.values()];
|
|
84
|
+
}
|
|
85
|
+
return current
|
|
86
|
+
.filter(item => node.predicate(node, item))
|
|
87
|
+
.map(item => node.right.eval(node.right, item));
|
|
88
|
+
};
|
|
69
89
|
const pathEval = (node, current) => {
|
|
70
90
|
let result = current;
|
|
71
91
|
|
|
@@ -207,15 +227,26 @@ export function parse(input, context = { globals }) {
|
|
|
207
227
|
}
|
|
208
228
|
}
|
|
209
229
|
if (last === DOT) {
|
|
210
|
-
if (left.path) {
|
|
211
|
-
left.path.push(...right.path);
|
|
212
|
-
return left;
|
|
213
|
-
}
|
|
214
230
|
switch (typeof left) {
|
|
215
231
|
case "number":
|
|
216
232
|
right.path.unshift(left);
|
|
217
233
|
return right;
|
|
218
234
|
}
|
|
235
|
+
|
|
236
|
+
if (left.path) {
|
|
237
|
+
left.path.push(...right.path);
|
|
238
|
+
return left;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (left.eval) {
|
|
242
|
+
return {
|
|
243
|
+
eval: predicateIteratorEval,
|
|
244
|
+
predicate: left.eval,
|
|
245
|
+
right
|
|
246
|
+
// path: right.path
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
219
250
|
return { eval: pathEval, path: [left.token, right.token] };
|
|
220
251
|
}
|
|
221
252
|
|
|
@@ -312,10 +343,13 @@ export const globals = {
|
|
|
312
343
|
}
|
|
313
344
|
return false;
|
|
314
345
|
},
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
346
|
+
ceil: Math.ceil,
|
|
347
|
+
floor: Math.floor,
|
|
348
|
+
abs: Math.abs,
|
|
349
|
+
min: Math.min,
|
|
350
|
+
max: Math.max,
|
|
351
|
+
uppercase: a => a.toUpperCase(),
|
|
352
|
+
lowercase: a => a.toLowerCase(),
|
|
319
353
|
substring: (s, a, b) => s.substring(a, b),
|
|
320
354
|
length: s => s.length
|
|
321
355
|
};
|
package/types/expression.d.mts
CHANGED
|
@@ -2,8 +2,11 @@ export function binop(op: any, left: any, right: any, fallback: any): any;
|
|
|
2
2
|
export function parse(input: any, context?: {
|
|
3
3
|
globals: {
|
|
4
4
|
in: (a: any, b: any) => boolean;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
ceil: (x: number) => number;
|
|
6
|
+
floor: (x: number) => number;
|
|
7
|
+
abs: (x: number) => number;
|
|
8
|
+
min: (...values: number[]) => number;
|
|
9
|
+
max: (...values: number[]) => number;
|
|
7
10
|
uppercase: (a: any) => any;
|
|
8
11
|
lowercase: (a: any) => any;
|
|
9
12
|
substring: (s: any, a: any, b: any) => any;
|
|
@@ -13,8 +16,11 @@ export function parse(input: any, context?: {
|
|
|
13
16
|
export namespace globals {
|
|
14
17
|
export function _in(a: any, b: any): boolean;
|
|
15
18
|
export { _in as in };
|
|
16
|
-
export
|
|
17
|
-
export
|
|
19
|
+
export let ceil: (x: number) => number;
|
|
20
|
+
export let floor: (x: number) => number;
|
|
21
|
+
export let abs: (x: number) => number;
|
|
22
|
+
export let min: (...values: number[]) => number;
|
|
23
|
+
export let max: (...values: number[]) => number;
|
|
18
24
|
export function uppercase(a: any): any;
|
|
19
25
|
export function lowercase(a: any): any;
|
|
20
26
|
export function substring(s: any, a: any, b: any): any;
|