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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/expand.mjs +25 -25
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "4.21.0",
3
+ "version": "4.21.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
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(/\$\{([^\}]*)\}/g, (match, expression, offset, string) => {
20
- context.tokens = tokens(expression);
21
- let value = parse(context);
22
-
23
- if (typeof value === "string" || value instanceof String) {
24
- value = _expand(value, path);
25
- } else if (value === undefined) {
26
- value = "${" + expression + "}";
27
- }
28
- if (string.length === expression.length + 3) {
29
- wholeValue = value;
30
- return "";
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
- if (value instanceof Promise) {
34
- localPromises.push(value);
35
- return "${" + (localPromises.length - 1) + "}";
36
+ if (value instanceof Promise) {
37
+ localPromises.push(value);
38
+ return "${" + (localPromises.length - 1) + "}";
39
+ }
40
+ return value;
36
41
  }
37
- return value;
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, [], promises);
142
- if (promises.length !== 0) {
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
  }