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
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. 2ndamount: 24.5,currency: "USD",rate: 1.centsis<unavailable>both times. - At the 2nd pause, select
compareOffers:centsA: 2500,centsB<unavailable>. - Breakpoints pane: a single breakpoint entry, not one per copy.
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.25and24.5,USD,1.
Other things to try
- From the 1st pause, press
F10orShift+F11.compareOffershas 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
priceA + priceB