@zvenigora/ng-eval-core 0.13.3 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -914,8 +914,11 @@ const refuseContextWrite = (target) => {
914
914
  *
915
915
  * The companion to {@link refuseContextWrite}, and the load-bearing one: the
916
916
  * context cannot be written to, and it cannot be obtained either. It is
917
- * raised from the value funnel in `visitor-result.ts`, so it covers every
918
- * value the walk pushes, whatever node pushed it.
917
+ * raised from the value funnel, `refuseFunnelledValue` in `visitor-result.ts`,
918
+ * which has two call sites: `pushVisitorResult`, so it covers every value the
919
+ * walk pushes, whatever node pushed it, and `assignment-expression.ts`, for a
920
+ * compound or logical assignment's target, which is read once and not pushed
921
+ * (`docs/backlog.md` A45, part 2).
919
922
  *
920
923
  * **It is at the funnel because a member read was not enough.** The first
921
924
  * version refused a context only as a member read's object and value, and
@@ -1276,7 +1279,6 @@ const refuseThisValue = (node) => {
1276
1279
  }
1277
1280
  };
1278
1281
 
1279
- // import { getCachedVisitorResult, setCachedVisitorResult } from './visitor-result-cache';
1280
1282
  /**
1281
1283
  * Reconstructs the dotted source path of a member chain (`a.b.c`).
1282
1284
  *
@@ -1325,16 +1327,7 @@ const readPath = (node) => {
1325
1327
  */
1326
1328
  const memberExpressionVisitor = (node, st, callback) => {
1327
1329
  beforeVisitor(node, st);
1328
- // Disable visitor result caching for now due to context sensitivity issues
1329
- // const cachedResult = getCachedVisitorResult(node, st.context);
1330
- // if (cachedResult !== undefined) {
1331
- // pushVisitorResult(node, st, cachedResult);
1332
- // afterVisitor(node, st);
1333
- // return;
1334
- // }
1335
1330
  const [, , value] = evaluateMember(node, st, callback);
1336
- // Disable visitor result caching for now
1337
- // setCachedVisitorResult(node, st.context, value);
1338
1331
  pushVisitorResult(node, st, value);
1339
1332
  afterVisitor(node, st);
1340
1333
  };
@@ -1398,7 +1391,10 @@ const evaluateMember = (node, st, callback) => {
1398
1391
  // holds with the original, which is an ordinary host object - so the fact
1399
1392
  // is carried from here, where it is known, rather than re-derived at the
1400
1393
  // call, where it is not (`docs/a35/plan.md` § 8 q7).
1401
- return [thisValue ?? object, contextKey, value, true];
1394
+ //
1395
+ // The fifth slot is the key the lookup matched, which a write reaches
1396
+ // (`docs/backlog.md` A44). Here it is the key the context resolved.
1397
+ return [thisValue ?? object, contextKey, value, true, contextKey];
1402
1398
  }
1403
1399
  else if (object instanceof EvalScope) {
1404
1400
  // A global scope reads its object as the context does, with a bare
@@ -1423,7 +1419,7 @@ const evaluateMember = (node, st, callback) => {
1423
1419
  // A namespaced or global prior scope is not the context's own chain: its
1424
1420
  // object, or the `thisArg` its host declared, is the receiver it has
1425
1421
  // always been.
1426
- return [thisValue ?? object, key, value, false];
1422
+ return [thisValue ?? object, key, value, false, key];
1427
1423
  }
1428
1424
  else {
1429
1425
  // Not the walk's own context, and not a scope. A context cannot reach
@@ -1432,8 +1428,10 @@ const evaluateMember = (node, st, callback) => {
1432
1428
  //
1433
1429
  // For regular objects, we need both case-insensitive lookup AND prototype pollution protection
1434
1430
  let value;
1435
- // The key the lookup actually matched, reported to the read hooks. The
1436
- // returned tuple keeps the original `key`; only the event is corrected.
1431
+ // The key the lookup actually matched, reported to the read hooks and
1432
+ // returned in the fifth slot, which a compound assignment and an update
1433
+ // write to (`docs/backlog.md` A44). The second slot keeps the original
1434
+ // `key`, which the call path names a function by.
1437
1435
  let resolvedKey = key;
1438
1436
  // A primitive receiver (string, number, boolean) is checked against the
1439
1437
  // primitive subset of the blocklist: `toString` and its kin are ordinary
@@ -1527,9 +1525,101 @@ const evaluateMember = (node, st, callback) => {
1527
1525
  value
1528
1526
  });
1529
1527
  }
1530
- return [object, key, value, false];
1528
+ return [object, key, value, false, resolvedKey];
1531
1529
  }
