pacc 4.37.7 → 4.38.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/expression.mjs +20 -6
- package/types/expression.d.mts +7 -4
package/package.json
CHANGED
package/src/expression.mjs
CHANGED
|
@@ -80,10 +80,14 @@ export function parse(input, context = { globals }) {
|
|
|
80
80
|
}
|
|
81
81
|
result = r;
|
|
82
82
|
} else {
|
|
83
|
-
if (result
|
|
84
|
-
result =
|
|
83
|
+
if (result === undefined && context.globals?.[p]) {
|
|
84
|
+
result = context.globals?.[p];
|
|
85
85
|
} else {
|
|
86
|
-
result
|
|
86
|
+
if (result instanceof Map) {
|
|
87
|
+
result = result.get(p);
|
|
88
|
+
} else {
|
|
89
|
+
result = result[p] ?? context.globals?.[p];
|
|
90
|
+
}
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
break;
|
|
@@ -117,7 +121,7 @@ export function parse(input, context = { globals }) {
|
|
|
117
121
|
|
|
118
122
|
const expect = expected => {
|
|
119
123
|
if (token !== expected) {
|
|
120
|
-
error(`unexpected '${token
|
|
124
|
+
error(`unexpected '${token?.str || token}' expecting '${expected.str}'`);
|
|
121
125
|
}
|
|
122
126
|
advance();
|
|
123
127
|
};
|
|
@@ -244,8 +248,12 @@ export function parse(input, context = { globals }) {
|
|
|
244
248
|
}
|
|
245
249
|
}
|
|
246
250
|
left.path.push(args);
|
|
247
|
-
left.eval = node =>
|
|
248
|
-
|
|
251
|
+
left.eval = node => {
|
|
252
|
+
const args = node.path[1].map(a =>
|
|
253
|
+
typeof a === "object" ? a.eval(a) : a
|
|
254
|
+
);
|
|
255
|
+
return context.globals[node.path[0]](...args);
|
|
256
|
+
};
|
|
249
257
|
return left;
|
|
250
258
|
}
|
|
251
259
|
break;
|
|
@@ -291,6 +299,12 @@ export function parse(input, context = { globals }) {
|
|
|
291
299
|
}
|
|
292
300
|
|
|
293
301
|
export const globals = {
|
|
302
|
+
in: (a, b) => {
|
|
303
|
+
if (Array.isArray(b)) {
|
|
304
|
+
return b.find(x => x === a) ? true : false;
|
|
305
|
+
}
|
|
306
|
+
return b.has(a);
|
|
307
|
+
},
|
|
294
308
|
min: (a, b) => (a < b ? a : b),
|
|
295
309
|
max: (a, b) => (a > b ? a : b),
|
|
296
310
|
substring: (s, a, b) => s.substring(a, b),
|
package/types/expression.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export function binop(op: any, left: any, right: any, fallback: any): any;
|
|
2
2
|
export function parse(input: any, context?: {
|
|
3
3
|
globals: {
|
|
4
|
+
in: (a: any, b: any) => any;
|
|
4
5
|
min: (a: any, b: any) => any;
|
|
5
6
|
max: (a: any, b: any) => any;
|
|
6
7
|
substring: (s: any, a: any, b: any) => any;
|
|
@@ -8,8 +9,10 @@ export function parse(input: any, context?: {
|
|
|
8
9
|
};
|
|
9
10
|
}): any;
|
|
10
11
|
export namespace globals {
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
function
|
|
14
|
-
function
|
|
12
|
+
export function _in(a: any, b: any): any;
|
|
13
|
+
export { _in as in };
|
|
14
|
+
export function min(a: any, b: any): any;
|
|
15
|
+
export function max(a: any, b: any): any;
|
|
16
|
+
export function substring(s: any, a: any, b: any): any;
|
|
17
|
+
export function length(s: any): any;
|
|
15
18
|
}
|