@witchcraft/expressit 0.2.2 → 0.3.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.
Files changed (122) hide show
  1. package/README.md +1 -2
  2. package/dist/Lexer.d.ts +99 -94
  3. package/dist/Lexer.d.ts.map +1 -1
  4. package/dist/Lexer.js +221 -574
  5. package/dist/Parser.d.ts +26 -26
  6. package/dist/Parser.d.ts.map +1 -1
  7. package/dist/Parser.js +106 -116
  8. package/dist/ast/builders/array.js +7 -8
  9. package/dist/ast/builders/condition.d.ts +1 -1
  10. package/dist/ast/builders/condition.d.ts.map +1 -1
  11. package/dist/ast/builders/condition.js +2 -1
  12. package/dist/ast/builders/delim.d.ts +2 -2
  13. package/dist/ast/builders/delim.d.ts.map +1 -1
  14. package/dist/ast/builders/error.d.ts +2 -2
  15. package/dist/ast/builders/error.d.ts.map +1 -1
  16. package/dist/ast/builders/expression.d.ts +2 -2
  17. package/dist/ast/builders/expression.d.ts.map +1 -1
  18. package/dist/ast/builders/expression.js +4 -8
  19. package/dist/ast/builders/group.d.ts +1 -1
  20. package/dist/ast/builders/group.d.ts.map +1 -1
  21. package/dist/ast/builders/group.js +8 -11
  22. package/dist/ast/builders/pos.d.ts +2 -2
  23. package/dist/ast/builders/pos.d.ts.map +1 -1
  24. package/dist/ast/builders/token.d.ts +2 -2
  25. package/dist/ast/builders/token.d.ts.map +1 -1
  26. package/dist/ast/builders/token.js +1 -1
  27. package/dist/ast/builders/type.d.ts +2 -2
  28. package/dist/ast/builders/type.d.ts.map +1 -1
  29. package/dist/ast/builders/variable.d.ts +3 -3
  30. package/dist/ast/builders/variable.d.ts.map +1 -1
  31. package/dist/ast/builders/variable.js +5 -6
  32. package/dist/ast/createConditionNode.d.ts +1 -1
  33. package/dist/ast/createConditionNode.d.ts.map +1 -1
  34. package/dist/ast/createConditionNode.js +1 -2
  35. package/dist/ast/createGroupNode.d.ts +1 -1
  36. package/dist/ast/createGroupNode.d.ts.map +1 -1
  37. package/dist/ast/createToken.d.ts +2 -2
  38. package/dist/ast/createToken.d.ts.map +1 -1
  39. package/dist/ast/createToken.js +2 -2
  40. package/dist/ast/error.d.ts +2 -2
  41. package/dist/ast/error.d.ts.map +1 -1
  42. package/dist/ast/error.js +1 -0
  43. package/dist/ast/handlers.d.ts +23 -23
  44. package/dist/ast/handlers.d.ts.map +1 -1
  45. package/dist/ast/handlers.js +23 -26
  46. package/dist/examples/ParserWithSqlSupport.d.ts +5 -5
  47. package/dist/examples/ParserWithSqlSupport.d.ts.map +1 -1
  48. package/dist/examples/ParserWithSqlSupport.js +22 -28
  49. package/dist/examples/ShortcutContextParser.js +2 -5
  50. package/dist/index.js +2 -2
  51. package/dist/internal/ExpressitError.d.ts +2 -2
  52. package/dist/internal/ExpressitError.d.ts.map +1 -1
  53. package/dist/internal/ExpressitError.js +7 -10
  54. package/dist/internal/checkParserOpts.js +21 -22
  55. package/dist/internal/escapeVariableOrPrefix.js +1 -1
  56. package/dist/internal/parseParserOptions.js +3 -4
  57. package/dist/package.json.js +2 -60
  58. package/dist/types/ast.d.ts +60 -58
  59. package/dist/types/ast.d.ts.map +1 -1
  60. package/dist/types/ast.js +26 -27
  61. package/dist/types/autocomplete.d.ts +23 -21
  62. package/dist/types/autocomplete.d.ts.map +1 -1
  63. package/dist/types/autocomplete.js +24 -21
  64. package/dist/types/errors.d.ts +12 -10
  65. package/dist/types/errors.d.ts.map +1 -1
  66. package/dist/types/errors.js +8 -7
  67. package/dist/types/index.js +2 -2
  68. package/dist/types/parser.d.ts +3 -3
  69. package/dist/types/parser.d.ts.map +1 -1
  70. package/dist/utils/extractTokens.js +4 -5
  71. package/dist/utils/generateParentsMap.js +7 -8
  72. package/dist/utils/getCursorInfo.js +5 -3
  73. package/dist/utils/getOppositeDelimiter.d.ts +2 -2
  74. package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
  75. package/dist/utils/getOppositeDelimiter.js +1 -1
  76. package/dist/utils/getSurroundingErrors.js +2 -3
  77. package/dist/utils/isBracket.js +1 -1
  78. package/dist/utils/isDelimiter.d.ts +2 -2
  79. package/dist/utils/isDelimiter.d.ts.map +1 -1
  80. package/dist/utils/isDelimiter.js +1 -1
  81. package/dist/utils/isNode.js +1 -1
  82. package/dist/utils/isParen.d.ts +2 -2
  83. package/dist/utils/isParen.d.ts.map +1 -1
  84. package/dist/utils/isParen.js +1 -1
  85. package/dist/utils/isQuote.d.ts +2 -2
  86. package/dist/utils/isQuote.d.ts.map +1 -1
  87. package/dist/utils/isQuote.js +1 -1
  88. package/dist/utils/isToken.js +1 -1
  89. package/dist/utils/prettyAst.js +10 -11
  90. package/package.json +19 -20
  91. package/src/Lexer.ts +100 -90
  92. package/src/Parser.ts +68 -68
  93. package/src/ast/builders/condition.ts +3 -3
  94. package/src/ast/builders/delim.ts +4 -4
  95. package/src/ast/builders/error.ts +3 -3
  96. package/src/ast/builders/expression.ts +4 -8
  97. package/src/ast/builders/group.ts +2 -4
  98. package/src/ast/builders/pos.ts +3 -3
  99. package/src/ast/builders/token.ts +3 -3
  100. package/src/ast/builders/type.ts +2 -2
  101. package/src/ast/builders/variable.ts +5 -5
  102. package/src/ast/createConditionNode.ts +2 -2
  103. package/src/ast/createGroupNode.ts +4 -4
  104. package/src/ast/createToken.ts +6 -6
  105. package/src/ast/error.ts +2 -2
  106. package/src/ast/handlers.ts +20 -20
  107. package/src/examples/ParserWithSqlSupport.ts +12 -6
  108. package/src/internal/ExpressitError.ts +6 -6
  109. package/src/internal/checkParserOpts.ts +13 -13
  110. package/src/internal/escapeVariableOrPrefix.ts +1 -1
  111. package/src/types/ast.ts +101 -96
  112. package/src/types/autocomplete.ts +26 -22
  113. package/src/types/errors.ts +18 -13
  114. package/src/types/parser.ts +3 -3
  115. package/src/utils/extractTokens.ts +1 -1
  116. package/src/utils/getCursorInfo.ts +2 -2
  117. package/src/utils/getOppositeDelimiter.ts +3 -3
  118. package/src/utils/getSurroundingErrors.ts +4 -4
  119. package/src/utils/isDelimiter.ts +3 -3
  120. package/src/utils/isParen.ts +2 -2
  121. package/src/utils/isQuote.ts +2 -2
  122. package/src/utils/prettyAst.ts +3 -3
package/dist/Parser.js CHANGED
@@ -1,12 +1,9 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { get } from "@alanscodelog/utils/get.js";
5
- import { insert } from "@alanscodelog/utils/insert.js";
6
- import { isArray } from "@alanscodelog/utils/isArray.js";
7
- import { isWhitespace } from "@alanscodelog/utils/isWhitespace.js";
8
- import { setReadOnly } from "@alanscodelog/utils/setReadOnly.js";
9
- import { unreachable } from "@alanscodelog/utils/unreachable.js";
1
+ import { get } from "@alanscodelog/utils/get";
2
+ import { insert } from "@alanscodelog/utils/insert";
3
+ import { isArray } from "@alanscodelog/utils/isArray";
4
+ import { isWhitespace } from "@alanscodelog/utils/isWhitespace";
5
+ import { setReadOnly } from "@alanscodelog/utils/setReadOnly";
6
+ import { unreachable } from "@alanscodelog/utils/unreachable";
10
7
  import { pos } from "./ast/builders/pos.js";
