@witchcraft/expressit 0.1.3 → 0.2.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 (288) hide show
  1. package/README.md +7 -5
  2. package/dist/Lexer.js +21 -42
  3. package/dist/Parser.d.ts +14 -29
  4. package/dist/Parser.d.ts.map +1 -1
  5. package/dist/Parser.js +151 -197
  6. package/dist/ast/builders/array.d.ts +1 -3
  7. package/dist/ast/builders/array.d.ts.map +1 -1
  8. package/dist/ast/builders/array.js +3 -5
  9. package/dist/ast/builders/condition.d.ts +5 -11
  10. package/dist/ast/builders/condition.d.ts.map +1 -1
  11. package/dist/ast/builders/condition.js +4 -7
  12. package/dist/ast/builders/delim.d.ts +1 -1
  13. package/dist/ast/builders/delim.js +2 -4
  14. package/dist/ast/builders/error.d.ts +3 -4
  15. package/dist/ast/builders/error.d.ts.map +1 -1
  16. package/dist/ast/builders/error.js +6 -2
  17. package/dist/ast/builders/expression.d.ts +3 -7
  18. package/dist/ast/builders/expression.d.ts.map +1 -1
  19. package/dist/ast/builders/expression.js +4 -7
  20. package/dist/ast/builders/group.d.ts +3 -8
  21. package/dist/ast/builders/group.d.ts.map +1 -1
  22. package/dist/ast/builders/group.js +3 -3
  23. package/dist/ast/builders/pos.d.ts +1 -2
  24. package/dist/ast/builders/pos.d.ts.map +1 -1
  25. package/dist/ast/builders/pos.js +3 -6
  26. package/dist/ast/builders/token.d.ts +3 -5
  27. package/dist/ast/builders/token.d.ts.map +1 -1
  28. package/dist/ast/builders/token.js +3 -4
  29. package/dist/ast/builders/type.d.ts +1 -1
  30. package/dist/ast/builders/variable.d.ts +3 -5
  31. package/dist/ast/builders/variable.d.ts.map +1 -1
  32. package/dist/ast/builders/variable.js +4 -7
  33. package/dist/ast/createArrayNode.d.ts +3 -0
  34. package/dist/ast/createArrayNode.d.ts.map +1 -0
  35. package/dist/ast/createArrayNode.js +12 -0
  36. package/dist/ast/createConditionNode.d.ts +11 -0
  37. package/dist/ast/createConditionNode.d.ts.map +1 -0
  38. package/dist/ast/createConditionNode.js +18 -0
  39. package/dist/ast/createExpressionNode.d.ts +3 -0
  40. package/dist/ast/createExpressionNode.d.ts.map +1 -0
  41. package/dist/ast/createExpressionNode.js +14 -0
  42. package/dist/ast/createGroupNode.d.ts +5 -0
  43. package/dist/ast/createGroupNode.d.ts.map +1 -0
  44. package/dist/ast/createGroupNode.js +14 -0
  45. package/dist/ast/createNormalizedCondition.d.ts +3 -0
  46. package/dist/ast/createNormalizedCondition.d.ts.map +1 -0
  47. package/dist/ast/createNormalizedCondition.js +10 -0
  48. package/dist/ast/createNormalizedExpression.d.ts +3 -0
  49. package/dist/ast/createNormalizedExpression.d.ts.map +1 -0
  50. package/dist/ast/createNormalizedExpression.js +10 -0
  51. package/dist/ast/createToken.d.ts +6 -0
  52. package/dist/ast/createToken.d.ts.map +1 -0
  53. package/dist/ast/createToken.js +15 -0
  54. package/dist/ast/createVariableNode.d.ts +3 -0
  55. package/dist/ast/createVariableNode.d.ts.map +1 -0
  56. package/dist/ast/createVariableNode.js +12 -0
  57. package/dist/ast/error.d.ts +3 -0
  58. package/dist/ast/error.d.ts.map +1 -0
  59. package/dist/ast/error.js +8 -0
  60. package/dist/ast/handlers.d.ts +5 -12
  61. package/dist/ast/handlers.d.ts.map +1 -1
  62. package/dist/ast/handlers.js +25 -37
  63. package/dist/ast/index.d.ts +9 -1
  64. package/dist/ast/index.d.ts.map +1 -1
  65. package/dist/ast/index.js +18 -2
  66. package/dist/defaults/defaultConditionNormalizer.d.ts +3 -0
  67. package/dist/defaults/defaultConditionNormalizer.d.ts.map +1 -0
  68. package/dist/defaults/defaultKeyParser.d.ts +3 -0
  69. package/dist/defaults/defaultKeyParser.d.ts.map +1 -0
  70. package/dist/{helpers/general → defaults}/defaultKeyParser.js +1 -2
  71. package/dist/defaults/defaultPrefixApplier.d.ts +3 -0
  72. package/dist/defaults/defaultPrefixApplier.d.ts.map +1 -0
  73. package/dist/defaults/defaultValueComparer.d.ts +3 -0
  74. package/dist/defaults/defaultValueComparer.d.ts.map +1 -0
  75. package/dist/{helpers/general → defaults}/index.d.ts +0 -2
  76. package/dist/defaults/index.d.ts.map +1 -0
  77. package/dist/{helpers/general → defaults}/index.js +0 -4
  78. package/dist/examples/shortcutContextParser.js +4 -10
  79. package/dist/index.d.ts +2 -1
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +3 -1
  82. package/dist/{helpers/errors.d.ts → internal/ExpressitError.d.ts} +3 -2
  83. package/dist/internal/ExpressitError.d.ts.map +1 -0
  84. package/dist/{helpers/errors.js → internal/ExpressitError.js} +3 -6
  85. package/dist/internal/applyBoolean.d.ts.map +1 -0
  86. package/dist/{helpers/general → internal}/applyPrefix.d.ts +1 -1
  87. package/dist/internal/applyPrefix.d.ts.map +1 -0
  88. package/dist/{helpers/parser → internal}/checkParserOpts.d.ts +2 -1
  89. package/dist/internal/checkParserOpts.d.ts.map +1 -0
  90. package/dist/{helpers/parser → internal}/checkParserOpts.js +22 -30
  91. package/dist/internal/escapeVariableOrPrefix.d.ts +2 -0
  92. package/dist/internal/escapeVariableOrPrefix.d.ts.map +1 -0
  93. package/dist/internal/escapeVariableOrPrefix.js +34 -0
  94. package/dist/internal/extractPosition.d.ts +5 -0
  95. package/dist/internal/extractPosition.d.ts.map +1 -0
  96. package/dist/internal/getUnclosedRightParenCount.d.ts +4 -0
  97. package/dist/internal/getUnclosedRightParenCount.d.ts.map +1 -0
  98. package/dist/{helpers/parser → internal}/getUnclosedRightParenCount.js +1 -1
  99. package/dist/{helpers/parser → internal}/parseParserOptions.d.ts +1 -1
  100. package/dist/internal/parseParserOptions.d.ts.map +1 -0
  101. package/dist/{helpers/parser → internal}/parseParserOptions.js +4 -4
  102. package/dist/internal/unescape.d.ts.map +1 -0
  103. package/dist/package.json.js +7 -7
  104. package/dist/types/ast.d.ts +195 -6
  105. package/dist/types/ast.d.ts.map +1 -1
  106. package/dist/types/ast.js +2 -0
  107. package/dist/types/autocomplete.d.ts +5 -6
  108. package/dist/types/autocomplete.d.ts.map +1 -1
  109. package/dist/types/parser.d.ts +17 -22
  110. package/dist/types/parser.d.ts.map +1 -1
  111. package/dist/utils/extractTokens.d.ts +2 -4
  112. package/dist/utils/extractTokens.d.ts.map +1 -1
  113. package/dist/utils/extractTokens.js +14 -18
  114. package/dist/utils/generateParentsMap.d.ts +10 -0
  115. package/dist/utils/generateParentsMap.d.ts.map +1 -0
  116. package/dist/utils/generateParentsMap.js +53 -0
  117. package/dist/utils/getCursorInfo.d.ts +1 -1
  118. package/dist/utils/getCursorInfo.d.ts.map +1 -1
  119. package/dist/utils/getCursorInfo.js +11 -21
  120. package/dist/utils/getOppositeDelimiter.d.ts +2 -1
  121. package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
  122. package/dist/utils/getOppositeDelimiter.js +9 -11
  123. package/dist/utils/getParent.d.ts +5 -0
  124. package/dist/utils/getParent.d.ts.map +1 -0
  125. package/dist/utils/getParent.js +6 -0
  126. package/dist/utils/getSurroundingErrors.d.ts +3 -4
  127. package/dist/utils/getSurroundingErrors.d.ts.map +1 -1
  128. package/dist/utils/getSurroundingErrors.js +3 -3
  129. package/dist/utils/index.d.ts +4 -0
  130. package/dist/utils/index.d.ts.map +1 -1
  131. package/dist/utils/index.js +8 -0
  132. package/dist/utils/isNode.d.ts +10 -0
  133. package/dist/utils/isNode.d.ts.map +1 -0
  134. package/dist/utils/isNode.js +6 -0
  135. package/dist/utils/isToken.d.ts +8 -0
  136. package/dist/utils/isToken.d.ts.map +1 -0
  137. package/dist/utils/isToken.js +6 -0
  138. package/dist/utils/prettyAst.d.ts +1 -2
  139. package/dist/utils/prettyAst.d.ts.map +1 -1
  140. package/dist/utils/prettyAst.js +20 -28
  141. package/package.json +7 -7
  142. package/src/Lexer.ts +2 -2
  143. package/src/Parser.ts +158 -165
  144. package/src/ast/builders/array.ts +4 -9
  145. package/src/ast/builders/condition.ts +10 -15
  146. package/src/ast/builders/delim.ts +1 -1
  147. package/src/ast/builders/error.ts +10 -6
  148. package/src/ast/builders/expression.ts +17 -23
  149. package/src/ast/builders/group.ts +7 -11
  150. package/src/ast/builders/pos.ts +2 -3
  151. package/src/ast/builders/token.ts +6 -7
  152. package/src/ast/builders/type.ts +1 -1
  153. package/src/ast/builders/variable.ts +6 -8
  154. package/src/ast/createArrayNode.ts +17 -0
  155. package/src/ast/createConditionNode.ts +58 -0
  156. package/src/ast/createExpressionNode.ts +21 -0
  157. package/src/ast/createGroupNode.ts +46 -0
  158. package/src/ast/createNormalizedCondition.ts +12 -0
  159. package/src/ast/createNormalizedExpression.ts +9 -0
  160. package/src/ast/createToken.ts +26 -0
  161. package/src/ast/createVariableNode.ts +18 -0
  162. package/src/ast/error.ts +9 -0
  163. package/src/ast/handlers.ts +26 -37
  164. package/src/ast/index.ts +9 -1
  165. package/src/{helpers/general → defaults}/defaultConditionNormalizer.ts +1 -1
  166. package/src/{helpers/general → defaults}/defaultKeyParser.ts +1 -1
  167. package/src/{helpers/general → defaults}/defaultPrefixApplier.ts +1 -1
  168. package/src/{helpers/general → defaults}/defaultValueComparer.ts +1 -1
  169. package/src/{helpers/general → defaults}/index.ts +0 -2
  170. package/src/index.ts +2 -1
  171. package/src/{helpers/errors.ts → internal/ExpressitError.ts} +2 -2
  172. package/src/{helpers/general → internal}/applyPrefix.ts +1 -1
  173. package/src/{helpers/parser → internal}/checkParserOpts.ts +16 -15
  174. package/src/internal/escapeVariableOrPrefix.ts +36 -0
  175. package/src/{helpers/parser → internal}/extractPosition.ts +2 -2
  176. package/src/{helpers/parser → internal}/getUnclosedRightParenCount.ts +1 -2
  177. package/src/{helpers/parser → internal}/parseParserOptions.ts +5 -5
  178. package/src/types/ast.ts +292 -7
  179. package/src/types/autocomplete.ts +5 -7
  180. package/src/types/parser.ts +17 -22
  181. package/src/utils/extractTokens.ts +16 -20
  182. package/src/utils/generateParentsMap.ts +60 -0
  183. package/src/utils/getCursorInfo.ts +4 -6
  184. package/src/utils/getOppositeDelimiter.ts +11 -10
  185. package/src/utils/getParent.ts +16 -0
  186. package/src/utils/getSurroundingErrors.ts +10 -9
  187. package/src/utils/index.ts +4 -0
  188. package/src/utils/isNode.ts +12 -0
  189. package/src/utils/isToken.ts +10 -0
  190. package/src/utils/prettyAst.ts +20 -17
  191. package/dist/ast/classes/ArrayNode.d.ts +0 -18
  192. package/dist/ast/classes/ArrayNode.d.ts.map +0 -1
  193. package/dist/ast/classes/ArrayNode.js +0 -55
  194. package/dist/ast/classes/Condition.d.ts +0 -13
  195. package/dist/ast/classes/Condition.d.ts.map +0 -1
  196. package/dist/ast/classes/Condition.js +0 -21
  197. package/dist/ast/classes/ConditionNode.d.ts +0 -73
  198. package/dist/ast/classes/ConditionNode.d.ts.map +0 -1
  199. package/dist/ast/classes/ConditionNode.js +0 -101
  200. package/dist/ast/classes/ErrorToken.d.ts +0 -27
  201. package/dist/ast/classes/ErrorToken.d.ts.map +0 -1
  202. package/dist/ast/classes/ErrorToken.js +0 -47
  203. package/dist/ast/classes/Expression.d.ts +0 -13
  204. package/dist/ast/classes/Expression.d.ts.map +0 -1
  205. package/dist/ast/classes/Expression.js +0 -19
  206. package/dist/ast/classes/ExpressionNode.d.ts +0 -21
  207. package/dist/ast/classes/ExpressionNode.d.ts.map +0 -1
  208. package/dist/ast/classes/ExpressionNode.js +0 -57
  209. package/dist/ast/classes/GroupNode.d.ts +0 -64
  210. package/dist/ast/classes/GroupNode.d.ts.map +0 -1
  211. package/dist/ast/classes/GroupNode.js +0 -69
  212. package/dist/ast/classes/Node.d.ts +0 -22
  213. package/dist/ast/classes/Node.d.ts.map +0 -1
  214. package/dist/ast/classes/Node.js +0 -28
  215. package/dist/ast/classes/Token.d.ts +0 -27
  216. package/dist/ast/classes/Token.d.ts.map +0 -1
  217. package/dist/ast/classes/Token.js +0 -28
  218. package/dist/ast/classes/ValidToken.d.ts +0 -26
  219. package/dist/ast/classes/ValidToken.d.ts.map +0 -1
  220. package/dist/ast/classes/ValidToken.js +0 -49
  221. package/dist/ast/classes/VariableNode.d.ts +0 -33
  222. package/dist/ast/classes/VariableNode.d.ts.map +0 -1
  223. package/dist/ast/classes/VariableNode.js +0 -58
  224. package/dist/ast/classes/index.d.ts +0 -12
  225. package/dist/ast/classes/index.d.ts.map +0 -1
  226. package/dist/ast/classes/index.js +0 -24
  227. package/dist/helpers/errors.d.ts.map +0 -1
  228. package/dist/helpers/general/applyBoolean.d.ts.map +0 -1
  229. package/dist/helpers/general/applyPrefix.d.ts.map +0 -1
  230. package/dist/helpers/general/defaultConditionNormalizer.d.ts +0 -3
  231. package/dist/helpers/general/defaultConditionNormalizer.d.ts.map +0 -1
  232. package/dist/helpers/general/defaultKeyParser.d.ts +0 -3
  233. package/dist/helpers/general/defaultKeyParser.d.ts.map +0 -1
  234. package/dist/helpers/general/defaultPrefixApplier.d.ts +0 -3
  235. package/dist/helpers/general/defaultPrefixApplier.d.ts.map +0 -1
  236. package/dist/helpers/general/defaultValueComparer.d.ts +0 -3
  237. package/dist/helpers/general/defaultValueComparer.d.ts.map +0 -1
  238. package/dist/helpers/general/index.d.ts.map +0 -1
  239. package/dist/helpers/index.d.ts +0 -4
  240. package/dist/helpers/index.d.ts.map +0 -1
  241. package/dist/helpers/index.js +0 -8
  242. package/dist/helpers/parser/assignParents.d.ts +0 -4
  243. package/dist/helpers/parser/assignParents.d.ts.map +0 -1
  244. package/dist/helpers/parser/assignParents.js +0 -71
  245. package/dist/helpers/parser/checkParserOpts.d.ts.map +0 -1
  246. package/dist/helpers/parser/extractPosition.d.ts +0 -5
  247. package/dist/helpers/parser/extractPosition.d.ts.map +0 -1
  248. package/dist/helpers/parser/getUnclosedRightParenCount.d.ts +0 -4
  249. package/dist/helpers/parser/getUnclosedRightParenCount.d.ts.map +0 -1
  250. package/dist/helpers/parser/index.d.ts +0 -9
  251. package/dist/helpers/parser/index.d.ts.map +0 -1
  252. package/dist/helpers/parser/index.js +0 -18
  253. package/dist/helpers/parser/parseParserOptions.d.ts.map +0 -1
  254. package/dist/helpers/parser/seal.d.ts +0 -8
  255. package/dist/helpers/parser/seal.d.ts.map +0 -1
  256. package/dist/helpers/parser/seal.js +0 -10
  257. package/dist/helpers/parser/setParent.d.ts +0 -6
  258. package/dist/helpers/parser/setParent.d.ts.map +0 -1
  259. package/dist/helpers/parser/setParent.js +0 -4
  260. package/dist/helpers/parser/unescape.d.ts.map +0 -1
  261. package/src/ast/classes/ArrayNode.ts +0 -46
  262. package/src/ast/classes/Condition.ts +0 -22
  263. package/src/ast/classes/ConditionNode.ts +0 -141
  264. package/src/ast/classes/ErrorToken.ts +0 -49
  265. package/src/ast/classes/Expression.ts +0 -26
  266. package/src/ast/classes/ExpressionNode.ts +0 -62
  267. package/src/ast/classes/GroupNode.ts +0 -127
  268. package/src/ast/classes/Node.ts +0 -47
  269. package/src/ast/classes/Token.ts +0 -59
  270. package/src/ast/classes/ValidToken.ts +0 -56
  271. package/src/ast/classes/VariableNode.ts +0 -67
  272. package/src/ast/classes/index.ts +0 -13
  273. package/src/helpers/index.ts +0 -6
  274. package/src/helpers/parser/assignParents.ts +0 -51
  275. package/src/helpers/parser/index.ts +0 -10
  276. package/src/helpers/parser/seal.ts +0 -14
  277. package/src/helpers/parser/setParent.ts +0 -5
  278. /package/dist/{helpers/general → defaults}/defaultConditionNormalizer.js +0 -0
  279. /package/dist/{helpers/general → defaults}/defaultPrefixApplier.js +0 -0
  280. /package/dist/{helpers/general → defaults}/defaultValueComparer.js +0 -0
  281. /package/dist/{helpers/general → internal}/applyBoolean.d.ts +0 -0
  282. /package/dist/{helpers/general → internal}/applyBoolean.js +0 -0
  283. /package/dist/{helpers/general → internal}/applyPrefix.js +0 -0
  284. /package/dist/{helpers/parser → internal}/extractPosition.js +0 -0
  285. /package/dist/{helpers/parser → internal}/unescape.d.ts +0 -0
  286. /package/dist/{helpers/parser → internal}/unescape.js +0 -0
  287. /package/src/{helpers/general → internal}/applyBoolean.ts +0 -0
  288. /package/src/{helpers/parser → internal}/unescape.ts +0 -0
