pacc 9.2.2 → 9.2.4
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 +1 -1
- package/src/ast.mjs +32 -20
- package/src/parser.mjs +2 -5
- package/src/tokens.mjs +13 -5
package/package.json
CHANGED
package/src/ast.mjs
CHANGED
|
@@ -19,26 +19,7 @@ export function keyedAccessOrGlobalEval(node, current, context) {
|
|
|
19
19
|
return keyedAccessEval(node, current, context) ?? context.valueFor(node.key);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
if (current === undefined) {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
if (current instanceof Map) {
|
|
27
|
-
return current.get(node.key);
|
|
28
|
-
}
|
|
29
|
-
if (current instanceof Set) {
|
|
30
|
-
return current.has(node.key) ? node.key : undefined;
|
|
31
|
-
}
|
|
32
|
-
if (current instanceof Iterator) {
|
|
33
|
-
if(typeof node.key === 'number') {
|
|
34
|
-
for(const item of current.drop(node.key)) {
|
|
35
|
-
return item;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return current.map(item => item[node.key]);
|
|
40
|
-
}
|
|
41
|
-
|
|
22
|
+
function scalarAccessEval(node, current, context) {
|
|
42
23
|
switch (typeof current[node.key]) {
|
|
43
24
|
case "function": {
|
|
44
25
|
const value = current[node.key]();
|
|
@@ -56,6 +37,37 @@ export function keyedAccessEval(node, current, context) {
|
|
|
56
37
|
return current[node.key];
|
|
57
38
|
}
|
|
58
39
|
|
|
40
|
+
function plain(value) {
|
|
41
|
+
if (typeof value === "function") {
|
|
42
|
+
return value();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function keyedAccessEval(node, current, context) {
|
|
49
|
+
if (current === undefined) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
if (current instanceof Map) {
|
|
53
|
+
return plain(current.get(node.key));
|
|
54
|
+
}
|
|
55
|
+
if (current instanceof Set) {
|
|
56
|
+
return current.has(node.key) ? node.key : undefined;
|
|
57
|
+
}
|
|
58
|
+
if (current instanceof Iterator) {
|
|
59
|
+
if (typeof node.key === "number") {
|
|
60
|
+
for (const item of current.drop(node.key)) {
|
|
61
|
+
return plain(item);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return current.map(item => scalarAccessEval(node, item, context));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return scalarAccessEval(node, current, context);
|
|
69
|
+
}
|
|
70
|
+
|
|
59
71
|
export function filterEval(node, current, context) {
|
|
60
72
|
if (typeof current.values === "function") {
|
|
61
73
|
current = current.values();
|
package/src/parser.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { tokens, EOF } from "./tokens.mjs";
|
|
|
3
3
|
export function parseOnly(input, context = {}) {
|
|
4
4
|
input = tokens(input, context);
|
|
5
5
|
|
|
6
|
-
let
|
|
6
|
+
let token, value;
|
|
7
7
|
|
|
8
8
|
function advance() {
|
|
9
9
|
const next = input.next();
|
|
@@ -18,9 +18,6 @@ export function parseOnly(input, context = {}) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const parser = {
|
|
21
|
-
get node() {
|
|
22
|
-
return node;
|
|
23
|
-
},
|
|
24
21
|
get token() {
|
|
25
22
|
return token;
|
|
26
23
|
},
|
|
@@ -40,7 +37,7 @@ export function parseOnly(input, context = {}) {
|
|
|
40
37
|
expression(precedence) {
|
|
41
38
|
const last = token;
|
|
42
39
|
advance();
|
|
43
|
-
node = last.nud(parser);
|
|
40
|
+
let node = last.nud(parser);
|
|
44
41
|
|
|
45
42
|
while (token.precedence > precedence) {
|
|
46
43
|
const last = token;
|
package/src/tokens.mjs
CHANGED
|
@@ -187,6 +187,13 @@ function createFilter(parser) {
|
|
|
187
187
|
case "number":
|
|
188
188
|
return { eval: keyedAccessEval, key: filter };
|
|
189
189
|
default:
|
|
190
|
+
if (
|
|
191
|
+
filter.eval === keyedAccessEval ||
|
|
192
|
+
filter.eval === keyedAccessOrGlobalEval
|
|
193
|
+
) {
|
|
194
|
+
return filter;
|
|
195
|
+
}
|
|
196
|
+
|
|
190
197
|
return { eval: filterEval, filter };
|
|
191
198
|
}
|
|
192
199
|
}
|
|
@@ -321,7 +328,7 @@ function evalOne(arg, current, context) {
|
|
|
321
328
|
}
|
|
322
329
|
|
|
323
330
|
export const globals = {
|
|
324
|
-
in: (args,current,context) => {
|
|
331
|
+
in: (args, current, context) => {
|
|
325
332
|
const a = evalOne(args[0], current, context);
|
|
326
333
|
const b = evalOne(args[1], current, context);
|
|
327
334
|
|
|
@@ -373,9 +380,9 @@ export const globals = {
|
|
|
373
380
|
const data = evalOne(args[0], current, context);
|
|
374
381
|
if (args.length >= 2) {
|
|
375
382
|
let order = 1;
|
|
376
|
-
if(args.length > 2) {
|
|
383
|
+
if (args.length > 2) {
|
|
377
384
|
const str = evalOne(args[2], current, context);
|
|
378
|
-
if(str ===
|
|
385
|
+
if (str === "descending") {
|
|
379
386
|
order = -1;
|
|
380
387
|
}
|
|
381
388
|
}
|
|
@@ -383,7 +390,8 @@ export const globals = {
|
|
|
383
390
|
return data.sort(
|
|
384
391
|
(a, b) =>
|
|
385
392
|
(selector.eval(selector, a, context) -
|
|
386
|
-
|
|
393
|
+
selector.eval(selector, b, context)) *
|
|
394
|
+
order
|
|
387
395
|
);
|
|
388
396
|
}
|
|
389
397
|
|
|
@@ -393,7 +401,7 @@ export const globals = {
|
|
|
393
401
|
const data = evalOne(args[0], current, context);
|
|
394
402
|
const length = evalOne(args[1], current, context);
|
|
395
403
|
|
|
396
|
-
if(data instanceof Iterator) {
|
|
404
|
+
if (data instanceof Iterator) {
|
|
397
405
|
return data.take(length);
|
|
398
406
|
}
|
|
399
407
|
|