@aws-lambda-powertools/jmespath 2.2.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.
package/lib/esm/Lexer.js CHANGED
@@ -1,15 +1,3 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- 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");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- 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");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
- };
12
- var _Lexer_instances, _Lexer_position, _Lexer_expression, _Lexer_chars, _Lexer_current, _Lexer_length, _Lexer_consumeComparatorSigns, _Lexer_consumeEqualSign, _Lexer_consumeIdentifier, _Lexer_consumeNegativeNumber, _Lexer_consumeNumber, _Lexer_consumeSquareBracket, _Lexer_initializeForExpression, _Lexer_next, _Lexer_consumeUntil, _Lexer_consumeLiteral, _Lexer_consumeQuotedIdentifier, _Lexer_consumeRawStringLiteral, _Lexer_matchOrElse;
13
1
  import { SIMPLE_TOKENS, START_IDENTIFIER, VALID_IDENTIFIER, VALID_NUMBER, WHITESPACE, } from './constants.js';
14
2
  import { EmptyExpressionError, LexerError } from './errors.js';
15
3
  /**
@@ -18,37 +6,11 @@ import { EmptyExpressionError, LexerError } from './errors.js';
18
6
  * This lexer tokenizes a JMESPath expression into a sequence of tokens.
19
7
  */
20
8
  class Lexer {
21
- constructor() {
22
- _Lexer_instances.add(this);
23
- _Lexer_position.set(this, void 0);
24
- _Lexer_expression.set(this, void 0);
25
- _Lexer_chars.set(this, void 0);
26
- _Lexer_current.set(this, void 0);
27
- _Lexer_length.set(this, void 0);
28
- /**
29
- * Consume a comparator sign.
30
- *
31
- * This method is called when the lexer encounters a comparator sign.
32
- *
33
- * @param current The current character
34
- */
35
- _Lexer_consumeComparatorSigns.set(this, (current) => {
36
- switch (current) {
37
- case '<':
38
- return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '=', 'lte', 'lt');
39
- case '>':
40
- return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '=', 'gte', 'gt');
41
- case '!':
42
- return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '=', 'ne', 'not');
43
- case '|':
44
- return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '|', 'or', 'pipe');
45
- case '&':
46
- return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '&', 'and', 'expref');
47
- default:
48
- return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeEqualSign).call(this);
49
- }
50
- });
51
- }
9
+ #position;
10
+ #expression;
11
+ #chars;
12
+ #current;
13
+ #length;
52
14
  /**
53
15
  * Tokenize a JMESPath expression.
54
16
  *
@@ -57,38 +19,38 @@ class Lexer {
57
19
  * @param expression The JMESPath expression to tokenize.
58
20
  */