package/dist/Parser.js CHANGED
@@ -1,9 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
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) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
4
  import { get } from "@alanscodelog/utils/get.js";
8
5
  import { insert } from "@alanscodelog/utils/insert.js";
9
6
  import { isArray } from "@alanscodelog/utils/isArray.js";
@@ -11,42 +8,35 @@ import { isWhitespace } from "@alanscodelog/utils/isWhitespace.js";
11
8
  import { setReadOnly } from "@alanscodelog/utils/setReadOnly.js";
12
9
  import { unreachable } from "@alanscodelog/utils/unreachable.js";
13
10
  import { pos } from "./ast/builders/pos.js";
14
- import { ArrayNode } from "./ast/classes/ArrayNode.js";
15
- import { ConditionNode } from "./ast/classes/ConditionNode.js";
16
- import { ErrorToken } from "./ast/classes/ErrorToken.js";
17
- import { ExpressionNode } from "./ast/classes/ExpressionNode.js";
18
- import { GroupNode } from "./ast/classes/GroupNode.js";
19
- import { Condition } from "./ast/classes/Condition.js";
20
- import { Expression } from "./ast/classes/Expression.js";
21
- import "@alanscodelog/utils/crop.js";
22
- import "@alanscodelog/utils/indent.js";
23
- import "@alanscodelog/utils/pretty.js";
24
- import { ValidToken } from "./ast/classes/ValidToken.js";
25
- import { VariableNode } from "./ast/classes/VariableNode.js";
11
+ import { createCondition } from "./ast/createNormalizedCondition.js";
12
+ import { createExpression } from "./ast/createNormalizedExpression.js";
26
13
  import { token, operator, expression, variable, condition, group, array, delimiter } from "./ast/handlers.js";
