tutuca 0.9.95 → 0.9.96

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.
@@ -47,6 +47,23 @@ class BindStep extends Step {
47
47
  }
48
48
  }
49
49
 
50
+ class ScopeBindStep extends BindStep {
51
+ constructor(val, binds = {}) {
52
+ super(binds);
53
+ this.val = val;
54
+ }
55
+ enterFrame(stack, _prev, next) {
56
+ const dyn = this.val.evalAsHandler(stack)?.call(stack.it) ?? {};
57
+ return stack.enter(next, { ...this.binds, ...dyn }, false);
58
+ }
59
+ withIndex(i) {
60
+ return new ScopeBindStep(this.val, { ...this.binds, key: i });
61
+ }
62
+ withKey(key) {
63
+ return new ScopeBindStep(this.val, { ...this.binds, key });
64
+ }
65
+ }
66
+
50
67
  class FieldStep extends Step {
51
68
  constructor(field) {
52
69
  super();
@@ -108,9 +125,9 @@ class SeqAccessStep extends Step {
108
125
  }
109
126
 
110
127
  class EachBindStep extends Step {
111
- constructor(seqVal, key) {
128
+ constructor(iterInfo, key) {
112
129
  super();
113
- this.seqVal = seqVal;
130
+ this.iterInfo = iterInfo;
114
131
  this.key = key;
115
132
  }
116
133
  lookup(v, _dval) {
@@ -120,8 +137,7 @@ class EachBindStep extends Step {
120
137
  return v;
121
138
  }
122
139
  enterFrame(stack, _prev, next) {
123
- const item = this.seqVal.eval(stack)?.get(this.key, null);
124
- return stack.enter(next, { key: this.key, value: item }, false);
140
+ return stack.enter(next, this.iterInfo.enrichBinds(stack, this.key), false);
125
141
  }
126
142
  toAbstractPathStep() {
127
143
  return null;
@@ -1776,6 +1792,9 @@ class Renderer {
1776
1792
  _renderMetadata(info) {
1777
1793
  return new VComment(`§${JSON.stringify(info)}§`);
1778
1794
  }
1795
+ renderScopeMeta(nid, dom) {
1796
+ return new VFragment([this._renderMetadata({ $: "Scope", nid }), dom]);
1797
+ }
1779
1798
  }
1780
1799
  var getSeqInfo = (seq) => isIndexed(seq) ? imIndexedIter : isKeyed(seq) ? imKeyedIter : seq?.[SEQ_INFO] ?? unkIter;
1781
1800
  var normalizeRange = (start, end, size) => {
@@ -2296,10 +2315,11 @@ class SlotNode extends WrapperNode {
2296
2315
  class ScopeNode extends WrapperNode {
2297
2316
  render(stack, rx) {
2298
2317
  const binds = this.val.evalAsHandler(stack)?.call(stack.it) ?? {};
2299
- return this.node.render(stack.enter(stack.it, binds, false), rx);
2318
+ const dom = this.node.render(stack.enter(stack.it, binds, false), rx);
2319
+ return rx.renderScopeMeta(this.nodeId, dom);
2300
2320
  }
2301
2321
  toPathStep(_ctx) {
2302
- return new BindStep({});
2322
+ return new ScopeBindStep(this.val);
2303
2323
  }
2304
2324
  wrapNode(node) {
2305
2325
  this.node = node;
@@ -2317,7 +2337,7 @@ class EachNode extends WrapperNode {
2317
2337
  return rx.renderEachWhen(stack, this.iterInfo, this.node, this.nodeId);
2318
2338
  }
2319
2339
  toPathStep(ctx) {
2320
- return ctx.hasKey ? new EachBindStep(this.val, ctx.key) : null;
2340
+ return ctx.hasKey ? new EachBindStep(this.iterInfo, ctx.key) : null;
2321
2341
  }
2322
2342
  static register = true;
2323
2343
  }
@@ -2336,6 +2356,16 @@ class IterInfo {
2336
2356
  const enricher = this.enrichWithVal?.evalAsHandler(stack) ?? null;
2337
2357
  return { seq, filter, loopWith, enricher };
2338
2358
  }
2359
+ enrichBinds(stack, key) {
2360
+ const { seq, loopWith, enricher } = this.eval(stack);
2361
+ const value = seq?.get ? seq.get(key, null) : null;
2362
+ const binds = { key, value };
2363
+ if (enricher) {
2364
+ const { iterData } = unpackLoopResult(loopWith.call(stack.it, seq), seq);
2365
+ enricher.call(stack.it, binds, key, value, iterData);
2366
+ }
2367
+ return binds;
2368
+ }
2339
2369
  }
2340
2370
  function xOp(consumed = [], { wrappable = false, wrapper = null } = {}) {
2341
2371
  return { consumed: new Set(consumed), wrappable, wrapper };
@@ -4420,6 +4420,23 @@ class BindStep extends Step {
4420
4420
  }
4421
4421
  }
4422
4422
 
4423
+ class ScopeBindStep extends BindStep {
4424
+ constructor(val, binds = {}) {
4425
+ super(binds);
4426
+ this.val = val;
4427
+ }
4428
+ enterFrame(stack, _prev, next) {
4429
+ const dyn = this.val.evalAsHandler(stack)?.call(stack.it) ?? {};
4430
+ return stack.enter(next, { ...this.binds, ...dyn }, false);
4431
+ }
4432
+ withIndex(i) {
4433
+ return new ScopeBindStep(this.val, { ...this.binds, key: i });
4434
+ }
4435
+ withKey(key) {
4436
+ return new ScopeBindStep(this.val, { ...this.binds, key });
4437
+ }
4438
+ }
4439
+
4423
4440
  class FieldStep extends Step {
4424
4441
  constructor(field) {
4425
4442
  super();
@@ -4481,9 +4498,9 @@ class SeqAccessStep extends Step {
4481
4498
  }
4482
4499
 
4483
4500
  class EachBindStep extends Step {
4484
- constructor(seqVal, key) {
4501
+ constructor(iterInfo, key) {
4485
4502
  super();
4486
- this.seqVal = seqVal;
4503
+ this.iterInfo = iterInfo;
4487
4504
  this.key = key;
4488
4505
  }
4489
4506
  lookup(v, _dval) {
@@ -4493,8 +4510,7 @@ class EachBindStep extends Step {
4493
4510
  return v;
4494
4511
  }
4495
4512
  enterFrame(stack, _prev, next) {
4496
- const item = this.seqVal.eval(stack)?.get(this.key, null);
4497
- return stack.enter(next, { key: this.key, value: item }, false);
4513
+ return stack.enter(next, this.iterInfo.enrichBinds(stack, this.key), false);
4498
4514
  }
4499
4515
  toAbstractPathStep() {
4500
4516
  return null;
@@ -6146,6 +6162,9 @@ class Renderer {
6146
6162
  _renderMetadata(info) {
6147
6163
  return new VComment(`§${JSON.stringify(info)}§`);
6148
6164
  }
6165
+ renderScopeMeta(nid, dom) {
6166
+ return new VFragment([this._renderMetadata({ $: "Scope", nid }), dom]);
6167
+ }
6149
6168
  }
6150
6169
  var getSeqInfo = (seq) => isIndexed(seq) ? imIndexedIter : isKeyed(seq) ? imKeyedIter : seq?.[SEQ_INFO] ?? unkIter;
6151
6170
  var normalizeRange = (start, end, size) => {
@@ -6666,10 +6685,11 @@ class SlotNode extends WrapperNode {
6666
6685
  class ScopeNode extends WrapperNode {
6667
6686
  render(stack, rx) {
6668
6687
  const binds = this.val.evalAsHandler(stack)?.call(stack.it) ?? {};
6669
- return this.node.render(stack.enter(stack.it, binds, false), rx);
6688
+ const dom = this.node.render(stack.enter(stack.it, binds, false), rx);
6689
+ return rx.renderScopeMeta(this.nodeId, dom);
6670
6690
  }
6671
6691
  toPathStep(_ctx) {
6672
- return new BindStep({});
6692
+ return new ScopeBindStep(this.val);
6673
6693
  }
6674
6694
  wrapNode(node) {
6675
6695
  this.node = node;
@@ -6687,7 +6707,7 @@ class EachNode extends WrapperNode {
6687
6707
  return rx.renderEachWhen(stack, this.iterInfo, this.node, this.nodeId);
6688
6708
  }
6689
6709
  toPathStep(ctx) {
6690
- return ctx.hasKey ? new EachBindStep(this.val, ctx.key) : null;
6710
+ return ctx.hasKey ? new EachBindStep(this.iterInfo, ctx.key) : null;
6691
6711
  }
6692
6712
  static register = true;
6693
6713
  }
@@ -6706,6 +6726,16 @@ class IterInfo {
6706
6726
  const enricher = this.enrichWithVal?.evalAsHandler(stack) ?? null;
6707
6727
  return { seq, filter, loopWith, enricher };
6708
6728
  }
6729
+ enrichBinds(stack, key) {
6730
+ const { seq, loopWith, enricher } = this.eval(stack);
6731
+ const value = seq?.get ? seq.get(key, null) : null;
6732
+ const binds = { key, value };
6733
+ if (enricher) {
6734
+ const { iterData } = unpackLoopResult(loopWith.call(stack.it, seq), seq);
6735
+ enricher.call(stack.it, binds, key, value, iterData);
6736
+ }
6737
+ return binds;
6738
+ }
6709
6739
  }
6710
6740
  function xOp(consumed = [], { wrappable = false, wrapper = null } = {}) {
6711
6741
  return { consumed: new Set(consumed), wrappable, wrapper };