pacc 4.18.0 → 4.18.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/expression.mjs +40 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "4.18.0",
3
+ "version": "4.18.2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -61,14 +61,34 @@ export function parse(context) {
61
61
  error(`Unexpected '${op.str || op}'`);
62
62
  }
63
63
 
64
- const pathEval = node => {
65
- let result = context.root;
64
+ const pathEval = (node, current) => {
65
+ let result = current;
66
66
 
67
67
  for (const p of node.path) {
68
68
  switch (typeof p) {
69
69
  case "string":
70
70
  case "number":
71
- result = result[p];
71
+ if(typeof result === 'function') {
72
+ const r = [];
73
+ for(const x of result()) {
74
+ r.push(x[p]);
75
+ }
76
+ result = r;
77
+ }
78
+ else {
79
+ result = result[p];
80
+ }
81
+ break;
82
+ case "object":
83
+ function* filter() {
84
+ for (const x of result) {
85
+ if (p.eval(p, x)) {
86
+ yield x;
87
+ }
88
+ }
89
+ }
90
+ //result = filter;
91
+ result = [...filter()];
72
92
  }
73
93
  }
74
94
 
@@ -136,6 +156,13 @@ export function parse(context) {
136
156
  }
137
157
  }
138
158
  return {
159
+ eval: (node, current) =>
160
+ binop(
161
+ token,
162
+ left.eval ? left.eval(left, current) : left,
163
+ right.eval ? right.eval(right, current) : right,
164
+ binopError
165
+ ),
139
166
  token,
140
167
  left,
141
168
  right
@@ -143,7 +170,7 @@ export function parse(context) {
143
170
  }
144
171
 
145
172
  case "infix": {
146
- const right = expression(token.precedence);
173
+ let right = expression(token.precedence);
147
174
  if (typeof left === typeof right) {
148
175
  switch (typeof left) {
149
176
  case "number":
@@ -169,11 +196,13 @@ export function parse(context) {
169
196
  }
170
197
 
171
198
  return {
172
- eval: (node) => {
173
- const left = node.left?.eval ? node.left.eval(node.left) : node.left;
174
- const right = node.right?.eval ? node.right.eval(node.right) : node.right;
175
- return binop(node.token,left,right);
176
- },
199
+ eval: (node, current) =>
200
+ binop(
201
+ token,
202
+ left.eval ? left.eval(left, current) : left,
203
+ right.eval ? right.eval(right, current) : right,
204
+ binopError
205
+ ),
177
206
  token,
178
207
  left,
179
208
  right
@@ -211,8 +240,8 @@ export function parse(context) {
211
240
 
212
241
  const result = expression(token.precedence ?? 0);
213
242
 
214
- if(context.exec !== false &&result?.eval) {
215
- return result.eval(result);
243
+ if (context.exec !== false && result?.eval) {
244
+ return result.eval(result, context.root);
216
245
  }
217
246
 
218
247
  return result;