pacc 4.7.3 → 4.8.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/package.json +1 -1
- package/src/settergetter.mjs +21 -8
package/package.json
CHANGED
package/src/settergetter.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* @typedef {import('./tokens.mjs').Token} Token
|
|
4
3
|
*/
|
|
@@ -17,6 +16,16 @@ import {
|
|
|
17
16
|
STAR
|
|
18
17
|
} from "./tokens.mjs";
|
|
19
18
|
|
|
19
|
+
function predicate(tokens, endToken) {
|
|
20
|
+
let predicate = [];
|
|
21
|
+
for (const token of tokens) {
|
|
22
|
+
if (token === endToken) break;
|
|
23
|
+
predicate.push(token);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return predicate;
|
|
27
|
+
}
|
|
28
|
+
|
|
20
29
|
/**
|
|
21
30
|
* Set object attribute.
|
|
22
31
|
* The name may be a property path like 'a.b.c'.
|
|
@@ -27,12 +36,14 @@ import {
|
|
|
27
36
|
export function setAttribute(object, expression, value) {
|
|
28
37
|
let anchor, anchorKey;
|
|
29
38
|
|
|
30
|
-
|
|
39
|
+
const next = tokens(expression);
|
|
40
|
+
|
|
41
|
+
for (let token of next) {
|
|
31
42
|
switch (token) {
|
|
32
43
|
case DOT:
|
|
33
|
-
case OPEN_BRACKET:
|
|
34
|
-
case CLOSE_BRACKET:
|
|
35
44
|
break;
|
|
45
|
+
case OPEN_BRACKET:
|
|
46
|
+
token = predicate(next, CLOSE_BRACKET)[0];
|
|
36
47
|
|
|
37
48
|
default:
|
|
38
49
|
if (anchor) {
|
|
@@ -40,13 +51,13 @@ export function setAttribute(object, expression, value) {
|
|
|
40
51
|
anchor = undefined;
|
|
41
52
|
}
|
|
42
53
|
|
|
43
|
-
const
|
|
54
|
+
const walk = object[token];
|
|
44
55
|
|
|
45
|
-
if (
|
|
56
|
+
if (walk === undefined || typeof walk !== "object") {
|
|
46
57
|
anchor = object;
|
|
47
58
|
anchorKey = token;
|
|
48
59
|
} else {
|
|
49
|
-
object =
|
|
60
|
+
object = walk;
|
|
50
61
|
}
|
|
51
62
|
}
|
|
52
63
|
}
|
|
@@ -91,7 +102,9 @@ export function getAttributeAndOperator(object, expression) {
|
|
|
91
102
|
let predicateTokens;
|
|
92
103
|
let op = EQUAL;
|
|
93
104
|
|
|
94
|
-
|
|
105
|
+
const next = tokens(expression);
|
|
106
|
+
|
|
107
|
+
for (const token of next) {
|
|
95
108
|
switch (token) {
|
|
96
109
|
case GREATER_EQUAL:
|
|
97
110
|
case LESS_EQUAL:
|