pacc 8.1.0 → 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/README.md +15 -5
- package/package.json +1 -1
- package/src/ast.mjs +26 -26
- package/src/expression.mjs +17 -14
package/README.md
CHANGED
|
@@ -26,6 +26,8 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
|
|
|
26
26
|
|
|
27
27
|
### Table of Contents
|
|
28
28
|
|
|
29
|
+
* [AST](#ast)
|
|
30
|
+
* [Properties](#properties)
|
|
29
31
|
* [binopError](#binoperror)
|
|
30
32
|
* [Parameters](#parameters)
|
|
31
33
|
* [prepareAttributesDefinitions](#prepareattributesdefinitions)
|
|
@@ -37,7 +39,7 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
|
|
|
37
39
|
* [parseBytes](#parsebytes)
|
|
38
40
|
* [Parameters](#parameters-4)
|
|
39
41
|
* [AttributeDefinition](#attributedefinition)
|
|
40
|
-
* [Properties](#properties)
|
|
42
|
+
* [Properties](#properties-1)
|
|
41
43
|
* [default\_attribute](#default_attribute)
|
|
42
44
|
* [default\_attribute](#default_attribute-1)
|
|
43
45
|
* [default\_attribute](#default_attribute-2)
|
|
@@ -121,7 +123,7 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
|
|
|
121
123
|
* [Parameters](#parameters-18)
|
|
122
124
|
* [lookup](#lookup)
|
|
123
125
|
* [Token](#token)
|
|
124
|
-
* [Properties](#properties-
|
|
126
|
+
* [Properties](#properties-2)
|
|
125
127
|
* [createToken](#createtoken)
|
|
126
128
|
* [Parameters](#parameters-19)
|
|
127
129
|
* [PLUS](#plus)
|
|
@@ -153,17 +155,25 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
|
|
|
153
155
|
* [IDENTIFIER](#identifier)
|
|
154
156
|
* [EOF](#eof)
|
|
155
157
|
* [Type](#type)
|
|
156
|
-
* [Properties](#properties-
|
|
158
|
+
* [Properties](#properties-3)
|
|
157
159
|
* [raiseOnUnknownType](#raiseonunknowntype)
|
|
158
160
|
* [Parameters](#parameters-20)
|
|
159
161
|
|
|
162
|
+
## AST
|
|
163
|
+
|
|
164
|
+
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
|
|
165
|
+
|
|
166
|
+
### Properties
|
|
167
|
+
|
|
168
|
+
* `eval` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** 
|
|
169
|
+
|
|
160
170
|
## binopError
|
|
161
171
|
|
|
162
172
|
### Parameters
|
|
163
173
|
|
|
164
174
|
* `op` **[Token](#token)** 
|
|
165
|
-
* `left` **AST** 
|
|
166
|
-
* `right` **AST** 
|
|
175
|
+
* `left` **[AST](#ast)** 
|
|
176
|
+
* `right` **[AST](#ast)** 
|
|
167
177
|
|
|
168
178
|
## prepareAttributesDefinitions
|
|
169
179
|
|
package/package.json
CHANGED
package/src/ast.mjs
CHANGED
|
@@ -72,55 +72,55 @@ export function binopEval(node, current, context) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export function predicateIteratorEval(node, current, context) {
|
|
75
|
-
if (current
|
|
76
|
-
current =
|
|
77
|
-
} else if (current instanceof Map) {
|
|
78
|
-
current = [...current.values()];
|
|
75
|
+
if (current.values) {
|
|
76
|
+
current = current.values();
|
|
79
77
|
}
|
|
78
|
+
|
|
80
79
|
return current
|
|
81
80
|
.filter(item => node.left.eval(node.left, item, context))
|
|
82
81
|
.map(item => node.right.eval(node.right, item, context));
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
export function pathEval(node, current, context) {
|
|
86
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
106
|
+
current = current[item] ?? context.getGlobal(item);
|
|
106
107
|
}
|
|
107
|
-
}
|
|
108
108
|
}
|
|
109
109
|
break;
|
|
110
110
|
case "object":
|
|
111
|
-
const r =
|
|
111
|
+
const r = current;
|
|
112
112
|
function* filter() {
|
|
113
113
|
for (const x of r) {
|
|
114
|
-
if (
|
|
114
|
+
if (item.eval(item, x, context)) {
|
|
115
115
|
yield x;
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
|
|
119
|
+
current = filter;
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
return
|
|
123
|
+
return current;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
export function functionEval(node, current, context) {
|
package/src/expression.mjs
CHANGED
|
@@ -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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
176
|
-
|
|
178
|
+
}
|
|
179
|
+
left.args = args;
|
|
180
|
+
left.eval = functionEval;
|
|
177
181
|
|
|
178
|
-
|
|
182
|
+
advance();
|
|
179
183
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
break;
|
|
184
|
+
return left;
|
|
185
|
+
}
|
|
183
186
|
case OPEN_BRACKET: {
|
|
184
187
|
const predicate = expression(0);
|
|
185
188
|
expect(CLOSE_BRACKET);
|