27
- import { applyBoolean } from "./helpers/general/applyBoolean.js";
28
- import { applyPrefix } from "./helpers/general/applyPrefix.js";
29
- import { checkParserOpts } from "./helpers/parser/checkParserOpts.js";
30
- import { extractPosition } from "./helpers/parser/extractPosition.js";
31
- import { getUnclosedRightParenCount } from "./helpers/parser/getUnclosedRightParenCount.js";
32
- import { parseParserOptions } from "./helpers/parser/parseParserOptions.js";
33
- import { seal } from "./helpers/parser/seal.js";
14
+ import { applyBoolean } from "./internal/applyBoolean.js";
15
+ import { applyPrefix } from "./internal/applyPrefix.js";
16
+ import { checkParserOpts } from "./internal/checkParserOpts.js";
17
+ import { escapeVariableOrPrefix } from "./internal/escapeVariableOrPrefix.js";
18
+ import { extractPosition } from "./internal/extractPosition.js";
19
+ import { getUnclosedRightParenCount } from "./internal/getUnclosedRightParenCount.js";
20
+ import { parseParserOptions } from "./internal/parseParserOptions.js";
21
+ import { unescape } from "./internal/unescape.js";
34
22
  import { Lexer, $C, $T } from "./Lexer.js";
35
- import { TOKEN_TYPE } from "./types/ast.js";
23
+ import { TOKEN_TYPE, AST_TYPE } from "./types/ast.js";
36
24
  import { SUGGESTION_TYPE } from "./types/autocomplete.js";
37
25
  import { extractTokens } from "./utils/extractTokens.js";
26
+ import { generateParentsMap } from "./utils/generateParentsMap.js";
38
27
  import { getCursorInfo } from "./utils/getCursorInfo.js";
28
+ import { getParent } from "./utils/getParent.js";
39
29
  import { getSurroundingErrors } from "./utils/getSurroundingErrors.js";
30
+ import { isNode } from "./utils/isNode.js";
31
+ import { isToken } from "./utils/isToken.js";
40
32
  const OPPOSITE = {
41
33
  [TOKEN_TYPE.AND]: TOKEN_TYPE.OR,
42
34
  [TOKEN_TYPE.OR]: TOKEN_TYPE.AND
43
35
  };
44
36
  function isEqualSet(setA, setB) {
45
- if (setA.size !== setB.size)
46
- return false;
37
+ if (setA.size !== setB.size) return false;
47
38
  for (const key of setA) {
48
- if (!setB.has(key))
49
- return false;
39
+ if (!setB.has(key)) return false;
50
40
  }
51
41
  return true;
52
42
  }
@@ -62,10 +52,9 @@ const createDefaultRequires = (partial = {}) => ({
62
52
  group: partial.group ?? false,
63
53
  prefix: partial.prefix ?? false
64
54
  });
