@zvenigora/ng-eval-core 0.6.1 → 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 {
@@ -3520,42 +3569,36 @@ const ensurePromise = (value) => {
3520
3569
  };
3521
3570
  const awaitVisitor = (node, st, callback) => {
3522
3571
  beforeVisitor(node, st);
3523
- const promise = new Promise((resolve, reject) => {
3524
- try {
3525
- callback(node.argument, st);
3526
- const value = popVisitorResult(node, st);
3527
- // Convert value to promise if it's not already one
3528
- const valuePromise = ensurePromise(value);
3529
- // Get timeout from context or use default
3530
- const contextObj = st.context?.original;
3531
- const timeout = (contextObj && typeof contextObj['__awaitTimeout'] === 'number'
3532
- ? contextObj['__awaitTimeout']
3533
- : DEFAULT_AWAIT_TIMEOUT);
3534
- // Race between the actual promise and timeout
3535
- Promise.race([
3536
- valuePromise,
3537
- createTimeoutPromise(timeout)
3538
- ])
3539
- .then(resolve)
3540
- .catch((error) => {
3541
- // Enhance error information with context
3542
- const enhancedError = error instanceof Error
3543
- ? error
3544
- : new Error(`Await expression failed: ${String(error)}`);
3545
- // Add source location information if available
3546
- if (node.start !== undefined && node.end !== undefined) {
3547
- enhancedError.message += ` at position ${node.start}-${node.end}`;
3548
- }
3549
- reject(enhancedError);
3550
- });
3551
- }
3552
- catch (synchronousError) {
3553
- // Handle synchronous errors immediately
3554
- const enhancedError = synchronousError instanceof Error
3555
- ? synchronousError
3556
- : new Error(`Await expression failed synchronously: ${String(synchronousError)}`);
3557
- reject(enhancedError);
3558
- }
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;
3559
3602
  });
3560
3603
  pushVisitorResult(node, st, promise);
3561
3604
  afterVisitor(node, st);
@@ -3692,7 +3735,11 @@ const isConstructorSafe = (constructor, constructorName) => {
3692
3735
  return true;
3693
3736
  };
3694
3737
  /**
3695
- * 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).
3696
3743
  */
3697
3744
  const safeNew = (constructor, args, constructorName) => {
3698
3745
  if (!constructor) {
@@ -3704,15 +3751,7 @@ const safeNew = (constructor, args, constructorName) => {
3704
3751
  if (!isConstructorSafe(constructor, constructorName)) {
3705
3752
  throw new Error(`Constructor blocked for security reasons: ${constructorName || 'anonymous'}`);
3706
3753
  }
3707
- try {
3708
- return Reflect.construct(constructor, args);
3709
- }
3710
- catch (error) {
3711
- if (error instanceof Error) {
3712
- throw new Error(`Constructor error: ${error.message}`);
3713
- }
3714
- throw error;
3715
- }
3754
+ return Reflect.construct(constructor, args);
3716
3755
  };
3717
3756
  const newExpressionVisitor = (node, st, callback) => {
3718
3757
  beforeVisitor(node, st);
@@ -4302,6 +4341,18 @@ const assignmentOperators = {
4302
4341
  };
4303
4342
  const assignmentExpressionVisitor = (node, st, callback) => {
4304
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
+ }
4305
4356
  callback(node.left, st);
4306
4357
  const left = popVisitorResult(node, st);
4307
4358
  callback(node.right, st);
@@ -4313,21 +4364,21 @@ const assignmentExpressionVisitor = (node, st, callback) => {
4313
4364
  else if (!st.context) {
4314
4365
  throw new Error(`Context is not set.`);
4315
4366
  }
4316
- else if (node.left.type === 'Identifier') {
4367
+ else if (target.type === 'Identifier') {
4317
4368
  const key = st.options?.caseInsensitive
4318
- ? st.context.getKey(node.left.name)
4319
- : node.left.name;
4369
+ ? st.context.getKey(target.name)
4370
+ : target.name;
4320
4371
  const value = func(left, right);
4321
4372
  // Scope first, the caller's object second. Before Phase 2 this was
4322
4373
  // `st.context.set(key, value)`, which consults no scope at all - so
4323
4374
  // `(x => (x = 99))(1)` wrote `99` into the caller's own object and left the
4324
4375
  // arrow's parameter untouched. See `assignToBinding` for why the fallback
4325
4376
  // to `set` is load-bearing rather than tidy.
4326
- assignToBinding(st, key, value, node.left.name);
4377
+ assignToBinding(st, key, value, target.name);
4327
4378
  pushVisitorResult(node, st, value);
4328
4379
  }
4329
- else if (node.left.type === 'MemberExpression') {
4330
- const [object, key,] = evaluateMember(node.left, st, callback);
4380
+ else if (target.type === 'MemberExpression') {
4381
+ const [object, key,] = evaluateMember(target, st, callback);
4331
4382
  const value = func(left, right);
4332
4383
  // Use safe property assignment to prevent prototype pollution
4333
4384
  safeSetProperty(object, key, value);
@@ -4342,29 +4393,37 @@ const updateOperators = {
4342
4393
  };
4343
4394
  const updateExpressionVisitor = (node, st, callback) => {
4344
4395
  beforeVisitor(node, st);
4396
+ // `(a)++` under `preserveParens` arrives wrapped (`docs/backlog-retired.md` A2).
4397
+ const target = unwrapParentheses(node.argument);
4345
4398
  if (!st.context) {
4346
4399
  throw new Error(`Context is not set.`);
4347
4400
  }
4348
- else if (node.argument.type === 'Identifier') {
4401
+ else if (target.type === 'Identifier') {
4349
4402
  const key = st.options?.caseInsensitive
4350
- ? st.context.getKey(node.argument.name)
4351
- : node.argument.name;
4403
+ ? st.context.getKey(target.name)
4404
+ : target.name;
4352
4405
  const value = st.context?.get(key);
4353
4406
  const newValue = updateOperators[node.operator](value);
4354
4407
  // The same redirection as `assignment-expression.ts`, and the site that
4355
4408
  // matters for `for (let i = 0; …; i++)`: without it every loop counter this
4356
4409
  // library runs would be written into the consumer's context object, and
4357
4410
  // left there.
4358
- assignToBinding(st, key, newValue, node.argument.name);
4411
+ assignToBinding(st, key, newValue, target.name);
4359
4412
  pushVisitorResult(node, st, node.prefix ? newValue : value);
4360
4413
  }
4361
- else if (node.argument.type === 'MemberExpression') {
4362
- const [object, property, value] = evaluateMember(node.argument, st, callback);
4414
+ else if (target.type === 'MemberExpression') {
4415
+ const [object, property, value] = evaluateMember(target, st, callback);
4363
4416
  const newValue = updateOperators[node.operator](value);
4364
4417
  // Use safe property assignment to prevent prototype pollution
4365
4418
  safeSetProperty(object, property, newValue);
4366
4419
  pushVisitorResult(node, st, node.prefix ? newValue : value);
4367
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
+ }
4368
4427
  afterVisitor(node, st);
4369
4428
  };
4370
4429
 
@@ -5414,22 +5473,14 @@ class ParserService {
5414
5473
  throw new Error('ParserService has been destroyed and cannot be used');
5415
5474
  }
5416
5475
  if (expr) {
5417
- try {
5418
- const parserOptions = { ...this.parserOptions, ...options };
5419
- const isCache = this.parserOptions.cacheSize && this._cache;
5420
- const ast = isCache
5421
- ? this.fromCacheOrParse(expr, parserOptions)
5422
- : parse(expr, parserOptions);
5423
- return ast;
5424
- }
5425
- catch (error) {
5426
- if (error instanceof Error) {
5427
- throw new Error(error.message);
5428
- }
5429
- else {
5430
- throw error;
5431
- }
5432
- }
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;
5433
5484
  }
5434
5485
  return undefined;
5435
5486
  }
@@ -5446,10 +5497,10 @@ class ParserService {
5446
5497
  }
5447
5498
  return undefined;
5448
5499
  }
5449
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.8", ngImport: i0, type: ParserService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5450
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.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' }); }
5451
5502
  }
5452
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.8", ngImport: i0, type: ParserService, decorators: [{
5503
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: ParserService, decorators: [{
5453
5504
  type: Injectable,
5454
5505
  args: [{
5455
5506
  providedIn: 'root'
@@ -5504,25 +5555,19 @@ class EvalService extends BaseEval {
5504
5555
  * @returns The result of the evaluation.
5505
5556
  */
5506
5557
  simpleEval(expression, context, options) {
5507
- try {
5508
- const ast = this.parse(expression);
5509
- // Through `createState`, which a subclass may override, rather than a
5510
- // private builder (`docs/a8/plan.md` § 2.1).
5511
- const state = this.createState(context, options);
5512
- if (state?.result && typeof expression === 'string') {
5513
- state.result.expression = expression;
5514
- }
5515
- const value = evaluate(ast, state);
5516
- return value;
5517
- }
5518
- catch (error) {
5519
- if (error instanceof Error) {
5520
- throw new Error(error.message);
5521
- }
5522
- else {
5523
- throw error;
5524
- }
5525
- }
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;
5526
5571
  }
5527
5572
  /**
5528
5573
  * Evaluates an expression using the provided state.
@@ -5533,22 +5578,12 @@ class EvalService extends BaseEval {
5533
5578
  * @throws If an error occurs during evaluation.
5534
5579
  */
5535
5580
  eval(expression, state) {
5536
- try {
5537
- const ast = this.parse(expression);
5538
- if (state?.result && typeof expression === 'string') {
5539
- state.result.expression = expression;
5540
- }
5541
- const value = evaluate(ast, state);
5542
- return value;
5543
- }
5544
- catch (error) {
5545
- if (error instanceof Error) {
5546
- throw new Error(error.message);
5547
- }
5548
- else {
5549
- throw error;
5550
- }
5581
+ const ast = this.parse(expression);
5582
+ if (state?.result && typeof expression === 'string') {
5583
+ state.result.expression = expression;
5551
5584
  }
5585
+ const value = evaluate(ast, state);
5586
+ return value;
5552
5587
  }
5553
5588
  /**
5554
5589
  * Asynchronously evaluates the given expression.
@@ -5558,25 +5593,15 @@ class EvalService extends BaseEval {
5558
5593
  * @returns A promise that resolves to the result of the evaluation.
5559
5594
  */
5560
5595
  simpleEvalAsync(expression, context, options) {
5561
- try {
5562
- const ast = this.parse(expression);
5563
- // As in `simpleEval`. The pending frame holds the state for as long as
5564
- // the promise it awaits is reachable, and nothing else does.
5565
- const state = this.createState(context, options);
5566
- if (state?.result && typeof expression === 'string') {
5567
- state.result.expression = expression;
5568
- }
5569
- const promise = evaluateAsync(ast, state);
5570
- return promise;
5571
- }
5572
- catch (error) {
5573
- if (error instanceof Error) {
5574
- throw new Error(error.message);
5575
- }
5576
- else {
5577
- throw error;
5578
- }
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;
5579
5602
  }
5603
+ const promise = evaluateAsync(ast, state);
5604
+ return promise;
5580
5605
  }
5581
5606
  /**
5582
5607
  * Asynchronously evaluates an expression using the provided state.
@@ -5587,27 +5612,17 @@ class EvalService extends BaseEval {
5587
5612
  * @throws If an error occurs during evaluation.
5588
5613
  */
5589
5614
  evalAsync(expression, state) {
5590
- try {
5591
- const ast = this.parse(expression);
5592
- if (state?.result && typeof expression === 'string') {
5593
- state.result.expression = expression;
5594
- }
5595
- const promise = evaluateAsync(ast, state);
5596
- return promise;
5597
- }
5598
- catch (error) {
5599
- if (error instanceof Error) {
5600
- throw new Error(error.message);
5601
- }
5602
- else {
5603
- throw error;
5604
- }
5615
+ const ast = this.parse(expression);
5616
+ if (state?.result && typeof expression === 'string') {
5617
+ state.result.expression = expression;
5605
5618
  }
5619
+ const promise = evaluateAsync(ast, state);
5620
+ return promise;
5606
5621
  }
5607
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.8", ngImport: i0, type: EvalService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5608
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.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' }); }
5609
5624
  }
5610
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.8", ngImport: i0, type: EvalService, decorators: [{
5625
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: EvalService, decorators: [{
5611
5626
  type: Injectable,
5612
5627
  args: [{
5613
5628
  providedIn: 'root'
@@ -5715,47 +5730,43 @@ class CompilerService extends BaseEval {
5715
5730
  * @throws Error if there is an error during compilation.
5716
5731
  */
5717
5732
  compile(expression) {
5718
- try {
5719
- const cacheKey = this.generateCacheKey(expression);
5720
- // Check cache first
5721
- const cached = this._compilationCache.get(cacheKey);
5722
- if (cached?.sync) {
5723
- // Update access order for LRU
5724
- this.updateAccessOrder(cacheKey);
5725
- cached.accessCount++;
5726
- // Check if entry is still fresh
5727
- const age = performance.now() - cached.timestamp;
5728
- if (age < this._cacheTTL) {
5729
- return cached.sync;
5730
- }
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;
5731
5748
  }
5732
- // Compile fresh
5733
- const ast = this.parse(expression);
5734
- const fn = compile(ast);
5735
- if (fn) {
5736
- // Cache the result
5737
- const existingCache = this._compilationCache.get(cacheKey) || {
5738
- timestamp: performance.now(),
5739
- accessCount: 0
5740
- };
5741
- existingCache.sync = fn;
5742
- existingCache.timestamp = performance.now();
5743
- existingCache.accessCount++;
5744
- this._compilationCache.set(cacheKey, existingCache);
5745
- this.updateAccessOrder(cacheKey);
5746
- // Cleanup if cache is getting too large
5747
- if (this._compilationCache.size > this._maxCacheSize * 1.2) {
5748
- this.cleanupCache();
5749
- }
5750
- }
5751
- return fn;
5752
5749
  }
5753
- catch (error) {
5754
- if (error instanceof Error) {
5755
- 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();
5756
5767
  }
5757
- throw new Error('error in compile');
5758
5768
  }
5769
+ return fn;
5759
5770
  }
5760
5771
  /**
5761
5772
  * Calls the given state callback function with the specified context and options.
@@ -5767,19 +5778,9 @@ class CompilerService extends BaseEval {
5767
5778
  */
5768
5779
  simpleCall(fn, context, options) {
5769
5780
  if (fn) {
5770
- try {
5771
- const state = this.createState(context, options);
5772
- const value = call(fn, state);
5773
- return value;
5774
- }
5775
- catch (error) {
5776
- if (error instanceof Error) {
5777
- throw new Error(error.message);
5778
- }
5779
- else {
5780
- throw new Error('call');
5781
- }
5782
- }
5781
+ const state = this.createState(context, options);
5782
+ const value = call(fn, state);
5783
+ return value;
5783
5784
  }
5784
5785
  return undefined;
5785
5786
  }
@@ -5793,18 +5794,8 @@ class CompilerService extends BaseEval {
5793
5794
  */
5794
5795
  call(fn, state) {
5795
5796
  if (fn) {
5796
- try {
5797
- const value = call(fn, state);
5798
- return value;
5799
- }
5800
- catch (error) {
5801
- if (error instanceof Error) {
5802
- throw new Error(error.message);
5803
- }
5804
- else {
5805
- throw new Error('call');
5806
- }
5807
- }
5797
+ const value = call(fn, state);
5798
+ return value;
5808
5799
  }
5809
5800
  return undefined;
5810
5801
  }
@@ -5815,47 +5806,39 @@ class CompilerService extends BaseEval {
5815
5806
  * @throws Error if there is an error during compilation.
5816
5807
  */
5817
5808
  compileAsync(expression) {
5818
- try {
5819
- const cacheKey = this.generateCacheKey(expression);
5820
- // Check cache first
5821
- const cached = this._compilationCache.get(cacheKey);
5822
- if (cached?.async) {
5823
- // Update access order for LRU
5824
- this.updateAccessOrder(cacheKey);
5825
- cached.accessCount++;
5826
- // Check if entry is still fresh
5827
- const age = performance.now() - cached.timestamp;
5828
- if (age < this._cacheTTL) {
5829
- return cached.async;
5830
- }
5831
- }
5832
- // Compile fresh
5833
- const ast = this.parse(expression);
5834
- const fn = compileAsync(ast);
5835
- if (fn) {
5836
- // Cache the result
5837
- const existingCache = this._compilationCache.get(cacheKey) || {
5838
- timestamp: performance.now(),
5839
- accessCount: 0
5840
- };
5841
- existingCache.async = fn;
5842
- existingCache.timestamp = performance.now();
5843
- existingCache.accessCount++;
5844
- this._compilationCache.set(cacheKey, existingCache);
5845
- this.updateAccessOrder(cacheKey);
5846
- // Cleanup if cache is getting too large
5847
- if (this._compilationCache.size > this._maxCacheSize * 1.2) {
5848
- this.cleanupCache();
5849
- }
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;
5850
5820
  }
5851
- return fn;
5852
5821
  }
5853
- catch (error) {
5854
- if (error instanceof Error) {
5855
- 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();
5856
5839
  }
5857
- throw new Error('error in compileAsync');
5858
5840
  }
5841
+ return fn;
5859
5842
  }
5860
5843
  /**
5861
5844
  * Calls the given asynchronous state callback function with the specified context and options.
@@ -5867,18 +5850,10 @@ class CompilerService extends BaseEval {
5867
5850
  */
5868
5851
  async simpleCallAsync(fn, context, options) {
5869
5852
  if (fn) {
5870
- try {
5871
- const state = this.createState(context, options);
5872
- const promise = callAsync(fn, state);
5873
- const value = await promise;
5874
- return value;
5875
- }
5876
- catch (error) {
5877
- if (error instanceof Error) {
5878
- throw new Error(error.message);
5879
- }
5880
- throw new Error('error in callAsync');
5881
- }
5853
+ const state = this.createState(context, options);
5854
+ const promise = callAsync(fn, state);
5855
+ const value = await promise;
5856
+ return value;
5882
5857
  }
5883
5858
  return undefined;
5884
5859
  }
@@ -5892,24 +5867,16 @@ class CompilerService extends BaseEval {
5892
5867
  */
5893
5868
  async callAsync(fn, state) {
5894
5869
  if (fn) {
5895
- try {
5896
- const promise = callAsync(fn, state);
5897
- const value = await promise;
5898
- return value;
5899
- }
5900
- catch (error) {
5901
- if (error instanceof Error) {
5902
- throw new Error(error.message);
5903
- }
5904
- throw new Error('error in callAsync');
5905
- }
5870
+ const promise = callAsync(fn, state);
5871
+ const value = await promise;
5872
+ return value;
5906
5873
  }
5907
5874
  return undefined;
5908
5875
  }
5909
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.8", ngImport: i0, type: CompilerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5910
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.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' }); }
5911
5878
  }
5912
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.8", ngImport: i0, type: CompilerService, decorators: [{
5879
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: CompilerService, decorators: [{
5913
5880
  type: Injectable,
5914
5881
  args: [{
5915
5882
  providedIn: 'root'
@@ -5940,24 +5907,16 @@ class DiscoveryService extends BaseEval {
5940
5907
  * @throws If an error occurs during the search process.
5941
5908
  */
5942
5909
  extract(expression, searchType) {
5943
- try {
5944
- const ast = this.parse(expression);
5945
- const value = extract(ast, searchType);
5946
- return value;
5947
- }
5948
- catch (error) {
5949
- if (error instanceof Error) {
5950
- throw new Error(error.message);
5951
- }
5952
- else {
5953
- throw error;
5954
- }
5955
- }
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;
5956
5915
  }
5957
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.8", ngImport: i0, type: DiscoveryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5958
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.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' }); }
5959
5918
  }
5960
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.8", ngImport: i0, type: DiscoveryService, decorators: [{
5919
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: DiscoveryService, decorators: [{
5961
5920
  type: Injectable,
5962
5921
  args: [{
5963
5922
  providedIn: 'root'