How This Example Works
Optimizing compilers and minifiers perform register allocation / variable coalescing: if three authored variables (calibratedMv, temperatureCelsius, and statusBadge) have non-overlapping lifetimes, the compiler reuses a single JavaScript variable let r for all three!
Without sub-range bindings, mapping all three names to r would cause every variable to show the wrong value (e.g. statusBadge showing 1250 at Step 1). Using SubRangeBinding[], each variable specifies exact [from, to) positions in generated code where it is unavailable, bound directly to "r", or algebraically reconstructed (`r * 10 + 500`).
What to Try & Verify in DevTools
Try:Click "Run & Pause in Debugger" to stop at debugger; // Step 1 in register-reuse.ts (where let r = 1250).
- Active Binding:
calibratedMvdisplays1250(bound directly tor). - Pre-Initialization Liveness:
temperatureCelsiusandstatusBadgeboth display<unavailable>instead of leakingr's current value.
Try:Press F8 (Resume) once to advance to debugger; // Step 2 (where r is overwritten with 75).
- Reassigned Register:
temperatureCelsiusbecomes live with value75(now bound tor). - Reverse Algebraic Binding:
calibratedMvstays1250because its active sub-range[step2Pos, step3Pos)switches its binding expression to"r * 10 + 500". - Still Uninitialized:
statusBadgeremains<unavailable>.
Try:Press F8 (Resume) once more to reach debugger; // Step 3 (where r is overwritten with the badge string).
- New Register Owner:
statusBadgebecomes"[CORE-TEMP-04] 75.0°C (WARN)"(bound tor). - Clobbered Register:
calibratedMvtransitions to<unavailable>becausernow holds a string. - Fallback Expression:
temperatureCelsius(75) stays live via(e.rawMillivolts + e.calibrationOffset - 500) / 10.
Try:Type cal, temp, or statusB in the Console to check autocomplete, or set a conditional breakpoint on line 18 (const statusBadge = ...) with condition temperatureCelsius >= 70 && calibratedMv === 1250.
- Autocomplete: All three coalesced variables appear in Console and breakpoint autocomplete.
- Sub-Range Condition Evaluation: At line 18, DevTools simultaneously resolves
temperatureCelsius(r) andcalibratedMv(r * 10 + 500) to pause execution.
Try:Run the expressions below in the Console at Steps 1, 2, and 3.
- PC-Sensitive Rewriting: DevTools picks the exact
SubRangeBindinginterval matching the current pausedline:columninbundle.js.
Other things to try
- Step with
F10instead of resuming, and watch when each variable switches between a value and<unavailable>. - Add
calibratedMv,temperatureCelsiusandstatusBadgeas Watch expressions before running. - Set a breakpoint on each
constline (instead of usingdebugger;) and check the Scope view.
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:
calibratedMv
temperatureCelsius * 1.8 + 32
statusBadge