json-p3 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +0 -1
  2. package/dist/json-p3.browser.js +5303 -0
  3. package/dist/json-p3.browser.min.js +2 -0
  4. package/dist/json-p3.browser.min.js.map +1 -0
  5. package/dist/json-p3.cjs.js +110 -109
  6. package/dist/json-p3.esm.js +110 -109
  7. package/dist/json-p3.iife.min.js +1 -1
  8. package/dist/json-p3.iife.min.js.map +1 -1
  9. package/package.json +11 -24
  10. package/dist/deep_equals.d.ts +0 -10
  11. package/dist/index.d.ts +0 -10
  12. package/dist/json-p3.iife.js +0 -5338
  13. package/dist/patch/errors.d.ts +0 -11
  14. package/dist/patch/index.d.ts +0 -11
  15. package/dist/patch/patch.d.ts +0 -161
  16. package/dist/path/environment.d.ts +0 -165
  17. package/dist/path/errors.d.ts +0 -65
  18. package/dist/path/expression.d.ts +0 -101
  19. package/dist/path/extra/expression.d.ts +0 -6
  20. package/dist/path/extra/index.d.ts +0 -0
  21. package/dist/path/extra/selectors.d.ts +0 -35
  22. package/dist/path/functions/count.d.ts +0 -7
  23. package/dist/path/functions/function.d.ts +0 -26
  24. package/dist/path/functions/has.d.ts +0 -44
  25. package/dist/path/functions/index.d.ts +0 -11
  26. package/dist/path/functions/length.d.ts +0 -7
  27. package/dist/path/functions/match.d.ts +0 -33
  28. package/dist/path/functions/pattern.d.ts +0 -2
  29. package/dist/path/functions/search.d.ts +0 -34
  30. package/dist/path/functions/value.d.ts +0 -7
  31. package/dist/path/index.d.ts +0 -76
  32. package/dist/path/lex.d.ts +0 -69
  33. package/dist/path/lru_cache.d.ts +0 -10
  34. package/dist/path/node.d.ts +0 -84
  35. package/dist/path/parse.d.ts +0 -61
  36. package/dist/path/path.d.ts +0 -42
  37. package/dist/path/segments.d.ts +0 -39
  38. package/dist/path/selectors.d.ts +0 -85
  39. package/dist/path/serialize.d.ts +0 -6
  40. package/dist/path/token.d.ts +0 -70
  41. package/dist/path/types.d.ts +0 -46
  42. package/dist/pointer/errors.d.ts +0 -42
  43. package/dist/pointer/index.d.ts +0 -24
  44. package/dist/pointer/pointer.d.ts +0 -106
  45. package/dist/tsconfig.tsbuildinfo +0 -1
  46. package/dist/types.d.ts +0 -25
@@ -1,5 +1,5 @@
1
1
  /*
2
- * json-p3 version 2.2.1
2
+ * json-p3 version 2.3.0
3
3
  * https://github.com/jg-rp/json-p3
4
4
  *
5
5
  * MIT License
@@ -337,10 +337,7 @@ class JSONPointer {
337
337
  }
338
338
  static encode(tokens) {
339
339
  if (!tokens.length) return "";
340
- return (
341
- // eslint-disable-next-line prefer-template
342
- "/" + tokens.map(token => token.replaceAll("~", "~0").replaceAll("/", "~1")).join("/")
343
- );
340
+ return "/" + tokens.map(token => token.replaceAll("~", "~0").replaceAll("/", "~1")).join("/");
344
341
  }
345
342
 
346
343
  /**
@@ -357,8 +354,7 @@ class JSONPointer {
357
354
  * If the value pointed to by _pointer_ does not exist in _value_, and
358
355
  * no fallback value is given.
359
356
  */
