pacc 4.18.3 → 4.20.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "4.18.3",
3
+ "version": "4.20.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/expand.mjs ADDED
@@ -0,0 +1,33 @@
1
+ import { parse } from "./expression.mjs";
2
+ import { tokens } from "./tokens.mjs";
3
+
4
+ export function expand(object, context) {
5
+ switch (typeof object) {
6
+ case "string":
7
+ return object.replaceAll(/\$\{([^\}]*)\}/g, (match, m1) => {
8
+ context.tokens = tokens(m1);
9
+ return parse(context) ?? "${" + m1 + "}";
10
+ });
11
+
12
+ case "object":
13
+ if (object instanceof Map) {
14
+ return new Map(
15
+ [...object].map(([k, v]) => [expand(k, context), expand(v, context)])
16
+ );
17
+ }
18
+
19
+ if (object instanceof Set) {
20
+ return new Set([...object].map(e => expand(e, context)));
21
+ }
22
+
23
+ if (Array.isArray(object)) {
24
+ return object.map(e => expand(e, context));
25
+ }
26
+
27
+ return Object.fromEntries(
28
+ Object.entries(object).map(([k, v]) => [k, expand(v, context)])
29
+ );
30
+ }
31
+
32
+ return object;
33
+ }
@@ -75,7 +75,7 @@ export function parse(context) {
75
75
  }
76
76
  result = r;
77
77
  } else {
78
- result = result[p];
78
+ result = result[p] ?? context.globals?.[p];
79
79
  }
80
80
  break;
81
81
  case "object":
@@ -172,8 +172,10 @@ export function parse(context) {
172
172
 
173
173
  case "infix": {
174
174
  let right = expression(token.precedence);
175
+
175
176
  if (typeof left === typeof right) {
176
177
  switch (typeof left) {
178
+ case "string":
177
179
  case "number":
178
180
  case "bigint":
179
181
  return binop(token, left, right, binopError);
package/src/module.mjs CHANGED
@@ -4,6 +4,8 @@ export * from "./multiple.mjs";
4
4
  export * from "./attributes.mjs";
5
5
  export * from "./common-attributes.mjs";
6
6
  export * from "./properties.mjs";
7
+ export * from "./expression.mjs";
8
+ export * from "./expand.mjs";
7
9
  export {
8
10
  setAttribute,
9
11
  getAttribute,
@@ -0,0 +1 @@
1
+ export function expand(object: any, context: any): any;
@@ -4,4 +4,6 @@ export * from "./multiple.mjs";
4
4
  export * from "./attributes.mjs";
5
5
  export * from "./common-attributes.mjs";
6
6
  export * from "./properties.mjs";
7
+ export * from "./expression.mjs";
8
+ export * from "./expand.mjs";
7
9
  export { setAttribute, getAttribute, getAttributeAndOperator } from "./settergetter.mjs";