classes-2-param-property.ts 650 B

123456789101112131415
  1. // A constructor PARAMETER PROPERTY (`constructor(private x: string) {}`) performs an
  2. // implicit `this.x = x` at runtime; reveal() then returns it into ask#2.
  3. // Probe: parameter properties are not PropertyDeclarations and the ctor body is empty —
  4. // is the implicit assignment modeled?
  5. // Expected: source -> ask#1, ask#1 -> ask#2 (ctor param property -> this.x), ask#2 -> sink.
  6. const secret = await agent("writer").ask<string>("secret");
  7. class Holder {
  8. constructor(private x: string) {}
  9. reveal(): string {
  10. return this.x;
  11. }
  12. }
  13. const h = new Holder(secret);
  14. const out = await agent("reader").ask<string>(`use ${h.reveal()}`);
  15. return out;