@aws-lambda-powertools/jmespath 2.3.0 → 2.4.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.
@@ -1,15 +1,3 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _TreeInterpreter_instances, _TreeInterpreter_functions, _TreeInterpreter_visitSubexpressionOrIndexExpressionOrPipe, _TreeInterpreter_visitField, _TreeInterpreter_visitComparator, _TreeInterpreter_visitCurrent, _TreeInterpreter_visitExpref, _TreeInterpreter_visitFunctionExpression, _TreeInterpreter_visitFilterProjection, _TreeInterpreter_visitFlatten, _TreeInterpreter_visitIdentity, _TreeInterpreter_visitIndex, _TreeInterpreter_visitSlice, _TreeInterpreter_visitKeyValPair, _TreeInterpreter_visitLiteral, _TreeInterpreter_visitMultiSelectObject, _TreeInterpreter_visitMultiSelectList, _TreeInterpreter_visitOrExpression, _TreeInterpreter_visitAndExpression, _TreeInterpreter_visitNotExpression, _TreeInterpreter_visitProjection, _TreeInterpreter_visitValueProjection;
13
1
  import { isIntegerNumber, isRecord, isStrictEqual, } from '@aws-lambda-powertools/commons/typeutils';
14
2
  import { ArityError, JMESPathError, JMESPathTypeError, UnknownFunctionError, VariadicArityError, } from './errors.js';
15
3
  import { Expression } from './Expression.js';
@@ -25,19 +13,18 @@ import { isTruthy, sliceArray } from './utils.js';
25
13
  * @internal
26
14
  */
27
15
  class TreeInterpreter {
16
+ #functions;
28
17
  /**
29
18
  * @param options The options to use for the interpreter.
30
19
  */
31
20
  constructor(options) {
32
- _TreeInterpreter_instances.add(this);
33
- _TreeInterpreter_functions.set(this, void 0);
34
21
  if (options?.customFunctions) {
35
- __classPrivateFieldSet(this, _TreeInterpreter_functions, options.customFunctions, "f");
22
+ this.#functions = options.customFunctions;
36
23
  }
37
24
  else {
38
- __classPrivateFieldSet(this, _TreeInterpreter_functions, new Functions(), "f");
25
+ this.#functions = new Functions();
39
26
  }
40
- __classPrivateFieldGet(this, _TreeInterpreter_functions, "f").introspectMethods();
27
+ this.#functions.introspectMethods();
41
28
  }
42
29
  /**
43
30
  * Visit a node in the AST.
@@ -50,28 +37,28 @@ class TreeInterpreter {
50
37
  visit(node, value) {
51
38
  const nodeType = node.type;
52
39
  const visitMethods = {
53
- subexpression: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitSubexpressionOrIndexExpressionOrPipe),
54
- field: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitField),
55
- comparator: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitComparator),
56
- current: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitCurrent),
57
- expref: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitExpref),
58
- function_expression: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitFunctionExpression),
59
- filter_projection: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitFilterProjection),
60
- flatten: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitFlatten),
61
- identity: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitIdentity),
62
- index: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitIndex),
63
- index_expression: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitSubexpressionOrIndexExpressionOrPipe),
64
- slice: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitSlice),
65
- key_val_pair: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitKeyValPair),
66
- literal: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitLiteral),
67
- multi_select_object: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitMultiSelectObject),
68
- multi_select_list: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitMultiSelectList),
69
- or_expression: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitOrExpression),
70
- and_expression: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitAndExpression),
71
- not_expression: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitNotExpression),
72
- pipe: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitSubexpressionOrIndexExpressionOrPipe),
73
- projection: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitProjection),
74
- value_projection: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitValueProjection),
40
+ subexpression: this.#visitSubexpressionOrIndexExpressionOrPipe,
41
+ field: this.#visitField,
42
+ comparator: this.#visitComparator,
43
+ current: this.#visitCurrent,
44
+ expref: this.#visitExpref,
45
+ function_expression: this.#visitFunctionExpression,
46
+ filter_projection: this.#visitFilterProjection,
47
+ flatten: this.#visitFlatten,
48
+ identity: this.#visitIdentity,
49
+ index: this.#visitIndex,
50
+ index_expression: this.#visitSubexpressionOrIndexExpressionOrPipe,
51
+ slice: this.#visitSlice,
52
+ key_val_pair: this.#visitKeyValPair,
53
+ literal: this.#visitLiteral,
54
+ multi_select_object: this.#visitMultiSelectObject,
55
+ multi_select_list: this.#visitMultiSelectList,
56
+ or_expression: this.#visitOrExpression,
57
+ and_expression: this.#visitAndExpression,
58
+ not_expression: this.#visitNotExpression,
59
+ pipe: this.#visitSubexpressionOrIndexExpressionOrPipe,
60
+ projection: this.#visitProjection,
61
+ value_projection: this.#visitValueProjection,
75
62
  };
76
63
  const visitMethod = visitMethods[nodeType];
77
64
  if (visitMethod) {
@@ -81,230 +68,374 @@ class TreeInterpreter {
81
68
  throw new JMESPathError(`Not Implemented: Invalid node type: ${node.type}`);
82
69
  }
83
70
  }
84
- }
85
- _TreeInterpreter_functions = new WeakMap(), _TreeInterpreter_instances = new WeakSet(), _TreeInterpreter_visitSubexpressionOrIndexExpressionOrPipe = function _TreeInterpreter_visitSubexpressionOrIndexExpressionOrPipe(node, value) {
86
- let result = value;
87
- for (const child of node.children) {
88
- result = this.visit(child, result);
89
- }
90
- return result;
91
- }, _TreeInterpreter_visitField = function _TreeInterpreter_visitField(node, value) {
92
- if (!node.value)
93
- return null;
94
- if (isRecord(value) &&
95
- typeof node.value === 'string' &&
96
- node.value in value) {
97
- return value[node.value];
71
+ /**
72
+ * Visit a subexpression, index expression, or pipe node.
73
+ *
74
+ * This method is shared between subexpression, index expression, and pipe
75
+ * since they all behave the same way in the context of an expression.
76
+ *
77
+ * They all visit their children and return the result of the last child.
78
+ *
79
+ * @param node The node to visit.
80
+ * @param value The current value to visit.
81
+ */
82
+ #visitSubexpressionOrIndexExpressionOrPipe(node, value) {
83
+ let result = value;
84
+ for (const child of node.children) {
85
+ result = this.visit(child, result);
86
+ }
87
+ return result;
98
88
  }