360
- resolve(value) {
361
- let fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : UNDEFINED;
357
+ resolve(value, fallback = UNDEFINED) {
362
358
  try {
363
359
  return this.tokens.reduce(this.getItem.bind(this), value);
364
360
  } catch (error) {
@@ -463,10 +459,7 @@ class JSONPointer {
463
459
  * @returns A new JSON Pointer that is the concatenation of all tokens or
464
460
  * "parts".
465
461
  */
466
- join() {
467
- for (var _len = arguments.length, tokens = new Array(_len), _key = 0; _key < _len; _key++) {
468
- tokens[_key] = arguments[_key];
469
- }
462
+ join(...tokens) {
470
463
  if (!tokens.length) {
471
464
  return this;
472
465
  }
@@ -515,7 +508,7 @@ class JSONPointer {
515
508
  }
516
509
  }
517
510
  const RE_RELATIVE_POINTER = /(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s;
518
- const RE_INT = /(0|[1-9][0-9]*)/;
511
+ const RE_INT = /(0|[1-9]\d*)/;
519
512
 
520
513
  /**
521
514
  * A relative JSON Pointer.
@@ -634,8 +627,7 @@ class RelativeJSONPointer {
634
627
  * @throws {@link JSONPointerSyntaxError}
635
628
  * If _pointer_ is malformed according to RFC 6901.
636
629
  */
637
- function resolve(pointer, value) {
638
- let fallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : UNDEFINED;
630
+ function resolve(pointer, value, fallback = UNDEFINED) {
639
631
  return new JSONPointer(pointer).resolve(value, fallback);
640
632
  }
641
633
 
@@ -739,10 +731,7 @@ class JSONPathNode {
739
731
  ...defaultSerializationOptions,
740
732
  ...options
741
733
  };
742
- return (
743
- // eslint-disable-next-line prefer-template
744
- "$" + this.location.map(s => isString(s) ? this.decodeNameLocation(s, opts) : `[${s}]`).join("")
745
- );
734
+ return "$" + this.location.map(s => isString(s) ? this.decodeNameLocation(s, opts) : `[${s}]`).join("");
746
735
  }
747
736
 
748
737
  /**
@@ -1137,16 +1126,16 @@ var expression = /*#__PURE__*/Object.freeze({
1137
1126
  });
1138
1127
 
1139
1128
  class Count {
1140
- argTypes = (() => [FunctionExpressionType.NodesType])();
1141
- returnType = (() => FunctionExpressionType.ValueType)();
1129
+ argTypes = [FunctionExpressionType.NodesType];
1130
+ returnType = FunctionExpressionType.ValueType;
1142
1131
  call(nodes) {
1143
1132
  return nodes.length;
1144
1133
  }
1145
1134
  }
1146
1135
 
1147
1136
  class Length {
1148
- argTypes = (() => [FunctionExpressionType.ValueType])();
1149
- returnType = (() => FunctionExpressionType.ValueType)();
1137
+ argTypes = [FunctionExpressionType.ValueType];
1138
+ returnType = FunctionExpressionType.ValueType;
1150
1139
  call(value) {
1151
1140
  if (isArray(value) || isString(value)) return value.length;
1152
1141
  if (isObject(value)) return Object.keys(value).length;
@@ -1158,9 +1147,7 @@ class Length {
1158
1147
  * A Least Recently Used cache, implemented as an extended Map.
1159
1148
  */
1160
1149
  class LRUCache extends Map {
1161
- constructor() {
1162
- let maxSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 128;
1163
- let entries = arguments.length > 1 ? arguments[1] : undefined;
1150
+ constructor(maxSize = 128, entries) {
1164
1151
  if (entries !== undefined) {
1165
1152
  super(entries);
1166
1153
  } else {
@@ -2478,11 +2465,10 @@ var check_1 = {
2478
2465
  var check$1 = check_1.check;
2479
2466
 
2480
2467
  class Match {
2481
- argTypes = (() => [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType])();
2482
- returnType = (() => FunctionExpressionType.LogicalType)();
2468
+ argTypes = [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType];
2469
+ returnType = FunctionExpressionType.LogicalType;
2483
2470
  #cache;
2484
- constructor() {
2485
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2471
+ constructor(options = {}) {
2486
2472
  this.options = options;
2487
2473
  this.cacheSize = options.cacheSize ?? 10;
2488
2474
  this.throwErrors = options.throwErrors ?? false;
@@ -2527,11 +2513,10 @@ class Match {
2527
2513
  }
2528
2514
 
2529
2515
  class Search {
2530
- argTypes = (() => [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType])();
2531
- returnType = (() => FunctionExpressionType.LogicalType)();
2516
+ argTypes = [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType];
2517
+ returnType = FunctionExpressionType.LogicalType;
2532
2518
  #cache;
2533
- constructor() {
2534
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2519
+ constructor(options = {}) {
2535
2520
  this.options = options;
2536
2521
  this.cacheSize = options.cacheSize ?? 10;
2537
2522
  this.throwErrors = options.throwErrors ?? false;
@@ -2576,8 +2561,8 @@ class Search {
2576
2561
  }
2577
2562
 
2578
2563
  class Value {
2579
- argTypes = (() => [FunctionExpressionType.NodesType])();
2580
- returnType = (() => FunctionExpressionType.ValueType)();
2564
+ argTypes = [FunctionExpressionType.NodesType];
2565
+ returnType = FunctionExpressionType.ValueType;
2581
2566
  call(nodes) {
2582
2567
  if (nodes.length === 1) return nodes.nodes[0].value;
2583
2568
  return Nothing;
@@ -2593,6 +2578,7 @@ let TokenKind = /*#__PURE__*/function (TokenKind) {
2593
2578
  TokenKind["COMMA"] = "TOKEN_COMMA";
2594
2579
  TokenKind["CURRENT"] = "TOKEN_CURRENT_VALUE";
2595
2580
  TokenKind["CURRENT_KEY"] = "TOKEN_CURRENT_KEY";
2581
+ // non-standard, default `#`
2596
2582
  TokenKind["DDOT"] = "TOKEN_DDOT";
2597
2583
  TokenKind["DOT"] = "TOKEN_DOT";
2598
2584
  TokenKind["DOUBLE_QUOTE_STRING"] = "TOKEN_DOUBLE_QUOTE_STRING";
@@ -2606,10 +2592,15 @@ let TokenKind = /*#__PURE__*/function (TokenKind) {
2606
2592
  TokenKind["GT"] = "TOKEN_GT";
2607
2593
  TokenKind["INDEX"] = "TOKEN_INDEX";
2608
2594
  TokenKind["KEY"] = "TOKEN_KEY";
2595
+ // non-standard, default `~<name>`
2609
2596
  TokenKind["KEY_DOUBLE_QUOTE_STRING"] = "TOKEN_KEY_DOUBLE_QUOTE_STRING";
2597
+ // non-standard, `~"<name>"`
2610
2598
  TokenKind["KEY_SINGLE_QUOTE_STRING"] = "TOKEN_KEY_SINGLE_QUOTE_STRING";
2599
+ // non-standard, `~'<name>'`
2611
2600
  TokenKind["KEYS"] = "TOKEN_KEYS";
2601
+ // non-standard, default `~`
2612
2602
  TokenKind["KEYS_FILTER"] = "TOKEN_KEYS_FILTER";
2603
+ // non-standard, `~?<expression>`
2613
2604
  TokenKind["LBRACKET"] = "TOKEN_LBRACKET";
2614
2605
  TokenKind["LE"] = "TOKEN_LE";
2615
2606
  TokenKind["LG"] = "TOKEN_LG";
@@ -2693,7 +2684,7 @@ class TokenStream {
2693
2684
  const exponentPattern = /[eE][+-]?\d+/y;
2694
2685
  const functionNamePattern = /[a-z][a-z_0-9]*/y;
2695
2686
  const indexPattern = /-?\d+/y;
2696
- const intPattern = /-?[0-9]+/y;
2687
+ const intPattern = /-?\d+/y;
2697
2688
  const namePattern = /[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y;
2698
2689
  const whitespace = new Set([" ", "\n", "\t", "\r"]);
2699
2690
  const nameFirstPattern = /[\u0080-\uFFFFa-zA-Z_]/; // don't set sticky bit
@@ -2718,7 +2709,13 @@ class Lexer {
2718
2709
  * If the stack is empty, we are not in a function call. Remember that
2719
2710
  * function arguments can use arbitrarily nested in parentheses.
2720
2711
  */
2721
- parenStack = [];
2712
+ funcCallStack = [];
2713
+
2714
+ /**
2715
+ * A stack of parentheses and square brackets used to check for balanced
2716
+ * brackets.
2717
+ */
2718
+ bracketStack = [];
2722
2719
 
2723
2720
  /** Tokens resulting from tokenizing a JSONPath query. */
2724
2721
  tokens = [];
@@ -2847,9 +2844,19 @@ function lex(environment, path) {
2847
2844
  function tokenize(environment, path) {
2848
2845
  const [lexer, tokens] = lex(environment, path);
2849
2846
  lexer.run();
2847
+
2848
+ // If there's an error, it will be the last token with kind set to ERROR.
2850
2849
  if (tokens.length && tokens[tokens.length - 1].kind === TokenKind.ERROR) {
2851
2850
  throw new JSONPathSyntaxError(tokens[tokens.length - 1].value, tokens[tokens.length - 1]);
2852
2851
  }
2852
+
2853
+ // If the bracket stack is not empty, we hav unbalanced brackets.
2854
+ // This might not be reachable.
2855
+ if (lexer.bracketStack.length !== 0) {
2856
+ const [ch, index] = lexer.bracketStack[lexer.bracketStack.length - 1];
2857
+ const msg = "unbalanced brackets";
2858
+ throw new JSONPathSyntaxError(msg, new Token(TokenKind.ERROR, ch, index, path));
2859
+ }
2853
2860
  return tokens;
2854
2861
  }
2855
2862
  function lexRoot(l) {
@@ -2879,6 +2886,7 @@ function lexSegment(l) {
2879
2886
  }
2880
2887
  return lexDotSelector;
2881
2888
  case "[":
2889
+ l.bracketStack.push(["[", l.start]);
2882
2890
  l.emit(TokenKind.LBRACKET);
2883
2891
  return lexInsideBracketedSelection;
2884
2892
  default:
@@ -2935,6 +2943,7 @@ function lexDescendantSelection(l) {
2935
2943
  l.emit(TokenKind.WILD);
2936
2944
  return lexSegment;
2937
2945
  case "[":
2946
+ l.bracketStack.push(["[", l.start]);
2938
2947
  l.emit(TokenKind.LBRACKET);
2939
2948
  return lexInsideBracketedSelection;
2940
2949
  default:
@@ -2993,7 +3002,6 @@ function lexInsideBracketedSelection(l) {
2993
3002
  continue;
2994
3003
  }
2995
3004
  if (!l.environment.strict && l.acceptMatchRun(l.environment.keysPattern)) {
2996
- // FIXME: fall back to legacy behavior if keysPattern is not the default
2997
3005
  switch (l.peek()) {
2998
3006
  case "'":
2999
3007
  l.ignore(); // ~
@@ -3016,6 +3024,12 @@ function lexInsideBracketedSelection(l) {
3016
3024
  const ch = l.next();
3017
3025
  switch (ch) {
3018
3026
  case "]":
3027
+ if (l.bracketStack.length === 0 || l.bracketStack[l.bracketStack.length - 1][0] !== "[") {
3028
+ l.backup();
3029
+ l.error("unbalanced brackets");
3030
+ return null;
3031
+ }
3032
+ l.bracketStack.pop();
3019
3033
  l.emit(TokenKind.RBRACKET);
3020
3034
  return lexSegment;
3021
3035
  case "":
@@ -3057,17 +3071,13 @@ function lexInsideFilter(l) {
3057
3071
  return null;
3058
3072
  case "]":
3059
3073
  l.filterLevel -= 1;
3060
- if (l.parenStack.length === 1) {
3061
- l.error("unbalanced parentheses");
3062
- return null;
3063
- }
3064
3074
  l.backup();
3065
3075
  return lexInsideBracketedSelection;
3066
3076
  case ",":
3067
3077
  l.emit(TokenKind.COMMA);
3068
3078
  // If we have unbalanced parens, we are inside a function call and a
3069
3079
  // comma separates arguments. Otherwise a comma separates selectors.
3070
- if (l.parenStack.length) continue;
3080
+ if (l.funcCallStack.length) continue;
3071
3081
  l.filterLevel -= 1;
3072
3082
  return lexInsideBracketedSelection;
3073
3083
  case "'":
@@ -3075,18 +3085,25 @@ function lexInsideFilter(l) {
3075
3085
  case '"':
3076
3086
  return lexDoubleQuoteStringInsideFilterExpression;
3077
3087
  case "(":
3088
+ l.bracketStack.push(["(", l.start]);
3078
3089
  l.emit(TokenKind.LPAREN);
3079
3090
  // Are we in a function call? If so, a function argument contains parens.
3080
- if (l.parenStack.length) l.parenStack[l.parenStack.length - 1] += 1;
3091
+ if (l.funcCallStack.length) l.funcCallStack[l.funcCallStack.length - 1] += 1;
3081
3092
  continue;
3082
3093
  case ")":
3094
+ if (l.bracketStack.length === 0 || l.bracketStack[l.bracketStack.length - 1][0] !== "(") {
3095
+ l.backup();
3096
+ l.error("unbalanced brackets");
3097
+ return null;
3098
+ }
3099
+ l.bracketStack.pop();
3083
3100
  l.emit(TokenKind.RPAREN);
3084
3101
  // Are we closing a function call or a parenthesized expression?
3085
- if (l.parenStack.length) {
3086
- if (l.parenStack[l.parenStack.length - 1] === 1) {
3087
- l.parenStack.pop();
3102
+ if (l.funcCallStack.length) {
3103
+ if (l.funcCallStack[l.funcCallStack.length - 1] === 1) {
3104
+ l.funcCallStack.pop();
3088
3105
  } else {
3089
- l.parenStack[l.parenStack.length - 1] -= 1;
3106
+ l.funcCallStack[l.funcCallStack.length - 1] -= 1;
3090
3107
  }
3091
3108
  }
3092
3109
  continue;
@@ -3183,8 +3200,9 @@ function lexInsideFilter(l) {
3183
3200
  // functions
3184
3201
  if (l.acceptMatchRun(functionNamePattern) && l.peek() === "(") {
3185
3202
  // Keep track of parentheses for this function call.
3186
- l.parenStack.push(1);
3203
+ l.funcCallStack.push(1);
3187
3204
  l.emit(TokenKind.FUNCTION);
3205
+ l.bracketStack.push(["(", l.start]);
3188
3206
  l.next();
3189
3207
  l.ignore();
3190
3208
  continue;
@@ -3375,10 +3393,7 @@ class SliceSelector extends JSONPathSelector {
3375
3393
  const step = this.step ? this.step : "1";
3376
3394
  return `${start}:${stop}:${step}`;
3377
3395
  }
3378
- checkRange() {
3379
- for (var _len = arguments.length, indices = new Array(_len), _key = 0; _key < _len; _key++) {
3380
- indices[_key] = arguments[_key];
3381
- }
3396
+ checkRange(...indices) {
3382
3397
  for (const index of indices) {
3383
3398
  if (index !== undefined && (index < this.environment.minIntIndex || index > this.environment.maxIntIndex)) {
3384
3399
  throw new JSONPathIndexError("index out of range", this.token);
@@ -3665,53 +3680,45 @@ class DescendantSegment extends JSONPathSegment {
3665
3680
  toString(options) {
3666
3681
  return `..[${this.selectors.map(s => s.toString(options)).join(", ")}]`;
3667
3682
  }
3668
- visit(node) {
3669
- var _this = this;
3670
- let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
3671
- return function* () {
3672
- if (depth >= _this.environment.maxRecursionDepth) {
3673
- throw new JSONPathRecursionLimitError("recursion limit reached", _this.token);
3683
+ *visit(node, depth = 1) {
3684
+ if (depth >= this.environment.maxRecursionDepth) {
3685
+ throw new JSONPathRecursionLimitError("recursion limit reached", this.token);
3686
+ }
3687
+ yield node;
3688
+ if (isArray(node.value)) {
3689
+ for (let i = 0; i < node.value.length; i++) {
3690
+ const _node = new JSONPathNode(node.value[i], node.location.concat(i), node.root);
3691
+ yield* this.visit(_node, depth + 1);
3692
+ }
3693
+ } else if (isObject(node.value)) {
3694
+ for (const [key, value] of this.environment.entries(node.value)) {
3695
+ const _node = new JSONPathNode(value, node.location.concat(key), node.root);
3696
+ yield* this.visit(_node, depth + 1);
3674
3697
  }
3698
+ }
3699
+ }
3700
+ *nondeterministicVisit(root, depth = 1) {
3701
+ let queue = Array.from(this.nondeterministicChildren(root)).map(node => [node, depth]);
3702
+ yield root;
3703
+ while (queue.length) {
3704
+ const [node, _depth] = queue.shift();
3675
3705
  yield node;
3676
- if (isArray(node.value)) {
3677
- for (let i = 0; i < node.value.length; i++) {
3678
- const _node = new JSONPathNode(node.value[i], node.location.concat(i), node.root);
3679
- yield* _this.visit(_node, depth + 1);
3680
- }
3681
- } else if (isObject(node.value)) {
3682
- for (const [key, value] of _this.environment.entries(node.value)) {
3683
- const _node = new JSONPathNode(value, node.location.concat(key), node.root);
3684
- yield* _this.visit(_node, depth + 1);
3685
- }
3706
+ if (_depth >= this.environment.maxRecursionDepth) {
3707
+ throw new JSONPathRecursionLimitError("recursion limit reached", this.token);
3686
3708
  }
3687
- }();
3688
- }
3689
- nondeterministicVisit(root) {
3690
- var _this2 = this;
3691
- let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
3692
- return function* () {
3693
- let queue = Array.from(_this2.nondeterministicChildren(root)).map(node => [node, depth]);
3694
- yield root;
3695
- while (queue.length) {
3696
- const [node, _depth] = queue.shift();
3697
- yield node;
3698
- if (_depth >= _this2.environment.maxRecursionDepth) {
3699
- throw new JSONPathRecursionLimitError("recursion limit reached", _this2.token);
3700
- }
3701
3709
 
3702
- // Visit child nodes now or queue them for later?
3703
- const visitChildren = Math.random() < 0.5;
3704
- for (const child of _this2.nondeterministicChildren(node)) {
3705
- if (visitChildren) {
3706
- yield child;
3707
- const grandchildren = Array.from(_this2.nondeterministicChildren(child)).map(n => [n, _depth + 2]);
3708
- queue = interleave(queue, grandchildren);
3709
- } else {
3710
- queue.push([child, _depth + 1]);
3711
- }
3710
+ // Visit child nodes now or queue them for later?
3711
+ const visitChildren = Math.random() < 0.5;
3712
+ for (const child of this.nondeterministicChildren(node)) {
3713
+ if (visitChildren) {
3714
+ yield child;
3715
+ const grandchildren = Array.from(this.nondeterministicChildren(child)).map(n => [n, _depth + 2]);
3716
+ queue = interleave(queue, grandchildren);
3717
+ } else {
3718
+ queue.push([child, _depth + 1]);
3712
3719
  }
3713
3720
  }
3714
- }();
3721
+ }
3715
3722
  }
3716
3723
  *nondeterministicChildren(node) {
3717
3724
  if (isString(node.value)) return;
@@ -3977,8 +3984,7 @@ class Parser {
3977
3984
  }
3978
3985
  return segments;
3979
3986
  }
3980
- parseQuery(stream) {
3981
- let inFilter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3987
+ parseQuery(stream, inFilter = false) {
3982
3988
  const segments = [];
3983
3989
  loop: for (;;) {
3984
3990
  switch (stream.current.kind) {
@@ -4130,8 +4136,7 @@ class Parser {
4130
4136
  }
4131
4137
  return selectors;
4132
4138
  }
4133
- parseFilter(stream) {
4134
- let keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
4139
+ parseFilter(stream, keys = false) {
4135
4140
  const tok = stream.next();
4136
4141
  const expr = this.parseFilterExpression(stream);
4137
4142
  if (expr instanceof FunctionExtension) {
@@ -4245,8 +4250,7 @@ class Parser {
4245
4250
  stream.expect(TokenKind.RPAREN);
4246
4251
  return new FunctionExtension(tok, tok.value, this.environment.checkWellTypedness(tok, args));
4247
4252
  }
4248
- parseFilterExpression(stream) {
4249
- let precedence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : PRECEDENCE_LOWEST;
4253
+ parseFilterExpression(stream, precedence = PRECEDENCE_LOWEST) {
4250
4254
  const func = this.tokenMap.get(stream.current.kind);
4251
4255
  if (!func) {
4252
4256
  let msg;
@@ -4316,7 +4320,6 @@ class Parser {
4316
4320
  rv.push(this.stringFromCodePoint(codepoint, token));
4317
4321
  break;
4318
4322
  default:
4319
- // TODO: This is unreachable. The lexer will catch unknown escape sequences.
4320
4323
  throw new JSONPathSyntaxError(`unknown escape sequence at index ${token.index + index - 1}`, token);
4321
4324
  }
4322
4325
  } else {
@@ -4496,12 +4499,11 @@ class JSONPathEnvironment {
4496
4499
  * A map of function names to objects implementing the {@link FilterFunction}
4497
4500
  * interface. You are free to set or delete custom filter functions directly.
4498
4501
  */
4499
- functionRegister = (() => new Map())();
4502
+ functionRegister = new Map();
4500
4503
  /**
4501
4504
  * @param options - Environment configuration options.
4502
4505
  */
4503
- constructor() {
4504
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4506
+ constructor(options = {}) {
4505
4507
  this.strict = options.strict ?? true;
4506
4508
  this.maxIntIndex = options.maxIntIndex ?? Math.pow(2, 53) - 1;
4507
4509
  this.minIntIndex = options.maxIntIndex ?? -Math.pow(2, 53) + 1;
@@ -4646,11 +4648,10 @@ class JSONPathEnvironment {
4646
4648
  * value and it contains a property matching the second argument.
4647
4649
  */
4648
4650
  class Has {
4649
- argTypes = (() => [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType])();
4650
- returnType = (() => FunctionExpressionType.LogicalType)();
4651
+ argTypes = [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType];
4652
+ returnType = FunctionExpressionType.LogicalType;
4651
4653
  #cache;
4652
- constructor() {
4653
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4654
+ constructor(options = {}) {
4654
4655
  this.options = options;
4655
4656
  this.cacheSize = options.cacheSize ?? 10;
4656
4657
  this.throwErrors = options.throwErrors ?? false;
@@ -5299,7 +5300,7 @@ var index = /*#__PURE__*/Object.freeze({
5299
5300
  apply: apply
5300
5301
  });
5301
5302
 
5302
- const version = "2.2.1";
5303
+ const version = "2.3.0";
5303
5304
 
5304
5305
  exports.DEFAULT_ENVIRONMENT = DEFAULT_ENVIRONMENT;
5305
5306
  exports.FunctionExpressionType = FunctionExpressionType;