@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.
package/CHANGELOG.md CHANGED
@@ -14,7 +14,62 @@ Versions 0.1.104–0.1.107 are on npm without entries here.
14
14
 
15
15
  ---
16
16
 
17
- ## [0.6.1] - 2026-09-29
17
+ ## [0.7.0] - 2026-10-01
18
+
19
+ **Errors keep their identity, `thisArg` is applied, and three silent outcomes now throw —
20
+ [A1](../../docs/backlog-retired.md#a1), [A2](../../docs/backlog-retired.md#a2),
21
+ [A5](../../docs/backlog-retired.md#a5), [A6](../../docs/backlog-retired.md#a6) and
22
+ [A7](../../docs/backlog-retired.md#a7).** A breaking minor. No exported symbol changes shape — the
23
+ `.d.ts` differs from 0.6.1 in documentation comments only — but what several methods throw, and
24
+ the `this` some calls receive, change. `eval-signals` 0.1.4 and `eval-forms` 0.2.5 widen their
25
+ peer ranges to admit it.
26
+
27
+ ### Breaking
28
+ - **Errors are no longer rewrapped.** The twelve service entry points — `EvalService`,
29
+ `CompilerService`, `DiscoveryService` and `ParserService` — and the evaluator's call and `new`
30
+ wrappers rethrow what they caught, where each raised a new `Error` carrying only the message. A
31
+ custom error keeps its class, `stack`, `cause` and properties, so `instanceof` works; a syntax
32
+ error is acorn's `SyntaxError`, with `pos` and `loc`. Messages lose the prefixes a throw used to
33
+ get: `Function call error: ` from inside a called function, and `Constructor error: ` from
34
+ inside a constructor. A thrown non-`Error` value propagates as thrown, where `CompilerService`
35
+ replaced it with a fixed message (`'call'`, `'error in compile'`, `'error in callAsync'`). Code
36
+ that matched a prefix or the message should select on the error itself.
37
+ [A5](../../docs/backlog-retired.md#a5), [A6](../../docs/backlog-retired.md#a6).
38
+ - **A synchronous throw under `await` throws synchronously.** `await obj.__proto__` became a
39
+ rejected promise: `simpleEval` and `eval` returned it instead of throwing, and the walk went on
40
+ with the operand still open. It now throws from the sync entry points, and `evalAsync` rejects
41
+ with the original error. An asynchronous rejection still carries ` at position <start>-<end>`.
42
+ Hooks see a failed walk: the operand and the `await` close with `completed: false` and an
43
+ `error`, where the operand used to close with no `error`.
44
+ [A1](../../docs/backlog-retired.md#a1).
45
+ - **Destructuring assignment throws instead of silently doing nothing.** `[a, b] = arr` and
46
+ `({ m } = o)` returned `undefined` and left the context unchanged. They now throw
47
+ `Unsupported assignment target: ArrayPattern` / `ObjectPattern`, before either side is
48
+ evaluated. [A2](../../docs/backlog-retired.md#a2).
49
+ - **`(a)++` works under `preserveParens`**, and so do `(a) = 1` and `(o.x)++`: a parenthesised
50
+ write target is unwrapped. Each used to push no value, so the nodes around it read the wrong
51
+ operands. Any other unsupported update target throws `Unsupported update target: <type>`.
52
+ [A2](../../docs/backlog-retired.md#a2).
53
+ - **`EvalScopeOptions.thisArg` is applied.** A method called on a scope's own object —
54
+ `cat.action()` through the namespace `cat` — receives the scope's `thisArg` as `this`, and
55
+ `this.fn()` receives the `thisArg` of the prior scope that supplies `fn`. With no `thisArg`,
56
+ `cat.action()` still receives the scope's object. `cat` itself still evaluates to the scope's
57
+ object, and `cat.x` reads and writes it, not `thisArg`. `EvalContext.getThis` answers with
58
+ that `thisArg`, and answers `undefined` for a key only a lookup resolves, where it returned the
59
+ lookup function: `this.fn()` for such a key now receives the context. The README's Scopes
60
+ example now uses a `thisArg` other than the scope's object.
61
+ [A7](../../docs/backlog-retired.md#a7).
62
+
63
+ ### Changed
64
+ - **The README says options-first calls cannot read collected hook errors, by design.**
65
+ `simpleEval(expr, context, { hooks })` never hands back its state: read `state.hookErrors`
66
+ after `createState` and `eval`, or set `onHookError: 'throw'` on the `EvalHooks` you pass.
67
+ Decided rather than built: [E5](../../docs/backlog-retired.md#e5).
68
+ - **`LICENSE` ships in the package**, which declared `"license": "MIT"` and shipped no file.
69
+
70
+ ---
71
+
72
+ ## [0.6.1] - 2026-09-30
18
73
 
19
74
  **A patch: two manifest-and-hygiene fixes, [F5](../../docs/backlog-retired.md#f5) and
20
75
  [B3](../../docs/backlog-retired.md#b3), a dead line removed, and a README correction.** No
@@ -46,7 +101,7 @@ unchanged: both declare `>=0.3.0 <0.7.0`.
46
101
  and is not currently applied: a method reached through a scope's namespace, such as
47
102
  `cat.action()`, is called with the scope's own object as `this`, whatever `thisArg` holds.
48
103
  Nothing changes at runtime; the README's Scopes section now says this. What `thisArg` should
49
- mean is open, as [A7](../../docs/backlog.md#a7), and answering it changes a call's receiver.
104
+ mean is open, as [A7](../../docs/backlog-retired.md#a7), and answering it changes a call's receiver.
50
105
 
51
106
  ---
52
107
 
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Mikhail Klygin (Zvenigora)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -44,7 +44,7 @@ expressions.length; // 2
44
44
 
45
45
  An evaluation context may carry prior scopes, each with its own `namespace` and case sensitivity. Bare identifiers are read from the context itself; a namespaced scope is reached through its namespace.
46
46
 
47
- `EvalScopeOptions` also accepts `thisArg`, but it is not currently applied: no call uses it as `this`. A method reached through a namespace, such as `cat.action(...)` below, is called with the scope's own object as `this`. The example sets `thisArg` to that same object, so its output does not depend on it.
47
+ `thisArg` is the `this` a scope's methods are called with. A method called on the scope's own object, such as `cat.action(...)` below, receives `thisArg`; so does `this.fn()` when a global scope supplies `fn`. Without `thisArg`, `cat.action(...)` receives the scope's object. Only the call's receiver changes: `cat` still evaluates to the scope's object, so `cat.num` reads it and `cat.x = 1` writes to it. Up to 0.6.x `thisArg` was accepted and never applied.
48
48
 
49
49
  ```javascript
50
50
  import { EvalContext, EvalScope, EvalScopeOptions,
@@ -68,12 +68,12 @@ const catOptions: EvalScopeOptions = {
68
68
  global: false,
69
69
  caseInsensitive: false,
70
70
  namespace: 'cat',
71
- thisArg: cat
71
+ thisArg: { name: 'Mister Whiskers' }
72
72
  };
73
73
  evalContext.priorScopes.push(EvalScope.fromObject(cat, catOptions));
74
74
 
75
75
  const result = service.simpleEval('cat.action(args, cat.num, "times")', evalContext);
76
- // 'Miss Kitty says meow 3 times'
76
+ // 'Mister Whiskers says meow 3 times' - `this` is thisArg; cat.num still reads cat
77
77
  ```
78
78
 
79
79
  Note that an `EvalContext` may back any number of evaluations, and that `caseInsensitive` set on the context alone does not reach the walk — pass it in the evaluation options too.
@@ -265,7 +265,7 @@ state.hookErrors; // [{ phase, nodeType, error }, ...]
265
265
 
266
266
  Two things to know about it:
267
267
 
268
- - **Reading `hookErrors` requires the state-first style.** `simpleEval` builds its state internally and never hands it back, so there is nowhere to read them from. Use `createState` plus `eval`.
268
+ - **Options-first calls cannot read collected hook errors, by design.** `simpleEval(expr, context, { hooks })` builds its state internally and never hands it back, so errors collected on it are out of reach. To read them, use the state-first style — `createState`, then `eval` — and read `state.hookErrors`. Or have a faulty hook fail the evaluation instead, with `onHookError: 'throw'` set on the `EvalHooks` you pass (see the next point).
269
269
  - **Passing both `hooks` and `onHookError` silently ignores `onHookError`.** A registry you pass through `options.hooks` is yours, and it keeps the policy it was constructed with; options never reconfigure an adopted registry. Pass the policy where the registry is built instead:
270
270
 
271
271
  ```javascript
@@ -306,7 +306,9 @@ try { service.eval('1 + boom()', state); } catch { /* rethrown */ }
306
306
  // innermost first, each carrying the error that aborted the walk
307
307
  ```
308
308
 
309
- **2. An enclosing visitor moved on without its child.** The node is flushed when the enclosing one closes, and there is **no** `error` — nothing was reported as thrown, and the evaluation may still produce a value:
309
+ **2. An enclosing visitor moved on without its child.** The node is flushed when the enclosing one closes, and there is **no** `error` — nothing was reported as thrown, and the evaluation may still produce a value.
310
+
311
+ Up to 0.6.x an `await` whose operand threw synchronously did this: it turned the throw into a rejected promise and closed without its operand. Since 0.7.0 no built-in visitor does — the throw propagates, so the same expression is now the first kind:
310
312
 
311
313
  ```javascript
312
314
  import { CompilerService, EvalService } from '@zvenigora/ng-eval-core';
@@ -323,11 +325,14 @@ state.hooks.on('after', '*', (e) => {
323
325
 
324
326
  const fn = compiler.compile('async () => await obj.__proto__');
325
327
  const arrow = compiler.call(fn, state); // returns the closure; seen === []
326
- await arrow().catch(() => undefined); // the body runs here
328
+ try { arrow(); } catch { /* the body runs here, and throws synchronously */ }
327
329
 
328
- // seen === [['MemberExpression', false]] - completed: false, but no error
330
+ // seen === [['MemberExpression', true], ['AwaitExpression', true]]
331
+ // up to 0.6.x: [['MemberExpression', false]] - completed: false, but no error
329
332
  ```
330
333
 
334
+ The second kind stays in the hook contract.
335
+
331
336
  So: test for the `error` property, not for `completed === false`.
332
337
 
333
338
  #### Cost