65
- const tokenRequiresWhitespace = (validToken, whitespace, wordOps) => {
66
- if (whitespace || validToken === void 0)
67
- return false;
68
- return validToken.type === TOKEN_TYPE.VALUE || [TOKEN_TYPE.AND, TOKEN_TYPE.OR, TOKEN_TYPE.NOT].includes(validToken.type) && wordOps.find((_) => _.value === validToken.value) !== void 0;
55
+ const tokenRequiresWhitespace = (valid, whitespace, wordOps) => {
56
+ if (whitespace || valid === void 0) return false;
57
+ return valid.type === TOKEN_TYPE.VALUE || [TOKEN_TYPE.AND, TOKEN_TYPE.OR, TOKEN_TYPE.NOT].includes(valid.type) && wordOps.find((_) => _.value === valid.value) !== void 0;
69
58
  };
70
59
  const tokenVariable = [TOKEN_TYPE.BACKTICK, TOKEN_TYPE.DOUBLEQUOTE, TOKEN_TYPE.SINGLEQUOTE, TOKEN_TYPE.VALUE, TOKEN_TYPE.REGEX];
71
60
  class Parser {
@@ -140,8 +129,6 @@ class Parser {
140
129
  * It can also parse the result from `lex`, but that is really only for internal use.
141
130
  */
142
131
  parse(input) {
143
- var _a;
144
- const doSeal = ((_a = arguments[1]) == null ? void 0 : _a.seal) ?? true;
145
132
  if (typeof input === "string" && isWhitespace(input)) {
146
133
  return token.value(void 0, { start: 0, end: 0 });
147
134
  }
@@ -153,9 +140,6 @@ class Parser {
153
140
  lexedTokens
154
141
  };
155
142
  const res = this.ruleMain();
156
- if (doSeal) {
157
- seal(res);
158
- }
159
143
  this.state = {
160
144
  rawInput: "",
161
145
  shift: 0,
@@ -190,13 +174,10 @@ class Parser {
190
174
  return false;
191
175
  }
192
176
  isType(token2, type) {
193
- if (token2 === void 0)
194
- return false;
195
- if (token2.type === type)
196
- return true;
177
+ if (token2 === void 0) return false;
178
+ if (token2.type === type) return true;
197
179
  const tokenType = this.getTokenType(token2.type);
198
- if ((tokenType == null ? void 0 : tokenType.type) === type)
199
- return true;
180
+ if ((tokenType == null ? void 0 : tokenType.type) === type) return true;
200
181
  const category = this.$categories[type];
201
182
  if ((category == null ? void 0 : category.entries[token2.type]) !== void 0) {
202
183
  return true;
@@ -337,38 +318,36 @@ class Parser {
337
318
  }
338
319
  this.restoreState(state);
339
320
  }
340
- if (type === "AND" && pairs.length === 0)
341
- return void 0;
321
+ if (type === "AND" && pairs.length === 0) return void 0;
342
322
  let res = pairs[pairs.length - 1][0];
343
323
  for (let i = pairs.length - 1; i > 0; i--) {
344
324
  const before = pairs[i - 1];
345
- if (type === "OR" && res === void 0 && before === void 0)
346
- return void 0;
325
+ if (type === "OR" && res === void 0 && before === void 0) return void 0;
347
326
  res = expression(before[0], before[1], res);
348
327
  }
349
328
  return res;
350
329
  }
351
330
  ruleCondition() {
352
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
331
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
353
332
  const not = this.ruleNot();
354
333
  const property = this.ruleConditionProperty();
355
- const propVal = ((_a = property == null ? void 0 : property.prop) == null ? void 0 : _a.value) === void 0 ? void 0 : property.prop.value instanceof ErrorToken ? "" : property.prop.value.value;
356
- const propOpVal = ((_b = property == null ? void 0 : property.rest) == null ? void 0 : _b.propertyOperator) === void 0 ? void 0 : property.rest.propertyOperator instanceof ErrorToken ? "" : (_c = property.rest.propertyOperator) == null ? void 0 : _c.value;
357
- const isExpanded = (((_d = property == null ? void 0 : property.rest) == null ? void 0 : _d.sepL) ?? ((_e = property == null ? void 0 : property.rest) == null ? void 0 : _e.sepR)) !== void 0;
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;
358
337
  const convertRegexValues = typeof this.options.regexValues === "function" && !this.options.regexValues(propVal, propOpVal, isExpanded);
359
338
  const convertArrayValues = typeof this.options.arrayValues === "function" && !this.options.arrayValues(propVal, propOpVal, isExpanded);
360
339
  let value = this.ruleConditionValue(property, { convertRegexValues, convertArrayValues });
361
340
  let group$1;
362
- if (!(value instanceof ArrayNode) && !isArray(value) && (!value || this.options.prefixableGroups) && this.isType(this.peek(1), $T.PAREN_L)) {
341
+ if (isNode(value) && !(value.type === AST_TYPE.ARRAY) && !isArray(value) && (!value || this.options.prefixableGroups) && this.isType(this.peek(1), $T.PAREN_L)) {
363
342
  group$1 = this.rulePlainGroup({ onlyValues: property !== void 0, convertRegexValues, convertArrayValues });
364
343
  }
365
344
  if (isArray(value)) {
366
345
  group$1 = value;
367
346
  value = void 0;
368
347
  }
369
- if (convertRegexValues && value instanceof VariableNode && ((_f = value.quote) == null ? void 0 : _f.left.type) === TOKEN_TYPE.REGEX) {
348
+ if (convertRegexValues && isNode(value) && value.type === AST_TYPE.VARIABLE && ((_g = value.quote) == null ? void 0 : _g.left.type) === TOKEN_TYPE.REGEX) {
370
349
  value = variable(void 0, void 0, token.value(
371
- (((_h = (_g = value.quote) == null ? void 0 : _g.left) == null ? void 0 : _h.value) ?? "") + (value.value.value ?? "") + (((_j = (_i = value.quote) == null ? void 0 : _i.right) == null ? void 0 : _j.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) ?? ""),
372
351
  pos(value)
373
352
  ), void 0);
374
353
  }
@@ -381,8 +360,7 @@ class Parser {
381
360
  }
382
361
  return group(not, value, ...group$1);
383
362
  }
384
- if ([not, property, value].every((_) => _ === void 0))
385
- return void 0;
363
+ if ([not, property, value].every((_) => _ === void 0)) return void 0;
386
364
  return condition(not, property == null ? void 0 : property.prop, property == null ? void 0 : property.rest, value);
387
365
  }
388
366
  ruleConditionValue(property, { convertRegexValues = false, convertArrayValues = false } = {}) {
@@ -393,23 +371,19 @@ class Parser {
393
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(
394
372
  this.isType(next3, $C.QUOTE_ANY) && this.isType(next4, $T.PAREN_L))))) {
395
373
  const res = this.ruleVariable({ unprefixed: true });
396
- if (res)
397
- return res;
374
+ if (res) return res;
398
375
  }
399
376
  if (!this.isType(next, $T.PAREN_L)) {
400
377
  const res = this.ruleVariable({ unprefixed: false });
401
- if (res)
402
- return res;
378
+ if (res) return res;
403
379
  }
404
380
  if (this.isType(next, $T.PAREN_L)) {
405
381
  const res = this.rulePlainGroup({ onlyValues: property !== void 0, convertRegexValues, convertArrayValues });
406
- if (res)
407
- return res;
382
+ if (res) return res;
408
383
  }
409
384
  if (this.isType(next, $T.BRACKET_L)) {
410
385
  const res = this.rulePlainBracketGroup({ convertArrayValues });
411
- if (res)
412
- return res;
386
+ if (res) return res;
413
387
  }
414
388
  return void 0;
415
389
  }
@@ -444,7 +418,7 @@ class Parser {
444
418
  regexValues: convertRegexValues,
445
419
  arrayValues: convertArrayValues
446
420
  }, "One");
447
- const parsed = this.subParserOne.parse(" ".repeat(start) + subInput, { seal: false });
421
+ const parsed = this.subParserOne.parse(" ".repeat(start) + subInput);
448
422
  return [parenL, parsed, parenR];
449
423
  }
450
424
  return [parenL, condition2, parenR];
@@ -467,8 +441,7 @@ class Parser {
467
441
  }
468
442
  }
469
443
  const bracketR = this.isType(this.peek(1), $T.BRACKET_R) ? this.ruleBracketR() : void 0;
470
- if (bracketL === void 0)
471
- throw new Error("bracketL is undefined, peek before using rule.");
444
+ if (bracketL === void 0) throw new Error("bracketL is undefined, peek before using rule.");
472
445
  if (!convertArrayValues) {
473
446
  return array(bracketL, values, bracketR);
474
447
  }
@@ -481,11 +454,11 @@ class Parser {
481
454
  expandedPropertySeparator: void 0,
482
455
  arrayValues: false
483
456
  }, "Two");
