EXAMPLE 07 • multi-callsite.ts

One Function Inlined at Two Call Sites

toCents() is inlined twice into compareOffers(). One authored breakpoint must resolve to both copies, each with its own call site and values.

Two Inlined Ranges Sharing One OriginalScopeDistinct callSite per Inlined CopyPer-Copy Bindings
OPEN CHROME DEVTOOLS (F12) FIRST, THEN TRIGGER:
Ready. Click "Run compareOffers()" with DevTools open.

How This Example Works

The compiler inlined toCents at both of its call sites, so every line of toCents exists twice in bundle.js. Both generated ranges reference the same toCents original scope, but each has its own callSite and binds the parameters to different generated variables.

What to Try & Verify in DevTools

Call Stack

Try:Set a breakpoint on line 4 (const cents = ...) of multi-callsite.ts and click Run compareOffers(). Resume (F8) after the first pause.

  • Pauses twice. 1st: toCents → compareOffers (line 14). 2nd: toCents → compareOffers (line 15).
  • Scope: 1st amount: 20, currency: "GBP", rate: 1.25. 2nd amount: 24.5, currency: "USD", rate: 1. cents is <unavailable> both times.
  • At the 2nd pause, select compareOffers: centsA: 2500, centsB <unavailable>.
  • Breakpoints pane: a single breakpoint entry, not one per copy.
Conditional Breakpoints

Try:Edit the breakpoint to the condition currency === "USD" and re-run. Then turn it into a logpoint amount, currency, rate and re-run.

  • Condition: pauses only once, in the 2nd copy (amount: 24.5).
  • Logpoint: the Console logs two lines, one per copy: 20, GBP, 1.25 and 24.5, USD, 1.
Other things to try
  • From the 1st pause, press F10 or Shift+F11. compareOffers has no code of its own between the two copies: where should you land?
  • Also set a breakpoint on line 3 (const rate = ...): it should hit in both copies, too.
  • Disable and re-enable the breakpoint from the Breakpoints pane, or reload the page with the breakpoint set.

Not sure if it's a DevTools bug? Tab 4. Decoded Scopes shows what the source map actually encodes.

Try in the Console While Paused

While paused, select a frame and evaluate these in the Console (Esc opens the drawer) using the authored names:

amount * rate
Expected Result: 25 (1st pause), 24.5 (2nd pause)
Same expression, different generated variables (a * r1 vs. b * r2).
priceA + priceB
Expected Result: 44.5
With compareOffers selected in the Call Stack.