pacc 8.1.1 → 8.1.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "8.1.1",
3
+ "version": "8.1.2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/ast.mjs CHANGED
@@ -72,8 +72,7 @@ export function binopEval(node, current, context) {
72
72
  }
73
73
 
74
74
  export function predicateIteratorEval(node, current, context) {
75
-
76
- if(current.values) {
75
+ if (current.values) {
77
76
  current = current.values();
78
77
  }
79
78
 
@@ -83,44 +82,45 @@ export function predicateIteratorEval(node, current, context) {
83
82
  }
84
83
 
85
84
  export function pathEval(node, current, context) {
86
- let result = current;
87
-
88
- for (const p of node.path) {
89
- switch (typeof p) {
85
+ for (const item of node.path) {
86
+ switch (typeof item) {
90
87
  case "string":
91
88
  case "number":
92
- if (typeof result === "function") {
93
- const r = [];
94
- for (const x of result()) {
95
- r.push(x[p]);
96
- }
97
- result = r;
98
- } else {
99
- if (result === undefined) {
100
- result = context.getGlobal(p);
101
- } else {
102
- if (result instanceof Map) {
103
- result = result.get(p);
89
+ switch (typeof current) {
90
+ case "function":
91
+ {
92
+ const r = [];
93
+ for (const x of current()) {
94
+ r.push(x[item]);
95
+ }
96
+ current = r;
97
+ }
98
+ break;
99
+ case "undefined":
100
+ current = context.getGlobal(item);
101
+ break;
102
+ default:
103
+ if (current instanceof Map) {
104
+ current = current.get(item);
104
105
  } else {
105
- result = result[p] ?? context.getGlobal(p);
106
+ current = current[item] ?? context.getGlobal(item);
106
107
  }
107
- }
108
108
  }
109
109
  break;
110
110
  case "object":
111
- const r = result;
111
+ const r = current;
112
112
  function* filter() {
113
113
  for (const x of r) {
114
- if (p.eval(p, x, context)) {
114
+ if (item.eval(item, x, context)) {
115
115
  yield x;
116
116
  }
117
117
  }
118
118
  }
119
- result = filter;
119
+ current = filter;
120
120
  }
121
121
  }
122
122
 
123
- return result;
123
+ return current;
124
124
  }
125
125
 
126
126
  export function functionEval(node, current, context) {
@@ -63,6 +63,11 @@ export function parse(input, context = {}) {
63
63
  return node;
64
64
  }
65
65
  case OPEN_BRACKET: {
66
+ if(token === CLOSE_BRACKET) {
67
+ advance();
68
+ return { eval: () => true };
69
+ }
70
+
66
71
  const node = expression(0);
67
72
  expect(CLOSE_BRACKET);
68
73
  switch (typeof node) {
@@ -163,23 +168,21 @@ export function parse(input, context = {}) {
163
168
  }
164
169
  case "prefix":
165
170
  switch (last) {
166
- case OPEN_ROUND:
167
- {
168
- const args = [];
169
- while (token !== CLOSE_ROUND) {
170
- args.push(expression(0));
171
- if (token === COMMA) {
172
- advance();
173
- }
171
+ case OPEN_ROUND: {
172
+ const args = [];
173
+ while (token !== CLOSE_ROUND) {
174
+ args.push(expression(0));
175
+ if (token === COMMA) {
176
+ advance();
174
177
  }
175
- left.args = args;
176
- left.eval = functionEval;
178
+ }
179
+ left.args = args;
180
+ left.eval = functionEval;
177
181
 
178
- advance();
182
+ advance();
179
183
 
180
- return left;
181
- }
182
- break;
184
+ return left;
185
+ }
183
186
  case OPEN_BRACKET: {
184
187
  const predicate = expression(0);
185
188
  expect(CLOSE_BRACKET);