484
- const parsed = this.subParserTwo.parse(" ".repeat(start) + subInput, { seal: false });
485
- if (parsed instanceof ConditionNode) {
457
+ const parsed = this.subParserTwo.parse(" ".repeat(start) + subInput);
458
+ if ("type" in parsed && parsed.type === AST_TYPE.CONDITION) {
486
459
  return parsed.value;
487
460
  }
488
- if (parsed instanceof ErrorToken || parsed instanceof ExpressionNode || parsed instanceof GroupNode) {
461
+ if ("valid" in parsed && !parsed.valid || "type" in parsed && (parsed.type === AST_TYPE.EXPRESSION || parsed.type === AST_TYPE.GROUP)) {
489
462
  unreachable("parsed.value should not be an ErrorToken, ExpressionNode, or GroupNode.");
490
463
  }
491
464
  return parsed;
@@ -650,8 +623,7 @@ class Parser {
650
623
  if (!unprefixed && this.options.prefixableStrings !== void 0 && this.isType(next2, $C.QUOTE_ANY) && next2 && this.isType(next4, next2.type) && next && this.options.prefixableStrings.includes(next.value)) {
651
624
  return this.ruleValueUnquoted({ onlyToken });
652
625
  }
653
- if (onlyToken)
654
- return void 0;
626
+ if (onlyToken) return void 0;
655
627
  return token.value(...this.processToken());
656
628
  }
657
629
  ruleValueUnquoted({
@@ -689,15 +661,15 @@ class Parser {
689
661
  return void 0;
690
662
  }
691
663
  /**
692
- * Given a list of @see Suggestion entries, the parser options, and a list of variables, prefixes, operators, etc, and the preferred quote type, returns a list of @see Completion entries.
664
+ * Given the ast, a list of {@link Suggestion} entries, the parser options, and a list of variables, prefixes, operators, etc, and the preferred quote type, returns a list of {@link Completion} entries.
693
665
  *
694
666
  * It takes care of suggesting the correct delimiters for fixes, quoting variables/prefixes if it would not be possible to parse them unquoted, and separating symbol from non-symbol (word) operators.
695
667
  *
696
- * Does not add whitespace or group requirements. The suggestion information is still in the completion if you wish to show these. But they should not be added to the completion value if using @see autoreplace which will take care of it.
668
+ * Does not add whitespace or group requirements. The suggestion information is still in the completion if you wish to show these. But they should not be added to the completion value if using {@link autoreplace} which will take care of it.
697
669
  *
698
- * Is not aware of existing values. You will have to use @see getCursorInfo to understand the context in which the suggestion was made, so that, for example, you could filter out used regex flags.
670
+ * Is not aware of existing values. You will have to use {@link getCursorInfo} to understand the context in which the suggestion was made, so that, for example, you could filter out used regex flags.
699
671
  */
700
- autocomplete(suggestions, {
672
+ autocomplete(ast, suggestions, {
701
673
  values = [],
702
674
  arrayValues = [],
703
675
  variables = [],
@@ -709,6 +681,7 @@ class Parser {
709
681
  regexFlags = ["i", "m", "u"],
710
682
  quote = '"'
711
683
  } = {}) {
684
+ const parentMap = generateParentsMap(ast);
712
685
  const self = this;
713
686
  return suggestions.map((suggestion) => {
714
687
  const type = suggestion.type;
@@ -735,7 +708,7 @@ class Parser {
735
708
  return true;
736
709
  }
737
710
  const token2 = suggestion2.cursorInfo;
738
- const flags = token2.at && ((_b = (_a = token2.at.parent) == null ? void 0 : _a.quote) == null ? void 0 : _b.flags) === suggestion2.cursorInfo.at ? token2.at : token2.next && ((_d = (_c = token2.next.parent) == null ? void 0 : _c.quote) == null ? void 0 : _d.flags) === suggestion2.cursorInfo.next ? token2.next : token2.prev && ((_f = (_e = token2.prev.parent) == null ? void 0 : _e.quote) == null ? void 0 : _f.flags) === suggestion2.cursorInfo.prev ? token2.prev : void 0;
711
+ 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;
739
712
  if ((_g = flags == null ? void 0 : flags.value) == null ? void 0 : _g.includes(value)) {
740
713
  return false;
741
714
  }
@@ -767,31 +740,17 @@ class Parser {
767
740
  case SUGGESTION_TYPE.ARRAY_VALUE:
768
741
  case SUGGESTION_TYPE.VARIABLE: {
769
742
  const arr = type === SUGGESTION_TYPE.VARIABLE ? variables : type === SUGGESTION_TYPE.ARRAY_VALUE ? arrayValues : type === SUGGESTION_TYPE.VALUE ? values : unreachable();
770
- return arr.map((variable2) => {
771
- const res = self.parse(variable2);
772
- if (res instanceof ConditionNode && res.operator === void 0 && res.value instanceof VariableNode && res.value.quote === void 0) {
773
- return { suggestion, value: res.value.value.value };
774
- } else {
775
- return { suggestion, value: quote + variable2.replace(new RegExp(quote, "g"), `\\${quote}`) + quote };
776
- }
777
- });
743
+ return arr.map((variable2) => ({ suggestion, value: escapeVariableOrPrefix(variable2, quote) }));
778
744
  }
779
745
  case SUGGESTION_TYPE.PREFIX:
780
- return prefixes.map((prefix) => {
781
- const res = self.parse(prefix);
782
- if (res instanceof ConditionNode && res.operator === void 0 && res.value instanceof VariableNode && res.value.quote === void 0) {
783
- return { suggestion, value: res.value.value.value };
784
- } else {
785
- return { suggestion, value: quote + prefix.replace(new RegExp(quote, "g"), `\\${quote}`) + quote };
786
- }
787
- });
746
+ return prefixes.map((prefix) => ({ suggestion, value: escapeVariableOrPrefix(prefix, quote) }));
788
747
  }
789
748
  }).flat();
790
749
  }
791
750
  /**
792
- * Given the input string and a @see Completion consisting of the value of the replacement and a @see Suggestion entry, returns the replacement string and the new position of the cursor.
751
+ * Given the input string and a {@link Completion} consisting of the value of the replacement and a {@link Suggestion} entry, returns the replacement string and the new position of the cursor.
793
752
  *
794
- * The value passed should be escaped if it's needed (or quoted). @see autocomplete already takes care of quoting variables if you're using it.
753
+ * The value passed should be escaped if it's needed (or quoted). {@link autocomplete} already takes care of quoting variables if you're using it.
795
754
  */
796
755
  autoreplace(input, { value, suggestion }) {
797
756
  const isQuotedLeft = ['"', "'", "`"].includes(value[0]);
@@ -819,9 +778,9 @@ class Parser {
819
778
  return { replacement, cursor };
820
779
  }
821
780
  /**
822
- * Returns a list of suggestions ( @see Suggestion ). These are not a list of autocomplete entries (with values), but more a list of entries describing possible suggestions. This list can then be passed to @see Parser["autocomplete"] to build a list to show users, from which you can then pick an entry to pass to @see Parser["autoreplace"] .
781
+ * Returns a list of suggestions ( {@link Suggestion} ). These are not a list of autocomplete entries (with values), but more a list of entries describing possible suggestions. This list can then be passed to {@link Parser}["autocomplete"] to build a list to show users, from which you can then pick an entry to pass to {@link Parser}["autoreplace"] .
823
782
  *
824
- * The list returned is "unsorted", but there is still some logic to the order. Fixes for errors are suggested first, in the order returned by @see getSurroundingErrors. Regular suggestions come after in the following order: prefixes if enabled, variables, boolean symbol operators, then boolean word operators.
783
+ * The list returned is "unsorted", but there is still some logic to the order. Fixes for errors are suggested first, in the order returned by {@link getSurroundingErrors}. Regular suggestions come after in the following order: prefixes if enabled, variables, boolean symbol operators, then boolean word operators.
825
784
  *
826
785
  * When the cursor is between two tokens that have possible suggestions, only suggestion types for the token before are returned. For example:
827
786
  *
@@ -841,7 +800,8 @@ class Parser {
841
800
  * ```
842
801
  */
843
802
  autosuggest(input, ast, index) {
844
- 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, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L;
803
+ 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;
804
+ const parentMap = generateParentsMap(ast);
845
805
  const opts = this.options;
846
806
  const tokens = extractTokens(ast);
847
807
  const token2 = getCursorInfo(input, tokens, index);
@@ -854,7 +814,7 @@ class Parser {
854
814
  const requiresWhitespacePrevOp = canSuggestOpAfterPrev ? false : requiresWhitespacePrev;
855
815
  const requireWhitespaceNextOp = !canSuggestOpAfterPrev && canSuggestOpBeforeNext ? false : requiresWhitespaceNext;
856
816
  const suggestions = [];
857
- if (ast instanceof ErrorToken) {
817
+ if (isToken(ast) && !ast.valid) {
858
818
  suggestions.push({
859
819
  type: SUGGESTION_TYPE.PREFIX,
860
820
  requires: createDefaultRequires({ group: true }),
@@ -882,16 +842,16 @@ class Parser {
882
842
  };
883
843
  for (const error of surroundingErrors) {
884
844
  for (const type of error.expected) {
885
- if (errorTypesHandled.includes(type))
886
- continue;
845
+ if (errorTypesHandled.includes(type)) continue;
887
846
  errorTypesHandled.push(type);
888
847
  switch (type) {
889
848
  case TOKEN_TYPE.DOUBLEQUOTE:
890
849
  case TOKEN_TYPE.SINGLEQUOTE:
891
850
  case TOKEN_TYPE.BACKTICK:
892
851
  {
893
- const isLeft = error.parent.quote.left === error;
894
- const isRight = error.parent.quote.right === error;
852
+ const errorParent = getParent(error, parentMap);
853
+ const isLeft = errorParent.quote.left === error;
854
+ const isRight = errorParent.quote.right === error;
895
855
  suggestions.push({
896
856
  ...errorSuggestion,
897
857
  type,
@@ -924,10 +884,8 @@ class Parser {
924
884
  }),
925
885
  range: pos({ start: index }, { fill: true })
926
886
  });
927
- if (type === TOKEN_TYPE.AND)
928
- errorTypesHandled.push(TOKEN_TYPE.OR);
929
- if (type === TOKEN_TYPE.OR)
930
- errorTypesHandled.push(TOKEN_TYPE.AND);
887
+ if (type === TOKEN_TYPE.AND) errorTypesHandled.push(TOKEN_TYPE.OR);
888
+ if (type === TOKEN_TYPE.OR) errorTypesHandled.push(TOKEN_TYPE.AND);
931
889
  break;
932
890
  case TOKEN_TYPE.PARENL:
933
891
  case TOKEN_TYPE.PARENR:
@@ -939,8 +897,9 @@ class Parser {
939
897
  });
940
898
  break;
941
899
  case TOKEN_TYPE.VALUE: {
942
- const prefixedValue = error.parent instanceof VariableNode ? (_d = (_c = error.parent) == null ? void 0 : _c.prefix) == null ? void 0 : _d.value : false;
943
- const isRegexValue = error.parent instanceof VariableNode && (((_e = error.parent.quote) == null ? void 0 : _e.left.type) === TOKEN_TYPE.REGEX || ((_f = error.parent.quote) == null ? void 0 : _f.right.type) === TOKEN_TYPE.REGEX);
900
+ const errorParent = getParent(error, parentMap);
901
+ 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;
902
+ 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);
944
903
  if (!isRegexValue) {
945
904
  if (!prefixedValue && opts.prefixableGroups) {
946
905
  suggestions.push({
@@ -1005,41 +964,42 @@ class Parser {
1005
964
  }
1006
965
  }
1007
966
  }
1008
- const prevVar = (_g = token2.valid.prev) == null ? void 0 : _g.parent;
1009
- const nextVar = (_h = token2.valid.next) == null ? void 0 : _h.parent;
1010
- const prevCondition = prevVar == null ? void 0 : prevVar.parent;
1011
- const nextCondition = nextVar == null ? void 0 : nextVar.parent;
1012
- const atVar = (_i = token2.at) == null ? void 0 : _i.parent;
1013
- const atCondition = atVar == null ? void 0 : atVar.parent;
1014
- const isVarPrev = !token2.whitespace.prev && ((_j = token2.valid.prev) == null ? void 0 : _j.type) !== TOKEN_TYPE.REGEX && prevVar instanceof VariableNode && (prevCondition instanceof ConditionNode && prevCondition.value === prevVar && (((_k = prevVar.quote) == null ? void 0 : _k.right) === token2.valid.prev || prevVar.value === token2.valid.prev) || prevCondition instanceof ArrayNode);
1015
- const isVarNext = !token2.whitespace.next && ((_l = token2.valid.next) == null ? void 0 : _l.type) !== TOKEN_TYPE.REGEX && nextVar instanceof VariableNode && (nextCondition instanceof ConditionNode && nextCondition.value === nextVar && (((_m = nextVar.quote) == null ? void 0 : _m.left) === token2.valid.next || nextVar.value === token2.valid.next) || nextCondition instanceof ArrayNode);
1016
- const isVarAt = atVar instanceof VariableNode && atCondition instanceof ConditionNode || prevVar instanceof VariableNode && token2.valid.prev === ((_n = prevVar == null ? void 0 : prevVar.quote) == null ? void 0 : _n.left) || nextVar instanceof VariableNode && token2.valid.next === ((_o = nextVar == null ? void 0 : nextVar.quote) == null ? void 0 : _o.right);
1017
- const isPropertyPrev = prevCondition instanceof ConditionNode && prevVar !== void 0 && prevVar === (prevCondition == null ? void 0 : prevCondition.property);
1018
- const isPropertyNext = nextCondition instanceof ConditionNode && nextVar !== void 0 && nextVar === (nextCondition == null ? void 0 : nextCondition.property);
1019
- const isPropertyAt = atCondition instanceof ConditionNode && atVar !== void 0 && atVar === (atCondition == null ? void 0 : atCondition.property);
1020
- const isPropertyOperatorPrev = prevVar instanceof ConditionNode && token2.valid.prev === (prevVar == null ? void 0 : prevVar.propertyOperator);
1021
- const isPropertyOperatorNext = nextVar instanceof ConditionNode && token2.valid.next === (nextVar == null ? void 0 : nextVar.propertyOperator);
1022
- const isPropertyOperatorAt = atVar instanceof ConditionNode && token2.at === (atVar == null ? void 0 : atVar.propertyOperator);
1023
- const noArrayValuesTarget = ((_p = token2.valid.prev) == null ? void 0 : _p.type) === TOKEN_TYPE.BRACKETL && (token2.valid.next === void 0 || ((_q = token2.valid.next) == null ? void 0 : _q.type) === TOKEN_TYPE.BRACKETR);
967
+ const prevVar = getParent(token2.valid.prev, parentMap);
968
+ const nextVar = getParent(token2.valid.next, parentMap);
969
+ const prevCondition = getParent(prevVar, parentMap);
970
+ const nextCondition = getParent(nextVar, parentMap);
971
+ const atVar = getParent(token2.at, parentMap);
972
+ const atCondition = getParent(atVar, parentMap);
973
+ 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);
974
+ 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);
975
+ 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);
976
+ const isPropertyPrev = (prevCondition == null ? void 0 : prevCondition.type) === AST_TYPE.CONDITION && prevVar !== void 0 && prevVar === (prevCondition == null ? void 0 : prevCondition.property);
977
+ const isPropertyNext = (nextCondition == null ? void 0 : nextCondition.type) === AST_TYPE.CONDITION && nextVar !== void 0 && nextVar === (nextCondition == null ? void 0 : nextCondition.property);
978
+ const isPropertyAt = (atCondition == null ? void 0 : atCondition.type) === AST_TYPE.CONDITION && atVar !== void 0 && atVar === (atCondition == null ? void 0 : atCondition.property);
979
+ const isPropertyOperatorPrev = (prevVar == null ? void 0 : prevVar.type) === AST_TYPE.CONDITION && token2.valid.prev === (prevVar == null ? void 0 : prevVar.propertyOperator);
980
+ const isPropertyOperatorNext = (nextVar == null ? void 0 : nextVar.type) === AST_TYPE.CONDITION && token2.valid.next === (nextVar == null ? void 0 : nextVar.propertyOperator);
981
+ const isPropertyOperatorAt = (atVar == null ? void 0 : atVar.type) === AST_TYPE.CONDITION && token2.at === (atVar == null ? void 0 : atVar.propertyOperator);
982
+ 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);
1024
983
  const target = isVarPrev ? token2.valid.prev : !noArrayValuesTarget && !isPropertyPrev && !isPropertyOperatorPrev && isVarNext ? token2.valid.next : isVarAt ? token2.at : void 0;
1025
984
  const propertyTarget = isPropertyPrev ? token2.valid.prev : !noArrayValuesTarget && !isVarPrev && !isPropertyOperatorPrev && isPropertyNext ? token2.valid.next : isPropertyAt ? token2.at : void 0;
1026
985
  const propOpTarget = isPropertyOperatorPrev ? token2.valid.prev : !noArrayValuesTarget && !isVarPrev && !isPropertyPrev && isPropertyOperatorNext ? token2.valid.next : isPropertyOperatorAt ? token2.at : void 0;
1027
986
  if (target) {
1028
- const parent = target.parent;
1029
- if (parent instanceof VariableNode) {
987
+ const parent = getParent(target, parentMap);
988
+ if (parent && parent.type === AST_TYPE.VARIABLE) {
1030
989
  const range = pos(parent);
1031
- const condition2 = parent == null ? void 0 : parent.parent;
990
+ const parentParent = getParent(parent, parentMap);
991
+ const condition2 = parentParent;
1032
992
  const isValue = condition2.propertyOperator !== void 0 && condition2.value === parent;
1033
- const maybeGroup = (_r = parent == null ? void 0 : parent.parent) == null ? void 0 : _r.parent;
1034
- const isPrefix = maybeGroup instanceof GroupNode && maybeGroup.prefix === condition2;
993
+ const maybeGroup = getParent(parentParent, parentMap);
994
+ const isPrefix = (maybeGroup == null ? void 0 : maybeGroup.type) === AST_TYPE.GROUP && maybeGroup.prefix === condition2;
1035
995
  const varStart = getCursorInfo(input, ast, parent.start);
1036
996
  const varEnd = getCursorInfo(input, ast, parent.end);
1037
997
  const targetRequiresWhitespacePrev = tokenRequiresWhitespace(varStart.valid.prev, varStart.whitespace.prev, wordOps);
1038
998
  const targetRequiresWhitespaceNext = tokenRequiresWhitespace(varEnd.valid.next, varEnd.whitespace.next, wordOps);
1039
- const prefixedValue = target.parent instanceof VariableNode ? (_t = (_s = target.parent) == null ? void 0 : _s.prefix) == null ? void 0 : _t.value : false;
1040
- const isSepPrev = ((_u = token2.prev) == null ? void 0 : _u.type) === TOKEN_TYPE.OP_EXPANDED_SEP;
1041
- const arrayValue = ((_v = target.parent) == null ? void 0 : _v.parent) instanceof ArrayNode;
1042
- const isRegexFlag = target === ((_w = parent.quote) == null ? void 0 : _w.flags);
999
+ const prefixedValue = parent.type === AST_TYPE.VARIABLE ? (_o = parent == null ? void 0 : parent.prefix) == null ? void 0 : _o.value : false;
1000
+ const isSepPrev = ((_p = token2.prev) == null ? void 0 : _p.type) === TOKEN_TYPE.OP_EXPANDED_SEP;
1001
+ const arrayValue = (parentParent == null ? void 0 : parentParent.type) === AST_TYPE.ARRAY;
1002
+ const isRegexFlag = target === ((_q = parent.quote) == null ? void 0 : _q.flags);
1043
1003
  if (!isRegexFlag && !isSepPrev && !isValue && !arrayValue && !prefixedValue && opts.prefixableGroups) {
1044
1004
  suggestions.push({
1045
1005
  ...baseSuggestion,
@@ -1088,16 +1048,17 @@ class Parser {
1088
1048
  });
1089
1049
  }
1090
1050
  if (propOpTarget) {
1051
+ const propOpTargetParent = getParent(propOpTarget, parentMap);
1091
1052
  suggestions.push({
1092
1053
  ...baseSuggestion,
1093
- type: propOpTarget.parent.sep ? SUGGESTION_TYPE.EXPANDED_PROPERTY_OPERATOR : SUGGESTION_TYPE.CUSTOM_PROPERTY_OPERATOR,
1054
+ type: propOpTargetParent.sep ? SUGGESTION_TYPE.EXPANDED_PROPERTY_OPERATOR : SUGGESTION_TYPE.CUSTOM_PROPERTY_OPERATOR,
1094
1055
  requires: createDefaultRequires(),
1095
1056
  range: pos(propOpTarget)
1096
1057
  });
1097
1058
  }
1098
- const canSuggestValue = token2.whitespace.next && (token2.whitespace.prev || ((_x = token2.prev) == null ? void 0 : _x.type) === TOKEN_TYPE.BRACKETL || ((_y = token2.prev) == null ? void 0 : _y.type) === TOKEN_TYPE.PARENL) || token2.whitespace.prev && (token2.whitespace.next || ((_z = token2.next) == null ? void 0 : _z.type) === TOKEN_TYPE.BRACKETR || ((_A = token2.next) == null ? void 0 : _A.type) === TOKEN_TYPE.PARENR);
1059
+ 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);
1099
1060
  if (canSuggestValue) {
1100
- const inArrayNode = [nextCondition, prevCondition, nextVar, prevVar].find((_) => _ instanceof ArrayNode) !== void 0;
1061
+ const inArrayNode = [nextCondition, prevCondition, nextVar, prevVar].find((_) => (_ == null ? void 0 : _.type) === AST_TYPE.ARRAY) !== void 0;
1101
1062
  const opsNotNeeded = ["and", "or"].includes(opts.onMissingBooleanOperator);
1102
1063
  if (inArrayNode || opsNotNeeded) {
1103
1064
  suggestions.push({
@@ -1118,10 +1079,13 @@ class Parser {
1118
1079
  });
1119
1080
  }
1120
1081
  }
1082
+ const tokenAtParent = getParent(token2.at, parentMap);
1083
+ const tokenValidPrevParent = getParent(token2.valid.prev, parentMap);
1084
+ const tokenValidNextParent = getParent(token2.valid.next, parentMap);
1121
1085
  const canSuggestRegexFlags = (
1122
1086
  // has existing flags before/after
1123
- token2.at && token2.at === ((_D = (_C = (_B = token2.at) == null ? void 0 : _B.parent) == null ? void 0 : _C.quote) == null ? void 0 : _D.flags) || token2.valid.prev && token2.valid.prev === ((_G = (_F = (_E = token2.valid.prev) == null ? void 0 : _E.parent) == null ? void 0 : _F.quote) == null ? void 0 : _G.flags) || token2.valid.next && token2.valid.next === ((_J = (_I = (_H = token2.valid.next) == null ? void 0 : _H.parent) == null ? void 0 : _I.quote) == null ? void 0 : _J.flags) || // no flags
1124
- ((_K = token2.valid.prev) == null ? void 0 : _K.type) === TOKEN_TYPE.REGEX && token2.valid.prev === ((_L = token2.valid.prev.parent.quote) == null ? void 0 : _L.right)
1087
+ 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
1088
+ ((_y = token2.valid.prev) == null ? void 0 : _y.type) === TOKEN_TYPE.REGEX && token2.valid.prev === ((_z = tokenValidPrevParent.quote) == null ? void 0 : _z.right)
1125
1089
  );
1126
1090
  if (canSuggestRegexFlags) {
1127
1091
  suggestions.push({
@@ -1162,12 +1126,12 @@ class Parser {
1162
1126
  evaluate(ast, context) {
1163
1127
  this._checkEvaluationOptions();
1164
1128
  const opts = this.options;
1165
- if (ast instanceof Condition) {
1129
+ if (ast.type === AST_TYPE.NORMALIZED_CONDITION) {
1166
1130
  const contextValue = get(context, ast.property);
1167
- const res = opts.valueComparer({ property: ast.property, value: ast.value, operator: ast.operator }, contextValue, context);
1131
+ const res = opts.valueComparer(ast, contextValue, context);
1168
1132
  return ast.negate ? !res : res;
1169
1133
  }
1170
- if (ast instanceof Expression) {
1134
+ if (ast.type === AST_TYPE.NORMALIZED_EXPRESSION) {
1171
1135
  const left = this.evaluate(ast.left, context);
1172
1136
  const right = this.evaluate(ast.right, context);
1173
1137
  return ast.operator === TOKEN_TYPE.AND ? left && right : left || right;
@@ -1192,16 +1156,14 @@ class Parser {
1192
1156
  getBestIndexes(indexes, existing, sortIndex = "") {
1193
1157
  indexes = indexes.filter((set) => {
1194
1158
  for (const key of set) {
1195
- if (!existing.has(key))
1196
- return false;
1159
+ if (!existing.has(key)) return false;
1197
1160
  }
1198
1161
  return true;
1199
1162
  });
1200
1163
  let finalIndexes = indexes;
1201
1164
  if (existing.has(sortIndex)) {
1202
1165
  const indexesWithSortIndex = indexes.filter((set) => set.has(sortIndex));
1203
- if (indexesWithSortIndex.length > 0)
1204
- finalIndexes = indexesWithSortIndex;
1166
+ if (indexesWithSortIndex.length > 0) finalIndexes = indexesWithSortIndex;
1205
1167
  }
1206
1168
  let smallest = Infinity;
1207
1169
  if (existing instanceof Map) {
@@ -1234,10 +1196,10 @@ class Parser {
1234
1196
  * Queries like `(a || b) && (a || c)` would require all the variables to be indexed `[Set(a), Set(b), Set(c)]`.
1235
1197
  */
1236
1198
  getIndexes(ast) {
1237
- if (ast instanceof Condition) {
1199
+ if (ast.type === AST_TYPE.NORMALIZED_CONDITION) {
1238
1200
  return [new Set(ast.property.join("."))];
1239
1201
  }
1240
- if (ast instanceof Expression) {
1202
+ if (ast.type === AST_TYPE.NORMALIZED_EXPRESSION) {
1241
1203
  const left = this.getIndexes(ast.left);
1242
1204
  const right = this.getIndexes(ast.right);
1243
1205
  if (ast.operator === TOKEN_TYPE.AND) {
@@ -1245,8 +1207,7 @@ class Parser {
1245
1207
  const allKeys = /* @__PURE__ */ new Set();
1246
1208
  for (const leftSet of left) {
1247
1209
  const exists = sets.find((set) => isEqualSet(set, leftSet));
1248
- if (exists)
1249
- continue;
1210
+ if (exists) continue;
1250
1211
  sets.push(leftSet);
1251
1212
  for (const key of leftSet) {
1252
1213
  allKeys.add(key);
@@ -1254,22 +1215,19 @@ class Parser {
1254
1215
  }
1255
1216
  for (const rightSet of right) {
1256
1217
  const exists = sets.find((set) => isEqualSet(set, rightSet));
1257
- if (exists)
1258
- continue;
1218
+ if (exists) continue;
1259
1219
  sets.push(rightSet);
1260
1220
  for (const key of rightSet) {
1261
1221
  allKeys.add(key);
1262
1222
  }
1263
1223
  }
1264
1224
  const commonKeys = /* @__PURE__ */ new Set();
1265
- outerCheck:
1266
- for (const key of allKeys) {
1267
- for (const set of sets) {
1268
- if (!set.has(key))
1269
- continue outerCheck;
1270
- }
1271
- commonKeys.add(key);
1225
+ outerCheck: for (const key of allKeys) {
1226
+ for (const set of sets) {
1227
+ if (!set.has(key)) continue outerCheck;
1272
1228
  }
1229
+ commonKeys.add(key);
1230
+ }
1273
1231
  if (commonKeys.size > 0) {
1274
1232
  return [commonKeys, allKeys];
1275
1233
  } else {
@@ -1304,20 +1262,20 @@ class Parser {
1304
1262
  * Normalizes the ast by applying {@link GroupNode GroupNodes} and converting {@link ConditionNode ConditionNodes} to {@link NormalizedConditionNode NormalizedConditionNodes}.
1305
1263
  */
1306
1264
  normalize(ast) {
1307
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1265
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
1308
1266
  this._checkEvaluationOptions();
1309
1267
  const opts = this.options;
1310
- if (ast instanceof ErrorToken || !ast.valid) {
1268
+ if (!ast.valid) {
1311
1269
  throw new Error("AST node must be valid.");
1312
1270
  }
1313
1271
  const prefix = arguments[1];
1314
1272
  const groupValue = arguments[2];
1315
1273
  let operator2 = arguments[3];
1316
1274
  const self_ = this;
1317
- if (ast instanceof ConditionNode) {
1318
- if (!(ast.value instanceof GroupNode)) {
1319
- const isValue = ast.value instanceof ArrayNode || ((_b = (_a = ast.value) == null ? void 0 : _a.quote) == null ? void 0 : _b.left.type) === TOKEN_TYPE.REGEX;
1320
- let name = ast.property ? unescape(ast.property.value.value) : isValue ? void 0 : unescape((_c = ast.value) == null ? void 0 : _c.value.value);
1275
+ if (ast.type === AST_TYPE.CONDITION) {
1276
+ if (!(ast.value.type === AST_TYPE.GROUP)) {
1277
+ 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;
1278
+ 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);
1321
1279
  const isNested = operator2 !== void 0;
1322
1280
  if (prefix !== void 0 && !isNested) {
1323
1281
  name = name ? applyPrefix(prefix, name, opts.prefixApplier) : prefix;
@@ -1327,16 +1285,16 @@ class Parser {
1327
1285
  value = name ?? true;
1328
1286
  name = prefix;
1329
1287
  } else {
1330
- value = ast.value instanceof ArrayNode ? ast.value.values.map((val) => unescape(val.value.value)) : ((_e = (_d = ast.value) == null ? void 0 : _d.quote) == null ? void 0 : _e.left.type) === TOKEN_TYPE.REGEX ? ast.value.value.value : ast.property && ast.value instanceof VariableNode ? unescape(ast.value.value.value) : true;
1288
+ 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;
1331
1289
  }
1332
1290
  const propertyKeys = name ? opts.keyParser(name) : [];
1333
1291
  const boolValue = applyBoolean(groupValue, ast.operator === void 0);
1334
- const valuePrefix = ast.value instanceof VariableNode && ast.value.prefix ? unescape(ast.value.prefix.value) : void 0;
1335
- operator2 ?? (operator2 = (_f = ast.propertyOperator) == null ? void 0 : _f.value);
1336
- const isRegex = ((_h = (_g = ast.value) == null ? void 0 : _g.quote) == null ? void 0 : _h.left.type) === TOKEN_TYPE.REGEX;
1337
- const isQuoted = ((_i = ast.value) == null ? void 0 : _i.quote) !== void 0;
1292
+ const valuePrefix = ast.value.type === AST_TYPE.VARIABLE && ast.value.prefix ? unescape(ast.value.prefix.value) : void 0;
1293
+ operator2 ?? (operator2 = (_h = ast.propertyOperator) == null ? void 0 : _h.value);
1294
+ const isRegex = ((_j = (_i = ast.value) == null ? void 0 : _i.quote) == null ? void 0 : _j.left.type) === TOKEN_TYPE.REGEX;
1295
+ const isQuoted = ((_k = ast.value) == null ? void 0 : _k.quote) !== void 0;
1338
1296
  const isExpanded = ast.sep !== void 0;
1339
- const regexFlags = (_l = (_k = (_j = ast.value) == null ? void 0 : _j.quote) == null ? void 0 : _k.flags) == null ? void 0 : _l.value;
1297
+ const regexFlags = (_n = (_m = (_l = ast.value) == null ? void 0 : _l.quote) == null ? void 0 : _m.flags) == null ? void 0 : _n.value;
1340
1298
  const query = {
1341
1299
  value,
1342
1300
  operator: operator2,
@@ -1350,28 +1308,28 @@ class Parser {
1350
1308
  condition: ast
1351
1309
  };
1352
1310
  const res = opts.conditionNormalizer(query);
1353
- return new Condition({ property: propertyKeys, ...res });
1311
+ return createCondition({ property: propertyKeys, ...res });
1354
1312
  } else {
1355
1313
  let name = unescape(ast.property.value.value);
1356
1314
  if (prefix !== void 0) {
1357
1315
  name = applyPrefix(prefix, name, opts.prefixApplier);
1358
1316
  }
1359
1317
  const boolValue = applyBoolean(groupValue, ast.operator === void 0);
1360
- const operator22 = (_m = ast.propertyOperator) == null ? void 0 : _m.value;
1318
+ const operator22 = (_o = ast.propertyOperator) == null ? void 0 : _o.value;
1361
1319
  return self_.normalize(ast.value, name, boolValue, operator22);
1362
1320
  }
1363
1321
  }
1364
- if (ast instanceof GroupNode) {
1365
- const _prefix = ast.prefix instanceof ConditionNode && ast.prefix.value instanceof VariableNode ? unescape(ast.prefix.value.value.value) : void 0;
1366
- const _groupValue = ast.prefix instanceof ConditionNode ? ast.prefix.operator === void 0 : !(ast.prefix instanceof ValidToken);
1322
+ if (ast.type === AST_TYPE.GROUP) {
1323
+ 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;
1324
+ 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);
1367
1325
  const applied = applyPrefix(prefix, _prefix ?? "", opts.prefixApplier);
1368
1326
  return self_.normalize(ast.expression, applied, applyBoolean(groupValue, _groupValue), operator2);
1369
1327
  }
1370
- if (ast instanceof ExpressionNode) {
1328
+ if (ast.type === AST_TYPE.EXPRESSION) {
1371
1329
  const left = self_.normalize(ast.left, prefix, groupValue, operator2);
1372
1330
  const right = self_.normalize(ast.right, prefix, groupValue, operator2);
1373
1331
  const type = groupValue === false ? OPPOSITE[ast.operator.type] : ast.operator.type;
1374
- return new Expression({ operator: type, left, right });
1332
+ return createExpression({ operator: type, left, right });
1375
1333
  }
1376
1334
  return unreachable();
1377
1335
  }
@@ -1382,11 +1340,11 @@ class Parser {
1382
1340
  * 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.
1383
1341
  */
1384
1342
  validate(ast, context) {
1385
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1343
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1386
1344
  const self = this;
1387
1345
  self._checkValidationOptions();
1388
1346
  const opts = self.options;
1389
- if (ast instanceof ErrorToken || !ast.valid) {
1347
+ if (!ast.valid) {
1390
1348
  throw new Error("AST node must be valid.");
1391
1349
  }
1392
1350
  const prefix = arguments[2];
@@ -1395,9 +1353,9 @@ class Parser {
1395
1353
  const prefixes = arguments[5] ?? [];
1396
1354
  let operator2 = arguments[6];
1397
1355
  const self_ = this;
1398
- if (ast instanceof ConditionNode) {
1399
- if (!(ast.value instanceof GroupNode)) {
1400
- const isValue = ast.value instanceof ArrayNode || ((_b = (_a = ast.value) == null ? void 0 : _a.quote) == null ? void 0 : _b.left.type) === TOKEN_TYPE.REGEX;
1356
+ if (ast.type === AST_TYPE.CONDITION) {
1357
+ if (!(ast.value.type === AST_TYPE.GROUP)) {
1358
+ 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;
1401
1359
  const nameNode = ast.property ? ast.property : isValue ? void 0 : ast.value;
1402
1360
  let name = nameNode ? unescape(nameNode.value.value) : void 0;
1403
1361
  const isNested = operator2 !== void 0;
@@ -1412,12 +1370,12 @@ class Parser {
1412
1370
  propertyNodes = [...prefixes];
1413
1371
  } else {
1414
1372
  propertyNodes = [...prefixes, ...nameNode ? [nameNode] : []];
1415
- value = ast.value instanceof ArrayNode ? 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 instanceof VariableNode ? ast.value : true;
1373
+ 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;
1416
1374
  }
1417
1375
  const propertyKeys = name ? opts.keyParser(name) : [];
1418
1376
  const contextValue = context !== void 0 ? get(context, propertyKeys) : void 0;
1419
1377
  const boolValue = applyBoolean(groupValue, ast.operator === void 0);
1420
- const valuePrefix = ast.value instanceof VariableNode && ast.value.prefix ? ast.value.prefix : void 0;
1378
+ const valuePrefix = ast.value.type === AST_TYPE.VARIABLE && ast.value.prefix ? ast.value.prefix : void 0;
1421
1379
  operator2 ?? (operator2 = ast.propertyOperator);
1422
1380
  const isRegex = ((_f = (_e = ast.value) == null ? void 0 : _e.quote) == null ? void 0 : _f.left.type) === TOKEN_TYPE.REGEX;
1423
1381
  const isQuoted = ((_g = ast.value) == null ? void 0 : _g.quote) !== void 0;
@@ -1439,11 +1397,9 @@ class Parser {
1439
1397
  condition: ast
1440
1398
  };
1441
1399
  const res = opts.valueValidator(contextValue, query, context);
1442
- if (res && !isArray(res))
1443
- throw new Error("The valueValidator must return an array or nothing/undefined");
1400
+ if (res && !isArray(res)) throw new Error("The valueValidator must return an array or nothing/undefined");
1444
1401
  if (res) {
1445
- for (const entry of res)
1446
- results.push(entry);
1402
+ for (const entry of res) results.push(entry);
1447
1403
  }
1448
1404
  } else {
1449
1405
  let name = unescape(ast.property.value.value);
@@ -1451,20 +1407,18 @@ class Parser {
1451
1407
  name = applyPrefix(prefix, name, opts.prefixApplier);
1452
1408
  }
1453
1409
  const boolValue = applyBoolean(groupValue, ast.operator === void 0);
1454
- if (ast.property)
1455
- prefixes.push(ast.property);
1410
+ if (ast.property) prefixes.push(ast.property);
1456
1411
  const operator22 = ast.propertyOperator;
1457
1412
  self_.validate(ast.value, context, name, boolValue, results, prefixes, operator22);
1458
1413
  }
1459
1414
  }
1460
- if (ast instanceof GroupNode) {
1461
- const _prefix = ast.prefix instanceof ConditionNode && ast.prefix.value instanceof VariableNode ? ast.prefix.value : void 0;
1462
- if (_prefix)
1463
- prefixes.push(_prefix);
1464
- const _groupValue = ast.prefix instanceof ConditionNode ? ast.prefix.operator === void 0 : !(ast.prefix instanceof ValidToken);
1415
+ if (ast.type === AST_TYPE.GROUP) {
1416
+ 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;
1417
+ if (_prefix) prefixes.push(_prefix);
1418
+ 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);
1465
1419
  self_.validate(ast.expression, context, applyPrefix(prefix, (_prefix == null ? void 0 : _prefix.value.value) ?? "", opts.prefixApplier), applyBoolean(groupValue, _groupValue), results, prefixes, operator2);
1466
1420
  }
1467
- if (ast instanceof ExpressionNode) {
1421
+ if (ast.type === AST_TYPE.EXPRESSION) {
1468
1422
  self_.validate(ast.left, context, prefix, groupValue, results, [...prefixes], operator2);
1469
1423
  self_.validate(ast.right, context, prefix, groupValue, results, [...prefixes], operator2);
1470
1424
  }