1532
1530
  };
1531
+ /**
1532
+ * An `=` target's object and key, with no value read: JavaScript's `=` does
1533
+ * not read its target (`docs/backlog.md` A45, part 2). The object, and a
1534
+ * computed key, are evaluated as {@link evaluateMember} evaluates them, once
1535
+ * and before the right side, and nothing reports a read of the target.
1536
+ *
1537
+ * The key checks the read used to make stay, and run here, before the right
1538
+ * side (`docs/a45/plan.md` D7): `safeSetProperty` refuses the same keys with
1539
+ * the same message, but only after the right side has run. A string, number or
1540
+ * boolean object gets the primitive subset's check, and any other object,
1541
+ * `null` and `undefined` included, the full blocklist.
1542
+ *
1543
+ * Under `caseInsensitive` a string key on an object is matched as the read
1544
+ * matches it, the own-key cache and then the prototype's own names, but tested
1545
+ * with `in` where the read tests `obj[key]`, so no getter is called
1546
+ * (`docs/backlog.md` A44). The match is checked against the blocklist, as the
1547
+ * read's `foundKey` is. Any other object takes the key as spelled, as on the
1548
+ * read path.
1549
+ *
1550
+ * The context branch still calls `getThis`, which reads the value it tests
1551
+ * (`docs/backlog.md` A49), and under `caseInsensitive` answers the `Registry`
1552
+ * copy (A50). An `EvalScope` is written as an object (A51).
1553
+ */
1554
+ const resolveMemberTarget = (node, st, callback) => {
1555
+ markThisPositional(node.object, !!st.options?.caseInsensitive);
1556
+ callback(node.object, st);
1557
+ const obj = popVisitorResult(node, st);
1558
+ const object = (node.optional ? (obj || {}) : obj);
1559
+ let key;
1560
+ if (!node.computed && node.property.type === 'Identifier') {
1561
+ key = node.property.name;
1562
+ }
1563
+ else if (node.property.type === 'Literal') {
1564
+ key = node.property.value;
1565
+ }
1566
+ else {
1567
+ callback(node.property, st);
1568
+ key = popVisitorResult(node, st);
1569
+ }
1570
+ if (object === st.context) {
1571
+ // As the read path's context branch, without its `get`.
1572
+ if (isDangerousProperty(key)) {
1573
+ throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
1574
+ }
1575
+ let contextKey = key;
1576
+ if (st.options?.caseInsensitive && typeof key === 'string') {
1577
+ contextKey = st.context.getKey(key);
1578
+ if (isDangerousProperty(contextKey)) {
1579
+ throw new Error(`Access to dangerous property "${String(contextKey)}" is blocked for security reasons`);
1580
+ }
1581
+ }
1582
+ return [st.context.getThis(contextKey) ?? object, contextKey];
1583
+ }
1584
+ else if (object instanceof EvalScope) {
1585
+ if (isDangerousProperty(key)) {
1586
+ throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
1587
+ }
1588
+ return [object, key];
1589
+ }
1590
+ const isPrimitive = (typeof object === 'string' || typeof object === 'number' || typeof object === 'boolean');
1591
+ if (isPrimitive ? isDangerousPrimitiveProperty(key) : isDangerousProperty(key)) {
1592
+ throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
1593
+ }
1594
+ if (st.options?.caseInsensitive && typeof key === 'string' && object && typeof object === 'object') {
1595
+ const target = object;
1596
+ let foundKey = getCachedCaseInsensitiveProperty(target, key, (a, b) => equalIgnoreCase(a, b) === true);
1597
+ if (!foundKey) {
1598
+ // As the read path's `obj[key]` test, a lookup that throws leaves the
1599
+ // key as spelled. A proxy's `has` trap is called here, which
1600
+ // JavaScript's `=` does not call.
1601
+ try {
1602
+ if (key in target) {
1603
+ foundKey = key;
1604
+ }
1605
+ else {
1606
+ const prototype = Object.getPrototypeOf(target);
1607
+ if (prototype) {
1608
+ foundKey = Object.getOwnPropertyNames(prototype).find(k => equalIgnoreCase(k, key));
1609
+ }
1610
+ }
1611
+ }
1612
+ catch {
1613
+ foundKey = undefined;
1614
+ }
1615
+ }
1616
+ if (foundKey && isDangerousProperty(foundKey)) {
1617
+ throw new Error(`Access to dangerous property "${foundKey}" is blocked for security reasons`);
1618
+ }
1619
+ return [object, foundKey || key];
1620
+ }
1621
+ return [object, key];
1622
+ };
1533
1623
 
