@zvenigora/ng-eval-core 0.6.0 → 0.7.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.
@@ -675,6 +675,21 @@ class Cache {
675
675
  }
676
676
  }
677
677
 
678
+ /**
679
+ * Strips the `ParenthesizedExpression` wrappers acorn keeps around a node
680
+ * under `preserveParens`, so `(a)` and `((a))` are handled as `a`. A walk
681
+ * passes through them without help, since `acorn-walk`'s base visitor does;
682
+ * only a visitor that branches on a child's *type* has to unwrap it first.
683
+ * @param node - The node, possibly parenthesised.
684
+ * @returns The innermost node that is not a `ParenthesizedExpression`.
685
+ */
686
+ const unwrapParentheses = (node) => {
687
+ let inner = node;
688
+ while (inner.type === 'ParenthesizedExpression') {
689
+ inner = inner.expression;
690
+ }
691
+ return inner;
692
+ };
678
693
  /**
679
694
  * Retrieves the key-value pair from an object based on the provided key.
680
695
  * @param obj - The object to search for the key-value pair.
@@ -1035,10 +1050,22 @@ class EvalContext {
1035
1050
  return this.scopeHolding(key) !== undefined;
1036
1051
  }
1037
1052
  /**
1038
- * Retrieves the `this` value of the specified key from the evaluation context.
1039
- * The value is searched in the original context, prior scopes, and lookup functions.
1053
+ * Retrieves the `this` value a call of the specified key receives through
1054
+ * `this.key()`.
1055
+ *
1056
+ * - A key the original context holds: the original context.
1057
+ * - A key a prior scope resolves: that scope's `thisArg`, or undefined when
1058
+ * it sets none. The first scope that resolves the key answers, as in
1059
+ * {@link get}.
1060
+ * - A key only a lookup resolves, or none: undefined. A lookup is a resolver,
1061
+ * not an object that holds the key.
1062
+ *
1063
+ * Undefined means "no receiver of its own", and the member visitor then falls
1064
+ * back to the object it was evaluating. Up to 0.6.x the prior-scope step
1065
+ * re-tested the original context and could never answer, and the lookup step
1066
+ * returned the lookup function itself (`docs/backlog-retired.md` A7).
1040
1067
  * @param key - The key to retrieve the value for.
1041
- * @returns The `this` value associated with the key, or undefined if not found.
1068
+ * @returns The `this` value associated with the key, or undefined.
1042
1069
  */
