@zvenigora/ng-eval-core 0.15.0 → 0.15.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.
package/CHANGELOG.md CHANGED
@@ -14,6 +14,40 @@ Versions 0.1.104–0.1.107 are on npm without entries here.
14
14
 
15
15
  ---
16
16
 
17
+ ## [0.15.1] - 2026-11-02
18
+
19
+ **A patch that fixes [A33](../../docs/backlog-retired.md#a33)**, the case-insensitive lookup
20
+ cache's miss across a same-count key swap, and documents [A34](../../docs/backlog-retired.md#a34),
21
+ an options object remembered by identity. The `.d.ts` differs from 0.15.0's only in JSDoc.
22
+ `eval-signals` 0.8.0 and `eval-forms` 0.8.0 take it through their peer range; for `eval-signals` a
23
+ row witnesses it. A33's lower bound is not measured.
24
+
25
+ ### Changed
26
+ - `ParserService.parserOptions`' and `parse`'s JSDoc, a new JSDoc on `defaultParserOptions`, and
27
+ the README's colon-identifier section say that a value written into an options object is not
28
+ reliably seen: the parse cache and `CompilerService`'s remember options objects by identity, so a
29
+ later parse or compile may keep a text's reading from before the write, or cache one made after it
30
+ as if nothing had changed; replace the object instead ([A34](../../docs/backlog-retired.md#a34)). No
31
+ behaviour changes. Documentation only: the JSDoc reaches the `.d.ts` and the bundle, the README
32
+ the tarball.
33
+
34
+ ### Fixed
35
+ - **Under `caseInsensitive`, a property added in the same interval as another is deleted is
36
+ found by a case variant of its name.** The lookup cache kept an earlier miss while the object's
37
+ own-key count was unchanged: after `delete x.a; x.c = 3`, `x.C` read `undefined`, and `x.C = 9`
38
+ or `x.C += 1` made a second own key `C` beside `c`. The same miss skipped a refusal: a case
39
+ variant of a blocked own name that is not an own property of the object's immediate prototype —
40
+ `prototype` on a plain object, every blocked name but `constructor` on an instance of a class that
41
+ declares none of them, any on an object made by `Object.create(null)` or `Object.create({})` —
42
+ read `undefined` and wrote a sibling key, where it is refused when no miss was cached. The blocked
43
+ property's value was neither returned nor written. Both are now refused, and a cached miss stands
44
+ only while the object's own names are those it was made from
45
+ ([A33](../../docs/backlog-retired.md#a33)). The cache now keeps each object's own names for as long
46
+ as the object lives, for every object a `caseInsensitive` member access with a string key reaches:
47
+ about 8 to 9 bytes per own name, and about 32 per index name of an array of a million elements.
48
+
49
+ ---
50
+
17
51
  ## [0.15.0] - 2026-10-31
18
52
 
19
53
  **An `await` gives JavaScript's answer or throws.** A minor carrying breaking changes
@@ -589,7 +623,7 @@ grammar's spec and corpus pass at 8.11.2 (the plan's § 8 q3). `eval-signals` 0.
589
623
  keys an AST, so a text compiled before `ParserService.parserOptions` was replaced through its
590
624
  setter — with `colonIdentifiers` turned on, for one — is compiled again rather than served the
591
625
  old function. A write in place into that object is not seen, as it is not for an AST
592
- ([A34](../../docs/backlog.md#a34)). Two narrower
626
+ ([A34](../../docs/backlog-retired.md#a34)). Two narrower
593
627
  changes: a subclass that sets `CompilerService`'s protected per-call options is served a function
594
628
  for its current ones, compiled on every call when they carry an acorn callback or `program`, and
595
629
  a value JSON cannot hold, set in `ParserService.parserOptions` under a key `defaultParserOptions`
@@ -607,7 +641,7 @@ grammar's spec and corpus pass at 8.11.2 (the plan's § 8 q3). `eval-signals` 0.
607
641
  carrying a callback or a `program` neither reads nor writes the cache, so the callback runs on
608
642
  every parse. A change made through the `parserOptions` setter is honoured for text already
609
643
  cached; a write in place into an options object, the service's or one passed again, is not
610
- ([A34](../../docs/backlog.md#a34)). Every published version to 0.11.1 is affected.
644
+ ([A34](../../docs/backlog-retired.md#a34)). Every published version to 0.11.1 is affected.
611
645
 
612
646
  ---
613
647
 
package/README.md CHANGED
@@ -215,7 +215,7 @@ Some expression languages name their values `Q1:1` or `VP14:0`. With `colonIdent
215
215
 
216
216
  `provideColonIdentifiers()` turns it on for an application: `ParserService` reads it when it is constructed, so every parse through `EvalService`, `CompilerService` and `DiscoveryService` follows it. Put it in the application's **root** providers. `ParserService` is provided in the root, so in a lazy route's providers, or any other child injector's, the provider would reach no parse; there it throws when that injector is created instead.
217
217
 
218
- A per-call `colonIdentifiers` in the options of `ParserService.parse`, or of the exported `parse`, overrides it — and the exported `parse` sees only the options it is given. Setting `ParserService.parserOptions` to a new object is the imperative alternative: every later parse or compile follows it, of a text seen before as of a new one, while a function already compiled keeps the reading it was compiled with.
218
+ A per-call `colonIdentifiers` in the options of `ParserService.parse`, or of the exported `parse`, overrides it — and the exported `parse` sees only the options it is given. Setting `ParserService.parserOptions` to a new object is the imperative alternative: every later parse or compile follows it, of a text seen before as of a new one, while a function already compiled keeps the reading it was compiled with. Writing into an options object instead — the one the getter returns, one passed to `parse` again, or the exported `defaultParserOptions`, which `EvalService` and `CompilerService` pass on every parse — is not reliably seen. The parse cache, and `CompilerService`'s, remember options objects by identity, not by their values, so a later parse or compile may keep a text's reading from before the write, or cache one made after it as if nothing had changed. Replace an options object; do not write into one.
219
219
 
220
220
  ```javascript
221
221
  import { EvalService, ParserService,
@@ -1174,10 +1174,10 @@ let entriesCreated = 0;
1174
1174
  *
1175
1175
  * A key found before is still the answer while it is still an own key of the
1176
1176
  * object, which is checked without a scan. One deleted or renamed since is
1177
- * scanned for again. A miss stays a miss while the object's own-key count is
1178
- * unchanged; a key added since changes the count, and the object's answers
1179
- * are made afresh. Not caught: a key added in the same interval as another is
1180
- * deleted, which leaves the count as it was, so a cached miss can outlive it.
1177
+ * scanned for again. A miss stays a miss while the object's own names are the
1178
+ * ones it was made from, in order; any difference, a key added in the same
1179
+ * interval as another is deleted included, and the object's answers are made
1180
+ * afresh (`docs/backlog-retired.md` A33).
1181
1181
  */
1182
1182
  function getCachedCaseInsensitiveProperty(obj, searchKey, equalIgnoreCase) {
1183
1183
  if (!obj || typeof obj !== 'object') {
@@ -1190,8 +1190,8 @@ function getCachedCaseInsensitiveProperty(obj, searchKey, equalIgnoreCase) {
1190
1190
  return cached;
1191
1191
  }
1192
1192
  const ownKeys = Object.getOwnPropertyNames(obj);
1193
- if (!entry || entry.keyCount !== ownKeys.length) {
1194
- entry = { keyCount: ownKeys.length, found: new Map() };
1193
+ if (!entry || !sameNames(entry.keys, ownKeys)) {
1194
+ entry = { keys: ownKeys, found: new Map() };
1195
1195
  propertyLookupCache.set(obj, entry);
1196
1196
  entriesCreated++;
1197
1197
  }
@@ -1202,6 +1202,17 @@ function getCachedCaseInsensitiveProperty(obj, searchKey, equalIgnoreCase) {
1202
1202
  entry.found.set(lowered, foundKey);
1203
1203
  return foundKey;
1204
1204
  }
1205
+ const sameNames = (a, b) => {
1206
+ if (a.length !== b.length) {
1207
+ return false;
1208
+ }
1209
+ for (let i = 0; i < a.length; i++) {
1210
+ if (a[i] !== b[i]) {
1211
+ return false;
1212
+ }
1213
+ }
1214
+ return true;
1215
+ };
1205
1216
  /**
1206
1217
  * Clears the property lookup cache (for testing or memory management)
1207
1218
  */
@@ -1210,8 +1221,9 @@ function clearPropertyLookupCache() {
1210
1221
  entriesCreated = 0;
1211
1222
  }
1212
1223
  /**
1213
- * Gets current property lookup cache statistics: the number of objects given
1214
- * an entry since the last clear, live or collected.
1224
+ * Gets current property lookup cache statistics: the number of entries made
1225
+ * since the last clear, live or collected; an object gets a new one when a
1226
+ * lookup that is not a cached hit finds its own names changed.
1215
1227
  */
1216
1228
  function getPropertyLookupCacheStats() {
1217
1229
  return {
@@ -7015,6 +7027,15 @@ class EvalState {
7015
7027
  }
7016
7028
  }
7017
7029
 
7030
+ /**
7031
+ * The options `EvalService` and `CompilerService` pass on every parse, as
7032
+ * this object itself; `ParserService` and `DiscoveryService` copy it when
7033
+ * constructed. Read it or copy it; do not write into it. A value written into
7034
+ * it is not reliably seen: the parse cache remembers it by identity, so a text
7035
+ * cached before the write can keep its reading, and one parsed while it held
7036
+ * the value can keep that reading after it is written back
7037
+ * (`docs/backlog-retired.md` A34).
7038
+ */
7018
7039
  const defaultParserOptions = {
7019
7040
  ...defaultOptions,
7020
7041
  ecmaVersion: 2020,
@@ -7562,7 +7583,7 @@ const buildParseFingerprint = (options) => {
7562
7583
  * object the `parserOptions` getter returns, an options object a caller passes
7563
7584
  * again after writing into it, or the exported `defaultParserOptions`. A change
7564
7585
  * through the `parserOptions` setter installs a new object, and is seen
7565
- * (`docs/backlog.md` A34).
7586
+ * (`docs/backlog-retired.md` A34).
7566
7587
  */
7567
7588
  const parseFingerprint = (memo, serviceOptions, callOptions) => {
7568
7589
  let byCall = memo.get(serviceOptions);
@@ -7648,6 +7669,15 @@ class ParserService {
7648
7669
  /**
7649
7670
  * Gets the parser options: the constructor's, or the last value given to
7650
7671
  * the setter.
7672
+ *
7673
+ * Replace the object through the setter rather than write into the one this
7674
+ * returns: a value written into it is not reliably seen. The parse cache,
7675
+ * and `CompilerService`'s cache of compiled strings, remember each pair of
7676
+ * options objects, this one and a call's, by identity, not by their values.
7677
+ * A later parse through a pair seen before the write, as `EvalService`'s and
7678
+ * `CompilerService`'s are, keeps a cached text's earlier reading and caches
7679
+ * a new text as if the options had not changed; a parse through a new
7680
+ * call-options object sees the write (`docs/backlog-retired.md` A34).
7651
7681
  */
7652
7682
  get parserOptions() {
7653
7683
  return this._parserOptions;
@@ -7743,7 +7773,10 @@ class ParserService {
7743
7773
  * @description
7744
7774
  * Parses expression and returns ES6/ES2023 AST.
7745
7775
  * @param expr expression to parse
7746
- * @param options optional parser options
7776
+ * @param options optional parser options, merged over `parserOptions`. Pass
7777
+ * a new object for new options: a value written into an object already
7778
+ * passed is not reliably seen, since the cache remembers the object by
7779
+ * identity (`docs/backlog-retired.md` A34).
7747
7780
  * @returns The parsed AST (Abstract Syntax Tree).
7748
7781
  */
7749
7782
  parse(expr, options) {
@@ -7998,7 +8031,7 @@ class CompilerService extends BaseEval {
7998
8031
  * the `ParserService.parserOptions` setter reaches a string compiled before
7999
8032
  * it (`docs/colon-identifiers/phase-9-plan.md` § 3.2). The memo is
8000
8033
  * `ParserService`'s kind, and a write in place goes unseen here as there
8001
- * (`docs/backlog.md` A34). `null` when that parse bypasses `ParserService`'s
8034
+ * (`docs/backlog-retired.md` A34). `null` when that parse bypasses `ParserService`'s
8002
8035
  * cache - a callback or a `program` among its options, or a value JSON
8003
8036
  * cannot hold - and this cache then bypasses too, since a cached function
8004
8037
  * runs no callback.