pacc 8.1.3 → 8.1.5

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.3",
3
+ "version": "8.1.5",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/ast.mjs CHANGED
@@ -86,41 +86,28 @@ export function predicateIteratorEval(node, current, context) {
86
86
  }
87
87
 
88
88
  export function pathEval(node, current, context) {
89
+ let collection = false;
89
90
  for (const item of node.path) {
90
91
  switch (typeof item) {
91
92
  case "string":
92
93
  case "number":
93
94
  switch (typeof current) {
94
- case "function":
95
- {
96
- const r = [];
97
- for (const x of current()) {
98
- r.push(x[item]);
99
- }
100
- current = r;
101
- }
102
- break;
103
95
  case "undefined":
104
96
  current = context.getGlobal(item);
105
97
  break;
106
98
  default:
107
- if (current instanceof Map) {
108
- current = current.get(item);
99
+ if (collection) {
100
+ current = current.map(x => x[item]);
109
101
  } else {
110
- current = current[item] ?? context.getGlobal(item);
102
+ current =
103
+ (current instanceof Map ? current.get(item) : current[item]) ??
104
+ context.getGlobal(item);
111
105
  }
112
106
  }
113
107
  break;
114
108
  case "object":
115
- const r = current;
116
- function* filter() {
117
- for (const x of r) {
118
- if (item.eval(item, x, context)) {
119
- yield x;
120
- }
121
- }
122
- }
123
- current = filter;
109
+ current = current.filter(c => item.eval(item, c, context));
110
+ collection = true;
124
111
  }
125
112
  }
126
113
 
@@ -135,12 +135,6 @@ export function parse(input, context = {}) {
135
135
  }
136
136
  }
137
137
  if (last === DOT) {
138
- switch (typeof left) {
139
- case "number":
140
- right.path.unshift(left);
141
- return right;
142
- }
143
-
144
138
  if (left.path) {
145
139
  left.path.push(...right.path);
146
140
  return left;