1043
1070
  getThis(key) {
1044
1071
  if (this._original) {
@@ -1048,15 +1075,8 @@ class EvalContext {
1048
1075
  }
1049
1076
  }
1050
1077
  for (const scope of this._priorScopes) {
1051
- const value = getContextValue(this._original, key);
1052
- if (value !== undefined) {
1053
- return scope;
1054
- }
1055
- }
1056
- for (const lookup of this._lookups) {
1057
- const value = lookup(key, this, this._options);
1058
- if (value !== undefined) {
1059
- return lookup;
1078
+ if (scope.get(key) !== undefined) {
1079
+ return scope.options.thisArg;
1060
1080
  }
1061
1081
  }
1062
1082
  return undefined;
@@ -1746,10 +1766,12 @@ class EvalHooks {
1746
1766
  * reaching the scan.
1747
1767
  *
1748
1768
  * Popping positionally instead would be correct only if every visitor
1749
- * bracketed its body exactly. `await-expression.ts` does not - it catches a
1750
- * child's synchronous throw and continues to its own `afterVisitor` - so a
1751
- * positional pop closes the child's frame under the parent's name, drops the
1752
- * child's `after` entirely, and leaks one frame onto the state for good.
1769
+ * bracketed its body exactly. Up to 0.6.x `await-expression.ts` did not - it
1770
+ * caught a child's synchronous throw and continued to its own
1771
+ * `afterVisitor` - so a positional pop closed the child's frame under the
1772
+ * parent's name, dropped the child's `after` entirely, and leaked one frame
1773
+ * onto the state for good. Since 0.7.0 no built-in visitor does that, and the
1774
+ * identity match stays as the guard against the next one.
1753
1775
  *
1754
1776
  * The synthesised events carry no `value` (the node never pushed one) and no
1755
1777
  * `error` (nothing threw; the frames are being closed because an enclosing
@@ -3421,7 +3443,13 @@ const isFunctionSafe = (fn, fnName) => {
3421
3443
  return true;
3422
3444
  };
3423
3445
  /**
3424
- * Safely calls a function with proper error handling and security checks
3446
+ * Calls a function after the security checks.
3447
+ *
3448
+ * Whatever the callee throws leaves the call as thrown - class, `cause` and
3449
+ * properties intact - so a consumer can select it by type. Up to 0.6.x it was
3450
+ * re-raised as a new `Error` with a fixed prefix on its message, which no
3451
+ * caller could route around, since the call is inside the walk
3452
+ * (`docs/backlog-retired.md` A6).
3425
3453
  */
3426
3454
  const safeCall = (caller, thisArg, args, optional = false, fnName) => {
3427
3455
  if (!caller) {
@@ -3436,15 +3464,36 @@ const safeCall = (caller, thisArg, args, optional = false, fnName) => {
3436
3464
  if (!isFunctionSafe(caller, fnName)) {
3437
3465
  throw new Error(`Function call blocked for security reasons: ${fnName || 'anonymous'}`);
3438
3466
  }
3439
- try {
3440
- return caller.apply(thisArg, args);
3467
+ return caller.apply(thisArg, args);
3468
+ };
3469
+ /**
3470
+ * The receiver for a method called on `object`: a prior scope's `thisArg` when
3471
+ * `object` is that scope's own object, `object` otherwise.
3472
+ *
3473
+ * `ns.fn()` reaches `fn` through the namespace, which evaluates to the scope's
3474
+ * object and has to keep doing so - `ns` alone, or `ns === x`, must not see
3475
+ * `thisArg`. So the substitution is made here, at the call, and nowhere
3476
+ * earlier: `evaluateMember`'s first slot is also the target of `ns.x = v`, and
3477
+ * a write belongs on the scope's object. Matched by identity, so it follows the
3478
+ * object rather than the name it was reached by; the first scope holding the
3479
+ * object answers, as in `EvalContext.get`. Up to 0.6.x `thisArg` was never
3480
+ * applied (`docs/backlog-retired.md` A7).
3481
+ *
3482
+ * `this.fn()` does not need this: `EvalContext.getThis` answers it.
3483
+ *
3484
+ * A call with no prior scopes pays one length check.
3485
+ */
3486
+ const scopeReceiver = (st, object) => {
3487
+ const priorScopes = st.context?.priorScopes;
3488
+ if (!priorScopes?.length) {
3489
+ return object;
3441
3490
  }
3442
- catch (error) {
3443
- if (error instanceof Error) {
3444
- throw new Error(`Function call error: ${error.message}`);
3491
+ for (const scope of priorScopes) {
3492
+ if (scope.context === object) {
3493
+ return scope.options.thisArg ?? object;
3445
3494
  }
3446
- throw error;
3447
3495
  }
3496
+ return object;
3448
3497
  };
3449
3498
  /**
3450
3499
  * Enhanced call expression visitor with security checks
@@ -3455,7 +3504,7 @@ const callExpressionVisitor = (node, st, callback) => {
3455
3504
  if (node.callee.type === 'MemberExpression') {
3456
3505
  const [object, propertyName, fn] = evaluateMember(node.callee, st, callback);
3457
3506
  const functionName = typeof propertyName === 'string' ? propertyName : undefined;
3458
- const value = safeCall(fn, object, args, node.callee.optional, functionName);
3507
+ const value = safeCall(fn, scopeReceiver(st, object), args, node.callee.optional, functionName);
3459
3508
  pushVisitorResult(node, st, value);
3460
3509
  }
3461
3510
  else {
@@ -3495,7 +3544,6 @@ const importExpressionVisitor = (node, st) => {
3495
3544
  beforeVisitor(node, st);
3496
3545
  // Block all dynamic imports for security reasons
3497
3546
  throw new Error('Function call blocked for security reasons: import');
3498
- afterVisitor(node, st);
3499
3547
  };
3500
3548
 
3501
3549
  // Default timeout for await expressions (30 seconds)
@@ -3521,42 +3569,36 @@ const ensurePromise = (value) => {
3521
3569
  };
3522
3570
  const awaitVisitor = (node, st, callback) => {
3523
3571
  beforeVisitor(node, st);
3524
- const promise = new Promise((resolve, reject) => {
3525
- try {
3526
- callback(node.argument, st);
3527
- const value = popVisitorResult(node, st);
3528
- // Convert value to promise if it's not already one
3529
- const valuePromise = ensurePromise(value);
3530
- // Get timeout from context or use default
3531
- const contextObj = st.context?.original;
3532
- const timeout = (contextObj && typeof contextObj['__awaitTimeout'] === 'number'
3533
- ? contextObj['__awaitTimeout']
3534
- : DEFAULT_AWAIT_TIMEOUT);
3535
- // Race between the actual promise and timeout
3536
- Promise.race([
3537
- valuePromise,
3538
- createTimeoutPromise(timeout)
3539
- ])
3540
- .then(resolve)
3541
- .catch((error) => {
3542
- // Enhance error information with context
3543
- const enhancedError = error instanceof Error
3544
- ? error
3545
- : new Error(`Await expression failed: ${String(error)}`);
3546
- // Add source location information if available
3547
- if (node.start !== undefined && node.end !== undefined) {
3548
- enhancedError.message += ` at position ${node.start}-${node.end}`;
3549
- }
3550
- reject(enhancedError);
3551
- });
3552
- }
3553
- catch (synchronousError) {
3554
- // Handle synchronous errors immediately
3555
- const enhancedError = synchronousError instanceof Error
3556
- ? synchronousError
3557
- : new Error(`Await expression failed synchronously: ${String(synchronousError)}`);
3558
- reject(enhancedError);
3559
- }
3572
+ // Outside any `Promise` executor, and uncaught here, as in every other
3573
+ // visitor: a synchronous throw from the operand propagates synchronously, and
3574
+ // `evaluate`'s `catch` unwinds the open nodes. Inside an executor it became a
3575
+ // rejected promise, which the sync entry points returned instead of throwing
3576
+ // while the walk carried on with the operand still open
3577
+ // (`docs/backlog-retired.md` A1).
3578
+ callback(node.argument, st);
3579
+ const value = popVisitorResult(node, st);
3580
+ // Convert value to promise if it's not already one
3581
+ const valuePromise = ensurePromise(value);
3582
+ // Get timeout from context or use default
3583
+ const contextObj = st.context?.original;
3584
+ const timeout = (contextObj && typeof contextObj['__awaitTimeout'] === 'number'
3585
+ ? contextObj['__awaitTimeout']
3586
+ : DEFAULT_AWAIT_TIMEOUT);
3587
+ // Race between the actual promise and timeout
3588
+ const promise = Promise.race([
3589
+ valuePromise,
3590
+ createTimeoutPromise(timeout)
3591
+ ])
3592
+ .catch((error) => {
3593
+ // Enhance error information with context
3594
+ const enhancedError = error instanceof Error
3595
+ ? error
3596
+ : new Error(`Await expression failed: ${String(error)}`);
3597
+ // Add source location information if available
3598
+ if (node.start !== undefined && node.end !== undefined) {
3599
+ enhancedError.message += ` at position ${node.start}-${node.end}`;
3600
+ }
3601
+ throw enhancedError;
3560
3602
  });
3561
3603
  pushVisitorResult(node, st, promise);
3562
3604
  afterVisitor(node, st);
@@ -3693,7 +3735,11 @@ const isConstructorSafe = (constructor, constructorName) => {
3693
3735
  return true;
3694
3736
  };
3695
3737
  /**
3696
- * Safely creates a new instance with proper security checks
3738
+ * Creates a new instance after the security checks.
3739
+ *
3740
+ * Whatever the constructor throws leaves as thrown, as in `safeCall`. Up to
3741
+ * 0.6.x it was re-raised as a new `Error` with a fixed prefix on its message
3742
+ * (`docs/backlog-retired.md` A6).
3697
3743
  */
3698
3744
  const safeNew = (constructor, args, constructorName) => {
3699
3745
  if (!constructor) {
@@ -3705,15 +3751,7 @@ const safeNew = (constructor, args, constructorName) => {
3705
3751
  if (!isConstructorSafe(constructor, constructorName)) {
3706
3752
  throw new Error(`Constructor blocked for security reasons: ${constructorName || 'anonymous'}`);
3707
3753
  }
3708
- try {
3709
- return Reflect.construct(constructor, args);
3710
- }
3711
- catch (error) {
3712
- if (error instanceof Error) {
3713
- throw new Error(`Constructor error: ${error.message}`);
3714
- }
3715
- throw error;
3716
- }
3754
+ return Reflect.construct(constructor, args);
3717
3755
  };
3718
3756
  const newExpressionVisitor = (node, st, callback) => {
3719
3757
  beforeVisitor(node, st);
@@ -4303,6 +4341,18 @@ const assignmentOperators = {
4303
4341
  };
4304
4342
  const assignmentExpressionVisitor = (node, st, callback) => {
4305
4343
  beforeVisitor(node, st);
4344
+ // `(a) = 1` under `preserveParens` arrives wrapped (`docs/backlog-retired.md`
4345
+ // A2). Any target other than an identifier or a member - destructuring,
4346
+ // `[a, b] = arr` and `({m} = o)` - used to fall out of the chain below having
4347
+ // pushed nothing, silently changing nothing. It is rejected here, above the
4348
+ // operands rather than as the chain's final `else`, so that neither side is
4349
+ // evaluated for an assignment that cannot happen: a right-hand side with an
4350
+ // effect would otherwise run first. Pushes nothing: `evaluate`'s `catch`
4351
+ // closes the open nodes.
4352
+ const target = unwrapParentheses(node.left);
4353
+ if (target.type !== 'Identifier' && target.type !== 'MemberExpression') {
4354
+ throw new Error(`Unsupported assignment target: ${target.type}`);
4355
+ }
4306
4356
  callback(node.left, st);
4307
4357
  const left = popVisitorResult(node, st);
4308
4358
  callback(node.right, st);
@@ -4314,21 +4364,21 @@ const assignmentExpressionVisitor = (node, st, callback) => {
4314
4364
  else if (!st.context) {
4315
4365
  throw new Error(`Context is not set.`);
4316
4366
  }
4317
- else if (node.left.type === 'Identifier') {
4367
+ else if (target.type === 'Identifier') {
4318
4368
  const key = st.options?.caseInsensitive
4319
- ? st.context.getKey(node.left.name)
4320
- : node.left.name;
4369
+ ? st.context.getKey(target.name)
4370
+ : target.name;
4321
4371
  const value = func(left, right);
4322
4372
  // Scope first, the caller's object second. Before Phase 2 this was
4323
4373
  // `st.context.set(key, value)`, which consults no scope at all - so
4324
4374
  // `(x => (x = 99))(1)` wrote `99` into the caller's own object and left the
4325
4375
  // arrow's parameter untouched. See `assignToBinding` for why the fallback
4326
4376
  // to `set` is load-bearing rather than tidy.
4327
- assignToBinding(st, key, value, node.left.name);
4377
+ assignToBinding(st, key, value, target.name);
4328
4378
  pushVisitorResult(node, st, value);
4329
4379
  }
4330
- else if (node.left.type === 'MemberExpression') {
4331
- const [object, key,] = evaluateMember(node.left, st, callback);
4380
+ else if (target.type === 'MemberExpression') {
4381
+ const [object, key,] = evaluateMember(target, st, callback);
4332
4382
  const value = func(left, right);
4333
4383
  // Use safe property assignment to prevent prototype pollution
4334
4384
  safeSetProperty(object, key, value);
@@ -4343,29 +4393,37 @@ const updateOperators = {
4343
4393
  };
4344
4394
  const updateExpressionVisitor = (node, st, callback) => {
4345
4395
  beforeVisitor(node, st);
4396
+ // `(a)++` under `preserveParens` arrives wrapped (`docs/backlog-retired.md` A2).
4397
+ const target = unwrapParentheses(node.argument);
4346
4398
  if (!st.context) {
4347
4399
  throw new Error(`Context is not set.`);
4348
4400
  }
4349
- else if (node.argument.type === 'Identifier') {
4401
+ else if (target.type === 'Identifier') {
4350
4402
  const key = st.options?.caseInsensitive
4351
- ? st.context.getKey(node.argument.name)
4352
- : node.argument.name;
4403
+ ? st.context.getKey(target.name)
4404
+ : target.name;
4353
4405
  const value = st.context?.get(key);
4354
4406
  const newValue = updateOperators[node.operator](value);
4355
4407
  // The same redirection as `assignment-expression.ts`, and the site that
4356
4408
  // matters for `for (let i = 0; …; i++)`: without it every loop counter this
4357
4409
  // library runs would be written into the consumer's context object, and
4358
4410
  // left there.
4359
- assignToBinding(st, key, newValue, node.argument.name);
4411
+ assignToBinding(st, key, newValue, target.name);
4360
4412
  pushVisitorResult(node, st, node.prefix ? newValue : value);
4361
4413
  }
4362
- else if (node.argument.type === 'MemberExpression') {
4363
- const [object, property, value] = evaluateMember(node.argument, st, callback);
4414
+ else if (target.type === 'MemberExpression') {
4415
+ const [object, property, value] = evaluateMember(target, st, callback);
4364
4416
  const newValue = updateOperators[node.operator](value);
4365
4417
  // Use safe property assignment to prevent prototype pollution
4366
4418
  safeSetProperty(object, property, newValue);
4367
4419
  pushVisitorResult(node, st, node.prefix ? newValue : value);
4368
4420
  }
4421
+ else {
4422
+ // Without this the visitor reached `afterVisitor` having pushed nothing,
4423
+ // and every node downstream popped its neighbour's value. Pushes nothing:
4424
+ // `evaluate`'s `catch` closes the open nodes.
4425
+ throw new Error(`Unsupported update target: ${target.type}`);
4426
+ }
4369
4427
  afterVisitor(node, st);
4370
4428
  };
4371
4429
 
@@ -5370,7 +5428,6 @@ class ParserService {
5370
5428
  // Keep cache size within bounds by clearing if it gets too large
5371
5429
  if (this._cache.size > this._cache.maxCacheSize * 0.8) {
5372
5430
  this._cache.clear();
5373
- console.debug('Parser cache cleared to prevent memory leaks');
5374
5431
  }
5375
5432
  }
5376
5433
  }, 5 * 60 * 1000); // 5 minutes
@@ -5416,22 +5473,14 @@ class ParserService {
5416
5473
  throw new Error('ParserService has been destroyed and cannot be used');
5417
5474
  }
5418
5475
  if (expr) {
5419
- try {
5420
- const parserOptions = { ...this.parserOptions, ...options };
5421
- const isCache = this.parserOptions.cacheSize && this._cache;
5422
- const ast = isCache
5423
- ? this.fromCacheOrParse(expr, parserOptions)
5424
- : parse(expr, parserOptions);
5425
- return ast;
5426
- }
5427
- catch (error) {
5428
- if (error instanceof Error) {
5429
- throw new Error(error.message);
5430
- }
5431
- else {
5432
- throw error;
5433
- }
5434
- }
5476
+ // No `catch`: a syntax error leaves as acorn raised it, a `SyntaxError`
5477
+ // with `pos` and `loc` (`docs/backlog-retired.md` A5).
5478
+ const parserOptions = { ...this.parserOptions, ...options };
5479
+ const isCache = this.parserOptions.cacheSize && this._cache;
5480
+ const ast = isCache
5481
+ ? this.fromCacheOrParse(expr, parserOptions)
5482
+ : parse(expr, parserOptions);
5483
+ return ast;
5435
5484
  }
5436
5485
  return undefined;
5437
5486
  }
@@ -5448,10 +5497,10 @@ class ParserService {
5448
5497
  }
5449
5498
  return undefined;
5450
5499
  }
5451
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: ParserService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5452
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: ParserService, providedIn: 'root' }); }
5500
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: ParserService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5501
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: ParserService, providedIn: 'root' }); }
5453
5502
  }
5454
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: ParserService, decorators: [{
5503
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: ParserService, decorators: [{
5455
5504
  type: Injectable,
5456
5505
  args: [{
5457
5506
  providedIn: 'root'
@@ -5506,25 +5555,19 @@ class EvalService extends BaseEval {
5506
5555
  * @returns The result of the evaluation.
5507
5556
  */
5508
5557
  simpleEval(expression, context, options) {
5509
- try {
5510
- const ast = this.parse(expression);
5511
- // Through `createState`, which a subclass may override, rather than a
5512
- // private builder (`docs/a8/plan.md` § 2.1).
5513
- const state = this.createState(context, options);
5514
- if (state?.result && typeof expression === 'string') {
5515
- state.result.expression = expression;
5516
- }
5517
- const value = evaluate(ast, state);
5518
- return value;
5519
- }
5520
- catch (error) {
5521
- if (error instanceof Error) {
5522
- throw new Error(error.message);
5523
- }
5524
- else {
5525
- throw error;
5526
- }
5527
- }
5558
+ // No `catch`: an error leaves this method as it was thrown, class, `cause`
5559
+ // and properties intact. Each entry point here and in the other services
5560
+ // used to raise a bare `Error` carrying only the message in its place
5561
+ // (`docs/backlog-retired.md` A5).
5562
+ const ast = this.parse(expression);
5563
+ // Through `createState`, which a subclass may override, rather than a
5564
+ // private builder (`docs/a8/plan.md` § 2.1).
5565
+ const state = this.createState(context, options);
5566
+ if (state?.result && typeof expression === 'string') {
5567
+ state.result.expression = expression;
5568
+ }
5569
+ const value = evaluate(ast, state);
5570
+ return value;
5528
5571
  }
5529
5572
  /**
5530
5573
  * Evaluates an expression using the provided state.
@@ -5535,22 +5578,12 @@ class EvalService extends BaseEval {
5535
5578
  * @throws If an error occurs during evaluation.
5536
5579
  */
5537
5580
  eval(expression, state) {
5538
- try {
5539
- const ast = this.parse(expression);
5540
- if (state?.result && typeof expression === 'string') {
5541
- state.result.expression = expression;
5542
- }
5543
- const value = evaluate(ast, state);
5544
- return value;
5545
- }
5546
- catch (error) {
5547
- if (error instanceof Error) {
5548
- throw new Error(error.message);
5549
- }
5550
- else {
5551
- throw error;
5552
- }
5581
+ const ast = this.parse(expression);
5582
+ if (state?.result && typeof expression === 'string') {
5583
+ state.result.expression = expression;
5553
5584
  }
5585
+ const value = evaluate(ast, state);
5586
+ return value;
5554
5587
  }
5555
5588
  /**
5556
5589
  * Asynchronously evaluates the given expression.
@@ -5560,25 +5593,15 @@ class EvalService extends BaseEval {
5560
5593
  * @returns A promise that resolves to the result of the evaluation.
5561
5594
  */
5562
5595
  simpleEvalAsync(expression, context, options) {
5563
- try {
5564
- const ast = this.parse(expression);
5565
- // As in `simpleEval`. The pending frame holds the state for as long as
5566
- // the promise it awaits is reachable, and nothing else does.
5567
- const state = this.createState(context, options);
5568
- if (state?.result && typeof expression === 'string') {
5569
- state.result.expression = expression;
5570
- }
5571
- const promise = evaluateAsync(ast, state);
5572
- return promise;
5573
- }
5574
- catch (error) {
5575
- if (error instanceof Error) {
5576
- throw new Error(error.message);
5577
- }
5578
- else {
5579
- throw error;
5580
- }
5596
+ const ast = this.parse(expression);
5597
+ // As in `simpleEval`. The pending frame holds the state for as long as
5598
+ // the promise it awaits is reachable, and nothing else does.
5599
+ const state = this.createState(context, options);
5600
+ if (state?.result && typeof expression === 'string') {
5601
+ state.result.expression = expression;
5581
5602
  }
5603
+ const promise = evaluateAsync(ast, state);
5604
+ return promise;
5582
5605
  }
5583
5606
  /**
5584
5607
  * Asynchronously evaluates an expression using the provided state.
@@ -5589,27 +5612,17 @@ class EvalService extends BaseEval {
5589
5612
  * @throws If an error occurs during evaluation.
5590
5613
  */
5591
5614
  evalAsync(expression, state) {
5592
- try {
5593
- const ast = this.parse(expression);
5594
- if (state?.result && typeof expression === 'string') {
5595
- state.result.expression = expression;
5596
- }
5597
- const promise = evaluateAsync(ast, state);
5598
- return promise;
5599
- }
5600
- catch (error) {
5601
- if (error instanceof Error) {
5602
- throw new Error(error.message);
5603
- }
5604
- else {
5605
- throw error;
5606
- }
5615
+ const ast = this.parse(expression);
5616
+ if (state?.result && typeof expression === 'string') {
5617
+ state.result.expression = expression;
5607
5618
  }
5619
+ const promise = evaluateAsync(ast, state);
5620
+ return promise;
5608
5621
  }
5609
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: EvalService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5610
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: EvalService, providedIn: 'root' }); }
5622
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: EvalService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5623
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: EvalService, providedIn: 'root' }); }
5611
5624
  }
5612
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: EvalService, decorators: [{
5625
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: EvalService, decorators: [{
5613
5626
  type: Injectable,
5614
5627
  args: [{
5615
5628
  providedIn: 'root'
@@ -5717,47 +5730,43 @@ class CompilerService extends BaseEval {
5717
5730
  * @throws Error if there is an error during compilation.
5718
5731
  */
5719
5732
  compile(expression) {
5720
- try {
5721
- const cacheKey = this.generateCacheKey(expression);
5722
- // Check cache first
5723
- const cached = this._compilationCache.get(cacheKey);
5724
- if (cached?.sync) {
5725
- // Update access order for LRU
5726
- this.updateAccessOrder(cacheKey);
5727
- cached.accessCount++;
5728
- // Check if entry is still fresh
5729
- const age = performance.now() - cached.timestamp;
5730
- if (age < this._cacheTTL) {
5731
- return cached.sync;
5732
- }
5733
+ // No `catch`, here or in the five methods below: an error leaves as it was
5734
+ // thrown. Each used to raise a bare `Error` carrying only the message in its
5735
+ // place, or a fixed message for a thrown non-`Error`
5736
+ // (`docs/backlog-retired.md` A5).
5737
+ const cacheKey = this.generateCacheKey(expression);
5738
+ // Check cache first
5739
+ const cached = this._compilationCache.get(cacheKey);
5740
+ if (cached?.sync) {
5741
+ // Update access order for LRU
5742
+ this.updateAccessOrder(cacheKey);
5743
+ cached.accessCount++;
5744
+ // Check if entry is still fresh
5745
+ const age = performance.now() - cached.timestamp;
5746
+ if (age < this._cacheTTL) {
5747
+ return cached.sync;
5733
5748
  }
5734
- // Compile fresh
5735
- const ast = this.parse(expression);
5736
- const fn = compile(ast);
5737
- if (fn) {
5738
- // Cache the result
5739
- const existingCache = this._compilationCache.get(cacheKey) || {
5740
- timestamp: performance.now(),
5741
- accessCount: 0
5742
- };
5743
- existingCache.sync = fn;
5744
- existingCache.timestamp = performance.now();
5745
- existingCache.accessCount++;
5746
- this._compilationCache.set(cacheKey, existingCache);
5747
- this.updateAccessOrder(cacheKey);
5748
- // Cleanup if cache is getting too large
5749
- if (this._compilationCache.size > this._maxCacheSize * 1.2) {
5750
- this.cleanupCache();
5751
- }
5752
- }
5753
- return fn;
5754
5749
  }
5755
- catch (error) {
5756
- if (error instanceof Error) {
5757
- throw new Error(error.message);
5750
+ // Compile fresh
5751
+ const ast = this.parse(expression);
5752
+ const fn = compile(ast);
5753
+ if (fn) {
5754
+ // Cache the result
5755
+ const existingCache = this._compilationCache.get(cacheKey) || {
5756
+ timestamp: performance.now(),
5757
+ accessCount: 0
5758
+ };
5759
+ existingCache.sync = fn;
5760
+ existingCache.timestamp = performance.now();
5761
+ existingCache.accessCount++;
5762
+ this._compilationCache.set(cacheKey, existingCache);
5763
+ this.updateAccessOrder(cacheKey);
5764
+ // Cleanup if cache is getting too large
5765
+ if (this._compilationCache.size > this._maxCacheSize * 1.2) {
5766
+ this.cleanupCache();
5758
5767
  }
5759
- throw new Error('error in compile');
5760
5768
  }
5769
+ return fn;
5761
5770
  }
5762
5771
  /**
5763
5772
  * Calls the given state callback function with the specified context and options.
@@ -5769,19 +5778,9 @@ class CompilerService extends BaseEval {
5769
5778
  */
5770
5779
  simpleCall(fn, context, options) {
5771
5780
  if (fn) {
5772
- try {
5773
- const state = this.createState(context, options);
5774
- const value = call(fn, state);
5775
- return value;
5776
- }
5777
- catch (error) {
5778
- if (error instanceof Error) {
5779
- throw new Error(error.message);
5780
- }
5781
- else {
5782
- throw new Error('call');
5783
- }
5784
- }
5781
+ const state = this.createState(context, options);
5782
+ const value = call(fn, state);
5783
+ return value;
5785
5784
  }
5786
5785
  return undefined;
5787
5786
  }
@@ -5795,18 +5794,8 @@ class CompilerService extends BaseEval {
5795
5794
  */
5796
5795
  call(fn, state) {
5797
5796
  if (fn) {
5798
- try {
5799
- const value = call(fn, state);
5800
- return value;
5801
- }
5802
- catch (error) {
5803
- if (error instanceof Error) {
5804
- throw new Error(error.message);
5805
- }
5806
- else {
5807
- throw new Error('call');
5808
- }
5809
- }
5797
+ const value = call(fn, state);
5798
+ return value;
5810
5799
  }
5811
5800
  return undefined;
5812
5801
  }
@@ -5817,47 +5806,39 @@ class CompilerService extends BaseEval {
5817
5806
  * @throws Error if there is an error during compilation.
5818
5807
  */
5819
5808
  compileAsync(expression) {
5820
- try {
5821
- const cacheKey = this.generateCacheKey(expression);
5822
- // Check cache first
5823
- const cached = this._compilationCache.get(cacheKey);
5824
- if (cached?.async) {
5825
- // Update access order for LRU
5826
- this.updateAccessOrder(cacheKey);
5827
- cached.accessCount++;
5828
- // Check if entry is still fresh
5829
- const age = performance.now() - cached.timestamp;
5830
- if (age < this._cacheTTL) {
5831
- return cached.async;
5832
- }
5833
- }
5834
- // Compile fresh
5835
- const ast = this.parse(expression);
5836
- const fn = compileAsync(ast);
5837
- if (fn) {
5838
- // Cache the result
5839
- const existingCache = this._compilationCache.get(cacheKey) || {
5840
- timestamp: performance.now(),
5841
- accessCount: 0
5842
- };
5843
- existingCache.async = fn;
5844
- existingCache.timestamp = performance.now();
5845
- existingCache.accessCount++;
5846
- this._compilationCache.set(cacheKey, existingCache);
5847
- this.updateAccessOrder(cacheKey);
5848
- // Cleanup if cache is getting too large
5849
- if (this._compilationCache.size > this._maxCacheSize * 1.2) {
5850
- this.cleanupCache();
5851
- }
5809
+ const cacheKey = this.generateCacheKey(expression);
5810
+ // Check cache first
5811
+ const cached = this._compilationCache.get(cacheKey);
5812
+ if (cached?.async) {
5813
+ // Update access order for LRU
5814
+ this.updateAccessOrder(cacheKey);
5815
+ cached.accessCount++;
5816
+ // Check if entry is still fresh
5817
+ const age = performance.now() - cached.timestamp;
5818
+ if (age < this._cacheTTL) {
5819
+ return cached.async;
5852
5820
  }
5853
- return fn;
5854
5821
  }
5855
- catch (error) {
5856
- if (error instanceof Error) {
5857
- throw new Error(error.message);
5822
+ // Compile fresh
5823
+ const ast = this.parse(expression);
5824
+ const fn = compileAsync(ast);
5825
+ if (fn) {
5826
+ // Cache the result
5827
+ const existingCache = this._compilationCache.get(cacheKey) || {
5828
+ timestamp: performance.now(),
5829
+ accessCount: 0
5830
+ };
5831
+ existingCache.async = fn;
5832
+ existingCache.timestamp = performance.now();
5833
+ existingCache.accessCount++;
5834
+ this._compilationCache.set(cacheKey, existingCache);
5835
+ this.updateAccessOrder(cacheKey);
5836
+ // Cleanup if cache is getting too large
5837
+ if (this._compilationCache.size > this._maxCacheSize * 1.2) {
5838
+ this.cleanupCache();
5858
5839
  }
5859
- throw new Error('error in compileAsync');
5860
5840
  }
5841
+ return fn;
5861
5842
  }
5862
5843
  /**
5863
5844
  * Calls the given asynchronous state callback function with the specified context and options.
@@ -5869,18 +5850,10 @@ class CompilerService extends BaseEval {
5869
5850
  */
5870
5851
  async simpleCallAsync(fn, context, options) {
5871
5852
  if (fn) {
5872
- try {
5873
- const state = this.createState(context, options);
5874
- const promise = callAsync(fn, state);
5875
- const value = await promise;
5876
- return value;
5877
- }
5878
- catch (error) {
5879
- if (error instanceof Error) {
5880
- throw new Error(error.message);
5881
- }
5882
- throw new Error('error in callAsync');
5883
- }
5853
+ const state = this.createState(context, options);
5854
+ const promise = callAsync(fn, state);
5855
+ const value = await promise;
5856
+ return value;
5884
5857
  }
5885
5858
  return undefined;
5886
5859
  }
@@ -5894,24 +5867,16 @@ class CompilerService extends BaseEval {
5894
5867
  */
5895
5868
  async callAsync(fn, state) {
5896
5869
  if (fn) {
5897
- try {
5898
- const promise = callAsync(fn, state);
5899
- const value = await promise;
5900
- return value;
5901
- }
5902
- catch (error) {
5903
- if (error instanceof Error) {
5904
- throw new Error(error.message);
5905
- }
5906
- throw new Error('error in callAsync');
5907
- }
5870
+ const promise = callAsync(fn, state);
5871
+ const value = await promise;
5872
+ return value;
5908
5873
  }
5909
5874
  return undefined;
5910
5875
  }
5911
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: CompilerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5912
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: CompilerService, providedIn: 'root' }); }
5876
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: CompilerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5877
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: CompilerService, providedIn: 'root' }); }
5913
5878
  }
5914
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: CompilerService, decorators: [{
5879
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: CompilerService, decorators: [{
5915
5880
  type: Injectable,
5916
5881
  args: [{
5917
5882
  providedIn: 'root'
@@ -5942,24 +5907,16 @@ class DiscoveryService extends BaseEval {
5942
5907
  * @throws If an error occurs during the search process.
5943
5908
  */
5944
5909
  extract(expression, searchType) {
5945
- try {
5946
- const ast = this.parse(expression);
5947
- const value = extract(ast, searchType);
5948
- return value;
5949
- }
5950
- catch (error) {
5951
- if (error instanceof Error) {
5952
- throw new Error(error.message);
5953
- }
5954
- else {
5955
- throw error;
5956
- }
5957
- }
5910
+ // No `catch`: a parse error leaves as acorn raised it, type and `pos` intact
5911
+ // (`docs/backlog-retired.md` A5).
5912
+ const ast = this.parse(expression);
5913
+ const value = extract(ast, searchType);
5914
+ return value;
5958
5915
  }
5959
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: DiscoveryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5960
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: DiscoveryService, providedIn: 'root' }); }
5916
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: DiscoveryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5917
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: DiscoveryService, providedIn: 'root' }); }
5961
5918
  }
5962
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: DiscoveryService, decorators: [{
5919
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: DiscoveryService, decorators: [{
5963
5920
  type: Injectable,
5964
5921
  args: [{
5965
5922
  providedIn: 'root'