11
8
  import { createCondition } from "./ast/createNormalizedCondition.js";
12
9
  import { createExpression } from "./ast/createNormalizedExpression.js";
@@ -22,6 +19,7 @@ import { unescape } from "./internal/unescape.js";
22
19
  import { Lexer, $C, $T } from "./Lexer.js";
23
20
  import { TOKEN_TYPE, AST_TYPE } from "./types/ast.js";
24
21
  import { SUGGESTION_TYPE } from "./types/autocomplete.js";
22
+ import "./types/errors.js";
25
23
  import { extractTokens } from "./utils/extractTokens.js";
26
24
  import { generateParentsMap } from "./utils/generateParentsMap.js";
27
25
  import { getCursorInfo } from "./utils/getCursorInfo.js";
@@ -47,7 +45,7 @@ const defaultNodeDirs = {
47
45
  const createDefaultRequires = (partial = {}) => ({
48
46
  whitespace: {
49
47
  ...defaultNodeDirs,
50
- ...partial.whitespace ? partial.whitespace : {}
48
+ ...partial.whitespace ?? {}
51
49
  },
52
50
  group: partial.group ?? false,
53
51
  prefix: partial.prefix ?? false
@@ -58,34 +56,8 @@ const tokenRequiresWhitespace = (valid, whitespace, wordOps) => {
58
56
  };
59
57
  const tokenVariable = [TOKEN_TYPE.BACKTICK, TOKEN_TYPE.DOUBLEQUOTE, TOKEN_TYPE.SINGLEQUOTE, TOKEN_TYPE.VALUE, TOKEN_TYPE.REGEX];
60
58
  class Parser {
61
- constructor(options) {
62
- // needed for evaluate and validate so they are only checked on demand
63
- __publicField(this, "evaluationOptionsChecked", false);
64
- __publicField(this, "validationOptionsChecked", false);
65
- __publicField(this, "options");
66
- __publicField(this, "lexer");
67
- __publicField(this, "$");
68
- __publicField(this, "$categories");
69
- __publicField(this, "info");
70
- __publicField(this, "state", {
71
- rawInput: "",
72
- lexedTokens: [],
73
- index: 0,
74
- shift: 0
75
- });
76
- __publicField(this, "subParserOne");
77
- __publicField(this, "subParserTwo");
78
- const opts = parseParserOptions(options ?? {});
79
- checkParserOpts(opts);
80
- this.options = opts;
81
- this.lexer = new Lexer(opts);
82
- this.$ = this.lexer.$;
83
- this.$categories = this.lexer.$categories;
84
- this.info = {
85
- expandedSepAlsoCustom: this.lexer.symbols.expandedSepAlsoCustom,
86
- customOpAlsoNegation: this.lexer.symbols.customOpAlsoNegation
87
- };
88
- }
59
+ // needed for evaluate and validate so they are only checked on demand
60
+ evaluationOptionsChecked = false;
89
61
  // eslint-disable-next-line @typescript-eslint/naming-convention
90
62
  _checkEvaluationOptions() {
91
63
  if (!this.evaluationOptionsChecked) {
@@ -93,6 +65,7 @@ class Parser {
93
65
  this.evaluationOptionsChecked = true;
94
66
  }
95
67
  }
68
+ validationOptionsChecked = false;
96
69
  // eslint-disable-next-line @typescript-eslint/naming-convention
97
70
  _checkValidationOptions() {
98
71
  if (!this.validationOptionsChecked) {
@@ -100,6 +73,29 @@ class Parser {
100
73
  this.validationOptionsChecked = true;
101
74
  }
102
75
  }
76
+ options;
77
+ lexer;
78
+ $;
79
+ $categories;
80
+ info;
81
+ constructor(options) {
82
+ const opts = parseParserOptions(options ?? {});
83
+ checkParserOpts(opts);
84
+ this.options = opts;
85
+ this.lexer = new Lexer(opts);
86
+ this.$ = this.lexer.$;
87
+ this.$categories = this.lexer.$categories;
88
+ this.info = {
89
+ expandedSepAlsoCustom: this.lexer.symbols.expandedSepAlsoCustom,
90
+ customOpAlsoNegation: this.lexer.symbols.customOpAlsoNegation
91
+ };
92
+ }
93
+ state = {
94
+ rawInput: "",
95
+ lexedTokens: [],
96
+ index: 0,
97
+ shift: 0
98
+ };
103
99
  /**
104
100
  * This is exposed mainly for debugging purposes. Use parse directly instead.
105
101
  */
@@ -148,6 +144,8 @@ class Parser {
148
144
  };
149
145
  return res;
150
146
  }
147
+ subParserOne;
148
+ subParserTwo;
151
149
  createSubParserIfNotExists(opts, which = "One") {
152
150
  if (this[`subParser${which}`] === void 0) {
153
151
  this[`subParser${which}`] = new Parser(opts);
@@ -161,8 +159,7 @@ class Parser {
161
159
  };
162
160
  }
163
161
  getCategoryTokens(type) {
164
- var _a;
165
- return (_a = this.$categories[type]) == null ? void 0 : _a.entries;
162
+ return this.$categories[type]?.entries;
166
163
  }
167
164
  getTokenType(type) {
168
165
  return this.$[type];
@@ -177,9 +174,9 @@ class Parser {
177
174
  if (token2 === void 0) return false;
178
175
  if (token2.type === type) return true;
179
176
  const tokenType = this.getTokenType(token2.type);
180
- if ((tokenType == null ? void 0 : tokenType.type) === type) return true;
177
+ if (tokenType?.type === type) return true;
181
178
  const category = this.$categories[type];
182
- if ((category == null ? void 0 : category.entries[token2.type]) !== void 0) {
179
+ if (category?.entries[token2.type] !== void 0) {
183
180
  return true;
184
181
  }
185
182
  return false;
@@ -207,8 +204,7 @@ class Parser {
207
204
  return this.peek(1) === void 0;
208
205
  }
209
206
  consumeAny() {
210
- var _a;
211
- return this.consume((_a = this.peek(1)) == null ? void 0 : _a.type);
207
+ return this.consume(this.peek(1)?.type);
212
208
  }
213
209
  consume(type) {
214
210
  if (type === void 0) {
@@ -220,21 +216,21 @@ class Parser {
220
216
  }
221
217
  if (this.$categories[type] !== void 0) {
222
218
  const categoryToken = this.$categories[type];
223
- const tokenType = categoryToken == null ? void 0 : categoryToken.entries[nextToken.type];
219
+ const tokenType = categoryToken?.entries[nextToken.type];
224
220
  if (categoryToken && tokenType) {
225
221
  this.state.index++;
226
222
  return this.transformCategoryToken(nextToken, categoryToken);
227
223
  } else {
228
- throw new Error("here");
224
+ unreachable();
229
225
  }
230
226
  } else {
231
227
  const tokenType = this.getTokenType(type);
232
228
  if (tokenType !== void 0) {
233
- if ((nextToken == null ? void 0 : nextToken.type) === tokenType.type) {
229
+ if (nextToken?.type === tokenType.type) {
234
230
  this.state.index++;
235
231
  return nextToken;
236
232
  } else {
237
- throw new Error(`Expected token type ${tokenType.type}, got ${nextToken == null ? void 0 : nextToken.type}`);
233
+ throw new Error(`Expected token type ${tokenType.type}, got ${nextToken?.type}`);
238
234
  }
239
235
  }
240
236
  }
@@ -256,11 +252,10 @@ class Parser {
256
252
  }
257
253
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
258
254
  ruleBool(type) {
259
- var _a;
260
255
  const OP_TYPE = type === "AND" ? $C.OPERATOR_AND : $C.OPERATOR_OR;
261
256
  const pairs = [];
262
257
  let next = this.peek(1);
263
- while (pairs.length < 1 || ((_a = pairs[pairs.length - 1]) == null ? void 0 : _a[1]) !== void 0) {
258
+ while (pairs.length < 1 || pairs[pairs.length - 1]?.[1] !== void 0) {
264
259
  const exp = type === "AND" ? this.ruleCondition() : this.ruleBool("AND");
265
260
  next = this.peek(1);
266
261
  const canAttemptErrorRecovery = type === "AND" ? ["error", "and"].includes(this.options.onMissingBooleanOperator) : this.options.onMissingBooleanOperator === "or";
@@ -328,12 +323,11 @@ class Parser {
328
323
  return res;
329
324
  }
330
325
  ruleCondition() {
331
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
332
326
  const not = this.ruleNot();
333
327
  const property = this.ruleConditionProperty();
334
- const propVal = ((_a = property == null ? void 0 : property.prop) == null ? void 0 : _a.value) === void 0 ? void 0 : !property.prop.value.valid ? "" : property.prop.value.value;
335
- const propOpVal = ((_b = property == null ? void 0 : property.rest) == null ? void 0 : _b.propertyOperator) === void 0 ? void 0 : !((_c = property.rest.propertyOperator) == null ? void 0 : _c.valid) ? "" : (_d = property.rest.propertyOperator) == null ? void 0 : _d.value;
336
- const isExpanded = (((_e = property == null ? void 0 : property.rest) == null ? void 0 : _e.sepL) ?? ((_f = property == null ? void 0 : property.rest) == null ? void 0 : _f.sepR)) !== void 0;
328
+ const propVal = property?.prop?.value === void 0 ? void 0 : !property.prop.value.valid ? "" : property.prop.value.value;
329
+ const propOpVal = property?.rest?.propertyOperator === void 0 ? void 0 : !property.rest.propertyOperator?.valid ? "" : property.rest.propertyOperator?.value;
330
+ const isExpanded = (property?.rest?.sepL ?? property?.rest?.sepR) !== void 0;
337
331
  const convertRegexValues = typeof this.options.regexValues === "function" && !this.options.regexValues(propVal, propOpVal, isExpanded);
338
332
  const convertArrayValues = typeof this.options.arrayValues === "function" && !this.options.arrayValues(propVal, propOpVal, isExpanded);
339
333
  let value = this.ruleConditionValue(property, { convertRegexValues, convertArrayValues });
@@ -345,15 +339,15 @@ class Parser {
345
339
  group$1 = value;
346
340
  value = void 0;
347
341
  }
348
- if (convertRegexValues && isNode(value) && value.type === AST_TYPE.VARIABLE && ((_g = value.quote) == null ? void 0 : _g.left.type) === TOKEN_TYPE.REGEX) {
342
+ if (convertRegexValues && isNode(value) && value.type === AST_TYPE.VARIABLE && value.quote?.left.type === TOKEN_TYPE.REGEX) {
349
343
  value = variable(void 0, void 0, token.value(
350
- (((_i = (_h = value.quote) == null ? void 0 : _h.left) == null ? void 0 : _i.value) ?? "") + (value.value.value ?? "") + (((_k = (_j = value.quote) == null ? void 0 : _j.right) == null ? void 0 : _k.value) ?? ""),
344
+ (value.quote?.left?.value ?? "") + (value.value.value ?? "") + (value.quote?.right?.value ?? ""),
351
345
  pos(value)
352
346
  ), void 0);
353
347
  }
354
348
  if (group$1) {
355
349
  if (property) {
356
- return condition(not, property == null ? void 0 : property.prop, property == null ? void 0 : property.rest, group(void 0, void 0, ...group$1));
350
+ return condition(not, property?.prop, property?.rest, group(void 0, void 0, ...group$1));
357
351
  }
358
352
  if (value) {
359
353
  return group(void 0, condition(not, void 0, void 0, value), ...group$1);
@@ -361,14 +355,14 @@ class Parser {
361
355
  return group(not, value, ...group$1);
362
356
  }
363
357
  if ([not, property, value].every((_) => _ === void 0)) return void 0;
364
- return condition(not, property == null ? void 0 : property.prop, property == null ? void 0 : property.rest, value);
358
+ return condition(not, property?.prop, property?.rest, value);
365
359
  }
366
360
  ruleConditionValue(property, { convertRegexValues = false, convertArrayValues = false } = {}) {
367
361
  const next = this.peek(1);
368
362
  const next2 = this.peek(2);
369
363
  const next3 = this.peek(3);
370
364
  const next4 = this.peek(4);
371
- if (this.options.prefixableGroups && property === void 0 && (next == null ? void 0 : next.type) !== $T.PAREN_L && (this.isType(next, $C.VALUE) && (this.isType(next2, $T.PAREN_L) || this.isType(next2, $C.QUOTE_ANY) && this.isType(next3, $T.PAREN_L)) || this.isType(next, $C.QUOTE_ANY) && (this.isType(next2, $T.PAREN_L) || this.isType(next2, $C.VALUE) && (this.isType(next3, $T.PAREN_L) || // "a(
365
+ if (this.options.prefixableGroups && property === void 0 && next?.type !== $T.PAREN_L && (this.isType(next, $C.VALUE) && (this.isType(next2, $T.PAREN_L) || this.isType(next2, $C.QUOTE_ANY) && this.isType(next3, $T.PAREN_L)) || this.isType(next, $C.QUOTE_ANY) && (this.isType(next2, $T.PAREN_L) || this.isType(next2, $C.VALUE) && (this.isType(next3, $T.PAREN_L) || // "a(
372
366
  this.isType(next3, $C.QUOTE_ANY) && this.isType(next4, $T.PAREN_L))))) {
373
367
  const res = this.ruleVariable({ unprefixed: true });
374
368
  if (res) return res;
@@ -396,7 +390,7 @@ class Parser {
396
390
  if (onlyValues && !this.nextIsEof()) {
397
391
  while (!this.nextIsEof() && (!this.isType(this.peek(1), $T.PAREN_R) || parenLeftCount !== 0)) {
398
392
  const token2 = this.consumeAny();
399
- start ?? (start = extractPosition(token2, this.state.shift).start);
393
+ start ??= extractPosition(token2, this.state.shift).start;
400
394
  if (token2.type === $T.PAREN_L) {
401
395
  parenLeftCount++;
402
396
  }
@@ -406,7 +400,7 @@ class Parser {
406
400
  }
407
401
  }
408
402
  if (start !== void 0) {
409
- end ?? (end = extractPosition(this.peek(0), this.state.shift).end);
403
+ end ??= extractPosition(this.peek(0), this.state.shift).end;
410
404
  }
411
405
  const parenR = this.isType(this.peek(1), $T.PAREN_R) ? this.ruleParenR() : void 0;
412
406
  if (start !== void 0) {
@@ -446,7 +440,7 @@ class Parser {
446
440
  return array(bracketL, values, bracketR);
447
441
  }
448
442
  const start = bracketL.start;
449
- const end = bracketR == null ? void 0 : bracketR.end;
443
+ const end = bracketR?.end;
450
444
  const subInput = this.state.rawInput.slice(start, end);
451
445
  this.createSubParserIfNotExists({
452
446
  ...this.options,
@@ -508,12 +502,12 @@ class Parser {
508
502
  const next3 = this.peek(3);
509
503
  if (next && (this.isExactType(next, $T.QUOTE_DOUBLE) || this.isExactType(next, $T.QUOTE_SINGLE) || this.isExactType(next, $T.QUOTE_BACKTICK))) {
510
504
  const quoteType = next.type;
511
- if ((next2 == null ? void 0 : next2.type) === quoteType) {
505
+ if (next2?.type === quoteType) {
512
506
  const quoteL = this.ruleQuote(quoteType);
513
507
  const quoteR = this.ruleQuote(quoteType);
514
508
  return variable(void 0, quoteL, void 0, quoteR);
515
509
  }
516
- if ((next3 == null ? void 0 : next3.type) === next.type) {
510
+ if (next3?.type === next.type) {
517
511
  const quoteL = this.ruleQuote(quoteType);
518
512
  const value = this.isType(next2, $T.VALUE_UNQUOTED) ? this.ruleValueUnquoted({}) : this.ruleValueNot(quoteType);
519
513
  const quoteR = this.ruleQuote(quoteType);
@@ -594,8 +588,8 @@ class Parser {
594
588
  }
595
589
  ruleQuote(type) {
596
590
  const quote = this.peek(1);
597
- if (type !== (quote == null ? void 0 : quote.type)) {
598
- throw new Error(`Expected quote type ${type}, got ${quote == null ? void 0 : quote.type}`);
591
+ if (type !== quote?.type) {
592
+ throw new Error(`Expected quote type ${type}, got ${quote?.type}`);
599
593
  }
600
594
  switch (type) {
601
595
  case $T.QUOTE_SINGLE:
@@ -635,7 +629,7 @@ class Parser {
635
629
  }
636
630
  ruleParenL() {
637
631
  const next = this.peek(1);
638
- const value = (next == null ? void 0 : next.type) === $T.PAREN_L ? this.consume($T.PAREN_L) : this.createErrorToken($T.PAREN_L);
632
+ const value = next?.type === $T.PAREN_L ? this.consume($T.PAREN_L) : this.createErrorToken($T.PAREN_L);
639
633
  const loc = extractPosition(value, this.state.shift);
640
634
  return this.state.shift === 0 || loc.start > 0 ? delimiter.parenL(value.isError ? void 0 : value.value, loc) : void 0;
641
635
  }
@@ -645,7 +639,7 @@ class Parser {
645
639
  }
646
640
  ruleBracketL() {
647
641
  const next = this.peek(1);
648
- const value = (next == null ? void 0 : next.type) === $T.BRACKET_L ? this.consume($T.BRACKET_L) : this.createErrorToken($T.BRACKET_L);
642
+ const value = next?.type === $T.BRACKET_L ? this.consume($T.BRACKET_L) : this.createErrorToken($T.BRACKET_L);
649
643
  const loc = extractPosition(value, this.state.shift);
650
644
  return this.state.shift === 0 || loc.start > 0 ? delimiter.bracketL(value.isError ? void 0 : value.value, loc) : void 0;
651
645
  }
@@ -703,14 +697,13 @@ class Parser {
703
697
  return [{ suggestion, value: "/" }];
704
698
  case SUGGESTION_TYPE.REGEX_FLAGS:
705
699
  return regexFlags.map((value) => ({ suggestion, value })).filter((completion) => {
706
- var _a, _b, _c, _d, _e, _f, _g;
707
700
  const { suggestion: suggestion2, value } = completion;
708
701
  if (suggestion2.type !== SUGGESTION_TYPE.REGEX_FLAGS) {
709
702
  return true;
710
703
  }
711
704
  const token2 = suggestion2.cursorInfo;
712
- const flags = token2.at && ((_b = (_a = getParent(token2.at, parentMap)) == null ? void 0 : _a.quote) == null ? void 0 : _b.flags) === suggestion2.cursorInfo.at ? token2.at : token2.next && ((_d = (_c = getParent(token2.next, parentMap)) == null ? void 0 : _c.quote) == null ? void 0 : _d.flags) === suggestion2.cursorInfo.next ? token2.next : token2.prev && ((_f = (_e = getParent(token2.prev, parentMap)) == null ? void 0 : _e.quote) == null ? void 0 : _f.flags) === suggestion2.cursorInfo.prev ? token2.prev : void 0;
713
- if ((_g = flags == null ? void 0 : flags.value) == null ? void 0 : _g.includes(value)) {
705
+ const flags = token2.at && getParent(token2.at, parentMap)?.quote?.flags === suggestion2.cursorInfo.at ? token2.at : token2.next && getParent(token2.next, parentMap)?.quote?.flags === suggestion2.cursorInfo.next ? token2.next : token2.prev && getParent(token2.prev, parentMap)?.quote?.flags === suggestion2.cursorInfo.prev ? token2.prev : void 0;
706
+ if (flags?.value?.includes(value)) {
714
707
  return false;
715
708
  }
716
709
  return true;
@@ -801,14 +794,13 @@ class Parser {
801
794
  * ```
802
795
  */
803
796
  autosuggest(input, ast, index) {
804
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
805
797
  const parentMap = generateParentsMap(ast);
806
798
  const opts = this.options;
807
799
  const tokens = extractTokens(ast);
808
800
  const token2 = getCursorInfo(input, tokens, index);
809
801
  const wordOps = [...opts.keywords.and, ...opts.keywords.or, ...opts.keywords.not].filter((op) => !op.isSymbol);
810
- const canSuggestOpAfterPrev = token2.valid.prev && tokenVariable.includes((_a = token2.valid.prev) == null ? void 0 : _a.type) && (token2.whitespace.prev || token2.valid.prev.type === TOKEN_TYPE.PARENR) && !token2.at && token2.valid.next === void 0;
811
- const canSuggestOpBeforeNext = token2.valid.next && tokenVariable.includes((_b = token2.valid.next) == null ? void 0 : _b.type) && token2.whitespace.next && // no parenL allowed since check since there will already be prefix suggestions
802
+ const canSuggestOpAfterPrev = token2.valid.prev && tokenVariable.includes(token2.valid.prev?.type) && (token2.whitespace.prev || token2.valid.prev.type === TOKEN_TYPE.PARENR) && !token2.at && token2.valid.next === void 0;
803
+ const canSuggestOpBeforeNext = token2.valid.next && tokenVariable.includes(token2.valid.next?.type) && token2.whitespace.next && // no parenL allowed since check since there will already be prefix suggestions
812
804
  !token2.at && token2.valid.prev === void 0;
813
805
  const requiresWhitespacePrev = tokenRequiresWhitespace(token2.valid.prev, token2.whitespace.prev, wordOps);
814
806
  const requiresWhitespaceNext = tokenRequiresWhitespace(token2.valid.next, token2.whitespace.next, wordOps);
@@ -899,8 +891,8 @@ class Parser {
899
891
  break;
900
892
  case TOKEN_TYPE.VALUE: {
901
893
  const errorParent = getParent(error, parentMap);
902
- const prefixedValue = (errorParent == null ? void 0 : errorParent.type) === AST_TYPE.VARIABLE ? (_d = (_c = getParent(error, parentMap)) == null ? void 0 : _c.prefix) == null ? void 0 : _d.value : false;
903
- const isRegexValue = (errorParent == null ? void 0 : errorParent.type) === AST_TYPE.VARIABLE && (((_e = errorParent.quote) == null ? void 0 : _e.left.type) === TOKEN_TYPE.REGEX || ((_f = errorParent.quote) == null ? void 0 : _f.right.type) === TOKEN_TYPE.REGEX);
894
+ const prefixedValue = errorParent?.type === AST_TYPE.VARIABLE ? getParent(error, parentMap)?.prefix?.value : false;
895
+ const isRegexValue = errorParent?.type === AST_TYPE.VARIABLE && (errorParent.quote?.left.type === TOKEN_TYPE.REGEX || errorParent.quote?.right.type === TOKEN_TYPE.REGEX);
904
896
  if (!isRegexValue) {
905
897
  if (!prefixedValue && opts.prefixableGroups) {
906
898
  suggestions.push({
@@ -971,16 +963,16 @@ class Parser {
971
963
  const nextCondition = getParent(nextVar, parentMap);
972
964
  const atVar = getParent(token2.at, parentMap);
973
965
  const atCondition = getParent(atVar, parentMap);
974
- const isVarPrev = !token2.whitespace.prev && ((_g = token2.valid.prev) == null ? void 0 : _g.type) !== TOKEN_TYPE.REGEX && (prevVar == null ? void 0 : prevVar.type) === AST_TYPE.VARIABLE && ((prevCondition == null ? void 0 : prevCondition.type) === AST_TYPE.CONDITION && prevCondition.value === prevVar && (((_h = prevVar.quote) == null ? void 0 : _h.right) === token2.valid.prev || prevVar.value === token2.valid.prev) || (prevCondition == null ? void 0 : prevCondition.type) === AST_TYPE.ARRAY);
975
- const isVarNext = !token2.whitespace.next && ((_i = token2.valid.next) == null ? void 0 : _i.type) !== TOKEN_TYPE.REGEX && (nextVar == null ? void 0 : nextVar.type) === AST_TYPE.VARIABLE && ((nextCondition == null ? void 0 : nextCondition.type) === AST_TYPE.CONDITION && nextCondition.value === nextVar && (((_j = nextVar.quote) == null ? void 0 : _j.left) === token2.valid.next || nextVar.value === token2.valid.next) || (nextCondition == null ? void 0 : nextCondition.type) === AST_TYPE.ARRAY);
976
- const isVarAt = (atVar == null ? void 0 : atVar.type) === AST_TYPE.VARIABLE && (atCondition == null ? void 0 : atCondition.type) === AST_TYPE.CONDITION || (prevVar == null ? void 0 : prevVar.type) === AST_TYPE.VARIABLE && token2.valid.prev === ((_k = prevVar == null ? void 0 : prevVar.quote) == null ? void 0 : _k.left) || (nextVar == null ? void 0 : nextVar.type) === AST_TYPE.VARIABLE && token2.valid.next === ((_l = nextVar == null ? void 0 : nextVar.quote) == null ? void 0 : _l.right);
977
- const isPropertyPrev = (prevCondition == null ? void 0 : prevCondition.type) === AST_TYPE.CONDITION && prevVar !== void 0 && prevVar === (prevCondition == null ? void 0 : prevCondition.property);
978
- const isPropertyNext = (nextCondition == null ? void 0 : nextCondition.type) === AST_TYPE.CONDITION && nextVar !== void 0 && nextVar === (nextCondition == null ? void 0 : nextCondition.property);
979
- const isPropertyAt = (atCondition == null ? void 0 : atCondition.type) === AST_TYPE.CONDITION && atVar !== void 0 && atVar === (atCondition == null ? void 0 : atCondition.property);
980
- const isPropertyOperatorPrev = (prevVar == null ? void 0 : prevVar.type) === AST_TYPE.CONDITION && token2.valid.prev === (prevVar == null ? void 0 : prevVar.propertyOperator);
981
- const isPropertyOperatorNext = (nextVar == null ? void 0 : nextVar.type) === AST_TYPE.CONDITION && token2.valid.next === (nextVar == null ? void 0 : nextVar.propertyOperator);
982
- const isPropertyOperatorAt = (atVar == null ? void 0 : atVar.type) === AST_TYPE.CONDITION && token2.at === (atVar == null ? void 0 : atVar.propertyOperator);
983
- const noArrayValuesTarget = ((_m = token2.valid.prev) == null ? void 0 : _m.type) === TOKEN_TYPE.BRACKETL && (token2.valid.next === void 0 || ((_n = token2.valid.next) == null ? void 0 : _n.type) === TOKEN_TYPE.BRACKETR);
966
+ const isVarPrev = !token2.whitespace.prev && token2.valid.prev?.type !== TOKEN_TYPE.REGEX && prevVar?.type === AST_TYPE.VARIABLE && (prevCondition?.type === AST_TYPE.CONDITION && prevCondition.value === prevVar && (prevVar.quote?.right === token2.valid.prev || prevVar.value === token2.valid.prev) || prevCondition?.type === AST_TYPE.ARRAY);
967
+ const isVarNext = !token2.whitespace.next && token2.valid.next?.type !== TOKEN_TYPE.REGEX && nextVar?.type === AST_TYPE.VARIABLE && (nextCondition?.type === AST_TYPE.CONDITION && nextCondition.value === nextVar && (nextVar.quote?.left === token2.valid.next || nextVar.value === token2.valid.next) || nextCondition?.type === AST_TYPE.ARRAY);
968
+ const isVarAt = atVar?.type === AST_TYPE.VARIABLE && atCondition?.type === AST_TYPE.CONDITION || prevVar?.type === AST_TYPE.VARIABLE && token2.valid.prev === prevVar?.quote?.left || nextVar?.type === AST_TYPE.VARIABLE && token2.valid.next === nextVar?.quote?.right;
969
+ const isPropertyPrev = prevCondition?.type === AST_TYPE.CONDITION && prevVar !== void 0 && prevVar === prevCondition?.property;
970
+ const isPropertyNext = nextCondition?.type === AST_TYPE.CONDITION && nextVar !== void 0 && nextVar === nextCondition?.property;
971
+ const isPropertyAt = atCondition?.type === AST_TYPE.CONDITION && atVar !== void 0 && atVar === atCondition?.property;
972
+ const isPropertyOperatorPrev = prevVar?.type === AST_TYPE.CONDITION && token2.valid.prev === prevVar?.propertyOperator;
973
+ const isPropertyOperatorNext = nextVar?.type === AST_TYPE.CONDITION && token2.valid.next === nextVar?.propertyOperator;
974
+ const isPropertyOperatorAt = atVar?.type === AST_TYPE.CONDITION && token2.at === atVar?.propertyOperator;
975
+ const noArrayValuesTarget = token2.valid.prev?.type === TOKEN_TYPE.BRACKETL && (token2.valid.next === void 0 || token2.valid.next?.type === TOKEN_TYPE.BRACKETR);
984
976
  const target = isVarPrev ? token2.valid.prev : !noArrayValuesTarget && !isPropertyPrev && !isPropertyOperatorPrev && isVarNext ? token2.valid.next : isVarAt ? token2.at : void 0;
985
977
  const propertyTarget = isPropertyPrev ? token2.valid.prev : !noArrayValuesTarget && !isVarPrev && !isPropertyOperatorPrev && isPropertyNext ? token2.valid.next : isPropertyAt ? token2.at : void 0;
986
978
  const propOpTarget = isPropertyOperatorPrev ? token2.valid.prev : !noArrayValuesTarget && !isVarPrev && !isPropertyPrev && isPropertyOperatorNext ? token2.valid.next : isPropertyOperatorAt ? token2.at : void 0;
@@ -992,15 +984,15 @@ class Parser {
992
984
  const condition2 = parentParent;
993
985
  const isValue = condition2.propertyOperator !== void 0 && condition2.value === parent;
994
986
  const maybeGroup = getParent(parentParent, parentMap);
995
- const isPrefix = (maybeGroup == null ? void 0 : maybeGroup.type) === AST_TYPE.GROUP && maybeGroup.prefix === condition2;
987
+ const isPrefix = maybeGroup?.type === AST_TYPE.GROUP && maybeGroup.prefix === condition2;
996
988
  const varStart = getCursorInfo(input, ast, parent.start);
997
989
  const varEnd = getCursorInfo(input, ast, parent.end);
998
990
  const targetRequiresWhitespacePrev = tokenRequiresWhitespace(varStart.valid.prev, varStart.whitespace.prev, wordOps);
999
991
  const targetRequiresWhitespaceNext = tokenRequiresWhitespace(varEnd.valid.next, varEnd.whitespace.next, wordOps);
1000
- const prefixedValue = parent.type === AST_TYPE.VARIABLE ? (_o = parent == null ? void 0 : parent.prefix) == null ? void 0 : _o.value : false;
1001
- const isSepPrev = ((_p = token2.prev) == null ? void 0 : _p.type) === TOKEN_TYPE.OP_EXPANDED_SEP;
1002
- const arrayValue = (parentParent == null ? void 0 : parentParent.type) === AST_TYPE.ARRAY;
1003
- const isRegexFlag = target === ((_q = parent.quote) == null ? void 0 : _q.flags);
992
+ const prefixedValue = parent.type === AST_TYPE.VARIABLE ? parent?.prefix?.value : false;
993
+ const isSepPrev = token2.prev?.type === TOKEN_TYPE.OP_EXPANDED_SEP;
994
+ const arrayValue = parentParent?.type === AST_TYPE.ARRAY;
995
+ const isRegexFlag = target === parent.quote?.flags;
1004
996
  if (!isRegexFlag && !isSepPrev && !isValue && !arrayValue && !prefixedValue && opts.prefixableGroups) {
1005
997
  suggestions.push({
1006
998
  ...baseSuggestion,
@@ -1057,9 +1049,9 @@ class Parser {
1057
1049
  range: pos(propOpTarget)
1058
1050
  });
1059
1051
  }
1060
- const canSuggestValue = token2.whitespace.next && (token2.whitespace.prev || ((_r = token2.prev) == null ? void 0 : _r.type) === TOKEN_TYPE.BRACKETL || ((_s = token2.prev) == null ? void 0 : _s.type) === TOKEN_TYPE.PARENL) || token2.whitespace.prev && (token2.whitespace.next || ((_t = token2.next) == null ? void 0 : _t.type) === TOKEN_TYPE.BRACKETR || ((_u = token2.next) == null ? void 0 : _u.type) === TOKEN_TYPE.PARENR);
1052
+ const canSuggestValue = token2.whitespace.next && (token2.whitespace.prev || token2.prev?.type === TOKEN_TYPE.BRACKETL || token2.prev?.type === TOKEN_TYPE.PARENL) || token2.whitespace.prev && (token2.whitespace.next || token2.next?.type === TOKEN_TYPE.BRACKETR || token2.next?.type === TOKEN_TYPE.PARENR);
1061
1053
  if (canSuggestValue) {
1062
- const inArrayNode = [nextCondition, prevCondition, nextVar, prevVar].find((_) => (_ == null ? void 0 : _.type) === AST_TYPE.ARRAY) !== void 0;
1054
+ const inArrayNode = [nextCondition, prevCondition, nextVar, prevVar].find((_) => _?.type === AST_TYPE.ARRAY) !== void 0;
1063
1055
  const opsNotNeeded = ["and", "or"].includes(opts.onMissingBooleanOperator);
1064
1056
  if (inArrayNode || opsNotNeeded) {
1065
1057
  suggestions.push({
@@ -1085,8 +1077,8 @@ class Parser {
1085
1077
  const tokenValidNextParent = getParent(token2.valid.next, parentMap);
1086
1078
  const canSuggestRegexFlags = (
1087
1079
  // has existing flags before/after
1088
- token2.at && token2.at === ((_v = tokenAtParent == null ? void 0 : tokenAtParent.quote) == null ? void 0 : _v.flags) || token2.valid.prev && token2.valid.prev === ((_w = tokenValidPrevParent == null ? void 0 : tokenValidPrevParent.quote) == null ? void 0 : _w.flags) || token2.valid.next && token2.valid.next === ((_x = tokenValidNextParent == null ? void 0 : tokenValidNextParent.quote) == null ? void 0 : _x.flags) || // no flags
1089
- ((_y = token2.valid.prev) == null ? void 0 : _y.type) === TOKEN_TYPE.REGEX && token2.valid.prev === ((_z = tokenValidPrevParent.quote) == null ? void 0 : _z.right)
1080
+ token2.at && token2.at === tokenAtParent?.quote?.flags || token2.valid.prev && token2.valid.prev === tokenValidPrevParent?.quote?.flags || token2.valid.next && token2.valid.next === tokenValidNextParent?.quote?.flags || // no flags
1081
+ token2.valid.prev?.type === TOKEN_TYPE.REGEX && token2.valid.prev === tokenValidPrevParent.quote?.right
1090
1082
  );
1091
1083
  if (canSuggestRegexFlags) {
1092
1084
  suggestions.push({
@@ -1263,7 +1255,6 @@ class Parser {
1263
1255
  * Normalizes the ast by applying {@link GroupNode GroupNodes} and converting {@link ConditionNode ConditionNodes} to {@link NormalizedConditionNode NormalizedConditionNodes}.
1264
1256
  */
1265
1257
  normalize(ast) {
1266
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
1267
1258
  this._checkEvaluationOptions();
1268
1259
  const opts = this.options;
1269
1260
  if (!ast.valid) {
@@ -1275,8 +1266,8 @@ class Parser {
1275
1266
  const self_ = this;
1276
1267
  if (ast.type === AST_TYPE.CONDITION) {
1277
1268
  if (!(ast.value.type === AST_TYPE.GROUP)) {
1278
- const isValue = ast.value.type === AST_TYPE.ARRAY || ((_b = (_a = ast.value) == null ? void 0 : _a.quote) == null ? void 0 : _b.left.type) === TOKEN_TYPE.REGEX;
1279
- let name = ((_d = (_c = ast.property) == null ? void 0 : _c.value) == null ? void 0 : _d.value) ? unescape(ast.property.value.value) : isValue ? void 0 : unescape(ast.value.value.value);
1269
+ const isValue = ast.value.type === AST_TYPE.ARRAY || ast.value?.quote?.left.type === TOKEN_TYPE.REGEX;
1270
+ let name = ast.property?.value?.value ? unescape(ast.property.value.value) : isValue ? void 0 : unescape(ast.value.value.value);
1280
1271
  const isNested = operator2 !== void 0;
1281
1272
  if (prefix !== void 0 && !isNested) {
1282
1273
  name = name ? applyPrefix(prefix, name, opts.prefixApplier) : prefix;
@@ -1286,16 +1277,16 @@ class Parser {
1286
1277
  value = name ?? true;
1287
1278
  name = prefix;
1288
1279
  } else {
1289
- value = ast.value.type === AST_TYPE.ARRAY ? ast.value.values.map((val) => unescape(val.value.value)) : ((_f = (_e = ast.value) == null ? void 0 : _e.quote) == null ? void 0 : _f.left.type) === TOKEN_TYPE.REGEX ? (_g = ast.value.value) == null ? void 0 : _g.value : ast.property && ast.value.type === AST_TYPE.VARIABLE ? unescape(ast.value.value.value) : true;
1280
+ value = ast.value.type === AST_TYPE.ARRAY ? ast.value.values.map((val) => unescape(val.value.value)) : ast.value?.quote?.left.type === TOKEN_TYPE.REGEX ? ast.value.value?.value : ast.property && ast.value.type === AST_TYPE.VARIABLE ? unescape(ast.value.value.value) : true;
1290
1281
  }
1291
1282
  const propertyKeys = name ? opts.keyParser(name) : [];
1292
1283
  const boolValue = applyBoolean(groupValue, ast.operator === void 0);
1293
1284
  const valuePrefix = ast.value.type === AST_TYPE.VARIABLE && ast.value.prefix ? unescape(ast.value.prefix.value) : void 0;
1294
- operator2 ?? (operator2 = (_h = ast.propertyOperator) == null ? void 0 : _h.value);
1295
- const isRegex = ((_j = (_i = ast.value) == null ? void 0 : _i.quote) == null ? void 0 : _j.left.type) === TOKEN_TYPE.REGEX;
1296
- const isQuoted = ((_k = ast.value) == null ? void 0 : _k.quote) !== void 0;
1285
+ operator2 ??= ast.propertyOperator?.value;
1286
+ const isRegex = ast.value?.quote?.left.type === TOKEN_TYPE.REGEX;
1287
+ const isQuoted = ast.value?.quote !== void 0;
1297
1288
  const isExpanded = ast.sep !== void 0;
1298
- const regexFlags = (_n = (_m = (_l = ast.value) == null ? void 0 : _l.quote) == null ? void 0 : _m.flags) == null ? void 0 : _n.value;
1289
+ const regexFlags = ast.value?.quote?.flags?.value;
1299
1290
  const query = {
1300
1291
  value,
1301
1292
  operator: operator2,
@@ -1316,14 +1307,14 @@ class Parser {
1316
1307
  name = applyPrefix(prefix, name, opts.prefixApplier);
1317
1308
  }
1318
1309
  const boolValue = applyBoolean(groupValue, ast.operator === void 0);
1319
- const operator22 = (_o = ast.propertyOperator) == null ? void 0 : _o.value;
1310
+ const operator22 = ast.propertyOperator?.value;
1320
1311
  return self_.normalize(ast.value, name, boolValue, operator22);
1321
1312
  }
1322
1313
  }
1323
1314
  if (ast.type === AST_TYPE.GROUP) {
1324
- const _prefix = ((_p = ast.prefix) == null ? void 0 : _p.type) === AST_TYPE.CONDITION && ((_q = ast.prefix) == null ? void 0 : _q.value.type) === AST_TYPE.VARIABLE ? unescape(ast.prefix.value.value.value) : void 0;
1315
+ const _prefix = ast.prefix?.type === AST_TYPE.CONDITION && ast.prefix?.value.type === AST_TYPE.VARIABLE ? unescape(ast.prefix.value.value.value) : void 0;
1325
1316
  const isNotToken = _prefix === void 0;
1326
- const _groupValue = ((_r = ast.prefix) == null ? void 0 : _r.type) === AST_TYPE.CONDITION ? ast.prefix.operator === void 0 : !(((_s = ast.prefix) == null ? void 0 : _s.valid) === true);
1317
+ const _groupValue = ast.prefix?.type === AST_TYPE.CONDITION ? ast.prefix.operator === void 0 : !(ast.prefix?.valid === true);
1327
1318
  const applied = isNotToken ? prefix : applyPrefix(prefix, _prefix, opts.prefixApplier);
1328
1319
  return self_.normalize(ast.expression, applied, applyBoolean(groupValue, _groupValue), operator2);
1329
1320
  }
@@ -1342,7 +1333,6 @@ class Parser {
1342
1333
  * The context does not need to be passed. If it's not passed, the function will not attempt to get the values (so it will not error) and the contextValue param of the valueValidator will be undefined.
1343
1334
  */
1344
1335
  validate(ast, context) {
1345
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1346
1336
  const self = this;
1347
1337
  self._checkValidationOptions();
1348
1338
  const opts = self.options;
@@ -1357,7 +1347,7 @@ class Parser {
1357
1347
  const self_ = this;
1358
1348
  if (ast.type === AST_TYPE.CONDITION) {
1359
1349
  if (!(ast.value.type === AST_TYPE.GROUP)) {
1360
- const isValue = ast.value.type === AST_TYPE.ARRAY || ((_b = (_a = ast.value) == null ? void 0 : _a.quote) == null ? void 0 : _b.left.type) === TOKEN_TYPE.REGEX;
1350
+ const isValue = ast.value.type === AST_TYPE.ARRAY || ast.value?.quote?.left.type === TOKEN_TYPE.REGEX;
1361
1351
  const nameNode = ast.property ? ast.property : isValue ? void 0 : ast.value;
1362
1352
  let name = nameNode ? unescape(nameNode.value.value) : void 0;
1363
1353
  const isNested = operator2 !== void 0;
@@ -1372,17 +1362,17 @@ class Parser {
1372
1362
  propertyNodes = [...prefixes];
1373
1363
  } else {
1374
1364
  propertyNodes = [...prefixes, ...nameNode ? [nameNode] : []];
1375
- value = ast.value.type === AST_TYPE.ARRAY ? ast.value.values : ((_d = (_c = ast.value) == null ? void 0 : _c.quote) == null ? void 0 : _d.left.type) === TOKEN_TYPE.REGEX ? ast.value : ast.property && ast.value.type === AST_TYPE.VARIABLE ? ast.value : true;
1365
+ value = ast.value.type === AST_TYPE.ARRAY ? ast.value.values : ast.value?.quote?.left.type === TOKEN_TYPE.REGEX ? ast.value : ast.property && ast.value.type === AST_TYPE.VARIABLE ? ast.value : true;
1376
1366
  }
1377
1367
  const propertyKeys = name ? opts.keyParser(name) : [];
1378
1368
  const contextValue = context !== void 0 ? get(context, propertyKeys) : void 0;
1379
1369
  const boolValue = applyBoolean(groupValue, ast.operator === void 0);
1380
1370
  const valuePrefix = ast.value.type === AST_TYPE.VARIABLE && ast.value.prefix ? ast.value.prefix : void 0;
1381
- operator2 ?? (operator2 = ast.propertyOperator);
1382
- const isRegex = ((_f = (_e = ast.value) == null ? void 0 : _e.quote) == null ? void 0 : _f.left.type) === TOKEN_TYPE.REGEX;
1383
- const isQuoted = ((_g = ast.value) == null ? void 0 : _g.quote) !== void 0;
1371
+ operator2 ??= ast.propertyOperator;
1372
+ const isRegex = ast.value?.quote?.left.type === TOKEN_TYPE.REGEX;
1373
+ const isQuoted = ast.value?.quote !== void 0;
1384
1374
  const isExpanded = ast.sep !== void 0;
1385
- const regexFlags = (_i = (_h = ast.value) == null ? void 0 : _h.quote) == null ? void 0 : _i.flags;
1375
+ const regexFlags = ast.value?.quote?.flags;
1386
1376
  const query = {
1387
1377
  value,
1388
1378
  operator: operator2,
@@ -1415,10 +1405,10 @@ class Parser {
1415
1405
  }
1416
1406
  }
1417
1407
  if (ast.type === AST_TYPE.GROUP) {
1418
- const _prefix = ((_j = ast.prefix) == null ? void 0 : _j.type) === AST_TYPE.CONDITION && ast.prefix.value.type === AST_TYPE.VARIABLE ? ast.prefix.value : void 0;
1408
+ const _prefix = ast.prefix?.type === AST_TYPE.CONDITION && ast.prefix.value.type === AST_TYPE.VARIABLE ? ast.prefix.value : void 0;
1419
1409
  if (_prefix) prefixes.push(_prefix);
1420
- const _groupValue = ((_k = ast.prefix) == null ? void 0 : _k.type) === AST_TYPE.CONDITION ? ast.prefix.operator === void 0 : !(((_l = ast.prefix) == null ? void 0 : _l.valid) === true);
1421
- self_.validate(ast.expression, context, applyPrefix(prefix, (_prefix == null ? void 0 : _prefix.value.value) ?? "", opts.prefixApplier), applyBoolean(groupValue, _groupValue), results, prefixes, operator2);
1410
+ const _groupValue = ast.prefix?.type === AST_TYPE.CONDITION ? ast.prefix.operator === void 0 : !(ast.prefix?.valid === true);
1411
+ self_.validate(ast.expression, context, applyPrefix(prefix, _prefix?.value.value ?? "", opts.prefixApplier), applyBoolean(groupValue, _groupValue), results, prefixes, operator2);
1422
1412
  }
1423
1413
  if (ast.type === AST_TYPE.EXPRESSION) {
1424
1414
  self_.validate(ast.left, context, prefix, groupValue, results, [...prefixes], operator2);
@@ -2,17 +2,16 @@ import { token } from "./token.js";
2
2
  import { TOKEN_TYPE } from "../../types/ast.js";
3
3
  import { createArrayNode } from "../createArrayNode.js";
4
4
  function array(values, bracket = { right: true, left: true }, parenLeftPos, parenRightPos) {
5
- var _a, _b, _c, _d, _e, _f;
6
5
  const node = {
7
6
  values
8
7
  };
9
8
  node.bracket = {};
10
- const start = ((_a = values[0]) == null ? void 0 : _a.start) ?? (parenLeftPos == null ? void 0 : parenLeftPos.end);
11
- const end = ((_b = values[values.length - 1]) == null ? void 0 : _b.end) ?? (parenRightPos == null ? void 0 : parenRightPos.start) ?? (parenLeftPos == null ? void 0 : parenLeftPos.end);
12
- parenLeftPos ?? (parenLeftPos = start !== void 0 ? { start: start - 1, end: start } : void 0);
13
- parenRightPos ?? (parenRightPos = end !== void 0 ? { start: end, end: end + 1 } : void 0);
9
+ const start = values[0]?.start ?? parenLeftPos?.end;
10
+ const end = values[values.length - 1]?.end ?? parenRightPos?.start ?? parenLeftPos?.end;
11
+ parenLeftPos ??= start !== void 0 ? { start: start - 1, end: start } : void 0;
12
+ parenRightPos ??= end !== void 0 ? { start: end, end: end + 1 } : void 0;
14
13
  node.bracket.left = token(TOKEN_TYPE.BRACKETL, "[", parenLeftPos);
15
- if (bracket == null ? void 0 : bracket.right) {
14
+ if (bracket?.right) {
16
15
  node.bracket.right = token(TOKEN_TYPE.BRACKETR, "]", parenRightPos);
17
16
  } else {
18
17
  if (parenRightPos) {
@@ -20,8 +19,8 @@ function array(values, bracket = { right: true, left: true }, parenLeftPos, pare
20
19
  }
21
20
  node.bracket.right = token(TOKEN_TYPE.BRACKETR, void 0, parenRightPos);
22
21
  }
23
- node.start = ((_c = node.bracket.left) == null ? void 0 : _c.start) ?? start ?? ((_d = node.bracket) == null ? void 0 : _d.right.start);
24
- node.end = ((_f = (_e = node.bracket) == null ? void 0 : _e.right) == null ? void 0 : _f.end) ?? end ?? node.bracket.left.end;
22
+ node.start = node.bracket.left?.start ?? start ?? node.bracket?.right.start;
23
+ node.end = node.bracket?.right?.end ?? end ?? node.bracket.left.end;
25
24
  return createArrayNode(node);
26
25
  }
27
26
  export {
@@ -10,5 +10,5 @@ import { type AnyToken, type ArrayNode, type ConditionNode, type ErrorToken, typ
10
10
  * @param propertyOperator Set the operator for a property condition. A property must have been passed. The property operator must be a valid token. There is no case where it would not be. If using an operator that is the same as a separator, if used as an operator, should be set as an operator.
11
11
  * @param sep Pass separator tokens for expanded property conditions.
12
12
  */
13
- export declare function condition(value: VariableNode | GroupNode | ArrayNode | ErrorToken, not?: true | ValidToken<TOKEN_TYPE.NOT>, property?: VariableNode | ErrorToken, propertyOperator?: AnyToken<TOKEN_TYPE.OP_CUSTOM | TOKEN_TYPE.VALUE>, { right, left }?: Partial<Record<"right" | "left", ValidToken<TOKEN_TYPE.OP_EXPANDED_SEP>>>): ConditionNode;
13
+ export declare function condition(value: VariableNode | GroupNode | ArrayNode | ErrorToken, not?: true | ValidToken<typeof TOKEN_TYPE.NOT>, property?: VariableNode | ErrorToken, propertyOperator?: AnyToken<typeof TOKEN_TYPE.OP_CUSTOM | typeof TOKEN_TYPE.VALUE>, { right, left }?: Partial<Record<"right" | "left", ValidToken<typeof TOKEN_TYPE.OP_EXPANDED_SEP>>>): ConditionNode;
14
14
  //# sourceMappingURL=condition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../../../src/ast/builders/condition.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAmB,KAAK,SAAS,EAAiB,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAG5M;;;;;;;;;;GAUG;AAEH,wBAAgB,SAAS,CACxB,KAAK,EACH,YAAY,GACZ,SAAS,GACT,SAAS,GACT,UAAU,EACZ,GAAG,GAAE,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,CAAQ,EAC7C,QAAQ,CAAC,EAAE,YAAY,GAAG,UAAU,EACpC,gBAAgB,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,EACpE,EAAE,KAAK,EAAE,IAAI,EAAE,GAAE,OAAO,CAAC,MAAM,CAAC,OAAO,GAAG,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAO,GAC9F,aAAa,CAsBf"}
1
+ {"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../../../src/ast/builders/condition.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAmB,KAAK,SAAS,EAAiB,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAG5M;;;;;;;;;;GAUG;AAEH,wBAAgB,SAAS,CACxB,KAAK,EACH,YAAY,GACZ,SAAS,GACT,SAAS,GACT,UAAU,EACZ,GAAG,GAAE,IAAI,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,CAAQ,EACpD,QAAQ,CAAC,EAAE,YAAY,GAAG,UAAU,EACpC,gBAAgB,CAAC,EAAE,QAAQ,CAAC,OAAO,UAAU,CAAC,SAAS,GAAG,OAAO,UAAU,CAAC,KAAK,CAAC,EAClF,EAAE,KAAK,EAAE,IAAI,EAAE,GAAE,OAAO,CAAC,MAAM,CAAC,OAAO,GAAG,MAAM,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,eAAe,CAAC,CAAC,CAAO,GACrG,aAAa,CAsBf"}
@@ -1,9 +1,10 @@
1
1
  import { pos } from "./pos.js";
2
+ import "../../types/ast.js";
2
3
  import { createConditionNode } from "../createConditionNode.js";
3
4
  function condition(value, not = true, property, propertyOperator, { right, left } = {}) {
4
5
  const position = pos(value);
5
6
  const notStart = not === true ? void 0 : not.start;
6
- position.start = notStart ?? (property == null ? void 0 : property.start) ?? (propertyOperator == null ? void 0 : propertyOperator.start) ?? position.start;
7
+ position.start = notStart ?? property?.start ?? propertyOperator?.start ?? position.start;
7
8
  const node = {
8
9
  property,
9
10
  value,
@@ -1,8 +1,8 @@
1
- import { type ExtractTokenType } from "../../types/ast.js";
1
+ import { type ExtractToken } from "../../types/ast.js";
2
2
  /**
3
3
  * Faster way, more intuitive way to generate the options for matching delimiters (e.g. quotes and parens) for functions like {@link variable} and {@link group} .
4
4
  */
5
- export declare function delim<TLeft extends boolean | string, TRight extends boolean | string, TType extends TLeft extends string ? ExtractTokenType<TLeft> : TRight extends string ? ExtractTokenType<TRight> : undefined>(left?: TLeft, right?: TRight): {
5
+ export declare function delim<TLeft extends boolean | string, TRight extends boolean | string, TType extends TLeft extends string ? ExtractToken<TLeft> : TRight extends string ? ExtractToken<TRight> : undefined>(left?: TLeft, right?: TRight): {
6
6
  left: TLeft extends string ? true : TLeft;
7
7
  right: TRight extends string ? true : TRight;
8
8
  } & TType extends undefined ? Record<string, never> : {
@@ -1 +1 @@
1
- {"version":3,"file":"delim.d.ts","sourceRoot":"","sources":["../../../src/ast/builders/delim.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAc,MAAM,oBAAoB,CAAA;AAEtE;;GAEG;AAEH,wBAAgB,KAAK,CACpB,KAAK,SAAS,OAAO,GAAG,MAAM,EAC9B,MAAM,SAAS,OAAO,GAAG,MAAM,EAC/B,KAAK,SAAS,KAAK,SAAS,MAAM,GAC/B,gBAAgB,CAAC,KAAK,CAAC,GACvB,MAAM,SAAS,MAAM,GACrB,gBAAgB,CAAC,MAAM,CAAC,GACxB,SAAS,EAEZ,IAAI,GAAE,KAAsB,EAC5B,KAAK,GAAE,MAAwB,GAE/B;IACC,IAAI,EAAE,KAAK,SAAS,MAAM,GAAG,IAAI,GAAG,KAAK,CAAA;IACzC,KAAK,EAAE,MAAM,SAAS,MAAM,GAAG,IAAI,GAAG,MAAM,CAAA;CAC5C,GAAG,KAAK,SAAS,SAAS,GAAG,MAAM,CAAC,MAAM,EAAC,KAAK,CAAC,GAAG;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,CAepE"}
1
+ {"version":3,"file":"delim.d.ts","sourceRoot":"","sources":["../../../src/ast/builders/delim.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAc,MAAM,oBAAoB,CAAA;AAElE;;GAEG;AAEH,wBAAgB,KAAK,CACpB,KAAK,SAAS,OAAO,GAAG,MAAM,EAC9B,MAAM,SAAS,OAAO,GAAG,MAAM,EAC/B,KAAK,SAAS,KAAK,SAAS,MAAM,GAC/B,YAAY,CAAC,KAAK,CAAC,GACnB,MAAM,SAAS,MAAM,GACrB,YAAY,CAAC,MAAM,CAAC,GACpB,SAAS,EAEZ,IAAI,GAAE,KAAsB,EAC5B,KAAK,GAAE,MAAwB,GAE/B;IACC,IAAI,EAAE,KAAK,SAAS,MAAM,GAAG,IAAI,GAAG,KAAK,CAAA;IACzC,KAAK,EAAE,MAAM,SAAS,MAAM,GAAG,IAAI,GAAG,MAAM,CAAA;CAC5C,GAAG,KAAK,SAAS,SAAS,GAAG,MAAM,CAAC,MAAM,EAAC,KAAK,CAAC,GAAG;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,CAepE"}