99
- else {
100
- return null;
89
+ /**
90
+ * Visit a field node.
91
+ *
92
+ * @param node The field node to visit.
93
+ * @param value The current value to visit.
94
+ */
95
+ #visitField(node, value) {
96
+ if (!node.value)
97
+ return null;
98
+ if (isRecord(value) &&
99
+ typeof node.value === 'string' &&
100
+ node.value in value) {
101
+ return value[node.value];
102
+ }
103
+ else {
104
+ return null;
105
+ }
101
106
  }
102
- }, _TreeInterpreter_visitComparator = function _TreeInterpreter_visitComparator(node, value) {
103
- const comparator = node.value;
104
- const left = this.visit(node.children[0], value);
105
- const right = this.visit(node.children[1], value);
106
- if (typeof comparator === 'string' &&
107
- ['eq', 'ne', 'gt', 'gte', 'lt', 'lte'].includes(comparator)) {
108
- // Common cases: comparator is == or !=
109
- if (comparator === 'eq') {
110
- return isStrictEqual(left, right);
111
- }
112
- else if (comparator === 'ne') {
113
- return !isStrictEqual(left, right);
114
- }
115
- else if (typeof left === 'number' && typeof right === 'number') {
116
- // Ordering operators only work on numbers. Evaluating them on other
117
- // types will return null.
118
- if (comparator === 'lt') {
119
- return left < right;
120
- }
121
- else if (comparator === 'lte') {
122
- return left <= right;
107
+ /**
108
+ * Visit a comparator node.
109
+ *
110
+ * @param node The comparator node to visit.
111
+ * @param value The current value to visit.
112
+ */
113
+ #visitComparator(node, value) {
114
+ const comparator = node.value;
115
+ const left = this.visit(node.children[0], value);
116
+ const right = this.visit(node.children[1], value);
117
+ if (typeof comparator === 'string' &&
118
+ ['eq', 'ne', 'gt', 'gte', 'lt', 'lte'].includes(comparator)) {
119
+ // Common cases: comparator is == or !=
120
+ if (comparator === 'eq') {
121
+ return isStrictEqual(left, right);
123
122
  }
124
- else if (comparator === 'gt') {
125
- return left > right;
123
+ else if (comparator === 'ne') {
124
+ return !isStrictEqual(left, right);
126
125
  }
127
- else {
128
- return left >= right;
126
+ else if (typeof left === 'number' && typeof right === 'number') {
127
+ // Ordering operators only work on numbers. Evaluating them on other
128
+ // types will return null.
129
+ if (comparator === 'lt') {
130
+ return left < right;
131
+ }
132
+ else if (comparator === 'lte') {
133
+ return left <= right;
134
+ }
135
+ else if (comparator === 'gt') {
136
+ return left > right;
137
+ }
138
+ else {
139
+ return left >= right;
140
+ }
129
141
  }
130
142
  }
143
+ else {
144
+ throw new JMESPathError(`Invalid comparator: ${comparator}`);
145
+ }
131
146
  }
132
- else {
133
- throw new JMESPathError(`Invalid comparator: ${comparator}`);
134
- }
135
- }, _TreeInterpreter_visitCurrent = function _TreeInterpreter_visitCurrent(_node, value) {
136
- return value;
137
- }, _TreeInterpreter_visitExpref = function _TreeInterpreter_visitExpref(node, _value) {
138
- return new Expression(node.children[0], this);
139
- }, _TreeInterpreter_visitFunctionExpression = function _TreeInterpreter_visitFunctionExpression(node, value) {
140
- const args = [];
141
- for (const child of node.children) {
142
- args.push(this.visit(child, value));
143
- }
144
- // check that method name is a string
145
- if (typeof node.value !== 'string') {
146
- throw new JMESPathError(`Function name must be a string, got ${node.value}`);
147
- }
148
- // convert snake_case to camelCase
149
- const normalizedFunctionName = node.value.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
150
- // capitalize first letter & add `func` prefix
151
- const funcName = `func${normalizedFunctionName.charAt(0).toUpperCase() +
152
- normalizedFunctionName.slice(1)}`;
153
- if (!__classPrivateFieldGet(this, _TreeInterpreter_functions, "f").methods.has(funcName)) {
154
- throw new UnknownFunctionError(node.value);
147
+ /**
148
+ * Visit a current node.
149
+ *
150
+ * @param node The current node to visit.
151
+ * @param value The current value to visit.
152
+ */
153
+ #visitCurrent(_node, value) {
154
+ return value;
155
155
  }
156
- try {
157
- // We know that methodName is a key of this.#functions, but TypeScript
158
- // doesn't know that, so we have to use @ts-ignore to tell it that it's
159
- // okay. We could use a type assertion like `as keyof Functions`, but
160
- // we also want to keep the args generic, so for now we'll just ignore it.
161
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
162
- // @ts-ignore-next-line
163
- return __classPrivateFieldGet(this, _TreeInterpreter_functions, "f")[funcName](args);
156
+ /**
157
+ * Visit an expref node.
158
+ *
159
+ * @param node The expref node to visit.
160
+ * @param value The current value to visit.
161
+ */
162
+ #visitExpref(node, _value) {
163
+ return new Expression(node.children[0], this);
164
164
  }
165
- catch (error) {
166
- if (error instanceof JMESPathTypeError ||
167
- error instanceof VariadicArityError ||
168
- error instanceof ArityError) {
169
- error.setEvaluatedFunctionName(node.value);
170
- throw error;
165
+ /**
166
+ * Visit a function expression node.
167
+ *
168
+ * @param node The function expression node to visit.
169
+ * @param value The current value to visit.
170
+ */
171
+ #visitFunctionExpression(node, value) {
172
+ const args = [];
173
+ for (const child of node.children) {
174
+ args.push(this.visit(child, value));
171
175
  }
172
- }
173
- }, _TreeInterpreter_visitFilterProjection = function _TreeInterpreter_visitFilterProjection(node, value) {
174
- const base = this.visit(node.children[0], value);
175
- if (!Array.isArray(base)) {
176
- return null;
177
- }
178
- const comparatorNode = node.children[2];
179
- const collected = [];
180
- for (const item of base) {
181
- if (isTruthy(this.visit(comparatorNode, item))) {
182
- const current = this.visit(node.children[1], item);
183
- if (current !== null) {
184
- collected.push(current);
176
+ // check that method name is a string
177
+ if (typeof node.value !== 'string') {
178
+ throw new JMESPathError(`Function name must be a string, got ${node.value}`);
179
+ }
180
+ // convert snake_case to camelCase
181
+ const normalizedFunctionName = node.value.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
182
+ // capitalize first letter & add `func` prefix
183
+ const funcName = `func${normalizedFunctionName.charAt(0).toUpperCase() +
184
+ normalizedFunctionName.slice(1)}`;
185
+ if (!this.#functions.methods.has(funcName)) {
186
+ throw new UnknownFunctionError(node.value);
187
+ }
188
+ try {
189
+ // We know that methodName is a key of this.#functions, but TypeScript
190
+ // doesn't know that, so we have to use @ts-ignore to tell it that it's
191
+ // okay. We could use a type assertion like `as keyof Functions`, but
192
+ // we also want to keep the args generic, so for now we'll just ignore it.
193
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
194
+ // @ts-ignore-next-line
195
+ return this.#functions[funcName](args);
196
+ }
197
+ catch (error) {
198
+ if (error instanceof JMESPathTypeError ||
199
+ error instanceof VariadicArityError ||
200
+ error instanceof ArityError) {
201
+ error.setEvaluatedFunctionName(node.value);
202
+ throw error;
185
203
  }
186
204
  }
187
205
  }
188
- return collected;
189
- }, _TreeInterpreter_visitFlatten = function _TreeInterpreter_visitFlatten(node, value) {
190
- const base = this.visit(node.children[0], value);
191
- if (!Array.isArray(base)) {
192
- return null;
193
- }
194
- const mergedList = [];
195
- for (const item of base) {
196
- if (Array.isArray(item)) {
197
- mergedList.push(...item);
206
+ /**
207
+ * Visit a filter projection node.
208
+ *
209
+ * @param node The filter projection node to visit.
210
+ * @param value The current value to visit.
211
+ */
212
+ #visitFilterProjection(node, value) {
213
+ const base = this.visit(node.children[0], value);
214
+ if (!Array.isArray(base)) {
215
+ return null;
198
216
  }
199
- else {
200
- mergedList.push(item);
217
+ const comparatorNode = node.children[2];
218
+ const collected = [];
219
+ for (const item of base) {
220
+ if (isTruthy(this.visit(comparatorNode, item))) {
221
+ const current = this.visit(node.children[1], item);
222
+ if (current !== null) {
223
+ collected.push(current);
224
+ }
225
+ }
201
226
  }
227
+ return collected;
202
228
  }
203
- return mergedList;
204
- }, _TreeInterpreter_visitIdentity = function _TreeInterpreter_visitIdentity(_node, value) {
205
- return value;
206
- }, _TreeInterpreter_visitIndex = function _TreeInterpreter_visitIndex(node, value) {
207
- if (!Array.isArray(value)) {
208
- return null;
209
- }
210
- // The Python implementation doesn't support string indexing
211
- // even though we could, so we won't either for now.
212
- if (typeof node.value !== 'number') {
213
- throw new JMESPathError(`Invalid index: ${node.value}`);
229
+ /**
230
+ * Visit a flatten node.
231
+ *
232
+ * @param node The flatten node to visit.
233
+ * @param value The current value to visit.
234
+ */
235
+ #visitFlatten(node, value) {
236
+ const base = this.visit(node.children[0], value);
237
+ if (!Array.isArray(base)) {
238
+ return null;
239
+ }
240
+ const mergedList = [];
241
+ for (const item of base) {
242
+ if (Array.isArray(item)) {
243
+ mergedList.push(...item);
244
+ }
245
+ else {
246
+ mergedList.push(item);
247
+ }
248
+ }
249
+ return mergedList;
214
250
  }
215
- const index = node.value < 0 ? value.length + node.value : node.value;
216
- const found = value[index];
217
- if (found === undefined) {
218
- return null;
251
+ /**
252
+ * Visit an identity node.
253
+ *
254
+ * @param node The identity node to visit.
255
+ * @param value The current value to visit.
256
+ */
257
+ #visitIdentity(_node, value) {
258
+ return value;
219
259
  }
220
- return found;
221
- }, _TreeInterpreter_visitSlice = function _TreeInterpreter_visitSlice(node, value) {
222
- const step = isIntegerNumber(node.children[2]) ? node.children[2] : 1;
223
- if (step === 0) {
224
- throw new Error('Invalid slice, step cannot be 0');
260
+ /**
261
+ * Visit an index node.
262
+ *
263
+ * @param node The index node to visit.
264
+ * @param value The current value to visit.
265
+ */
266
+ #visitIndex(node, value) {
267
+ if (!Array.isArray(value)) {
268
+ return null;
269
+ }
270
+ // The Python implementation doesn't support string indexing
271
+ // even though we could, so we won't either for now.
272
+ if (typeof node.value !== 'number') {
273
+ throw new JMESPathError(`Invalid index: ${node.value}`);
274
+ }
275
+ const index = node.value < 0 ? value.length + node.value : node.value;
276
+ const found = value[index];
277
+ if (found === undefined) {
278
+ return null;
279
+ }
280
+ return found;
225
281
  }
226
- if (!Array.isArray(value)) {
227
- return null;
282
+ /**
283
+ * Visit a slice node.
284
+ *
285
+ * @param node The slice node to visit.
286
+ * @param value The current value to visit.
287
+ */
288
+ #visitSlice(node, value) {
289
+ const step = isIntegerNumber(node.children[2]) ? node.children[2] : 1;
290
+ if (step === 0) {
291
+ throw new Error('Invalid slice, step cannot be 0');
292
+ }
293
+ if (!Array.isArray(value)) {
294
+ return null;
295
+ }
296
+ if (value.length === 0) {
297
+ return [];
298
+ }
299
+ return sliceArray({
300
+ array: value,
301
+ start: node.children[0],
302
+ end: node.children[1],
303
+ step,
304
+ });
228
305
  }
229
- if (value.length === 0) {
230
- return [];
306
+ /**
307
+ * Visit a key-value pair node.
308
+ *
309
+ * @param node The key-value pair node to visit.
310
+ * @param value The current value to visit.
311
+ */
312
+ #visitKeyValPair(node, value) {
313
+ return this.visit(node.children[0], value);
231
314
  }
232
- return sliceArray({
233
- array: value,
234
- start: node.children[0],
235
- end: node.children[1],
236
- step,
237
- });
238
- }, _TreeInterpreter_visitKeyValPair = function _TreeInterpreter_visitKeyValPair(node, value) {
239
- return this.visit(node.children[0], value);
240
- }, _TreeInterpreter_visitLiteral = function _TreeInterpreter_visitLiteral(node, _value) {
241
- return node.value;
242
- }, _TreeInterpreter_visitMultiSelectObject = function _TreeInterpreter_visitMultiSelectObject(node, value) {
243
- if (Object.is(value, null)) {
244
- return null;
315
+ /**
316
+ * Visit a literal node.
317
+ *
318
+ * @param node The literal node to visit.
319
+ * @param value The current value to visit.
320
+ */
321
+ #visitLiteral(node, _value) {
322
+ return node.value;
245
323
  }
246
- const collected = {};
247
- for (const child of node.children) {
248
- if (typeof child.value === 'string') {
249
- collected[child.value] = this.visit(child, value);
324
+ /**
325
+ * Visit a multi-select object node.
326
+ *
327
+ * @param node The multi-select object node to visit.
328
+ * @param value The current value to visit.
329
+ */
330
+ #visitMultiSelectObject(node, value) {
331
+ if (Object.is(value, null)) {
332
+ return null;
250
333
  }
334
+ const collected = {};
335
+ for (const child of node.children) {
336
+ if (typeof child.value === 'string') {
337
+ collected[child.value] = this.visit(child, value);
338
+ }
339
+ }
340
+ return collected;
251
341
  }
252
- return collected;
253
- }, _TreeInterpreter_visitMultiSelectList = function _TreeInterpreter_visitMultiSelectList(node, value) {
254
- if (Object.is(value, null)) {
255
- return null;
256
- }
257
- const collected = [];
258
- for (const child of node.children) {
259
- collected.push(this.visit(child, value));
260
- }
261
- return collected;
262
- }, _TreeInterpreter_visitOrExpression = function _TreeInterpreter_visitOrExpression(node, value) {
263
- const matched = this.visit(node.children[0], value);
264
- if (!isTruthy(matched)) {
265
- return this.visit(node.children[1], value);
342
+ /**
343
+ * Visit a multi-select list node.
344
+ *
345
+ * @param node The multi-select list node to visit.
346
+ * @param value The current value to visit.
347
+ */
348
+ #visitMultiSelectList(node, value) {
349
+ if (Object.is(value, null)) {
350
+ return null;
351
+ }
352
+ const collected = [];
353
+ for (const child of node.children) {
354
+ collected.push(this.visit(child, value));
355
+ }
356
+ return collected;
266
357
  }
267
- return matched;
268
- }, _TreeInterpreter_visitAndExpression = function _TreeInterpreter_visitAndExpression(node, value) {
269
- const matched = this.visit(node.children[0], value);
270
- if (!isTruthy(matched)) {
358
+ /**
359
+ * Visit an or expression node.
360
+ *
361
+ * @param node The or expression node to visit.
362
+ * @param value The current value to visit.
363
+ */
364
+ #visitOrExpression(node, value) {
365
+ const matched = this.visit(node.children[0], value);
366
+ if (!isTruthy(matched)) {
367
+ return this.visit(node.children[1], value);
368
+ }
271
369
  return matched;
272
370
  }
273
- return this.visit(node.children[1], value);
274
- }, _TreeInterpreter_visitNotExpression = function _TreeInterpreter_visitNotExpression(node, value) {
275
- const originalResult = this.visit(node.children[0], value);
276
- if (typeof originalResult === 'number' && originalResult === 0) {
277
- // Special case for 0, !0 should be false, not true.
278
- // 0 is not a special cased integer in jmespath.
279
- return false;
280
- }
281
- return !isTruthy(originalResult);
282
- }, _TreeInterpreter_visitProjection = function _TreeInterpreter_visitProjection(node, value) {
283
- const base = this.visit(node.children[0], value);
284
- if (!Array.isArray(base)) {
285
- return null;
371
+ /**
372
+ * Visit an and expression node.
373
+ *
374
+ * @param node The and expression node to visit.
375
+ * @param value The current value to visit.
376
+ */
377
+ #visitAndExpression(node, value) {
378
+ const matched = this.visit(node.children[0], value);
379
+ if (!isTruthy(matched)) {
380
+ return matched;
381
+ }
382
+ return this.visit(node.children[1], value);
286
383
  }
287
- const collected = [];
288
- for (const item of base) {
289
- const current = this.visit(node.children[1], item);
290
- if (current !== null) {
291
- collected.push(current);
384
+ /**
385
+ * Visit a not expression node.
386
+ *
387
+ * @param node The not expression node to visit.
388
+ * @param value The current value to visit.
389
+ */
390
+ #visitNotExpression(node, value) {
391
+ const originalResult = this.visit(node.children[0], value);
392
+ if (typeof originalResult === 'number' && originalResult === 0) {
393
+ // Special case for 0, !0 should be false, not true.
394
+ // 0 is not a special cased integer in jmespath.
395
+ return false;
292
396
  }
397
+ return !isTruthy(originalResult);
293
398
  }
294
- return collected;
295
- }, _TreeInterpreter_visitValueProjection = function _TreeInterpreter_visitValueProjection(node, value) {
296
- const base = this.visit(node.children[0], value);
297
- if (!isRecord(base)) {
298
- return null;
399
+ /**
400
+ * Visit a projection node.
401
+ *
402
+ * @param node The projection node to visit.
403
+ * @param value The current value to visit.
404
+ */
405
+ #visitProjection(node, value) {
406
+ const base = this.visit(node.children[0], value);
407
+ if (!Array.isArray(base)) {
408
+ return null;
409
+ }
410
+ const collected = [];
411
+ for (const item of base) {
412
+ const current = this.visit(node.children[1], item);
413
+ if (current !== null) {
414
+ collected.push(current);
415
+ }
416
+ }
417
+ return collected;
299
418
  }
300
- const values = Object.values(base);
301
- const collected = [];
302
- for (const item of values) {
303
- const current = this.visit(node.children[1], item);
304
- if (current !== null) {
305
- collected.push(current);
419
+ /**
420
+ * Visit a value projection node.
421
+ *
422
+ * @param node The value projection node to visit.
423
+ * @param value The current value to visit.
424
+ */
425
+ #visitValueProjection(node, value) {
426
+ const base = this.visit(node.children[0], value);
427
+ if (!isRecord(base)) {
428
+ return null;
429
+ }
430
+ const values = Object.values(base);
431
+ const collected = [];
432
+ for (const item of values) {
433
+ const current = this.visit(node.children[1], item);
434
+ if (current !== null) {
435
+ collected.push(current);
436
+ }
306
437
  }
438
+ return collected;
307
439
  }
308
- return collected;
309
- };
440
+ }
310
441
  export { TreeInterpreter };