classes-2-class-accessors.ts 707 B

12345678910111213141516171819
  1. // Class-declared accessors with DIFFERENT names (so the raw field write cannot mask the
  2. // accessor path): the setter stores its parameter into this.hidden, the getter reads it
  3. // back. Runtime: v.input = secret => setter => this.hidden = secret; v.output => getter
  4. // => secret feeds ask#2.
  5. // Expected: source -> ask#1, ask#1 -> ask#2 (setter param -> this.hidden -> getter), ask#2 -> sink.
  6. const secret = await agent("writer").ask<string>("secret");
  7. class Vault {
  8. hidden = "";
  9. set input(x: string) {
  10. this.hidden = x;
  11. }
  12. get output(): string {
  13. return this.hidden;
  14. }
  15. }
  16. const v = new Vault();
  17. v.input = secret;
  18. const out = await agent("reader").ask<string>(`use ${v.output}`);
  19. return out;