1534
1624
  const arrayExpressionVisitor = (node, st, callback) => {
1535
1625
  beforeVisitor(node, st);
@@ -1667,10 +1757,11 @@ const contextSetInScope = (context, key, value) => methodOf(context, 'setInScope
1667
1757
  * `EvalContext.push` as the class defines it, for a context that may be
1668
1758
  * undefined.
1669
1759
  *
1670
- * The optional receiver is deliberate: every scope push in the evaluator is
1671
- * written `st.context?.push(...)`, and its pop is paired with it by a
1672
- * `finally`. Both wrappers no-op on an absent context, so a walk with no
1673
- * context pushes nothing and pops nothing, exactly as the optional chain did.
1760
+ * The optional receiver is deliberate: every scope push in the evaluator
1761
+ * calls `contextPush(st.context, ...)`, and its pop, `contextPop`, runs in the
1762
+ * `finally` of a `try` opened on the next line. Both wrappers no-op on an
1763
+ * absent context, so a walk with no context pushes nothing and pops nothing,
1764
+ * exactly as the `st.context?.push(...)` optional chain they replaced did.
1674
1765
  */
1675
1766
  const contextPush = (context, scope, options) => {
1676
1767
  if (!context) {
@@ -2323,8 +2414,9 @@ const safeCall = (caller, thisArg, args, optional = false, fnName) => {
2323
2414
  * `ns.fn()` reaches `fn` through the namespace, which evaluates to the scope's
2324
2415
  * object and has to keep doing so - `ns` alone, or `ns === x`, must not see
2325
2416
  * `thisArg`. So the substitution is made here, at the call, and nowhere
2326
- * earlier: `evaluateMember`'s first slot is also the target of `ns.x = v`, and
2327
- * a write belongs on the scope's object. Matched by identity, so it follows the
2417
+ * earlier: `evaluateMember`'s first slot is also the target of `ns.x += v` and
2418
+ * `ns.x++`, as `resolveMemberTarget`'s is of `ns.x = v`, and a write belongs on
2419
+ * the scope's object. Matched by identity, so it follows the
2328
2420
  * object rather than the name it was reached by; the first scope holding the
2329
2421
  * object answers, as in `EvalContext.get`. Up to 0.6.x `thisArg` was never
2330
2422
  * applied (`docs/backlog-retired.md` A7).
@@ -2643,11 +2735,14 @@ const readName = (node, fn) => {
2643
2735
  * The funnel (`docs/a35/plan.md` § 3.3): refuses a dangerous function pushed
2644
2736
  * by any node but an exempt one, so no visitor - including one not yet
2645
2737
  * written - can hand it on as an argument, a receiver, an element, a branch
2646
- * or the expression's result. `pushVisitorResult` calls it for a function
2647
- * value only.
2648
- *
2649
- * It sees only what passes through the walk's own stack. A value that reaches
2650
- * native code without being pushed is not seen: the elements of an array the
2738
+ * or the expression's result. `refuseFunnelledValue` (`visitor-result.ts`)
2739
+ * calls it for a function value only, from its two call sites:
2740
+ * `pushVisitorResult`, for every pushed value, and `assignment-expression.ts`,
2741
+ * for a compound or logical assignment's target, which is read once and not
2742
+ * pushed (`docs/backlog.md` A45, part 2).
2743
+ *
2744
+ * It sees only what is pushed on the walk's own stack, and those targets. A
2745
+ * value that reaches native code without either is not seen: the elements of an array the
2651
2746
  * host built, spread into a call, which stays a documented limit. The other
2652
2747
  * such route, through `this` and the receiver of a call
2653
2748
  * (`docs/backlog-retired.md` A39), is closed in 0.13.0 elsewhere - by
@@ -2682,20 +2777,40 @@ const refuseDangerousRead = (node, value) => {
2682
2777
  * run-to-run noise, so this is not a speed claim; it is that the helper cost a
2683
2778
  * frame on the hot path and bought nothing, and that `addTraceBounded`'s own
2684
2779
  * docblock claims one call per push, which only this shape makes true.
2780
+ * {@link refuseFunnelledValue} is the one frame the push path does take, since
2781
+ * an assignment target read without a push needs the same two tests, and a
2782
+ * second copy of them could drift from the first (`docs/a45/plan.md` § 3.2;
2783
+ * its cost is measured by that plan's step 4).
2685
2784
  *
2686
2785
  * **The value stack is not bounded and must not be.** It is how visitors return
2687
2786
  * values to each other, and dropping an entry desynchronises every node above
2688
2787
  * it. Only the trace - which nothing in this library reads - is capped.
2689
2788
  *
2690
- * **Every function value pushed here passes the funnel**, `refuseDangerousRead`
2691
- * (`docs/a35/plan.md` § 3.3): a dangerous function is refused wherever it was
2692
- * read, unless the node pushing it is a callee, a tag or `typeof`'s operand.
2693
- * The call is behind `typeof value === 'function'`, so a value that is not a
2694
- * function pays one comparison and no frame on this per-node path. `await`
2695
- * pushes its promise here too, which is not a function.
2789
+ * **Every value pushed here passes the funnel**, {@link refuseFunnelledValue}.
2696
2790
  * `pushVisitorResultAsync` has no caller, and no check.
2697
2791
  */
2698
2792
  const pushVisitorResult = (node, st, value) => {
2793
+ refuseFunnelledValue(node, st, value);
2794
+ const result = st.result;
2795
+ result.stack.push(value);
2796
+ result.addTraceBounded(node, value, st.maxTraceItems);
2797
+ return value;
2798
+ };
2799
+ /**
2800
+ * The funnel's two tests, made on every pushed value and on a value a visitor
2801
+ * reads without pushing it: a compound or logical assignment's target, which
2802
+ * `assignment-expression.ts` reads once and does not walk
2803
+ * (`docs/backlog.md` A45, part 2). One definition serves both, so what the
2804
+ * funnel refuses cannot differ between them.
2805
+ *
2806
+ * **A function value passes `refuseDangerousRead`** (`docs/a35/plan.md`
2807
+ * § 3.3): a dangerous function is refused wherever it was read, unless the
2808
+ * node is a callee, a tag or `typeof`'s operand. The call is behind
2809
+ * `typeof value === 'function'`, so a value that is not a function pays one
2810
+ * comparison on this per-node path. `await` pushes its promise here too,
2811
+ * which is not a function.
2812
+ */
2813
+ const refuseFunnelledValue = (node, st, value) => {
2699
2814
  if (typeof value === 'function') {
2700
2815
  refuseDangerousRead(node, value);
2701
2816
  }
@@ -2728,10 +2843,6 @@ const pushVisitorResult = (node, st, value) => {
2728
2843
  // `eval.service.context-write.spec.ts`.
2729
2844
  refuseContextRead();
2730
2845
  }
2731
- const result = st.result;
2732
- result.stack.push(value);
2733
- result.addTraceBounded(node, value, st.maxTraceItems);
2734
- return value;
2735
2846
  };
2736
2847
  const popVisitorResult = (node, st) => {
2737
2848
  const result = st.result;
@@ -2871,6 +2982,60 @@ const refuseDangerousMatch = (node, st) => {
2871
2982
  throw new Error(`Access to dangerous property "${String(matched)}" is blocked for security reasons`);
2872
2983
  }
2873
2984
  };
2985
+ /**
2986
+ * The `caseInsensitive` read of a name: the context, then the literals
2987
+ * registry for a name `get` finds nothing for. Only `undefined` falls through,
2988
+ * so a key holding `null` reads as `null`. Up to 0.13.3 the fallback was
2989
+ * `??`, which turned that `null` into `undefined` (`docs/backlog.md` A52).
2990
+ */
2991
+ const readCaseInsensitive = (node, st) => {
2992
+ const found = st.context?.get(node.name);
2993
+ return found === undefined ? literals.get(node.name) : found;
2994
+ };
2995
+ /**
2996
+ * An identifier target's checks, which the visitor makes before any lookup: a
2997
+ * name on the blocklist, `this` written as a name - a host-built one, or under
2998
+ * `caseInsensitive` any spelling of it - and under `caseInsensitive` a name
2999
+ * whose lookup matched a blocklisted key. A target is never a member's object,
3000
+ * so `refuseThisValue` refuses every `this` that reaches it - unless a
3001
+ * host-built AST reused one `this` node as a member's object, visited first,
3002
+ * the mark-reuse limit `this-position.ts` describes. No target path evaluates
3003
+ * `this` to the context, so that node is written as a key named `this`.
3004
+ *
3005
+ * Every identifier target is checked here and by nothing else: `=`'s, which
3006
+ * reads nothing, and through {@link readIdentifierTarget} a compound or logical
3007
+ * operator's and an update's (`docs/a45/plan.md` D8, D11). Without it,
3008
+ * `constructor = 1` would write an own `constructor` onto the context, as
3009
+ * `constructor++` did up to 0.13.3.
3010
+ */
3011
+ const refuseIdentifierTarget = (node, st) => {
3012
+ refuseDangerousName(node);
3013
+ const caseInsensitive = !!st.options?.caseInsensitive;
3014
+ if (caseInsensitive ? !!equalIgnoreCase(node.name, 'this') : node.name === 'this') {
3015
+ refuseThisValue(node);
3016
+ }
3017
+ if (caseInsensitive) {
3018
+ refuseDangerousMatch(node, st);
3019
+ }
3020
+ };
3021
+ /**
3022
+ * An assignment or update target's read, for a compound or logical operator
3023
+ * and for `++` and `--`: the visitor's own checks and read, with no push and
3024
+ * no node hooks, since the target is read and not walked (`docs/backlog.md`
3025
+ * A45, part 2). The checks are {@link refuseIdentifierTarget}'s, so a refused
3026
+ * target reads nothing. Then it reads the name as the visitor does, and
3027
+ * reports the read: up to 0.13.3 an identifier update reported none.
3028
+ */
3029
+ const readIdentifierTarget = (node, st) => {
3030
+ refuseIdentifierTarget(node, st);
3031
+ const value = st.options?.caseInsensitive
3032
+ ? readCaseInsensitive(node, st)
3033
+ : st.context?.get(node.name);
3034
+ if (st.hasHooks && st.hooks.hasReadHooks) {
3035
+ emitRead(node, st, value);
3036
+ }
3037
+ return value;
3038
+ };
2874
3039
  const identifierVisitor = (node, st) => {
2875
3040
  if (st.options?.caseInsensitive) {
2876
3041
  return identifierVisitorCaseInsensitive(node, st);
@@ -2900,7 +3065,6 @@ const identifierVisitor = (node, st) => {
2900
3065
  const identifierVisitorCaseInsensitive = (node, st) => {
2901
3066
  beforeVisitor(node, st);
2902
3067
  refuseDangerousName(node);
2903
- const context = st.context;
2904
3068
  const isThis = !!equalIgnoreCase(node.name, 'this');
2905
3069
  // `This` is refused outside a member's object, as `this` is
2906
3070
  // (`this-position.ts`).
@@ -2912,7 +3076,7 @@ const identifierVisitorCaseInsensitive = (node, st) => {
2912
3076
  }
2913
3077
  const value = isThis
2914
3078
  ? st.context
2915
- : context?.get(node.name) ?? literals.get(node.name);
3079
+ : readCaseInsensitive(node, st);
2916
3080
  if (st.hasHooks && st.hooks.hasReadHooks && !isThis) {
2917
3081
  emitRead(node, st, value);
2918
3082
  }
@@ -2940,7 +3104,6 @@ const literalVisitor = (node, st) => {
2940
3104
  afterVisitor(node, st);
2941
3105
  };
2942
3106
 
2943
- // import { getCachedVisitorResult, setCachedVisitorResult } from './visitor-result-cache';
2944
3107
  /**
2945
3108
  * Converts value to primitive for comparison operations
2946
3109
  */
@@ -3087,20 +3250,11 @@ const evaluateBinaryOperation = (operator, left, right) => {
3087
3250
  */
3088
3251
  const binaryExpressionVisitor = (node, st, callback) => {
3089
3252
  beforeVisitor(node, st);
3090
- // Disable visitor result caching for now due to context sensitivity issues
3091
- // const cachedResult = getCachedVisitorResult(node, st.context);
3092
- // if (cachedResult !== undefined) {
3093
- // pushVisitorResult(node, st, cachedResult);
3094
- // afterVisitor(node, st);
3095
- // return;
3096
- // }
3097
3253
  callback(node.left, st);
3098
3254
  const left = popVisitorResult(node, st);
3099
3255
  callback(node.right, st);
3100
3256
  const right = popVisitorResult(node, st);
3101
3257
  const value = evaluateBinaryOperation(node.operator, left, right);
3102
- // Disable visitor result caching for now
3103
- // setCachedVisitorResult(node, st.context, value);
3104
3258
  pushVisitorResult(node, st, value);
3105
3259
  afterVisitor(node, st);
3106
3260
  };
@@ -4041,8 +4195,40 @@ const assignmentExpressionVisitor = (node, st, callback) => {
4041
4195
  if (target.type !== 'Identifier' && target.type !== 'MemberExpression') {
4042
4196
  throw new Error(`Unsupported assignment target: ${target.type}`);
4043
4197
  }
4044
- callback(node.left, st);
4045
- const left = popVisitorResult(node, st);
4198
+ // The target is not walked, and is evaluated once, before the right side
4199
+ // (`docs/backlog.md` A45, part 2). `=` reads nothing of it, as JavaScript's
4200
+ // `=` does not: an identifier gets the identifier visitor's checks, and a
4201
+ // member is resolved to its object and key. A compound or logical target is
4202
+ // read once, as an update reads its operand: a member through one
4203
+ // `evaluateMember` call, whose object and matched key the write reuses
4204
+ // (A44), and an identifier through the identifier visitor's own read. The
4205
+ // value read is not pushed, so it is given the funnel's tests here, or a
4206
+ // listed function read as a target would be combined and written where
4207
+ // `fetch || 1` refuses it.
4208
+ const plain = node.operator === '=';
4209
+ let left;
4210
+ let targetObject;
4211
+ let targetKey;
4212
+ if (target.type === 'Identifier') {
4213
+ if (plain) {
4214
+ refuseIdentifierTarget(target, st);
4215
+ }
4216
+ else {
4217
+ left = readIdentifierTarget(target, st);
4218
+ }
4219
+ }
4220
+ else if (plain) {
4221
+ [targetObject, targetKey] = resolveMemberTarget(target, st, callback);
4222
+ }
4223
+ else {
4224
+ const [object, , value, , key] = evaluateMember(target, st, callback);
4225
+ targetObject = object;
4226
+ targetKey = key;
4227
+ left = value;
4228
+ }
4229
+ if (!plain) {
4230
+ refuseFunnelledValue(target, st, left);
4231
+ }
4046
4232
  // A logical assignment that short-circuits gives `left` and does nothing
4047
4233
  // more: its right side is not evaluated and nothing is written, so no write
4048
4234
  // policy is asked (`docs/backlog.md` A45, part 1). The rule is
@@ -4081,7 +4267,8 @@ const assignmentExpressionVisitor = (node, st, callback) => {
4081
4267
  pushVisitorResult(node, st, value);
4082
4268
  }
4083
4269
  else if (target.type === 'MemberExpression') {
4084
- const [object, key,] = evaluateMember(target, st, callback);
4270
+ const object = targetObject;
4271
+ const key = targetKey;
4085
4272
  const value = func(left, right);
4086
4273
  // A member write never reaches `EvalContext.set`, so a context policing
4087
4274
  // writes is asked here instead - `EvalContext.checkMemberWrite`.
@@ -4104,12 +4291,18 @@ const updateExpressionVisitor = (node, st, callback) => {
4104
4291
  throw new Error(`Context is not set.`);
4105
4292
  }
4106
4293
  else if (target.type === 'Identifier') {
4294
+ // The target read a compound assignment makes: the identifier visitor's
4295
+ // checks, before any lookup, then one read and its read event
4296
+ // (`docs/a45/plan.md` D8, D9, D11). Up to 0.13.3 an update checked
4297
+ // nothing and reported nothing, so `constructor++` wrote an own
4298
+ // `constructor` onto the context. It takes no funnel check, as the member
4299
+ // branch takes none: `fetch++` gives `NaN` (`docs/backlog-retired.md` A40).
4300
+ const value = readIdentifierTarget(target, st);
4107
4301
  // The fallback `assignment-expression.ts` takes, for the same reason
4108
4302
  // (`docs/backlog-retired.md` A43).
4109
4303
  const key = st.options?.caseInsensitive
4110
4304
  ? st.context.getKey(target.name) ?? target.name
4111
4305
  : target.name;
4112
- const value = st.context?.get(key);
4113
4306
  // The update run natively on a copy of the operand. JavaScript converts
4114
4307
  // the operand to a numeric once, then adds or subtracts, and a postfix
4115
4308
  // update gives that converted old value. `value + 1` on the operand as
@@ -4129,7 +4322,8 @@ const updateExpressionVisitor = (node, st, callback) => {
4129
4322
  pushVisitorResult(node, st, node.prefix ? updated : old);
4130
4323
  }
4131
4324
  else if (target.type === 'MemberExpression') {
4132
- const [object, property, value] = evaluateMember(target, st, callback);
4325
+ // The write reaches the key the lookup matched (`docs/backlog.md` A44).
4326
+ const [object, , value, , property] = evaluateMember(target, st, callback);
4133
4327
  // As in the identifier branch: one native conversion, before the write.
4134
4328
  let updated = value;
4135
4329
  const old = node.operator === '++' ? updated++ : updated--;
@@ -4689,7 +4883,7 @@ const arrowFunctionExpressionVisitor = (node, st, callback) => {
4689
4883
  // and - since this closure's body is a re-entrant `evaluate` that pushes
4690
4884
  // again - a plant that evaluates anything recurses until the stack is
4691
4885
  // gone, leaving a reused context unusable (`docs/backlog.md` A42).
4692
- contextPush(st.context, newContext);
4886
+ contextPush(st.context, newContext, st.options);
4693
4887
  try {
4694
4888
  return evaluate(node.body, st);
4695
4889
  }
@@ -7213,13 +7407,31 @@ function provideColonIdentifiers() {
7213
7407
  */
7214
7408
  class ParserService {
7215
7409
  /**
7216
- * Gets the parser options.
7410
+ * Gets the parser options: the constructor's, or the last value given to
7411
+ * the setter.
7217
7412
  */
7218
7413
  get parserOptions() {
7219
7414
  return this._parserOptions;
7220
7415
  }
7221
7416
  /**
7222
- * Sets the parser options.
7417
+ * Sets the parser options for direct `ParserService.parse` calls, which
7418
+ * merge the options they are given over this value, the call's key winning,
7419
+ * for every key but `cacheSize`.
7420
+ *
7421
+ * `EvalService`, `CompilerService` and `DiscoveryService` pass their own
7422
+ * options on every parse, and those carry every key of
7423
+ * `defaultParserOptions`, so for each of them the service's key wins over
7424
+ * this value, `cacheSize` again aside. Only `cacheSize` and a key
7425
+ * `defaultParserOptions` does not carry reach those services through the
7426
+ * setter: `colonIdentifiers` is the one the README relies on
7427
+ * (`docs/backlog-retired.md` A30).
7428
+ *
7429
+ * `cacheSize` is read from this value alone, never from a call's or a
7430
+ * service's options. It sizes the parse cache once, at construction, and a
7431
+ * later value does not resize it. Whether a parse uses the cache is read
7432
+ * from it on every parse, so a later falsy one stops every parse using the
7433
+ * cache, the services' included.
7434
+ *
7223
7435
  * @param value The parser options to set.
7224
7436
  */
7225
7437
  set parserOptions(value) {
@@ -7335,10 +7547,10 @@ class ParserService {
7335
7547
  }
7336
7548
  return undefined;
7337
7549
  }
7338
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: ParserService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
7339
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: ParserService, providedIn: 'root' }); }
7550
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: ParserService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
7551
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: ParserService, providedIn: 'root' }); }
7340
7552
  }
7341
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: ParserService, decorators: [{
7553
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: ParserService, decorators: [{
7342
7554
  type: Injectable,
7343
7555
  args: [{
7344
7556
  providedIn: 'root'
@@ -7457,10 +7669,10 @@ class EvalService extends BaseEval {
7457
7669
  const promise = evaluateAsync(ast, state);
7458
7670
  return promise;
7459
7671
  }
7460
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: EvalService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
7461
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: EvalService, providedIn: 'root' }); }
7672
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: EvalService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
7673
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: EvalService, providedIn: 'root' }); }
7462
7674
  }
7463
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: EvalService, decorators: [{
7675
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: EvalService, decorators: [{
7464
7676
  type: Injectable,
7465
7677
  args: [{
7466
7678
  providedIn: 'root'
@@ -7739,10 +7951,10 @@ class CompilerService extends BaseEval {
7739
7951
  }
7740
7952
  return undefined;
7741
7953
  }
7742
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: CompilerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
7743
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: CompilerService, providedIn: 'root' }); }
7954
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: CompilerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
7955
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: CompilerService, providedIn: 'root' }); }
7744
7956
  }
7745
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: CompilerService, decorators: [{
7957
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: CompilerService, decorators: [{
7746
7958
  type: Injectable,
7747
7959
  args: [{
7748
7960
  providedIn: 'root'
@@ -7779,10 +7991,10 @@ class DiscoveryService extends BaseEval {
7779
7991
  const value = extract(ast, searchType);
7780
7992
  return value;
7781
7993
  }
7782
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: DiscoveryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
7783
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: DiscoveryService, providedIn: 'root' }); }
7994
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: DiscoveryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
7995
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: DiscoveryService, providedIn: 'root' }); }
7784
7996
  }
7785
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: DiscoveryService, decorators: [{
7997
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: DiscoveryService, decorators: [{
7786
7998
  type: Injectable,
7787
7999
  args: [{
7788
8000
  providedIn: 'root'