destructure-alias.ts 579 B

12345678910
  1. // Destructuring aliasing (heap fix): a destructuring declaration off a live place binds
  2. // each extracted name to the container's LIVE field, not a snapshot. `const { o } = wrap`
  3. // makes `o` the same object as `wrap.o`, so `o.f = secret` is visible through `wrap.o.f`.
  4. // Expected: source -> ask#1, ask#1 -> ask#2 (secret through the shared extracted field), ask#2 -> sink.
  5. const wrap = { o: { f: "" } };
  6. const { o } = wrap;
  7. const secret = await agent("writer").ask<string>("secret");
  8. o.f = secret;
  9. const out = await agent("reader").ask<string>(`use ${wrap.o.f}`);
  10. return out;