@bablr/agast-vm 0.6.0 → 0.6.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/lib/context.js CHANGED
@@ -3,10 +3,7 @@ import {
3
3
  getCooked as getCookedFromTree,
4
4
  sourceTextFor as sourceTextForTree,
5
5
  } from '@bablr/agast-helpers/tree';
6
- import {
7
- getCooked as getCookedFromStream,
8
- sourceTextFor as sourceTextForStream,
9
- } from '@bablr/agast-helpers/stream';
6
+ import { getCooked as getCookedFromStream } from '@bablr/agast-helpers/stream';
10
7
  import { OpenNodeTag, CloseNodeTag } from '@bablr/agast-helpers/symbols';
11
8
  import { facades, actuals } from './facades.js';
12
9
 
@@ -52,6 +49,10 @@ export const ContextFacade = class AgastContextFacade {
52
49
  return actuals.get(this).buildRange(tags);
53
50
  }
54
51
 
52
+ nodeForTag(tag) {
53
+ return actuals.get(this).nodeForTag(tag);
54
+ }
55
+
55
56
  unbox(value) {
56
57
  return actuals.get(this).unbox(value);
57
58
  }
@@ -65,6 +66,7 @@ export const Context = class AgastContext {
65
66
  constructor() {
66
67
  this.prevTags = new WeakMap();
67
68
  this.nextTags = new WeakMap();
69
+ this.tagNodes = new WeakMap();
68
70
  this.unboxedValues = new WeakMap();
69
71
  this.facade = new ContextFacade();
70
72
 
@@ -100,6 +102,10 @@ export const Context = class AgastContext {
100
102
  return this.nextTags.get(token);
101
103
  }
102
104
 
105
+ nodeForTag(tag) {
106
+ return this.tagNodes.get(tag);
107
+ }
108
+
103
109
  sourceTextFor(node) {
104
110
  return sourceTextForTree(node);
105
111
  }
package/lib/evaluate.js CHANGED
@@ -72,7 +72,7 @@ const __evaluate = function* agast(ctx, strategy, options = {}) {
72
72
  s = s.accept();
73
73
 
74
74
  if (s.depth === 0) {
75
- yield* s.emit();
75
+ yield* s.emit(options);
76
76
  }
77
77
 
78
78
  returnValue = facades.get(s);
@@ -87,7 +87,7 @@ const __evaluate = function* agast(ctx, strategy, options = {}) {
87
87
  }
88
88
 
89
89
  case 'advance': {
90
- const { 0: embeddedTag, 1: options } = args;
90
+ const { 0: embeddedTag, 1: advanceOptions } = args;
91
91
 
92
92
  const tag = embeddedTag.value;
93
93
 
@@ -186,7 +186,7 @@ const __evaluate = function* agast(ctx, strategy, options = {}) {
186
186
 
187
187
  returnValue = s.advance(
188
188
  buildNodeOpenTag(flags, language, type, attributes),
189
- getEmbeddedExpression(options),
189
+ getEmbeddedExpression(advanceOptions),
190
190
  );
191
191
  break;
192
192
  }
@@ -194,7 +194,10 @@ const __evaluate = function* agast(ctx, strategy, options = {}) {
194
194
  case OpenFragmentTag: {
195
195
  const { flags } = tag.value;
196
196
 
197
- returnValue = s.advance(buildFragmentOpenTag(flags), getEmbeddedExpression(options));
197
+ returnValue = s.advance(
198
+ buildFragmentOpenTag(flags),
199
+ getEmbeddedExpression(advanceOptions),
200
+ );
198
201
  break;
199
202
  }
200
203
 
@@ -214,7 +217,7 @@ const __evaluate = function* agast(ctx, strategy, options = {}) {
214
217
  throw new Error();
215
218
  }
216
219
 
217
- yield* s.emit();
220
+ yield* s.emit(options);
218
221
 
219
222
  break;
220
223
  }
@@ -274,7 +277,7 @@ const __evaluate = function* agast(ctx, strategy, options = {}) {
274
277
  }
275
278
 
276
279
  if (!unboundAttributes.size) {
277
- yield* s.emit();
280
+ yield* s.emit(options);
278
281
  }
279
282
 
280
283
  returnValue = getRange(s.node);
package/lib/state.js CHANGED
@@ -17,6 +17,8 @@ import * as btree from '@bablr/agast-helpers/btree';
17
17
  import {
18
18
  buildBeginningOfStreamToken,
19
19
  buildEmbeddedNode,
20
+ buildEffect,
21
+ buildYieldEffect,
20
22
  } from '@bablr/agast-vm-helpers/internal-builders';
21
23
  import {
22
24
  DoctypeTag,
@@ -148,7 +150,7 @@ export const State = class AgastState extends WeakStackFrame {
148
150
  }
149
151
 
150
152
  get tagNodes() {
151
- return this.internalContext.tagNodes;
153
+ return this.context.tagNodes;
152
154
  }
153
155
 
154
156
  get unboundAttributes() {
@@ -423,7 +425,7 @@ export const State = class AgastState extends WeakStackFrame {
423
425
  return tag;
424
426
  }
425
427
 
426
- *emit() {
428
+ *emit(options) {
427
429
  const { nextTags } = this.context;
428
430
  if (!this.depth) {
429
431
  let emittable = this.emitted ? nextTags.get(this.emitted) : this.result;
@@ -436,7 +438,8 @@ export const State = class AgastState extends WeakStackFrame {
436
438
  nodeStates.get(this.nodeForTag(emittable)).unboundAttributes?.size
437
439
  )
438
440
  ) {
439
- yield emittable;
441
+ yield options.emitEffects ? buildYieldEffect(emittable) : emittable;
442
+
440
443
  this.emitted = emittable;
441
444
  emittable = nextTags.get(this.emitted);
442
445
  }
package/package.json CHANGED
@@ -1,12 +1,10 @@
1
1
  {
2
2
  "name": "@bablr/agast-vm",
3
3
  "description": "A VM providing DOM-like guarantees about agAST trees",
4
- "version": "0.6.0",
4
+ "version": "0.6.1",
5
5
  "author": "Conrad Buck<conartist6@gmail.com>",
6
6
  "type": "module",
7
- "files": [
8
- "lib"
9
- ],
7
+ "files": ["lib"],
10
8
  "exports": {
11
9
  ".": "./lib/index.js"
12
10
  },