pacc 4.21.0 → 4.22.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/expand.mjs +29 -25
package/package.json
CHANGED
package/src/expand.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { parse } from "./expression.mjs";
|
|
2
2
|
import { tokens } from "./tokens.mjs";
|
|
3
3
|
|
|
4
|
+
const maxNestingLevel = 5;
|
|
5
|
+
|
|
4
6
|
export function expand(object, context) {
|
|
5
7
|
const promises = [];
|
|
6
|
-
const maxNestingLevel = 5;
|
|
7
8
|
|
|
8
9
|
function _expand(object, path) {
|
|
9
10
|
if (path.length >= maxNestingLevel) {
|
|
@@ -16,26 +17,29 @@ export function expand(object, context) {
|
|
|
16
17
|
let wholeValue;
|
|
17
18
|
|
|
18
19
|
const localPromises = [];
|
|
19
|
-
const v = object.replace(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
const v = object.replace(
|
|
21
|
+
/\$\{([^\}]*)\}/g,
|
|
22
|
+
(match, expression, offset, string) => {
|
|
23
|
+
context.tokens = tokens(expression);
|
|
24
|
+
let value = parse(context);
|
|
25
|
+
|
|
26
|
+
if (typeof value === "string" || value instanceof String) {
|
|
27
|
+
value = _expand(value, path);
|
|
28
|
+
} else if (value === undefined) {
|
|
29
|
+
value = "${" + expression + "}";
|
|
30
|
+
}
|
|
31
|
+
if (string.length === expression.length + 3) {
|
|
32
|
+
wholeValue = value;
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
if (value instanceof Promise) {
|
|
37
|
+
localPromises.push(value);
|
|
38
|
+
return "${" + (localPromises.length - 1) + "}";
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
36
41
|
}
|
|
37
|
-
|
|
38
|
-
});
|
|
42
|
+
);
|
|
39
43
|
|
|
40
44
|
if (wholeValue !== undefined) {
|
|
41
45
|
return wholeValue;
|
|
@@ -95,7 +99,6 @@ export function expand(object, context) {
|
|
|
95
99
|
|
|
96
100
|
for (let index = 0; index < object.length; index++) {
|
|
97
101
|
const o = object[index];
|
|
98
|
-
|
|
99
102
|
const r = _expand(o, [
|
|
100
103
|
...path,
|
|
101
104
|
{
|
|
@@ -113,6 +116,10 @@ export function expand(object, context) {
|
|
|
113
116
|
return array;
|
|
114
117
|
}
|
|
115
118
|
|
|
119
|
+
if(object instanceof context.stopClass) {
|
|
120
|
+
return object;
|
|
121
|
+
}
|
|
122
|
+
|
|
116
123
|
let newObject = {};
|
|
117
124
|
|
|
118
125
|
for (let [key, value] of Object.entries(object)) {
|
|
@@ -138,9 +145,6 @@ export function expand(object, context) {
|
|
|
138
145
|
return newObject;
|
|
139
146
|
}
|
|
140
147
|
|
|
141
|
-
const value = _expand(object, []
|
|
142
|
-
|
|
143
|
-
return Promise.all(promises).then(() => value);
|
|
144
|
-
}
|
|
145
|
-
return value;
|
|
148
|
+
const value = _expand(object, []);
|
|
149
|
+
return promises.length > 0 ? Promise.all(promises).then(() => value) : value;
|
|
146
150
|
}
|