59
21
  *tokenize(expression) {
60
- __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_initializeForExpression).call(this, expression);
61
- while (__classPrivateFieldGet(this, _Lexer_current, "f") !== '' && __classPrivateFieldGet(this, _Lexer_current, "f") !== undefined) {
62
- if (SIMPLE_TOKENS.has(__classPrivateFieldGet(this, _Lexer_current, "f"))) {
22
+ this.#initializeForExpression(expression);
23
+ while (this.#current !== '' && this.#current !== undefined) {
24
+ if (SIMPLE_TOKENS.has(this.#current)) {
63
25
  yield {
64
26
  // We know that SIMPLE_TOKENS has this.#current as a key because
65
27
  // we checked for that above.
66
28
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
67
- type: SIMPLE_TOKENS.get(__classPrivateFieldGet(this, _Lexer_current, "f")),
68
- value: __classPrivateFieldGet(this, _Lexer_current, "f"),
69
- start: __classPrivateFieldGet(this, _Lexer_position, "f"),
70
- end: __classPrivateFieldGet(this, _Lexer_position, "f") + 1,
29
+ type: SIMPLE_TOKENS.get(this.#current),
30
+ value: this.#current,
31
+ start: this.#position,
32
+ end: this.#position + 1,
71
33
  };
72
- __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
34
+ this.#next();
73
35
  }
74
- else if (START_IDENTIFIER.has(__classPrivateFieldGet(this, _Lexer_current, "f"))) {
75
- yield __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeIdentifier).call(this);
36
+ else if (START_IDENTIFIER.has(this.#current)) {
37
+ yield this.#consumeIdentifier();
76
38
  }
77
- else if (WHITESPACE.has(__classPrivateFieldGet(this, _Lexer_current, "f"))) {
78
- __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
39
+ else if (WHITESPACE.has(this.#current)) {
40
+ this.#next();
79
41
  }
80
- else if (__classPrivateFieldGet(this, _Lexer_current, "f") === '[') {
81
- yield __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeSquareBracket).call(this);
42
+ else if (this.#current === '[') {
43
+ yield this.#consumeSquareBracket();
82
44
  }
83
- else if (__classPrivateFieldGet(this, _Lexer_current, "f") === `'`) {
84
- yield __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeRawStringLiteral).call(this);
45
+ else if (this.#current === `'`) {
46
+ yield this.#consumeRawStringLiteral();
85
47
  }
86
- else if (__classPrivateFieldGet(this, _Lexer_current, "f") === '`') {
87
- yield __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeLiteral).call(this);
48
+ else if (this.#current === '`') {
49
+ yield this.#consumeLiteral();
88
50
  }
89
- else if (VALID_NUMBER.has(__classPrivateFieldGet(this, _Lexer_current, "f"))) {
90
- const start = __classPrivateFieldGet(this, _Lexer_position, "f");
91
- const buff = __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeNumber).call(this);
51
+ else if (VALID_NUMBER.has(this.#current)) {
52
+ const start = this.#position;
53
+ const buff = this.#consumeNumber();
92
54
  yield {
93
55
  type: 'number',
94
56
  value: parseInt(buff),
@@ -96,173 +58,282 @@ class Lexer {
96
58
  end: start + buff.length,
97
59
  };
98
60
  }
99
- else if (__classPrivateFieldGet(this, _Lexer_current, "f") === '-') {
100
- yield __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeNegativeNumber).call(this);
61
+ else if (this.#current === '-') {
62
+ yield this.#consumeNegativeNumber();
101
63
  }
102
- else if (__classPrivateFieldGet(this, _Lexer_current, "f") === '"') {
103
- yield __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeQuotedIdentifier).call(this);
64
+ else if (this.#current === '"') {
65
+ yield this.#consumeQuotedIdentifier();
104
66
  }
105
- else if (['<', '>', '!', '=', '|', '&'].includes(__classPrivateFieldGet(this, _Lexer_current, "f"))) {
106
- yield __classPrivateFieldGet(this, _Lexer_consumeComparatorSigns, "f").call(this, __classPrivateFieldGet(this, _Lexer_current, "f"));
67
+ else if (['<', '>', '!', '=', '|', '&'].includes(this.#current)) {
68
+ yield this.#consumeComparatorSigns(this.#current);
107
69
  }
108
70
  else {
109
- throw new LexerError(__classPrivateFieldGet(this, _Lexer_position, "f"), __classPrivateFieldGet(this, _Lexer_current, "f"));
71
+ throw new LexerError(this.#position, this.#current);
110
72
  }
111
73
  }
112
- yield { type: 'eof', value: '', start: __classPrivateFieldGet(this, _Lexer_length, "f"), end: __classPrivateFieldGet(this, _Lexer_length, "f") };
113
- }
114
- }
115
- _Lexer_position = new WeakMap(), _Lexer_expression = new WeakMap(), _Lexer_chars = new WeakMap(), _Lexer_current = new WeakMap(), _Lexer_length = new WeakMap(), _Lexer_consumeComparatorSigns = new WeakMap(), _Lexer_instances = new WeakSet(), _Lexer_consumeEqualSign = function _Lexer_consumeEqualSign() {
116
- if (__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this) === '=') {
117
- __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
118
- return {
119
- type: 'eq',
120
- value: '==',
121
- start: __classPrivateFieldGet(this, _Lexer_position, "f") - 1,
122
- end: __classPrivateFieldGet(this, _Lexer_position, "f"),
123
- };
124
- }
125
- else {
126
- throw new LexerError(__classPrivateFieldGet(this, _Lexer_position, "f") - 1, '=');
127
- }
128
- }, _Lexer_consumeIdentifier = function _Lexer_consumeIdentifier() {
129
- const start = __classPrivateFieldGet(this, _Lexer_position, "f");
130
- let buff = __classPrivateFieldGet(this, _Lexer_current, "f");
131
- while (VALID_IDENTIFIER.has(__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this))) {
132
- buff += __classPrivateFieldGet(this, _Lexer_current, "f");
74
+ yield { type: 'eof', value: '', start: this.#length, end: this.#length };
133
75
  }
134
- return {
135
- type: 'unquoted_identifier',
136
- value: buff,
137
- start,
138
- end: start + buff.length,
76
+ /**
77
+ * Consume a comparator sign.
78
+ *
79
+ * This method is called when the lexer encounters a comparator sign.
80
+ *
81
+ * @param current The current character
82
+ */
83
+ #consumeComparatorSigns = (current) => {
84
+ switch (current) {
85
+ case '<':
86
+ return this.#matchOrElse('=', 'lte', 'lt');
87
+ case '>':
88
+ return this.#matchOrElse('=', 'gte', 'gt');
89
+ case '!':
90
+ return this.#matchOrElse('=', 'ne', 'not');
91
+ case '|':
92
+ return this.#matchOrElse('|', 'or', 'pipe');
93
+ case '&':
94
+ return this.#matchOrElse('&', 'and', 'expref');
95
+ default:
96
+ return this.#consumeEqualSign();
97
+ }
139
98
  };
140
- }, _Lexer_consumeNegativeNumber = function _Lexer_consumeNegativeNumber() {
141
- const start = __classPrivateFieldGet(this, _Lexer_position, "f");
142
- const buff = __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeNumber).call(this);
143
- if (buff.length > 1) {
99
+ /**
100
+ * Consume an equal sign.
101
+ *
102
+ * This method is called when the lexer encounters an equal sign.
103
+ * It checks if the next character is also an equal sign and returns
104
+ * the corresponding token.
105
+ */
106
+ #consumeEqualSign() {
107
+ if (this.#next() === '=') {
108
+ this.#next();
109
+ return {
110
+ type: 'eq',
111
+ value: '==',
112
+ start: this.#position - 1,
113
+ end: this.#position,
114
+ };
115
+ }
116
+ else {
117
+ throw new LexerError(this.#position - 1, '=');
118
+ }
119
+ }
120
+ /**
121
+ * Consume an unquoted identifier.
122
+ *
123
+ * This method is called when the lexer encounters a character that is a valid
124
+ * identifier. It advances the lexer until it finds a character that is not a
125
+ * valid identifier and returns the corresponding token.
126
+ */
127
+ #consumeIdentifier() {
128
+ const start = this.#position;
129
+ let buff = this.#current;
130
+ while (VALID_IDENTIFIER.has(this.#next())) {
131
+ buff += this.#current;
132
+ }
144
133
  return {
145
- type: 'number',
146
- value: parseInt(buff),
147
- start: start,
134
+ type: 'unquoted_identifier',
135
+ value: buff,
136
+ start,
148
137
  end: start + buff.length,
149
138
  };
150
139
  }
151
- else {
152
- // If the negative sign is not followed by a number, it is an error.
153
- throw new LexerError(start, 'Unknown token after "-"');
154
- }
155
- }, _Lexer_consumeNumber = function _Lexer_consumeNumber() {
156
- let buff = __classPrivateFieldGet(this, _Lexer_current, "f");
157
- while (VALID_NUMBER.has(__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this))) {
158
- buff += __classPrivateFieldGet(this, _Lexer_current, "f");
159
- }
160
- return buff;
161
- }, _Lexer_consumeSquareBracket = function _Lexer_consumeSquareBracket() {
162
- const start = __classPrivateFieldGet(this, _Lexer_position, "f");
163
- const nextChar = __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
164
- if (nextChar == ']') {
165
- __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
166
- return { type: 'flatten', value: '[]', start: start, end: start + 2 };
140
+ /**
141
+ * Consume a negative number.
142
+ *
143
+ * This method is called when the lexer encounters a negative sign.
144
+ * It checks if the next character is a number and returns the corresponding token.
145
+ */
146
+ #consumeNegativeNumber() {
147
+ const start = this.#position;
148
+ const buff = this.#consumeNumber();
149
+ if (buff.length > 1) {
150
+ return {
151
+ type: 'number',
152
+ value: parseInt(buff),
153
+ start: start,
154
+ end: start + buff.length,
155
+ };
156
+ }
157
+ else {
158
+ // If the negative sign is not followed by a number, it is an error.
159
+ throw new LexerError(start, 'Unknown token after "-"');
160
+ }
167
161
  }
168
- else if (nextChar == '?') {
169
- __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
170
- return { type: 'filter', value: '[?', start: start, end: start + 2 };
162
+ /**
163
+ * Consume a raw string that is a number.
164
+ *
165
+ * It takes the current position and advances
166
+ * the lexer until it finds a character that
167
+ * is not a number.
168
+ */
169
+ #consumeNumber() {
170
+ let buff = this.#current;
171
+ while (VALID_NUMBER.has(this.#next())) {
172
+ buff += this.#current;
173
+ }
174
+ return buff;
171
175
  }
172
- else {
173
- return { type: 'lbracket', value: '[', start: start, end: start + 1 };
176
+ /**
177
+ * Consume a square bracket.
178
+ *
179
+ * This method is called when the lexer encounters a square bracket.
180
+ * It checks if the next character is a question mark or a closing
181
+ * square bracket and returns the corresponding token.
182
+ */
183
+ #consumeSquareBracket() {
184
+ const start = this.#position;
185
+ const nextChar = this.#next();
186
+ if (nextChar == ']') {
187
+ this.#next();
188
+ return { type: 'flatten', value: '[]', start: start, end: start + 2 };
189
+ }
190
+ else if (nextChar == '?') {
191
+ this.#next();
192
+ return { type: 'filter', value: '[?', start: start, end: start + 2 };
193
+ }
194
+ else {
195
+ return { type: 'lbracket', value: '[', start: start, end: start + 1 };
196
+ }
174
197
  }
175
- }, _Lexer_initializeForExpression = function _Lexer_initializeForExpression(expression) {
176
- if (typeof expression !== 'string') {
177
- throw new EmptyExpressionError();
198
+ /**
199
+ * Initializes the lexer for the given expression.
200
+ *
201
+ * We use a separate method for this instead of the constructor
202
+ * because we want to be able to reuse the same lexer instance
203
+ * and also because we want to be able to expose a public API
204
+ * for tokenizing expressions like `new Lexer().tokenize(expression)`.
205
+ *
206
+ * @param expression The JMESPath expression to tokenize.
207
+ */
208
+ #initializeForExpression(expression) {
209
+ if (typeof expression !== 'string') {
210
+ throw new EmptyExpressionError();
211
+ }
212
+ this.#position = 0;
213
+ this.#expression = expression;
214
+ this.#chars = Array.from(expression);
215
+ this.#current = this.#chars[0];
216
+ this.#length = this.#expression.length;
178
217
  }
179
- __classPrivateFieldSet(this, _Lexer_position, 0, "f");
180
- __classPrivateFieldSet(this, _Lexer_expression, expression, "f");
181
- __classPrivateFieldSet(this, _Lexer_chars, Array.from(expression), "f");
182
- __classPrivateFieldSet(this, _Lexer_current, __classPrivateFieldGet(this, _Lexer_chars, "f")[0], "f");
183
- __classPrivateFieldSet(this, _Lexer_length, __classPrivateFieldGet(this, _Lexer_expression, "f").length, "f");
184
- }, _Lexer_next = function _Lexer_next() {
185
- if (__classPrivateFieldGet(this, _Lexer_position, "f") === __classPrivateFieldGet(this, _Lexer_length, "f") - 1) {
186
- __classPrivateFieldSet(this, _Lexer_current, '', "f");
218
+ /**
219
+ * Advance the lexer to the next character in the expression.
220
+ */
221
+ #next() {
222
+ if (this.#position === this.#length - 1) {
223
+ this.#current = '';
224
+ }
225
+ else {
226
+ this.#position += 1;
227
+ this.#current = this.#chars[this.#position];
228
+ }
229
+ return this.#current;
187
230
  }
188
- else {
189
- __classPrivateFieldSet(this, _Lexer_position, __classPrivateFieldGet(this, _Lexer_position, "f") + 1, "f");
190
- __classPrivateFieldSet(this, _Lexer_current, __classPrivateFieldGet(this, _Lexer_chars, "f")[__classPrivateFieldGet(this, _Lexer_position, "f")], "f");
231
+ /**
232
+ * Consume until the given delimiter is reached allowing
233
+ * for escaping of the delimiter with a backslash (`\`).
234
+ *
235
+ * @param delimiter The delimiter to consume until.
236
+ */
237
+ #consumeUntil(delimiter) {
238
+ const start = this.#position;
239
+ let buff = '';
240
+ this.#next();
241
+ while (this.#current !== delimiter) {
242
+ if (this.#current === '\\') {
243
+ buff += '\\';
244
+ this.#next();
245
+ }
246
+ if (this.#current === '') {
247
+ // We've reached the end of the expression (EOF) before
248
+ // we found the delimiter. This is an error.
249
+ throw new LexerError(start, this.#expression.substring(start));
250
+ }
251
+ buff += this.#current;
252
+ this.#next();
253
+ }
254
+ // Skip the closing delimiter
255
+ this.#next();
256
+ return buff;
191
257
  }
192
- return __classPrivateFieldGet(this, _Lexer_current, "f");
193
- }, _Lexer_consumeUntil = function _Lexer_consumeUntil(delimiter) {
194
- const start = __classPrivateFieldGet(this, _Lexer_position, "f");
195
- let buff = '';
196
- __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
197
- while (__classPrivateFieldGet(this, _Lexer_current, "f") !== delimiter) {
198
- if (__classPrivateFieldGet(this, _Lexer_current, "f") === '\\') {
199
- buff += '\\';
200
- __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
258
+ /**
259
+ * Process a literal.
260
+ *
261
+ * A literal is a JSON string that is enclosed in backticks.
262
+ */
263
+ #consumeLiteral() {
264
+ const start = this.#position;
265
+ const lexeme = this.#consumeUntil('`').replace('\\`', '`');
266
+ try {
267
+ const parsedJson = JSON.parse(lexeme);
268
+ return {
269
+ type: 'literal',
270
+ value: parsedJson,
271
+ start,
272
+ end: this.#position - start,
273
+ };
201
274
  }
202
- if (__classPrivateFieldGet(this, _Lexer_current, "f") === '') {
203
- // We've reached the end of the expression (EOF) before
204
- // we found the delimiter. This is an error.
205
- throw new LexerError(start, __classPrivateFieldGet(this, _Lexer_expression, "f").substring(start));
275
+ catch (error) {
276
+ throw new LexerError(start, lexeme);
206
277
  }
207
- buff += __classPrivateFieldGet(this, _Lexer_current, "f");
208
- __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
209
278
  }
210
- // Skip the closing delimiter
211
- __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
212
- return buff;
213
- }, _Lexer_consumeLiteral = function _Lexer_consumeLiteral() {
214
- const start = __classPrivateFieldGet(this, _Lexer_position, "f");
215
- const lexeme = __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeUntil).call(this, '`').replace('\\`', '`');
216
- try {
217
- const parsedJson = JSON.parse(lexeme);
279
+ /**
280
+ * Process a quoted identifier.
281
+ *
282
+ * A quoted identifier is a string that is enclosed in double quotes.
283
+ */
284
+ #consumeQuotedIdentifier() {
285
+ const start = this.#position;
286
+ const lexeme = '"' + this.#consumeUntil('"') + '"';
287
+ const tokenLen = this.#position - start;
218
288
  return {
219
- type: 'literal',
220
- value: parsedJson,
289
+ type: 'quoted_identifier',
290
+ value: JSON.parse(lexeme),
221
291
  start,
222
- end: __classPrivateFieldGet(this, _Lexer_position, "f") - start,
292
+ end: tokenLen,
223
293
  };
224
294
  }
225
- catch (error) {
226
- throw new LexerError(start, lexeme);
295
+ /**
296
+ * Process a raw string literal.
297
+ *
298
+ * A raw string literal is a string that is enclosed in single quotes.
299
+ */
300
+ #consumeRawStringLiteral() {
301
+ const start = this.#position;
302
+ const lexeme = this.#consumeUntil(`'`).replace(`\\'`, `'`);
303
+ const tokenLen = this.#position - start;
304
+ return {
305
+ type: 'literal',
306
+ value: lexeme,
307
+ start,
308
+ end: tokenLen,
309
+ };
227
310
  }
228
- }, _Lexer_consumeQuotedIdentifier = function _Lexer_consumeQuotedIdentifier() {
229
- const start = __classPrivateFieldGet(this, _Lexer_position, "f");
230
- const lexeme = '"' + __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeUntil).call(this, '"') + '"';
231
- const tokenLen = __classPrivateFieldGet(this, _Lexer_position, "f") - start;
232
- return {
233
- type: 'quoted_identifier',
234
- value: JSON.parse(lexeme),
235
- start,
236
- end: tokenLen,
237
- };
238
- }, _Lexer_consumeRawStringLiteral = function _Lexer_consumeRawStringLiteral() {
239
- const start = __classPrivateFieldGet(this, _Lexer_position, "f");
240
- const lexeme = __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeUntil).call(this, `'`).replace(`\\'`, `'`);
241
- const tokenLen = __classPrivateFieldGet(this, _Lexer_position, "f") - start;
242
- return {
243
- type: 'literal',
244
- value: lexeme,
245
- start,
246
- end: tokenLen,
247
- };
248
- }, _Lexer_matchOrElse = function _Lexer_matchOrElse(expected, matchType, elseType) {
249
- const start = __classPrivateFieldGet(this, _Lexer_position, "f");
250
- const current = __classPrivateFieldGet(this, _Lexer_current, "f");
251
- const nextChar = __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
252
- if (nextChar === expected) {
253
- __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
311
+ /**
312
+ * Match the expected character and return the corresponding token type.
313
+ *
314
+ * @param expected The expected character
315
+ * @param matchType The token type to return if the expected character is found
316
+ * @param elseType The token type to return if the expected character is not found
317
+ */
318
+ #matchOrElse(expected, matchType, elseType) {
319
+ const start = this.#position;
320
+ const current = this.#current;
321
+ const nextChar = this.#next();
322
+ if (nextChar === expected) {
323
+ this.#next();
324
+ return {
325
+ type: matchType,
326
+ value: current + nextChar,
327
+ start,
328
+ end: start + 2,
329
+ };
330
+ }
254
331
  return {
255
- type: matchType,
256
- value: current + nextChar,
332
+ type: elseType,
333
+ value: current,
257
334
  start,
258
- end: start + 2,
335
+ end: start,
259
336
  };
260
337
  }
261
- return {
262
- type: elseType,
263
- value: current,
264
- start,
265
- end: start,
266
- };
267
- };
338
+ }
268
339
  export { Lexer };
@@ -1,6 +1,8 @@
1
1
  import { TreeInterpreter } from './TreeInterpreter.js';
2
2
  import { ArityError, JMESPathTypeError, UnknownFunctionError, VariadicArityError, } from './errors.js';
3
3
  class ParsedResult {
4
+ expression;
5
+ parsed;
4
6
  constructor(expression, parsed) {
5
7
  this.expression = expression;
6
8
  this.parsed = parsed;