pacc 4.9.1 → 4.10.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/expression.mjs +4 -1
- package/src/settergetter.mjs +21 -1
package/package.json
CHANGED
package/src/expression.mjs
CHANGED
|
@@ -50,6 +50,9 @@ export function parse(context) {
|
|
|
50
50
|
case OPEN_BRACKET: {
|
|
51
51
|
const node = expression(0);
|
|
52
52
|
expect(CLOSE_BRACKET);
|
|
53
|
+
if (typeof node === "number") {
|
|
54
|
+
return { path: [node] };
|
|
55
|
+
}
|
|
53
56
|
return node;
|
|
54
57
|
}
|
|
55
58
|
}
|
|
@@ -97,7 +100,7 @@ export function parse(context) {
|
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
if (right.token === EOF) {
|
|
100
|
-
error("
|
|
103
|
+
error("unexpected EOF");
|
|
101
104
|
}
|
|
102
105
|
return {
|
|
103
106
|
token,
|
package/src/settergetter.mjs
CHANGED
|
@@ -58,7 +58,27 @@ export function setAttribute(object, expression, value) {
|
|
|
58
58
|
* @returns {any} value associated with the given property name
|
|
59
59
|
*/
|
|
60
60
|
export function getAttribute(object, expression) {
|
|
61
|
-
|
|
61
|
+
const { path } = parse({ tokens: tokens(expression) });
|
|
62
|
+
|
|
63
|
+
for (const key of path) {
|
|
64
|
+
if (object !== undefined) {
|
|
65
|
+
switch (typeof object[key]) {
|
|
66
|
+
case "function":
|
|
67
|
+
object = object[key]();
|
|
68
|
+
if (typeof object[Symbol.iterator] === "function") {
|
|
69
|
+
object = [...object];
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
object = object[key];
|
|
74
|
+
break;
|
|
75
|
+
case "undefined":
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return object;
|
|
62
82
|
}
|
|
63
83
|
|
|
64
84
|
/**
|