pacc 4.23.1 → 4.24.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "4.23.1",
3
+ "version": "4.24.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/expand.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { parse } from "./expression.mjs";
2
- import { tokens } from "./tokens.mjs";
3
2
 
4
3
  const maxNestingLevel = 5;
5
4
 
@@ -20,8 +19,7 @@ export function expand(object, context) {
20
19
  const v = object.replace(
21
20
  /\$\{([^\}]*)\}/g,
22
21
  (match, expression, offset, string) => {
23
- context.tokens = tokens(expression);
24
- let value = parse(context);
22
+ let value = parse(expression,context);
25
23
 
26
24
  if (typeof value === "string" || value instanceof String) {
27
25
  value = _expand(value, path);
@@ -1,4 +1,5 @@
1
1
  import {
2
+ tokens,
2
3
  DOT,
3
4
  OPEN_ROUND,
4
5
  CLOSE_ROUND,
@@ -51,7 +52,9 @@ export function binop(op, left, right, fallback) {
51
52
  return fallback(op, left, right);
52
53
  }
53
54
 
54
- export function parse(context) {
55
+ export function parse(input, context = {}) {
56
+ input = tokens(input);
57
+
55
58
  let node, token, value;
56
59
 
57
60
  function error(message) {
@@ -76,13 +79,17 @@ export function parse(context) {
76
79
  }
77
80
  result = r;
78
81
  } else {
79
- result = result[p] ?? context.globals?.[p];
82
+ if (result instanceof Map) {
83
+ result = result.get(p);
84
+ } else {
85
+ result = result[p] ?? context.globals?.[p];
86
+ }
80
87
  }
81
88
  break;
82
89
  case "object":
83
- const input = result;
90
+ const r = result;
84
91
  function* filter() {
85
- for (const x of input) {
92
+ for (const x of r) {
86
93
  if (p.eval(p, x)) {
87
94
  yield x;
88
95
  }
@@ -96,7 +103,7 @@ export function parse(context) {
96
103
  };
97
104
 
98
105
  const advance = () => {
99
- const next = context.tokens.next();
106
+ const next = input.next();
100
107
  if (next.done) {
101
108
  token = EOF;
102
109
  } else {
@@ -28,7 +28,7 @@ import { prepareValue } from "./attributes.mjs";
28
28
  * @param {Object} definition type def
29
29
  */
30
30
  export function setAttribute(object, expression, value, definition) {
31
- const { path } = parse({ tokens: tokens(expression), exec: false });
31
+ const { path } = parse(expression, { exec: false });
32
32
 
33
33
  let anchor, anchorKey;
34
34
 
@@ -61,7 +61,7 @@ export function setAttribute(object, expression, value, definition) {
61
61
  * @returns {any} value associated with the given property name
62
62
  */
63
63
  export function getAttribute(object, expression, definition) {
64
- const { path } = parse({ tokens: tokens(expression), exec: false });
64
+ const { path } = parse(expression, { exec: false });
65
65
 
66
66
  for (const key of path) {
67
67
  if (object !== undefined) {
@@ -1,2 +1,2 @@
1
1
  export function binop(op: any, left: any, right: any, fallback: any): any;
2
- export function parse(context: any): any;
2
+ export function parse(input: any, context?: {}): any;