pacc 8.0.5 → 8.1.0

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/README.md CHANGED
@@ -26,14 +26,16 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
26
26
 
27
27
  ### Table of Contents
28
28
 
29
- * [prepareAttributesDefinitions](#prepareattributesdefinitions)
29
+ * [binopError](#binoperror)
30
30
  * [Parameters](#parameters)
31
- * [mergeAttributeDefinitions](#mergeattributedefinitions)
31
+ * [prepareAttributesDefinitions](#prepareattributesdefinitions)
32
32
  * [Parameters](#parameters-1)
33
- * [attributeIterator](#attributeiterator)
33
+ * [mergeAttributeDefinitions](#mergeattributedefinitions)
34
34
  * [Parameters](#parameters-2)
35
- * [parseBytes](#parsebytes)
35
+ * [attributeIterator](#attributeiterator)
36
36
  * [Parameters](#parameters-3)
37
+ * [parseBytes](#parsebytes)
38
+ * [Parameters](#parameters-4)
37
39
  * [AttributeDefinition](#attributedefinition)
38
40
  * [Properties](#properties)
39
41
  * [default\_attribute](#default_attribute)
@@ -88,13 +90,11 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
88
90
  * [timeout\_attribute](#timeout_attribute)
89
91
  * [language\_attribute](#language_attribute)
90
92
  * [environmentValues](#environmentvalues)
91
- * [Parameters](#parameters-4)
92
- * [expand](#expand)
93
93
  * [Parameters](#parameters-5)
94
+ * [expand](#expand)
95
+ * [Parameters](#parameters-6)
94
96
  * [promises](#promises)
95
97
  * [error](#error)
96
- * [Parameters](#parameters-6)
97
- * [binopError](#binoperror)
98
98
  * [Parameters](#parameters-7)
99
99
  * [filter](#filter)
100
100
  * [Parameters](#parameters-8)
@@ -157,6 +157,14 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
157
157
  * [raiseOnUnknownType](#raiseonunknowntype)
158
158
  * [Parameters](#parameters-20)
159
159
 
160
+ ## binopError
161
+
162
+ ### Parameters
163
+
164
+ * `op` **[Token](#token)** 
165
+ * `left` **AST** 
166
+ * `right` **AST** 
167
+
160
168
  ## prepareAttributesDefinitions
161
169
 
162
170
  Create attributes from its definition.
@@ -482,14 +490,6 @@ Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global
482
490
 
483
491
  * `message` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
484
492
 
485
- ## binopError
486
-
487
- ### Parameters
488
-
489
- * `op` **[Token](#token)** 
490
- * `left` **AST** 
491
- * `right` **AST** 
492
-
493
493
  ## filter
494
494
 
495
495
  Generate filter function.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "8.0.5",
3
+ "version": "8.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/ast.mjs CHANGED
@@ -13,6 +13,11 @@ import {
13
13
  MINUS
14
14
  } from "./tokens.mjs";
15
15
 
16
+ /**
17
+ * @typedef {Object} AST
18
+ * @property {Function} [eval]
19
+ */
20
+
16
21
  /**
17
22
  *
18
23
  * @param {Token} op
@@ -21,7 +26,7 @@ import {
21
26
  *
22
27
  */
23
28
  export function binopError(op, left, right) {
24
- throw new Error(`Unexpected '${op.str || op}'`,{ cause: op});
29
+ throw new Error(`Unexpected '${op.str || op}'`, { cause: op });
25
30
  }
26
31
 
27
32
  export function binop(op, left, right, fallback) {
@@ -73,7 +78,7 @@ export function predicateIteratorEval(node, current, context) {
73
78
  current = [...current.values()];
74
79
  }
75
80
  return current
76
- .filter(item => node.predicate(node, item, context))
81
+ .filter(item => node.left.eval(node.left, item, context))
77
82
  .map(item => node.right.eval(node.right, item, context));
78
83
  }
79
84
 
@@ -117,3 +122,10 @@ export function pathEval(node, current, context) {
117
122
 
118
123
  return result;
119
124
  }
125
+
126
+ export function functionEval(node, current, context) {
127
+ const args = node.args.map(a =>
128
+ typeof a === "object" ? a.eval(a, current, context) : a
129
+ );
130
+ return context.getGlobal(node.path[0])(...args);
131
+ }
@@ -10,7 +10,14 @@ import {
10
10
  EOF
11
11
  } from "./tokens.mjs";
12
12
 
13
- import {binopError, binop, binopEval, predicateIteratorEval, pathEval} from "./ast.mjs";
13
+ import {
14
+ binopError,
15
+ binop,
16
+ binopEval,
17
+ predicateIteratorEval,
18
+ pathEval,
19
+ functionEval
20
+ } from "./ast.mjs";
14
21
 
15
22
  /**
16
23
  *
@@ -101,14 +108,8 @@ export function parse(input, context = {}) {
101
108
  }
102
109
  }
103
110
 
104
- return {
105
- eval: (node, current, context) =>
106
- binop(
107
- last,
108
- left.eval ? left.eval(left, current, context) : left,
109
- right.eval ? right.eval(right, current, context) : right,
110
- binopError
111
- ),
111
+ return {
112
+ eval: binopEval,
112
113
  token: last,
113
114
  left,
114
115
  right
@@ -141,7 +142,7 @@ export function parse(input, context = {}) {
141
142
  if (left.eval) {
142
143
  return {
143
144
  eval: predicateIteratorEval,
144
- predicate: left.eval,
145
+ left,
145
146
  right
146
147
  };
147
148
  }
@@ -171,13 +172,8 @@ export function parse(input, context = {}) {
171
172
  advance();
172
173
  }
173
174
  }
174
- left.path.push(args);
175
- left.eval = (node, current, context) => {
176
- const args = node.path[1].map(a =>
177
- typeof a === "object" ? a.eval(a, current, context) : a
178
- );
179
- return context.getGlobal(node.path[0])(...args);
180
- };
175
+ left.args = args;
176
+ left.eval = functionEval;
181
177
 
182
178
  advance();
183
179
 
package/types/ast.d.mts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @typedef {Object} AST
3
+ * @property {Function} [eval]
4
+ */
1
5
  /**
2
6
  *
3
7
  * @param {Token} op
@@ -10,3 +14,7 @@ export function binop(op: any, left: any, right: any, fallback: any): any;
10
14
  export function binopEval(node: any, current: any, context: any): any;
11
15
  export function predicateIteratorEval(node: any, current: any, context: any): any;
12
16
  export function pathEval(node: any, current: any, context: any): any;
17
+ export function functionEval(node: any, current: any, context: any): any;
18
+ export type AST = {
19
+ eval?: Function;
20
+ };