pacc 4.21.0 → 4.21.1
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 +25 -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
|
{
|
|
@@ -138,9 +141,6 @@ export function expand(object, context) {
|
|
|
138
141
|
return newObject;
|
|
139
142
|
}
|
|
140
143
|
|
|
141
|
-
const value = _expand(object, []
|
|
142
|
-
|
|
143
|
-
return Promise.all(promises).then(() => value);
|
|
144
|
-
}
|
|
145
|
-
return value;
|
|
144
|
+
const value = _expand(object, []);
|
|
145
|
+
return promises.length > 0 ? Promise.all(promises).then(() => value) : value;
|
|
146
146
|
}
|